]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/Config.pm
* Move code from bugreport.cgi to Debbugs::CGI::Bugreport
[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 $gPseudoMaintFile $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(%gDistributionAliases),
65                                  qw(@gPostProcessall @gRemovalDefaultDistributionTags @gRemovalDistributionTags @gRemovalArchitectures),
66                                  qw(@gRemovalStrongSeverityDefaultDistributionTags),
67                                  qw(@gDefaultArchitectures),
68                                  qw($gTemplateDir),
69                                  qw($gDefaultPackage),
70                                  qw($gSpamMaxThreads $gSpamSpamsPerThread $gSpamKeepRunning $gSpamScan $gSpamCrossassassinDb),
71                                 ],
72                      text     => [qw($gBadEmailPrefix $gHTMLTail $gHTMLExpireNote),
73                                  ],
74                      config   => [qw(%config)],
75                     );
76      @EXPORT_OK = ();
77      Exporter::export_ok_tags(qw(globals text config));
78      $EXPORT_TAGS{all} = [@EXPORT_OK];
79      $ENV{HOME} = '' if not defined $ENV{HOME};
80 }
81
82 use File::Basename qw(dirname);
83 use IO::File;
84 use Safe;
85
86 =head1 CONFIGURATION VARIABLES
87
88 =head2 General Configuration
89
90 =over
91
92 =cut
93
94 # read in the files;
95 %config = ();
96 # untaint $ENV{DEBBUGS_CONFIG_FILE} if it's owned by us
97 # This enables us to test things that are -T.
98 if (exists $ENV{DEBBUGS_CONFIG_FILE}) {
99      if (${[stat($ENV{DEBBUGS_CONFIG_FILE})]}[4] = $<) {
100           $ENV{DEBBUGS_CONFIG_FILE} =~ /(.+)/;
101           $ENV{DEBBUGS_CONFIG_FILE} = $1;
102      }
103      else {
104           die "Environmental variable DEBBUGS_CONFIG_FILE set, and $ENV{DEBBUGS_CONFIG_FILE} is not owned by the user running this script.";
105      }
106 }
107 read_config(exists $ENV{DEBBUGS_CONFIG_FILE}?$ENV{DEBBUGS_CONFIG_FILE}:'/etc/debbugs/config');
108
109 =item email_domain $gEmailDomain
110
111 The email domain of the bts
112
113 =cut
114
115 set_default(\%config,'email_domain','bugs.something');
116
117 =item list_domain $gListDomain
118
119 The list domain of the bts, defaults to the email domain
120
121 =cut
122
123 set_default(\%config,'list_domain',$config{email_domain});
124
125 =item web_host $gWebHost
126
127 The web host of the bts; defaults to the email domain
128
129 =cut
130
131 set_default(\%config,'web_host',$config{email_domain});
132
133 =item web_host_bug_dir $gWebHostDir
134
135 The directory of the web host on which bugs are kept, defaults to C<''>
136
137 =cut
138
139 set_default(\%config,'web_host_bug_dir','');
140
141 =item web_domain $gWebDomain
142
143 Full path of the web domain where bugs are kept, defaults to the
144 concatenation of L</web_host> and L</web_host_bug_dir>
145
146 =cut
147
148 set_default(\%config,'web_domain',$config{web_host}.($config{web_host}=~m{/$}?'':'/').$config{web_host_bug_dir});
149
150 =item html_suffix $gHTMLSuffix
151
152 Suffix of html pages, defaults to .html
153
154 =cut
155
156 set_default(\%config,'html_suffix','.html');
157
158 =item cgi_domain $gCGIDomain
159
160 Full path of the web domain where cgi scripts are kept. Defaults to
161 the concatentation of L</web_host> and cgi.
162
163 =cut
164
165 set_default(\%config,'cgi_domain',$config{web_domain}.($config{web_domain}=~m{/$}?'':'/').'cgi');
166
167 =item mirrors @gMirrors
168
169 List of mirrors [What these mirrors are used for, no one knows.]
170
171 =cut
172
173
174 set_default(\%config,'mirrors',[]);
175
176 =item package_pages  $gPackagePages
177
178 Domain where the package pages are kept; links should work in a
179 package_pages/foopackage manner. Defaults to undef, which means that
180 package links will not be made.
181
182 =cut
183
184
185 set_default(\%config,'package_pages',undef);
186
187 =item package_pages  $gUsertagPackageDomain
188
189 Domain where where usertags of packages belong; defaults to $gPackagePages
190
191 =cut
192
193 set_default(\%config,'usertag_package_domain',$config{package_pages});
194
195
196 =item subscription_domain $gSubscriptionDomain
197
198 Domain where subscriptions to package lists happen
199
200 =cut
201
202
203 set_default(\%config,'subscription_domain',undef);
204
205 =back
206
207 =cut
208
209
210 =head2 Project Identification
211
212 =over
213
214 =item project $gProject
215
216 Name of the project
217
218 Default: 'Something'
219
220 =cut
221
222 set_default(\%config,'project','Something');
223
224 =item project_title $gProjectTitle
225
226 Name of this install of Debbugs, defaults to "L</project> Debbugs Install"
227
228 Default: "$config{project} Debbugs Install"
229
230 =cut
231
232 set_default(\%config,'project_title',"$config{project} Debbugs Install");
233
234 =item maintainer $gMaintainer
235
236 Name of the maintainer of this debbugs install
237
238 Default: 'Local DebBugs Owner's
239
240 =cut
241
242 set_default(\%config,'maintainer','Local DebBugs Owner');
243
244 =item maintainer_webpage $gMaintainerWebpage
245
246 Webpage of the maintainer of this install of debbugs
247
248 Default: "$config{web_domain}/~owner"
249
250 =cut
251
252 set_default(\%config,'maintainer_webpage',"$config{web_domain}/~owner");
253
254 =item maintainer_email $gMaintainerEmail
255
256 Email address of the maintainer of this Debbugs install
257
258 Default: 'root@'.$config{email_domain}
259
260 =cut
261
262 set_default(\%config,'maintainer_email','root@'.$config{email_domain});
263
264 =item unknown_maintainer_email
265
266 Email address where packages with an unknown maintainer will be sent
267
268 Default: $config{maintainer_email}
269
270 =back
271
272 =cut
273
274 set_default(\%config,'unknown_maintainer_email',$config{maintainer_email});
275
276 =head2 BTS Mailing Lists
277
278
279 =over
280
281 =item submit_list
282
283 =item maint_list
284
285 =item forward_list
286
287 =item done_list
288
289 =item request_list
290
291 =item submitter_list
292
293 =item control_list
294
295 =item summary_list
296
297 =item mirror_list
298
299 =back
300
301 =cut
302
303 set_default(\%config,   'submit_list',   'bug-submit-list');
304 set_default(\%config,    'maint_list',    'bug-maint-list');
305 set_default(\%config,    'quiet_list',    'bug-quiet-list');
306 set_default(\%config,  'forward_list',  'bug-forward-list');
307 set_default(\%config,     'done_list',     'bug-done-list');
308 set_default(\%config,  'request_list',  'bug-request-list');
309 set_default(\%config,'submitter_list','bug-submitter-list');
310 set_default(\%config,  'control_list',  'bug-control-list');
311 set_default(\%config,  'summary_list',  'bug-summary-list');
312 set_default(\%config,   'mirror_list',   'bug-mirror-list');
313 set_default(\%config,   'strong_list',   'bug-strong-list');
314
315 =head2 Misc Options
316
317 =over
318
319 =cut
320
321 set_default(\%config,'mailer','exim');
322 set_default(\%config,'bug','bug');
323 set_default(\%config,'bugs','bugs');
324
325 =item remove_age
326
327 Age at which bugs are archived/removed
328
329 Default: 28
330
331 =cut
332
333 set_default(\%config,'remove_age',28);
334
335 =item save_old_bugs
336
337 Whether old bugs are saved or deleted
338
339 Default: 1
340
341 =cut
342
343 set_default(\%config,'save_old_bugs',1);
344
345 =item distribution_aliases
346
347 Map of distribution aliases to the distribution name
348
349 Default:
350          {experimental => 'experimental',
351           unstable     => 'unstable',
352           testing      => 'testing',
353           stable       => 'stable',
354           oldstable    => 'oldstable',
355           sid          => 'unstable',
356           lenny        => 'testing',
357           etch         => 'stable',
358           sarge        => 'oldstable',
359          }
360
361 =cut
362
363 set_default(\%config,'distribution_aliases',
364             {experimental => 'experimental',
365              unstable     => 'unstable',
366              testing      => 'testing',
367              stable       => 'stable',
368              oldstable    => 'oldstable',
369              sid          => 'unstable',
370              lenny        => 'testing',
371              etch         => 'stable',
372              sarge        => 'oldstable',
373             },
374            );
375
376
377
378 =item distributions
379
380 List of valid distributions
381
382 Default: The values of the distribution aliases map.
383
384 =cut
385
386 my %_distributions_default;
387 @_distributions_default{values %{$config{distribution_aliases}}} = values %{$config{distribution_aliases}};
388 set_default(\%config,'distributions',[keys %_distributions_default]);
389
390
391 =item default_architectures
392
393 List of default architectures to use when architecture(s) are not
394 specified
395
396 Default: i386 amd64 arm ppc sparc alpha
397
398 =cut
399
400 set_default(\%config,'default_architectures',
401             [qw(i386 amd64 arm powerpc sparc alpha)]
402            );
403
404 =item removal_distribution_tags
405
406 Tags which specifiy distributions to check
407
408 Default: @{$config{distributions}}
409
410 =cut
411
412 set_default(\%config,'removal_distribution_tags',
413             [@{$config{distributions}}]);
414
415 =item removal_default_distribution_tags
416
417 For removal/archival purposes, all bugs are assumed to have these tags
418 set.
419
420 Default: qw(unstable testing);
421
422 =cut
423
424 set_default(\%config,'removal_default_distribution_tags',
425             [qw(unstable testing)]
426            );
427
428 =item removal_strong_severity_default_distribution_tags
429
430 For removal/archival purposes, all bugs with strong severity are
431 assumed to have these tags set.
432
433 Default: qw(unstable testing stable);
434
435 =cut
436
437 set_default(\%config,'removal_strong_severity_default_distribution_tags',
438             [qw(unstable testing stable)]
439            );
440
441
442 =item removal_architectures
443
444 For removal/archival purposes, these architectures are consulted if
445 there is more than one architecture applicable. If the bug is in a
446 package not in any of these architectures, the architecture actually
447 checked is undefined.
448
449 Default: value of default_architectures
450
451 =cut
452
453 set_default(\%config,'removal_architectures',
454             $config{default_architectures},
455            );
456
457
458 =item package_name_re
459
460 The regex which will match a package name
461
462 Default: '[a-z0-9][a-z0-9\.+-]+'
463
464 =cut
465
466 set_default(\%config,'package_name_re',
467             '[a-z0-9][a-z0-9\.+-]+');
468
469 =item package_version_re
470
471 The regex which will match a package version
472
473 Default: '[A-Za-z0-9:+\.-]+'
474
475 =cut
476
477
478 set_default(\%config,'package_version_re',
479             '[A-Za-z0-9:+\.~-]+');
480
481
482 =item default_package
483
484 This is the name of the default package. If set, bugs assigned to
485 packages without a maintainer and bugs missing a Package: psuedoheader
486 will be assigned to this package instead.
487
488 Defaults to unset, which is the traditional debbugs behavoir
489
490 =cut
491
492 set_default(\%config,'default_package',
493             undef
494            );
495
496
497 =item control_internal_requester
498
499 This address is used by Debbugs::Control as the request address which
500 sent a control request for faked log messages.
501
502 Default:"Debbugs Internal Request <$config{maintainer_email}>"
503
504 =cut
505
506 set_default(\%config,'control_internal_requester',
507             "Debbugs Internal Request <$config{maintainer_email}>",
508            );
509
510 =item control_internal_request_addr
511
512 This address is used by Debbugs::Control as the address to which a
513 faked log message request was sent.
514
515 Default: "internal_control\@$config{email_domain}";
516
517 =cut
518
519 set_default(\%config,'control_internal_request_addr',
520             'internal_control@'.$config{email_domain},
521            );
522
523
524 =item exclude_from_control
525
526 Addresses which are not allowed to send messages to control
527
528 =cut
529
530 set_default(\%config,'exclude_from_control',[]);
531
532
533
534
535 set_default(\%config,'default_severity','normal');
536 set_default(\%config,'show_severities','critical, grave, normal, minor, wishlist');
537 set_default(\%config,'strong_severities',[qw(critical grave)]);
538 set_default(\%config,'severity_list',[qw(critical grave normal wishlist)]);
539 set_default(\%config,'severity_display',{critical => "Critical $config{bugs}",
540                                          grave    => "Grave $config{bugs}",
541                                          normal   => "Normal $config{bugs}",
542                                          wishlist => "Wishlist $config{bugs}",
543                                         });
544
545 set_default(\%config,'tags',[qw(patch wontfix moreinfo unreproducible fixed),
546                              @{$config{distributions}}
547                             ]);
548
549 set_default(\%config,'bounce_froms','^mailer|^da?emon|^post.*mast|^root|^wpuser|^mmdf|^smt.*|'.
550             '^mrgate|^vmmail|^mail.*system|^uucp|-maiser-|^mal\@|'.
551             '^mail.*agent|^tcpmail|^bitmail|^mailman');
552
553 set_default(\%config,'config_dir',dirname(exists $ENV{DEBBUGS_CONFIG_FILE}?$ENV{DEBBUGS_CONFIG_FILE}:'/etc/debbugs/config'));
554 set_default(\%config,'spool_dir','/var/lib/debbugs/spool');
555 set_default(\%config,'incoming_dir','incoming');
556 set_default(\%config,'web_dir','/var/lib/debbugs/www');
557 set_default(\%config,'doc_dir','/var/lib/debbugs/www/txt');
558 set_default(\%config,'lib_path','/usr/lib/debbugs');
559
560
561 =item template_dir
562
563 directory of templates; defaults to /usr/share/debbugs/templates.
564
565 =cut
566
567 set_default(\%config,'template_dir','/usr/share/debbugs/templates');
568
569
570 set_default(\%config,'maintainer_file',$config{config_dir}.'/Maintainers');
571 set_default(\%config,'maintainer_file_override',$config{config_dir}.'/Maintainers.override');
572 set_default(\%config,'pseudo_maint_file',$config{config_dir}.'/pseudo-packages.maint');
573 set_default(\%config,'pseudo_desc_file',$config{config_dir}.'/pseudo-packages.description');
574 set_default(\%config,'package_source',$config{config_dir}.'/indices/sources');
575
576
577 =item version_packages_dir
578
579 Location where the version package information is kept; defaults to
580 spool_dir/../versions/pkg
581
582 =cut
583
584 set_default(\%config,'version_packages_dir',$config{spool_dir}.'/../versions/pkg');
585
586 =item version_time_index
587
588 Location of the version/time index file. Defaults to
589 spool_dir/../versions/idx/versions_time.idx if spool_dir/../versions
590 exists; otherwise defaults to undef.
591
592 =cut
593
594
595 set_default(\%config,'version_time_index', -d $config{spool_dir}.'/../versions' ? $config{spool_dir}.'/../versions/indices/versions_time.idx' : undef);
596
597 =item version_index
598
599 Location of the version index file. Defaults to
600 spool_dir/../versions/indices/versions.idx if spool_dir/../versions
601 exists; otherwise defaults to undef.
602
603 =cut
604
605 set_default(\%config,'version_index',-d $config{spool_dir}.'/../versions' ? $config{spool_dir}.'/../versions/indices/versions.idx' : undef);
606
607 =item binary_source_map
608
609 Location of the binary -> source map. Defaults to
610 spool_dir/../versions/indices/bin2src.idx if spool_dir/../versions
611 exists; otherwise defaults to undef.
612
613 =cut
614
615 set_default(\%config,'binary_source_map',-d $config{spool_dir}.'/../versions' ? $config{spool_dir}.'/../versions/indices/binsrc.idx' : undef);
616
617 =item source_binary_map
618
619 Location of the source -> binary map. Defaults to
620 spool_dir/../versions/indices/src2bin.idx if spool_dir/../versions
621 exists; otherwise defaults to undef.
622
623 =cut
624
625 set_default(\%config,'source_binary_map',-d $config{spool_dir}.'/../versions' ? $config{spool_dir}.'/../versions/indices/srcbin.idx' : undef);
626
627
628
629 set_default(\%config,'post_processall',[]);
630
631 =item sendmail
632
633 Sets the sendmail binary to execute; defaults to /usr/lib/sendmail
634
635 =cut
636
637 set_default(\%config,'sendmail','/usr/lib/sendmail');
638
639 =item spam_scan
640
641 Whether or not spamscan is being used; defaults to 0 (not being used
642
643 =cut
644
645 set_default(\%config,'spam_scan',0);
646
647 =item spam_crossassassin_db
648
649 Location of the crosassassin database, defaults to
650 spool_dir/../CrossAssassinDb
651
652 =cut
653
654 set_default(\%config,'spam_crossassassin_db',$config{spool_dir}.'/../CrossAssassinDb');
655
656 =item spam_max_cross
657
658 Maximum number of cross-posted messages
659
660 =cut
661
662 set_default(\%config,'spam_max_cross',6);
663
664
665 =item spam_spams_per_thread
666
667 Number of spams for each thread (on average). Defaults to 200
668
669 =cut
670
671 set_default(\%config,'spam_spams_per_thread',200);
672
673 =item spam_max_threads
674
675 Maximum number of threads to start. Defaults to 20
676
677 =cut
678
679 set_default(\%config,'spam_max_threads',20);
680
681 =item spam_keep_running
682
683 Maximum number of seconds to run without restarting. Defaults to 3600.
684
685 =cut
686
687 set_default(\%config,'spam_keep_running',3600);
688
689 =item spam_mailbox
690
691 Location to store spam messages; is run through strftime to allow for
692 %d,%m,%Y, et al. Defaults to 'spool_dir/../mail/spam/assassinated.%Y-%m-%d'
693
694 =cut
695
696 set_default(\%config,'spam_mailbox',$config{spool_dir}.'/../mail/spam/assassinated.%Y-%m-%d');
697
698 =item spam_crossassassin_mailbox
699
700 Location to store crossassassinated messages; is run through strftime
701 to allow for %d,%m,%Y, et al. Defaults to
702 'spool_dir/../mail/spam/crossassassinated.%Y-%m-%d'
703
704 =cut
705
706 set_default(\%config,'spam_crossassassin_mailbox',$config{spool_dir}.'/../mail/spam/crossassassinated.%Y-%m-%d');
707
708 =item spam_local_tests_only
709
710 Whether only local tests are run, defaults to 0
711
712 =cut
713
714 set_default(\%config,'spam_local_tests_only',0);
715
716 =item spam_user_prefs
717
718 User preferences for spamassassin, defaults to $ENV{HOME}/.spamassassin/user_prefs
719
720 =cut
721
722 set_default(\%config,'spam_user_prefs',"$ENV{HOME}/.spamassassin/user_prefs");
723
724 =item spam_rules_dir
725
726 Site rules directory for spamassassin, defaults to
727 '/usr/share/spamassassin'
728
729 =cut
730
731 set_default(\%config,'spam_rules_dir','/usr/share/spamassassin');
732
733 =back
734
735
736 =head2 Text Fields
737
738 The following are the only text fields in general use in the scripts;
739 a few additional text fields are defined in text.in, but are only used
740 in db2html and a few other specialty scripts.
741
742 Earlier versions of debbugs defined these values in /etc/debbugs/text,
743 but now they are required to be in the configuration file. [Eventually
744 the longer ones will move out into a fully fledged template system.]
745
746 =cut
747
748 =over
749
750 =item bad_email_prefix
751
752 This prefixes the text of all lines in a bad e-mail message ack.
753
754 =cut
755
756 set_default(\%config,'bad_email_prefix','');
757
758
759 =item text_instructions
760
761 This gives more information about bad e-mails to receive.in
762
763 =cut
764
765 set_default(\%config,'text_instructions',$config{bad_email_prefix});
766
767 =item html_tail
768
769 This shows up at the end of (most) html pages
770
771 In many pages this has been replaced by the html/tail template.
772
773 =cut
774
775 set_default(\%config,'html_tail',<<END);
776  <ADDRESS>$config{maintainer} &lt;<A HREF=\"mailto:$config{maintainer_email}\">$config{maintainer_email}</A>&gt;.
777  Last modified:
778  <!--timestamp-->
779  SUBSTITUTE_DTIME
780  <!--timestamp-->
781  <P>
782  <A HREF=\"http://$config{web_domain}/\">Debian $config{bug} tracking system</A><BR>
783  Copyright (C) 1999 Darren O. Benham,
784  1997,2003 nCipher Corporation Ltd,
785  1994-97 Ian Jackson.
786  </ADDRESS>
787 END
788
789
790 =item html_expire_note
791
792 This message explains what happens to archive/remove-able bugs
793
794 =cut
795
796 set_default(\%config,'html_expire_note',
797             "(Closed $config{bugs} are archived $config{remove_age} days after the last related message is received.)");
798
799 =back
800
801 =cut
802
803
804 sub read_config{
805      my ($conf_file) = @_;
806      # first, figure out what type of file we're reading in.
807      my $fh = new IO::File $conf_file,'r'
808           or die "Unable to open configuration file $conf_file for reading: $!";
809      # A new version configuration file must have a comment as its first line
810      my $first_line = <$fh>;
811      my ($version) = defined $first_line?$first_line =~ /VERSION:\s*(\d+)/i:undef;
812      if (defined $version) {
813           if ($version == 1) {
814                # Do something here;
815                die "Version 1 configuration files not implemented yet";
816           }
817           else {
818                die "Version $version configuration files are not supported";
819           }
820      }
821      else {
822           # Ugh. Old configuration file
823           # What we do here is we create a new Safe compartment
824           # so fucked up crap in the config file doesn't sink us.
825           my $cpt = new Safe or die "Unable to create safe compartment";
826           # perldoc Opcode; for details
827           $cpt->permit('require',':filesys_read','entereval','caller','pack','unpack','dofile');
828           $cpt->reval(qq(require '$conf_file';));
829           die "Error in configuration file: $@" if $@;
830           # Now what we do is check out the contents of %EXPORT_TAGS to see exactly which variables
831           # we want to glob in from the configuration file
832           for my $variable (@{$EXPORT_TAGS{globals}}) {
833                my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
834                my $var_glob = $cpt->varglob($glob_name);
835                my $value; #= $cpt->reval("return $variable");
836                # print STDERR "$variable $value",qq(\n);
837                if (defined $var_glob) {{
838                     no strict 'refs';
839                     if ($glob_type eq '%') {
840                          $value = {%{*{$var_glob}}} if defined *{$var_glob}{HASH};
841                     }
842                     elsif ($glob_type eq '@') {
843                          $value = [@{*{$var_glob}}] if defined *{$var_glob}{ARRAY};
844                     }
845                     else {
846                          $value = ${*{$var_glob}};
847                     }
848                     # We punt here, because we can't tell if the value was
849                     # defined intentionally, or if it was just left alone;
850                     # this tries to set sane defaults.
851                     set_default(\%config,$hash_name,$value) if defined $value;
852                }}
853           }
854      }
855 }
856
857 sub __convert_name{
858      my ($variable) = @_;
859      my $hash_name = $variable;
860      $hash_name =~ s/^([\$\%\@])g//;
861      my $glob_type = $1;
862      my $glob_name = 'g'.$hash_name;
863      $hash_name =~ s/(HTML|CGI)/ucfirst(lc($1))/ge;
864      $hash_name =~ s/^([A-Z]+)/lc($1)/e;
865      $hash_name =~ s/([A-Z]+)/'_'.lc($1)/ge;
866      return $hash_name unless wantarray;
867      return ($hash_name,$glob_name,$glob_type);
868 }
869
870 # set_default
871
872 # sets the configuration hash to the default value if it's not set,
873 # otherwise doesn't do anything
874 # If $USING_GLOBALS, then sets an appropriate global.
875
876 sub set_default{
877      my ($config,$option,$value) = @_;
878      my $varname;
879      if ($USING_GLOBALS) {
880           # fix up the variable name
881           $varname = 'g'.join('',map {ucfirst $_} split /_/, $option);
882           # Fix stupid HTML names
883           $varname =~ s/(Html|Cgi)/uc($1)/ge;
884      }
885      # update the configuration value
886      if (not $USING_GLOBALS and not exists $config->{$option}) {
887           $config->{$option} = $value;
888      }
889      elsif ($USING_GLOBALS) {{
890           no strict 'refs';
891           # Need to check if a value has already been set in a global
892           if (defined *{"Debbugs::Config::${varname}"}) {
893                $config->{$option} = *{"Debbugs::Config::${varname}"};
894           }
895           else {
896                $config->{$option} = $value;
897           }
898      }}
899      if ($USING_GLOBALS) {{
900           no strict 'refs';
901           *{"Debbugs::Config::${varname}"} = $config->{$option};
902      }}
903 }
904
905
906 ### import magick
907
908 # All we care about here is whether we've been called with the globals or text option;
909 # if so, then we need to export some symbols back up.
910 # In any event, we call exporter.
911
912 sub import {
913      if (grep /^:(?:text|globals)$/, @_) {
914           $USING_GLOBALS=1;
915           for my $variable (map {@$_} @EXPORT_TAGS{map{(/^:(text|globals)$/?($1):())} @_}) {
916                my $tmp = $variable;
917                no strict 'refs';
918                # Yes, I don't care if these are only used once
919                no warnings 'once';
920                # No, it doesn't bother me that I'm assigning an undefined value to a typeglob
921                no warnings 'misc';
922                my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
923                $tmp =~ s/^[\%\$\@]//;
924                *{"Debbugs::Config::${tmp}"} = ref($config{$hash_name})?$config{$hash_name}:\$config{$hash_name};
925           }
926      }
927      Debbugs::Config->export_to_level(1,@_);
928 }
929
930
931 1;