#!/usr/bin/perl -w # # Create/Change the blackboard.dat file appropriately # given this input from a CGI Form. # # Varibale Used, Post or Get format # mode=message|graffiti Type of writing to place on the blackboard. # font=figlet_font Grafitti using this figlet font. # text=...message... The Message to be displayed # # # Anthony Thyssen 2 April 1995 # Last Change: 1 January 1997 # # --- Initialize --- $SCRIPT_URL = "blackboard.cgi"; $RETURN_URL = "./"; $DATA_FILE = "blackboard.dat"; $LOG_FILE = "blackboard.log"; #$LOCK_FILE = "/tmp/blackboard_LOCK"; $ENV{'PATH'} = '/usr/ucb:/bin:/usr/bin:/opt/bin:/home/anthony/bin/b_linux'; $FIGLET = 'figlet -w80 -cn -f '; $DATE = `date '+%d %h %y, %H:%M'`; # current date $DATE =~ s/\s+$//; # remove the return if present @fonts = ( # graffiti qw( graffiti gothic ), # standard qw( small standard big stop ), # slant/italic qw( smslant slant speed ), # block qw( rectangles chunky bulbhead serifcap eftirobot doom ogre drpepper ), # thin qw( short mini pepper straight bigfig twopoint threepoint weird cybermedium ), # thin/script qw( stampatello script slscript ), # shadowed qw( smshadow shadow ), # banners qw( basic computer whimsy banner banner3 ), # other qw( eftiwall ), ); $font_default = "small"; $font_header = "small"; # --- Set the defaults --- $FORM{'mode'} = 'message'; $FORM{'font'} = 'graffiti'; # --- Subroutines --- sub header { q*Content-type: text/html Blackboard

Blackboard

Warning: This page will not work on client programs without support for forms.

