sub authenticate { if(!exists($cookies{userid})) { print "Status: 302 Found\nLocation: http://$ENV{SERVER_NAME}/\n\n"; exit(0); } } sub from_base_36 { my $thenum = "$_[0]"; my $result = 0; foreach $which (split //, $thenum) { my $value = index("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", $which); $result *= 10; $result += $value; } return $result; } sub to_base_36 { my $thenum = $_[0]; my $result = ""; use integer; while($thenum) { $result .= substr("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", $thenum % 36, 1); $thenum /= 10; } return $result; } sub parseform { my $qs = shift; my $hashref = shift; my $listref = shift if @_; if(!$qs && $ENV{REQUEST_METHOD} eq "POST") { read(STDIN, $qs, $ENV{CONTENT_LENGTH}, 0); } my(@kvs) = split /&/, $qs; foreach $kv (@kvs) { my($key, $value) = split /=/, $kv; $key = &unescape($key); @$listref = (@$listref, $key) if defined($listref) && !defined($$hashref{$key}); $$hashref{$key} .= "\0" if (defined($$hashref{$key})); $$hashref{$key} .= $value; } } sub unescape { my($todecode) = @_; $todecode =~ tr/+/ /; $todecode =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge; return $todecode; } sub urlencode { my($toencode) = @_; $todecode =~ s/&/&/gs; $todecode =~ s/"/"/gs; $todecode =~ s//>/gs; return $toencode; } sub set_diff { my ($lista, $listb) = @_; my @l = (); foreach my $i (@$lista) { push @l, $i unless grep {$_ == $i} @$listb; } return @l; } sub parse_email_list { my($emails) = @_; my %emails; $emails =~ s/[,;\s]([^@]+\s+)*[^@]+\s*<([^@\s>]+@[^@\s>]+)>/ $2/gs; foreach (split /[,;\s]+/, $emails) { push @emails, $_ unless $emails{$_}; $emails{$_}=1; } return @emails; } $headers = << 'HEADERS'; Content-type: text/html HEADERS $leadin = << 'LEADIN'; Invitotron

LEADIN $leadout = << 'LEADOUT';

LEADOUT $dateformat = '%d %b %Y %I:%M%p'; 1;