#!/usr/bin/perl ############################################### # inf10.cgi # V2.0 (2005.6.14) # Copyright(C) CGI-design ############################################### require './cgi-lib.pl'; $script = 'inf10.cgi'; $base = './infdata'; #データ格納ディレクトリ $catfile = "$base/cat.txt"; #分類 $cnofile = "$base/cno.txt"; #分類番号 $nofile = "$base/no.txt"; #記事番号 $opfile = "$base/option.txt"; #オプション $cgi_lib'maxdata = 400000; #入力最大容量(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<>情報<><>$base<>$base<><><>#ECF0EC<>#000000<>#CAD8CB<>#5A6D45<>#ffffff<>#5A6D45<>160<>160<>25"; close OUT; chmod(0666,$catfile); chmod(0666,$cnofile); chmod(0666,$nofile); } ### メイン処理 ### &ReadParse; $mode = $in{'mode'}; open(IN,"$opfile") || &error("OPEN ERROR"); ($pass,$title,$home,$savedir,$loaddir,$home_icon,$bg_img,$bg_color,$text_color,$mbg_color,$cat_color,$sub_color,$subbg_color,$max_w,$max_h,$menurate) = split(/<>/,); close IN; if ($menurate == 0) {$menurate = 25;} $catno = $in{'cno'}; if (!$catno) {open(IN,"$catfile") || &error("OPEN ERROR"); ($catno) = split(/<>/,); close IN;} $inffile = "$base/$catno.txt"; if ($mode eq 'menu') {&menu;} elsif ($mode eq 'main') {&main;} elsif ($mode eq 'admin') {&admin;} else {&frame;} print "\n"; exit; ### sub header { print "Content-type: text/html\n\n"; print "\n"; print "$title\n"; $head = 1; } ### sub frame { &header; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; exit; } ### sub menu { &header; print "
\n"; if ($home) { print "
"; if ($home_icon) {print "";} else {print "[HOME]";} print "
\n"; } print "
\n"; open(IN,"$catfile") || &error("OPEN ERROR"); while () { ($cno,$cat) = split(/<>/); print "\n"; } close IN; print "
$cat

\n"; print "
[編集]
\n"; } ### sub main { &header; print "
\n"; open(IN,"$catfile") || &error("OPEN ERROR"); while () { ($cno,$cat) = split(/<>/); if ($cno eq $catno) {last;} } close IN; print "
$cat
\n"; if ($catno) { open(IN,"$inffile") || &error("OPEN ERROR"); while () { ($no,$sub,$com,$side,$img) = split(/<>/); &infdsp; } close IN; } print "
\n"; # 次の行は著作権表示ですので削除しないで下さい。# print "CGI-design\n"; } ### sub infdsp { $com =~ s/([^=^\"]|^)(http\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#\%]+)/$1$2<\/a>/g; if ($sub) {print "
$sub
\n";} print "
\n"; @img = split(/:/,$img); $n = 0; for ($i=0; $i<16; $i+=4) {if ($img[$i]) {$n++;}} if ($n < 3) { if ($side) {&imgdsp(' align=right');} else {&imgdsp(' align=left');} print "$com"; } else { print "$com
\n"; &imgdsp(''); } print "
\n"; } ### sub imgdsp { $j = 0; for ($i=0; $i<16; $i+=4) { if ($img[$i]) { $imgfile = "$loaddir/$no-$j.$img[$i]"; $imgsrc = ""; if ($img[$i+3]) {print "
$imgsrc";} else {print $imgsrc;} } $j++; } } ### 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"; print "

\n"; $wrt = $in{'wrt'}; if ($in{'cat'}) {&catset;} elsif ($in{'set'}) {&setup;} else {&edtin;} } ### sub edtin { if (!$catno) {print "


