1 # This module is part of debbugs, and is released
2 # under the terms of the GPL version 2, or any later
3 # version at your option.
4 # See the file README and COPYING for more information.
6 # Copyright 2007 by Don Armstrong <don@donarmstrong.com>.
8 package Debbugs::Config;
12 Debbugs::Config -- Configuration information for debbugs
18 # to get the compatiblity interface
20 use Debbugs::Config qw(:globals);
24 This module provides configuration variables for all of debbugs.
26 =head1 CONFIGURATION FILES
28 The default configuration file location is /etc/debbugs/config; this
29 configuration file location can be set by modifying the
30 DEBBUGS_CONFIG_FILE env variable to point at a different location.
36 use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT $USING_GLOBALS %config);
37 use base qw(Exporter);
40 # set the version for version checking
42 $DEBUG = 0 unless defined $DEBUG;
46 %EXPORT_TAGS = (globals => [qw($gEmailDomain $gListDomain $gWebHost $gWebHostBugDir),
47 qw($gWebDomain $gHTMLSuffix $gCGIDomain $gMirrors),
48 qw($gPackagePages $gSubscriptionDomain $gProject $gProjectTitle),
49 qw($gMaintainer $gMaintainerWebpage $gMaintainerEmail $gUnknownMaintainerEmail),
50 qw($gSubmitList $gMaintList $gQuietList $gForwardList),
51 qw($gDoneList $gRequestList $gSubmitterList $gControlList),
53 qw($gPackageVersionRe),
54 qw($gSummaryList $gMirrorList $gMailer $gBug),
55 qw($gBugs $gRemoveAge $gSaveOldBugs $gDefaultSeverity),
56 qw($gShowSeverities $gBounceFroms $gConfigDir $gSpoolDir),
57 qw($gIncomingDir $gWebDir $gDocDir $gMaintainerFile),
58 qw($gMaintainerFileOverride $gPseudoDescFile $gPackageSource),
59 qw($gVersionPackagesDir $gVersionIndex $gBinarySourceMap $gSourceBinaryMap),
60 qw($gVersionTimeIndex),
61 qw($gSendmail $gLibPath $gSpamScan @gExcludeFromControl),
62 qw(%gSeverityDisplay @gTags @gSeverityList @gStrongSeverities),
64 qw(@gPostProcessall @gRemovalDefaultDistributionTags @gRemovalDistributionTags @gRemovalArchitectures),
66 text => [qw($gBadEmailPrefix $gHTMLTail $gHTMLExpireNote),
68 config => [qw(%config)],
71 Exporter::export_ok_tags(qw(globals text config));
72 $EXPORT_TAGS{all} = [@EXPORT_OK];
75 use File::Basename qw(dirname);
79 =head1 CONFIGURATION VARIABLES
81 =head2 General Configuration
89 # untaint $ENV{DEBBUGS_CONFIG_FILE} if it's owned by us
90 # This enables us to test things that are -T.
91 if (exists $ENV{DEBBUGS_CONFIG_FILE} and
92 ${[stat($ENV{DEBBUGS_CONFIG_FILE})]}[4] = $<) {
93 $ENV{DEBBUGS_CONFIG_FILE} =~ /(.+)/;
94 $ENV{DEBBUGS_CONFIG_FILE} = $1;
96 read_config(exists $ENV{DEBBUGS_CONFIG_FILE}?$ENV{DEBBUGS_CONFIG_FILE}:'/etc/debbugs/config');
98 =item email_domain $gEmailDomain
100 The email domain of the bts
104 set_default(\%config,'email_domain','bugs.something');
106 =item list_domain $gListDomain
108 The list domain of the bts, defaults to the email domain
112 set_default(\%config,'list_domain',$config{email_domain});
114 =item web_host $gWebHost
116 The web host of the bts; defaults to the email domain
120 set_default(\%config,'web_host',$config{email_domain});
122 =item web_host_bug_dir $gWebHostDir
124 The directory of the web host on which bugs are kept, defaults to C<''>
128 set_default(\%config,'web_host_bug_dir','');
130 =item web_domain $gWebDomain
132 Full path of the web domain where bugs are kept, defaults to the
133 concatenation of L</web_host> and L</web_host_bug_dir>
137 set_default(\%config,'web_domain',$config{web_host}.'/'.$config{web_host_bug_dir});
139 =item html_suffix $gHTMLSuffix
141 Suffix of html pages, defaults to .html
145 set_default(\%config,'html_suffix','.html');
147 =item cgi_domain $gCGIDomain
149 Full path of the web domain where cgi scripts are kept. Defaults to
150 the concatentation of L</web_host> and cgi.
154 set_default(\%config,'cgi_domain',$config{web_domain}.($config{web_domain}=~m{/$}?'':'/').'cgi');
156 =item mirrors @gMirrors
158 List of mirrors [What these mirrors are used for, no one knows.]
163 set_default(\%config,'mirrors',[]);
165 =item package_pages $gPackagePages
167 Domain where the package pages are kept; links should work in a
168 package_pages/foopackage manner. Defaults to undef, which means that
169 package links will not be made.
174 set_default(\%config,'package_pages',undef);
176 =item subscription_domain $gSubscriptionDomain
178 Domain where subscriptions to package lists happen
183 set_default(\%config,'subscription_domain',undef);
190 =head2 Project Identification
194 =item project $gProject
202 set_default(\%config,'project','Something');
204 =item project_title $gProjectTitle
206 Name of this install of Debbugs, defaults to "L</project> Debbugs Install"
208 Default: "$config{project} Debbugs Install"
212 set_default(\%config,'project_title',"$config{project} Debbugs Install");
214 =item maintainer $gMaintainer
216 Name of the maintainer of this debbugs install
218 Default: 'Local DebBugs Owner's
222 set_default(\%config,'maintainer','Local DebBugs Owner');
224 =item maintainer_webpage $gMaintainerWebpage
226 Webpage of the maintainer of this install of debbugs
228 Default: "$config{web_domain}/~owner"
232 set_default(\%config,'maintainer_webpage',"$config{web_domain}/~owner");
234 =item maintainer_email
236 Email address of the maintainer of this Debbugs install
238 Default: 'root@'.$config{email_domain}
242 set_default(\%config,'maintainer_email','root@'.$config{email_domain});
244 =item unknown_maintainer_email
246 Email address where packages with an unknown maintainer will be sent
248 Default: $config{maintainer_email}
254 set_default(\%config,'unknown_maintainer_email',$config{maintainer_email});
256 =head2 BTS Mailing Lists
283 set_default(\%config, 'submit_list', 'bug-submit-list');
284 set_default(\%config, 'maint_list', 'bug-maint-list');
285 set_default(\%config, 'quiet_list', 'bug-quiet-list');
286 set_default(\%config, 'forward_list', 'bug-forward-list');
287 set_default(\%config, 'done_list', 'bug-done-list');
288 set_default(\%config, 'request_list', 'bug-request-list');
289 set_default(\%config,'submitter_list','bug-submitter-list');
290 set_default(\%config, 'control_list', 'bug-control-list');
291 set_default(\%config, 'summary_list', 'bug-summary-list');
292 set_default(\%config, 'mirror_list', 'bug-mirror-list');
293 set_default(\%config, 'strong_list', 'bug-strong-list');
301 set_default(\%config,'mailer','exim');
302 set_default(\%config,'bug','bug');
303 set_default(\%config,'bugs','bugs');
307 Age at which bugs are archived/removed
313 set_default(\%config,'remove_age',28);
317 Whether old bugs are saved or deleted
323 set_default(\%config,'save_old_bugs',1);
327 List of valid distributions
329 Default: qw(experimental unstable testing stable oldstable);
333 set_default(\%config,'distributions',[qw(experimental unstable testing stable oldstable)]);
335 =item removal_distribution_tags
337 Tags which specifiy distributions to check
339 Default: @{$config{distributions}}
343 set_default(\%config,'removal_distribution_tags',
344 [@{$config{distributions}}]);
346 =item removal_default_distribution_tags
348 For removal/archival purposes, all bugs are assumed to have these tags
351 Default: qw(unstable testing);
355 set_default(\%config,'removal_default_distribution_tags',
356 [qw(unstable testing)]
359 =item removal_architectures
361 For removal/archival purposes, these architectures are consulted if
362 there is more than one architecture applicable. If the bug is in a
363 package not in any of these architectures, the architecture actually
364 checked is undefined.
366 Default: qw(i386 amd64 arm ppc sparc alpha);
370 set_default(\%config,'removal_architectures',
371 [qw(i386 amd64 arm ppc sparc alpha)]
375 =item package_name_re
377 The regex which will match a package name
379 Default: '[a-z0-9][a-z0-9\.+-]+'
383 set_default(\%config,'package_name_re',
384 '[a-z0-9][a-z0-9\.+-]+');
386 =item package_version_re
388 The regex which will match a package version
390 Default: '[A-Za-z0-9:+\.-]+'
394 set_default(\%config,'package_version_re',
395 '[A-Za-z0-9:+\.~-]+');
399 =item exclude_from_control
401 Addresses which are not allowed to send messages to control
405 set_default(\%config,'exclude_from_control',[]);
410 set_default(\%config,'default_severity','normal');
411 set_default(\%config,'show_severities','critical, grave, normal, minor, wishlist');
412 set_default(\%config,'strong_severities',[qw(critical grave)]);
413 set_default(\%config,'severity_list',[qw(critical grave normal wishlist)]);
414 set_default(\%config,'severity_display',{critical => "Critical $config{bugs}",
415 grave => "Grave $config{bugs}",
416 normal => "Normal $config{bugs}",
417 wishlist => "Wishlist $config{bugs}",
420 set_default(\%config,'tags',[qw(patch wontfix moreinfo unreproducible fixed),
421 @{$config{distributions}}
424 set_default(\%config,'bounce_froms','^mailer|^da?emon|^post.*mast|^root|^wpuser|^mmdf|^smt.*|'.
425 '^mrgate|^vmmail|^mail.*system|^uucp|-maiser-|^mal\@|'.
426 '^mail.*agent|^tcpmail|^bitmail|^mailman');
428 set_default(\%config,'config_dir',dirname(exists $ENV{DEBBUGS_CONFIG_FILE}?$ENV{DEBBUGS_CONFIG_FILE}:'/etc/debbugs/config'));
429 set_default(\%config,'spool_dir','/var/lib/debbugs/spool');
430 set_default(\%config,'incoming_dir','incoming');
431 set_default(\%config,'web_dir','/var/lib/debbugs/www');
432 set_default(\%config,'doc_dir','/var/lib/debbugs/www/txt');
433 set_default(\%config,'lib_path','/usr/lib/debbugs');
435 set_default(\%config,'maintainer_file',$config{config_dir}.'/Maintainers');
436 set_default(\%config,'maintainer_file_override',$config{config_dir}.'/Maintainers.override');
437 set_default(\%config,'pseudo_desc_file',$config{config_dir}.'/pseudo-packages.description');
438 set_default(\%config,'package_source',$config{config_dir}.'/indices/sources');
441 =item version_packages_dir
443 Location where the version package information is kept; defaults to
444 spool_dir/../versions/pkg
448 set_default(\%config,'version_packages_dir',$config{spool_dir}.'/../versions/pkg');
450 =item version_time_index
452 Location of the version/time index file. Defaults to
453 spool_dir/../versions/idx/versions_time.idx
458 set_default(\%config,'version_time_index',$config{spool_dir}.'../versions/idx/versions_time.idx');
462 Location of the version index file. Defaults to
463 spool_dir/../versions/idx/versions.idx
467 set_default(\%config,'version_index',$config{spool_dir}.'../versions/idx/versions.idx');
469 =item binary_source_map
471 Location of the binary -> source map. Defaults to
472 spool_dir/../versions/idx/binsrc.idx
476 set_default(\%config,'binary_source_map',$config{spool_dir}.'../versions/idx/binsrc.idx');
478 =item source_binary_map
480 Location of the source -> binary map. Defaults to
481 spool_dir/../versions/idx/srcbin.idx
485 set_default(\%config,'source_binary_map',$config{spool_dir}.'../versions/idx/srcbin.idx');
489 set_default(\%config,'post_processall',[]);
493 Sets the sendmail binary to execute; defaults to /usr/lib/sendmail
497 set_default(\%config,'sendmail','/usr/lib/sendmail');
501 Whether or not spamscan is being used; defaults to 0 (not being used
505 set_default(\%config,'spam_scan',0);
513 The following are the only text fields in general use in the scripts;
514 a few additional text fields are defined in text.in, but are only used
515 in db2html and a few other specialty scripts.
517 Earlier versions of debbugs defined these values in /etc/debbugs/text,
518 but now they are required to be in the configuration file. [Eventually
519 the longer ones will move out into a fully fledged template system.]
525 =item bad_email_prefix
527 This prefixes the text of all lines in a bad e-mail message ack.
531 set_default(\%config,'bad_email_prefix','');
534 =item text_instructions
536 This gives more information about bad e-mails to receive.in
540 set_default(\%config,'text_instructions',$config{bad_email_prefix});
544 This shows up at the end of (most) html pages
548 set_default(\%config,'html_tail',<<END);
549 <ADDRESS>$config{maintainer} <<A HREF=\"mailto:$config{maintainer_email}\">$config{maintainer_email}</A>>.
555 <A HREF=\"http://$config{web_domain}/\">Debian $config{bug} tracking system</A><BR>
556 Copyright (C) 1999 Darren O. Benham,
557 1997,2003 nCipher Corporation Ltd,
563 =item html_expire_note
565 This message explains what happens to archive/remove-able bugs
569 set_default(\%config,'html_expire_note',
570 "(Closed $config{bugs} are archived $config{remove_age} days after the last related message is received.)");
578 my ($conf_file) = @_;
579 # first, figure out what type of file we're reading in.
580 my $fh = new IO::File $conf_file,'r'
581 or die "Unable to open configuration file $conf_file for reading: $!";
582 # A new version configuration file must have a comment as its first line
583 my $first_line = <$fh>;
584 my ($version) = defined $first_line?$first_line =~ /VERSION:\s*(\d+)/i:undef;
585 if (defined $version) {
588 die "Version 1 configuration files not implemented yet";
591 die "Version $version configuration files are not supported";
595 # Ugh. Old configuration file
596 # What we do here is we create a new Safe compartment
597 # so fucked up crap in the config file doesn't sink us.
598 my $cpt = new Safe or die "Unable to create safe compartment";
599 # perldoc Opcode; for details
600 $cpt->permit('require',':filesys_read','entereval','caller','pack','unpack','dofile');
601 $cpt->reval(qq(require '$conf_file';));
602 die "Error in configuration file: $@" if $@;
603 # Now what we do is check out the contents of %EXPORT_TAGS to see exactly which variables
604 # we want to glob in from the configuration file
605 for my $variable (@{$EXPORT_TAGS{globals}}) {
606 my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
607 my $var_glob = $cpt->varglob($glob_name);
608 my $value; #= $cpt->reval("return $variable");
609 # print STDERR "$variable $value",qq(\n);
610 if (defined $var_glob) {{
612 if ($glob_type eq '%') {
613 $value = {%{*{$var_glob}}} if defined *{$var_glob}{HASH};
615 elsif ($glob_type eq '@') {
616 $value = [@{*{$var_glob}}] if defined *{$var_glob}{ARRAY};
619 $value = ${*{$var_glob}};
621 # We punt here, because we can't tell if the value was
622 # defined intentionally, or if it was just left alone;
623 # this tries to set sane defaults.
624 set_default(\%config,$hash_name,$value) if defined $value;
632 my $hash_name = $variable;
633 $hash_name =~ s/^([\$\%\@])g//;
635 my $glob_name = 'g'.$hash_name;
636 $hash_name =~ s/(HTML|CGI)/ucfirst(lc($1))/ge;
637 $hash_name =~ s/^([A-Z]+)/lc($1)/e;
638 $hash_name =~ s/([A-Z]+)/'_'.lc($1)/ge;
639 return $hash_name unless wantarray;
640 return ($hash_name,$glob_name,$glob_type);
645 # sets the configuration hash to the default value if it's not set,
646 # otherwise doesn't do anything
647 # If $USING_GLOBALS, then sets an appropriate global.
650 my ($config,$option,$value) = @_;
652 if ($USING_GLOBALS) {
653 # fix up the variable name
654 $varname = 'g'.join('',map {ucfirst $_} split /_/, $option);
655 # Fix stupid HTML names
656 $varname =~ s/(Html|Cgi)/uc($1)/ge;
658 # update the configuration value
659 if (not $USING_GLOBALS and not exists $config->{$option}) {
660 $config->{$option} = $value;
662 elsif ($USING_GLOBALS) {{
664 # Need to check if a value has already been set in a global
665 if (defined *{"Debbugs::Config::${varname}"}) {
666 $config->{$option} = *{"Debbugs::Config::${varname}"};
669 $config->{$option} = $value;
672 if ($USING_GLOBALS) {{
674 *{"Debbugs::Config::${varname}"} = $config->{$option};
681 # All we care about here is whether we've been called with the globals or text option;
682 # if so, then we need to export some symbols back up.
683 # In any event, we call exporter.
686 if (grep /^:(?:text|globals)$/, @_) {
688 for my $variable (map {@$_} @EXPORT_TAGS{map{(/^:(text|globals)$/?($1):())} @_}) {
691 # Yes, I don't care if these are only used once
693 # No, it doesn't bother me that I'm assigning an undefined value to a typeglob
695 my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
696 $tmp =~ s/^[\%\$\@]//;
697 *{"Debbugs::Config::${tmp}"} = ref($config{$hash_name})?$config{$hash_name}:\$config{$hash_name};
700 Debbugs::Config->export_to_level(1,@_);