#!/usr/bin/perl ############################################### # voice.cgi # V1.0 (2008.1.15) # Copyright(C) CGI-design ############################################### require './cgi-lib.pl'; $script = 'voice.cgi'; $base = './voicedata'; #データ格納ディレクトリ $voicefile = "$base/voice.txt"; #記事 $nofile = "$base/no.txt"; #記事番号 $catfile = "$base/cat.txt"; #分類 $cnofile = "$base/cno.txt"; #分類番号 $opfile = "$base/option.txt"; $cgi_lib'maxdata = 200000; #入力最大容量(byte) 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<>./temp.html<>$base<>$base<>#ffffff,#000000,#C48E74,#ffffee,#C48E74,#ffffee,#FF6600<>4<>20<>500<>160<>160"; close OUT; chmod(0666,$voicefile); chmod(0666,$nofile); chmod(0666,$catfile); chmod(0666,$cnofile); } ### メイン処理 ### &ReadParse; while (($n,$val) = each %in) { if ($n eq 'img') {next;} $val =~ s/&/&/g; $val =~ s//>/g; $val =~ s/"/"/g; $val =~ s/\r\n|\r|\n/
/g; $in{$n} = $val; } $mode = $in{'mode'}; $catno = $in{'cno'}; $num = $in{'num'}; open (IN,"$opfile") || &error("OPEN ERROR"); ($pass,$tempfile,$savedir,$loaddir,$colors,$cols,$page,$dspw,$max_w,$max_h) = split(/<>/,); close IN; ($bg_color,$text_color,$frame_color,$catbg_color,$sub_color,$combg_color,$vol_color) = split(/,/,$colors); if ($cols == 0) {$cols = 4;} if ($page == 0) {$page = 20;} $perw = int(100 / $cols); $back = $num - $page; $next = $num + $page; if ($mode eq 'top') {⊤} elsif ($mode eq 'admin') {&admin;} else {&main;} exit; ### sub header { print "Content-type: text/html\n\n"; print "\n"; print "お客様の声\n"; $head = 1; } ### sub top { &header; print "\n"; $m = -1; @data = (); open (IN,"$voicefile") || &error("OPEN ERROR"); while () { $m++; if ($m < $num || $next <= $m) {next;} push(@data,$_); } close IN; print "現在のコメント ",$m+1,"件\n"; print "\n"; foreach (@data) { ($no,$cno,$imgt,$imgw,$imgh,$imgb,$year,$mon,$day,$sub) = split(/<>/); print "\n"; } print "
$mon/$day$sub
\n"; if (0 <= $back) {print " ";} if ($next <= $m) {print "";} print "\n"; } ### sub main { if (!$mode && $catno) {&detcatf; return;} $htmp = $ftmp = ''; $flag = 0; open (IN,"$tempfile") || &error("OPEN ERROR"); while () { if (//) {$flag = 1;} elsif (!$flag) {$htmp .= $_;} else {$ftmp .= $_;} } close IN; print "Content-type: text/html\n\n"; print $htmp; $head = 1; &idx; if ($mode eq 'detail') {&detail;} elsif ($mode eq 'detcat') {&detcat;} else {&list;} print $ftmp; } ### sub list { $m = -1; print "\n"; open (IN,"$voicefile") || &error("OPEN ERROR"); while () { ($no,$cno,$imgt,$imgw,$imgh,$imgb,$year,$mon,$day,$sub,$com) = split(/<>/); $m++; if ($m < $num) {next;} if ($next <= $m) {last;} print "\n"; print "\n"; } close IN; print "
$year年$mon月$day日$sub [ $cat{$cno} ]

\n"; if (0 <= $back) {print "  ";} if ($next <= $m) {print "";} } ### sub idx { print "\n"; $k = 0; %cat = (); open (IN,"$catfile") || &error("OPEN ERROR"); while () { ($cno,$cat) = split(/<>/); $cat{$cno} = $cat; if (!$k) {print "";} print "\n"; $k++; if ($k == $cols) {print "\n"; $k = 0;} } close IN; if ($k) { for ($k+1 .. $cols) {print "";} print ""; } print "
$cat

