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