#!/usr/bin/perl ############################################### # inf18.cgi # V1.0 (2010.8.31) # Copyright(C) CGI-design ############################################### $script = 'inf18.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'); open (OUT,">$opfile") || &error("OPEN ERROR"); print OUT "$pass<>#ffffff,#000000"; close OUT; } ### メイン処理 ### 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/&/&/g; $val =~ s//>/g; $val =~ s/"/"/g; $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,$colors) = split(/<>/,); close IN; ($bg_color,$text_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 "Information\n"; $head = 1; } ### sub main { &header; print "\n"; &dsp; #次の行は著作権表示ですので削除しないで下さい。# print "









CGI-design
\n"; } ### sub dsp { print "\n"; open (IN,"$inffile") || &error("OPEN ERROR"); while () { ($no,$year,$mon,$day,$com,$url) = split(/<>/); $com =~ s/([^=^\"]|^)(https?\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#\%]+)/$1$2<\/a>/g; if ($url) {$com = "$com";} $date = sprintf("$year.%02d.%02d",$mon,$day); print ""; if ($mode eq 'admin') {print "";} print "\n"; } close IN; print "
 $date $com
\n"; } ### sub admin { &header; print "
\n"; $inpass = $in{'pass'}; if ($inpass eq '') { print "



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

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

\n"; if ($in{'set'}) {&setup;} else {&edtin;} print "\n"; } ### 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,$url) = split(/<>/); if ($in{$no}) {last;} } close IN; print "\n"; $com =~ s/
/\r/g; } else { $year = $nowyear; $mon = $nowmon; $day = $nowday; $com = $url = ''; } print "
\n"; 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; $in{'no'} = $no; &edtwrt; } ### sub edtwrt { $newdata = "$in{'no'}<>$in{'year'}<>$in{'mon'}<>$in{'day'}<>$in{'com'}<>$in{'url'}<>\n"; $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 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'});} $colors = $in{'colors'}; $colors =~ s/\0/,/g; open (OUT,">$opfile") || &error("OPEN ERROR"); print OUT "$pass<>$colors"; close OUT; } 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 "
カラーコード
$name[$_]\n"; print "\n"; print "
パスワード変更 (英数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; }