#!C:\Perl\bin\perl.exe ############################################### # view44.cgi # V1.0 (2005.6.21) # Copyright(C) CGI-design ############################################### eval 'use Image::Magick;'; if ($@) {$magick = 0;} else {$magick = 1;} $script = 'view44.cgi'; $base = './viewdata'; #データ格納ディレクトリ $catfile = "$base/cat.txt"; #分類 $cnofile = "$base/cno.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<>Photo Album<><><><><><><>#FAFAEB<>#000000<>#c00000<>#ffffff<>#800000<>150<>150<>5<>20"; close OUT; chmod(0666,$catfile); chmod(0666,$cnofile); } ### メイン処理 ### if ($ENV{'REQUEST_METHOD'} eq "POST") {read(STDIN,$in,$ENV{'CONTENT_LENGTH'});} else {$in = $ENV{'QUERY_STRING'};} foreach (split(/&/,$in)) { ($n,$val) = split(/=/); $val =~ tr/+/ /; $val =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $in{$n} = $val; } $mode = $in{'mode'}; $num = $in{'num'}; open (IN,"$opfile") || &error("OPEN ERROR"); # 2009.12.12まで #($pass,$title,$adm_com,$home,$savedir,$loaddir,$bg_img,$home_icon,$bg_color,$text_color,$title_color,$cat_color,$catbg_color,$max_w,$max_h,$cols,$page) = split(/<>/,); # 2009.12.13から ($pass,$title,$adm_com,$home,$savedir,$loaddir,$bg_img,$home_icon,$bg_color,$text_color,$title_color,$cat_color,$catbg_color,$max_w,$max_h,$cols,$page,$description,$keywords) = split(/<>/,); close IN; if ($cols == 0) {$cols = 5;} if ($page == 0) {$page = 20;} $catno = $in{'cno'}; if (!$catno) {open (IN,"$catfile") || &error("OPEN ERROR"); ($catno) = split(/<>/,); close IN;} $viewfile = "$base/$catno.txt"; if ($mode eq 'thumb') {&thumb;} elsif ($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"; print "\n"; print "\n"; $head = 1; } # 2009.12.31追加 sub adminheader { print "Content-type: text/html\n\n"; print "\n"; # print "$title\n"; print "$title\n"; print "\n"; print "\n"; $head = 1; } # 2009.12.30追加 sub thumbheader { print "Content-type: text/html\n\n"; print "\n"; $xxcat = $cat; $xxcat =~ s/
/ /g; print "$title - $xxcat\n"; print "\n"; print "\n"; $head = 1; } # 2009.12.30追加 sub photoheader { print "Content-type: text/html\n\n"; print "\n"; $xxcat = $cat; $xxcat =~ s/
/ /g; print "$title - $xxcat - $file\n"; print "\n"; print "\n"; $head = 1; } ### sub main { &header; print "
\n"; print "
"; # if ($home) {if ($home_icon) {print "";} else {print "[HOME]";}} # タイトルに H1タグ を使う print "

$title

flickrへ
\n"; # print "$title\n"; # 概要に H2タグ を使う print "

$adm_com

\n"; $perw = int(100 / $cols); $k = 0; if ($magick) {$is = 's-';} else {$is = '';} print "\n"; open (IN,"$catfile") || &error("OPEN ERROR"); while () { ($cno,$dir,$cat) = split(/<>/); open (INV,"$base/$cno.txt") || &error("OPEN ERROR"); ($file,$img_w,$img_h) = split(/<>/,); close INV; if (!$k) {print "\n";} #修正 valign=middle × # print "\n"; #オリジナル 2009.12.12まで # print "\n"; # 2009.12.12 画像にALTとTITLEを入れる # print "\n"; # 2009.12.30 画像にALTとTITLEを入れる $xxfile = $file; $xxfile =~ s/-/ /g; $xxfile =~ s/.jpg//g; $xxcat = $cat; $xxcat =~ s/
/ /g; print "\n"; $k++; if ($k == $cols) {print "\n"; $k = 0;} } close IN; if ($k) { for ($k+1 .. $cols) {print "";} print ""; } print "

$cat

$cat
\"$is$file
$cat
\"$xxfile
$cat
\n"; print "
[編集]
\n"; # print "ホーム・ページ
\n"; # print "ホーム・ページ
\n"; if ($home) {if ($home_icon) {print "";} else {print "ホーム・ページ

";}} # 次の行は著作権表示ですので削除しないで下さい。# print "
CGI-design
\n"; } ### sub thumb { # 2009.12.30 &catread; &thumbheader; print "

