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 $gPseudoMaintFile $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(%gDistributionAliases),
65 qw(@gPostProcessall @gRemovalDefaultDistributionTags @gRemovalDistributionTags @gRemovalArchitectures),
66 qw(@gRemovalStrongSeverityDefaultDistributionTags),
69 text => [qw($gBadEmailPrefix $gHTMLTail $gHTMLExpireNote),
71 config => [qw(%config)],
74 Exporter::export_ok_tags(qw(globals text config));
75 $EXPORT_TAGS{all} = [@EXPORT_OK];
78 use File::Basename qw(dirname);
82 =head1 CONFIGURATION VARIABLES
84 =head2 General Configuration
92 # untaint $ENV{DEBBUGS_CONFIG_FILE} if it's owned by us
93 # This enables us to test things that are -T.
94 if (exists $ENV{DEBBUGS_CONFIG_FILE}) {
95 if (${[stat($ENV{DEBBUGS_CONFIG_FILE})]}[4] = $<) {
96 $ENV{DEBBUGS_CONFIG_FILE} =~ /(.+)/;
97 $ENV{DEBBUGS_CONFIG_FILE} = $1;
100 die "Environmental variable DEBBUGS_CONFIG_FILE set, and $ENV{DEBBUGS_CONFIG_FILE} is not owned by the user running this script.";
103 read_config(exists $ENV{DEBBUGS_CONFIG_FILE}?$ENV{DEBBUGS_CONFIG_FILE}:'/etc/debbugs/config');
105 =item email_domain $gEmailDomain
107 The email domain of the bts
111 set_default(\%config,'email_domain','bugs.something');
113 =item list_domain $gListDomain
115 The list domain of the bts, defaults to the email domain
119 set_default(\%config,'list_domain',$config{email_domain});
121 =item web_host $gWebHost
123 The web host of the bts; defaults to the email domain
127 set_default(\%config,'web_host',$config{email_domain});
129 =item web_host_bug_dir $gWebHostDir
131 The directory of the web host on which bugs are kept, defaults to C<''>
135 set_default(\%config,'web_host_bug_dir','');
137 =item web_domain $gWebDomain
139 Full path of the web domain where bugs are kept, defaults to the
140 concatenation of L</web_host> and L</web_host_bug_dir>
144 set_default(\%config,'web_domain',$config{web_host}.'/'.$config{web_host_bug_dir});
146 =item html_suffix $gHTMLSuffix
148 Suffix of html pages, defaults to .html
152 set_default(\%config,'html_suffix','.html');
154 =item cgi_domain $gCGIDomain
156 Full path of the web domain where cgi scripts are kept. Defaults to
157 the concatentation of L</web_host> and cgi.
161 set_default(\%config,'cgi_domain',$config{web_domain}.($config{web_domain}=~m{/$}?'':'/').'cgi');
163 =item mirrors @gMirrors
165 List of mirrors [What these mirrors are used for, no one knows.]
170 set_default(\%config,'mirrors',[]);
172 =item package_pages $gPackagePages
174 Domain where the package pages are kept; links should work in a
175 package_pages/foopackage manner. Defaults to undef, which means that
176 package links will not be made.
181 set_default(\%config,'package_pages',undef);
183 =item package_pages $gUsertagPackageDomain
185 Domain where where usertags of packages belong; defaults to $gPackagePages
189 set_default(\%config,'usertag_package_domain',$config{package_pages});
192 =item subscription_domain $gSubscriptionDomain
194 Domain where subscriptions to package lists happen
199 set_default(\%config,'subscription_domain',undef);
206 =head2 Project Identification
210 =item project $gProject
218 set_default(\%config,'project','Something');
220 =item project_title $gProjectTitle
222 Name of this install of Debbugs, defaults to "L</project> Debbugs Install"
224 Default: "$config{project} Debbugs Install"
228 set_default(\%config,'project_title',"$config{project} Debbugs Install");
230 =item maintainer $gMaintainer
232 Name of the maintainer of this debbugs install
234 Default: 'Local DebBugs Owner's
238 set_default(\%config,'maintainer','Local DebBugs Owner');
240 =item maintainer_webpage $gMaintainerWebpage
242 Webpage of the maintainer of this install of debbugs
244 Default: "$config{web_domain}/~owner"
248 set_default(\%config,'maintainer_webpage',"$config{web_domain}/~owner");
250 =item maintainer_email $gMaintainerEmail
252 Email address of the maintainer of this Debbugs install
254 Default: 'root@'.$config{email_domain}
258 set_default(\%config,'maintainer_email','root@'.$config{email_domain});
260 =item unknown_maintainer_email
262 Email address where packages with an unknown maintainer will be sent
264 Default: $config{maintainer_email}
270 set_default(\%config,'unknown_maintainer_email',$config{maintainer_email});
272 =head2 BTS Mailing Lists
299 set_default(\%config, 'submit_list', 'bug-submit-list');
300 set_default(\%config, 'maint_list', 'bug-maint-list');
301 set_default(\%config, 'quiet_list', 'bug-quiet-list');
302 set_default(\%config, 'forward_list', 'bug-forward-list');
303 set_default(\%config, 'done_list', 'bug-done-list');
304 set_default(\%config, 'request_list', 'bug-request-list');
305 set_default(\%config,'submitter_list','bug-submitter-list');
306 set_default(\%config, 'control_list', 'bug-control-list');
307 set_default(\%config, 'summary_list', 'bug-summary-list');
308 set_default(\%config, 'mirror_list', 'bug-mirror-list');
309 set_default(\%config, 'strong_list', 'bug-strong-list');
317 set_default(\%config,'mailer','exim');
318 set_default(\%config,'bug','bug');
319 set_default(\%config,'bugs','bugs');
323 Age at which bugs are archived/removed
329 set_default(\%config,'remove_age',28);
333 Whether old bugs are saved or deleted
339 set_default(\%config,'save_old_bugs',1);
341 =item distribution_aliases
343 Map of distribution aliases to the distribution name
346 {experimental => 'experimental',
347 unstable => 'unstable',
348 testing => 'testing',
350 oldstable => 'oldstable',
354 sarge => 'oldstable',
359 set_default(\%config,'distribution_aliases',
360 {experimental => 'experimental',
361 unstable => 'unstable',
362 testing => 'testing',
364 oldstable => 'oldstable',
368 sarge => 'oldstable',
376 List of valid distributions
378 Default: The values of the distribution aliases map.
382 my %_distributions_default;
383 @_distributions_default{values %{$config{distribution_aliases}}} = values %{$config{distribution_aliases}};
384 set_default(\%config,'distributions',[keys %_distributions_default]);
387 =item default_architectures
389 List of default architectures to use when architecture(s) are not
392 Default: i386 amd64 arm ppc sparc alpha
396 set_default(\%config,'default_architectures',
397 [qw(i386 amd64 arm ppc sparc alpha)]
400 =item removal_distribution_tags
402 Tags which specifiy distributions to check
404 Default: @{$config{distributions}}
408 set_default(\%config,'removal_distribution_tags',
409 [@{$config{distributions}}]);
411 =item removal_default_distribution_tags
413 For removal/archival purposes, all bugs are assumed to have these tags
416 Default: qw(unstable testing);
420 set_default(\%config,'removal_default_distribution_tags',
421 [qw(unstable testing)]
424 =item removal_strong_severity_default_distribution_tags
426 For removal/archival purposes, all bugs with strong severity are
427 assumed to have these tags set.
429 Default: qw(unstable testing stable);
433 set_default(\%config,'removal_strong_severity_default_distribution_tags',
434 [qw(unstable testing stable)]
438 =item removal_architectures
440 For removal/archival purposes, these architectures are consulted if
441 there is more than one architecture applicable. If the bug is in a
442 package not in any of these architectures, the architecture actually
443 checked is undefined.
445 Default: value of default_architectures
449 set_default(\%config,'removal_architectures',
450 $config{default_architectures},
454 =item package_name_re
456 The regex which will match a package name
458 Default: '[a-z0-9][a-z0-9\.+-]+'
462 set_default(\%config,'package_name_re',
463 '[a-z0-9][a-z0-9\.+-]+');
465 =item package_version_re
467 The regex which will match a package version
469 Default: '[A-Za-z0-9:+\.-]+'
473 set_default(\%config,'package_version_re',
474 '[A-Za-z0-9:+\.~-]+');
477 =item control_internal_requester
479 This address is used by Debbugs::Control as the request address which
480 sent a control request for faked log messages.
482 Default:"Debbugs Internal Request <$config{maintainer_email}>"
486 set_default(\%config,'control_internal_requester',
487 "Debbugs Internal Request <$config{maintainer_email}>",
490 =item control_internal_request_addr
492 This address is used by Debbugs::Control as the address to which a
493 faked log message request was sent.
495 Default: "internal_control\@$config{email_domain}";
499 set_default(\%config,'control_internal_request_addr',
500 'internal_control@'.$config{email_domain},
504 =item exclude_from_control
506 Addresses which are not allowed to send messages to control
510 set_default(\%config,'exclude_from_control',[]);
515 set_default(\%config,'default_severity','normal');
516 set_default(\%config,'show_severities','critical, grave, normal, minor, wishlist');
517 set_default(\%config,'strong_severities',[qw(critical grave)]);
518 set_default(\%config,'severity_list',[qw(critical grave normal wishlist)]);
519 set_default(\%config,'severity_display',{critical => "Critical $config{bugs}",
520 grave => "Grave $config{bugs}",
521 normal => "Normal $config{bugs}",
522 wishlist => "Wishlist $config{bugs}",
525 set_default(\%config,'tags',[qw(patch wontfix moreinfo unreproducible fixed),
526 @{$config{distributions}}
529 set_default(\%config,'bounce_froms','^mailer|^da?emon|^post.*mast|^root|^wpuser|^mmdf|^smt.*|'.
530 '^mrgate|^vmmail|^mail.*system|^uucp|-maiser-|^mal\@|'.
531 '^mail.*agent|^tcpmail|^bitmail|^mailman');
533 set_default(\%config,'config_dir',dirname(exists $ENV{DEBBUGS_CONFIG_FILE}?$ENV{DEBBUGS_CONFIG_FILE}:'/etc/debbugs/config'));
534 set_default(\%config,'spool_dir','/var/lib/debbugs/spool');
535 set_default(\%config,'incoming_dir','incoming');
536 set_default(\%config,'web_dir','/var/lib/debbugs/www');
537 set_default(\%config,'doc_dir','/var/lib/debbugs/www/txt');
538 set_default(\%config,'lib_path','/usr/lib/debbugs');
543 directory of templates; defaults to /usr/share/debbugs/templates.
547 set_default(\%config,'template_dir','/usr/share/debbugs/templates');
550 set_default(\%config,'maintainer_file',$config{config_dir}.'/Maintainers');
551 set_default(\%config,'maintainer_file_override',$config{config_dir}.'/Maintainers.override');
552 set_default(\%config,'pseudo_maint_file',$config{config_dir}.'/pseudo-packages.maint');
553 set_default(\%config,'pseudo_desc_file',$config{config_dir}.'/pseudo-packages.description');
554 set_default(\%config,'package_source',$config{config_dir}.'/indices/sources');
557 =item version_packages_dir
559 Location where the version package information is kept; defaults to
560 spool_dir/../versions/pkg
564 set_default(\%config,'version_packages_dir',$config{spool_dir}.'/../versions/pkg');
566 =item version_time_index
568 Location of the version/time index file. Defaults to
569 spool_dir/../versions/idx/versions_time.idx if spool_dir/../versions
570 exists; otherwise defaults to undef.
575 set_default(\%config,'version_time_index', -d $config{spool_dir}.'/../versions' ? $config{spool_dir}.'/../versions/indices/versions_time.idx' : undef);
579 Location of the version index file. Defaults to
580 spool_dir/../versions/indices/versions.idx if spool_dir/../versions
581 exists; otherwise defaults to undef.
585 set_default(\%config,'version_index',-d $config{spool_dir}.'/../versions' ? $config{spool_dir}.'/../versions/indices/versions.idx' : undef);
587 =item binary_source_map
589 Location of the binary -> source map. Defaults to
590 spool_dir/../versions/indices/bin2src.idx if spool_dir/../versions
591 exists; otherwise defaults to undef.
595 set_default(\%config,'binary_source_map',-d $config{spool_dir}.'/../versions' ? $config{spool_dir}.'/../versions/indices/binsrc.idx' : undef);
597 =item source_binary_map
599 Location of the source -> binary map. Defaults to
600 spool_dir/../versions/indices/src2bin.idx if spool_dir/../versions
601 exists; otherwise defaults to undef.
605 set_default(\%config,'source_binary_map',-d $config{spool_dir}.'/../versions' ? $config{spool_dir}.'/../versions/indices/srcbin.idx' : undef);
609 set_default(\%config,'post_processall',[]);
613 Sets the sendmail binary to execute; defaults to /usr/lib/sendmail
617 set_default(\%config,'sendmail','/usr/lib/sendmail');
621 Whether or not spamscan is being used; defaults to 0 (not being used
625 set_default(\%config,'spam_scan',0);
633 The following are the only text fields in general use in the scripts;
634 a few additional text fields are defined in text.in, but are only used
635 in db2html and a few other specialty scripts.
637 Earlier versions of debbugs defined these values in /etc/debbugs/text,
638 but now they are required to be in the configuration file. [Eventually
639 the longer ones will move out into a fully fledged template system.]
645 =item bad_email_prefix
647 This prefixes the text of all lines in a bad e-mail message ack.
651 set_default(\%config,'bad_email_prefix','');
654 =item text_instructions
656 This gives more information about bad e-mails to receive.in
660 set_default(\%config,'text_instructions',$config{bad_email_prefix});
664 This shows up at the end of (most) html pages
668 set_default(\%config,'html_tail',<<END);
669 <ADDRESS>$config{maintainer} <<A HREF=\"mailto:$config{maintainer_email}\">$config{maintainer_email}</A>>.
675 <A HREF=\"http://$config{web_domain}/\">Debian $config{bug} tracking system</A><BR>
676 Copyright (C) 1999 Darren O. Benham,
677 1997,2003 nCipher Corporation Ltd,
683 =item html_expire_note
685 This message explains what happens to archive/remove-able bugs
689 set_default(\%config,'html_expire_note',
690 "(Closed $config{bugs} are archived $config{remove_age} days after the last related message is received.)");
698 my ($conf_file) = @_;
699 # first, figure out what type of file we're reading in.
700 my $fh = new IO::File $conf_file,'r'
701 or die "Unable to open configuration file $conf_file for reading: $!";
702 # A new version configuration file must have a comment as its first line
703 my $first_line = <$fh>;
704 my ($version) = defined $first_line?$first_line =~ /VERSION:\s*(\d+)/i:undef;
705 if (defined $version) {
708 die "Version 1 configuration files not implemented yet";
711 die "Version $version configuration files are not supported";
715 # Ugh. Old configuration file
716 # What we do here is we create a new Safe compartment
717 # so fucked up crap in the config file doesn't sink us.
718 my $cpt = new Safe or die "Unable to create safe compartment";
719 # perldoc Opcode; for details
720 $cpt->permit('require',':filesys_read','entereval','caller','pack','unpack','dofile');
721 $cpt->reval(qq(require '$conf_file';));
722 die "Error in configuration file: $@" if $@;
723 # Now what we do is check out the contents of %EXPORT_TAGS to see exactly which variables
724 # we want to glob in from the configuration file
725 for my $variable (@{$EXPORT_TAGS{globals}}) {
726 my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
727 my $var_glob = $cpt->varglob($glob_name);
728 my $value; #= $cpt->reval("return $variable");
729 # print STDERR "$variable $value",qq(\n);
730 if (defined $var_glob) {{
732 if ($glob_type eq '%') {
733 $value = {%{*{$var_glob}}} if defined *{$var_glob}{HASH};
735 elsif ($glob_type eq '@') {
736 $value = [@{*{$var_glob}}] if defined *{$var_glob}{ARRAY};
739 $value = ${*{$var_glob}};
741 # We punt here, because we can't tell if the value was
742 # defined intentionally, or if it was just left alone;
743 # this tries to set sane defaults.
744 set_default(\%config,$hash_name,$value) if defined $value;
752 my $hash_name = $variable;
753 $hash_name =~ s/^([\$\%\@])g//;
755 my $glob_name = 'g'.$hash_name;
756 $hash_name =~ s/(HTML|CGI)/ucfirst(lc($1))/ge;
757 $hash_name =~ s/^([A-Z]+)/lc($1)/e;
758 $hash_name =~ s/([A-Z]+)/'_'.lc($1)/ge;
759 return $hash_name unless wantarray;
760 return ($hash_name,$glob_name,$glob_type);
765 # sets the configuration hash to the default value if it's not set,
766 # otherwise doesn't do anything
767 # If $USING_GLOBALS, then sets an appropriate global.
770 my ($config,$option,$value) = @_;
772 if ($USING_GLOBALS) {
773 # fix up the variable name
774 $varname = 'g'.join('',map {ucfirst $_} split /_/, $option);
775 # Fix stupid HTML names
776 $varname =~ s/(Html|Cgi)/uc($1)/ge;
778 # update the configuration value
779 if (not $USING_GLOBALS and not exists $config->{$option}) {
780 $config->{$option} = $value;
782 elsif ($USING_GLOBALS) {{
784 # Need to check if a value has already been set in a global
785 if (defined *{"Debbugs::Config::${varname}"}) {
786 $config->{$option} = *{"Debbugs::Config::${varname}"};
789 $config->{$option} = $value;
792 if ($USING_GLOBALS) {{
794 *{"Debbugs::Config::${varname}"} = $config->{$option};
801 # All we care about here is whether we've been called with the globals or text option;
802 # if so, then we need to export some symbols back up.
803 # In any event, we call exporter.
806 if (grep /^:(?:text|globals)$/, @_) {
808 for my $variable (map {@$_} @EXPORT_TAGS{map{(/^:(text|globals)$/?($1):())} @_}) {
811 # Yes, I don't care if these are only used once
813 # No, it doesn't bother me that I'm assigning an undefined value to a typeglob
815 my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
816 $tmp =~ s/^[\%\$\@]//;
817 *{"Debbugs::Config::${tmp}"} = ref($config{$hash_name})?$config{$hash_name}:\$config{$hash_name};
820 Debbugs::Config->export_to_level(1,@_);