#!/usr/bin/perl ############################################### # sche14.cgi # V2.1 (2005.11.27) # Copyright(C) CGI-design ############################################### require './cgi-lib.pl'; $script = 'sche14.cgi'; $base = './schedata'; #データ格納ディレクトリ $nofile = "$base/no.txt"; #記事番号 $recfile = "$base/rec.txt"; #カラー情報 $opfile = "$base/option.txt"; #オプション $cgi_lib'maxdata = 200000000000; #入力最大容量(byte) @fc = ('#000000','#800000','#0000ff','#008040','#ff0000','#c100c1','#ff80c0'); @bc = ('#d3e3fe','#e6edff','#d5fdec','#e6ffff','#ffd9ec','#ff9f9f','#be8eb5','#fcc592','#fee9c5','#f8ddcf','#fef5da','#ffffff'); @wcolor = ("#ff0000","#000000","#000000","#000000","#000000","#000000","#0000ff"); @week = ('日','月','火','水','木','金','土'); @mdays = (31,28,31,30,31,30,31,31,30,31,30,31); 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<>$base/home.gif<>$base/last.gif<>$base/next.gif<>$base/sche.gif<>$base/new.gif<>$base/holiday.gif<><>#fafaf5<>#000000<>#800000<>#0000ff<>#ffffff<>3<>200<>200"; close OUT; chmod(0666,$recfile); open (OUT,">$recfile") || &error("OPEN ERROR"); print OUT "$fc[2]<>$bc[0]"; close OUT; chmod(0666,$nofile); } ##### メイン処理 ##### &ReadParse; $mode = $in{'mode'}; open (IN,"$opfile") || &error("OPEN ERROR"); ($pass,$title,$home,$savedir,$loaddir,$home_icon,$last_icon,$next_icon,$sche_icon,$new_icon,$holi_icon,$bg_img,$bg_color,$text_color,$title_color,$sub_color,$sche_color,$newday,$max_w,$max_h) = split(/<>/,); close IN; $nowtime = time; ($sec,$min,$hour,$nowday,$nowmon,$nowyear) = localtime; $nowyear += 1900; $nowmon++; $newtime = $nowtime - $newday * 24 * 3600; $logyear = $in{'year'}; $logmon = $in{'mon'}; if (!$logyear) {$logyear = $nowyear; $logmon = $nowmon;} $logfile = "$base/$logyear$logmon.txt"; if ($mode eq 'admin') {&admin;} else {&main;} print "\n"; exit; ### sub header { print "Content-type: text/html\n\n"; print "\n"; print "Schedule\n"; $head = 1; } ### sub main { &header; print "
\n"; print "
\n"; if ($home) {if ($home_icon) {print "";} else {print "[HOME]";}} print ""; if ($title =~ /http:/) {print "\n";} else {print "$title\n";} print "編集
\n"; &dsp; # 次の行は著作権表示ですので削除しないで下さい。# print "CGI-design\n"; } ### sub dsp { @data=@lognum=@logno=(); if (-e $logfile) { open (IN,"$logfile") || &error("OPEN ERROR"); while () { push (@data,$_); ($no,$time,$day) = split(/<>/); $lognum[$day]++; if (!$logno[$day]) {$logno[$day] = $no;} } close IN; } $mdays = $mdays[$logmon - 1]; if ($logmon == 2 && $logyear % 4 == 0) {$mdays = 29;} print "
\n"; print "\n"; $mon = $logmon - 1; if ($mon < 1) {$mon = 12; $year = $logyear - 1;} else {$year = $logyear;} print "\n"; print "\n"; $mon = $logmon + 1; if (12 < $mon) {$mon = 1; $year = $logyear + 1;} else {$year = $logyear;} print "
 $logyear年
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
$logmon月
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; for (0 .. 6) {print "\n";} print "\n"; &holi_set; $wday = &get_date($logyear,$logmon,1); $w=$n=0; $k=1; for (0 .. 41) { if (!$w) {print "";} if ($wday <= $_ && $k <= $mdays) { if ($w == 1) {$n++;} $wcolor = $wcolor[$w]; if (2002 < $logyear) { &get_holiday($logmon,$k,$w,$n); if ($holiday) {$wcolor = $wcolor[0];} } if ($logyear == $nowyear && $logmon == $nowmon && $k == $nowday) {$bc = '#dFFF00';} elsif ($holiday || !$w) {$bc = '#fef0ef';} elsif ($w == 6) {$bc = '#eeffff';} else {$bc = '#ffffe8';} if ($k < 10) {$day = " $k";} else {$day = $k;} print "\n"; $k++; } else {print "\n";} $w++; if ($w == 7) { print "\n"; if ($mdays < $k) {last;} $w = 0; } } print "
$week[$_]
$day\n"; if ($holiday && $holi_icon) {print " \"$holiday\"";} print "
 "; if ($lognum[$k]) {for (1 .. $lognum[$k]) {print "\"詳細\"";}} print "
