]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/Config.pm
* Add $gSpamScan support to Debbugs::Config
[debbugs.git] / Debbugs / Config.pm
1
2 package Debbugs::Config;
3
4 =head1 NAME
5
6 Debbugs::Config -- Configuration information for debbugs
7
8 =head1 SYNOPSIS
9
10  use Debbugs::Config;
11
12 # to get the compatiblity interface
13
14  use Debbugs::Config qw(:globals);
15
16 =head1 DESCRIPTION
17
18 This module provides configuration variables for all of debbugs.
19
20 =head1 CONFIGURATION FILES
21
22 The default configuration file location is /etc/debbugs/config; this
23 configuration file location can be set by modifying the
24 DEBBUGS_CONFIG_FILE env variable to point at a different location.
25
26 =cut
27
28 use warnings;
29 use strict;
30 use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT $USING_GLOBALS %config);
31 use base qw(Exporter);
32
33 BEGIN {
34      # set the version for version checking
35      $VERSION     = 1.00;
36      $DEBUG = 0 unless defined $DEBUG;
37      $USING_GLOBALS = 0;
38
39      @EXPORT = ();
40      %EXPORT_TAGS = (globals => [qw($gEmailDomain $gListDomain $gWebHost $gWebHostBugDir),
41                                  qw($gWebDomain $gHTMLSuffix $gCGIDomain $gMirrors),
42                                  qw($gPackagePages $gSubscriptionDomain $gProject $gProjectTitle),
43                                  qw($gMaintainer $gMaintainerWebpage $gMaintainerEmail $gUnknownMaintainerEmail),
44                                  qw($gSubmitList $gMaintList $gQuietList $gForwardList),
45                                  qw($gDoneList $gRequestList $gSubmitterList $gControlList),
46                                  qw($gSummaryList $gMirrorList $gMailer $gBug),
47                                  qw($gBugs $gRemoveAge $gSaveOldBugs $gDefaultSeverity),
48                                  qw($gShowSeverities $gBounceFroms $gConfigDir $gSpoolDir),
49                                  qw($gIncomingDir $gWebDir $gDocDir $gMaintainerFile),
50                                  qw($gMaintainerFileOverride $gPseudoDescFile $gPackageSource),
51                                  qw($gVersionPackagesDir $gVersionIndex $gBinarySourceMap $gSourceBinaryMap),
52                                  qw($gSendmail $gLibPath $gSpamScan),
53                                  qw(%gSeverityDisplay @gTags @gSeverityList @gStrongSeverities),
54                                  qw(%gSearchEstraier),
55                                  qw(@gPostProcessall),
56                                 ],
57                      text     => [qw($gBadEmailPrefix $gHTMLTail $gHTMLExpireNote),
58                                  ],
59                      config   => [qw(%config)],
60                     );
61      @EXPORT_OK = ();
62      Exporter::export_ok_tags(qw(globals text config));
63      $EXPORT_TAGS{all} = [@EXPORT_OK];
64 }
65
66 use File::Basename qw(dirname);
67 use IO::File;
68 use Safe;
69
70 =head1 CONFIGURATION VARIABLES
71
72 =head2 General Configuration
73
74 =over
75
76 =cut
77
78 # read in the files;
79 %config = ();
80 # untaint $ENV{DEBBUGS_CONFIG_FILE} if it's owned by us
81 # This enables us to test things that are -T.
82 if (exists $ENV{DEBBUGS_CONFIG_FILE} and
83     ${[stat($ENV{DEBBUGS_CONFIG_FILE})]}[4] = $<) {
84      $ENV{DEBBUGS_CONFIG_FILE} =~ /(.+)/;
85      $ENV{DEBBUGS_CONFIG_FILE} = $1;
86 }
87 read_config(exists $ENV{DEBBUGS_CONFIG_FILE}?$ENV{DEBBUGS_CONFIG_FILE}:'/etc/debbugs/config');
88
89 =item email_domain $gEmailDomain
90
91 The email domain of the bts
92
93 =cut
94
95 set_default(\%config,'email_domain','bugs.something');
96
97 =item list_domain $gListDomain
98
99 The list domain of the bts, defaults to the email domain
100
101 =cut
102
103 set_default(\%config,'list_domain',$config{email_domain});
104
105 =item web_host $gWebHost
106
107 The web host of the bts; defaults to the email domain
108
109 =cut
110
111 set_default(\%config,'web_host',$config{email_domain});
112
113 =item web_host_bug_dir $gWebHostDir
114
115 The directory of the web host on which bugs are kept, defaults to C<''>
116
117 =cut
118
119 set_default(\%config,'web_host_bug_dir','');
120
121 =item web_domain $gWebDomain
122
123 Full path of the web domain where bugs are kept, defaults to the
124 concatenation of L</web_host> and L</web_host_bug_dir>
125
126 =cut
127
128 set_default(\%config,'web_domain',$config{web_host}.'/'.$config{web_host_bug_dir});
129
130 =item html_suffix $gHTMLSuffix
131
132 Suffix of html pages, defaults to .html
133
134 =cut
135
136 set_default(\%config,'html_suffix','.html');
137
138 =item cgi_domain $gCGIDomain
139
140 Full path of the web domain where cgi scripts are kept. Defaults to
141 the concatentation of L</web_host> and cgi.
142
143 =cut
144
145 set_default(\%config,'cgi_domain',$config{web_domain}.($config{web_domain}=~m{/$}?'':'/').'cgi');
146
147 =item mirrors @gMirrors
148
149 List of mirrors [What these mirrors are used for, no one knows.]
150
151 =cut
152
153
154 set_default(\%config,'mirrors',[]);
155
156 =item package_pages  $gPackagePages
157
158 Domain where the package pages are kept; links should work in a
159 package_pages/foopackage manner. Defaults to undef, which means that
160 package links will not be made.
161
162 =cut
163
164
165 set_default(\%config,'package_pages',undef);
166
167 =item subscription_domain $gSubscriptionDomain
168
169 Domain where subscriptions to package lists happen
170
171 =cut
172
173
174 set_default(\%config,'subscription_domain',undef);
175
176 =back
177
178 =cut
179
180
181 =head2 Project Identification
182
183 =over
184
185 =item project $gProject
186
187 Name of the project
188
189 Default: 'Something'
190
191 =cut
192
193 set_default(\%config,'project','Something');
194
195 =item project_title $gProjectTitle
196
197 Name of this install of Debbugs, defaults to "L</project> Debbugs Install"
198
199 Default: "$config{project} Debbugs Install"
200
201 =cut
202
203 set_default(\%config,'project_title',"$config{project} Debbugs Install");
204
205 =item maintainer $gMaintainer
206
207 Name of the maintainer of this debbugs install
208
209 Default: 'Local DebBugs Owner's
210
211 =cut
212
213 set_default(\%config,'maintainer','Local DebBugs Owner');
214
215 =item maintainer_webpage $gMaintainerWebpage
216
217 Webpage of the maintainer of this install of debbugs
218
219 Default: "$config{web_domain}/~owner"
220
221 =cut
222
223 set_default(\%config,'maintainer_webpage',"$config{web_domain}/~owner");
224
225 =item maintainer_email
226
227 Email address of the maintainer of this Debbugs install
228
229 Default: 'root@'.$config{email_domain}
230
231 =cut
232
233 set_default(\%config,'maintainer_email','root@'.$config{email_domain});
234
235 =item unknown_maintainer_email
236
237 Email address where packages with an unknown maintainer will be sent
238
239 Default: $config{maintainer_email}
240
241 =back
242
243 =cut
244
245 set_default(\%config,'unknown_maintainer_email',$config{maintainer_email});
246
247 =head2 BTS Mailing Lists
248
249
250 =over
251
252 =item submit_list
253
254 =item maint_list
255
256 =item forward_list
257
258 =item done_list
259
260 =item request_list
261
262 =item submitter_list
263
264 =item control_list
265
266 =item summary_list
267
268 =item mirror_list
269
270 =back
271
272 =cut
273
274 set_default(\%config,   'submit_list',   'bug-submit-list');
275 set_default(\%config,    'maint_list',    'bug-maint-list');
276 set_default(\%config,    'quiet_list',    'bug-quiet-list');
277 set_default(\%config,  'forward_list',  'bug-forward-list');
278 set_default(\%config,     'done_list',     'bug-done-list');
279 set_default(\%config,  'request_list',  'bug-request-list');
280 set_default(\%config,'submitter_list','bug-submitter-list');
281 set_default(\%config,  'control_list',  'bug-control-list');
282 set_default(\%config,  'summary_list',  'bug-summary-list');
283 set_default(\%config,   'mirror_list',   'bug-mirror-list');
284
285 =head2 Misc Options
286
287 =over
288
289 =cut
290
291 set_default(\%config,'mailer','exim');
292 set_default(\%config,'bug','bug');
293 set_default(\%config,'bugs','bugs');
294
295 =item remove_age
296
297 Age at which bugs are archived/removed
298
299 Default: 28
300
301 =cut
302
303 set_default(\%config,'remove_age',28);
304
305 =item save_old_bugs
306
307 Whether old bugs are saved or deleted
308
309 Default: 1
310
311 =cut
312
313 set_default(\%config,'save_old_bugs',1);
314
315 =item distributions
316
317 List of valid distributions
318
319 Default: qw(experimental unstable testing stable oldstable);
320
321 =cut
322
323 set_default(\%config,'distributions',[qw(experimental unstable testing stable oldstable)]);
324
325 =item removal_distribution_tags
326
327 Tags which specifiy distributions to check
328
329 Default: @{$config{distributions}}
330
331 =cut
332
333 set_default(\%config,'removal_distribution_tags',
334             [@{$config{distributions}}]);
335
336 =item removal_default_distribution_tags
337
338 For removal/archival purposes, all bugs are assumed to have these tags
339 set.
340
341 Default: qw(unstable testing);
342
343 =cut
344
345 set_default(\%config,'removal_default_distribution_tags',
346             [qw(unstable testing)]
347            );
348
349 set_default(\%config,'default_severity','normal');
350 set_default(\%config,'show_severities','critical, grave, normal, minor, wishlist');
351 set_default(\%config,'strong_severities',[qw(critical grave)]);
352 set_default(\%config,'severity_list',[qw(critical grave normal wishlist)]);
353 set_default(\%config,'severity_display',{critical => "Critical $config{bugs}",
354                                          grave    => "Grave $config{bugs}",
355                                          normal   => "Normal $config{bugs}",
356                                          wishlist => "Wishlist $config{bugs}",
357                                         });
358
359 set_default(\%config,'tags',[qw(patch wontfix moreinfo unreproducible fixed),
360                              @{$config{distributions}}
361                             ]);
362
363 set_default(\%config,'bounce_froms','^mailer|^da?emon|^post.*mast|^root|^wpuser|^mmdf|^smt.*|'.
364             '^mrgate|^vmmail|^mail.*system|^uucp|-maiser-|^mal\@|'.
365             '^mail.*agent|^tcpmail|^bitmail|^mailman');
366
367 set_default(\%config,'config_dir',dirname(exists $ENV{DEBBUGS_CONFIG_FILE}?$ENV{DEBBUGS_CONFIG_FILE}:'/etc/debbugs/config'));
368 set_default(\%config,'spool_dir','/var/lib/debbugs/spool');
369 set_default(\%config,'incoming_dir','incoming');
370 set_default(\%config,'web_dir','/var/lib/debbugs/www');
371 set_default(\%config,'doc_dir','/var/lib/debbugs/www/txt');
372 set_default(\%config,'lib_path','/usr/lib/debbugs');
373
374 set_default(\%config,'maintainer_file',$config{config_dir}.'/Maintainers');
375 set_default(\%config,'maintainer_file_override',$config{config_dir}.'/Maintainers.override');
376 set_default(\%config,'pseudo_desc_file',$config{config_dir}.'/pseudo-packages.description');
377 set_default(\%config,'package_source',$config{config_dir}.'/indices/sources');
378
379 set_default(\%config,'version_packages_dir',$config{spool_dir}.'/../versions/pkg');
380
381 set_default(\%config,'post_processall',[]);
382
383 =item sendmail
384
385 Sets the sendmail binary to execute; defaults to /usr/lib/sendmail
386
387 =cut
388
389 set_default(\%config,'sendmail','/usr/lib/sendmail');
390
391 =item spam_scan
392
393 Whether or not spamscan is being used; defaults to 0 (not being used
394
395 =cut
396
397 set_default(\%config,'spam_scan',0);
398
399
400 =back
401
402
403 =head2 Text Fields
404
405 The following are the only text fields in general use in the scripts;
406 a few additional text fields are defined in text.in, but are only used
407 in db2html and a few other specialty scripts.
408
409 Earlier versions of debbugs defined these values in /etc/debbugs/text,
410 but now they are required to be in the configuration file. [Eventually
411 the longer ones will move out into a fully fledged template system.]
412
413 =cut
414
415 =over
416
417 =item bad_email_prefix
418
419 This prefixes the text of all lines in a bad e-mail message ack.
420
421 =cut
422
423 set_default(\%config,'bad_email_prefix','');
424
425
426 =item text_instructions
427
428 This gives more information about bad e-mails to receive.in
429
430 =cut
431
432 set_default(\%config,'text_instructions',$config{bad_email_prefix});
433
434 =item html_tail
435
436 This shows up at the end of (most) html pages
437
438 =cut
439
440 set_default(\%config,'html_tail',<<END);
441  <ADDRESS>$config{maintainer} &lt;<A HREF=\"mailto:$config{maintainer_email}\">$config{maintainer_email}</A>&gt;.
442  Last modified:
443  <!--timestamp-->
444  SUBSTITUTE_DTIME
445  <!--timestamp-->
446  <P>
447  <A HREF=\"http://$config{web_domain}/\">Debian $config{bug} tracking system</A><BR>
448  Copyright (C) 1999 Darren O. Benham,
449  1997,2003 nCipher Corporation Ltd,
450  1994-97 Ian Jackson.
451  </ADDRESS>
452 END
453
454
455 =item html_expire_note
456
457 This message explains what happens to archive/remove-able bugs
458
459 =cut
460
461 set_default(\%config,'html_expire_note',
462             "(Closed $config{bugs} are archived $config{remove_age} days after the last related message is received.)");
463
464 =back
465
466 =cut
467
468
469 sub read_config{
470      my ($conf_file) = @_;
471      # first, figure out what type of file we're reading in.
472      my $fh = new IO::File $conf_file,'r'
473           or die "Unable to open configuration file $conf_file for reading: $!";
474      # A new version configuration file must have a comment as its first line
475      my $first_line = <$fh>;
476      my ($version) = defined $first_line?$first_line =~ /VERSION:\s*(\d+)/i:undef;
477      if (defined $version) {
478           if ($version == 1) {
479                # Do something here;
480                die "Version 1 configuration files not implemented yet";
481           }
482           else {
483                die "Version $version configuration files are not supported";
484           }
485      }
486      else {
487           # Ugh. Old configuration file
488           # What we do here is we create a new Safe compartment
489           # so fucked up crap in the config file doesn't sink us.
490           my $cpt = new Safe or die "Unable to create safe compartment";
491           # perldoc Opcode; for details
492           $cpt->permit('require',':filesys_read','entereval','caller','pack','unpack','dofile');
493           $cpt->reval(qq(require '$conf_file';));
494           die "Error in configuration file: $@" if $@;
495           # Now what we do is check out the contents of %EXPORT_TAGS to see exactly which variables
496           # we want to glob in from the configuration file
497           for my $variable (@{$EXPORT_TAGS{globals}}) {
498                my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
499                my $var_glob = $cpt->varglob($glob_name);
500                my $value; #= $cpt->reval("return $variable");
501                # print STDERR "$variable $value",qq(\n);
502                if (defined $var_glob) {{
503                     no strict 'refs';
504                     if ($glob_type eq '%') {
505                          $value = {%{*{$var_glob}}} if defined *{$var_glob}{HASH};
506                     }
507                     elsif ($glob_type eq '@') {
508                          $value = [@{*{$var_glob}}] if defined *{$var_glob}{ARRAY};
509                     }
510                     else {
511                          $value = ${*{$var_glob}};
512                     }
513                     # We punt here, because we can't tell if the value was
514                     # defined intentionally, or if it was just left alone;
515                     # this tries to set sane defaults.
516                     set_default(\%config,$hash_name,$value) if defined $value;
517                }}
518           }
519      }
520 }
521
522 sub __convert_name{
523      my ($variable) = @_;
524      my $hash_name = $variable;
525      $hash_name =~ s/^([\$\%\@])g//;
526      my $glob_type = $1;
527      my $glob_name = 'g'.$hash_name;
528      $hash_name =~ s/(HTML|CGI)/ucfirst(lc($1))/ge;
529      $hash_name =~ s/^([A-Z]+)/lc($1)/e;
530      $hash_name =~ s/([A-Z]+)/'_'.lc($1)/ge;
531      return $hash_name unless wantarray;
532      return ($hash_name,$glob_name,$glob_type);
533 }
534
535 # set_default
536
537 # sets the configuration hash to the default value if it's not set,
538 # otherwise doesn't do anything
539 # If $USING_GLOBALS, then sets an appropriate global.
540
541 sub set_default{
542      my ($config,$option,$value) = @_;
543      my $varname;
544      if ($USING_GLOBALS) {
545           # fix up the variable name
546           $varname = 'g'.join('',map {ucfirst $_} split /_/, $option);
547           # Fix stupid HTML names
548           $varname =~ s/(Html|Cgi)/uc($1)/ge;
549      }
550      # update the configuration value
551      if (not $USING_GLOBALS and not exists $config->{$option}) {
552           $config->{$option} = $value;
553      }
554      elsif ($USING_GLOBALS) {{
555           no strict 'refs';
556           # Need to check if a value has already been set in a global
557           if (defined *{"Debbugs::Config::${varname}"}) {
558                $config->{$option} = *{"Debbugs::Config::${varname}"};
559           }
560           else {
561                $config->{$option} = $value;
562           }
563      }}
564      if ($USING_GLOBALS) {{
565           no strict 'refs';
566           *{"Debbugs::Config::${varname}"} = $config->{$option};
567      }}
568 }
569
570
571 ### import magick
572
573 # All we care about here is whether we've been called with the globals or text option;
574 # if so, then we need to export some symbols back up.
575 # In any event, we call exporter.
576
577 sub import {
578      if (grep /^:(?:text|globals)$/, @_) {
579           $USING_GLOBALS=1;
580           for my $variable (map {@$_} @EXPORT_TAGS{map{(/^:(text|globals)$/?($1):())} @_}) {
581                my $tmp = $variable;
582                no strict 'refs';
583                # Yes, I don't care if these are only used once
584                no warnings 'once';
585                # No, it doesn't bother me that I'm assigning an undefined value to a typeglob
586                no warnings 'misc';
587                my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
588                $tmp =~ s/^[\%\$\@]//;
589                *{"Debbugs::Config::${tmp}"} = ref($config{$hash_name})?$config{$hash_name}:\$config{$hash_name};
590           }
591      }
592      Debbugs::Config->export_to_level(1,@_);
593 }
594
595
596 1;