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