#!/usr/bin/perl -wT #---------------------------------------------------------------------- # heading : Your Settings # description : Domain pseudonyms # longdesc : Manage domain specific pseudonyms # navigation : 100 453 # # Author Stephen Noble dungog.net # #---------------------------------------------------------------------- package esmith; use strict; use CGI ':all'; use CGI::Carp qw(fatalsToBrowser); use esmith::cgi; use esmith::config; use esmith::util; use esmith::db; sub showInitial ($$$); #main form sub performSave ($); sub editEmail ($$); sub performModifyEmail ($); sub removeEmail ($); sub performSelect ($); BEGIN { # Clear PATH and related environment variables so that calls to # external programs do not cause results to be tainted. See # "perlsec" manual page for details. $ENV {'PATH'} = '/usr/sbin:/usr/bin:/usr/local/bin'; $ENV {'SHELL'} = '/bin/bash'; delete $ENV {'ENV'}; } esmith::util::setRealToEffective (); $CGI::POST_MAX=1024 * 100; # max 100K posts $CGI::DISABLE_UPLOADS = 1; # no uploads my %conf; tie %conf, 'esmith::config'; my %accounts; tie %accounts, 'esmith::config', '/home/e-smith/db/accounts'; my %domains; tie %domains, 'esmith::config', '/home/e-smith/db/domains'; my %dungog; tie %dungog, 'esmith::config', '/home/e-smith/db/dungog'; #------------------------------------------------------------ # examine state parameter and display the appropriate form #------------------------------------------------------------ my $q = new CGI; if (! grep (/^state$/, $q->param)) { showInitial ($q, '', ''); } elsif ($q->param ('state') eq "save") { performSave ($q); } elsif ($q->param ('state') eq "edit") { editEmail ($q, ''); } elsif ($q->param ('state') eq "performEmail") { performModifyEmail ($q); } elsif ($q->param ('state') eq "remove") { removeEmail ($q); } elsif ($q->param ('state') eq "select") { performSelect ($q); } else { esmith::cgi::genStateError ($q, \%conf); } exit (0); #------------------------------------------------------------ sub showInitial ($$$) { my ($q, $msg, $passdomain) = @_; my $acct = $ENV{'REMOTE_USER'}; my @domains = (); my $domain = ''; my $userlist = ''; my @selected1 = (); # find domains for this owner foreach my $dom (keys %dungog) { if (db_get_type(\%dungog, $dom) eq 'domain') { my $owner = db_get_prop(\%dungog, $dom, "owner") || ''; if ($owner eq $acct || $owner eq 'everyone') { push (@domains, $dom); $domain = $dom; } #or a member of a group $userlist = db_get_prop(\%accounts, $owner, 'Members') || ''; @selected1 = split (/,/, $userlist); foreach my $user (@selected1) { if ($user eq $acct) { push (@domains, $dom); $domain = $dom; } } } } #change to a passed value if ($passdomain ne '') { $domain = $passdomain; } # find system users in group my $group = db_get_prop(\%accounts, $domain, "group") || 'everyone'; my $userlist2 = db_get_prop(\%accounts, $group, 'Members') || ''; my @selected2 ; if ($group eq 'everyone') { foreach (keys %accounts) { push (@selected2, $_) if (db_get_type(\%accounts, $_) eq 'user'); } } elsif ($group eq 'Administrator') { @selected2 = ($acct); } else { @selected2 = split (/,/, $userlist2); } if ($msg eq '') { esmith::cgi::genHeaderNonCacheable ($q, \%conf, "Domain pseudonyms. "); } else { esmith::cgi::genHeaderNonCacheable ($q, \%conf, "Domain pseudonyms. "); print $q->h4 ('Operation status report'); print $q->p ($msg); print $q->hr; } print $q->startform (-method => 'POST', -action => $q->url (-absolute => 1)); #are there any ? my $domains = @domains; if ($domains == 0) { print $q->p ($q->b ("There are no Domains allocated to user $acct")); } else { print $q->p ("Pseudonyms for the Domain $domain managed by $acct (" . db_get_prop(\%accounts, $acct, 'FirstName') . ' ' . db_get_prop(\%accounts, $acct, 'LastName') . ")."); if ($domains > 1) { print $q->p ($q->td ("You have multiple domains, you can change below...")); foreach (@domains) { print $q->Tr ($q->td ($q->a ({href => $q->url (-absolute => 1) . "?state=select&swap=$_"}, "$_"), " ; ")); } } #commom with userpanel print $q->p ($q->b ("Delegate the domain \"$domain\"")); print $q->Tr (esmith::cgi::genTextRow ($q, 'Forward all email for this domain to a remote mailserver, either use a FQDN mail.domain.net or an IP address. Or leave blank and forward domain specific pseudonyms below ')); print '
'; print $q->Tr (esmith::cgi::genNameValueRow ($q,"Server Name or IP", "MailServer", db_get_prop(\%domains, $domain, "MailServer") || '',)); # get all pseudonyms my @vdemail = (); foreach (keys %accounts) { push (@vdemail, $_) if (db_get_type(\%accounts, $_) eq 'pseudonym'); } # find email for this domain my @vdemail2 = (); foreach (@vdemail) { (my $u, my $d) = split (/@/, $_); push (@vdemail2, $u) if (defined $d and $d eq $domain); } #are there any ? my $vdemail = @vdemail2; if ($vdemail == 0) { print $q->p ($q->b ("There are no pseudonyms for the domain \"$domain\"")); print $q->p ($q->a ({href => $q->url (-absolute => 1) . "?state=edit&domain=$domain&pseu=new2user"}, 'Click here'), 'to add your first pseudonym.'); } else { print $q->p ($q->b ("Current List of pseudonyms for the domain \"$domain\"")); print $q->p ($q->a ({href => $q->url (-absolute => 1) . "?state=edit&domain=$domain&pseu=new2user"}, 'Click here'), "to add another pseudonym."); print "