\n"; } ### sub detail { open (IN,"$voicefile") || &error("OPEN ERROR"); while () { ($no,$cno,$imgt,$imgw,$imgh,$imgb,$year,$mon,$day,$sub,$com) = split(/<>/); if ($no eq $in{'no'}) {last;} } close IN; &dsp; print "
→戻る
\n"; } ### sub dsp { print "
■$sub"; if ($mode eq 'admin') {print "";} print "
\n"; $com =~ s/([^=^\"]|^)(http\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#\%]+)/$1$2<\/a>/g; print "
\n"; if ($imgt) { $imgfile = "$loaddir/$no.$imgt"; $imgsrc = ""; if ($imgb) {print "$imgsrc";} else {print $imgsrc;} } print "$com
\n"; print "
\n"; } ### sub detcat { print "
$cat{$catno}

\n"; &detdsp; if (0 <= $back) {print "
  ";} if ($next <= $m) {print "";} } ### sub detdsp { $m = -1; open (IN,"$voicefile") || &error("OPEN ERROR"); while () { ($no,$cno,$imgt,$imgw,$imgh,$imgb,$year,$mon,$day,$sub,$com) = split(/<>/); if ($cno ne $catno) {next;} $m++; if ($m < $num) {next;} if ($next <= $m) {last;} &dsp; } close IN; } ### sub detcatf { &header; print "
\n"; &detdsp; if (0 <= $back) {print "  ";} if ($next <= $m) {print "";} print "
\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"; print "

\n"; $wrt = $in{'wrt'}; if ($in{'cat'}) {&catset;} elsif ($in{'set'}) {&setup;} else {®in;} print "\n"; } ### sub regin { if ($in{'newwrt'}) {&newwrt;} elsif ($in{'edtwrt'}) {&edtwrt;} elsif ($in{'delwrt'}) {&delwrt;} if (!$catno) {open (IN,"$catfile") || &error("OPEN ERROR"); ($catno) = split(/<>/,); close IN;} &in_form; print "
修正、削除する場合は「修正」をクリックして下さい。

\n"; print "\n"; $k = 0; open (IN,"$catfile") || &error("OPEN ERROR"); while () { ($cno,$cat) = split(/<>/); if (!$k) {print "";} print "\n"; if ($cno eq $catno) {print "\n"; $k++; if ($k == $cols) {print "\n"; $k = 0;} } close IN; if ($k) { for ($k+1 .. $cols) {print "";} print ""; } print "
";} else {print "";} print "\n"; print "\n"; print "\n"; print "$cat
\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; &detdsp; print "
\n"; print ""; if (0 <= $back) { print "\n"; } if ($next <= $m) { print "\n"; } print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; } ### sub in_form { print "
\n"; print "\n"; print "\n"; if ($in{'edt'}) { open (IN,"$voicefile") || &error("OPEN ERROR"); while () { ($no,$cno,$imgt,$imgw,$imgh,$imgb,$year,$mon,$day,$sub,$com) = split(/<>/); if ($in{$no}) {last;} } close IN; print "\n"; $com =~ s/
/\r/g; } else { $cno = $catno; $sub = $com = ''; } print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
分類 \n"; $k = 0; open (IN,"$catfile") || &error("OPEN ERROR"); while () { ($cn,$cat) = split(/<>/); if (!$k) {print "";} if ($cn eq $cno) {$chk = ' checked';} else {$chk = '';} print "\n"; $k++; if ($k == $cols) {print "\n"; $k = 0;} } close IN; if ($k) {print "";} print "
$cat
題名