\n"; print "\n"; foreach (@data) { ($no,$time,$day,$wday,$sub) = split(/<>/); if ($logyear == $nowyear && $logmon == $nowmon && $day == $nowday) {$bc = '#dfff00';} else {$bc = '#ffffff';} print "\n"; } print "
日 付題 名
  $logmon月$day日($week[$wday]) $sub"; if ($newtime < $time) {print " ";} print "

\n"; foreach (@data) { ($no,$time,$day,$wday,$sub,$com,$img_type,$img_w,$img_h,$img_big,$ftcolor,$frcolor) = split(/<>/); &dsp_log; } } ### sub dsp_log { $com =~ s/([^=^\"]|^)(http\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#\%]+)/$1$2<\/a>/g; print "\n"; print "\n"; if ($mode eq 'admin') { print "\n"; } print "
 $logyear年$logmon月$day日($week[$wday])  $sub
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; if ($img_type) { $imgfile = "$loaddir/$no.$img_type"; $imgsrc = ""; if ($img_big) {print "$imgsrc";} else {print $imgsrc;} } print "$com
\n"; print "
▲top
\n"; } ### sub get_date { my($y,$m,$d) = @_; if ($m < 3){$y--; $m+=12;} return ($y+int($y/4)-int($y/100)+int($y/400)+int((13*$m+8)/5)+$d)%7; } ### sub holi_set { $def = 0.242194*($logyear-1980)-int(($logyear-1980)/4); $spr = int(20.8431+$def); $aut = int(23.2488+$def); %holi_d = ('0101','元日','0211','建国記念の日',"03$spr",'春分の日','0429','みどりの日','0503','憲法記念日','0505','こどもの日',"09$aut",'秋分の日','1103','文化の日','1123','勤労感謝の日','1223','天皇誕生日'); %holi_w = ('012','成人の日','073','海の日','093','敬老の日','102','体育の日'); } ### sub get_holiday { $sm = sprintf("%02d%02d",$_[0],$_[1]); $holiday = $holi_d{$sm}; if ($sm eq '0504' && 1 < $_[2]) {$holiday = '国民の休日';} if ($holiday && !$_[2]) {$hflag = 1;} if (!$holiday && $_[2] == 1) { $smw = sprintf("%02d$_[3]",$_[0]); $holiday = $holi_w{$smw}; if ($hflag) {$holiday = '振替休日'; $hflag = 0;} } if ($logyear eq '2009' && $sm eq '0922') {$holiday = '国民の休日';} } ### 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"; $act = $in{'act'}; if ($in{'set'}) {&setup;} else {&edt;} } ### sub edt { if ($in{'newwrt'}) {&newwrt;} elsif ($in{'edtwrt'}) {&edtwrt;} elsif ($in{'delwrt'}) {&delwrt;} &in_form; print "
記事を修正・削除する場合は[修正]をクリックして下さい。

\n"; &dsp; } ### sub in_form { print "
\n"; print "\n"; print "\n"; print "\n"; if (!$act) { print "\n"; $sub=$com=''; open (IN,"$recfile") || &error("OPEN ERROR"); ($ftcolor,$frcolor) = split(/<>/,); close IN; } else { print "\n"; print "\n"; print "\n"; open (IN,"$logfile") || &error("OPEN ERROR"); while () { ($no,$time,$day,$wday,$sub,$com,$img_type,$img_w,$img_h,$img_big,$ftcolor,$frcolor) = split(/<>/); if ($no eq $in{'no'}) {last;} } close IN; $com =~ s/
/\r/g; print "
\n"; } print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
日付
日付 $logyear年$logmon月$day日($week[$wday])
題名

