-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathezmlm-web.cgi
executable file
·3084 lines (2589 loc) · 88.8 KB
/
ezmlm-web.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
#===========================================================================
# ezmlm-web.cgi - version 3.3.1
# $Id$
#
# This file is part of ezmlm-web.
#
# All user configuration happens in the config file ``ezmlmwebrc''
# POD documentation is at the end of this file
#
# Copyright (C) 1999-2000, Guy Antony Halse, All Rights Reserved.
# Copyright (C) 2005-2008, Lars Kruse, All Rights Reserved.
#
# ezmlm-web is distributed under a BSD-style license. Please refer to
# the copyright file included with the release for details.
# ==========================================================================
package ezmlm_web;
# Modules to include
use strict;
use Getopt::Std;
use ClearSilver;
use Mail::Ezmlm;
use File::Copy;
use File::Path;
use DB_File;
use CGI;
use IO::File;
use POSIX;
use English;
use MIME::QuotedPrint;
# optional modules - they will be loaded later if they are available
#Encode
#POSIX
#Mail::Ezmlm::GpgEzmlm
#Mail::Ezmlm::GpgKeyRing
#Mail::Address OR Email::Address
my $mail_address_package;
# we can use either the Mail::Address or the Email::Address module
# "Mail::Address" was used exclusively until ezmlm-web v3.2, thus it is proven
# to work with ezmlm-web
# the downside of Mail::Address is, that it is not available in the debian
# distribution
if (&safely_import_module("Mail::Address")) {
$mail_address_package = "Mail::Address";
} elsif (&safely_import_module("Email::Address")) {
$mail_address_package = "Email::Address";
} else {
die "Failed to import the Mail::Address and the Email::Address module.\n" .
"At least one of these modules is required for ezmlm-web.\n";
}
# the Encode module is optional - we do not break if it is absent
my $ENCODE_SUPPORT = 1;
unless (&safely_import_module("Encode")) {
$ENCODE_SUPPORT = 0;
warn "Encoding module is not available - charset conversion will fail!";
}
################## some preparations at the beginning ##################
# drop privileges (necessary for calling gpg)
# this should not do any other harm
$UID = $EUID;
$GID = $EGID;
my $VERSION;
$VERSION = '3.3.1';
my $q = new CGI;
$q->import_names('Q');
use vars qw[$opt_c $opt_d $opt_C];
getopts('cd:C:');
# Suid stuff requires a secure path.
# The following three lines are taken from "man perlrun"
$ENV{PATH} = '/bin';
$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
# We run suid so we can't use $ENV{'HOME'} and $ENV{'USER'} to determine the
# user. :( Don't alter this line unless you are _sure_ you have to.
my @tmp = getpwuid($>); use vars qw[$USER]; $USER=$tmp[0];
# defined by our environment - see above
use vars qw[$HOME_DIR]; $HOME_DIR=$tmp[7];
# use strict is a good thing++
# some configuration settings
use vars qw[$DEFAULT_OPTIONS $UNSAFE_RM $ALIAS_USER $LIST_DIR];
use vars qw[$QMAIL_BASE $PRETTY_NAMES $DOTQMAIL_DIR];
use vars qw[$FILE_UPLOAD $WEBUSERS_FILE $MAIL_DOMAIN $HTML_TITLE];
use vars qw[$TEMPLATE_DIR $LANGUAGE_DIR $HTML_LANGUAGE];
use vars qw[$HTML_CSS_COMMON $HTML_CSS_COLOR];
use vars qw[$MAIL_ADDRESS_PREFIX @HTML_LINKS];
use vars qw[@INTERFACE_OPTIONS_BLACKLIST];
use vars qw[$DEBUG];
# default interface template (basic/normal/expert)
use vars qw[$DEFAULT_INTERFACE_TYPE];
# some settings for encrypted mailing lists
use vars qw[$ENCRYPTION_SUPPORT $GPG_KEYRING_DEFAULT_LOCATION];
# settings for multi-domain setups
use vars qw[%DOMAINS $CURRENT_DOMAIN];
# some deprecated configuration settings - they have to be registered
# otherwise old configuration files would break
use vars qw[$HTML_CSS_FILE]; # replaced by HTML_CSS_COMMON since v3.2
# Get user configuration stuff
my $config_file;
if (defined($opt_C)) {
$opt_C =~ /^([-\w.\/]+)$/; # security check by ooyama
$config_file = $1; # Command Line
} elsif (defined($ENV{EZMLM_WEB_RC}) && $ENV{EZMLM_WEB_RC} =~ /^(\/[^\`]+)$/) {
$config_file = $1;
} elsif (-e "$HOME_DIR/.ezmlmwebrc") {
$config_file = "$HOME_DIR/.ezmlmwebrc"; # User
} elsif (-e "/etc/ezmlm-web/ezmlmwebrc") {
$config_file = "/etc/ezmlm-web/ezmlmwebrc"; # System (new style - since v2.2)
} elsif (-e "/etc/ezmlm/ezmlmwebrc") {
$config_file = "/etc/ezmlm/ezmlmwebrc"; # System (old style - up to v2.1)
} else {
&fatal_error("Unable to find config file");
}
unless (my $return = do $config_file) {
if ($@) {
&fatal_error("Failed to parse the config file ($config_file): $@");
} elsif (!defined $return) {
&fatal_error("Failed to read the config file ($config_file): $!");
} else {
# the last statement of the config file return False -> this is ok
}
}
# define some more variables, that may not be manipulated via the config
# file
# "pagedata" contains the hdf tree for clearsilver
# "pagename" refers to the template file that should be used
# "ui_template" is one of "basic", "normal" and "expert"
use vars qw[$pagedata $pagename];
use vars qw[$error $customError $warning $customWarning $success];
use vars qw[$ui_template $LOGIN_NAME];
use vars qw[$posix_enabled $child_return];
# cached data
use vars qw[%CACHED_DATA];
# available features
use vars qw[%FEATURES];
####### validate configuration and apply some default settings ##########
# do we support encrypted mailing lists an keyring management?
$ENCRYPTION_SUPPORT = 0 unless defined($ENCRYPTION_SUPPORT);
if ($ENCRYPTION_SUPPORT) {
$FEATURES{GPGEZMLM} = (0==0)
if (&safely_import_module("Mail::Ezmlm::GpgEzmlm"));
$FEATURES{GPGKEYRING} = (0==0)
if (&safely_import_module("Mail::Ezmlm::GpgKeyRing"));
# did we load any modules?
if (scalar keys %FEATURES == 0) {
warn "WARNING: all of the supported encryption modules "
. "(Mail::Ezmlm::GpgEzmlm and Mail::Ezmlm::GpgKeyRing) failed "
. "to load. Encryption support is disabled.";
$ENCRYPTION_SUPPORT = 0;
}
}
# Allow suid wrapper to override default list directory ...
if (defined($opt_d)) {
$LIST_DIR = $1 if ($opt_d =~ /^([-\@\w.\/]+)$/);
}
# check required configuration settings
&fatal_error("Configuration setting 'LIST_DIR' not specified!")
unless (defined($LIST_DIR));
&fatal_error("Configuration setting 'LANGUAGE_DIR' not specified!")
unless (defined($LANGUAGE_DIR));
&fatal_error("Configuration setting 'TEMPLATE_DIR' not specified!")
unless (defined($TEMPLATE_DIR));
# If WEBUSERS_FILE is not defined in ezmlmwebrc (as before version 2.2),
# then use former default value for compatibility
$WEBUSERS_FILE = $LIST_DIR . '/webusers' unless (defined($WEBUSERS_FILE));
# check for non-default dotqmail directory
$DOTQMAIL_DIR = $HOME_DIR unless defined($DOTQMAIL_DIR);
# check default options for new mailing lists
$DEFAULT_OPTIONS = 'aBDFGHiJkLMNOpQRSTUWx' unless defined($DEFAULT_OPTIONS);
# check default language
$HTML_LANGUAGE = 'en' unless defined($HTML_LANGUAGE);
# check stylesheet
# HTML_CSS_FILE was replaced by HTML_CSS_COMMON in v3.2
unless (defined($HTML_CSS_COMMON)) {
# HTML_CSS_COMMON is undefined - we will check the deprecated setting first
if (defined($HTML_CSS_FILE)) {
# ok - we fall back to the deprecated setting
$HTML_CSS_COMMON = $HTML_CSS_FILE;
} else {
# nothing is defined - we use the default value
$HTML_CSS_COMMON = '/ezmlm-web/default.css';
}
}
# CSS color scheme
$HTML_CSS_COLOR = '/ezmlm-web/color-red-blue.css'
unless defined($HTML_CSS_COLOR);
# check template directory
$TEMPLATE_DIR = 'template' unless defined($TEMPLATE_DIR);
# check QMAIL_BASE
$QMAIL_BASE = '/var/qmail/control' unless defined($QMAIL_BASE);
# check UNSAFE_RM
$UNSAFE_RM = 0 unless defined($UNSAFE_RM);
# check PRETTY_NAMES
$PRETTY_NAMES = 0 unless defined($PRETTY_NAMES);
# check FILE_UPLOAD
$FILE_UPLOAD = 1 unless defined($FILE_UPLOAD);
# check ALIAS_USER
$ALIAS_USER = 'alias' unless defined($ALIAS_USER);
# check HTML_TITLE
$HTML_TITLE = '' unless defined($HTML_TITLE);
# check HTML_LINKS
@HTML_LINKS = () unless defined(@HTML_LINKS);
# check DEFAULT_INTERFACE_TYPE
$DEFAULT_INTERFACE_TYPE = 'normal' unless defined($DEFAULT_INTERFACE_TYPE);
# check possible blacklist of interface options (since v3.3)
@INTERFACE_OPTIONS_BLACKLIST = () unless defined(@INTERFACE_OPTIONS_BLACKLIST);
# check the configured detault location of gnupg keyrings
$GPG_KEYRING_DEFAULT_LOCATION = ".gnupg"
unless defined($GPG_KEYRING_DEFAULT_LOCATION);
# undef CURRENT_DOMAIN if it is invalid
if (%DOMAINS) {
undef $CURRENT_DOMAIN
if (defined($CURRENT_DOMAIN) && ($CURRENT_DOMAIN eq ''));
}
# determine MAIL_DOMAIN
unless (defined($MAIL_DOMAIN) && ($MAIL_DOMAIN ne '')) {
if ((-e "$QMAIL_BASE/virtualdomains")
&& open(VD, "<$QMAIL_BASE/virtualdomains")) {
# Work out if this user has a virtual host and set input accordingly ...
while(<VD>) {
last if (($MAIL_DOMAIN) = /(.+?):$USER/);
}
close VD;
}
# use 'defaultdomain' or 'me' if no matching virtualdomain was found
if (defined($MAIL_DOMAIN) && ($MAIL_DOMAIN ne '')) {
# the prefix is empty for virtual domains
$MAIL_ADDRESS_PREFIX = "" unless (defined($MAIL_ADDRESS_PREFIX));
} else {
# Work out default domain name from qmail (for David Summers)
if (open(GETHOST, "<$QMAIL_BASE/defaultdomain")
|| open(GETHOST, "<$QMAIL_BASE/me")) {
chomp($MAIL_DOMAIN = <GETHOST>);
close GETHOST;
} else {
&fatal_error("Unable to read $QMAIL_BASE/me: $!");
}
}
}
# check MAIL_ADDRESS_PREFIX
unless (defined($MAIL_ADDRESS_PREFIX)) {
if ($USER eq $ALIAS_USER) {
$MAIL_ADDRESS_PREFIX = "";
} else {
$MAIL_ADDRESS_PREFIX = "$USER-"
}
}
# check DEBUG - enable debug messages if set > 0
$DEBUG = 0 unless defined($DEBUG);
if ( $DEBUG > 0 ) {
eval "use warnings";
eval "use CGI::Carp qw(fatalsToBrowser warningsToBrowser)";
eval "use CGI qw(:standard)";
}
# get the current login name advertised to the webserver (if it is defined)
$LOGIN_NAME = lc($ENV{'REMOTE_USER'});
# Remove leading and trailing whitespace (they are ignored by http-auth).
# Otherwise the webauth check does not work properly.
$LOGIN_NAME =~ s/^\s+//;
$LOGIN_NAME =~ s/\s+$//;
# check if the POSIX module is available
$posix_enabled = &safely_import_module("POSIX");
###################### process a request ########################
# Untaint form input ...
&untaint;
my $pagedata = &init_hdf();
my $list;
my $action;
$action = defined($q->param('action'))
? $q->param('action')
: '';
# get the list object
if (defined($q->param('list'))) {
$list = get_list_object($q->param('list'));
} else {
$list = undef;
}
# This is where we decide what to do, depending on the form state and the
# user's chosen course of action ...
# TODO: unify all these "is list param set?" checks ...
if (defined($action) && ($action eq 'show_mime_examples')) {
&output_mime_examples();
exit 0;
} elsif (%DOMAINS
&& (!defined($CURRENT_DOMAIN) || ($action eq 'domain_select'))) {
# domain support is enabled, but no domain is selected
$pagename = 'domain_select';
# undef the currently selected domain
undef $CURRENT_DOMAIN;
} elsif (!&check_permission_for_action()) {
$pagename = 'list_select';
$error = 'Forbidden';
} elsif (defined($action) && ($action eq '' || $action eq 'list_select')) {
# Default action. Present a list of available lists to the user ...
$pagename = 'list_select';
} elsif ($action eq 'show_page') {
$pagename = $q->param('pagename');
unless (-e "$TEMPLATE_DIR/$pagename.cs") {
$pagename = 'list_select';
$error = 'UnknownAction';
}
} elsif ($action eq 'subscribers') {
# display list (or part list) subscribers
if ($list) {
$pagename = 'subscribers';
} else {
$pagename = 'list_select';
$error = 'ParameterMissing';
}
} elsif ($action eq 'address_del') {
# Delete a subscriber ...
if ($list) {
$success = 'DeleteAddress' if (&delete_address($list));
$pagename = 'subscribers';
} else {
$error = 'ParameterMissing';
$pagename = 'list_select';
}
} elsif ($action eq 'address_add') {
# Add a subscriber ...
# no selected addresses -> no error
if ($list) {
$success = 'AddAddress' if (&add_address($list));
$pagename = 'subscribers';
} else {
$error = 'ParameterMissing';
$pagename = 'list_select';
}
} elsif ($action eq 'download_subscribers') {
# requesting a text file of all subscribers
if ($list) {
&download_subscribers($list);
# just in case we return (something bad happened)
$pagename = 'subscribers';
} else {
$pagename = 'list_select';
$error = 'ParameterMissing';
}
} elsif ($action eq 'subscribe_log') {
if ($list) {
&set_pagedata_subscription_log($list);
$pagename = 'show_subscription_log';
} else {
$pagename = 'list_select';
$error = 'ParameterMissing';
}
} elsif ($action eq 'list_delete_ask') {
# Confirm list removal
if ($list) {
$pagename = 'list_delete';
} else {
$pagename = 'list_select';
$error = 'ParameterMissing';
}
} elsif ($action eq 'list_delete_do') {
# User really wants to delete a list ...
if ($list) {
$success = 'DeleteList' if (&delete_list($list));
$list = undef;
} else {
$error = 'ParameterMissing';
}
$pagename = 'list_select';
} elsif ($action eq 'list_create_ask') {
# User wants to create a list ...
$pagename = 'list_create';
} elsif ($action eq 'list_create_do') {
# create the new list
# Message if list creation is unsuccessful ...
if (defined($q->param('new_list'))) {
if ($list = &create_list($q->param('new_list'))) {
$success = 'CreateList';
$pagename = 'subscribers';
} else {
$pagename = 'list_create';
}
} else {
$error = 'ParameterMissing';
}
} elsif (($action eq 'config_ask') || ($action eq 'config_do')) {
# User wants to see/change the configuration ...
my $subset = $q->param('config_subset');
if ($list && ($subset ne '')) {
if ($subset =~ m/^RESERVED-([\w_-]*)$/) {
$pagename = $1
} elsif (($subset =~ /^[\w]*$/)
&& (-e "$TEMPLATE_DIR/config_$subset" . ".cs")) {
$pagename = 'config_' . $subset;
} else {
$pagename = '';
}
if ($pagename ne '') {
$success = 'UpdateConfig'
if (($action eq 'config_do') && &update_config($list));
} else {
$error = 'UnknownConfigPage';
warn "missing config page: $subset";
$pagename = 'list_select';
}
} else {
$error = 'ParameterMissing';
$pagename = 'list_select';
}
} elsif ($FEATURES{GPGEZMLM} && ($action eq 'gpgezmlm_convert_ask')) {
if ($list) {
$pagename = 'gpgezmlm_convert';
} else {
$pagename = 'list_select';
$error = 'ParameterMissing';
}
} elsif ($FEATURES{GPGEZMLM} && ($action eq 'gpgezmlm_convert_enable')) {
if (!defined($list)) {
$pagename = 'list_select';
$error = 'ParameterMissing';
} elsif (ref($list) && $list->isa("Mail::Ezmlm::GpgEzmlm")) {
$pagename = 'gpgezmlm_convert';
$warning = 'GpgEzmlmConvertAlreadyEnabled';
} else {
my $enc_list = Mail::Ezmlm::GpgEzmlm->convert_to_encrypted($list->thislist());
if ($enc_list) {
$list = $enc_list;
# if the keyring already contains a secret key, then we do not
# need to generate a new one
my $keyring = get_keyring($list);
my @secret_keys = $keyring->get_secret_keys();
if ($#secret_keys >= 0) {
$pagename = 'gnupg_secret';
} else {
$pagename = 'gnupg_generate_key';
}
$success = 'GpgEzmlmConvertEnable';
} else {
$pagename = 'gpgezmlm_convert';
$warning = 'GpgEzmlmConvertEnable';
}
}
} elsif ($FEATURES{GPGEZMLM} && ($action eq 'gpgezmlm_convert_disable')) {
if (!defined($list)) {
$pagename = 'list_select';
$error = 'ParameterMissing';
} elsif (ref($list) && $list->isa("Mail::Ezmlm::GpgEzmlm")) {
my $plain_list = $list->convert_to_plaintext();
if ($plain_list) {
$list = $plain_list;
$pagename = 'gpgezmlm_convert';
$success = 'GpgEzmlmConvertDisable';
} else {
$pagename = 'gpgezmlm_convert';
$warning = 'GpgEzmlmConvertDisable';
}
} else {
$pagename = 'gpgezmlm_convert';
$warning = 'GpgEzmlmConvertAlreadyDisabled';
}
} elsif ($FEATURES{GPGKEYRING} && (($action eq 'gnupg_ask') ||
($action eq 'gnupg_do'))) {
# User wants to manage keys (only for encrypted mailing lists)
my $subset = $q->param('gnupg_subset');
if ($list && ($subset ne '')) {
if (($subset =~ /^[\w]*$/)
&& (-e "$TEMPLATE_DIR/gnupg_$subset" . ".cs")) {
if ($action eq 'gnupg_do') {
if (&manage_gnupg_keys($list)) {
# some functions may set 'success' on their own
$success = 'UpdateGnupg' unless $success;
}
} else {
# warnings are defined in the respective subs
$pagename = 'gnupg_' . $subset;
}
} else {
$error = 'UnknownGnupgPage';
warn "missing gnupg page: $subset";
$pagename = 'list_select';
}
} else {
$error = 'ParameterMissing';
$pagename = 'list_select';
}
} elsif ($FEATURES{GPGKEYRING} && ($action eq 'gnupg_export')) {
if ($list && defined($q->param('gnupg_keyid'))) {
if (&gnupg_export_key($list, $q->param('gnupg_keyid'))) {
# the key was printed to stdout - we can exit now
# TODO: this should be something like "skip_output" instead
exit 0;
} else {
$warning = 'GnupgExportKey';
# pagename is quite random here ...
$pagename = 'gnupg_public';
}
} else {
$error = 'ParameterMissing';
$pagename = 'list_select';
}
} elsif ($action eq 'textfiles') {
# Edit DIR/text ...
if ($list) {
$pagename = 'textfiles';
} else {
$error = 'ParameterMissing';
$pagename = 'list_select';
}
} elsif ($action eq 'textfile_edit') {
# edit the content of a text file
if ($list && defined($q->param('file'))) {
if (!&check_filename($q->param('file'))) {
$error = 'InvalidFileName';
$pagename = 'textfiles';
} else {
$pagename = 'textfile_edit';
}
} else {
$error = 'ParameterMissing';
$pagename = 'list_select';
}
} elsif ($action eq 'textfile_save') {
# User wants to save a new version of something in DIR/text ...
if ($list && defined($q->param('file')) && defined($q->param('content'))) {
if (!&check_filename($q->param('file'))) {
$error = 'InvalidFileName';
$pagename = 'textfiles';
} elsif (&save_text($list)) {
$pagename = 'textfiles';
$success = 'SaveFile';
} else {
$warning = 'SaveFile';
$pagename = 'textfile_edit';
}
} else {
$error = 'ParameterMissing';
if ($list) {
$pagename = 'textfiles';
} else {
$pagename = 'list_select';
}
}
} elsif ($action eq 'textfile_reset') {
# User wants to remove a customized text file (idx >= 5) ...
if ($list && defined($q->param('file'))) {
if (!&check_filename($q->param('file'))) {
$error = 'InvalidFileName';
$pagename = 'textfiles';
} elsif (Mail::Ezmlm->get_version() < 5) {
$warning = 'RequiresIDX5';
$pagename = 'textfile_edit';
} elsif ($list->is_text_default($q->param('file'))) {
$warning = 'ResetFileIsDefault';
$pagename = 'textfile_edit';
} elsif ($list->reset_text($q->param('file'))) {
$success = 'ResetFile';
$pagename = 'textfiles';
} else {
$warning = 'ResetFile';
$pagename = 'textfile_edit';
}
} else {
$error = 'ParameterMissing';
if ($list) {
$pagename = 'textfiles';
} else {
$pagename = 'list_select';
}
}
} else {
$pagename = 'list_select';
$error = 'UnknownAction';
}
# read the current state (after the changes are done)
&set_pagedata($list);
# set default action, if there is no list available and the user is
# allowed to create a new one
if (((!defined($action)) || ($action eq ''))
&& ((%DOMAINS && defined($CURRENT_DOMAIN)) || (!%DOMAINS))
&& &webauth_create_list($WEBUSERS_FILE)
&& ($pagedata->getValue('Data.Lists.0','') eq '')) {
$pagename = 'list_create';
}
# Print page and exit :) ...
&output_page;
exit;
# =========================================================================
sub init_hdf {
# initialize the data for clearsilver
my $hdf = ClearSilver::HDF->new();
&fatal_error("Language data dir ($LANGUAGE_DIR) not found!")
unless (-e $LANGUAGE_DIR);
$hdf->setValue("LanguageDir", "$LANGUAGE_DIR/");
&fatal_error("Template dir ($TEMPLATE_DIR) not found!")
unless (-e $TEMPLATE_DIR);
$hdf->setValue("TemplateDir", "$TEMPLATE_DIR/");
# easy/normal/expert
my $one_template;
my @all_templates = &get_available_interfaces();
if (defined($q->param('template'))) {
foreach $one_template (@all_templates) {
$ui_template = $q->param('template')
if ($q->param('template') eq $one_template);
}
}
$ui_template = $DEFAULT_INTERFACE_TYPE unless defined($ui_template);
$hdf->setValue("Config.UI.LinkAttrs.template", $ui_template);
# retrieve available interface sets and add them to the dataset
my %interfaces = &get_available_interfaces();
my $interface;
foreach $interface (keys %interfaces) {
$hdf->setValue("Config.UI.Interfaces.$interface",
$interfaces{$interface});
}
# retrieve available languages and add them to the dataset
my %languages = &get_available_interface_languages();
my $lang;
foreach $lang (sort keys %languages) {
$hdf->setValue("Config.UI.Languages.$lang", $languages{$lang});
}
$hdf = &load_interface_language($hdf);
$hdf->setValue("ScriptName", $ENV{SCRIPT_NAME})
if (defined($ENV{SCRIPT_NAME}));
$hdf->setValue("Stylesheet.0", "$HTML_CSS_COMMON");
$hdf->setValue("Stylesheet.1", "$HTML_CSS_COLOR");
$hdf->setValue("Config.PageTitle", "$HTML_TITLE");
my $i;
for $i (0 .. $#HTML_LINKS) {
$hdf->setValue("Config.PageLinks.$i.name", $HTML_LINKS[$i]{name});
$hdf->setValue("Config.PageLinks.$i.url", $HTML_LINKS[$i]{url});
$i++;
}
# support for encryption?
$hdf->setValue("Config.Features.GpgEzmlm", 1) if ($FEATURES{GPGEZMLM});
$hdf->setValue("Config.Features.GpgKeyRing", 1) if ($FEATURES{GPGKEYRING});
# enable some features that are only available for specific versions
# of ezmlm-idx
if (Mail::Ezmlm->get_version() >= 5.1) {
$hdf->setValue("Config.Features.KeepFiles", 1);
}
if (Mail::Ezmlm->get_version() >= 5) {
$hdf->setValue("Config.Features.LanguageSelect", 1);
$hdf->setValue("Config.Features.CharsetSelect", 1);
$hdf->setValue("Config.Features.CopyLines", 1);
}
$hdf->setValue("Config.Version.ezmlm_web", "$VERSION");
return $hdf;
}
# =========================================================================
sub output_page {
# Print the page
my $ui_template_file = "$TEMPLATE_DIR/ui/${ui_template}.hdf";
&fatal_error("UI template file ($ui_template_file) not found")
unless (-e $ui_template_file);
$pagedata->readFile($ui_template_file);
$pagedata->setValue('Data.Success', "$success") if (defined($success));
$pagedata->setValue('Data.Error', "$error") if (defined($error));
$pagedata->setValue('Data.Warning', "$warning") if (defined($warning));
$pagedata->setValue('Data.customError', "$customError")
if (defined($customError));
$pagedata->setValue('Data.customWarning', "$customWarning")
if (defined($customWarning));
$pagedata->setValue('Data.Action', "$pagename");
my $pagefile = $TEMPLATE_DIR . "/main.cs";
&fatal_error("main template ($pagefile) not found!")
unless (-e "$pagefile");
&fatal_error("sub template ($TEMPLATE_DIR/$pagename.cs) not found!")
unless (-e "$TEMPLATE_DIR/$pagename.cs");
# print http header
print "Content-Type: text/html; charset=utf-8\n\n";
my $cs = ClearSilver::CS->new($pagedata);
$cs->parseFile($pagefile);
my $output;
if ($output = $cs->render()) {
print $output;
} else {
&fatal_error($cs->displayError());
}
}
# ---------------------------------------------------------------------------
# create the list object - also check for encryption and other modules
sub get_list_object {
my $listname = shift;
my ($list, @module_order, $one_module);
@module_order = ();
# gpg-ezmlm
push(@module_order, "Mail::Ezmlm::GpgEzmlm")
if ($FEATURES{GPGEZMLM});
# default
push(@module_order, "Mail::Ezmlm");
for $one_module (@module_order) {
$list = $one_module->new("$LIST_DIR/$listname");
# invalid lists are undef
return $list if (defined($list) && (defined($list->thislist())));
}
return undef;
}
# ---------------------------------------------------------------------------
sub load_interface_language {
my ($data) = @_;
my $config_language;
# load default language (configured or 'en') first
# this will serve as a fallback
#
# we do not have to load 'en' separately as a fallback, because partly
# translated language files always include the English default for all
# missing strings
if (&check_interface_language($HTML_LANGUAGE)) {
$config_language = "$HTML_LANGUAGE";
} else {
$config_language = 'en';
}
$data->readFile("$LANGUAGE_DIR/$config_language" . ".hdf");
# check for preferred browser language
my $prefLang = &get_browser_language();
# take it, if a supported browser language was found
$config_language = $prefLang unless ($prefLang eq '');
######### temporary language setting? ############
# the default language can be overriden by the language selection form
if ($q->param('web_lang')) {
my $weblang = $q->param('web_lang');
if (&check_interface_language($weblang)) {
# load the data
$config_language = "$weblang";
} else {
# no valid language was selected - so you may ignore it
$warning = 'InvalidLanguage';
}
}
# add the setting to every link
$data->setValue('Config.UI.LinkAttrs.web_lang', "$config_language");
# import the configured resp. the temporarily selected language
$data->readFile("$LANGUAGE_DIR/$config_language" . ".hdf");
return $data;
}
# ---------------------------------------------------------------------------
sub get_browser_language {
# look for preferred browser language setting
# this code was adapted from Per Cederberg
# http://www.percederberg.net/home/perl/select.perl
# it returns an empty string, if no supported language was found
my ($lang_main, $lang_sub, $lang_name, $one_lang, @langs, @res);
my (@main_langs);
# Use language preference settings
if (defined($ENV{HTTP_ACCEPT_LANGUAGE})
&& ($ENV{HTTP_ACCEPT_LANGUAGE} ne '')) {
@langs = split(/,/, $ENV{HTTP_ACCEPT_LANGUAGE});
} else {
return "";
}
foreach $one_lang (@langs) {
# get the first part of the language setting
$one_lang =~ m/^([a-z]+)(_[A-Z]+)?/;
$lang_main = defined($1) ? $1 : "";
$lang_sub = defined($2) ? $2 : "";
$lang_name = $lang_main . $lang_sub;
# check, if it is available
if (&check_interface_language($lang_name)) {
$res[$#res+1] = $lang_name;
} else {
# remember the main languages of all non-supported regional
# languages (only if the main language ist supported)
$main_langs[$#main_langs+1] = $lang_main
if (&check_interface_language($lang_main));
}
}
# add the previously remembered main languages to the list of
# preferred languages
# useful, if someone configured 'de_AT' without the general 'de'
$res[$#res+1] = $_ foreach (@main_langs);
# if everything fails - return empty string
$res[0] = "" if ($#res lt 0);
return $res[0];
}
# ---------------------------------------------------------------------------
sub set_pagedata_domains {
my $domain_name;
# multi-domain setup?
if (defined($CURRENT_DOMAIN)) {
$pagedata->setValue("Config.UI.LinkAttrs.domain", $CURRENT_DOMAIN);
$pagedata->setValue("Data.CurrentDomain", $CURRENT_DOMAIN);
$pagedata->setValue("Data.CurrentDomain.Description",
$DOMAINS{$CURRENT_DOMAIN}{name});
}
foreach $domain_name (sort keys %DOMAINS) {
if (&webauth_visible_domain($domain_name)) {
$pagedata->setValue("Data.Domains.$domain_name",
$DOMAINS{$domain_name}{'name'});
}
}
}
# ---------------------------------------------------------------------------
sub set_pagedata_list_of_lists {
my (@files, $i, $num);
# for a multi-domain setup there are no lists available if no domain
# is selected
return (0==0) if (%DOMAINS && !defined($CURRENT_DOMAIN));
# undefined $LIST_DIR?
return (0==0) if (!defined($LIST_DIR) || ($LIST_DIR eq ''));
# Read the list directory for mailing lists.
return (0==0) unless (opendir DIR, $LIST_DIR);
@files = sort grep !/^\./, readdir DIR;
closedir DIR;
$num = 0;
# Check that they actually are lists and add good ones to pagedata ...
foreach $i (0 .. $#files) {
if ((-e "$LIST_DIR/$files[$i]/lock") &&
(&webauth_access_list($files[$i], $WEBUSERS_FILE))) {
$pagedata->setValue("Data.Lists." . $num, "$files[$i]");
$num++;
}
}
}
# ---------------------------------------------------------------------------
sub set_pagedata {
my $list = shift;
# read available list of lists
&set_pagedata_list_of_lists();
# multi domain support?
&set_pagedata_domains() if (%DOMAINS);
$pagedata->setValue("Data.LocalPrefix", $MAIL_ADDRESS_PREFIX);
$pagedata->setValue("Data.HostName", $MAIL_DOMAIN);
# modules
# TODO: someone should test, if the mysql support works
$pagedata->setValue("Data.Modules.mySQL",
($Mail::Ezmlm::MYSQL_BASE)? 1 : 0);
# permission for list creation
my $create_allowed;
# for a multi-domain setup we disallow list creation until a domain
# is selected
if (%DOMAINS && (!defined($CURRENT_DOMAIN) || ($CURRENT_DOMAIN eq ''))) {
$create_allowed = (0==1);
} else {
$create_allowed = &webauth_create_list($WEBUSERS_FILE);
}
$pagedata->setValue("Data.Permissions.Create", $create_allowed ? 1 : 0);
# file upload permission
$pagedata->setValue("Data.Permissions.FileUpload", ($FILE_UPLOAD)? 1 : 0);
# ezmlm-idx v5.0 stuff
$pagedata->setValue('Data.areDefaultTextsAvailable',
(Mail::Ezmlm->get_version() >= 5)? 1 : 0);
# get available languages for all lists
# no results for ezmlm-idx < 5.0
my $i = 0;
my $item;
foreach $item (sort Mail::Ezmlm->get_available_languages()) {
$pagedata->setValue("Data.AvailableLanguages." . $i, $item);
$i++;
}
# display webuser textfield?
$pagedata->setValue("Data.WebUser.show", (-e "$WEBUSERS_FILE")? 1 : 0);
# default username for webuser file
$pagedata->setValue("Data.WebUser.UserName", $LOGIN_NAME || 'ALL');
# list specific configuration - use defaults if no list is selected
if ($list) {
&set_pagedata4options($list, $list->getconfig());
&set_pagedata4list($list, &get_list_part());
} else {
&set_pagedata4options($list, $DEFAULT_OPTIONS);
}
# add module-specific pagedata
if ($list) {
if (ref($list) && $list->isa("Mail::Ezmlm::GpgEzmlm")) {
set_pagedata_gpgezmlm($list);
}