分類を設定して下さい。\n"; return;} if ($in{'newwrt'}) {&newwrt;} elsif ($in{'edtwrt'}) {&edtwrt;} elsif ($in{'delwrt'}) {&delwrt;} elsif ($in{'sort'}) {&edtsort;} &cat_idx; &in_form; print "
記事を修正、削除する場合は[修正]をクリックして下さい。\n"; $k = 0; $rate = 114 - $menurate; print "\n"; print "\n"; open (IN,"$inffile") || &error("OPEN ERROR"); @data = ; close IN; foreach (@data) { ($no,$sub,$com,$side,$img) = split(/<>/); print "\n"; $k++; } print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "

\n"; &infdsp; print "


\n"; } ### sub cat_idx { $catcols = int(100 / $menurate); $perw = int(100 / $catcols); open (IN,"$catfile") || &error("OPEN ERROR"); @cat = ; close IN; print "\n"; $k = 0; foreach (@cat) { ($cno,$cat) = split(/<>/); if (!$k) {print "";} if ($cno eq $catno) {$bc = ' bgcolor="#ffff00"';} else {$bc = '';} print "\n"; $k++; if ($k == $catcols) {print "\n"; $k = 0;} } if ($k) { for ($k+1 .. $catcols) {print "";} print ""; } print "
\n"; print "\n"; print "\n"; print "\n"; print " $cat

