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