\n"; # 2009.12.30 # &catread; print "\n"; print "
 [戻る]$cat
\n"; print "
$com
\n"; &dsp; if ($m < $page) {return;} print "\n"; $i = 1; for ($k=0; $k<=$m; $k+=$page) { if ($k == $num) {print "\n";} else {print "\n";} $i++; } print "
Page$iPage$i

\n"; } ### sub catread { open (IN,"$catfile") || &error("OPEN ERROR"); while () { ($cno,$dir,$cat,$com) = split(/<>/); if ($cno eq $catno) {last;} } close IN; } ### sub dsp { if (!-e $viewfile) {return;} $next = $num + $page; $perw = int(100 / $cols); $k = 0; $m = -1; #2009.11.15変更 # print "\n"; #オリジナル print "
\n"; if ($mode eq 'admin') {$tar = ' target="_blank"';} else {$tar = '';} if ($magick) {$is = 's-';} else {$is = '';} open (IN,"$viewfile") || &error("OPEN ERROR"); while () { $m++; if ($m < $num || $next <= $m) {next;} ($file,$img_w,$img_h) = split(/<>/); if (!$k) {print "\n";} #2009.11.15追加 if ($max_w < $max_h) {$whsize = $max_h;} else {$whsize = $max_w;} #2009.11.15変更 print "\n"; $k++; if ($k == $cols) {print "\n"; $k = 0;} } close IN; if ($k) { for ($k+1 .. $cols) {print "";} print ""; } print "
\n"; #オリジナル # print "\n"; if ($mode eq 'admin') { if ($magick && !-e "$savedir$dir/s-$file") {print "
$file


";} else {print "\n";} print "
削除"; } else { # 2009.12.12まで # print "\n"; # 2009.12.13から # print "\"$title\n"; # 2009.12.30から $xxfile = $file; $xxfile =~ s/-/ /g; $xxfile =~ s/.jpg//g; $xxcat = $cat; $xxcat =~ s/
/ /g; print "\"$title\n"; } print "

\n"; } ### sub photo { # 2009.12.30 # &header; # 2009.12.30 # print "
\n"; &catread; $sel = $in{'sel'}; open (IN,"$viewfile") || &error("OPEN ERROR"); @data = ; close IN; ($file) = split(/<>/,$data[$sel]); # 2009.12.30 &photoheader; # 2009.12.30 print "
\n"; $sum = @data; $next = $sel + 1; $back = $sel - 1; ################################ ################################ ################################ ################################ ################################ ################################ # 2009.12.30まで # if ($next < $sum) {$nidx = "$script?mode=photo&cno=$catno&sel=$next&num=$num";} else {$nidx = $script;} # 2009.12.30まで # if (0 <= $back) {$bidx = "$script?mode=photo&cno=$catno&sel=$back&num=$num";} else {$bidx = $script?mode=thumb&cno=$catno&num=$num;} # 2009.12.30から if ($next < $sum) {$nidx = "$script?mode=photo&cno=$catno&sel=$next&num=$num";} else {$nidx = "$script?mode=thumb&cno=$catno&num=$num";} # 2009.12.30から if (0 <= $back) {$bidx = "$script?mode=photo&cno=$catno&sel=$back&num=$num";} else {$bidx = "$script?mode=thumb&cno=$catno&num=$num";} # 2012.11.02から print "
\n"; print "
\n"; # 2009.12.30から print "\n"; print "\n"; ################################ ################################ ################################ ################################ ################################ ################################ # print "
 [一覧に戻る][前へ]   $next/$sum   [次へ]
\n"; # 2009.12.12まで # if (-f "$loaddir$dir/f-$file") { # print "\n";} # else {print "\n";} # 2009.12.13から if (-f "$loaddir$dir/f-$file") { print "\"$title\n";} else {print "\"$title\n";} } ### sub admin { &adminheader; 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 { &catread; if ($wrt) {&edtwrt;} elsif ($in{'edt'}) {&thgen;} &catidx; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "上記の分類名をクリックし、「更新する」を押して下さい。

\n"; print "

\n"; &dsp; print "
\n"; if ($m < $page) {return;} print "\n"; $i = 1; for ($k=0; $k<=$m; $k+=$page) { if ($k == $num) {print "\n";} else { print "\n"; } $i++; } print "
Page$i
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "

