Finally allowed "username@domain.com" to be specified
[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 use MAPSUtil;
27
28 use CGI qw/:standard *table/;
29 use CGI::Carp 'fatalsToBrowser';
30
31 my $userid;
32 my $Userid;
33 my $type = 'black';
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) = OnBlacklist($sender);
50
51     if ($status != 0) {
52       print br {-class => 'error'}, "The email address $sender is already on ${Userid}'s $type list";
53     } else {
54       Add2Blacklist($sender, $userid, $comment);
55       print br "The email address, $sender, has been added to ${Userid}'s $type list";
56
57       # Now remove this entry from the other lists (if present)
58       for my $otherlist ('white', 'null') {
59         my $sth = FindList $otherlist, $sender;
60         my ($sequence, $count);
61
62         ($_, $_, $_, $_, $_, $sequence) = GetList($sth);
63
64         if ($sequence) {
65           $count = DeleteList($otherlist, $sequence);
66           print br "Removed $sender from ${Userid}'s " . ucfirst $otherlist . ' list'
67             if $count > 0;
68
69           ResequenceList($userid, $otherlist);
70         } # if
71       } # for
72     } # if
73
74     $nextseq++;
75   } # while
76 } # Add2List
77
78 # Main
79 $userid = Heading(
80   'getcookie',
81   '',
82   'Add to Black List',
83   'Add to Black List',
84 );
85
86 $Userid = ucfirst $userid;
87
88 SetContext($userid);
89
90 NavigationBar($userid);
91
92 Add2List;
93
94 print start_form {
95   -method       => 'post',
96   -action       => 'processaction.cgi',
97   -name         => 'list'
98 };
99
100 print '<p></p><center>',
101   hidden ({-name => 'type',
102      -default    => $type}),
103   submit ({-name => 'action',
104      -value      => 'Add'}),
105   '</center>';
106
107 Footing;
108
109 exit;