#!/usr/bin/perl ############################################### # inf11.cgi # V1.0 (2005.12.17) # Copyright(C) CGI-design ############################################### $script = 'inf11.cgi'; $base = './infdata'; #データ格納ディレクトリ $inffile = "$base/inf.txt"; #記事 $nofile = "$base/no.txt"; #記事番号 $opfile = "$base/option.txt"; open (IN,"$opfile") || &error("OPEN ERROR"); $opdata = ; close IN; if (!$opdata) { $pass = &crypt('cgi'); chmod(0666,$opfile); open (OUT,">$opfile") || &error("OPEN ERROR"); print OUT "$pass<>情報<>280<>#ffffff,#000000,#c00000"; close OUT; chmod(0666,$inffile); chmod(0666,$nofile); } ### メイン処理 ### if ($ENV{'REQUEST_METHOD'} eq "POST") {read(STDIN,$in,$ENV{'CONTENT_LENGTH'});} else {$in = $ENV{'QUERY_STRING'};} %in = (); foreach (split(/&/,$in)) { ($n,$val) = split(/=/); $val =~ tr/+/ /; $val =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $val =~ s/\r\n|\r|\n/
/g; if (defined($in{$n})) {$in{$n} .= "\0$val";} else {$in{$n} = $val;} } $mode = $in{'mode'}; open (IN,"$opfile") || &error("OPEN ERROR"); ($pass,$title,$dspw,$colors) = split(/<>/,); close IN; ($bg_color,$text_color,$title_color) = split(/,/,$colors); if ($mode eq 'admin') {&admin;} else {&main;} print "\n"; exit; ### sub header { print "Content-type: text/html\n\n"; print "\n"; print "$title\n"; $head = 1; } ### sub main { &header; print "\n"; print "
$title
\n"; &dsp; print "
\n"; #次の行は著作権表示ですので削除しないで下さい。# print "\n"; } ### sub dsp { open (IN,"$inffile") || &error("OPEN ERROR"); while () { ($no,$year,$mon,$day,$com) = split(/<>/); $com =~ s/([^=^\"]|^)(http\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#\%]+)/$1$2<\/a>/g; print ""; if ($mode eq 'admin') {print "";} print "
$year.$mon.$day | $com

\n"; } close IN; } ### sub admin { &header; print "
\n"; $inpass = $in{'pass'}; if ($inpass eq '') { print "
[Return]
\n"; print "



パスワードを入力して下さい

\n"; print "
\n"; print "\n"; print "\n"; print "
\n"; print "
\n"; exit; } $mat = &decrypt($inpass,$pass); if (!$mat) {&error("パスワードが違います");} print "\n"; print "
 Return
\n"; print "\n"; print "\n"; print "\n"; print "

\n"; if ($in{'set'}) {&setup;} else {&edtin;} } ### sub edtin { if ($in{'newwrt'}) {&newwrt;} elsif ($in{'edtwrt'}) {&edtwrt;} elsif ($in{'delwrt'}) {&delwrt;} &in_form; print "
修正、削除する場合は「修正」をクリックして下さい。\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "
\n"; &dsp; print "
\n"; } ### sub in_form { ($sec,$min,$hour,$nowday,$nowmon,$nowyear) = localtime; $nowyear += 1900; $nowmon++; print "
\n"; print "\n"; print "\n"; if ($in{'edt'}) { open (IN,"$inffile") || &error("OPEN ERROR"); while () { ($no,$year,$mon,$day,$com) = split(/<>/); if ($in{$no}) {last;} } close IN; print "\n"; $com =~ s/
/\r/g; } else { $year = $nowyear; $mon = $nowmon; $day = $nowday; $com = ''; } print "
\n"; print "\n"; print "\n"; print "
日付 

内容
"; if ($in{'edt'}) { print "\n"; print "
\n"; } else {print "";} print "
\n"; } ### sub newwrt { open (IN,"$nofile") || &error("OPEN ERROR"); $no = ; close IN; $no++; open (OUT,">$nofile") || &error("OPEN ERROR"); print OUT $no; close OUT; $newdata = "$no<>$in{'year'}<>$in{'mon'}<>$in{'day'}<>$in{'com'}<>\n"; &logwrt; } ### sub logwrt { $newdate = sprintf("$in{'year'}%02d%02d",$in{'mon'},$in{'day'}); $flag = 0; @new = (); open (IN,"$inffile") || &error("OPEN ERROR"); while () { ($no,$year,$mon,$day) = split(/<>/); if ($no eq $in{'no'}) {next;} if (!$flag) { $date = sprintf("$year%02d%02d",$mon,$day); if ($date <= $newdate) {push(@new,$newdata); $flag = 1;} } push(@new,$_); } close IN; if (!$flag) {push(@new,$newdata);} open (OUT,">$inffile") || &error("OPEN ERROR"); print OUT @new; close OUT; } ### sub edtwrt { $newdata = "$in{'no'}<>$in{'year'}<>$in{'mon'}<>$in{'day'}<>$in{'com'}<>\n"; &logwrt; } ### sub delwrt { @new = (); open (IN,"$inffile") || &error("OPEN ERROR"); while () { ($no) = split(/<>/); if ($no ne $in{'no'}) {push(@new,$_);} } close IN; open (OUT,">$inffile") || &error("OPEN ERROR"); print OUT @new; close OUT; } ### sub setup { if ($in{'wrt'}) { if ($in{'newpass'} ne '') {$pass = &crypt($in{'newpass'});} $title = $in{'title'}; $dspw = $in{'dspw'}; $colors = $in{'colors'}; $colors =~ s/\0/,/g; open (OUT,">$opfile") || &error("OPEN ERROR"); print OUT "$pass<>$title<>$dspw<>$colors"; close OUT; } print "下記に入力後、「設定する」を押して下さい。\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "

\n"; print "
\n"; print "\n"; print "\n"; @name = ('基本背景色','基本文字色','タイトル色'); @colors = split(/,/,$colors); for (0 .. $#name) { print "\n"; } print "\n"; print "\n"; print "
タイトル
カラーコード
$name[$_]\n"; print "\n"; print "
記事表\示幅px
パスワード変更 (英数8文字以内)
\n"; } ### sub crypt { @salt = ('a' .. 'z','A' .. 'Z','0' .. '9'); srand; $salt = "$salt[int(rand($#salt))]$salt[int(rand($#salt))]"; return crypt($_[0],$salt); } ### sub decrypt { $salt = $_[1] =~ /^\$1\$(.*)\$/ && $1 || substr($_[1],0,2); if (crypt($_[0],$salt) eq $_[1] || crypt($_[0],'$1$' . $salt) eq $_[1]) {return 1;} return 0; } ### sub error { if (!$head) {&header; print "
\n";} print "



ERROR !!

$_[0]\n"; print "
\n"; exit; }