#!/usr/local/bin/perl # SSIemu v0.5 beta (Jan-06-2000) # Copyright (C) 2000 Kan-chan # Web site: http://kan-chan.stbbs.net/download/ # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the Free # Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # # v0.5 First release # # Usage: # 1. Modify the perl directory written on the top of this script # if it is required. # 2. Modify the value of $lockfiledir if needed. # 3. Upload files to the following directories and change the # permission. If you cannot use 707/705/606, try 777/755/666. # 4. Add to HTML file # Also, change SSI command from # # public_html/ # | # |-- index.html (permission:606 or 666) # |-- cgi-bin/ # |-- ssiemu.cgi (permission:705 or 755) # |-- lock/ (permission:707 or 777) # # The name of temporary file to lock the process $lockfiledir = "./lock/"; $buffer = $ENV{'QUERY_STRING'}; @pairs = split(/&/,$buffer); foreach $pair (@pairs) { ($name,$value) = split(/=/,$pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } $htmlfile = $FORM{'html'}; if ($htmlfile eq '') { &error_open_html; exit; } $lockfile = $htmlfile; $lockfile =~ s/\//\$/g; $lockfile =~ s/\./_/g; $lockfile = "$lockfiledir$lockfile.\$\$\$"; $htmlpath = $htmlfile; if ($htmlpath =~ /\//){ $htmlpath =~ s/(.*)\/.*/$1\//g; } else{ $htmlpath = './'; } # Wait until the lock is released for ($i=1;$i<=6;$i++){ if (!(-e $lockfile)) { last; } elsif ($i == 1){ $filetime = (stat($lockfile))[9]; if ($filetime < time() - 10 * 60){ &unlock; } } elsif ($i >= 6){ &error_busy; exit; } sleep(1); } # Create a lock file open(OUT, ">$lockfile"); close(OUT); # Read/write count file if (!open(IN, "<$htmlfile")) { &unlock; &error_open_html; exit; } $s = ''; while () { $s .= $_; } close(IN); $s =~ s//''.&cmd_config_timefmt($1)/eg; $s =~ s/.*/''.&cmd_env($1).''/eg; $s =~ s/.*/''.&cmd_exec($1).''/eg; if (!open(OUT, ">$htmlfile")) { &unlock; &error_open_html; exit; } print OUT $s; close(OUT); # Remove the lock file &unlock; &dummy_bitmap; #Exit this program exit; # If a lock file exists, delete the file sub unlock { if (-e $lockfile) { unlink($lockfile); } } sub cmd_config_timefmt{ $timefmt = $_[0]; return ''; } sub cmd_env{ $e = $_[0]; if ($e eq 'LAST_MODIFIED'){ $filedate = (stat($htmlfile))[9]; $ret = &getdatestr($filedate); }else{ $ret = $ENV{$e}; } return $ret; } sub getdatestr{ # Days of week in English @month_s = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ); @month_l = ( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ); @wdays_s = ( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" ); @wdays_l = ( "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ); $date = $_[0]; if ($timefmt eq ''){ $timefmt = '%A, %m-%b-%Y %X %Z'; } ($sec, $min, $hour, $mday, $mon, $year, $wday) = localtime($date); if ($hour < 12){ $ampm = 'AM'; $hour12 = $hour; } else{ $ampm = 'PM'; $hour12 = $hour - 12; } if ($hour12 == 0) { $hour12 = 12; } $year += 1900; $year_s = sprintf("%02d", $year % 100); $month = sprintf("%02d", $mon + 1); $mday = sprintf("%02d", $mday); $hour = sprintf("%02d", $hour); $hour12 = sprintf("%02d", $hour12); $min = sprintf("%02d", $min); $sec = sprintf("%02d", $sec); $tz = $ENV{'TZ'}; $tz = 'JST-9'; $tz =~ s/(.*)[+-].*/$1/g; # $ret = sprintf("%s, %02d-%s-%d %02d:%02d:%02d %s", @wdays_l[$wday], $mday, @month_s[$mon], $year, $hour, $min, $sec, $tz); $ret = $timefmt; $ret =~ s/%c/$month\/$mday\/$year_s $hour:$min:$sec/g; $ret =~ s/%x/$month\/$mday\/$year_s/g; $ret =~ s/%X/$hour:$min:$sec/g; $ret =~ s/%y/$year_s/g; $ret =~ s/%Y/$year/g; $ret =~ s/%b/@month_s[$mon]/g; $ret =~ s/%B/@month_l[$mon]/g; $ret =~ s/%m/$month/g; $ret =~ s/%a/@wdays_s[$wday]/g; $ret =~ s/%A/@wdays_l[$wday]/g; $ret =~ s/%d/$mday/g; $ret =~ s/%w/$wday/g; $ret =~ s/%p/$ampm/g; $ret =~ s/%H/$hour/g; $ret =~ s/%I/$hour12/g; $ret =~ s/%M/$min/g; $ret =~ s/%s/$sec/g; $ret =~ s/%Z/$tz/g; return $ret; } sub cmd_exec{ $cmd = $_[0]; $ret = ''; if (!open(IN, "cd $htmlpath;./$cmd|")) { &unlock; &error_run_command; } while() {$ret .= $_;} close(IN); $ret =~ s/\n//g; return $ret; } sub dummy_bitmap { @bitmap = ( "47","49","46","38","39","61","08","00","08","00","80","00","00","00","00","00", "FF","FF","FF","21","F9","04","01","00","00","01","00","2C","00","00","00","00", "08","00","08","00","40","02","06","8C","8F","A9","CB","ED","5D","00","3B" ); print "Content-type: image/gif\nPragma: no-cache\n\n"; binmode(STDOUT); foreach (@bitmap) { print pack('C',hex($_)); } } sub error_busy { print <<"EOF" Content-type: image/x-xbitmap #define err_width 96 #define err_height 24 static unsigned char err_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xe3, 0xe7, 0x27, 0xe8, 0xe7, 0x07, 0x3e, 0x82, 0x78, 0x82, 0x00, 0x20, 0x24, 0x20, 0x28, 0x28, 0x20, 0x08, 0x42, 0x82, 0x84, 0x44, 0x00, 0x20, 0x24, 0x20, 0x48, 0x24, 0x20, 0x08, 0x42, 0x82, 0x84, 0x44, 0x00, 0x20, 0x20, 0x20, 0x48, 0x24, 0x20, 0x08, 0x42, 0x82, 0x04, 0x28, 0x00, 0xc0, 0xe3, 0xe7, 0x47, 0xe4, 0xe7, 0x07, 0x7e, 0x82, 0x78, 0x10, 0x00, 0x00, 0x24, 0x20, 0x82, 0x22, 0x20, 0x02, 0x42, 0x82, 0x80, 0x10, 0x00, 0x20, 0x24, 0x20, 0x84, 0x22, 0x20, 0x04, 0x42, 0x82, 0x84, 0x10, 0x00, 0x20, 0x24, 0x20, 0x04, 0x21, 0x20, 0x04, 0x42, 0x44, 0x84, 0x10, 0x00, 0xc0, 0xe3, 0x27, 0x08, 0xe1, 0x27, 0x08, 0x3e, 0x38, 0x78, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; EOF } sub error_open_html { print <<"EOF" Content-type: image/x-xbitmap #define err_width 96 #define err_height 24 static unsigned char err_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x20, 0x84, 0x42, 0x1c, 0x1f, 0x38, 0x9e, 0x2f, 0x04, 0x00, 0x00, 0x10, 0x51, 0x8c, 0x46, 0x22, 0x04, 0x44, 0xa2, 0x60, 0x04, 0x00, 0x00, 0x08, 0x50, 0x94, 0x4a, 0x41, 0x04, 0x82, 0xa2, 0xa0, 0x04, 0x00, 0x00, 0x08, 0x50, 0x94, 0x4a, 0x41, 0x04, 0x82, 0xa2, 0xaf, 0x04, 0x00, 0x00, 0x08, 0x88, 0xa4, 0x52, 0x41, 0x04, 0x82, 0x9e, 0x20, 0x05, 0x00, 0x00, 0x08, 0xf8, 0xa4, 0x52, 0x41, 0x04, 0x82, 0x82, 0x20, 0x05, 0x00, 0x00, 0x10, 0x05, 0xc5, 0x62, 0x22, 0x04, 0x44, 0x82, 0x20, 0x06, 0x00, 0x00, 0xe0, 0x04, 0x85, 0x42, 0x1c, 0x04, 0x38, 0x82, 0x2f, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x7d, 0x41, 0x01, 0xbe, 0x82, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x11, 0x63, 0x01, 0x82, 0x82, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x11, 0x63, 0x01, 0x82, 0x82, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x11, 0x55, 0x01, 0x9e, 0x82, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x11, 0x55, 0x01, 0x82, 0x82, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x11, 0x55, 0x01, 0x82, 0x82, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x11, 0x49, 0x01, 0x82, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x11, 0x49, 0x1f, 0x82, 0xbe, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; EOF } sub error_run_command { print <<"EOF" Content-type: image/x-xbitmap #define err_width 96 #define err_height 24 static unsigned char err_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x20, 0x84, 0x42, 0x1c, 0x1f, 0x3e, 0xa1, 0x10, 0x00, 0x00, 0x00, 0x10, 0x51, 0x8c, 0x46, 0x22, 0x04, 0x42, 0xa1, 0x11, 0x00, 0x00, 0x00, 0x08, 0x50, 0x94, 0x4a, 0x41, 0x04, 0x42, 0xa1, 0x12, 0x00, 0x00, 0x00, 0x08, 0x50, 0x94, 0x4a, 0x41, 0x04, 0x3e, 0xa1, 0x12, 0x00, 0x00, 0x00, 0x08, 0x88, 0xa4, 0x52, 0x41, 0x04, 0x12, 0xa1, 0x14, 0x00, 0x00, 0x00, 0x08, 0xf8, 0xa4, 0x52, 0x41, 0x04, 0x22, 0xa1, 0x14, 0x00, 0x00, 0x00, 0x10, 0x05, 0xc5, 0x62, 0x22, 0x04, 0x22, 0xa1, 0x18, 0x00, 0x00, 0x00, 0xe0, 0x04, 0x85, 0x42, 0x1c, 0x04, 0x42, 0x9e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x3e, 0x1c, 0x1c, 0x1f, 0x84, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x42, 0x22, 0x22, 0x21, 0x8a, 0xb1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x42, 0x41, 0x41, 0x21, 0x8a, 0xb1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x3e, 0x41, 0x01, 0x1f, 0x8a, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x12, 0x41, 0x71, 0x09, 0x91, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x22, 0x41, 0x41, 0x11, 0x9f, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x22, 0x22, 0x22, 0x91, 0xa0, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x42, 0x1c, 0x1c, 0xa1, 0xa0, 0xa4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; EOF }