#!/usr/local/bin/perl # opg.cgi means Ore Power Gold # 2000/9/14 ver 0.1.3 #やあ3のパワーを表すcgi #text表示用 my @a, @b ,@s; my @wsize, @wcount; ######################################################## #default value set $ver = "0.1.3 2000/9/18"; $diarydir = "/home/yar-3/diary/"; #$diarydir = "diary"; $author = "yar-3"; $max = 90; #日数 $width = 60; # width of graph $HNS = 0; $TDS = 1; $sys = $HNS; #日記システムの選択 $lang = 1; $back_uri = "./"; # URL for back $ref_uri = "./"; # URL for refer-diary $weekstat = 1; # week summary ######################################################## #設定ファイルの読み込み require "./opg.ph" if (-e "./opg.ph"); $tt = time + $jisa * 3600; ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($tt); # 今日を取得 $year += 1900; $mon++; $startdate = sprintf("%0.4d%0.2d%02.d", $year,$mon,$mday); $startdotw = $wday; # 今日の曜日 #print "$startdate $startdotw\n"; if ($lang == 0) { # default=0: japanese @week = ("","月","火","水","木","金",""); #日本語 } else { @week = ("Su","Mo","Tu","We","Th","Fr","Sa"); #English } #他の言語に対応する場合はここらへんをアレせよ @dom = (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); # days of months ######################################################## #引数の解釈 masato-3 from i system if ($ARGV[0] eq '-t') { # デバック用オプション引数を使った実行 # 使用例 : ./index.cgi -t word=system $query_string = $ARGV[1]; splice(@ARGV, 0, 2); # オプション引数を除去 } elsif ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $query_string, $ENV{'CONTENT_LENGTH'}); } else { $query_string = $ENV{'QUERY_STRING'}; } @x = split(/&/, $query_string); foreach $x (@x) { ($name, $value) = split(/=/, $x); $value =~ tr/+/ /; $value =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C", hex($1))/eg; $FORM{$name} = $value; } ######################################################## #引数の適用 $max = $FORM{'max'} if ($FORM{'max'}); # max=100 if($FORM{'startdate'}) { $startdate = $FORM{'startdate'}; # startdate=20000914 ここから日数分さかのぼる my ($y, $m, $d) = ($startdate =~ /(\d\d\d\d)(\d\d)(\d\d)/); $startdotw = &get_dow($y,$m,$d); } if ($FORM{'mrep'}) { $mrep = $FORM{'mrep'}; # mrep=200009 monthly report $mrep =~ /(\d\d\d\d)(\d\d)/; $startdate = "$1$2" . $dom[$2]; # 20000931 とする my ($y, $m, $d) = ($startdate =~ /(\d\d\d\d)(\d\d)(\d\d)/); $startdotw = &get_dow($y,$m,$d); $enddate = "$1$2" . "01"; } &makefilelist; $maxsize = 0; #maximum size of hnf $sum = 0; # 合計 for ($i = 0; $i < $max ; $i++) { $t = (stat($a[$i]))[7]; # size get if ($t > $maxsize) { $maxsize = $t; $maxday = $i; } #push(@s, $t); # 配列に格納 $size[$i] = $t; $sum += $t; } print "content-type: text/html\n"; print "charset: euc-jp\n\n"; &printhead; &printform; &printdata; &printfoot; end; sub printdata { if ($maxsize == 0) { print "no diary\n"; return; } $w = $startdotw; print "
";
	print "    day     : size : bar\n";
	for ($i = 0; $i <$max ; $i++) {
		print "";
		print "$b[$i]($week[$w]):";
		$buf = sprintf("%6d", $size[$i]);
		print "$buf:";
		if ($i == $maxday) {
			print "";
		}
		for ($j=0;$j<$size[$i] * $width / $maxsize;$j++) {
			print "*";
		}
		if ($i == $maxday) {
			print "";
		}
		print "\n";
		$wcount[$w]++;
		$wsize[$w] += $size[$i];
		$w--;
		if ($w < 0) { $w = 6;}
	}
	print "
