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(%gObsoleteSeverities),
66 qw(@gPostProcessall @gRemovalDefaultDistributionTags @gRemovalDistributionTags @gRemovalArchitectures),
67 qw(@gRemovalStrongSeverityDefaultDistributionTags),
68 qw(@gDefaultArchitectures),
71 qw($gSpamMaxThreads $gSpamSpamsPerThread $gSpamKeepRunning $gSpamScan $gSpamCrossassassinDb),
73 text => [qw($gBadEmailPrefix $gHTMLTail $gHTMLExpireNote),
75 config => [qw(%config)],
78 Exporter::export_ok_tags(qw(globals text config));
79 $EXPORT_TAGS{all} = [@EXPORT_OK];
80 $ENV{HOME} = '' if not defined $ENV{HOME};
83 use File::Basename qw(dirname);
87 =head1 CONFIGURATION VARIABLES
89 =head2 General Configuration
97 # untaint $ENV{DEBBUGS_CONFIG_FILE} if it's owned by us
98 # This enables us to test things that are -T.
99 if (exists $ENV{DEBBUGS_CONFIG_FILE}) {
100 if (${[stat($ENV{DEBBUGS_CONFIG_FILE})]}[4] = $<) {
101 $ENV{DEBBUGS_CONFIG_FILE} =~ /(.+)/;
102 $ENV{DEBBUGS_CONFIG_FILE} = $1;
105 die "Environmental variable DEBBUGS_CONFIG_FILE set, and $ENV{DEBBUGS_CONFIG_FILE} is not owned by the user running this script.";
108 read_config(exists $ENV{DEBBUGS_CONFIG_FILE}?$ENV{DEBBUGS_CONFIG_FILE}:'/etc/debbugs/config');
110 =item email_domain $gEmailDomain
112 The email domain of the bts
116 set_default(\%config,'email_domain','bugs.something');
118 =item list_domain $gListDomain
120 The list domain of the bts, defaults to the email domain
124 set_default(\%config,'list_domain',$config{email_domain});
126 =item web_host $gWebHost
128 The web host of the bts; defaults to the email domain
132 set_default(\%config,'web_host',$config{email_domain});
134 =item web_host_bug_dir $gWebHostDir
136 The directory of the web host on which bugs are kept, defaults to C<''>
140 set_default(\%config,'web_host_bug_dir','');
142 =item web_domain $gWebDomain
144 Full path of the web domain where bugs are kept, defaults to the
145 concatenation of L</web_host> and L</web_host_bug_dir>
149 set_default(\%config,'web_domain',$config{web_host}.($config{web_host}=~m{/$}?'':'/').$config{web_host_bug_dir});
151 =item html_suffix $gHTMLSuffix
153 Suffix of html pages, defaults to .html
157 set_default(\%config,'html_suffix','.html');
159 =item cgi_domain $gCGIDomain
161 Full path of the web domain where cgi scripts are kept. Defaults to
162 the concatentation of L</web_host> and cgi.
166 set_default(\%config,'cgi_domain',$config{web_domain}.($config{web_domain}=~m{/$}?'':'/').'cgi');
168 =item mirrors @gMirrors
170 List of mirrors [What these mirrors are used for, no one knows.]
175 set_default(\%config,'mirrors',[]);
177 =item package_pages $gPackagePages
179 Domain where the package pages are kept; links should work in a
180 package_pages/foopackage manner. Defaults to undef, which means that
181 package links will not be made.
186 set_default(\%config,'package_pages',undef);
188 =item package_pages $gUsertagPackageDomain
190 Domain where where usertags of packages belong; defaults to $gPackagePages
194 set_default(\%config,'usertag_package_domain',$config{package_pages});
197 =item subscription_domain $gSubscriptionDomain
199 Domain where subscriptions to package lists happen
204 set_default(\%config,'subscription_domain',undef);
211 =head2 Project Identification
215 =item project $gProject
223 set_default(\%config,'project','Something');
225 =item project_title $gProjectTitle
227 Name of this install of Debbugs, defaults to "L</project> Debbugs Install"
229 Default: "$config{project} Debbugs Install"
233 set_default(\%config,'project_title',"$config{project} Debbugs Install");
235 =item maintainer $gMaintainer
237 Name of the maintainer of this debbugs install
239 Default: 'Local DebBugs Owner's
243 set_default(\%config,'maintainer','Local DebBugs Owner');
245 =item maintainer_webpage $gMaintainerWebpage
247 Webpage of the maintainer of this install of debbugs
249 Default: "$config{web_domain}/~owner"
253 set_default(\%config,'maintainer_webpage',"$config{web_domain}/~owner");
255 =item maintainer_email $gMaintainerEmail
257 Email address of the maintainer of this Debbugs install
259 Default: 'root@'.$config{email_domain}
263 set_default(\%config,'maintainer_email','root@'.$config{email_domain});
265 =item unknown_maintainer_email
267 Email address where packages with an unknown maintainer will be sent
269 Default: $config{maintainer_email}
275 set_default(\%config,'unknown_maintainer_email',$config{maintainer_email});
277 =head2 BTS Mailing Lists
304 set_default(\%config, 'submit_list', 'bug-submit-list');
305 set_default(\%config, 'maint_list', 'bug-maint-list');
306 set_default(\%config, 'quiet_list', 'bug-quiet-list');
307 set_default(\%config, 'forward_list', 'bug-forward-list');
308 set_default(\%config, 'done_list', 'bug-done-list');
309 set_default(\%config, 'request_list', 'bug-request-list');
310 set_default(\%config,'submitter_list','bug-submitter-list');
311 set_default(\%config, 'control_list', 'bug-control-list');
312 set_default(\%config, 'summary_list', 'bug-summary-list');
313 set_default(\%config, 'mirror_list', 'bug-mirror-list');
314 set_default(\%config, 'strong_list', 'bug-strong-list');
322 set_default(\%config,'mailer','exim');
323 set_default(\%config,'bug','bug');
324 set_default(\%config,'bugs','bugs');
328 Age at which bugs are archived/removed
334 set_default(\%config,'remove_age',28);
338 Whether old bugs are saved or deleted
344 set_default(\%config,'save_old_bugs',1);
346 =item distribution_aliases
348 Map of distribution aliases to the distribution name
351 {experimental => 'experimental',
352 unstable => 'unstable',
353 testing => 'testing',
355 oldstable => 'oldstable',
359 sarge => 'oldstable',
364 set_default(\%config,'distribution_aliases',
365 {experimental => 'experimental',
366 unstable => 'unstable',
367 testing => 'testing',
369 oldstable => 'oldstable',
373 sarge => 'oldstable',
381 List of valid distributions
383 Default: The values of the distribution aliases map.
387 my %_distributions_default;
388 @_distributions_default{values %{$config{distribution_aliases}}} = values %{$config{distribution_aliases}};
389 set_default(\%config,'distributions',[keys %_distributions_default]);
392 =item default_architectures
394 List of default architectures to use when architecture(s) are not
397 Default: i386 amd64 arm ppc sparc alpha
401 set_default(\%config,'default_architectures',
402 [qw(i386 amd64 arm powerpc sparc alpha)]
405 =item removal_unremovable_tags
407 Bugs which have these tags set cannot be archived
413 set_default(\%config,'removal_unremovable_tags',
417 =item removal_distribution_tags
419 Tags which specifiy distributions to check
421 Default: @{$config{distributions}}
425 set_default(\%config,'removal_distribution_tags',
426 [@{$config{distributions}}]);
428 =item removal_default_distribution_tags
430 For removal/archival purposes, all bugs are assumed to have these tags
433 Default: qw(unstable testing);
437 set_default(\%config,'removal_default_distribution_tags',
438 [qw(unstable testing)]
441 =item removal_strong_severity_default_distribution_tags
443 For removal/archival purposes, all bugs with strong severity are
444 assumed to have these tags set.
446 Default: qw(unstable testing stable);
450 set_default(\%config,'removal_strong_severity_default_distribution_tags',
451 [qw(unstable testing stable)]
455 =item removal_architectures
457 For removal/archival purposes, these architectures are consulted if
458 there is more than one architecture applicable. If the bug is in a
459 package not in any of these architectures, the architecture actually
460 checked is undefined.
462 Default: value of default_architectures
466 set_default(\%config,'removal_architectures',
467 $config{default_architectures},
471 =item package_name_re
473 The regex which will match a package name
475 Default: '[a-z0-9][a-z0-9\.+-]+'
479 set_default(\%config,'package_name_re',
480 '[a-z0-9][a-z0-9\.+-]+');
482 =item package_version_re
484 The regex which will match a package version
486 Default: '[A-Za-z0-9:+\.-]+'
491 set_default(\%config,'package_version_re',
492 '[A-Za-z0-9:+\.~-]+');
495 =item default_package
497 This is the name of the default package. If set, bugs assigned to
498 packages without a maintainer and bugs missing a Package: psuedoheader
499 will be assigned to this package instead.
501 Defaults to unset, which is the traditional debbugs behavoir
505 set_default(\%config,'default_package',
510 =item control_internal_requester
512 This address is used by Debbugs::Control as the request address which
513 sent a control request for faked log messages.
515 Default:"Debbugs Internal Request <$config{maintainer_email}>"
519 set_default(\%config,'control_internal_requester',
520 "Debbugs Internal Request <$config{maintainer_email}>",
523 =item control_internal_request_addr
525 This address is used by Debbugs::Control as the address to which a
526 faked log message request was sent.
528 Default: "internal_control\@$config{email_domain}";
532 set_default(\%config,'control_internal_request_addr',
533 'internal_control@'.$config{email_domain},
537 =item exclude_from_control
539 Addresses which are not allowed to send messages to control
543 set_default(\%config,'exclude_from_control',[]);
547 =item default_severity
549 The default severity of bugs which have no severity set
555 set_default(\%config,'default_severity','normal');
557 =item severity_display
559 A hashref of severities and the informative text which describes them.
563 {critical => "Critical $config{bugs}",
564 grave => "Grave $config{bugs}",
565 normal => "Normal $config{bugs}",
566 wishlist => "Wishlist $config{bugs}",
571 set_default(\%config,'severity_display',{critical => "Critical $config{bugs}",
572 grave => "Grave $config{bugs}",
573 normal => "Normal $config{bugs}",
574 wishlist => "Wishlist $config{bugs}",
577 =item show_severities
579 A scalar list of the severities to show
581 Defaults to the concatenation of the keys of the severity_display
582 hashlist with ', ' above.
586 set_default(\%config,'show_severities',join(', ',keys %{$config{severity_display}}));
588 =item strong_severities
590 An arrayref of the serious severities which shoud be emphasized
592 Default: [qw(critical grave)]
596 set_default(\%config,'strong_severities',[qw(critical grave)]);
600 An arrayref of a list of the severities
602 Defaults to the keys of the severity display hashref
606 set_default(\%config,'severity_list',[keys %{$config{severity_display}}]);
608 =item obsolete_severities
610 A hashref of obsolete severities with the replacing severity
616 set_default(\%config,'obsolete_severities',{});
620 An arrayref of the tags used
622 Default: [qw(patch wontfix moreinfo unreproducible fixed)] and also
623 includes the distributions.
627 set_default(\%config,'tags',[qw(patch wontfix moreinfo unreproducible fixed),
628 @{$config{distributions}}
631 set_default(\%config,'bounce_froms','^mailer|^da?emon|^post.*mast|^root|^wpuser|^mmdf|^smt.*|'.
632 '^mrgate|^vmmail|^mail.*system|^uucp|-maiser-|^mal\@|'.
633 '^mail.*agent|^tcpmail|^bitmail|^mailman');
635 set_default(\%config,'config_dir',dirname(exists $ENV{DEBBUGS_CONFIG_FILE}?$ENV{DEBBUGS_CONFIG_FILE}:'/etc/debbugs/config'));
636 set_default(\%config,'spool_dir','/var/lib/debbugs/spool');
640 Directory which contains the usertags
642 Default: $config{spool_dir}/user
646 set_default(\%config,'usertag_dir',$config{spool_dir}.'/user');
647 set_default(\%config,'incoming_dir','incoming');
648 set_default(\%config,'web_dir','/var/lib/debbugs/www');
649 set_default(\%config,'doc_dir','/var/lib/debbugs/www/txt');
650 set_default(\%config,'lib_path','/usr/lib/debbugs');
655 directory of templates; defaults to /usr/share/debbugs/templates.
659 set_default(\%config,'template_dir','/usr/share/debbugs/templates');
662 set_default(\%config,'maintainer_file',$config{config_dir}.'/Maintainers');
663 set_default(\%config,'maintainer_file_override',$config{config_dir}.'/Maintainers.override');
664 set_default(\%config,'pseudo_maint_file',$config{config_dir}.'/pseudo-packages.maint');
665 set_default(\%config,'pseudo_desc_file',$config{config_dir}.'/pseudo-packages.description');
666 set_default(\%config,'package_source',$config{config_dir}.'/indices/sources');
669 =item version_packages_dir
671 Location where the version package information is kept; defaults to
672 spool_dir/../versions/pkg
676 set_default(\%config,'version_packages_dir',$config{spool_dir}.'/../versions/pkg');
678 =item version_time_index
680 Location of the version/time index file. Defaults to
681 spool_dir/../versions/idx/versions_time.idx if spool_dir/../versions
682 exists; otherwise defaults to undef.
687 set_default(\%config,'version_time_index', -d $config{spool_dir}.'/../versions' ? $config{spool_dir}.'/../versions/indices/versions_time.idx' : undef);
691 Location of the version index file. Defaults to
692 spool_dir/../versions/indices/versions.idx if spool_dir/../versions
693 exists; otherwise defaults to undef.
697 set_default(\%config,'version_index',-d $config{spool_dir}.'/../versions' ? $config{spool_dir}.'/../versions/indices/versions.idx' : undef);
699 =item binary_source_map
701 Location of the binary -> source map. Defaults to
702 spool_dir/../versions/indices/bin2src.idx if spool_dir/../versions
703 exists; otherwise defaults to undef.
707 set_default(\%config,'binary_source_map',-d $config{spool_dir}.'/../versions' ? $config{spool_dir}.'/../versions/indices/binsrc.idx' : undef);
709 =item source_binary_map
711 Location of the source -> binary map. Defaults to
712 spool_dir/../versions/indices/src2bin.idx if spool_dir/../versions
713 exists; otherwise defaults to undef.
717 set_default(\%config,'source_binary_map',-d $config{spool_dir}.'/../versions' ? $config{spool_dir}.'/../versions/indices/srcbin.idx' : undef);
721 set_default(\%config,'post_processall',[]);
725 Sets the sendmail binary to execute; defaults to /usr/lib/sendmail
729 set_default(\%config,'sendmail','/usr/lib/sendmail');
733 Whether or not spamscan is being used; defaults to 0 (not being used
737 set_default(\%config,'spam_scan',0);
739 =item spam_crossassassin_db
741 Location of the crosassassin database, defaults to
742 spool_dir/../CrossAssassinDb
746 set_default(\%config,'spam_crossassassin_db',$config{spool_dir}.'/../CrossAssassinDb');
750 Maximum number of cross-posted messages
754 set_default(\%config,'spam_max_cross',6);
757 =item spam_spams_per_thread
759 Number of spams for each thread (on average). Defaults to 200
763 set_default(\%config,'spam_spams_per_thread',200);
765 =item spam_max_threads
767 Maximum number of threads to start. Defaults to 20
771 set_default(\%config,'spam_max_threads',20);
773 =item spam_keep_running
775 Maximum number of seconds to run without restarting. Defaults to 3600.
779 set_default(\%config,'spam_keep_running',3600);
783 Location to store spam messages; is run through strftime to allow for
784 %d,%m,%Y, et al. Defaults to 'spool_dir/../mail/spam/assassinated.%Y-%m-%d'
788 set_default(\%config,'spam_mailbox',$config{spool_dir}.'/../mail/spam/assassinated.%Y-%m-%d');
790 =item spam_crossassassin_mailbox
792 Location to store crossassassinated messages; is run through strftime
793 to allow for %d,%m,%Y, et al. Defaults to
794 'spool_dir/../mail/spam/crossassassinated.%Y-%m-%d'
798 set_default(\%config,'spam_crossassassin_mailbox',$config{spool_dir}.'/../mail/spam/crossassassinated.%Y-%m-%d');
800 =item spam_local_tests_only
802 Whether only local tests are run, defaults to 0
806 set_default(\%config,'spam_local_tests_only',0);
808 =item spam_user_prefs
810 User preferences for spamassassin, defaults to $ENV{HOME}/.spamassassin/user_prefs
814 set_default(\%config,'spam_user_prefs',"$ENV{HOME}/.spamassassin/user_prefs");
818 Site rules directory for spamassassin, defaults to
819 '/usr/share/spamassassin'
823 set_default(\%config,'spam_rules_dir','/usr/share/spamassassin');
830 The following are the only text fields in general use in the scripts;
831 a few additional text fields are defined in text.in, but are only used
832 in db2html and a few other specialty scripts.
834 Earlier versions of debbugs defined these values in /etc/debbugs/text,
835 but now they are required to be in the configuration file. [Eventually
836 the longer ones will move out into a fully fledged template system.]
842 =item bad_email_prefix
844 This prefixes the text of all lines in a bad e-mail message ack.
848 set_default(\%config,'bad_email_prefix','');
851 =item text_instructions
853 This gives more information about bad e-mails to receive.in
857 set_default(\%config,'text_instructions',$config{bad_email_prefix});
861 This shows up at the end of (most) html pages
863 In many pages this has been replaced by the html/tail template.
867 set_default(\%config,'html_tail',<<END);
868 <ADDRESS>$config{maintainer} <<A HREF=\"mailto:$config{maintainer_email}\">$config{maintainer_email}</A>>.
874 <A HREF=\"http://$config{web_domain}/\">Debian $config{bug} tracking system</A><BR>
875 Copyright (C) 1999 Darren O. Benham,
876 1997,2003 nCipher Corporation Ltd,
882 =item html_expire_note
884 This message explains what happens to archive/remove-able bugs
888 set_default(\%config,'html_expire_note',
889 "(Closed $config{bugs} are archived $config{remove_age} days after the last related message is received.)");
897 my ($conf_file) = @_;
898 # first, figure out what type of file we're reading in.
899 my $fh = new IO::File $conf_file,'r'
900 or die "Unable to open configuration file $conf_file for reading: $!";
901 # A new version configuration file must have a comment as its first line
902 my $first_line = <$fh>;
903 my ($version) = defined $first_line?$first_line =~ /VERSION:\s*(\d+)/i:undef;
904 if (defined $version) {
907 die "Version 1 configuration files not implemented yet";
910 die "Version $version configuration files are not supported";
914 # Ugh. Old configuration file
915 # What we do here is we create a new Safe compartment
916 # so fucked up crap in the config file doesn't sink us.
917 my $cpt = new Safe or die "Unable to create safe compartment";
918 # perldoc Opcode; for details
919 $cpt->permit('require',':filesys_read','entereval','caller','pack','unpack','dofile');
920 $cpt->reval(qq(require '$conf_file';));
921 die "Error in configuration file: $@" if $@;
922 # Now what we do is check out the contents of %EXPORT_TAGS to see exactly which variables
923 # we want to glob in from the configuration file
924 for my $variable (@{$EXPORT_TAGS{globals}}) {
925 my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
926 my $var_glob = $cpt->varglob($glob_name);
927 my $value; #= $cpt->reval("return $variable");
928 # print STDERR "$variable $value",qq(\n);
929 if (defined $var_glob) {{
931 if ($glob_type eq '%') {
932 $value = {%{*{$var_glob}}} if defined *{$var_glob}{HASH};
934 elsif ($glob_type eq '@') {
935 $value = [@{*{$var_glob}}] if defined *{$var_glob}{ARRAY};
938 $value = ${*{$var_glob}};
940 # We punt here, because we can't tell if the value was
941 # defined intentionally, or if it was just left alone;
942 # this tries to set sane defaults.
943 set_default(\%config,$hash_name,$value) if defined $value;
951 my $hash_name = $variable;
952 $hash_name =~ s/^([\$\%\@])g//;
954 my $glob_name = 'g'.$hash_name;
955 $hash_name =~ s/(HTML|CGI)/ucfirst(lc($1))/ge;
956 $hash_name =~ s/^([A-Z]+)/lc($1)/e;
957 $hash_name =~ s/([A-Z]+)/'_'.lc($1)/ge;
958 return $hash_name unless wantarray;
959 return ($hash_name,$glob_name,$glob_type);
964 # sets the configuration hash to the default value if it's not set,
965 # otherwise doesn't do anything
966 # If $USING_GLOBALS, then sets an appropriate global.
969 my ($config,$option,$value) = @_;
971 if ($USING_GLOBALS) {
972 # fix up the variable name
973 $varname = 'g'.join('',map {ucfirst $_} split /_/, $option);
974 # Fix stupid HTML names
975 $varname =~ s/(Html|Cgi)/uc($1)/ge;
977 # update the configuration value
978 if (not $USING_GLOBALS and not exists $config->{$option}) {
979 $config->{$option} = $value;
981 elsif ($USING_GLOBALS) {{
983 # Need to check if a value has already been set in a global
984 if (defined *{"Debbugs::Config::${varname}"}) {
985 $config->{$option} = *{"Debbugs::Config::${varname}"};
988 $config->{$option} = $value;
991 if ($USING_GLOBALS) {{
993 *{"Debbugs::Config::${varname}"} = $config->{$option};
1000 # All we care about here is whether we've been called with the globals or text option;
1001 # if so, then we need to export some symbols back up.
1002 # In any event, we call exporter.
1005 if (grep /^:(?:text|globals)$/, @_) {
1007 for my $variable (map {@$_} @EXPORT_TAGS{map{(/^:(text|globals)$/?($1):())} @_}) {
1008 my $tmp = $variable;
1010 # Yes, I don't care if these are only used once
1012 # No, it doesn't bother me that I'm assigning an undefined value to a typeglob
1014 my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
1015 $tmp =~ s/^[\%\$\@]//;
1016 *{"Debbugs::Config::${tmp}"} = ref($config{$hash_name})?$config{$hash_name}:\$config{$hash_name};
1019 Debbugs::Config->export_to_level(1,@_);