\n"; } ### sub in_form { print "
\n"; print "\n"; print "\n"; print "\n"; if ($in{'edt'}) { open(IN,"$inffile") || &error("OPEN ERROR"); while () { ($no,$sub,$com,$side,$img) = split(/<>/); if ($in{$no}) {last;} } close IN; print "\n"; print "***** 修正・削除 *****
\n"; $com =~ s/
/\r/g; @img = split(/:/,$img); } else { print "***** 新規登録 *****
\n"; $sub=$com=$side=''; @img = (); } print "
\n"; print "\n"; print "\n"; for (0 .. 3) { print "\n"; $chk0=$chk1=''; if ($side) {$chk1 = ' checked';} else {$chk0 = ' checked';} print "\n"; print "
題名

内容
画像",$_+1,"\n"; if ($img[4*$_]) {print " 削除";} } print "
位置左寄せ 右寄せ  (位置は画像が2枚以下の場合に有効)
"; if ($in{'edt'}) { print "\n"; print "
\n"; } else {print "";} print "
\n"; } ### sub edtsort { @new = (); open (IN,"$inffile") || &error("OPEN ERROR"); @data = ; close IN; for (0 .. $#data) {$num{$_} = $in{"num$_"};} foreach (sort {$num{$a} <=> $num{$b}} keys(%num)) {push(@new,$data[$_]);} open (OUT,">$inffile") || &error("OPEN ERROR"); print OUT @new; close OUT; $in{'edt'} = ''; } ### sub newwrt { $in{'com'} =~ s/\r\n|\r|\n/
/g; open (IN,"$nofile") || &error("OPEN ERROR"); $no = ; close IN; $no++; open (OUT,">$nofile") || &error("OPEN ERROR"); print OUT $no; close OUT; $img = ''; for (0 .. 3) { &img("$savedir/$no-$_","img$_"); $img .= "$type:$width:$height:$big:"; } open (OUT,">>$inffile") || &error("OPEN ERROR"); print OUT "$no<>$in{'sub'}<>$in{'com'}<>$in{'side'}<>$img<>\n"; close OUT; } ### sub edtwrt { $in{'com'} =~ s/\r\n|\r|\n/
/g; @new = (); open (IN,"$inffile") || &error("OPEN ERROR"); while () { ($no,$sub,$com,$side,$img) = split(/<>/); if ($no eq $in{'no'}) { @img = split(/:/,$img); $img = ''; for $n (0 .. 3) { if ($in{"del$n"}) { unlink "$savedir/$no-$n.$img[4*$n]"; $img .= "::::"; } else { &img("$savedir/$no-$n","img$n"); if ($type) { if ($type ne $img[4*$n]) {unlink "$savedir/$no-$n.$img[4*$n]";} $img .= "$type:$width:$height:$big:"; } else { $img .= "$img[4*$n]:$img[4*$n+1]:$img[4*$n+2]:$img[4*$n+3]:"; } } } push(@new,"$no<>$in{'sub'}<>$in{'com'}<>$in{'side'}<>$img<>\n"); } else {push(@new,$_);} } close IN; open (OUT,">$inffile") || &error("OPEN ERROR"); print OUT @new; close OUT; } ### sub delwrt { @new = (); open (IN,"$inffile") || &error("OPEN ERROR"); while () { ($no,$sub,$com,$side,$img) = split(/<>/); if ($no eq $in{'no'}) { @img = split(/:/,$img); for (0 .. 3) { $img_type = $img[4*$_]; if ($img_type) {unlink "$savedir/$no-$_.$img_type";} } } else {push(@new,$_);} } close IN; open (OUT,">$inffile") || &error("OPEN ERROR"); print OUT @new; close OUT; } ### sub catset { if ($wrt) { @new = (); %num = (); open (IN,"$catfile") || &error("OPEN ERROR"); @cat = ; close IN; for (0 .. $#cat) {$num{$_} = $in{"num$_"};} foreach (sort {$num{$a} <=> $num{$b}} keys(%num)) { ($cno,$cat) = split(/<>/,$cat[$_]); if ($in{"del$cno"}) { $inffile = "$base/$cno.txt"; open (IN,"$inffile") || &error("OPEN ERROR"); while () { ($no,$sub,$com,$side,$img) = split(/<>/); @img = split(/:/,$img); for (0 .. 3) { $img_type = $img[4*$_]; if ($img_type) {unlink "$savedir/$no-$_.$img_type";} } } close IN; unlink "$inffile"; } else { push(@new,"$cno<>$in{\"cat$cno\"}<>\n"); } } open (OUT,">$catfile") || &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; $inffile = "$base/$cno.txt"; open (OUT,">$inffile") || &error("$inffileファイルを作成できません"); close OUT; chmod(0666,$inffile); 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"; open (IN,"$catfile") || &error("OPEN ERROR"); @cat = ; close IN; $k = 0; foreach (@cat) { ($cno,$cat) = split(/<>/); print "\n"; print "\n"; print "\n"; $k++; } print "
表\示順分類削除
\n"; } ### sub setup { if ($wrt) { if ($in{'newpass'} ne '') {$pass = &crypt($in{'newpass'});} $title = $in{'title'}; $home = $in{'home'}; $savedir = $in{'savedir'}; $loaddir = $in{'loaddir'}; $icon = $in{'icon'}; if ($icon) { &img("$savedir/$icon",'img'); if ($type) {$icontype = "$icon.$type";} else {$icontype = '';} if ($icon eq 'wall') {$bg_img = $icontype;} elsif ($icon eq 'home') {$home_icon = $icontype;} } $bg_color = $in{'color0'}; $text_color = $in{'color1'}; $mbg_color = $in{'color2'}; $cat_color = $in{'color3'}; $sub_color = $in{'color4'}; $subbg_color = $in{'color5'}; $max_w = $in{'max_w'}; $max_h = $in{'max_h'}; $menurate = $in{'menurate'}; open (OUT,">$opfile") || &error("OPEN ERROR"); print OUT "$pass<>$title<>$home<>$savedir<>$loaddir<>$home_icon<>$bg_img<>$bg_color<>$text_color<>$mbg_color<>$cat_color<>$sub_color<>$subbg_color<>$max_w<>$max_h<>$menurate"; 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 = ('壁紙','ホーム'); @data = ($bg_img,$home_icon); @icon = ('wall','home'); print "\n"; print "\n"; @name = ('基本背景色','基本文字色','分類背景色','分類色','題名色','題名背景色'); @data = ($bg_color,$text_color,$mbg_color,$cat_color,$sub_color,$subbg_color); for (0 .. $#name) { print "\n"; } print "\n"; print "\n"; print "\n"; print "
タイトル
ホームURL
画像格納ディレクトリ
画像読出ディレクトリ

壁紙、アイコン
\n"; for (0 .. $#name) { print "$name[$_]"; if ($data[$_]) { if ($_) {$w = '';} else {$w = ' width=30';} print "    "; } else {print "(無)   ";} } print "
カラーコード
$name[$_]\n"; print "\n"; print "
画像表\示横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; }