\n"; print "Max. day is "; print "$b[$maxday]: $size[$maxday]
\n"; print "Total is " . sprintf("%dKB.\n", $sum/1024); print "Ave. is " . sprintf("%d.\n", $sum / $max); #for ($i=0;$i<$max;$i++) { #print "$i=$b[$i]:$size[$i] \n"; #} if ($weekstat) { &printweek; } } sub printweek { #曜日ごとの集計 my $i, $j, $wmaxsize, $wmax; print "
weekly status
\n"; for($i=0;$i<7;$i++) { $wsize[$i] = $wsize[$i] / $wcount[$i]; # normalize if ($wmaxsize < $wsize[$i]) { $wmaxsize = $wsize[$i]; $wmax = $i; } } print "
\n";
	for ($i=0;$i<7;$i++) {
		print "$week[$i]:" . sprintf("%8d:", $wsize[$i]);
		if ($i == $wmax) {
			print "";
		}
		for ($j=0;$j<$wsize[$i]*$width/$wmaxsize;$j++) {
			print "@";
		}
		if ($i == $wmax) {
			print "";
		}
		print "\n";
	}
	print "
\n"; } sub printform { #フォームを表示 my $mrep; $startdate =~ /(\d{6}).*/; $mrep = $1; print < startdate: max:
monthly report:

EOF } sub printhead { print < Ore Power Gold $author

Ore Power Gold $author

version $ver
back
EOF } sub printfoot { print < back
Ore Power Gold is made by yar-3(ore\@yar-3.net) and OPG supporters.
Ore Power Home Page EOF } sub makefilelist { my $i, $tmpdate, $tmpdotw; $tmpdate = $startdate; $tmpdotw = $startdotw; for($i=0;$i<$max;$i++) { #print $tmpdate; push(@a, &makefilename($tmpdate)); #diary/2000/d20000913.hnf push(@b, $tmpdate); # 20000913 if ($tmpdate == $enddate) { $max = $i + 1; last; } $tmpdate = &prevday($tmpdate); } } sub makefilename { if ($sys == $HNS) { $_[0] =~ /(\d\d\d\d).+/; push(@c, $_[0]); return "$diarydir/$1/d". $_[0] . ".hnf"; } if ($sys == $TDS) { $_[0] =~ /(\d\d\d\d)(\d\d)(\d\d)/; push(@c, $_[0] . "#$3"); return "$diarydir/$1/$2/$3.tdf"; } } # 1日前の日付を知る # 20000101 -> 19991231 sub prevday { my $ty, $tm, $td, $tmpdate; $_[0] =~ /(\d{4})(\d\d)(\d\d)/i; #(2000)(09)(14) $ty = $1; $tm = $2; $td = $3; #print "##$_[0]## $1 $2 $3\n"; $td--; if ($td == 0) { #前月に移動 $tm--; if ($tm == 0) { #現在1月だったら年も移動 $ty--; $tm = 12; $td = 31; } elsif ($tm == 2) { #2月ならうるう歳check if ($ty % 4 == 0) { if ($ty % 400 == 0) { #2000年とか $td = 29; } elsif ($ty % 100 == 0) { #1900年とか $td = 28; } else { $td = 29; } } else { $td = 28; } } else {#2-12月 $td = $dom[$tm]; } } return sprintf("%0.4d%0.2d%02.d", $ty,$tm,$td); } #曜日を取得! sub getdayoftheweek { my ($y, $m, $d) = ($_[0] =~ /(\d\d\d\d)(\d\d)(\d\d)/); return $week[&get_dow($y,$m,$d)]; } #曜日を取得(0:日, 1:月, ..., 6:土) sub get_dow { # hnsのDate.pmを参考に書き換えました # これでtimelocal()を使わずにすみますヨ。 my ($y, $m, $d) = @_; $y = $y + 399 if ($m < 3); ($y + int($y/4) - int($y/100) + int($y/400) + (0, 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4)[$m] + $d ) % 7; } # 2000/9/8 ver 0.0.3 # 2000/9/7 first version # special thanks # tokumi-3 # docile-3 # masato-3 (sub routines for i system)