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