内容
画像
"; if ($in{'edt'}) { print "\n"; print "
\n"; } else { print ""; } print "
\n"; } ### sub newwrt { $in{'com'} =~ s/\r\n|\r|\n/
/g; ($sec,$min,$hour,$day,$mon,$year) = localtime; $year += 1900; $mon++; open (IN,"$nofile") || &error("OPEN ERROR"); $no = ; close IN; $no++; open (OUT,">$nofile") || &error("OPEN ERROR"); print OUT $no; close OUT; &img("$savedir/$no",'img'); open (IN,"$voicefile") || &error("OPEN ERROR"); @new = ; close IN; unshift(@new,"$no<>$catno<>$type<>$width<>$height<>$big<>$year<>$mon<>$day<>$in{'sub'}<>$in{'com'}<>\n"); open (OUT,">$voicefile") || &error("OPEN ERROR"); print OUT @new; close OUT; } ### sub edtwrt { $in{'com'} =~ s/\r\n|\r|\n/
/g; &img("$savedir/$in{'no'}",'img'); @new = (); open (IN,"$voicefile") || &error("OPEN ERROR"); while () { ($no,$cno,$imgt,$imgw,$imgh,$imgb,$year,$mon,$day) = split(/<>/); if ($no eq $in{'no'}) { if ($type) {$imgt = $type; $imgw = $width; $imgh = $height; $imgb = $big;} push(@new,"$no<>$catno<>$imgt<>$imgw<>$imgh<>$imgb<>$year<>$mon<>$day<>$in{'sub'}<>$in{'com'}<>\n"); } else {push(@new,$_);} } close IN; open (OUT,">$voicefile") || &error("OPEN ERROR"); print OUT @new; close OUT; } ### sub delwrt { @new = (); open (IN,"$voicefile") || &error("OPEN ERROR"); while () { ($no,$cno,$imgt) = split(/<>/); if ($no eq $in{'no'}) {if ($imgt) {unlink "$savedir/$no.$imgt";}} else {push(@new,$_);} } close IN; open (OUT,">$voicefile") || &error("OPEN ERROR"); print OUT @new; close OUT; } ### sub catset { if ($wrt) { @new = (); %num = (); $delflag = 0; open (IN,"$catfile") || &error("OPEN ERROR"); @cat = ; close IN; for (0 .. $#cat) {$num{$_} = $in{"num$_"};} foreach (sort {$num{$a} <=> $num{$b}} keys(%num)) { ($cno) = split(/<>/,$cat[$_]); if ($in{"del$cno"}) {$delflag = 1;} else {push(@new,"$cno<>$in{\"cat$cno\"}<>\n");} } open (OUT,">$catfile") || &error("OPEN ERROR"); print OUT @new; close OUT; if ($delflag) { @new = (); open (IN,"$voicefile") || &error("OPEN ERROR"); while () { ($no,$cno,$imgt) = split(/<>/); if ($in{"del$cno"}) {if ($imgt) {unlink "$savedir/$no.$imgt";}} else {push(@new,$_);} } close IN; open (OUT,">$voicefile") || &error("OPEN ERROR"); print OUT @new; close OUT; } } elsif ($in{'add'}) { open (IN,"$cnofile") || &error("OPEN ERROR"); $cno = ; close IN; $cno++; open (OUT,">$cnofile") || &error("OPEN ERROR"); print OUT $cno; close OUT; open (OUT,">>$catfile") || &error("OPEN ERROR"); print OUT "$cno<><>\n"; close OUT; } print "分類を削除すると、その分類に属する全ての記事を削除します。

\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print " 

\n"; print "\n"; print "\n"; $k = 0; open (IN,"$catfile") || &error("OPEN ERROR"); while () { ($cno,$cat) = split(/<>/); print "\n"; print "\n"; print "\n"; $k++; } close IN; print "
表\示順分類番号分類削除
$cno
\n"; } ### sub setup { if ($wrt) { if ($in{'newpass'} ne '') {$pass = &crypt($in{'newpass'});} $tempfile = $in{'tempfile'}; $savedir = $in{'savedir'}; $loaddir = $in{'loaddir'}; $colors = $in{'colors'}; $colors =~ s/\0/,/g; $cols = $in{'cols'}; $page = $in{'page'}; $dspw = $in{'dspw'}; $max_w = $in{'max_w'}; $max_h = $in{'max_h'}; open (OUT,">$opfile") || &error("OPEN ERROR"); print OUT "$pass<>$tempfile<>$savedir<>$loaddir<>$colors<>$cols<>$page<>$dspw<>$max_w<>$max_h"; close OUT; } print "下記に入力後、「設定する」を押して下さい。

