Large MAPS update
[clearscm.git] / maps / bin / add2blacklist.cgi
1 #!/usr/bin/perl
2 ################################################################################
3 #
4 # File:         $RCSfile: add2blacklist.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 = 'black';
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) = OnBlacklist($sender);
49
50     if ($status != 0) {
51       print br {-class => 'error'}, "The email address $sender is already on ${Userid}'s $type list";
52     } else {
53       Add2Blacklist($sender, $userid, $comment);
54       print br "The email address, $sender, has been added to ${Userid}'s $type list";
55
56       # Now remove this entry from the other lists (if present)
57       for my $otherlist ('white', 'null') {
58         my $sth = FindList $otherlist, $sender;
59         my ($sequence, $count);
60
61         ($_, $_, $_, $_, $_, $sequence) = GetList($sth);
62
63         if ($sequence) {
64           $count = DeleteList($otherlist, $sequence);
65           print br "Removed $sender from ${Userid}'s " . ucfirst $otherlist . ' list'
66             if $count > 0;
67
68           ResequenceList($userid, $otherlist);
69         } # if
70       } # for
71     } # if
72
73     $nextseq++;
74   } # while
75 } # Add2List
76
77 # Main
78 $userid = Heading(
79   'getcookie',
80   '',
81   'Add to Black List',
82   'Add to Black List',
83 );
84
85 $Userid = ucfirst $userid;
86
87 SetContext($userid);
88
89 NavigationBar($userid);
90
91 Add2List;
92
93 print start_form {
94   -method       => 'post',
95   -action       => 'processaction.cgi',
96   -name         => 'list'
97 };
98
99 print '<p></p><center>',
100   hidden ({-name => 'type',
101      -default    => $type}),
102   submit ({-name => 'action',
103      -value      => 'Add New Entry'}),
104   '</center>';
105
106 Footing;
107
108 exit;