]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/Config.pm
* Add Debbugs::Control which will eventually contain most of the
[debbugs.git] / Debbugs / Config.pm
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.
5 #
6 # Copyright 2007 by Don Armstrong <don@donarmstrong.com>.
7
8 package Debbugs::Config;
9
10 =head1 NAME
11
12 Debbugs::Config -- Configuration information for debbugs
13
14 =head1 SYNOPSIS
15
16  use Debbugs::Config;
17
18 # to get the compatiblity interface
19
20  use Debbugs::Config qw(:globals);
21
22 =head1 DESCRIPTION
23
24 This module provides configuration variables for all of debbugs.
25
26 =head1 CONFIGURATION FILES
27
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.
31
32 =cut
33
34 use warnings;
35 use strict;
36 use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT $USING_GLOBALS %config);
37 use base qw(Exporter);
38
39 BEGIN {
40      # set the version for version checking
41      $VERSION     = 1.00;
42      $DEBUG = 0 unless defined $DEBUG;
43      $USING_GLOBALS = 0;
44
45      @EXPORT = ();
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),
52                                  qw($gStrongList),
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),
63                                  qw(%gSearchEstraier),
64                                  qw(@gPostProcessall @gRemovalDefaultDistributionTags @gRemovalDistributionTags @gRemovalArchitectures),
65                                 ],
66                      text     => [qw($gBadEmailPrefix $gHTMLTail $gHTMLExpireNote),
67                                  ],
68                      config   => [qw(%config)],
69                     );
70      @EXPORT_OK = ();
71      Exporter::export_ok_tags(qw(globals text config));
72      $EXPORT_TAGS{all} = [@EXPORT_OK];
73 }
74
75 use File::Basename qw(dirname);
76 use IO::File;
77 use Safe;
78
79 =head1 CONFIGURATION VARIABLES
80
81 =head2 General Configuration
82
83 =over
84
85 =cut
86
87 # read in the files;
88 %config = ();
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;
95 }
96 read_config(exists $ENV{DEBBUGS_CONFIG_FILE}?$ENV{DEBBUGS_CONFIG_FILE}:'/etc/debbugs/config');
97
98 =item email_domain $gEmailDomain
99
100 The email domain of the bts
101
102 =cut
103
104 set_default(\%config,'email_domain','bugs.something');
105
106 =item list_domain $gListDomain
107
108 The list domain of the bts, defaults to the email domain
109
110 =cut
111
112 set_default(\%config,'list_domain',$config{email_domain});
113
114 =item web_host $gWebHost
115
116 The web host of the bts; defaults to the email domain
117
118 =cut
119
120 set_default(\%config,'web_host',$config{email_domain});
121
122 =item web_host_bug_dir $gWebHostDir
123
124 The directory of the web host on which bugs are kept, defaults to C<''>
125
126 =cut
127
128 set_default(\%config,'web_host_bug_dir','');
129
130 =item web_domain $gWebDomain
131
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>
134
135 =cut
136
137 set_default(\%config,'web_domain',$config{web_host}.'/'.$config{web_host_bug_dir});
138
139 =item html_suffix $gHTMLSuffix
140
141 Suffix of html pages, defaults to .html
142
143 =cut
144
145 set_default(\%config,'html_suffix','.html');
146
147 =item cgi_domain $gCGIDomain
148
149 Full path of the web domain where cgi scripts are kept. Defaults to
150 the concatentation of L</web_host> and cgi.
151
152 =cut
153
154 set_default(\%config,'cgi_domain',$config{web_domain}.($config{web_domain}=~m{/$}?'':'/').'cgi');
155
156 =item mirrors @gMirrors
157
158 List of mirrors [What these mirrors are used for, no one knows.]
159
160 =cut
161
162
163 set_default(\%config,'mirrors',[]);
164
165 =item package_pages  $gPackagePages
166
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.
170
171 =cut
172
173
174 set_default(\%config,'package_pages',undef);
175
176 =item subscription_domain $gSubscriptionDomain
177
178 Domain where subscriptions to package lists happen
179
180 =cut
181
182
183 set_default(\%config,'subscription_domain',undef);
184
185 =back
186
187 =cut
188
189
190 =head2 Project Identification
191
192 =over
193
194 =item project $gProject
195
196 Name of the project
197
198 Default: 'Something'
199
200 =cut
201
202 set_default(\%config,'project','Something');
203
204 =item project_title $gProjectTitle
205
206 Name of this install of Debbugs, defaults to "L</project> Debbugs Install"
207
208 Default: "$config{project} Debbugs Install"
209
210 =cut
211
212 set_default(\%config,'project_title',"$config{project} Debbugs Install");
213
214 =item maintainer $gMaintainer
215
216 Name of the maintainer of this debbugs install
217
218 Default: 'Local DebBugs Owner's
219
220 =cut
221
222 set_default(\%config,'maintainer','Local DebBugs Owner');
223
224 =item maintainer_webpage $gMaintainerWebpage
225
226 Webpage of the maintainer of this install of debbugs
227
228 Default: "$config{web_domain}/~owner"
229
230 =cut
231
232 set_default(\%config,'maintainer_webpage',"$config{web_domain}/~owner");
233
234 =item maintainer_email
235
236 Email address of the maintainer of this Debbugs install
237
238 Default: 'root@'.$config{email_domain}
239
240 =cut
241
242 set_default(\%config,'maintainer_email','root@'.$config{email_domain});
243
244 =item unknown_maintainer_email
245
246 Email address where packages with an unknown maintainer will be sent
247
248 Default: $config{maintainer_email}
249
250 =back
251
252 =cut
253
254 set_default(\%config,'unknown_maintainer_email',$config{maintainer_email});
255
256 =head2 BTS Mailing Lists
257
258
259 =over
260
261 =item submit_list
262
263 =item maint_list
264
265 =item forward_list
266
267 =item done_list
268
269 =item request_list
270
271 =item submitter_list
272
273 =item control_list
274
275 =item summary_list
276
277 =item mirror_list
278
279 =back
280
281 =cut
282
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');
294
295 =head2 Misc Options
296
297 =over
298
299 =cut
300
301 set_default(\%config,'mailer','exim');
302 set_default(\%config,'bug','bug');
303 set_default(\%config,'bugs','bugs');
304
305 =item remove_age
306
307 Age at which bugs are archived/removed
308
309 Default: 28
310
311 =cut
312
313 set_default(\%config,'remove_age',28);
314
315 =item save_old_bugs
316
317 Whether old bugs are saved or deleted
318
319 Default: 1
320
321 =cut
322
323 set_default(\%config,'save_old_bugs',1);
324
325 =item distributions
326
327 List of valid distributions
328
329 Default: qw(experimental unstable testing stable oldstable);
330
331 =cut
332
333 set_default(\%config,'distributions',[qw(experimental unstable testing stable oldstable)]);
334
335 =item removal_distribution_tags
336
337 Tags which specifiy distributions to check
338
339 Default: @{$config{distributions}}
340
341 =cut
342
343 set_default(\%config,'removal_distribution_tags',
344             [@{$config{distributions}}]);
345
346 =item removal_default_distribution_tags
347
348 For removal/archival purposes, all bugs are assumed to have these tags
349 set.
350
351 Default: qw(unstable testing);
352
353 =cut
354
355 set_default(\%config,'removal_default_distribution_tags',
356             [qw(unstable testing)]
357            );
358
359 =item removal_architectures
360
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.
365
366 Default: qw(i386 amd64 arm ppc sparc alpha);
367
368 =cut
369
370 set_default(\%config,'removal_architectures',
371             [qw(i386 amd64 arm ppc sparc alpha)]
372            );
373
374
375 =item package_name_re
376
377 The regex which will match a package name
378
379 Default: '[a-z0-9][a-z0-9\.+-]+'
380
381 =cut
382
383 set_default(\%config,'package_name_re',
384             '[a-z0-9][a-z0-9\.+-]+');
385
386 =item package_version_re
387
388 The regex which will match a package version
389
390 Default: '[A-Za-z0-9:+\.-]+'
391
392 =cut
393
394 set_default(\%config,'package_version_re',
395             '[A-Za-z0-9:+\.~-]+');
396
397
398 =item control_internal_requester
399
400 This address is used by Debbugs::Control as the request address which
401 sent a control request for faked log messages.
402
403 Default:"Debbugs Internal Request <$config{maintainer_email}>"
404
405 =cut
406
407 set_default(\%config,'control_internal_requester',
408             "Debbugs Internal Request <$config{maintainer_email}>",
409            );
410
411 =item control_internal_request_addr
412
413 This address is used by Debbugs::Control as the address to which a
414 faked log message request was sent.
415
416 Default: "internal_control\@$config{email_domain}";
417
418 =cut
419
420 set_default(\%config,'control_internal_request_addr',
421             'internal_control@'.$config{email_domain},
422            );
423
424
425 =item exclude_from_control
426
427 Addresses which are not allowed to send messages to control
428
429 =cut
430
431 set_default(\%config,'exclude_from_control',[]);
432
433
434
435
436 set_default(\%config,'default_severity','normal');
437 set_default(\%config,'show_severities','critical, grave, normal, minor, wishlist');
438 set_default(\%config,'strong_severities',[qw(critical grave)]);
439 set_default(\%config,'severity_list',[qw(critical grave normal wishlist)]);
440 set_default(\%config,'severity_display',{critical => "Critical $config{bugs}",
441                                          grave    => "Grave $config{bugs}",
442                                          normal   => "Normal $config{bugs}",
443                                          wishlist => "Wishlist $config{bugs}",
444                                         });
445
446 set_default(\%config,'tags',[qw(patch wontfix moreinfo unreproducible fixed),
447                              @{$config{distributions}}
448                             ]);
449
450 set_default(\%config,'bounce_froms','^mailer|^da?emon|^post.*mast|^root|^wpuser|^mmdf|^smt.*|'.
451             '^mrgate|^vmmail|^mail.*system|^uucp|-maiser-|^mal\@|'.
452             '^mail.*agent|^tcpmail|^bitmail|^mailman');
453
454 set_default(\%config,'config_dir',dirname(exists $ENV{DEBBUGS_CONFIG_FILE}?$ENV{DEBBUGS_CONFIG_FILE}:'/etc/debbugs/config'));
455 set_default(\%config,'spool_dir','/var/lib/debbugs/spool');
456 set_default(\%config,'incoming_dir','incoming');
457 set_default(\%config,'web_dir','/var/lib/debbugs/www');
458 set_default(\%config,'doc_dir','/var/lib/debbugs/www/txt');
459 set_default(\%config,'lib_path','/usr/lib/debbugs');
460
461 set_default(\%config,'maintainer_file',$config{config_dir}.'/Maintainers');
462 set_default(\%config,'maintainer_file_override',$config{config_dir}.'/Maintainers.override');
463 set_default(\%config,'pseudo_desc_file',$config{config_dir}.'/pseudo-packages.description');
464 set_default(\%config,'package_source',$config{config_dir}.'/indices/sources');
465
466
467 =item version_packages_dir
468
469 Location where the version package information is kept; defaults to
470 spool_dir/../versions/pkg
471
472 =cut
473
474 set_default(\%config,'version_packages_dir',$config{spool_dir}.'/../versions/pkg');
475
476 =item version_time_index
477
478 Location of the version/time index file. Defaults to
479 spool_dir/../versions/idx/versions_time.idx if spool_dir/../versions
480 exists; otherwise defaults to undef.
481
482 =cut
483
484
485 set_default(\%config,'version_time_index', -d $config{spool_dir}.'/../versions' ? $config{spool_dir}.'/../versions/indices/versions_time.idx' : undef);
486
487 =item version_index
488
489 Location of the version index file. Defaults to
490 spool_dir/../versions/indices/versions.idx if spool_dir/../versions
491 exists; otherwise defaults to undef.
492
493 =cut
494
495 set_default(\%config,'version_index',-d $config{spool_dir}.'/../versions' ? $config{spool_dir}.'/../versions/indices/versions.idx' : undef);
496
497 =item binary_source_map
498
499 Location of the binary -> source map. Defaults to
500 spool_dir/../versions/indices/bin2src.idx if spool_dir/../versions
501 exists; otherwise defaults to undef.
502
503 =cut
504
505 set_default(\%config,'binary_source_map',-d $config{spool_dir}.'/../versions' ? $config{spool_dir}.'/../versions/indices/binsrc.idx' : undef);
506
507 =item source_binary_map
508
509 Location of the source -> binary map. Defaults to
510 spool_dir/../versions/indices/src2bin.idx if spool_dir/../versions
511 exists; otherwise defaults to undef.
512
513 =cut
514
515 set_default(\%config,'source_binary_map',-d $config{spool_dir}.'/../versions' ? $config{spool_dir}.'/../versions/indices/srcbin.idx' : undef);
516
517
518
519 set_default(\%config,'post_processall',[]);
520
521 =item sendmail
522
523 Sets the sendmail binary to execute; defaults to /usr/lib/sendmail
524
525 =cut
526
527 set_default(\%config,'sendmail','/usr/lib/sendmail');
528
529 =item spam_scan
530
531 Whether or not spamscan is being used; defaults to 0 (not being used
532
533 =cut
534
535 set_default(\%config,'spam_scan',0);
536
537
538 =back
539
540
541 =head2 Text Fields
542
543 The following are the only text fields in general use in the scripts;
544 a few additional text fields are defined in text.in, but are only used
545 in db2html and a few other specialty scripts.
546
547 Earlier versions of debbugs defined these values in /etc/debbugs/text,
548 but now they are required to be in the configuration file. [Eventually
549 the longer ones will move out into a fully fledged template system.]
550
551 =cut
552
553 =over
554
555 =item bad_email_prefix
556
557 This prefixes the text of all lines in a bad e-mail message ack.
558
559 =cut
560
561 set_default(\%config,'bad_email_prefix','');
562
563
564 =item text_instructions
565
566 This gives more information about bad e-mails to receive.in
567
568 =cut
569
570 set_default(\%config,'text_instructions',$config{bad_email_prefix});
571
572 =item html_tail
573
574 This shows up at the end of (most) html pages
575
576 =cut
577
578 set_default(\%config,'html_tail',<<END);
579  <ADDRESS>$config{maintainer} &lt;<A HREF=\"mailto:$config{maintainer_email}\">$config{maintainer_email}</A>&gt;.
580  Last modified:
581  <!--timestamp-->
582  SUBSTITUTE_DTIME
583  <!--timestamp-->
584  <P>
585  <A HREF=\"http://$config{web_domain}/\">Debian $config{bug} tracking system</A><BR>
586  Copyright (C) 1999 Darren O. Benham,
587  1997,2003 nCipher Corporation Ltd,
588  1994-97 Ian Jackson.
589  </ADDRESS>
590 END
591
592
593 =item html_expire_note
594
595 This message explains what happens to archive/remove-able bugs
596
597 =cut
598
599 set_default(\%config,'html_expire_note',
600             "(Closed $config{bugs} are archived $config{remove_age} days after the last related message is received.)");
601
602 =back
603
604 =cut
605
606
607 sub read_config{
608      my ($conf_file) = @_;
609      # first, figure out what type of file we're reading in.
610      my $fh = new IO::File $conf_file,'r'
611           or die "Unable to open configuration file $conf_file for reading: $!";
612      # A new version configuration file must have a comment as its first line
613      my $first_line = <$fh>;
614      my ($version) = defined $first_line?$first_line =~ /VERSION:\s*(\d+)/i:undef;
615      if (defined $version) {
616           if ($version == 1) {
617                # Do something here;
618                die "Version 1 configuration files not implemented yet";
619           }
620           else {
621                die "Version $version configuration files are not supported";
622           }
623      }
624      else {
625           # Ugh. Old configuration file
626           # What we do here is we create a new Safe compartment
627           # so fucked up crap in the config file doesn't sink us.
628           my $cpt = new Safe or die "Unable to create safe compartment";
629           # perldoc Opcode; for details
630           $cpt->permit('require',':filesys_read','entereval','caller','pack','unpack','dofile');
631           $cpt->reval(qq(require '$conf_file';));
632           die "Error in configuration file: $@" if $@;
633           # Now what we do is check out the contents of %EXPORT_TAGS to see exactly which variables
634           # we want to glob in from the configuration file
635           for my $variable (@{$EXPORT_TAGS{globals}}) {
636                my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
637                my $var_glob = $cpt->varglob($glob_name);
638                my $value; #= $cpt->reval("return $variable");
639                # print STDERR "$variable $value",qq(\n);
640                if (defined $var_glob) {{
641                     no strict 'refs';
642                     if ($glob_type eq '%') {
643                          $value = {%{*{$var_glob}}} if defined *{$var_glob}{HASH};
644                     }
645                     elsif ($glob_type eq '@') {
646                          $value = [@{*{$var_glob}}] if defined *{$var_glob}{ARRAY};
647                     }
648                     else {
649                          $value = ${*{$var_glob}};
650                     }
651                     # We punt here, because we can't tell if the value was
652                     # defined intentionally, or if it was just left alone;
653                     # this tries to set sane defaults.
654                     set_default(\%config,$hash_name,$value) if defined $value;
655                }}
656           }
657      }
658 }
659
660 sub __convert_name{
661      my ($variable) = @_;
662      my $hash_name = $variable;
663      $hash_name =~ s/^([\$\%\@])g//;
664      my $glob_type = $1;
665      my $glob_name = 'g'.$hash_name;
666      $hash_name =~ s/(HTML|CGI)/ucfirst(lc($1))/ge;
667      $hash_name =~ s/^([A-Z]+)/lc($1)/e;
668      $hash_name =~ s/([A-Z]+)/'_'.lc($1)/ge;
669      return $hash_name unless wantarray;
670      return ($hash_name,$glob_name,$glob_type);
671 }
672
673 # set_default
674
675 # sets the configuration hash to the default value if it's not set,
676 # otherwise doesn't do anything
677 # If $USING_GLOBALS, then sets an appropriate global.
678
679 sub set_default{
680      my ($config,$option,$value) = @_;
681      my $varname;
682      if ($USING_GLOBALS) {
683           # fix up the variable name
684           $varname = 'g'.join('',map {ucfirst $_} split /_/, $option);
685           # Fix stupid HTML names
686           $varname =~ s/(Html|Cgi)/uc($1)/ge;
687      }
688      # update the configuration value
689      if (not $USING_GLOBALS and not exists $config->{$option}) {
690           $config->{$option} = $value;
691      }
692      elsif ($USING_GLOBALS) {{
693           no strict 'refs';
694           # Need to check if a value has already been set in a global
695           if (defined *{"Debbugs::Config::${varname}"}) {
696                $config->{$option} = *{"Debbugs::Config::${varname}"};
697           }
698           else {
699                $config->{$option} = $value;
700           }
701      }}
702      if ($USING_GLOBALS) {{
703           no strict 'refs';
704           *{"Debbugs::Config::${varname}"} = $config->{$option};
705      }}
706 }
707
708
709 ### import magick
710
711 # All we care about here is whether we've been called with the globals or text option;
712 # if so, then we need to export some symbols back up.
713 # In any event, we call exporter.
714
715 sub import {
716      if (grep /^:(?:text|globals)$/, @_) {
717           $USING_GLOBALS=1;
718           for my $variable (map {@$_} @EXPORT_TAGS{map{(/^:(text|globals)$/?($1):())} @_}) {
719                my $tmp = $variable;
720                no strict 'refs';
721                # Yes, I don't care if these are only used once
722                no warnings 'once';
723                # No, it doesn't bother me that I'm assigning an undefined value to a typeglob
724                no warnings 'misc';
725                my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
726                $tmp =~ s/^[\%\$\@]//;
727                *{"Debbugs::Config::${tmp}"} = ref($config{$hash_name})?$config{$hash_name}:\$config{$hash_name};
728           }
729      }
730      Debbugs::Config->export_to_level(1,@_);
731 }
732
733
734 1;