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