\n"; } ### sub catidx { $perw = int(100 / $cols); print "\n"; $k = 0; open (IN,"$catfile") || &error("OPEN ERROR"); while () { ($cno,$d,$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 edtwrt { $m = 0; open (IN,"$viewfile") || &error("OPEN ERROR"); while () { if ($in{"del$m"}) { ($file) = split(/<>/); unlink "$savedir$dir/$file"; if ($magick && -e "$savedir$dir/s-$file") {unlink "$savedir$dir/s-$file";} } $m++; } close IN; @new = (); opendir (PHOTO,"$savedir$dir") || &error("OPEN DIR ERROR"); while ($file = readdir PHOTO) { # print $file; # if (- $file) {print $file; # next;} # if ($file eq '.' || $file eq '..' || $file =~ /^s-/) {next;} if ($file eq '.' || $file eq '..' || $file =~ /^s-/ || $file =~ /^f-/) {next;} # if ($file eq '.' || $file eq '..' || $file =~ /^s-/ || $file =~ /^f-/ || -d "$file" || $file eq 'Thumbs.db') {next;} # if ($file eq '.' || $file eq '..' || $file =~ /^s-/ || $file =~ /^f-/ || -d $file) {next;} &img("$savedir$dir/$file"); push(@new,"$file<>$width<>$height<>\n"); } closedir PHOTO; open (OUT,">$viewfile") || &error("OPEN ERROR"); print OUT @new; close OUT; } ### sub thgen { $m = 0; open (IN,"$viewfile") || &error("OPEN ERROR"); while () { if ($in{"th$m"}) { ($file,$img_w,$img_h) = split(/<>/); last; } $m++; } close IN; $im = Image::Magick->new; $im->Read("$savedir$dir/$file"); $im->Scale(width=>$img_w,height=>$img_h); $im->Write("$savedir$dir/s-$file"); chmod (0666,"$savedir$dir/s-$file"); } ### 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,$dir) = split(/<>/,$cat[$_]); if ($in{"del$cno"}) { $viewfile = "$base/$cno.txt"; open (IN,"$viewfile") || &error("OPEN ERROR"); while () { ($file) = split(/<>/); unlink "$savedir$dir/$file"; if ($magick && -e "$savedir$dir/s-$file") {unlink "$savedir$dir/s-$file";} } close IN; unlink "$viewfile"; rmdir "$savedir$dir"; } else { $com = $in{"com$cno"}; $com =~ s/\r\n|\r|\n/
/g; $dir = $in{"dir$cno"}; if (!$dir) {&error("Dirを入力して下さい");} if (!-e "$savedir$dir") {&error("$savedir$dirが存在しません");} push(@new,"$cno<>$dir<>$in{\"cat$cno\"}<>$com<>\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; $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"; open (IN,"$catfile") || &error("OPEN ERROR"); @cat = ; close IN; $k = 0; foreach (@cat) { ($cno,$dir,$cat,$com) = split(/<>/); $com =~ s/
/\r/g; print "
\n"; print "\n"; print "\n"; print "\n"; $k++; } print "
表\示順分類名、画像ディレクトリコメント削除
分類
Dir 
\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'}; $bg_img = $in{'bg_img'}; $home_icon = $in{'home_icon'}; $bg_color = $in{'color0'}; $text_color = $in{'color1'}; $title_color = $in{'color2'}; $cat_color = $in{'color3'}; $catbg_color = $in{'color4'}; $max_w = $in{'max_w'}; $max_h = $in{'max_h'}; $cols = $in{'cols'}; $page = $in{'page'}; 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<>$max_w<>$max_h<>$cols<>$page<>$description<>$keywords"; close OUT; } print "
\n"; print "\n"; print "\n"; print "\n"; print "

\n"; print "
\n"; print "\n"; # 2009.12.13 DESCRIPTION 追加 # print "\n"; # 2010.01.01変更 print "\n"; # 2009.12.13 KEYWORDS 追加 # print "\n"; # 2010.01.01変更 print "\n"; $adm_com =~ s/
/\r/g; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; @name = ('基本背景色','基本文字色','タイトル','分類名','分類名背景色'); @data = ($bg_color,$text_color,$title_color,$cat_color,$catbg_color); for (0 .. $#name) { print "\n"; } print "\n"; print "\n"; print "
タイトル
DESCRIPTION

DESCRIPTION
KEYWORDS

KEYWORDS

コメント
ホームURL
画像格納ディレクトリ
画像読出ディレクトリ
壁紙
ホームアイコン
カラーコード
$name[$_]\n"; print "\n"; print "
サムネイル表\示横maxpx 縦maxpx\n"; print "  列 枚/ページ
パスワード変更 (英数8文字以内)
\n"; } ### sub img { ($t,$width,$height) = &getImageSize("$_[0]"); 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; }