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.11";
25 my ($cfgfile, $redir_errors) = @_;
27 # Default configuration options (overwritten in usevote.cfg)
28 %config = (votefile => "votes",
29 votename => "unkonfiguriertes Usevote",
30 resultfile => "ergebnis.alle",
31 rulefile => "usevote.rul",
32 badaddrfile => "mailpatterns.cfg",
33 messagefile => "messages.cfg",
34 idfile => "scheinkennungen",
35 requestfile => "anforderung",
36 errorfile => "errors.log",
37 lockfile => "usevote.lock",
45 voteaccount => "<> (unkonfiguriertes Usevote)",
46 mailfrom => "<> (unkonfiguriertes Usevote)",
48 mailboxtype => "mbox",
49 mailstart => "^From ",
50 archivedir => "fertig",
52 templatedir => "templates",
53 formats => "UVformats.pm",
54 domailfile => "tmp/domail",
55 controlfile => "tmp/ack.control",
56 mailcmd => "sendmail -oi -oem",
58 sleepcmd => "sleep 1",
62 pop3server => "localhost",
64 pop3user => "default",
65 pop3pass => "default",
67 pop3uidlcache => "uidlcache",
68 pop3server_req => "localhost",
70 pop3user_req => "default",
71 pop3pass_req => "default",
73 pop3uidlcache_req => "uidlcache_req",
74 pop3server_bounce => "localhost",
75 pop3port_bounce => 110,
76 pop3user_bounce => "default",
77 pop3pass_bounce => "default",
78 pop3delete_bounce => 0,
79 pop3uidlcache_bounce => 'uidlcache_bounce',
81 smtpserver => 'localhost',
83 smtphelo => hostfqdn(),
88 name_re => '[a-zA-ZäöüÄÖÜß-]{2,} +.*[a-zA-ZäöüÄÖÜß]{2,}',
89 ja_stimme => '(J\s*A|J|(D\s*A\s*)?F\s*U\s*E\s*R)',
90 nein_stimme => '(N\s*E\s*I\s*N|N|(D\s*A\s*)?G\s*E\s*G\s*E\s*N)',
91 enth_stimme => '(E|E\s*N\s*T\s*H\s*A\s*L\s*T\s*U\s*N\s*G)',
92 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',
93 condition1 => '$yes>=2*$no', # twice as many yes as no
94 condition2 => '$yes>=60', # min 60 yes votes
95 prop_formula => '$yes/$no',
96 tpl_ack_mail => 'ack-mail',
97 tpl_bouncelist => 'bouncelist',
98 tpl_mailheader => 'mailheader',
99 tpl_result_multi => 'result-multi',
100 tpl_result_single => 'result-single',
101 tpl_result_prop => 'result-proportional',
102 tpl_votes_multi => 'votes-multi',
103 tpl_votes_single => 'votes-single',
104 tpl_voterlist => 'voterlist',
105 tpl_ballot => 'ballot',
106 tpl_ballot_request => 'ballot-request',
107 tpl_ballot_personal => 'ballot-personal',
108 tpl_addr_reg => 'address-not-registered',
109 tpl_no_ballotid => 'no-ballotid',
110 tpl_wrong_ballotid => 'wrong-ballotid',
111 tpl_bdsg_error => 'bdsg-error',
112 tpl_cancelled => 'cancelled',
113 tpl_invalid_account => 'invalid-account',
114 tpl_invalid_name => 'invalid-name',
115 tpl_multiple_votes => 'multiple-votes',
116 tpl_no_ballot => 'no-ballot',
117 tpl_no_votes => 'no-votes',
118 tpl_rule_violated => 'rule-violated',
119 begin_divider => 'Alles vor dieser Zeile bitte loeschen',
120 end_divider => 'Alles nach dieser Zeile bitte loeschen',
121 nametext => 'Dein Realname, falls nicht im FROM-Header:',
122 nametext2 => 'Waehlername:',
123 addresstext => 'Waehleradresse:',
124 ballotidtext => 'Wahlscheinkennung:',
125 bdsgtext => 'Datenschutzklausel - Zustimmung',
126 bdsgfile => 'bdsgtext.cfg',
128 usevote_version => $usevote_version); # needed for use in templates
134 open (RES, "<$config{messagefile}")
135 or die "Could not read message file $config{messagefile}!\n\n";
139 foreach my $line (@lines) {
141 $line =~ s/^#.*//; # Delete comments
142 if ($line =~ m/^\s*([A-Za-z0-9_-]+)\s*=\s*(.+)\s*$/){
147 # missing "groupX =" lines in config file?
148 die UVmessage::get("CONF_NOGROUPS", CONFIGFILE=>$cfgfile) . "\n\n" unless (@groups);
150 # redirect errors to a file if desired by calling script
151 open (STDERR, ">$config{errorfile}") if ($redir_errors);
153 # check for data protection law? read text for ballot
154 parse_bdsgtext() if ($config{bdsg});
156 # personalized ballots? read ballot IDs
157 read_ballot_ids() if ($config{personal});
159 load_formats() if ($config{formats});
164 ##############################################################################
166 ##############################################################################
172 open ($CONFIG, "<$cfgfile") or die "Could not find config file $cfgfile!\n\n";
175 next if (/^#/); # line is a comment
177 s/\r//; # delete \r if present
178 s/([^\\])#.*$/$1/; # Remove comments not starting at beginning of line.
179 # (ignore escaped comment sign \#)
182 if (/^include (\S+)$/) {
183 # include other config file
186 } elsif (my($key, $value) = split (/\s*=\s*/, $_, 2)) {
187 # delete trailing spaces
190 # evaluate quotation marks
191 $value =~ s/^\"([^\"]+[^\\\"])\".*$/$1/;
194 if ($key =~ /^group(\d+)$/) {
196 $groups[$num-1] = $value; # internal index starts at 0
198 $config{$key} = $value;
208 ##############################################################################
209 # parse data protection law texts #
210 ##############################################################################
214 open (BDSG, "<$config{bdsgfile}") or die UVmessage::get("CONF_NOBDSGFILE",
215 ('BDSGFILE' => "$config{bdsgfile}")) . "\n\n";
219 $config{bdsginfo} = '';
221 foreach my $line (@bdsg) {
222 $config{bdsginfo} .= $line unless ($line =~ /^\s*#/);
225 my $bdsgtmp = $config{bdsginfo};
226 $bdsgtmp =~ s/\"/\\\"/g;
227 $bdsgtmp =~ s/\'/\\\'/g;
228 $bdsgtmp =~ s/\(/\\\(/g;
229 $bdsgtmp =~ s/\)/\\\)/g;
230 $bdsgtmp =~ s/\[/\\\[/g;
231 $bdsgtmp =~ s/\]/\\\]/g;
232 $bdsgtmp =~ s/\./\\\./g;
233 $bdsgtmp =~ s/\!/\\\!/g;
234 my @bdsgtext = split(' ', $bdsgtmp);
236 # Build Regular Expression from single words.
237 # There has to be at least a space between two words, additional characters
238 # are allowed, e.g. quotation marks (but no letters)
239 $bdsg_regexp = join('\s\W*?', @bdsgtext);
241 # Build Regular Expression from $config{bdsgtext}
242 $bdsg2_regexp = join('\s\W*?', split(' ', $config{bdsgtext}));
246 ##############################################################################
247 # Read suspicious mail addresses (normally mailpatterns.cfg) #
248 ##############################################################################
254 open (BADADDR, "<$config{badaddrfile}") or die
255 UVmessage::get("CONF_NOBADADDR",(BADADDRFILE => $config{badaddrfile})) . "\n\n";
259 # Comment line? Not only whitespaces?
260 if (/^[^#]/ && /[^\s]/) {
270 ##############################################################################
272 ##############################################################################
274 sub read_ballot_ids {
275 # open file with ballot ids
276 open(FILE, "<$config{idfile}") or return 1;
279 # Format: mailaddress (whitespace) ballot ID
280 if (/^(.+@.+)\s+([a-z0-9]+)/) {
281 # $1=mailadresse, $2=ballot ID
290 ##############################################################################
291 # Funktionen für Templates laden #
292 ##############################################################################
295 my $modules = $config{formats};
297 my @modules = split(/\s*,\s*/, $modules);
299 foreach my $module (@modules){
307 ##############################################################################
309 ##############################################################################
312 print UVmessage::get("CONF_CONFIG"), "\n\n";
313 foreach my $option (keys %config) {
314 print "$option = $config{$option}\n";
317 print "\n", UVmessage::get("CONF_TEST_RULES");
320 for (my $n=0; $n<@rules; $n++) {
321 my $text = UVrules::rule_print($n);
326 print UVmessage::get("CONF_NO_RULES"), "\n\n";