#! /usr/bin/perl # # album2.cgi # 写真タイトルのリストとそれぞれをコメント付きで表示。 # # 2.022 : 12/27/08 : ディレクトリ指定のリンクエラーを修正 # 2.021 : 12/21/08 : 簡易モードにディレクトリ指定のオプションを追加 # 2.020 : 1/7/08 : 画像クリックによるリンクエラーを修正 # 2.019 : 12/29/06 : head_insert_enを修正 # 2.018 : 2/18/06 : 戻るリンク名のオプションを追加 # 2.017 : 10/2/05 : Copyrightにリンクを追加 # 2.016 : 9/7/05 : cryptを修正 # 2.015 : 8/15/05 : 簡易モード、リストファイル処理を若干修正 # 2.014 : 8/12/05 : 簡易モードを追加 # 2.013 : 7/31/05 : リストファイルなしでもデフォルトでCGI起動するように変更 # 2.012 : 7/24/05 : 写真をクリックすると次の写真を表示するよう変更 # 2.011 : 2/21/05 : 管理用セットアップのパスワード認証でまれにミスするバグを修正 # 2.01 : 1/22/05 : 次の写真が無い時にプリロードをしないように修正 # 2.0 : 5/27/04 : Created # # $Id: album2.cgi,v 1.30 2008/12/26 18:51:19 Hideki Kanayama Exp $ # Copyright(c) 2004-2008 Hideki Kanayama All rights reserved use CGI::Carp qw(fatalsToBrowser); my $cgilib_en = 1 if (-e "cgi-lib.pl"); require "cgi-lib.pl" if ($cgilib_en); $setupfile = "album_setup.pl"; $admindat="albumadmin.txt"; # このスクリプト名 $script = "album2.cgi"; $version='2.022'; $reservedyear='2004-2008'; $lang = 0; #### 環境設定 ここから ############## # 画像があるディレクトリ(album2.cgiからみた相対パス)、httpからの指定でも可 $imagedir = "."; # アルバムのリストファイル。写真のファイル名、タイトル、コメントをこの中に書く $file = "album.lst"; # 戻り先のリンク。 (album2.cgiから見た相対パスとファイル名、絶対パス、httpからの指定でも可) $back = "../.."; $backname = "戻る"; # アルバムタイトルの設定 $title='サンプルアルバム'; $title_color="#000000"; $title_size='+2'; $title_face=''; # メニューの位置 1:左 0:右 $menu_locate=0; # メニューテキストエリアのサイズ $menu_height=18; # background $bgimage_en=0; $bgcolor="#ffffff"; $bgimagefile=""; #スタイルシート 1:on 0:off $style_sheet_en = 0; $style_sheet = ' A:link {text-decoration: none} A:visited {text-decoration: none} A:active {text-decoration: none} '; #〜内に挿入できる構文 1:on, 0:off $head_insert_en = 0; $head_insert = ''; #### 環境設定 ここまで ############## require "$setupfile" if (-e "$setupfile"); if ($cgilib_en == 0){ &miniparse; } else { $parse_admin = ' &ReadParse; %in=&mbdecode(%in); if (! -e "$admindat"){ if ($in{mode} eq \'adminpwd\'){ &wradminpwd; } else { &setadminpwd; } }'; eval $parse_admin; } if ($bgimage_en == 1){ $bgimage = "background=\"$bgimagefile\""; } else { $bgimage = "bgcolor=\"$bgcolor\""; } if ($in{mode} eq 'setup'){ if ($cgilib_en == 1){ &setadminpwd; } else { &error("cgi-lib.plがありません。"); } } elsif ($in{mode} eq 'setupform'){ &setupform; } elsif ($in{mode} eq 'makesetup'){ &makesetup; } else { &dispphoto; } exit; sub dispphoto { $imagedir = $in{dir} ? $in{dir} : $imagedir; if (!open(FILE,"< $file")){ opendir(IMGDIR,"$imagedir") or &error("ディレクトリ$imagedirが開けません"); @filelist = grep !/^\./, readdir IMGDIR; closedir(IMGDIR); @newlist = ( grep /\.jpe?g$/i, @filelist); @newlist = (@newlist, grep /\.gif$/i, @filelist); @newlist = (@newlist, grep /\.png$/i, @filelist); @newlist = (@newlist, grep /\.bmp$/i, @filelist); @newlist = (@newlist, grep /\.tiff?$/i, @filelist); @newlist = (@newlist, grep /\.ief$/i, @filelist); @newlist = (@newlist, grep /\.cgm$/i, @filelist); @newlist = (@newlist, grep /\.pcx$/i, @filelist); @filelist = sort @newlist; &error("画像ファイルが$imagedirにありません。") if ($#filelist == -1); if ($in{image} eq ''){ $image = $filelist[0]; $previmage = ''; $nextimage = $filelist[1]; } else { $image = $in{image}; my $hitnum; foreach (@filelist){ last if (/^$in{image}$/); $hitnum++; } $previmage = $filelist[$hitnum-1] unless ($hitnum == 0); $nextimage = $filelist[$hitnum+1] unless ($hitnum >= $#filelist); } $title = $image; } else { @filelist = ; chomp(@filelist); @filelist = grep !/^\s*$/, @filelist; @filelist = grep !/^\s*,/, @filelist; @filelist = grep !/^\s*#/, @filelist; if ($in{image} eq '') { $line = $filelist[0]; ($image,$title,$comment)=split(/,/,$line); $line = $filelist[1]; ($nextimage,$nexttitle,$nextcomment)=split(/,/,$line); } else { my $i=0; foreach (@filelist){ ($image,$title,$comment)=split(/,/); if ($image eq $in{image}){ ($nextimage,$nexttitle,$nextcomment)=split(/,/,$filelist[$i+1]); ($previmage,$prevtitle,$prevcomment)=split(/,/,$filelist[$i-1]) unless ($i == 0); last; } $i++; } } close(FILE); } $title = $image if ($title eq ''); $nexttitle = $nextimage if ($nexttitle eq ''); $prevtitle = $previmage if ($prevtitle eq ''); print "Content-Type: text/html\n\n"; print < $title END_HEAD1 if ($head_insert_en == 1){ print "$head_insert"; } if ($style_sheet_en == 1){ print "\n"; } print "\n"; $flag = 0; foreach (@filelist){ ($photoimage,$phototitle,$photocomment)=split(/,/); if ($flag == 1) {$nextimage = $photoimage;last;} if ($image eq $photoimage){$flag = 1;} } print "\n"; print "
$title