内容
画像
文字色\n"; foreach (@fc) { if ($_ eq $ftcolor) {$chk = ' checked';} else {$chk = '';} print "\n"; } print "
枠色\n"; foreach (@bc) { if ($_ eq $frcolor) {$chk = ' checked';} else {$chk = '';} print "\n"; } print "
"; if (!$act) {print "";} else { print "\n"; print "
\n"; } print "
\n"; } ### sub newwrt { $in{'com'} =~ s/\r\n|\r|\n/
/g; $wday = &get_date($logyear,$logmon,$in{'day'}); 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'); $newdata = "$no<>$nowtime<>$in{'day'}<>$wday<>$in{'sub'}<>$in{'com'}<>$type<>$width<>$height<>$big<>$in{'ftcolor'}<>$in{'frcolor'}<>\n"; if (-e $logfile) { @new = (); $flag = 0; open (IN,"$logfile") || &error("OPEN ERROR"); while () { ($no,$time,$day) = split(/<>/); if (!$flag && $in{'day'} < $day) {push(@new,$newdata); $flag = 1;} push(@new,$_); } close IN; if (!$flag) {push(@new,$newdata);} open (OUT,">$logfile") || &error("OPEN ERROR"); print OUT @new; close OUT; } else { open (OUT,">$logfile") || &error("OPEN ERROR"); print OUT $newdata; close OUT; chmod(0666,$logfile); } open (OUT,">$recfile") || &error("OPEN ERROR"); print OUT "$in{'ftcolor'}<>$in{'frcolor'}"; close OUT; } ### sub edtwrt { $in{'com'} =~ s/\r\n|\r|\n/
/g; &img("$savedir/$in{'no'}",'img'); @new = (); open (IN,"$logfile") || &error("OPEN ERROR"); while () { ($no,$time,$day,$wday,$sub,$com,$img_type,$img_w,$img_h,$img_big) = split(/<>/); if ($no eq $in{'no'}) { if ($type) {$img_type = $type; $img_w = $width; $img_h = $height; $img_big = $big;} push(@new,"$no<>$time<>$day<>$wday<>$in{'sub'}<>$in{'com'}<>$img_type<>$img_w<>$img_h<>$img_big<>$in{'ftcolor'}<>$in{'frcolor'}<>\n"); } else {push(@new,$_);} } close IN; open (OUT,">$logfile") || &error("OPEN ERROR"); print OUT @new; close OUT; } ### sub delwrt { @new = (); open (IN,"$logfile") || &error("OPEN ERROR"); while () { ($no,$time,$day,$wday,$sub,$com,$img_type) = split(/<>/); if ($no eq $in{'no'}) {if ($img_type) {unlink "$savedir/$no.$img_type";}} else {push(@new,$_);} } close IN; open (OUT,">$logfile") || &error("OPEN ERROR"); print OUT @new; close OUT; } ### sub setup { if ($in{'wrt'}) { if ($in{'newpass'} ne '') {$pass = &crypt($in{'newpass'});} $title = $in{'title'}; $home = $in{'home'}; $savedir = $in{'savedir'}; $loaddir = $in{'loaddir'}; $home_icon = $in{'home_icon'}; $last_icon = $in{'last_icon'}; $next_icon = $in{'next_icon'}; $sche_icon = $in{'sche_icon'}; $new_icon = $in{'new_icon'}; $holi_icon = $in{'holi_icon'}; $bg_img = $in{'bg_img'}; $bg_color = $in{'color0'}; $text_color = $in{'color1'}; $title_color = $in{'color2'}; $sub_color = $in{'color3'}; $sche_color = $in{'color4'}; $newday = $in{'newday'}; $max_w = $in{'max_w'}; $max_h = $in{'max_h'}; open (OUT,">$opfile") || &error("OPEN ERROR"); print OUT "$pass<>$title<>$home<>$savedir<>$loaddir<>$home_icon<>$last_icon<>$next_icon<>$sche_icon<>$new_icon<>$holi_icon<>$bg_img<>$bg_color<>$text_color<>$title_color<>$sub_color<>$sche_color<>$newday<>$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"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; @name = ('基本背景色','基本文字色','タイトル色','題名色','内容背景色'); @data = ($bg_color,$text_color,$title_color,$sub_color,$sche_color); for (0 .. $#name) { print "\n"; } print "\n"; print "\n"; print "\n"; print "
タイトル
ホームURL
画像格納ディレクトリ
画像読出ディレクトリ
ホームアイコン\n"; if ($home_icon) {print " ";} print "
LASTアイコン 
NEXTアイコン 
スケジュールアイコン 
NEWアイコン 
休日アイコン\n"; if ($holi_icon) {print " ";} print "
壁紙\n"; if ($bg_img) {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; }