* } sub address { q*


Program: ``blackboard''
Author: Anthony Thyssen, < anthony@cit.gu.edu.au> on 2 April 1995
* } sub output_error { # Output a error form print "Content-type: text/html\n\n", "Blackboard Error\n", "

Blackboard Error

\n\n", @_, "

\n", &address; exit(0); } # # Lock File Routine # USAGE: &lock(FILE,type) where type is either 'W', 'R' or 'U' # # Using Fcntl Module (perl5) require "Fcntl.pm"; %lock_types = ( 'W', &Fcntl::F_WRLCK, # write lock 'R', &Fcntl::F_RDLCK, # read lock 'U', &Fcntl::F_UNLCK ); # unlock sub lock { local(*FILE, $type) = @_; local($lock) = pack('sslls', $lock_types{$type}, 0, 0, 0, 0); die ("fcntl_lock '$type': $!\n") if fcntl(*FILE, &Fcntl::F_SETLKW, $lock) == -1; } sub htmlize_text { local($text) = @_; return $text if $pre_htmlized; # a hack for direct edit of board data $text =~ s/\&/\&/g; $text =~ s/\/\>/g; return $text; } sub output_blackboard { local($text) = @_; # Limit it somehow to 30 lines -- HOW # Log the original into the logfile if( ! defined $FORM{'testing'} ) { if( ! open(BOARD, ">>$LOG_FILE") ) { # Open the blackboard log file &output_error("Unable to write blackboard log : $!"); } &lock(BOARD, 'W'); # write file lock seek(BOARD, 0, 2); # ensure we are at the end of file print BOARD "$DATE -- from ", $ENV{'HTTP_FROM'}, " at ", ($ENV{'REMOTE_HOST'} || $ENV{'REMOTE_ADDR'}) , "\n"; print BOARD "Graffiti'ed \`\`$FORM{text}'' using font $FORM{'font'}\n" if $FORM{'mode'} eq 'graffiti'; print BOARD $text, "\n"; print BOARD "-" x 79, "\n"; &lock(BOARD, 'U'); # unlock the file close(BOARD); } # Output the text into blackbord file if( ! open(BOARD, ">$DATA_FILE") ) { # Open the blackboard file &output_error("Unable to write blackboard : $!"); } &lock(BOARD, 'W'); print BOARD &htmlize_text($text); &lock(BOARD, 'U'); close(BOARD); } sub message_form { local($text) = join('',@_); print &header, "Please create/edit/write/edit the graffitti on the blackboard.\n", "

\n", "
\n", #"\n", #" testing - printer off
\n", "\n", "\n", "

\n", "Warning: HTML tags, or advertising will not be tolerated.

\n", &address; exit(0); } sub graffiti_form { print &header, "Please write the message you wish to graffiti onto the blackboard.\n", "
\n", "Font Style to Grafitti:
\n", "Text to Graffiti:
\n", #"\n", #" testing - printer off
\n", "\n", "\n", "

\n", "Warning: HTML tags, or advertising will not be tolerated.

\n", &address; exit(0); } sub font_list { print "Content-type: text/plain\n\n", `echo Blackboard Font List | $FIGLET '$font_header' 2>&1`, '-'x79, "\n"; foreach $font ( @fonts ) { print "$font\n", `echo '$font' | $FIGLET '$font' 2>&1`, "\n"; } exit(0); } sub return_redirect { print "Location: $RETURN_URL\n"; print "Content-type: text/html\n\n"; print "The reply to your message is here."; print &address; exit 0; } # --- Read Arguments --- print "Content-type: text/html\n\n" if $DEBUG; sub clean_arg { local($arg) = @_; $arg =~ tr/+/ /; # CGI string decoding $arg =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $arg =~ s/'//g; # remove any single quotes $arg =~ s/\r\n?/\n/g; # clean up end of lines # do not do any other special processing for this program return( $arg ); } # Get the post variables if ( defined $ENV{'CONTENT_LENGTH'} ) { local($buffer) = ""; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); foreach $arg ( split(/&/, $buffer) ) { local($name, $value) = split(/=/, $arg.'='); $FORM{&clean_arg($name)} = &clean_arg($value); print "FORM Arg ``$name'' = ``$value''
\n" if $DEBUG; } } if ( defined $ENV{'QUERY_STRING'} ) { foreach $arg ( split(/&/, $ENV{'QUERY_STRING'}) ) { local($name, $value) = split(/=/, $arg.'='); $FORM{&clean_arg($name)} = &clean_arg($value); print "FORM Arg ``$name'' = ``$value''
\n" if $DEBUG; } } $FORM{'font'} =~ s/\W//g; # remove any bad characters in font name # --- Do the Job --- &font_list if $FORM{'mode'} eq "font_list"; if( ! defined $FORM{'text'} ) { $pre_htmlized++, &message_form(`cat '$DATA_FILE'`) if $FORM{'mode'} eq "edit"; &message_form('') if $FORM{'mode'} eq "message"; &graffiti_form if $FORM{'mode'} eq "graffiti"; &output_error("Unknown mode: $FORM{'mode'}\n"); } elsif( $FORM{'text'} =~ /http:\/\//i || $FORM{'text'} =~ /\[url/i || $FORM{'text'} =~ / You are hereby ordered to cease, or you will charged for miss-use of classroom resources."); } if( $FORM{'mode'} eq "message" ) { &output_blackboard($FORM{'text'}); &return_redirect; } if( $FORM{'mode'} eq "graffiti" ) { $FORM{'text'} =~ s/["'`\000-\037\177-\377]//g; if( ! open(FIGLET, "echo '$FORM{'text'}' | $FIGLET '$FORM{'font'}' 2>&1 |") ) { &output_error("Unable to run figlet command : $!"); } undef $/; # read all in one go $graffiti = ; $/ = "\n"; # return to normal close(FIGLET); # put graffitti in edit box. &message_form($graffiti); #&output_blackboard($graffiti); # put graffitti in edit box. #&return_redirect; } &output_error("Unknown mode: $FORM{'mode'}\n");