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.09";
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 mailstart => "^From ",
49 archivedir => "fertig",
51 templatedir => "templates",
52 formats => "UVformats.pm",
53 domailfile => "tmp/domail",
54 controlfile => "tmp/ack.control",
55 mailcmd => "sendmail -oi -oem",
57 sleepcmd => "sleep 1",
61 pop3server => "localhost",
63 pop3user => "default",
64 pop3pass => "default",
66 pop3uidlcache => "uidlcache",
67 pop3server_req => "localhost",
69 pop3user_req => "default",
70 pop3pass_req => "default",
72 pop3uidlcache_req => "uidlcache_req",
73 pop3server_bounce => "localhost",
74 pop3port_bounce => 110,
75 pop3user_bounce => "default",
76 pop3pass_bounce => "default",
77 pop3delete_bounce => 0,
78 pop3uidlcache_bounce => 'uidlcache_bounce',
80 smtpserver => 'localhost',
82 smtphelo => hostfqdn(),
87 name_re => '[a-zA-ZäöüÄÖÜß-]{2,} +.*[a-zA-ZäöüÄÖÜß]{2,}',
88 ja_stimme => '(J\s*A|J|(D\s*A\s*)?F\s*U\s*E\s*R)',
89 nein_stimme => '(N\s*E\s*I\s*N|N|(D\s*A\s*)?G\s*E\s*G\s*E\s*N)',
90 enth_stimme => '(E|E\s*N\s*T\s*H\s*A\s*L\s*T\s*U\s*N\s*G)',
91 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',
92 condition1 => '$yes>=2*$no', # twice as many yes as no
93 condition2 => '$yes>=60', # min 60 yes votes
94 prop_formula => '$yes/$no',
95 tpl_ack_mail => 'ack-mail',
96 tpl_bouncelist => 'bouncelist',
97 tpl_mailheader => 'mailheader',
98 tpl_result_multi => 'result-multi',
99 tpl_result_single => 'result-single',
100 tpl_result_prop => 'result-proportional',
101 tpl_votes_multi => 'votes-multi',
102 tpl_votes_single => 'votes-single',
103 tpl_voterlist => 'voterlist',
104 tpl_ballot => 'ballot',
105 tpl_ballot_request => 'ballot-request',
106 tpl_ballot_personal => 'ballot-personal',
107 tpl_addr_reg => 'address-not-registered',
108 tpl_no_ballotid => 'no-ballotid',
109 tpl_wrong_ballotid => 'wrong-ballotid',
110 tpl_bdsg_error => 'bdsg-error',
111 tpl_cancelled => 'cancelled',
112 tpl_invalid_account => 'invalid-account',
113 tpl_invalid_name => 'invalid-name',
114 tpl_multiple_votes => 'multiple-votes',
115 tpl_no_ballot => 'no-ballot',
116 tpl_no_votes => 'no-votes',
117 tpl_rule_violated => 'rule-violated',
118 begin_divider => 'Alles vor dieser Zeile bitte loeschen',
119 end_divider => 'Alles nach dieser Zeile bitte loeschen',
120 nametext => 'Dein Realname, falls nicht im FROM-Header:',
121 nametext2 => 'Waehlername:',
122 addresstext => 'Waehleradresse:',
123 ballotidtext => 'Wahlscheinkennung:',
124 bdsgtext => 'Datenschutzklausel - Zustimmung',
125 bdsgfile => 'bdsgtext.cfg',
127 usevote_version => $usevote_version); # needed for use in templates
133 open (RES, "<$config{messagefile}")
134 or die "Could not read message file $config{messagefile}!\n\n";
138 foreach my $line (@lines) {
140 $line =~ s/^#.*//; # Delete comments
141 if ($line =~ m/^\s*([A-Za-z0-9_-]+)\s*=\s*(.+)\s*$/){
146 # missing "groupX =" lines in config file?
147 die UVmessage::get("CONF_NOGROUPS", CONFIGFILE=>$cfgfile) . "\n\n" unless (@groups);
149 # redirect errors to a file if desired by calling script
150 open (STDERR, ">$config{errorfile}") if ($redir_errors);
152 # check for data protection law? read text for ballot
153 parse_bdsgtext() if ($config{bdsg});
155 # personalized ballots? read ballot IDs
156 read_ballot_ids() if ($config{personal});
158 load_formats() if ($config{formats});
163 ##############################################################################
165 ##############################################################################
171 open ($CONFIG, "<$cfgfile") or die "Could not find config file $cfgfile!\n\n";
174 next if (/^#/); # line is a comment
176 s/\r//; # delete \r if present
177 s/([^\\])#.*$/$1/; # Remove comments not starting at beginning of line.
178 # (ignore escaped comment sign \#)
181 if (/^include (\S+)$/) {
182 # include other config file
185 } elsif (my($key, $value) = split (/\s*=\s*/, $_, 2)) {
186 # delete trailing spaces
189 # evaluate quotation marks
190 $value =~ s/^\"([^\"]+[^\\\"])\".*$/$1/;
193 if ($key =~ /^group(\d+)$/) {
195 $groups[$num-1] = $value; # internal index starts at 0
197 $config{$key} = $value;
207 ##############################################################################
208 # parse data protection law texts #
209 ##############################################################################
213 open (BDSG, "<$config{bdsgfile}") or die UVmessage::get("CONF_NOBDSGFILE",
214 ('BDSGFILE' => "$config{bdsgfile}")) . "\n\n";
218 $config{bdsginfo} = '';
220 foreach my $line (@bdsg) {
221 $config{bdsginfo} .= $line unless ($line =~ /^\s*#/);
224 my $bdsgtmp = $config{bdsginfo};
225 $bdsgtmp =~ s/\"/\\\"/g;
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 my @bdsgtext = split(' ', $bdsgtmp);
235 # Build Regular Expression from single words.
236 # There has to be at least a space between two words, additional characters
237 # are allowed, e.g. quotation marks (but no letters)
238 $bdsg_regexp = join('\s\W*?', @bdsgtext);
240 # Build Regular Expression from $config{bdsgtext}
241 $bdsg2_regexp = join('\s\W*?', split(' ', $config{bdsgtext}));
245 ##############################################################################
246 # Read suspicious mail addresses (normally mailpatterns.cfg) #
247 ##############################################################################
253 open (BADADDR, "<$config{badaddrfile}") or die
254 UVmessage::get("CONF_NOBADADDR",(BADADDRFILE => $config{badaddrfile})) . "\n\n";
258 # Comment line? Not only whitespaces?
259 if (/^[^#]/ && /[^\s]/) {
269 ##############################################################################
271 ##############################################################################
273 sub read_ballot_ids {
274 # open file with ballot ids
275 open(FILE, "<$config{idfile}") or return 1;
278 # Format: mailaddress (whitespace) ballot ID
279 if (/^(.+@.+)\s+([a-z0-9]+)/) {
280 # $1=mailadresse, $2=ballot ID
289 ##############################################################################
290 # Funktionen für Templates laden #
291 ##############################################################################
294 my $modules = $config{formats};
296 my @modules = split(/\s*,\s*/, $modules);
298 foreach my $module (@modules){
306 ##############################################################################
308 ##############################################################################
311 print UVmessage::get("CONF_CONFIG"), "\n\n";
312 foreach my $option (keys %config) {
313 print "$option = $config{$option}\n";
316 print "\n", UVmessage::get("CONF_TEST_RULES");
319 for (my $n=0; $n<@rules; $n++) {
320 my $text = UVrules::rule_print($n);
325 print UVmessage::get("CONF_NO_RULES"), "\n\n";