annotate contrib/web/perl-admin/htdocs/subscribers.cgi @ 787:284c640f1b3f

Check return status in mlmmj-perl-admin when adding subscribers (Florian Streibelt, Bitmand)
author Ben Schmidt
date Sun, 21 Nov 2010 00:31:09 +1100
parents 7fefd9a9fad5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
1 #!/usr/bin/perl -w
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
2
657
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
3 # Copyright (C) 2004, 2005, 2006, 2007 Christian Laursen <christian@pil.dk>
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
4 # Copyright (C) 2007 Franky Van Liedekerke <liedekef@telenet.be>
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
5 #
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
6 # $Id$
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
7 #
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
8 # Permission is hereby granted, free of charge, to any person obtaining a copy
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
9 # of this software and associated documentation files (the "Software"), to
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
10 # deal in the Software without restriction, including without limitation the
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
11 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
12 # sell copies of the Software, and to permit persons to whom the Software is
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
13 # furnished to do so, subject to the following conditions:
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
14 #
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
15 # The above copyright notice and this permission notice shall be included in
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
16 # all copies or substantial portions of the Software.
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
17 #
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
19 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
20 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
21 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
22 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
23 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
24 # IN THE SOFTWARE.
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
25
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
26 use strict;
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
27 use URI::Escape;
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
28 use HTML::Entities;
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
29 use CGI;
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
30 use CGI::FastTemplate;
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
31 use Digest::MD5;
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
32
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
33 use vars qw($topdir $templatedir $list);
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
34
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
35 if (exists $ENV{CONFIG_PATH}) {
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
36 require $ENV{CONFIG_PATH};
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
37 } else {
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
38 require "../conf/config.pl";
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
39 }
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
40
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
41 my $mlmmjsub = "/usr/local/bin/mlmmj-sub";
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
42 my $mlmmjunsub = "/usr/local/bin/mlmmj-unsub";
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
43
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
44 my $tpl = new CGI::FastTemplate($templatedir);
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
45
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
46 my $q = new CGI;
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
47 $list = $q->param("list");
388
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
48 my $update = $q->param("update");
546
82f9cc69709e Added a search function
xi
parents: 516
diff changeset
49 my $search = $q->param("search");
82f9cc69709e Added a search function
xi
parents: 516
diff changeset
50 my $email = $q->param("email");
657
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
51 my $file = $q->param("file");
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
52 my $removeall = $q->param("removeall");
546
82f9cc69709e Added a search function
xi
parents: 516
diff changeset
53
82f9cc69709e Added a search function
xi
parents: 516
diff changeset
54 # Everything is submitted from the same form so a little hackery is needed
82f9cc69709e Added a search function
xi
parents: 516
diff changeset
55 # to pick the right action to perform. When doing subscribe and search we
82f9cc69709e Added a search function
xi
parents: 516
diff changeset
56 # don't depend on the submit buttons since hitting enter in either of the
82f9cc69709e Added a search function
xi
parents: 516
diff changeset
57 # text fields will pick the "Subscribe" button.
82f9cc69709e Added a search function
xi
parents: 516
diff changeset
58 #
82f9cc69709e Added a search function
xi
parents: 516
diff changeset
59 # If an email has been entered for subscription, clear the search field.
82f9cc69709e Added a search function
xi
parents: 516
diff changeset
60
82f9cc69709e Added a search function
xi
parents: 516
diff changeset
61 if (defined $email && $email !~ /^$/) {
82f9cc69709e Added a search function
xi
parents: 516
diff changeset
62 $search = undef;
82f9cc69709e Added a search function
xi
parents: 516
diff changeset
63 } else {
82f9cc69709e Added a search function
xi
parents: 516
diff changeset
64 $email = undef;
82f9cc69709e Added a search function
xi
parents: 516
diff changeset
65 }
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
66
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
67 die "no list specified" unless $list;
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
68 die "non-existent list" unless -d("$topdir/$list");
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
69
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
70 $tpl->define(main => "subscribers.html",
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
71 row => "subscribers_row.html");
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
72
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
73 my $action = '';
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
74
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
75 my $subscribers;
552
fee753d23b25 Show list name on configure and subscriber pages as well as the number of
xi
parents: 551
diff changeset
76 my $subcount;
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
77
657
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
78 if (defined $removeall) {
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
79 my $removeall_check = $q->param("removeall_check");
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
80 if ($removeall_check) {
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
81 unlink <$topdir/$list/subscribers.d/*>;
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
82 unlink <$topdir/$list/nomailsubs.d/*>;
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
83 unlink <$topdir/$list/digesters.d/*>;
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
84 $action = "All subscribers have been removed.";
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
85 } else {
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
86 $action = "Safety check not clicked, nothing done.";
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
87 }
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
88 } elsif (defined $file) {
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
89 my $subscriber = $q->param("subscriber");
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
90 my $digester = $q->param("digester");
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
91 my $nomailsub = $q->param("nomailsub");
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
92 my $upload_handle = $q->upload("file");
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
93 binmode $upload_handle;
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
94 while (<$upload_handle>) {
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
95 s/\r?\n$//;
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
96 my $email=$_;
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
97 if ($email =~ /^[a-z0-9\.\-_\@]+$/i) {
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
98 if ($subscriber) {
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
99 system "$mlmmjsub -L $topdir/$list -a $email -U -s";
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
100 }
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
101 if ($digester) {
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
102 system "$mlmmjsub -L $topdir/$list -a $email -Ud -s";
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
103 }
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
104 if ($nomailsub) {
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
105 system "$mlmmjsub -L $topdir/$list -a $email -Un -s";
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
106 }
787
284c640f1b3f Check return status in mlmmj-perl-admin when adding subscribers (Florian
Ben Schmidt
parents: 657
diff changeset
107 if ($? == 0) {
284c640f1b3f Check return status in mlmmj-perl-admin when adding subscribers (Florian
Ben Schmidt
parents: 657
diff changeset
108 $action .= "$email has been subscribed.<br>\n";
284c640f1b3f Check return status in mlmmj-perl-admin when adding subscribers (Florian
Ben Schmidt
parents: 657
diff changeset
109 } else {
284c640f1b3f Check return status in mlmmj-perl-admin when adding subscribers (Florian
Ben Schmidt
parents: 657
diff changeset
110 $action .= "error subscribing $email (code $?)<br>\n";
284c640f1b3f Check return status in mlmmj-perl-admin when adding subscribers (Florian
Ben Schmidt
parents: 657
diff changeset
111 }
657
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
112 } else {
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
113 $action .= '"'.encode_entities($email).'" is not a valid email address.<br>';
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
114 }
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
115 }
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
116 } elsif (defined $email) {
388
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
117 my $subscriber = $q->param("subscriber");
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
118 my $digester = $q->param("digester");
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
119 my $nomailsub = $q->param("nomailsub");
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
120 if ($email =~ /^[a-z0-9\.\-_\@]+$/i) {
388
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
121 if ($subscriber) {
657
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
122 system "$mlmmjsub -L $topdir/$list -a $email -U -s";
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
123 }
388
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
124 if ($digester) {
657
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
125 system "$mlmmjsub -L $topdir/$list -a $email -Ud -s";
388
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
126 }
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
127 if ($nomailsub) {
657
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
128 system "$mlmmjsub -L $topdir/$list -a $email -Un -s";
388
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
129 }
787
284c640f1b3f Check return status in mlmmj-perl-admin when adding subscribers (Florian
Ben Schmidt
parents: 657
diff changeset
130 if ($? == 0) {
284c640f1b3f Check return status in mlmmj-perl-admin when adding subscribers (Florian
Ben Schmidt
parents: 657
diff changeset
131 $action = "$email has been added";
284c640f1b3f Check return status in mlmmj-perl-admin when adding subscribers (Florian
Ben Schmidt
parents: 657
diff changeset
132 } else {
284c640f1b3f Check return status in mlmmj-perl-admin when adding subscribers (Florian
Ben Schmidt
parents: 657
diff changeset
133 $action = "error adding $email (code $?)";
284c640f1b3f Check return status in mlmmj-perl-admin when adding subscribers (Florian
Ben Schmidt
parents: 657
diff changeset
134 }
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
135 } else {
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
136 $action = '"'.encode_entities($email).'" is not a valid email address.';
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
137 }
388
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
138 } elsif (defined $update) {
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
139 my $maxid = $q->param("maxid");
388
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
140 $subscribers = get_subscribers();
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
141 for (my $i = 0; $i < $maxid; ++$i) {
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
142 my $email = $q->param("email$i");
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
143 if (defined $email) {
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
144 if ($email =~ /^[a-z0-9\.\-_\@]+$/i) {
388
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
145 my $updated = 0;
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
146
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
147 my @actions = ();
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
148
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
149 push @actions, {oldstatus => exists $subscribers->{$email}->{subscriber},
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
150 newstatus => defined $q->param("subscriber$i"),
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
151 action => ''};
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
152 push @actions, {oldstatus => exists $subscribers->{$email}->{digester},
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
153 newstatus => defined $q->param("digester$i"),
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
154 action => '-d'};
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
155 push @actions, {oldstatus => exists $subscribers->{$email}->{nomailsub},
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
156 newstatus => defined $q->param("nomailsub$i"),
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
157 action => '-n'};
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
158
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
159 for my $action (@actions) {
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
160 if ($action->{oldstatus} && !$action->{newstatus}) {
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
161 system "$mlmmjunsub -L $topdir/$list -a $email $action->{action}";
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
162 $updated = 1;
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
163 } elsif (!$action->{oldstatus} && $action->{newstatus}) {
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
164 system "$mlmmjsub -L $topdir/$list -a $email $action->{action}";
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
165 $updated = 1;
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
166 }
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
167 }
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
168
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
169 if ($updated) {
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
170 $action .= "Subscription for $email has been updated.<br>\n";
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
171 }
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
172 } else {
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
173 $action .= '"'.encode_entities($email).'" is not a valid email address.'."<br>\n";
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
174 }
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
175 }
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
176 }
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
177 }
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
178
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
179 $tpl->assign(ACTION => $action);
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
180
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
181 $subscribers = get_subscribers();
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
182
547
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
183 my $paginator = '';
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
184 my $page = $q->param('page');
657
7fefd9a9fad5 Merged changes from Franky Van Liedekerke <liedekef@telenet.be>:
xi
parents: 552
diff changeset
185 $page = 0 unless defined $page && $page =~ /^\d+$/;
547
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
186 if (keys %$subscribers > 50) {
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
187 $paginator = 'Pages: ';
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
188 my $pages = (keys %$subscribers) / 50;
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
189 $page = 0 unless ($page >= 0 && $page < $pages);
551
6f12e58e4e7d Add missing &
xi
parents: 550
diff changeset
190 my $searchstr = (defined $search && $search ne '') ? '&search='.uri_escape($search) : '';
547
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
191
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
192 for (my $i = 0; $ i < $pages; ++$i) {
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
193 if ($page == $i) {
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
194 $paginator .= ($i + 1)."&nbsp;";
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
195 } else {
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
196 $paginator .= "<a href=\"?list=".uri_escape($list)."&page=$i$searchstr\">".($i + 1)."</a>&nbsp;";
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
197 }
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
198 }
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
199 }
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
200
388
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
201 my $i = 0;
547
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
202 my @addresses = sort {lc $a cmp lc $b} keys %$subscribers;
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
203 if ($paginator ne '') {
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
204 @addresses = @addresses[$page * 50 .. ($page + 1) * 50 - 1];
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
205 pop @addresses until defined $addresses[@addresses - 1];
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
206 }
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
207
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
208 for my $address (@addresses) {
388
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
209 $tpl->assign(EMAIL => $address,
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
210 ID => $i++,
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
211 SCHECKED => $subscribers->{$address}->{subscriber} ? 'checked' : '',
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
212 DCHECKED => $subscribers->{$address}->{digester} ? 'checked' : '',
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
213 NCHECKED => $subscribers->{$address}->{nomailsub} ? 'checked' : '');
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
214 $tpl->parse(ROWS => '.row');
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
215 }
388
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
216 if (keys %$subscribers == 0) {
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
217 $tpl->assign(ROWS => '');
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
218 }
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
219
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
220 $tpl->assign(LIST => encode_entities($list),
547
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
221 MAXID => scalar(@addresses),
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
222 SEARCH => defined $search ? $search : '',
ccba16f72354 Added pagination
xi
parents: 546
diff changeset
223 PAGINATOR => $paginator,
552
fee753d23b25 Show list name on configure and subscriber pages as well as the number of
xi
parents: 551
diff changeset
224 PAGE => $page,
fee753d23b25 Show list name on configure and subscriber pages as well as the number of
xi
parents: 551
diff changeset
225 SUBCOUNT => $subcount);
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
226
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
227 print "Content-type: text/html\n\n";
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
228
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
229 $tpl->parse(CONTENT => "main");
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
230 $tpl->print;
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
231
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
232 sub get_subscribers {
388
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
233 my %subscribers = ();
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
234
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
235 my @subscribers = `/usr/local/bin/mlmmj-list -L $topdir/$list`;
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
236 my @digesters = `/usr/local/bin/mlmmj-list -L $topdir/$list -d`;
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
237 my @nomailsubs = `/usr/local/bin/mlmmj-list -L $topdir/$list -n`;
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
238
388
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
239 chomp @subscribers;
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
240 chomp @digesters;
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
241 chomp @nomailsubs;
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
242
546
82f9cc69709e Added a search function
xi
parents: 516
diff changeset
243 if (defined $search) {
548
79b94f047b30 Make search case insensitive
xi
parents: 547
diff changeset
244 $search = lc $search;
79b94f047b30 Make search case insensitive
xi
parents: 547
diff changeset
245 @subscribers = grep {index(lc $_, $search) != -1} @subscribers;
79b94f047b30 Make search case insensitive
xi
parents: 547
diff changeset
246 @digesters = grep {index(lc $_, $search) != -1} @digesters;
79b94f047b30 Make search case insensitive
xi
parents: 547
diff changeset
247 @nomailsubs = grep {index(lc $_, $search) != -1} @nomailsubs;
546
82f9cc69709e Added a search function
xi
parents: 516
diff changeset
248 }
82f9cc69709e Added a search function
xi
parents: 516
diff changeset
249
388
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
250 for my $address (@subscribers) {
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
251 $subscribers{$address}->{subscriber} = 1;
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
252 }
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
253
388
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
254 for my $address (@digesters) {
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
255 $subscribers{$address}->{digester} = 1;
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
256 }
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
257
388
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
258 for my $address (@nomailsubs) {
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
259 $subscribers{$address}->{nomailsub} = 1;
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
260 }
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
261
552
fee753d23b25 Show list name on configure and subscriber pages as well as the number of
xi
parents: 551
diff changeset
262 $subcount = scalar(keys %subscribers);
fee753d23b25 Show list name on configure and subscriber pages as well as the number of
xi
parents: 551
diff changeset
263
388
b58c5059749e perl interface update from xi
mmj
parents: 359
diff changeset
264 return \%subscribers;
359
ca217febcfbd Rerwrite the way listtexts are handled and move Subject: out into the file
mmj
parents:
diff changeset
265 }