source: server/common/oursrc/execsys/upd-execsys @ 26

Last change on this file since 26 was 26, checked in by jbarnold, 16 years ago
added support for .cgi files
File size: 2.6 KB
Line 
1#!/usr/bin/perl -w
2use strict;
3
4# upd-execsys
5# Copyright (C) 2006  Jeff Arnold <jbarnold@mit.edu>
6#
7# This program is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public License
9# as published by the Free Software Foundation; either version 2
10# of the License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
20#
21# See /COPYRIGHT in this repository for more information.
22
23my @dynamic = qw(
24 pl
25 php
26 py
27 cgi
28 scm
29);
30
31my @static = qw(
32 html
33 css
34 gif
35 jpg
36 png
37 htm
38 jpeg
39 js
40 ico
41 xml
42 xsl
43 tiff
44 tif
45 tgz
46 tar
47 jar
48 pdf
49 ps
50 doc
51 xls
52 ppt
53 swf
54 mp3
55);
56
57my %map;
58open(TYPES, "./mime.types");
59while(my $line = <TYPES>) {
60        next if($line =~ /^\#/ or $line =~ /^\s*$/);
61        my ($type, $exts) = ($line =~ /^(\S*)\s+(.*)$/);
62        next if($exts =~ /^\s*$/);
63       
64        foreach my $ext (split " ", $exts) {
65                $map{$ext} = $type;
66        }
67}
68close(TYPES);
69
70undef $/;
71my $regexp = '(.*[\/\#]+\sSTART-AUTOGENERATED:[^!]*!).*\s([\/\#]+\sEND-AUTOGENERATED.*)';
72
73# Read existing binfmt file
74
75open(BINFMT, "./execsys-binfmt.pre");
76my $file = <BINFMT>;
77my ($fstart, $fend) = ($file =~ /$regexp/s);
78close(BINFMT);
79
80# Write new binfmt file
81
82open(BINFMT, ">./execsys-binfmt");
83print BINFMT $fstart, "\n";
84
85foreach my $ext (@dynamic) {
86  my $path = $ENV{"${ext}_path"};
87  print BINFMT "echo \":${ext}:E::${ext}::${path}:\" > /proc/sys/fs/binfmt_misc/register\n" if($path);
88}
89
90foreach my $ext (@static) {
91        print BINFMT "echo \":${ext}:E::${ext}::$ENV{syscat_path}:\" > /proc/sys/fs/binfmt_misc/register\n";
92}
93print BINFMT $fend;
94close(BINFMT);
95
96open(CONF, ">./execsys.conf");
97
98foreach my $ext (@dynamic, @static) {
99        print CONF <<END
100<Files *.$ext>
101        SetHandler cgi-script
102        Options +ExecCGI
103</Files>
104
105END
106}
107close(CONF);
108
109open(CAT, "./staticsys-cat.c.pre");
110$file = <CAT>;
111($fstart, $fend) = ($file =~ /$regexp/s);
112close(CAT);
113
114open(CAT, ">./staticsys-cat.c");
115print CAT $fstart, "\n";
116print CAT '#define NEXTS ', scalar(@static), "\n";
117print CAT "const char *map[2 * NEXTS] = {\n";
118for(my $i = 0; $i < scalar(@static); $i++) {
119        my $comma = ( $i < scalar(@static)-1 ? "," : "" );
120        print CAT "\t\"$static[$i]\", \"$map{$static[$i]}\"$comma\n";
121}
122print CAT "};\n";
123print CAT $fend;
124close(CAT);
Note: See TracBrowser for help on using the repository browser.