#!/usr/bin/perl ####################################################### # Email Management System # Created by Aaron Anderson # Contact me at: sulfericacid@qwest.net ####################################################### use strict; use warnings; use POSIX; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use SDBM_File; ###################################### # You may need to configure the following ###################################### my $password = "test"; ## Set the above to whatever you want the admin password to be my $url = "http://sulfericacid.perlmonk.org/rac/rac/secure.pl?lookup="; ## The above is a link to your secure.pl file. Change the url but it must be secure.pl?lookup= at the end ###################################### # Please do not configure anything blow this line ###################################### my $cookiename = "login"; my $favorite = param('flavor'); my $tasty = cookie($cookiename); my $pass = url_param('pass'); my $edituser = url_param('lookup'); my %emails; my $emails = "mylist.dbm"; #change to location of snail mail database my $lookup = url_param('lookup'); tie %emails, 'SDBM_File', $emails, O_CREAT | O_RDWR, 0644; if ( !tied %emails ) { print "database unsuccessful $!.\n"; } # No cookie, so if no favourite value, print new form unless ($tasty eq $password) { print header(-expires=>'now'), start_html("Denied"); print "DENIED"; exit; } print header(); print start_html('Email Management- Address lookup'); ################################################# # User update checking ################################################# if (param('update')) { my $name = param('name'); my $email = param('email'); my $add1 = param('add1'); my $add2 = param('add2'); my $city = param('city'); my $zip = param('zip'); my $country = param('country'); if($email && $name) { if ( exists $emails{$email} && $lookup ne $email) { print "This email address is already being used, please select another."; } else { my $info = join("::", $name, $add1, $add2, $city, $zip, $country); delete $emails{$edituser}; $emails{$email} = "$info"; print "Updated!"; print ""; #exit; } } else { print "A name and email address are required."; } } ################################################# # Edit/Delete button checking ################################################# if (param('delete')) { delete $emails{$edituser}; print "User information was deleted!"; exit; } if (param('edit')) { my ($name, $add1, $add2, $city, $zip, $country) = split(/::/, $emails{$edituser}); print start_form(), table( Tr( td("Name: "), td( textfield( -name => 'name', -default =>"$name", -size => 40 ) ) ), Tr( td("Email: "), td( textfield( -name => 'email', -default =>"$edituser", -size => 40 ) ) ), Tr( td("Address 1: "), td( textfield( -name => 'add1', -default =>"$add1", -size => 40 ) ) ), Tr( td("Address 2: "), td( textfield( -name => 'add2', -default =>"$add2", -size => 40 ) ) ), Tr( td("City/State: "), td( textfield( -name => 'city', -default =>"$city", -size => 40 ) ) ), Tr( td("Zip: "), td( textfield( -name => 'zip', -default =>"$zip", -size => 40 ) ) ), Tr( td("Country: "), td( textfield( -name => 'country', -default =>"$country", -size => 40 ) ) ), Tr( td(), td(submit('update')) ), ), end_form(); exit; } ################################################# # Determine if user is found in database, if so print user data and form buttons ################################################# if ($edituser) { if (exists $emails{$edituser}) { my ($name, $add1, $add2, $city, $zip, $country) = split(/::/, $emails{$edituser}); my $email = $emails{$_}; print "
| ";
print "$name "; if ($add1) { print "$add1 "; } if ($add2 ne "") { print "$add2 "; } if ($city) { print "$city "; } if ($zip) { print "$zip "; } if ($country) { print "$country "; } if ($edituser) { print " $edituser "; } print " | "; print start_form(), submit('edit'), end_form(); print start_form(), submit('delete'), end_form(); print " |