1 # UVconfig: Reads config files and tests configuration
2 # Used by all components
7 use Net::Domain qw(hostname hostfqdn hostdomain);
9 use vars qw(@ISA @EXPORT $VERSION $usevote_version %config %messages
10 @rules @groups $bdsg_regexp $bdsg2_regexp %ids %functions);
14 @EXPORT = qw($usevote_version %config %messages @rules @groups
15 $bdsg_regexp $bdsg2_regexp %ids %functions);
21 $usevote_version = "UseVoteGer 4.12";
25 my ($cfgfile, $redir_errors) = @_;
27 # Default configuration options (overwritten in usevote.cfg)
28 %config = (votefile => "votes",
29 votename => "unkonfiguriertes Usevote",
30 sampleballotfile => "ballot.sample",
31 resultfile => "ergebnis.alle",
32 rulefile => "usevote.rul",
33 badaddrfile => "mailpatterns.cfg",
34 messagefile => "messages.cfg",
35 idfile => "scheinkennungen",
36 requestfile => "anforderung",
37 errorfile => "errors.log",
38 lockfile => "usevote.lock",
46 voteaccount => "<> (unkonfiguriertes Usevote)",
47 mailfrom => "<> (unkonfiguriertes Usevote)",
49 mailboxtype => "mbox",
50 mailstart => "^From ",
51 archivedir => "fertig",
53 templatedir => "templates",
54 formats => "UVformats.pm",
55 domailfile => "tmp/domail",
56 controlfile => "tmp/ack.control",
57 mailcmd => "sendmail -oi -oem",
59 sleepcmd => "sleep 1",
64 pop3server => "localhost",
66 pop3user => "default",
67 pop3pass => "default",
69 pop3uidlcache => "uidlcache",
70 pop3server_req => "localhost",
72 pop3user_req => "default",
73 pop3pass_req => "default",
75 pop3uidlcache_req => "uidlcache_req",
76 pop3server_bounce => "localhost",
77 pop3port_bounce => 110,
78 pop3user_bounce => "default",
79 pop3pass_bounce => "default",
80 pop3delete_bounce => 0,
81 pop3uidlcache_bounce => 'uidlcache_bounce',
83 smtpserver => 'localhost',
85 smtphelo => hostfqdn(),
90 name_re => '[a-zA-ZäöüÄÖÜß-]{2,} +.*[a-zA-ZäöüÄÖÜß]{2,}',
91 ja_stimme => '(J\s*A|J|(D\s*A\s*)?F\s*U\s*E\s*R)',
92 nein_stimme => '(N\s*E\s*I\s*N|N|(D\s*A\s*)?G\s*E\s*G\s*E\s*N)',
93 enth_stimme => '(E|E\s*N\s*T\s*H\s*A\s*L\s*T\s*U\s*N\s*G)',
94 ann_stimme => 'A\s*N\s*N\s*U\s*L\s*L\s*I\s*E\s*R\s*U\s*N\s*G',
96 condition1 => '$yes>=2*$no', # twice as many yes as no
97 condition2 => '$yes>=15', # min 15 yes votes
98 prop_formula => '$yes/$no',
99 tpl_ack_mail => 'ack-mail',
100 tpl_bouncelist => 'bouncelist',
101 tpl_mailheader => 'mailheader',
102 tpl_result_multi => 'result-multi',
103 tpl_result_single => 'result-single',
104 tpl_result_prop => 'result-proportional',
105 tpl_votes_multi => 'votes-multi',
106 tpl_votes_single => 'votes-single',
107 tpl_voterlist => 'voterlist',
108 tpl_ballot => 'ballot',
109 tpl_ballot_request => 'ballot-request',
110 tpl_ballot_personal => 'ballot-personal',
111 tpl_addr_reg => 'address-not-registered',
112 tpl_no_ballotid => 'no-ballotid',
113 tpl_wrong_ballotid => 'wrong-ballotid',
114 tpl_bdsg_error => 'bdsg-error',
115 tpl_cancelled => 'cancelled',
116 tpl_invalid_account => 'invalid-account',
117 tpl_invalid_name => 'invalid-name',
118 tpl_multiple_votes => 'multiple-votes',
119 tpl_no_ballot => 'no-ballot',
120 tpl_no_votes => 'no-votes',
121 tpl_rule_violated => 'rule-violated',
122 begin_divider => 'Alles vor dieser Zeile bitte loeschen',
123 end_divider => 'Alles nach dieser Zeile bitte loeschen',
124 ballotintro => 'WAHLSCHEIN fuer',
125 nametext => 'Dein Realname, falls nicht im FROM-Header:',
126 nametext2 => 'Waehlername:',
127 addresstext => 'Waehleradresse:',
128 ballotidtext => 'Wahlscheinkennung:',
129 bdsgtext => 'Datenschutzklausel - Zustimmung',
130 bdsgfile => 'bdsgtext.cfg',
132 usevote_version => $usevote_version); # needed for use in templates
138 open (RES, "<$config{messagefile}")
139 or die "Could not read message file $config{messagefile}!\n\n";
143 foreach my $line (@lines) {
145 $line =~ s/^#.*//; # Delete comments
146 if ($line =~ m/^\s*([A-Za-z0-9_-]+)\s*=\s*(.+)\s*$/){
151 # missing "groupX =" lines in config file?
152 die UVmessage::get("CONF_NOGROUPS", CONFIGFILE=>$cfgfile) . "\n\n" unless (@groups);
154 # redirect errors to a file if desired by calling script
155 open (STDERR, ">$config{errorfile}") if ($redir_errors);
157 # check for data protection law? read text for ballot
158 parse_bdsgtext() if ($config{bdsg});
160 # personalized ballots? read ballot IDs
161 read_ballot_ids() if ($config{personal});
163 load_formats() if ($config{formats});
168 ##############################################################################
170 ##############################################################################
176 open ($CONFIG, "<$cfgfile") or die "Could not find config file $cfgfile!\n\n";
179 next if (/^#/); # line is a comment
181 s/\r//; # delete \r if present
182 s/([^\\])#.*$/$1/; # Remove comments not starting at beginning of line.
183 # (ignore escaped comment sign \#)
186 if (/^include (\S+)$/) {
187 # include other config file
190 } elsif (my($key, $value) = split (/\s*=\s*/, $_, 2)) {
191 # delete trailing spaces
194 # evaluate quotation marks
195 $value =~ s/^\"([^\"]+[^\\\"])\".*$/$1/;
198 if ($key =~ /^group(\d+)$/) {
200 $groups[$num-1] = $value; # internal index starts at 0
202 $config{$key} = $value;
212 ##############################################################################
213 # parse data protection law texts #
214 ##############################################################################
218 open (BDSG, "<$config{bdsgfile}") or die UVmessage::get("CONF_NOBDSGFILE",
219 ('BDSGFILE' => "$config{bdsgfile}")) . "\n\n";
223 $config{bdsginfo} = '';
225 foreach my $line (@bdsg) {
226 $config{bdsginfo} .= $line unless ($line =~ /^\s*#/);
229 my $bdsgtmp = $config{bdsginfo};
230 $bdsgtmp =~ s/\"/\\\"/g;
231 $bdsgtmp =~ s/\'/\\\'/g;
232 $bdsgtmp =~ s/\(/\\\(/g;
233 $bdsgtmp =~ s/\)/\\\)/g;
234 $bdsgtmp =~ s/\[/\\\[/g;
235 $bdsgtmp =~ s/\]/\\\]/g;
236 $bdsgtmp =~ s/\./\\\./g;
237 $bdsgtmp =~ s/\!/\\\!/g;
238 my @bdsgtext = split(' ', $bdsgtmp);
240 # Build Regular Expression from single words.
241 # There has to be at least a space between two words, additional characters
242 # are allowed, e.g. quotation marks (but no letters)
243 $bdsg_regexp = join('\s\W*?', @bdsgtext);
245 # Build Regular Expression from $config{bdsgtext}
246 $bdsg2_regexp = join('\s\W*?', split(' ', $config{bdsgtext}));
250 ##############################################################################
251 # Read suspicious mail addresses (normally mailpatterns.cfg) #
252 ##############################################################################
258 open (BADADDR, "<$config{badaddrfile}") or die
259 UVmessage::get("CONF_NOBADADDR",(BADADDRFILE => $config{badaddrfile})) . "\n\n";
263 # Comment line? Not only whitespaces?
264 if (/^[^#]/ && /[^\s]/) {
274 ##############################################################################
276 ##############################################################################
278 sub read_ballot_ids {
279 # open file with ballot ids
280 open(FILE, "<$config{idfile}") or return 1;
283 # Format: mailaddress (whitespace) ballot ID
284 if (/^(.+@.+)\s+([a-z0-9]+)/) {
285 # $1=mailadresse, $2=ballot ID
294 ##############################################################################
295 # Funktionen für Templates laden #
296 ##############################################################################
299 my $modules = $config{formats};
301 my @modules = split(/\s*,\s*/, $modules);
303 foreach my $module (@modules){
311 ##############################################################################
313 ##############################################################################
316 print UVmessage::get("CONF_CONFIG"), "\n\n";
317 foreach my $option (keys %config) {
318 print "$option = $config{$option}\n";
321 print "\n", UVmessage::get("CONF_TEST_RULES");
324 for (my $n=0; $n<@rules; $n++) {
325 my $text = UVrules::rule_print($n);
330 print UVmessage::get("CONF_NO_RULES"), "\n\n";