#!/usr/bin/perl -w use strict; use warnings; use POSIX; use CGI qw/:standard/; require SDBM_File; my %emails; my $list = ""; #change to location of database my $adminmail = 'admin@test.com'; my $sendmail = "/usr/lib/sendmail"; tie %emails, 'SDBM_File', $list, O_CREAT | O_RDWR, 0644; flock($list, 2) || die "flocking failed $!"; if ( !tied %emails ) { print "database unsuccessful $!.\n"; } print header, start_html('Email Management'); print start_form(), table( Tr( td("Name: "), td( textfield( -name => 'name', -size => 40 ) ) ), Tr( td("Email: "), td( textfield( -name => 'email', -size => 40 ) ) ), Tr( td( radio_group( -name => 'update', -values => [ 'add', 'rem' ] ) ), ), Tr( td(), td(submit) ), ), end_form(), hr(); if(param()){ my $email = param('email'); my $name = param('name'); my $update = param('update'); if($name){ if($email){ if($update eq "add"){ if(exists $emails{$email}){ print "Email already exists in database.\n"; } else{ $emails{$email} = $name; print "Email address added to our system!

\n"; print "Database contains:\n"; foreach ( sort keys(%emails) ) { print "$_ => $emails{$_}
"; } } } elsif($update eq "rem"){ if(exists $emails{$email}){ del $emails{$email}; print "Email address was removed from the system.\n"; } else{ print "Oops, it doesn't appear that address is in our database.\n"; } } } else{ print "For this to work please add your email address.\n"; } }else{ print "Unless your name is null, please go back and fill it in.\n"; } } print end_html();