dd7068b918f2e4f4b4aea5df504bfac1cf495082
[clearscm.git] / maps / bin / add2whitelist.cgi
1 #!/usr/bin/perl
2 ################################################################################
3 #
4 # File:         $RCSfile: add2whitelist.cgi,v $
5 # Revision:     $Revision: 1.1 $
6 # Description:  Add an email address to the blacklist
7 # Author:       Andrew@DeFaria.com
8 # Created:      Mon Jan 16 20:25:32 PST 2006
9 # Modified:     $Date: 2013/06/12 14:05:47 $
10 # Language:     Perl
11 #
12 # (C) Copyright 2000-2006, Andrew@DeFaria.com, all rights reserved.
13 #
14 ################################################################################
15 use strict;
16 use warnings;
17
18 use FindBin;
19 $0 = $FindBin::Script;
20
21 use lib "$FindBin::Bin/../lib";
22
23 use MAPS;
24 use MAPSLog;
25 use MAPSWeb;
26
27 use CGI qw/:standard *table/;
28 use CGI::Carp 'fatalsToBrowser';
29
30 my $userid;
31 my $Userid;
32 my $type = 'white';
33
34 sub Add2List() {
35   my $sender  = '';
36   my $nextseq = GetNextSequenceNo($userid, $type);
37
38   while () {
39     my $pattern = param "pattern$nextseq";
40     my $domain  = param "domain$nextseq";
41     my $comment = param "comment$nextseq";
42
43     last if ((!defined $pattern || $pattern eq '') &&
44              (!defined $domain  || $domain  eq ''));
45
46     $sender = lc "$pattern\@$domain";
47
48     my ($status, $rule) = OnWhitelist($sender, $userid);
49
50     if ($status != 0) {
51       print br {-class => 'error'}, "The email address $sender is already on ${Userid}'s $type list";
52     } else {
53       my $messages = Add2Whitelist($sender, $userid, $comment);
54
55       print br "The email address, $sender, has been added to ${Userid}'s $type list";
56       if ($messages > 0) {
57         if ($messages == 1) {
58           print br 'Your previous message has been delivered';
59         } else {
60           print br "Your previous $messages messages have been delivered";
61         } # if
62       } elsif ($messages == -1) {
63         print br {-class => 'error'}, 'Unable to deliver message';
64       } else {
65         print br 'Unable to find any old messages but future messages will now be delivered.';
66       } # if
67
68       # Now remove this entry from the other lists (if present)
69       for my $otherlist ('black', 'null') {
70         my $sth = FindList($otherlist, $sender);
71         my ($sequence, $count);
72
73         ($_, $_, $_, $_, $_, $sequence) = GetList($sth);
74
75         if ($sequence) {
76           $count = DeleteList($otherlist, $sequence);
77           print br "Removed $sender from ${Userid}'s " . ucfirst $otherlist . ' list'
78             if $count > 0;
79
80           ResequenceList($userid, $otherlist);
81         } # if
82       } # for
83     } # if
84
85     $nextseq++;
86   } # while
87 } # Add2List
88
89 # Main
90 $userid = Heading(
91   'getcookie',
92   '',
93   'Add to White List',
94   'Add to White List',
95 );
96
97 $userid ||= $ENV{USER};
98
99 $Userid = ucfirst $userid;
100
101 SetContext($userid);
102
103 NavigationBar($userid);
104
105 Add2List;
106
107 print start_form {
108   -method => 'post',
109   -action => 'processaction.cgi',
110   -name   => 'list'
111 };
112
113 print '<p></p><center>',
114   hidden ({-name    => 'type',
115            -default => $type}),
116   submit ({-name    => 'action',
117            -value   => 'Add'}),
118   '</center>';
119
120 Footing;
121
122 exit;