\n"; print "

$backname

\n" if ($cgilib_en != 0); print "\n"; print "\n"; if ($menu_locate == 0){ print "\n"; print "\n"; } else { print "\n"; print "\n"; } print "\n"; print "\n"; if ($menu_locate == 1){ &listform; } if ($nextimage ne ''){ if ($in{dir} ne '') { $nextlink1 = ""; } else { $nextlink1 = ""; } $nextlink2 = ""; } else { $nextlink1 = ''; $nextlink2 = ''; } print "\n"; if ($menu_locate == 0){ &listform; } print "\n"; print "
$comment  $comment
$nextlink1$nextlink2
\n"; if ($previmage eq '') { $prevlink="$back"; $prevtitle = "$backname"; $noleft_toplink = 1 if ($cgilib_en == 0); } else { if ($in{dir} ne ''){ $prevlink = "$script?image=$previmage&dir=$in{dir}"; } else { $prevlink = "$script?image=$previmage"; } } if ($nextimage eq '') { $nextlink="$back"; $nexttitle = "$backname"; $noright_toplink = 1 if ($cgilib_en == 0); } else { if ($in{dir} ne ''){ $nextlink = "$script?image=$nextimage&dir=$in{dir}"; } else { $nextlink = "$script?image=$nextimage"; } } print < BOTTOM print qq{}; print qq{←$prevtitle} if ($noleft_toplink == 0); print qq{\n}; print qq{}; print qq{$nexttitle→} if ($noright_toplink == 0); print qq{\n}; print "\n"; print qq{

