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

Last change on this file since 141 was 141, checked in by jbarnold, 15 years ago
removed autogenerated execsys.conf from repo; added capitalized ext support
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 JPG
56);
57
58my %map;
59open(TYPES, "./mime.types");
60while(my $line = <TYPES>) {
61        next if($line =~ /^\#/ or $line =~ /^\s*$/);
62        my ($type, $exts) = ($line =~ /^(\S*)\s+(.*)$/);
63        next if($exts =~ /^\s*$/);
64       
65        foreach my $ext (split " ", $exts) {
66                $map{$ext} = $type;
67                $map{uc($ext)} = $type;
68        }
69}
70close(TYPES);
71
72undef $/;
73my $regexp = '(.*[\/\#]+\sSTART-AUTOGENERATED:[^!]*!).*\s([\/\#]+\sEND-AUTOGENERATED.*)';
74
75# Read existing binfmt file
76
77open(BINFMT, "./execsys-binfmt.pre");
78my $file = <BINFMT>;
79my ($fstart, $fend) = ($file =~ /$regexp/s);
80close(BINFMT);
81
82# Write new binfmt file
83
84open(BINFMT, ">./execsys-binfmt");
85print BINFMT $fstart, "\n";
86
87foreach my $ext (@dynamic) {
88  my $path = $ENV{"${ext}_path"};
89  print BINFMT "echo \":${ext}:E::${ext}::${path}:\" > /proc/sys/fs/binfmt_misc/register\n" if($path);
90}
91
92foreach my $ext (@static) {
93        print BINFMT "echo \":${ext}:E::${ext}::$ENV{syscat_path}:\" > /proc/sys/fs/binfmt_misc/register\n";
94}
95print BINFMT $fend;
96close(BINFMT);
97
98open(CONF, ">./execsys.conf");
99
100foreach my $ext (@dynamic, @static) {
101        print CONF <<END
102<Files *.$ext>
103        SetHandler cgi-script
104        Options +ExecCGI
105</Files>
106
107END
108}
109close(CONF);
110
111open(CAT, "./static-cat.c.pre");
112$file = <CAT>;
113($fstart, $fend) = ($file =~ /$regexp/s);
114close(CAT);
115
116open(CAT, ">./static-cat.c");
117print CAT $fstart, "\n";
118print CAT '#define NEXTS ', scalar(@static), "\n";
119print CAT "const char *map[2 * NEXTS] = {\n";
120for(my $i = 0; $i < scalar(@static); $i++) {
121        my $comma = ( $i < scalar(@static)-1 ? "," : "" );
122        print CAT "\t\"$static[$i]\", \"$map{$static[$i]}\"$comma\n";
123}
124print CAT "};\n";
125print CAT $fend;
126close(CAT);
Note: See TracBrowser for help on using the repository browser.