| 1 | #!/usr/bin/perl -w | 
|---|
| 2 | use 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 |  | 
|---|
| 23 | my @dynamic = qw( | 
|---|
| 24 | pl | 
|---|
| 25 | php | 
|---|
| 26 | py | 
|---|
| 27 | cgi | 
|---|
| 28 | scm | 
|---|
| 29 | ); | 
|---|
| 30 |  | 
|---|
| 31 | my @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 |  | 
|---|
| 57 | my %map; | 
|---|
| 58 | open(TYPES, "./mime.types"); | 
|---|
| 59 | while(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 | } | 
|---|
| 68 | close(TYPES); | 
|---|
| 69 |  | 
|---|
| 70 | undef $/; | 
|---|
| 71 | my $regexp = '(.*[\/\#]+\sSTART-AUTOGENERATED:[^!]*!).*\s([\/\#]+\sEND-AUTOGENERATED.*)'; | 
|---|
| 72 |  | 
|---|
| 73 | # Read existing binfmt file | 
|---|
| 74 |  | 
|---|
| 75 | open(BINFMT, "./execsys-binfmt.pre"); | 
|---|
| 76 | my $file = <BINFMT>; | 
|---|
| 77 | my ($fstart, $fend) = ($file =~ /$regexp/s); | 
|---|
| 78 | close(BINFMT); | 
|---|
| 79 |  | 
|---|
| 80 | # Write new binfmt file | 
|---|
| 81 |  | 
|---|
| 82 | open(BINFMT, ">./execsys-binfmt"); | 
|---|
| 83 | print BINFMT $fstart, "\n"; | 
|---|
| 84 |  | 
|---|
| 85 | foreach 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 |  | 
|---|
| 90 | foreach my $ext (@static) { | 
|---|
| 91 | print BINFMT "echo \":${ext}:E::${ext}::$ENV{syscat_path}:\" > /proc/sys/fs/binfmt_misc/register\n"; | 
|---|
| 92 | } | 
|---|
| 93 | print BINFMT $fend; | 
|---|
| 94 | close(BINFMT); | 
|---|
| 95 |  | 
|---|
| 96 | open(CONF, ">./execsys.conf"); | 
|---|
| 97 |  | 
|---|
| 98 | foreach my $ext (@dynamic, @static) { | 
|---|
| 99 | print CONF <<END | 
|---|
| 100 | <Files *.$ext> | 
|---|
| 101 | SetHandler cgi-script | 
|---|
| 102 | Options +ExecCGI | 
|---|
| 103 | </Files> | 
|---|
| 104 |  | 
|---|
| 105 | END | 
|---|
| 106 | } | 
|---|
| 107 | close(CONF); | 
|---|
| 108 |  | 
|---|
| 109 | open(CAT, "./static-cat.c.pre"); | 
|---|
| 110 | $file = <CAT>; | 
|---|
| 111 | ($fstart, $fend) = ($file =~ /$regexp/s); | 
|---|
| 112 | close(CAT); | 
|---|
| 113 |  | 
|---|
| 114 | open(CAT, ">./static-cat.c"); | 
|---|
| 115 | print CAT $fstart, "\n"; | 
|---|
| 116 | print CAT '#define NEXTS ', scalar(@static), "\n"; | 
|---|
| 117 | print CAT "const char *map[2 * NEXTS] = {\n"; | 
|---|
| 118 | for(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 | } | 
|---|
| 122 | print CAT "};\n"; | 
|---|
| 123 | print CAT $fend; | 
|---|
| 124 | close(CAT); | 
|---|