管理用
} if ($cgilib_en == 1); ©right; print "\n"; } exit; sub listform { print "\n"; print "
\n"; print "\n"; print "\n"; } sub mbdecode { local(%in) = @_; while (($key,$value)=each %in){ $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # &jcode'convert(*value,'sjis'); if ($key ne main && $key ne style_sheet && $key ne head_insert){ $br = ""; } else { $br = "
"; } $value =~ s//>/g; if ($value =~ /\r\n/) { $value =~ s/\r\n/$br/g; } if ($value =~ /\n/) { $value =~ s/\n/$br/g; } if ($value =~ /\r/) { $value =~ s/\r/$br/g; } if ($value =~ /,/) { $value =~ s/,/,/g; } if ($key eq subject){ $value =~ s/\'/'/g; } $in{"$key"}=$value; } return(%in); } sub copyright { my $mysite = ('http://www.hidekik.com/','http://www.hidekik.com/en/')[$lang]; print "
album2.cgi Ver. $version
\n"; print "
Copyright(C) $reservedyear, hidekik.com
\n"; } sub wradminpwd { $passwd = &makecrypt($in{pwd}); if (open(FILE,"> $admindat")){ print FILE "$passwd"; close(FILE); print "Location: $script\n\n"; exit; } else { print "Content-type:text/html\n\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "パスワードファイル作成に失敗しました\n"; print "\n"; print "\n"; print "パスワードファイル作成に失敗しました。"; print "\n"; exit; } } sub setadminpwd { print "Content-type:text/html\n\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "管理者用パスワード\n"; print "\n"; print "\n"; print "\n"; if ($in{mode} eq 'setup'){ print "
管理者用パスワードを入力してください。
\n"; print "\n"; print "\n"; print "\n"; } else { print "
管理者用パスワードを設定してください。
\n"; print "\n"; print "\n"; print "\n"; } print "
\n"; print "\n"; exit; } sub makecrypt { my $plain = shift; my $salt = join "", ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]; my $result = crypt($plain,$salt) or crypt($plain,'$1$'.$salt.'$'); return $result; } sub setupform { if (open(FILE,"< $admindat")){; $filepwd = ; close(FILE); $inpwd = crypt($in{pwd},$filepwd); } else { print "Content-type:text/html\n\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "パスワードファイルが存在しません\n"; print "\n"; print "\n"; print "パスワードファイルが存在しません。"; print ""; exit; } $period = join(',',@period); $menu_locate_check[$menu_locate] = "checked"; $bgimage_check[$bgimage_en] = "checked"; $style_sheet_check[$style_sheet_en] = "checked"; $head_insert_check[$head_insert_en] = "checked"; print "Content-type:text/html\n\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "管理人セットアップ\n"; print "\n"; print "\n"; if ("$inpwd" eq "$filepwd"){ print "
"; print ""; print ""; print <
  • セットアップリンクを非表\\示にしている場合は、$script?mode=setupからパスワードを入力してこのページに入ってください。
  • 数字やカラー指定は必ず半角で指定してください。全角やブランクだとCGIが起動しなくなります。万一間違って全角で書いてしまった場合は、$mbsetupfileをエディタで開きその場所を半角に正しく修正してください。それで直ります。
画像ディレクトリ CGIディレクトリからみた相対パス。httpからのURL指定でも可。
リストファイル アルバムのリストファイル。写真のファイル名、タイトル、コメントをこのファイルに書く。
戻り先のリンク $scriptからみた相対パスとファイル名、絶対パス、httpからの指定でも可)

リンク名 アルバムタイトル タイトル:
色:color= サイズ:size= フォント:face= メニューの位置 右 メニューのテキストエリアサイズ 壁紙 画像 カラー
画像ファイル
カラー
スタイルシート 有効 無効

<head>内挿入文 有効 無効
HTML書式
ポップアップ広告やJavascript、<META>を挿入したい場合にここに記述する。
以下の記述が<head>〜</head>内に挿入される。

END print ""; print ""; } else { print "
パスワードが違います。
"; } print ""; exit; } ########################################################################### # Setup files write ####################################################### ########################################################################### sub makesetup { if (open(FILE,"< $admindat")){; $filepwd = ; close(FILE); $inpwd = crypt($in{pwd},$filepwd); } else { print "Content-type:text/html\n\n"; print ""; print "パスワードファイルが存在しません。"; print ""; exit; } #print "Content-Type: text/html\n\n"; #$item_value1 = ''; #foreach (keys(%in)){ # print "$_:$in{$_}
"; #} #exit; $in{title_size} =~ s/ /+/; foreach (keys(%in)){ $in{$_} =~ s/
/\n/g; $in{$_} =~ s/,/,/g; $in{$_} =~ s/<//g; } #$in{period} =~ s/,/,/g; if ("$inpwd" eq "$filepwd"){ open(SETUP,"> $setupfile"); print SETUP <〜内に挿入できる構\\文 1:on, 0:off \$head_insert_en = $in{head_insert_en}; \$head_insert = '$in{head_insert}'; #### 環境設定 ここまで ############## END close(SETUP); print "Location: $script\n\n"; } else { print "Content-type:text/html\n\n"; print ""; print "
パスワードが違います。
"; print ""; exit; } } sub error { my ($msg) = shift; unlink("$lockfile"); &htmlhead($msg); print "
$msg
\n"; &htmltail; exit; } sub htmlhead { my ($title) = shift; if ($bgimage_en == 1){ $bgimage = "background=\"$bgimagefile\""; } else { $bgimage = "bgcolor=\"$bgcolor\""; } print "Content-type:text/html\n\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "$title\n"; if ($head_insert_en == 1){ print "$head_insert\n"; } if ($style_sheet_en == 1){ print "\n"; } print "\n"; print "\n"; } sub htmltail { print "
$script Ver. $version
\n"; print "
Copyright(C) $resrevedyear, Hideki
\n"; print "\n"; } sub miniparse { if ($ENV{"REQUEST_METHOD"} eq "GET"){ $data=$ENV{"QUERY_STRING"}; } elsif ($ENV{"REQUEST_METHOD"} eq "POST"){ read(STDIN,$data,$ENV{"CONTENT_LENGTH"}); } @tmparray=split(/&/,$data); foreach $string (@tmparray){ ($key,$value)=split(/=/,$string); $in{"$key"}=$value; } }