]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/Config.pm
7cdbb306e5db45df8095fbf4f8fc90a23e1b50f9
[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                      config   => [qw(%config)],
56                     );
57      @EXPORT_OK = ();
58      Exporter::export_ok_tags(qw(globals config));
59      $EXPORT_TAGS{all} = [@EXPORT_OK];
60 }
61
62 use File::Basename qw(dirname);
63 use IO::File;
64 use Safe;
65
66 =head1 CONFIGURATION VARIABLES
67
68 =head2 General Configuration
69
70 =over
71
72 =cut
73
74 # read in the files;
75 %config = ();
76 read_config(exists $ENV{DEBBUGS_CONFIG_FILE}?$ENV{DEBBUGS_CONFIG_FILE}:'/etc/debbugs/config');
77
78 =item email_domain
79
80 The email domain of the bts
81
82 =cut
83
84 set_default(\%config,'email_domain','bugs.something');
85
86 =item list_domain
87
88 The list domain of the bts, defaults to the email domain
89
90 =cut
91
92 set_default(\%config,'list_domain',$config{email_domain});
93
94 =item web_host
95
96 The web host of the bts; defaults to the email domain
97
98 =cut
99
100 set_default(\%config,'web_host',$config{email_domain});
101
102 =item web_host_bug_dir
103
104 The directory of the web host on which bugs are kept, defaults to C<''>
105
106 =cut
107
108 set_default(\%config,'web_host_bug_dir','');
109
110 =item web_domain
111
112 Full path of the web domain where bugs are kept, defaults to the
113 concatenation of L</web_host> and L</web_host_bug_dir>
114
115 =cut
116
117 set_default(\%config,'web_domain',$config{web_host}.'/'.$config{web_host_bug_dir});
118
119 =item html_suffix
120
121 Suffix of html pages, defaults to .html
122
123 =cut
124
125 set_default(\%config,'html_suffix','.html');
126
127 =item cgi_domain
128
129 Full path of the web domain where cgi scripts are kept. Defaults to
130 the concatentation of L</web_host> and cgi.
131
132 =cut
133
134 set_default(\%config,'cgi_domain',$config{web_domain}.($config{web_domain}=~m{/$}?'':'/').'cgi');
135
136 =item mirrors
137
138 List of mirrors [What these mirrors are used for, no one knows.]
139
140 =cut
141
142
143 set_default(\%config,'mirrors',[]);
144
145 =item package_pages
146
147 Domain where the package pages are kept; links should work in a
148 package_pages/foopackage manner. Defaults to undef, which means that
149 package links will not be made.
150
151 =cut
152
153
154 set_default(\%config,'package_pages',undef);
155
156 =item subscription_domain
157
158 Domain where subscriptions to package lists happen
159
160 =cut
161
162
163 set_default(\%config,'subscription_domain',undef);
164
165 =back
166
167 =cut
168
169
170 =head2 Project Identification
171
172 =over
173
174 =item project
175
176 Name of the project
177
178 =cut
179
180 set_default(\%config,'project','Something');
181
182 =item project_title
183
184 Name of this install of Debbugs, defaults to "L</project> Debbugs Install"
185
186 =cut
187
188 set_default(\%config,'project_title',"$config{project} Debbugs Install");
189
190 =item maintainer
191
192 Name of the maintainer of this debbugs install
193
194 =cut
195
196 set_default(\%config,'maintainer','Local DebBugs Owner');
197
198 =item maintainer_webpage
199
200 Webpage of the maintainer of this install of debbugs
201
202 =cut
203
204 set_default(\%config,'maintainer_webpage',"$config{web_domain}/~owner");
205
206 =item maintainer_email
207
208 Email address of the maintainer of this Debbugs install
209
210 =cut
211
212 set_default(\%config,'maintainer_email','root@'.$config{email_domain});
213
214 =item unknown_maintainer_email
215
216 Email address where packages with an unknown maintainer will be sent
217
218 =cut
219
220 set_default(\%config,'unknown_maintainer_email',$config{maintainer_email});
221
222 =head2 BTS Mailing Lists
223
224
225 =over
226
227 =item submit_list
228
229 =item maint_list
230
231 =item forward_list
232
233 =item done_list
234
235 =item request_list
236
237 =item submitter_list
238
239 =item control_list
240
241 =item summary_list
242
243 =item mirror_list
244
245 =back
246
247 =cut
248
249 set_default(\%config,   'submit_list',   'bug-submit-list');
250 set_default(\%config,    'maint_list',    'bug-maint-list');
251 set_default(\%config,    'quiet_list',    'bug-quiet-list');
252 set_default(\%config,  'forward_list',  'bug-forward-list');
253 set_default(\%config,     'done_list',     'bug-done-list');
254 set_default(\%config,  'request_list',  'bug-request-list');
255 set_default(\%config,'submitter_list','bug-submitter-list');
256 set_default(\%config,  'control_list',  'bug-control-list');
257 set_default(\%config,  'summary_list',  'bug-summary-list');
258 set_default(\%config,   'mirror_list',   'bug-mirror-list');
259
260 =head2 Misc Options
261
262 =cut
263
264 set_default(\%config,'mailer','exim');
265 set_default(\%config,'bug','bug');
266 set_default(\%config,'bugs','bugs');
267 set_default(\%config,'remove_age',28);
268
269 set_default(\%config,'save_old_bugs',1);
270
271 set_default(\%config,'default_severity','normal');
272 set_default(\%config,'show_severities','critical, grave, normal, minor, wishlist');
273 set_default(\%config,'strong_severities',[qw(critical grave)]);
274 set_default(\%config,'severity_list',[qw(critical grave normal wishlist)]);
275 set_default(\%config,'severity_display',{critical => "Critical $config{bugs}",
276                                          grave    => "Grave $config{bugs}",
277                                          normal   => "Normal $config{bugs}",
278                                          wishlist => "Wishlist $config{bugs}",
279                                         });
280
281 set_default(\%config,'tags',[qw(patch wontfix moreinfo unreproducible fixed stable)]);
282
283 set_default(\%config,'bounce_froms','^mailer|^da?emon|^post.*mast|^root|^wpuser|^mmdf|^smt.*|'.
284             '^mrgate|^vmmail|^mail.*system|^uucp|-maiser-|^mal\@|'.
285             '^mail.*agent|^tcpmail|^bitmail|^mailman');
286
287 set_default(\%config,'config_dir',dirname(exists $ENV{DEBBUGS_CONFIG_FILE}?$ENV{DEBBUGS_CONFIG_FILE}:'/etc/debbugs/config'));
288 set_default(\%config,'spool_dir','/var/lib/debbugs/spool');
289 set_default(\%config,'incoming_dir','incoming');
290 set_default(\%config,'web_dir','/var/lib/debbugs/www');
291 set_default(\%config,'doc_dir','/var/lib/debbugs/www/txt');
292
293 set_default(\%config,'maintainer_file',$config{config_dir}.'/Maintainers');
294 set_default(\%config,'maintainer_file_override',$config{config_dir}.'/Maintainers.override');
295 set_default(\%config,'pseduo_desc_file',$config{config_dir}.'/pseudo-packages.description');
296 set_default(\%config,'package_source',$config{config_dir}.'/indices/sources');
297
298 set_default(\%config,'version_packages_dir',$config{spool_dir}.'/../versions/pkg');
299 #set_default(\%config,'version_packages_dir',$config{spool_dir}'/../versions/pkg');
300
301
302 sub read_config{
303      my ($conf_file) = @_;
304      # first, figure out what type of file we're reading in.
305      my $fh = new IO::File $conf_file,'r'
306           or die "Unable to open configuration file $conf_file for reading: $!";
307      # A new version configuration file must have a comment as its first line
308      my $first_line = <$fh>;
309      my ($version) = $first_line =~ /VERSION:\s*(\d+)/i;
310      if (defined $version) {
311           if ($version == 1) {
312                # Do something here;
313                die "Version 1 configuration files not implemented yet";
314           }
315           else {
316                die "Version $version configuration files are not supported";
317           }
318      }
319      else {
320           # Ugh. Old configuration file
321           # What we do here is we create a new Safe compartment
322           # so fucked up crap in the config file doesn't sink us.
323           my $cpt = new Safe or die "Unable to create safe compartment";
324           # perldoc Opcode; for details
325           $cpt->permit('require',':filesys_read','entereval','caller','pack','unpack','dofile');
326           $cpt->reval(q($gMaintainerFile = 'FOOOO'));
327           $cpt->reval(qq(require '$conf_file';));
328           die "Error in configuration file: $@" if $@;
329           # Now what we do is check out the contents of %EXPORT_TAGS to see exactly which variables
330           # we want to glob in from the configuration file
331           for my $variable (@{$EXPORT_TAGS{globals}}) {
332                my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
333                my $var_glob = $cpt->varglob($glob_name);
334                my $value; #= $cpt->reval("return $variable");
335                #print STDERR $value,qq(\n);
336                if (defined $var_glob) {{
337                     no strict 'refs';
338                     if ($glob_type eq '%') {
339                          $value = {%{*{$var_glob}}};
340                     }
341                     elsif ($glob_type eq '@') {
342                          $value = [@{*{$var_glob}}];
343                     }
344                     else {
345                          $value = ${*{$var_glob}};
346                     }
347                     # We punt here, because we can't tell if the value was
348                     # defined intentionally, or if it was just left alone;
349                     # this tries to set sane defaults.
350                     set_default(\%config,$hash_name,$value) if defined $value;
351                }}
352           }
353      }
354 }
355
356 sub __convert_name{
357      my ($variable) = @_;
358      my $hash_name = $variable;
359      $hash_name =~ s/^([\$\%\@])g//;
360      my $glob_type = $1;
361      my $glob_name = 'g'.$hash_name;
362      $hash_name =~ s/^([A-Z]+)/lc($1)/e;
363      $hash_name =~ s/([A-Z]+)/'_'.lc($1)/ge;
364      return $hash_name unless wantarray;
365      return ($hash_name,$glob_name,$glob_type);
366 }
367
368 # set_default
369
370 # sets the configuration hash to the default value if it's not set,
371 # otherwise doesn't do anything
372 # If $USING_GLOBALS, then sets an appropriate global.
373
374 sub set_default{
375      my ($config,$option,$value) = @_;
376      # update the configuration value
377      if (not $USING_GLOBALS and not exists $config{$option}) {
378           $config{$option} = $value;
379      }
380      else {
381           # Need to check if a value has already been set in a global
382      }
383      if ($USING_GLOBALS) {{
384           # fix up the variable name
385           my $varname = 'g'.join('',map {ucfirst $_} $option);
386           # Fix stupid HTML names
387           $varname =~ s/Html/HTML/;
388           no strict 'refs';
389           my $ref = ref $config{$option} || 'SCALAR';
390           *{"Debbugs::Config::${varname}"} = $config{$option};
391      }}
392 }
393
394
395 ### import magick
396
397 # All we care about here is whether we've been called with the globals option;
398 # if so, then we need to export some symbols back up; otherwise we call exporter.
399
400 sub import {
401      if (grep $_ eq ':globals', @_) {
402           $USING_GLOBALS=1;
403           for my $variable (@{$EXPORT_TAGS{globals}}) {
404                my $tmp = $variable;
405                no strict 'refs';
406                # Yes, I don't care if these are only used once
407                no warnings 'once';
408                # No, it doesn't bother me that I'm assigning an undefined value to a typeglob
409                no warnings 'misc';
410                my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
411                $tmp =~ s/^[\%\$\@]//;
412                *{"Debbugs::Config::${tmp}"} = ref($config{$hash_name})?$config{$hash_name}:\$config{$hash_name};
413           }
414      }
415      Debbugs::Config->export_to_level(1,@_);
416 }
417
418
419 1;