#!/usr/bin/perl -Tw
# (Text::Template can't do -T, but no user input is used dangerously)
#
-# $Id: shift.cgi,v 1.1 2000-05-11 11:27:32 ivan Exp $
+# $Id: shift.cgi,v 1.5 2002-07-10 01:08:49 ivan Exp $
#
# Copyright (C) 2000 Adam Gould
# Copyright (C) 2000 Michal Migurski
# user-servicable parts
###
-$template_file = '/home/ivan/staffsheet/table.html';
-$data_directory = '/home/ivan/staffsheet/data';
-$mail_smtpserver = 'localhost'; # set blank to disable
+$template_file = '/var/www/www.420.am/staff/table.html';
+$data_directory = '/var/www/www.420.am/staff/data';
+#$mail_smtpserver = 'localhost'; # set blank to disable
+$mail_smtpserver = ''; # set blank to disable
$mail_from = 'ivan-misconfigured-shift-from@420.am';
$mail_subject = 'Your shift has been replaced';
@mail_cc = (
use strict;
use vars qw( $template_file $data_directory $mail_smtpserver $mail_from
$mail_subject @mail_cc $mail_footer
- $cgi $template %shifthash %warning @messages );
+ $cgi $template %shifthash %warning @messages $magic );
use subs qw( form inputbox );
use Fcntl ":flock";
use CGI 2.15;
foreach my $field ( @diff_fields ) {
$shifthash{$field}='' unless defined $shifthash{$field};
if ( $shifthash{$field} eq $cgi->param($field. '_old') ) {
- if ( $cgi->param($field. "_new") =~
- /\b(\w[\w\-\.\+]*\@(([\w\.\-]+\.)+\w+))\b/
- || $cgi->param($field. "_new") =~ /^\s*$/
+ if ( $cgi->param($field. "_new") =~
+ /^\s*(\w[\w\s\.\'\-]{0,99}<?\s{0,9}(\w[\w\-\.\+]{0,99}\@(([\w\.\-]{1,99}\.){1,99}\w{1,99}))\s{0,9}>?)\s*$/
+ || $cgi->param($field. "_new") =~ /^\s*()$/
) {
+ my $new = $1;
open(FILE,">$data_directory/.new.$field")
or die "Can't open file $data_directory/$field: $!";
- print FILE $cgi->param($field. "_new");
+ print FILE $new;
close FILE;
rename "$data_directory/.new.$field", "$data_directory/$field";
$warning{$field} = '';
"Hi,",
"",
"The \"$field\" shift you signed up for has been changed to",
- '"'. $cgi->param($field. "_new"). '"',
+ '"'. $new. '"',
"",
split("\n", $mail_footer),
],
# subroutines for the template
sub form {
- $cgi->start_form;
+ $magic = defined $cgi->param('__MAGIC') ? $cgi->param('__MAGIC') : '';
+ $cgi->delete_all();
+ $cgi->start_form();
}
sub inputbox {
my $field = shift;
return $shifthash{$field} || " "
- if defined $cgi->param('__MAGIC') && $cgi->param('__MAGIC') eq 'print';
+ if $magic eq 'print';
$shifthash{$field}='' unless defined $shifthash{$field};
$warning{$field}='' unless defined $warning{$field};
#"$field ".