#!/usr/bin/perl ############################################### # view28.cgi # V2.0 (2004.11.12) # Copyright(C) CGI-design ############################################### require './cgi-lib.pl'; $script = 'view28.cgi'; $base = './viewdata'; #データ格納ディレクトリ $catfile = "$base/cat.txt"; #分類 $cnofile = "$base/cno.txt"; #分類番号 $nofile = "$base/no.txt"; #データ番号 $opfile = "$base/option.txt"; #オプション $cgi_lib'maxdata = 3000000; #入力最大容量(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<>[ I Love Sunset! ]<><><>$base<>$base<><><>#f7eeee<>#764747<>#cc9999<>#764747<>#d1b4b4<>#ffffff<>120<>4"; close OUT; chmod(0666,$catfile); chmod(0666,$cnofile); chmod(0666,$nofile); } ### メイン処理 ### &ReadParse; $mode = $in{'mode'}; open (IN,"$opfile") || &error("OPEN ERROR"); ($pass,$title,$adm_com,$home,$savedir,$loaddir,$bg_img,$home_icon,$bg_color,$text_color,$title_color,$cat_color,$catbg_color,$thbg_color,$img_h,$cols) = split(/<>/,); close IN; if ($cols == 0) {$cols = 4;} $catno = $in{'cno'}; if (!$catno) {open (IN,"$catfile") || &error("OPEN ERROR"); ($catno) = split(/<>/,); close IN;} $viewfile = "$base/$catno.txt"; if ($mode eq 'photo') {&photo;} elsif ($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 "
"; if ($home) {if ($home_icon) {print "";} else {print "[HOME]";}} print "$title
\n"; print "
$adm_com
\n"; $perw = int(100 / $cols); $k = 0; print "\n"; open (IN,"$catfile") || &error("OPEN ERROR"); while () { ($cno,$cat) = split(/<>/); open (INV,"$base/$cno.txt") || &error("OPEN ERROR"); ($no,$img_type) = split(/<>/,); close INV; if (!$k) {print "";} print "\n"; $k++; if ($k == $cols) {print "\n"; $k = 0;} } close IN; if ($k) { for ($k+1 .. $cols) {print "";} print ""; } print "
\n"; print "\n"; print "
$cat
\n"; print "
[編集]
\n"; # 次の行は著作権表示ですので削除しないで下さい。# print "CGI-design\n"; } ### sub photo { &header; print "
\n"; open (IN,"$catfile") || &error("OPEN ERROR"); while () { ($cno,$cat) = split(/<>/); if ($cno eq $catno) {last;} } close IN; $sel = $in{'sel'}; open (IN,"$viewfile") || &error("OPEN ERROR"); @data = ; close IN; ($no,$img_type) = split(/<>/,$data[$sel]); $sum = @data; $next = $sel + 1; print "\n"; print "\n"; print "
[Return]$cat ($next/$sum)
"; if ($next < $sum) {print "";} else {print "";} print "
\n"; } ### 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 ($wrt) {&edtwrt;} &catidx; print "
\n"; print "\n"; print "\n"; print "\n"; print "

\n"; print "
画像

\n"; &dsp; print "
\n"; } ### sub catidx { $perw = int(100 / $cols); print "\n"; $k = 0; open (IN,"$catfile") || &error("OPEN ERROR"); while () { ($cno,$cat) = split(/<>/); if (!$k) {print "";} 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 "\n"; print " $cat

\n"; } ### sub dsp { if (!-e $viewfile) {return;} $perw = int(100 / $cols); $k = 0; print "\n"; open (IN,"$viewfile") || &error("OPEN ERROR"); while () { ($no,$img_type) = split(/<>/); if (!$k) {print "\n";} print "\n"; $k++; if ($k == $cols) {print "\n"; $k = 0;} } close IN; if ($k) { for ($k+1 .. $cols) {print "";} print ""; } print "

\n"; print "削除

\n"; } ### sub edtwrt { @new = (); open (IN,"$viewfile") || &error("OPEN ERROR"); while () { ($no,$img_type) = split(/<>/); if ($in{"del$no"}) {unlink "$savedir/$no.$img_type";} else {push(@new,$_);} } close IN; if ($in{'img'}) { 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'); push(@new,"$no<>$type<>\n"); } open (OUT,">$viewfile") || &error("OPEN ERROR"); print OUT @new; close OUT; } ### sub catset { if ($wrt) { @new = (); open (IN,"$catfile") || &error("OPEN ERROR"); while () { ($cno) = split(/<>/); if ($in{"del$cno"}) { $viewfile = "$base/$cno.txt"; open (INV,"$viewfile") || &error("OPEN ERROR"); while () { ($no,$img_type) = split(/<>/); unlink "$savedir/$no.$img_type"; } close INV; unlink "$viewfile"; } else {push(@new,"$cno<>$in{\"cat$cno\"}<>\n");} } close IN; open (OUT,">$catfile") || &error("OPEN ERROR"); print OUT @new; close OUT; } elsif ($in{'add_cat'}) { open (IN,"$cnofile") || &error("OPEN ERROR"); $cno = ; close IN; $cno++; open (OUT,">$cnofile") || &error("OPEN ERROR"); print OUT $cno; close OUT; $viewfile = "$base/$cno.txt"; open (OUT,">$viewfile") || &error("$viewfileファイルを作成できません"); close OUT; chmod(0666,$viewfile); 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"; $k = 1; open (IN,"$catfile") || &error("OPEN ERROR"); while () { ($cno,$cat) = split(/<>/); print "\n"; print "\n"; $k++; } close IN; print "
No分類名削除
$k
\n"; } ### sub setup { if ($wrt) { if ($in{'newpass'} ne '') {$pass = &crypt($in{'newpass'});} $title = $in{'title'}; $adm_com = $in{'adm_com'}; $adm_com =~ s/\r\n|\r|\n/
/g; $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'}; $title_color = $in{'color2'}; $cat_color = $in{'color3'}; $catbg_color = $in{'color4'}; $thbg_color = $in{'color5'}; $img_h = $in{'img_h'}; $cols = $in{'cols'}; open (OUT,">$opfile") || &error("OPEN ERROR"); print OUT "$pass<>$title<>$adm_com<>$home<>$savedir<>$loaddir<>$bg_img<>$home_icon<>$bg_color<>$text_color<>$title_color<>$cat_color<>$catbg_color<>$thbg_color<>$img_h<>$cols"; close OUT; } print "
\n"; print "\n"; print "\n"; print "\n"; print "

\n"; print "
\n"; print "\n"; $adm_com =~ s/
/\r/g; 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,$title_color,$cat_color,$catbg_color,$thbg_color); for (0 .. $#name) { 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 "
サムネイル表\示px  
パスワード変更 (英数8文字以内)
\n"; } ### sub img { $type=$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); } ### 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; }