6b80947dba5ced014c8ead7fac34b4773d6f8c50
[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 use MAPSUtil;
27
28 use CGI qw/:standard *table/;
29 use CGI::Carp 'fatalsToBrowser';
30
31 my $userid;
32 my $Userid;
33 my $type = 'white';
34
35 sub Add2List() {
36   my $sender  = '';
37   my $nextseq = GetNextSequenceNo($userid, $type);
38
39   while () {
40     my $pattern = param "pattern$nextseq";
41     my $domain  = param "domain$nextseq";
42     my $comment = param "comment$nextseq";
43
44     last if ((!defined $pattern || $pattern eq '') &&
45              (!defined $domain  || $domain  eq ''));
46
47     $sender = CheckEmail $pattern, $domain;
48
49     my ($status, $rule) = OnWhitelist($sender, $userid);
50
51     if ($status != 0) {
52       print br {-class => 'error'}, "The email address $sender is already on ${Userid}'s $type list";
53     } else {
54       my $messages = Add2Whitelist($sender, $userid, $comment);
55
56       print br "The email address, $sender, has been added to ${Userid}'s $type list";
57       if ($messages > 0) {
58         if ($messages == 1) {
59           print br 'Your previous message has been delivered';
60         } else {
61           print br "Your previous $messages messages have been delivered";
62         } # if
63       } elsif ($messages == -1) {
64         print br {-class => 'error'}, 'Unable to deliver message';
65       } else {
66         print br 'Unable to find any old messages but future messages will now be delivered.';
67       } # if
68
69       # Now remove this entry from the other lists (if present)
70       for my $otherlist ('black', 'null') {
71         my $sth = FindList($otherlist, $sender);
72         my ($sequence, $count);
73
74         ($_, $_, $_, $_, $_, $sequence) = GetList($sth);
75
76         if ($sequence) {
77           $count = DeleteList($otherlist, $sequence);
78           print br "Removed $sender from ${Userid}'s " . ucfirst $otherlist . ' list'
79             if $count > 0;
80
81           ResequenceList($userid, $otherlist);
82         } # if
83       } # for
84     } # if
85
86     $nextseq++;
87   } # while
88 } # Add2List
89
90 # Main
91 $userid = Heading(
92   'getcookie',
93   '',
94   'Add to White List',
95   'Add to White List',
96 );
97
98 $userid ||= $ENV{USER};
99
100 $Userid = ucfirst $userid;
101
102 SetContext($userid);
103
104 NavigationBar($userid);
105
106 Add2List;
107
108 print start_form {
109   -method => 'post',
110   -action => 'processaction.cgi',
111   -name   => 'list'
112 };
113
114 print '<p></p><center>',
115   hidden ({-name    => 'type',
116            -default => $type}),
117   submit ({-name    => 'action',
118            -value   => 'Add'}),
119   '</center>';
120
121 Footing;
122
123 exit;