2 package Debbugs::Config;
6 Debbugs::Config -- Configuration information for debbugs
12 # to get the compatiblity interface
14 use Debbugs::Config qw(:globals);
18 This module provides configuration variables for all of debbugs.
20 =head1 CONFIGURATION FILES
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.
30 use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT $USING_GLOBALS %config);
31 use base qw(Exporter);
34 # set the version for version checking
36 $DEBUG = 0 unless defined $DEBUG;
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),
53 qw(%gSeverityDisplay @gTags @gSeverityList @gStrongSeverities),
57 text => [qw($gBadEmailPrefix $gHTMLTail $gHTMLExpireNote),
59 config => [qw(%config)],
62 Exporter::export_ok_tags(qw(globals text config));
63 $EXPORT_TAGS{all} = [@EXPORT_OK];
66 use File::Basename qw(dirname);
70 =head1 CONFIGURATION VARIABLES
72 =head2 General Configuration
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;
87 read_config(exists $ENV{DEBBUGS_CONFIG_FILE}?$ENV{DEBBUGS_CONFIG_FILE}:'/etc/debbugs/config');
89 =item email_domain $gEmailDomain
91 The email domain of the bts
95 set_default(\%config,'email_domain','bugs.something');
97 =item list_domain $gListDomain
99 The list domain of the bts, defaults to the email domain
103 set_default(\%config,'list_domain',$config{email_domain});
105 =item web_host $gWebHost
107 The web host of the bts; defaults to the email domain
111 set_default(\%config,'web_host',$config{email_domain});
113 =item web_host_bug_dir $gWebHostDir
115 The directory of the web host on which bugs are kept, defaults to C<''>
119 set_default(\%config,'web_host_bug_dir','');
121 =item web_domain $gWebDomain
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>
128 set_default(\%config,'web_domain',$config{web_host}.'/'.$config{web_host_bug_dir});
130 =item html_suffix $gHTMLSuffix
132 Suffix of html pages, defaults to .html
136 set_default(\%config,'html_suffix','.html');
138 =item cgi_domain $gCGIDomain
140 Full path of the web domain where cgi scripts are kept. Defaults to
141 the concatentation of L</web_host> and cgi.
145 set_default(\%config,'cgi_domain',$config{web_domain}.($config{web_domain}=~m{/$}?'':'/').'cgi');
147 =item mirrors @gMirrors
149 List of mirrors [What these mirrors are used for, no one knows.]
154 set_default(\%config,'mirrors',[]);
156 =item package_pages $gPackagePages
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.
165 set_default(\%config,'package_pages',undef);
167 =item subscription_domain $gSubscriptionDomain
169 Domain where subscriptions to package lists happen
174 set_default(\%config,'subscription_domain',undef);
181 =head2 Project Identification
185 =item project $gProject
193 set_default(\%config,'project','Something');
195 =item project_title $gProjectTitle
197 Name of this install of Debbugs, defaults to "L</project> Debbugs Install"
199 Default: "$config{project} Debbugs Install"
203 set_default(\%config,'project_title',"$config{project} Debbugs Install");
205 =item maintainer $gMaintainer
207 Name of the maintainer of this debbugs install
209 Default: 'Local DebBugs Owner's
213 set_default(\%config,'maintainer','Local DebBugs Owner');
215 =item maintainer_webpage $gMaintainerWebpage
217 Webpage of the maintainer of this install of debbugs
219 Default: "$config{web_domain}/~owner"
223 set_default(\%config,'maintainer_webpage',"$config{web_domain}/~owner");
225 =item maintainer_email
227 Email address of the maintainer of this Debbugs install
229 Default: 'root@'.$config{email_domain}
233 set_default(\%config,'maintainer_email','root@'.$config{email_domain});
235 =item unknown_maintainer_email
237 Email address where packages with an unknown maintainer will be sent
239 Default: $config{maintainer_email}
245 set_default(\%config,'unknown_maintainer_email',$config{maintainer_email});
247 =head2 BTS Mailing Lists
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');
291 set_default(\%config,'mailer','exim');
292 set_default(\%config,'bug','bug');
293 set_default(\%config,'bugs','bugs');
297 Age at which bugs are archived/removed
303 set_default(\%config,'remove_age',28);
307 Whether old bugs are saved or deleted
313 set_default(\%config,'save_old_bugs',1);
317 List of valid distributions
319 Default: qw(experimental unstable testing stable oldstable);
323 set_default(\%config,'distributions',[qw(experimental unstable testing stable oldstable)]);
325 =item removal_distribution_tags
327 Tags which specifiy distributions to check
329 Default: @{$config{distributions}}
333 set_default(\%config,'removal_distribution_tags',
334 [@{$config{distributions}}]);
336 =item removal_default_distribution_tags
338 For removal/archival purposes, all bugs are assumed to have these tags
341 Default: qw(unstable testing);
345 set_default(\%config,'removal_default_distribution_tags',
346 [qw(unstable testing)]
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}",
359 set_default(\%config,'tags',[qw(patch wontfix moreinfo unreproducible fixed),
360 @{$config{distributions}}
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');
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');
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');
379 set_default(\%config,'version_packages_dir',$config{spool_dir}.'/../versions/pkg');
381 set_default(\%config,'post_processall',[]);
385 Sets the sendmail binary to execute; defaults to /usr/lib/sendmail
389 set_default(\%config,'sendmail',$config{sendmail},'/usr/lib/sendmail');
396 The following are the only text fields in general use in the scripts;
397 a few additional text fields are defined in text.in, but are only used
398 in db2html and a few other specialty scripts.
400 Earlier versions of debbugs defined these values in /etc/debbugs/text,
401 but now they are required to be in the configuration file. [Eventually
402 the longer ones will move out into a fully fledged template system.]
408 =item bad_email_prefix
410 This prefixes the text of all lines in a bad e-mail message ack.
414 set_default(\%config,'bad_email_prefix','');
417 =item text_instructions
419 This gives more information about bad e-mails to receive.in
423 set_default(\%config,'text_instructions',$config{bad_email_prefix});
427 This shows up at the end of (most) html pages
431 set_default(\%config,'html_tail',<<END);
432 <ADDRESS>$config{maintainer} <<A HREF=\"mailto:$config{maintainer_email}\">$config{maintainer_email}</A>>.
438 <A HREF=\"http://$config{web_domain}/\">Debian $config{bug} tracking system</A><BR>
439 Copyright (C) 1999 Darren O. Benham,
440 1997,2003 nCipher Corporation Ltd,
446 =item html_expire_note
448 This message explains what happens to archive/remove-able bugs
452 set_default(\%config,'html_expire_note',
453 "(Closed $config{bugs} are archived $config{remove_age} days after the last related message is received.)");
461 my ($conf_file) = @_;
462 # first, figure out what type of file we're reading in.
463 my $fh = new IO::File $conf_file,'r'
464 or die "Unable to open configuration file $conf_file for reading: $!";
465 # A new version configuration file must have a comment as its first line
466 my $first_line = <$fh>;
467 my ($version) = defined $first_line?$first_line =~ /VERSION:\s*(\d+)/i:undef;
468 if (defined $version) {
471 die "Version 1 configuration files not implemented yet";
474 die "Version $version configuration files are not supported";
478 # Ugh. Old configuration file
479 # What we do here is we create a new Safe compartment
480 # so fucked up crap in the config file doesn't sink us.
481 my $cpt = new Safe or die "Unable to create safe compartment";
482 # perldoc Opcode; for details
483 $cpt->permit('require',':filesys_read','entereval','caller','pack','unpack','dofile');
484 $cpt->reval(qq(require '$conf_file';));
485 die "Error in configuration file: $@" if $@;
486 # Now what we do is check out the contents of %EXPORT_TAGS to see exactly which variables
487 # we want to glob in from the configuration file
488 for my $variable (@{$EXPORT_TAGS{globals}}) {
489 my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
490 my $var_glob = $cpt->varglob($glob_name);
491 my $value; #= $cpt->reval("return $variable");
492 # print STDERR "$variable $value",qq(\n);
493 if (defined $var_glob) {{
495 if ($glob_type eq '%') {
496 $value = {%{*{$var_glob}}} if defined *{$var_glob}{HASH};
498 elsif ($glob_type eq '@') {
499 $value = [@{*{$var_glob}}] if defined *{$var_glob}{ARRAY};
502 $value = ${*{$var_glob}};
504 # We punt here, because we can't tell if the value was
505 # defined intentionally, or if it was just left alone;
506 # this tries to set sane defaults.
507 set_default(\%config,$hash_name,$value) if defined $value;
515 my $hash_name = $variable;
516 $hash_name =~ s/^([\$\%\@])g//;
518 my $glob_name = 'g'.$hash_name;
519 $hash_name =~ s/(HTML|CGI)/ucfirst(lc($1))/ge;
520 $hash_name =~ s/^([A-Z]+)/lc($1)/e;
521 $hash_name =~ s/([A-Z]+)/'_'.lc($1)/ge;
522 return $hash_name unless wantarray;
523 return ($hash_name,$glob_name,$glob_type);
528 # sets the configuration hash to the default value if it's not set,
529 # otherwise doesn't do anything
530 # If $USING_GLOBALS, then sets an appropriate global.
533 my ($config,$option,$value) = @_;
535 if ($USING_GLOBALS) {
536 # fix up the variable name
537 $varname = 'g'.join('',map {ucfirst $_} split /_/, $option);
538 # Fix stupid HTML names
539 $varname =~ s/(Html|Cgi)/uc($1)/ge;
541 # update the configuration value
542 if (not $USING_GLOBALS and not exists $config->{$option}) {
543 $config->{$option} = $value;
545 elsif ($USING_GLOBALS) {{
547 # Need to check if a value has already been set in a global
548 if (defined *{"Debbugs::Config::${varname}"}) {
549 $config->{$option} = *{"Debbugs::Config::${varname}"};
552 $config->{$option} = $value;
555 if ($USING_GLOBALS) {{
557 *{"Debbugs::Config::${varname}"} = $config->{$option};
564 # All we care about here is whether we've been called with the globals or text option;
565 # if so, then we need to export some symbols back up.
566 # In any event, we call exporter.
569 if (grep /^:(?:text|globals)$/, @_) {
571 for my $variable (map {@$_} @EXPORT_TAGS{map{(/^:(text|globals)$/?($1):())} @_}) {
574 # Yes, I don't care if these are only used once
576 # No, it doesn't bother me that I'm assigning an undefined value to a typeglob
578 my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
579 $tmp =~ s/^[\%\$\@]//;
580 *{"Debbugs::Config::${tmp}"} = ref($config{$hash_name})?$config{$hash_name}:\$config{$hash_name};
583 Debbugs::Config->export_to_level(1,@_);