#! c:/perl/bin/perl # # topdisp.cgi # Display announcment on the top page. # # 12/29/05 : Fixed & handling for firefox 1.5. # 9/4/05 : Deleted jcode.pl # 4/24/05 : Modified & processing # 12/17/04 : Added processing for & # 12/2/04 : Deleted + space conversion # 8/28/04 : Added e # 8/14/04 : Added data file edit mode # 8/8/04 : Initial revision # # $Id: topdisp.cgi,v 1.2 2005/12/29 03:45:07 Hideki Kanayama Exp $ # #Invoke from SSI. # # <!--#include virtual="topdisp.cgi?mode=[event|notice|update|admin]" --> # #makes it work. #The parameter of mode can be anything as long as it matchs the first column of the data file. # #e.g.:mode=event, mode=special #Each line displays with encircled by<li>. # # Format of data file # type, attribute, contents, date # Type : Will be set by mode in the CGI parameter. # event : event # notice : notice # update : update notice # admin : admin message # and so on.... # attribute : vine # v : Display # i : Do not display # n : Do not display any time(Will not be displayed even in full display mode) # e : End parse(ignored with display=all) # Use this attribute if you want the CGI to terminate file parse at 'e' is present. The CGI does not parse below the 'e'. # # If you want to put in the data file, Use "&#44;". # Comment is a #. # # Data file example # ------------------------------- ## notice #notice,v,No Announcement so far. #notice,e # ## Updates #update,v,The mail address has been udpated,7/30/04 #update,v,Renewal!,7/3/04 #update,e #update,i,Updated the address book,6/20/04 #update,i,Updated1&#44;2&#44;3 in the mail address,6/18/04 #update,i,A new message board has been installed,6/10/04 # ## Event #event,v,We have a meeting on 15th.,8/1/04 #event,n,No events now. # #--------------------------------- # # Edit mode # Invoked by topdisp.cgi?edit=on. # You can simply edit and press "update". # You can also specify data file name. # # # Full display mode # topdisp.cgi?mode=<[event|notice|update|admin]>&display=all # Display all contents of the specified mode. # 'v' and 'i' in attribute will be ignored. 'n' will not be displayed. # This mode should be used from usual CGI from a browser. # require "cgi-lib.pl"; $admindat = "adminpwd.dat"; $script = "topdisp.cgi"; $setupfile = "topdisp_setup.pl"; $datafile = "topdisp.dat"; if (-e "$setupfile") { require "$setupfile"; } $agent = $ENV{'HTTP_USER_AGENT'}; &ReadParse; %all=&mbdecode(%in); if ($all{admin} eq 'on'){ &wradminpwd; } if (! -e "$admindat"){ &setadminpwd; } if ($all{edit} eq 'on'){ &dispedit; } elsif ($all{edit} eq 'write'){ &dispwrite; } else { &display; } sub dispedit { print "Content-Type: text/html\n\n"; if ($all{referer} eq ''){ $referer = "$ENV{HTTP_REFERER}"; } else { $referer = $all{referer}; } if ($all{pwd} eq ''){ print <
Please set admin password.
END exit; } open(FILE,"< $admindat"); $adminpwd = ; close(FILE); if (crypt($all{pwd},$adminpwd) ne "$adminpwd") { print <
Password mismatch.
END exit; } print <

Edit data file

data file name

END if ($all{dironly} ne 'on'){ open(FILE,"< $datafile") || "

Cannot open $datafile
\n"; print <
\n"; close(FILE); } print < END2 } sub dispwrite { open (FILE, "> $setupfile") || "Cannot create a setup file:$setupfile\n"; print FILE < $all{datafile}") || "Cannot save data file :$all{datafile}\n"; print FILE $all{contents}; close(FILE); } print "Content-Type: text/html\n\n"; print "
Updated data file:$datafile
Go back to original page.
\n"; } sub display { print "Content-Type: text/html\n\n"; if (open(FILE,"< $datafile")) { if ($all{mode} eq ''){ print "Please invoke the CGI from a SSI and use mode=<event>.
\n"; print "e.g.:<!--#include virtual=\"$script?mode=event -->
\n"; } else { while (){ s/[\n\r]*$//; /^[ ]*#*$/ && next; ($attribute,$visible,$main,$date)=split(/,/); if (("$attribute" eq "$all{mode}") && ("$visible" eq 'e')){ if ("$all{display}" eq 'all') {next;} else {last;} } if ((("$attribute" eq "$all{mode}") && (("$visible" eq 'v') || (("$all{display}" eq 'all') && ("$visible" ne 'n'))))){ $dispdate = ''; if ($date ne ''){ $dispdate = "($date)"; } print "
  • $main$dispdate\n"; } } } close(FILE); exit; } else { print "
    Cannot open $datafile
    \n"; print "Create data file.
    \n"; print "Do not create data file and only update the data file name.
    \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; $value =~ s/\r\n/\n/g if ($key eq contents); $in{"$key"}=$value; } return(%in); } sub salt { my $length = 2; $length = $_[0] if exists $_[0]; return join "", ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[map {rand 64} (1..$length)]; } sub makecrypt { my $plain = shift; my $salt = &salt; my $result = crypt($plain,$salt); $result=crypt($plain,'$1$'.$salt.'$') if ($result eq ''); return $result; } sub setadminpwd { print "Content-type:text/html\n\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "admin password\n"; print "\n"; print "\n"; print "
    \n"; print "
    Please set admin password
    \n"; print "\n"; print "\n"; print "\n"; print "
    \n"; print "\n"; exit; } sub wradminpwd { $passwd = &makecrypt($all{pwd}); if (open(FILE,"> $admindat")){ print FILE "$passwd"; close(FILE); } else { print "Content-type:text/html\n\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "Failed to make a password.\n"; print "\n"; print "\n"; print "Failed to make a password."; print "\n"; exit; } }