| [1] | 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 | 
|---|
| [26] | 27 |  cgi | 
|---|
| [1] | 28 |  scm | 
|---|
| [163] | 29 |  exe | 
|---|
| [1] | 30 | ); | 
|---|
 | 31 |  | 
|---|
 | 32 | my @static = qw( | 
|---|
 | 33 |  html | 
|---|
 | 34 |  css | 
|---|
 | 35 |  gif | 
|---|
 | 36 |  jpg | 
|---|
 | 37 |  png | 
|---|
 | 38 |  htm | 
|---|
 | 39 |  jpeg | 
|---|
 | 40 |  js | 
|---|
 | 41 |  ico | 
|---|
 | 42 |  xml | 
|---|
 | 43 |  xsl | 
|---|
 | 44 |  tiff | 
|---|
 | 45 |  tif | 
|---|
 | 46 |  tgz | 
|---|
 | 47 |  tar | 
|---|
 | 48 |  jar | 
|---|
| [254] | 49 |  zip | 
|---|
| [1] | 50 |  pdf | 
|---|
 | 51 |  ps | 
|---|
 | 52 |  doc | 
|---|
 | 53 |  xls | 
|---|
 | 54 |  ppt | 
|---|
 | 55 |  swf | 
|---|
 | 56 |  mp3 | 
|---|
| [254] | 57 |  mov | 
|---|
 | 58 |  wmv | 
|---|
| [255] | 59 |  mpg | 
|---|
 | 60 |  mpeg | 
|---|
 | 61 |  avi | 
|---|
| [254] | 62 |  il | 
|---|
| [140] | 63 |  JPG | 
|---|
| [315] | 64 |  xhtml | 
|---|
| [617] | 65 |  svg | 
|---|
| [1] | 66 | ); | 
|---|
 | 67 |  | 
|---|
 | 68 | my %map; | 
|---|
 | 69 | open(TYPES, "./mime.types"); | 
|---|
 | 70 | while(my $line = <TYPES>) { | 
|---|
 | 71 |         next if($line =~ /^\#/ or $line =~ /^\s*$/); | 
|---|
 | 72 |         my ($type, $exts) = ($line =~ /^(\S*)\s+(.*)$/); | 
|---|
 | 73 |         next if($exts =~ /^\s*$/); | 
|---|
 | 74 |          | 
|---|
 | 75 |         foreach my $ext (split " ", $exts) { | 
|---|
 | 76 |                 $map{$ext} = $type; | 
|---|
| [141] | 77 |                 $map{uc($ext)} = $type; | 
|---|
| [1] | 78 |         } | 
|---|
 | 79 | } | 
|---|
 | 80 | close(TYPES); | 
|---|
 | 81 |  | 
|---|
 | 82 | undef $/; | 
|---|
 | 83 | my $regexp = '(.*[\/\#]+\sSTART-AUTOGENERATED:[^!]*!).*\s([\/\#]+\sEND-AUTOGENERATED.*)'; | 
|---|
 | 84 |  | 
|---|
 | 85 | # Read existing binfmt file | 
|---|
 | 86 |  | 
|---|
 | 87 | open(BINFMT, "./execsys-binfmt.pre"); | 
|---|
 | 88 | my $file = <BINFMT>; | 
|---|
 | 89 | my ($fstart, $fend) = ($file =~ /$regexp/s); | 
|---|
 | 90 | close(BINFMT); | 
|---|
 | 91 |  | 
|---|
 | 92 | # Write new binfmt file | 
|---|
 | 93 |  | 
|---|
 | 94 | open(BINFMT, ">./execsys-binfmt"); | 
|---|
 | 95 | print BINFMT $fstart, "\n"; | 
|---|
 | 96 |  | 
|---|
 | 97 | foreach my $ext (@dynamic) { | 
|---|
 | 98 |   my $path = $ENV{"${ext}_path"}; | 
|---|
 | 99 |   print BINFMT "echo \":${ext}:E::${ext}::${path}:\" > /proc/sys/fs/binfmt_misc/register\n" if($path); | 
|---|
 | 100 | } | 
|---|
 | 101 |  | 
|---|
| [302] | 102 | #foreach my $ext (@static) { | 
|---|
 | 103 | #       print BINFMT "echo \":${ext}:E::${ext}::$ENV{syscat_path}:\" > /proc/sys/fs/binfmt_misc/register\n"; | 
|---|
 | 104 | #} | 
|---|
| [1] | 105 | print BINFMT $fend; | 
|---|
 | 106 | close(BINFMT); | 
|---|
 | 107 |  | 
|---|
 | 108 | open(CONF, ">./execsys.conf"); | 
|---|
 | 109 |  | 
|---|
 | 110 | foreach my $ext (@dynamic, @static) { | 
|---|
 | 111 |         print CONF <<END | 
|---|
 | 112 | <Files *.$ext> | 
|---|
 | 113 |         SetHandler cgi-script | 
|---|
 | 114 |         Options +ExecCGI | 
|---|
 | 115 | </Files> | 
|---|
 | 116 |  | 
|---|
 | 117 | END | 
|---|
 | 118 | } | 
|---|
 | 119 | close(CONF); | 
|---|
 | 120 |  | 
|---|
| [104] | 121 | open(CAT, "./static-cat.c.pre"); | 
|---|
| [1] | 122 | $file = <CAT>; | 
|---|
 | 123 | ($fstart, $fend) = ($file =~ /$regexp/s); | 
|---|
 | 124 | close(CAT); | 
|---|
 | 125 |  | 
|---|
| [104] | 126 | open(CAT, ">./static-cat.c"); | 
|---|
| [1] | 127 | print CAT $fstart, "\n"; | 
|---|
 | 128 | print CAT '#define NEXTS ', scalar(@static), "\n"; | 
|---|
 | 129 | print CAT "const char *map[2 * NEXTS] = {\n"; | 
|---|
 | 130 | for(my $i = 0; $i < scalar(@static); $i++) { | 
|---|
 | 131 |         my $comma = ( $i < scalar(@static)-1 ? "," : "" ); | 
|---|
 | 132 |         print CAT "\t\"$static[$i]\", \"$map{$static[$i]}\"$comma\n"; | 
|---|
 | 133 | } | 
|---|
 | 134 | print CAT "};\n"; | 
|---|
 | 135 | print CAT $fend; | 
|---|
 | 136 | close(CAT); | 
|---|