#!/usr/bin/perl #!C:\PERL\5.00502\BIN\MSWIN32-X86-OBJECT\perl #!/usr/bin/perl # Set Variables $guestdata = 'guest.dat'; $guestdef = 'guest.def'; $add_file ='addguest.html'; $cgiurl = 'index.cgi'; $admincgiurl = 'admin.cgi'; $title = '訪客留言板'; # Set Your Options: $perorder = 0; # 1 = Yes; 0 = No $use_time = 1; # 1 = YES; 0 = NO # Done ############################################################################## print "Content-type: text/html\n\n"; &ReadSIN(*data); if($data{'option'} eq 'form'){ print "新增訪客"; print "

加入留言簿

請在以下的空欄中填上你的基本資料及你的留言! 謝謝!!\n"; print "
\n"; local $type; } elsif($data{'option'} eq 'add'){ @LOADER = &CheckData(*data); local $count = &WriteData(); &PrintOK($count); exit; } elsif($data{'option'} eq 'adminform'){ } elsif($data{'option'} eq 'adminform'){ } else{ open(DATA,$guestdata); @datalines = ; close(DATA); local $c = $#datalines + 1; print "$title\n\n"; print "

\n"; #print "

★$title★

\n"; print "
歡迎光臨留言板,您的意見與鼓勵是我們提供更好服務的動力!

\n"; #print "◇歡迎光臨留言板,你可以在這裡留下您的資料哦!!
\n"; print "
【留言吧!】【回首頁】【內容索引】【管理】
\n"; print "
目前有 $c 人留言 期待您的留言 ※最後更新日期:

\n"; local $dataline; if ($preorder == 0) { @datalines = reverse(@datalines) } foreach $dataline (@datalines) { @data = split(/&&/,$dataline); &PrintData(@data); } exit; } exit; ################################################### sub ReadSIN { local (*in) = @_ if @_; local ($i, $key, $val); if ($ENV{'REQUEST_METHOD'} eq 'GET') { $in = $ENV{'QUERY_STRING'}; } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN,$in,$ENV{'CONTENT_LENGTH'}); } @in = split(/[&;]/,$in); foreach $i (0 .. $#in) { $in[$i] =~ s/\+/ /g; ($key, $val) = split(/=/,$in[$i],2); # splits on the first =. $key =~ s/%(..)/pack("c",hex($1))/ge; $val =~ s/%(..)/pack("c",hex($1))/ge; if($val =~/&/){ CgiErr('請勿使用“&”作為輸入!!'); last; } $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator $in{$key} .= $val; } if(&CgiErr() > 0){ &CgiErr('>>|'); } } sub CgiErr{ ## print error message !! @ErrMesg=(); local ($mesg) = $_[0] if @_; local ($i,$err_message,$k,$mesgdata,$l); if($mesg =~/^>>\|*(.*)/){ push(@ErrMesg,$1) if $1; if($#ErrMesg != -1){ print "
\n"; foreach $k(0..$#ErrMesg){ if($ErrMesg[$k]=~/System/i){ print "\n"; } else{ print "\n"; } } print "
資料有誤,請仔細察看下列項目!!
Warn !!$ErrMesg[$k]
Data Error$ErrMesg[$k]
\n"; if($mesg =~/^>>\|(.*)/){ print "\n"; print "\n"; print "\n"; exit; } } return @ErrMesg ; } else{ push(@ErrMesg,$mesg) if ($mesg) ; return @ErrMesg ; } } sub PrintData{ local (@in) = @_ if @_; print "
姓名:$in[1]性別:$in[2]年齡:$in[3]服務或就讀單位:$in[4]\n"; print "
服務所在地:$in[5]職業:$in[6]學歷:$in[7]\n"; if ($in[7]) { print "
$in[1]的E-mail信箱:$in[8]\n";} if ($in[8]) { print "
$in[1]的首頁:$in[9]\n";} print "
$in[1]的留言:
$in[10]
\n"; print "
★留言日期:$in[11]
\n"; } sub CheckData{ local (*in) = @_ if @_ ; local (@defs,@LOADER,$cond,@datas,$line); open(DEF,$guestdef) || CgiErr('>>|Systen can\'t open defineS file !!'); @datas = ; close(DEF); foreach $line(@datas) { if ($line eq '') { next; } @defs = split(/\|/,$line,4); push(@LOADER,$defs[0]); if ($defs[3]=~/N/g) { if ($in{$defs[0]} eq '') {;CgiErr('>>|有些欄位是一定要填寫的,請再檢查一次!!'); } } if($defs[3]=~/E/g){ unless ($in{$defs[0]}=~/.+\@.+..+..+/) { $in{$defs[0]} = ''; } } if($defs[3]=~/W/g){ unless ($in{$defs[0]}=~/http:\/\/.+\..+\..+/) { $in{$defs[0]} = ''; } } if($defs[1] eq 'textarea'){ if ($in{'html'} ne 'y') { $in{$defs[0]} =~s//>/g; $in{$defs[0]} =~s/"/"/g; } $in{$defs[0]} =~s/\cM//g; $in{$defs[0]} =~s/\n\n/

/g; $in{$defs[0]} =~s/\n/
/g; } if(($defs[1] eq 'select')||($defs[1] eq 'radio')){ unless ($defs[2]=~/$in{$defs[0]}/g) { CgiErr('>>|CGI 參數傳遞錯誤!!'); } } } return @LOADER; } sub WriteData{ #mon/dd/yy-hh/mim/ss local ($e,$date,@e,$count); local($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $mon++; if ($use_time == 1) { $date = "$mon/$mday/$year-$hour:$min:$sec"; } else{ $date = "$mon/$mday/$year";} chop($date) if ($date =~ /\n/); open(D,$guestdata); @e = ; close(D); ($count,$_) = split(/&&/,$e[$#e]); $count++; open(DATA,">>$guestdata"); print DATA "$count&&"; foreach $e (@LOADER) { print DATA "$data{$e}&&"; } print DATA "$date\n"; close(DATA); return $count ; } sub PrintOK{ local ($c) = $_[0] if @_; local ($t,$e); print "Thank You!! ^_^\n"; print "★謝謝您在版上留下寶貴的意見!!★

\n"; print "◇您的意見已加入站上的留言板了,您是第 $c 位留言者!!


\n"; print "您的資料如下:

\n"; print "

\n"; foreach $e (@LOADER) { if ($data{$e}) {print "
▲$e$data{$e}\n"; } } print "

回訪客留言板\n"; }