\n"; print "
\n"; 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 "\n"; print "\n"; print "
テンプレートファイル
画像格納ディレクトリ
画像読出ディレクトリ
カラーコード
$name[$_]\n"; print "\n"; print "
分類表\示
記事表\示件/ページ  表\示幅(管理画面)px
画像表\示横maxpx  縦maxpx (設定変更後の画像入力から有効)
パスワード変更 (英数8文字以内)
\n"; } ### sub img { $type=$width=$height=$big=$mac=''; $imgdata = $in{"$_[1]"}; if (!$imgdata) {return;} foreach (@in) { if (/$_[1]/ and /Content-Type:(.+)/i) { if ($1 =~ /image\/.*jpeg/i) {$type = 'jpg';} elsif ($1 =~ /image\/gif/i) {$type = 'gif';} elsif ($1 =~ /image\/.*png/i) {$type = 'png';} } if (/application\/x-macbinary/i) {$mac = 1;} } if (!$type) {&error("このファイルはアップロードできません");} if ($mac) { $leng = substr($imgdata,83,4); $leng = unpack("%N",$leng); $imgdata = substr($imgdata,128,$leng); } $img_file = "$_[0].$type"; open (IMG,">$img_file") || &error("$img_fileファイルを作成できません"); binmode IMG; print IMG $imgdata; close IMG; chmod (0666,$img_file); ($t,$width,$height) = &getImageSize("$img_file"); if (!$width || !$height) {&error("ファイルを認識できません");} $big = 0; if ($max_w && $max_w < $width) {$rate_w = $max_w / $width; $big = 1;} else {$rate_w = 1;} if ($max_h && $max_h < $height) {$rate_h = $max_h / $height; $big = 1;} else {$rate_h = 1;} if ($big) { if ($rate_w < $rate_h) {$rate = $rate_w;} else {$rate = $rate_h;} $width = int($width * $rate); $height = int($height * $rate); } } #========================================= # Get Image Pixel Size.(出典:stdio-902) #========================================= sub getImageSize { local($file_name) = @_; local($head); return if (!open IMG, $file_name); binmode IMG; read IMG, $head, 8; if ($head eq "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a") { local($width, $height); if (read(IMG, $head, 4) != 4 || read(IMG, $head, 4) != 4 || $head ne 'IHDR') { close IMG; return "PNG", 0; } read IMG, $head, 8; close IMG; $width = unpack "N", substr($head, 0, 4); $height = unpack "N", substr($head, 4, 4); return "PNG", $width, $height; } $head = substr $head, 0, 3; if ($head eq "\x47\x49\x46") { local($head, $width, $height); seek IMG, 6, 0; read IMG, $head, 4; close IMG; ($width, $height) = unpack "vv", $head; return "GIF", $width, $height; } $head = substr $head, 0, 2; if ($head eq "\xff\xd8") { local($head, $width, $height, $w1, $w2, $h1, $h2, $l1, $l2, $length); seek IMG, 2, 0; while (read IMG, $head, 1) { last if ($head eq ""); if ($head eq "\xff") { $head = getc IMG; if ($head =~ /^[\xc0-\xc3\xc5-\xcf]$/) { seek IMG, 3, 1; last if (read(IMG, $head, 4) != 4); close IMG; ($h1, $h2, $w1, $w2) = unpack "C4", $head; $height = $h1 * 256 + $h2; $width = $w1 * 256 + $w2; return "JPG", $width, $height; } elsif ($head eq "\xd9" || $head eq "\xda") { last; } else { last if (read(IMG, $head, 2) != 2); ($l1, $l2) = unpack "CC", $head; $length = $l1 * 256 + $l2; seek IMG, $length - 2, 1; } } } close IMG; return "JPG", 0; } return 0; } ### 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; }