1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
6 # <sales@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 # 02110-1301 or visit their web page on the internet at
27 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 # CONTRIBUTION SUBMISSION POLICY:
32 # (The following paragraph is not intended to limit the rights granted
33 # to you to modify and distribute this software under the terms of
34 # the GNU General Public License and is only of importance to you if
35 # you choose to contribute your changes and enhancements to the
36 # community by submitting them to Best Practical Solutions, LLC.)
38 # By intentionally submitting any modifications, corrections or
39 # derivatives to this work, or any other work intended for use with
40 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 # you are the copyright holder for those contributions and you grant
42 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 # royalty-free, perpetual, license to use, copy, create derivative
44 # works based on those contributions, and sublicense and distribute
45 # those contributions and any derivatives thereof.
47 # END BPS TAGGED BLOCK }}}
59 RT::Config - RT's config
65 my $config = RT::Config->new;
69 my $rt_web_path = $config->Get('WebPath');
70 $config->Set(EmailOutputEncoding => 'latin1');
72 # get config object from RT package
75 my $config = RT->Config;
79 C<RT::Config> class provide access to RT's and RT extensions' config files.
81 RT uses two files for site configuring:
83 First file is F<RT_Config.pm> - core config file. This file is shipped
84 with RT distribution and contains default values for all available options.
85 B<You should never edit this file.>
87 Second file is F<RT_SiteConfig.pm> - site config file. You can use it
88 to customize your RT instance. In this file you can override any option
89 listed in core config file.
91 RT extensions could also provide thier config files. Extensions should
92 use F<< <NAME>_Config.pm >> and F<< <NAME>_SiteConfig.pm >> names for
93 config files, where <NAME> is extension name.
95 B<NOTE>: All options from RT's config and extensions' configs are saved
96 in one place and thus extension could override RT's options, but it is not
103 Hash of Config options that may be user overridable
104 or may require more logic than should live in RT_*Config.pm
106 Keyed by config name, there are several properties that
107 can be set for each config optin:
109 Section - What header this option should be grouped
110 under on the user Settings page
111 Overridable - Can users change this option
112 SortOrder - Within a Section, how should the options be sorted
113 for display to the user
114 Widget - Mason component path to widget that should be used
115 to display this config option
116 WidgetArguments - An argument hash passed to the WIdget
117 Description - Friendly description to show the user
118 Values - Arrayref of options (for select Widget)
119 ValuesLabel - Hashref, key is the Value from the Values
120 list, value is a user friendly description
122 Callback - subref that receives no arguments. It returns
123 a hashref of items that are added to the rest
124 of the WidgetArguments
125 PostLoadCheck - subref passed the RT::Config object and the current
126 setting of the config option. Can make further checks
127 (such as seeing if a library is installed) and then change
128 the setting of this or other options in the Config using
129 the RT::Config option.
130 Obfuscate - subref passed the RT::Config object, current setting of the config option
131 and a user object, can return obfuscated value. it's called in
132 RT->Config->GetObfuscated()
137 # General user overridable options
139 Section => 'General',
142 Widget => '/Widgets/Form/Select',
144 Description => 'Default queue', #loc
146 my $ret = { Values => [], ValuesLabel => {}};
147 my $q = RT::Queues->new($HTML::Mason::Commands::session{'CurrentUser'});
149 while (my $queue = $q->Next) {
150 next unless $queue->CurrentUserHasRight("CreateTicket");
151 push @{$ret->{Values}}, $queue->Id;
152 $ret->{ValuesLabel}{$queue->Id} = $queue->Name;
158 RememberDefaultQueue => {
159 Section => 'General',
162 Widget => '/Widgets/Form/Boolean',
164 Description => 'Remember default queue' # loc
168 Section => 'General',
171 Widget => '/Widgets/Form/Select',
173 Description => 'Username format', # loc
174 Values => [qw(concise verbose)],
176 concise => 'Short usernames', # loc
177 verbose => 'Name and email address', # loc
181 AutocompleteOwners => {
182 Section => 'General',
185 Widget => '/Widgets/Form/Boolean',
187 Description => 'Use autocomplete to find owners?', # loc
188 Hints => 'Replaces the owner dropdowns with textboxes' #loc
191 WebDefaultStylesheet => {
192 Section => 'General', #loc
195 Widget => '/Widgets/Form/Select',
197 Description => 'Theme', #loc
198 # XXX: we need support for 'get values callback'
199 Values => [qw(web2 freeside2.1 freeside3 aileron ballard)],
201 PostLoadCheck => sub {
203 my $value = $self->Get('WebDefaultStylesheet');
205 my @comp_roots = RT::Interface::Web->ComponentRoots;
206 for my $comp_root (@comp_roots) {
207 return if -d $comp_root.'/NoAuth/css/'.$value;
210 $RT::Logger->warning(
211 "The default stylesheet ($value) does not exist in this instance of RT. "
212 . "Defaulting to freeside3."
215 #$self->Set('WebDefaultStylesheet', 'aileron');
216 $self->Set('WebDefaultStylesheet', 'freeside3');
219 UseSideBySideLayout => {
220 Section => 'Ticket composition',
223 Widget => '/Widgets/Form/Boolean',
225 Description => 'Use a two column layout for create and update forms?' # loc
228 MessageBoxRichText => {
229 Section => 'Ticket composition',
232 Widget => '/Widgets/Form/Boolean',
234 Description => 'WYSIWYG message composer' # loc
237 MessageBoxRichTextHeight => {
238 Section => 'Ticket composition',
241 Widget => '/Widgets/Form/Integer',
243 Description => 'WYSIWYG composer height', # loc
247 Section => 'Ticket composition',
250 Widget => '/Widgets/Form/Integer',
252 Description => 'Message box width', #loc
255 MessageBoxHeight => {
256 Section => 'Ticket composition',
259 Widget => '/Widgets/Form/Integer',
261 Description => 'Message box height', #loc
265 Section => 'Ticket composition', #loc
268 Widget => '/Widgets/Form/Select',
270 Description => 'Message box wrapping', #loc
271 Values => [qw(SOFT HARD)],
272 Hints => "When the WYSIWYG editor is not enabled, this setting determines whether automatic line wraps in the ticket message box are sent to RT or not.", # loc
275 DefaultTimeUnitsToHours => {
276 Section => 'Ticket composition', #loc
279 Widget => '/Widgets/Form/Boolean',
281 Description => 'Enter time in hours by default', #loc
282 Hints => 'Only for entry, not display', #loc
285 SearchResultsRefreshInterval => {
286 Section => 'General', #loc
289 Widget => '/Widgets/Form/Select',
291 Description => 'Search results refresh interval', #loc
292 Values => [qw(0 120 300 600 1200 3600 7200)],
294 0 => "Don't refresh search results.", #loc
295 120 => "Refresh search results every 2 minutes.", #loc
296 300 => "Refresh search results every 5 minutes.", #loc
297 600 => "Refresh search results every 10 minutes.", #loc
298 1200 => "Refresh search results every 20 minutes.", #loc
299 3600 => "Refresh search results every 60 minutes.", #loc
300 7200 => "Refresh search results every 120 minutes.", #loc
305 # User overridable options for RT at a glance
306 DefaultSummaryRows => {
307 Section => 'RT at a glance', #loc
310 Widget => '/Widgets/Form/Integer',
312 Description => 'Number of search results', #loc
315 HomePageRefreshInterval => {
316 Section => 'RT at a glance', #loc
319 Widget => '/Widgets/Form/Select',
321 Description => 'Home page refresh interval', #loc
322 Values => [qw(0 120 300 600 1200 3600 7200)],
324 0 => "Don't refresh home page.", #loc
325 120 => "Refresh home page every 2 minutes.", #loc
326 300 => "Refresh home page every 5 minutes.", #loc
327 600 => "Refresh home page every 10 minutes.", #loc
328 1200 => "Refresh home page every 20 minutes.", #loc
329 3600 => "Refresh home page every 60 minutes.", #loc
330 7200 => "Refresh home page every 120 minutes.", #loc
335 # User overridable options for Ticket displays
337 Section => 'Ticket display', #loc
340 Widget => '/Widgets/Form/Integer',
342 Description => 'Maximum inline message length', #loc
344 "Length in characters; Use '0' to show all messages inline, regardless of length" #loc
347 OldestTransactionsFirst => {
348 Section => 'Ticket display',
351 Widget => '/Widgets/Form/Boolean',
353 Description => 'Show oldest history first', #loc
356 DeferTransactionLoading => {
357 Section => 'Ticket display',
360 Widget => '/Widgets/Form/Boolean',
362 Description => 'Hide ticket history by default', #loc
365 ShowUnreadMessageNotifications => {
366 Section => 'Ticket display',
369 Widget => '/Widgets/Form/Boolean',
371 Description => 'Notify me of unread messages', #loc
376 Section => 'Ticket display',
379 Widget => '/Widgets/Form/Boolean',
381 Description => 'add <pre> tag around plain text attachments', #loc
382 Hints => "Use this to protect the format of plain text" #loc
386 Section => 'Ticket display',
389 Widget => '/Widgets/Form/Boolean',
391 Description => 'display wrapped and formatted plain text attachments', #loc
392 Hints => 'Use css rules to display text monospaced and with formatting preserved, but wrap as needed. This does not work well with IE6 and you should use the previous option', #loc
395 DisplayAfterQuickCreate => {
396 Section => 'Ticket display',
399 Widget => '/Widgets/Form/Boolean',
401 Description => 'On Quick Create, redirect to ticket display', #loc
405 MoreAboutRequestorTicketList => {
406 Section => 'Ticket display', #loc
409 Widget => '/Widgets/Form/Select',
411 Description => q|What tickets to display in the 'More about requestor' box|, #loc
412 Values => [qw(Active Inactive All None)],
414 Active => "Show the Requestor's 10 highest priority active tickets", #loc
415 Inactive => "Show the Requestor's 10 highest priority inactive tickets", #loc
416 All => "Show the Requestor's 10 highest priority tickets", #loc
417 None => "Show no tickets for the Requestor", #loc
421 SimplifiedRecipients => {
422 Section => 'Ticket display', #loc
425 Widget => '/Widgets/Form/Boolean',
427 Description => q|Show simplified recipient list on ticket update|, #loc
430 DisplayTicketAfterQuickCreate => {
431 Section => 'Ticket display',
434 Widget => '/Widgets/Form/Boolean',
436 Description => q{Display ticket after "Quick Create"}, #loc
440 # User overridable locale options
442 Section => 'Locale', #loc
444 Widget => '/Widgets/Form/Select',
446 Description => 'Date format', #loc
447 Callback => sub { my $ret = { Values => [], ValuesLabel => {}};
448 my $date = RT::Date->new($HTML::Mason::Commands::session{'CurrentUser'});
450 foreach my $value ($date->Formatters) {
451 push @{$ret->{Values}}, $value;
452 $ret->{ValuesLabel}{$value} = $date->$value();
461 PostLoadCheck => sub {
463 my $value = $self->Get('RTAddressRegexp');
466 'The RTAddressRegexp option is not set in the config.'
467 .' Not setting this option results in additional SQL queries to'
468 .' check whether each address belongs to RT or not.'
469 .' It is especially important to set this option if RT recieves'
470 .' emails on addresses that are not in the database or config.'
472 } elsif (ref $value and ref $value eq "Regexp") {
473 # Ensure that the regex is case-insensitive; while the
474 # local part of email addresses is _technically_
475 # case-sensitive, most MTAs don't treat it as such.
476 $RT::Logger->warning(
477 'RTAddressRegexp is set to a case-sensitive regular expression.'
478 .' This may lead to mail loops with MTAs which treat the'
479 .' local part as case-insensitive -- which is most of them.'
480 ) if "$value" =~ /^\(\?[a-z]*-([a-z]*):/ and "$1" =~ /i/;
484 # User overridable mail options
486 Section => 'Mail', #loc
488 Default => 'Individual messages',
489 Widget => '/Widgets/Form/Select',
491 Description => 'Email delivery', #loc
493 'Individual messages', #loc
495 'Weekly digest', #loc
501 Section => 'Mail', #loc
504 Widget => '/Widgets/Form/Boolean',
506 Description => 'Outgoing mail', #loc
507 Hints => 'Should RT send you mail for ticket updates you make?', #loc
511 # this tends to break extensions that stash links in ticket update pages
514 PostLoadCheck => sub {
515 my ($self,$value) = @_;
516 $RT::Logger->error("your \$Organization setting ($value) appears to contain whitespace. Please fix this.")
521 # Internal config options
524 PostLoadCheck => sub {
526 my $v = $self->Get('FullTextSearch');
527 return unless $v->{Enable} and $v->{Indexed};
528 my $dbtype = $self->Get('DatabaseType');
529 if ($dbtype eq 'Oracle') {
530 if (not $v->{IndexName}) {
531 $RT::Logger->error("No IndexName set for full-text index; disabling");
532 $v->{Enable} = $v->{Indexed} = 0;
534 } elsif ($dbtype eq 'Pg') {
536 if (not $v->{'Column'}) {
537 $RT::Logger->error("No Column set for full-text index; disabling");
538 $v->{Enable} = $v->{Indexed} = 0;
539 } elsif ($v->{'Column'} eq "Content"
540 and (not $v->{'Table'} or $v->{'Table'} eq "Attachments")) {
541 $RT::Logger->error("Column for full-text index is set to Content, not tsvector column; disabling");
542 $v->{Enable} = $v->{Indexed} = 0;
544 } elsif ($dbtype eq 'mysql') {
545 if (not $v->{'Table'}) {
546 $RT::Logger->error("No Table set for full-text index; disabling");
547 $v->{Enable} = $v->{Indexed} = 0;
548 } elsif ($v->{'Table'} eq "Attachments") {
549 $RT::Logger->error("Table for full-text index is set to Attachments, not SphinxSE table; disabling");
550 $v->{Enable} = $v->{Indexed} = 0;
551 } elsif (not $v->{'MaxMatches'}) {
552 $RT::Logger->warn("No MaxMatches set for full-text index; defaulting to 10000");
553 $v->{MaxMatches} = 10_000;
556 $RT::Logger->error("Indexed full-text-search not supported for $dbtype");
563 PostLoadCheck => sub {
567 return if $INC{'GraphViz.pm'};
569 return if eval {require GraphViz; 1};
570 $RT::Logger->debug("You've enabled GraphViz, but we couldn't load the module: $@");
571 $self->Set( DisableGraphViz => 1 );
576 PostLoadCheck => sub {
580 return if $INC{'GD.pm'};
582 return if eval {require GD; 1};
583 $RT::Logger->debug("You've enabled GD, but we couldn't load the module: $@");
584 $self->Set( DisableGD => 1 );
587 MailPlugins => { Type => 'ARRAY' },
590 PostLoadCheck => sub {
592 my $value = $self->Get('Plugins');
593 # XXX Remove in RT 4.2
594 return unless $value and grep {$_ eq "RT::FM"} @{$value};
595 warn 'RTFM has been integrated into core RT, and must be removed from your @Plugins';
598 GnuPG => { Type => 'HASH' },
599 GnuPGOptions => { Type => 'HASH',
600 PostLoadCheck => sub {
602 my $gpg = $self->Get('GnuPG');
603 return unless $gpg->{'Enable'};
604 my $gpgopts = $self->Get('GnuPGOptions');
605 unless (-d $gpgopts->{homedir} && -r _ ) { # no homedir, no gpg
607 "RT's GnuPG libraries couldn't successfully read your".
608 " configured GnuPG home directory (".$gpgopts->{homedir}
609 ."). PGP support has been disabled");
610 $gpg->{'Enable'} = 0;
615 require RT::Crypt::GnuPG;
616 unless (RT::Crypt::GnuPG->Probe()) {
618 "RT's GnuPG libraries couldn't successfully execute gpg.".
619 " PGP support has been disabled");
620 $gpg->{'Enable'} = 0;
624 ReferrerWhitelist => { Type => 'ARRAY' },
625 ResolveDefaultUpdateType => {
626 PostLoadCheck => sub {
629 return unless $value;
630 $RT::Logger->info('The ResolveDefaultUpdateType config option has been deprecated. '.
631 'You can change the site default in your %Lifecycles config.');
635 PostLoadCheck => sub {
639 # "In most cases, you should leave $WebPath set to '' (an empty value)."
640 return unless $value;
642 # try to catch someone who assumes that you shouldn't leave this empty
644 $RT::Logger->error("For the WebPath config option, use the empty string instead of /");
648 # $WebPath requires a leading / but no trailing /, or it can be blank.
649 return if $value =~ m{^/.+[^/]$};
651 if ($value =~ m{/$}) {
652 $RT::Logger->error("The WebPath config option requires no trailing slash");
655 if ($value !~ m{^/}) {
656 $RT::Logger->error("The WebPath config option requires a leading slash");
661 PostLoadCheck => sub {
666 $RT::Logger->error("You must set the WebDomain config option");
670 if ($value =~ m{^(\w+://)}) {
671 $RT::Logger->error("The WebDomain config option must not contain a scheme ($1)");
675 if ($value =~ m{(/.*)}) {
676 $RT::Logger->error("The WebDomain config option must not contain a path ($1)");
680 if ($value =~ m{:(\d*)}) {
681 $RT::Logger->error("The WebDomain config option must not contain a port ($1)");
687 PostLoadCheck => sub {
692 $RT::Logger->error("You must set the WebPort config option");
696 if ($value !~ m{^\d+$}) {
697 $RT::Logger->error("The WebPort config option must be an integer");
702 PostLoadCheck => sub {
707 $RT::Logger->error("You must set the WebBaseURL config option");
711 if ($value !~ m{^https?://}i) {
712 $RT::Logger->error("The WebBaseURL config option must contain a scheme (http or https)");
715 if ($value =~ m{/$}) {
716 $RT::Logger->error("The WebBaseURL config option requires no trailing slash");
719 if ($value =~ m{^https?://.+?(/[^/].*)}i) {
720 $RT::Logger->error("The WebBaseURL config option must not contain a path ($1)");
725 PostLoadCheck => sub {
730 $RT::Logger->error("You must set the WebURL config option");
734 if ($value !~ m{^https?://}i) {
735 $RT::Logger->error("The WebURL config option must contain a scheme (http or https)");
738 if ($value !~ m{/$}) {
739 $RT::Logger->error("The WebURL config option requires a trailing slash");
743 EmailInputEncodings => {
745 PostLoadCheck => sub {
747 my $value = $self->Get('EmailInputEncodings');
748 return unless $value && @$value;
751 foreach my $encoding ( grep defined && length, splice @$value ) {
752 next if $seen{ $encoding };
753 if ( $encoding eq '*' ) {
754 unshift @$value, '*';
758 my $canonic = Encode::resolve_alias( $encoding );
759 unless ( $canonic ) {
760 warn "Unknown encoding '$encoding' in \@EmailInputEncodings option";
762 elsif ( $seen{ $canonic }++ ) {
766 push @$value, $canonic;
774 PostLoadCheck => sub {
777 # XXX Remove in RT 4.2
779 The ActiveStatus configuration has been replaced by the new Lifecycles
780 functionality. You should set the 'active' property of the 'default'
781 lifecycle and add transition rules; see RT_Config.pm for documentation.
787 PostLoadCheck => sub {
790 # XXX Remove in RT 4.2
792 The InactiveStatus configuration has been replaced by the new Lifecycles
793 functionality. You should set the 'inactive' property of the 'default'
794 lifecycle and add transition rules; see RT_Config.pm for documentation.
805 Object constructor returns new object. Takes no arguments.
811 my $class = ref($proto) ? ref($proto) : $proto;
812 my $self = bless {}, $class;
829 my %args = ( File => '', @_ );
830 $args{'File'} =~ s/(?<=Config)(?=\.pm$)/Meta/;
836 Load all configs. First of all load RT's config then load
837 extensions' config files in alphabetical order.
845 $self->InitConfig( File => 'RT_Config.pm' );
846 $self->LoadConfig( File => 'RT_Config.pm' );
848 my @configs = $self->Configs;
849 $self->InitConfig( File => $_ ) foreach @configs;
850 $self->LoadConfig( File => $_ ) foreach @configs;
856 Takes param hash with C<File> field.
857 First, the site configuration file is loaded, in order to establish
858 overall site settings like hostname and name of RT instance.
859 Then, the core configuration file is loaded to set fallback values
860 for all settings; it bases some values on settings from the site
863 B<Note> that core config file don't change options if site config
864 has set them so to add value to some option instead of
865 overriding you have to copy original value from core config file.
871 my %args = ( File => '', @_ );
872 $args{'File'} =~ s/(?<!Site)(?=Config\.pm$)/Site/;
873 if ( $args{'File'} eq 'RT_SiteConfig.pm'
874 and my $site_config = $ENV{RT_SITE_CONFIG} )
876 $self->_LoadConfig( %args, File => $site_config );
878 $self->_LoadConfig(%args);
880 $args{'File'} =~ s/Site(?=Config\.pm$)//;
881 $self->_LoadConfig(%args);
887 my %args = ( File => '', @_ );
889 my ($is_ext, $is_site);
890 if ( $args{'File'} eq ($ENV{RT_SITE_CONFIG}||'') ) {
891 ($is_ext, $is_site) = ('', 1);
893 $is_ext = $args{'File'} =~ /^(?!RT_)(?:(.*)_)(?:Site)?Config/ ? $1 : '';
894 $is_site = $args{'File'} =~ /SiteConfig/ ? 1 : 0;
899 local *Set = sub(\[$@%]@) {
900 my ( $opt_ref, @args ) = @_;
901 my ( $pack, $file, $line ) = caller;
902 return $self->SetFromConfig(
908 SiteConfig => $is_site,
909 Extension => $is_ext,
912 my @etc_dirs = ($RT::LocalEtcPath);
913 push @etc_dirs, RT->PluginDirs('etc') if $is_ext;
914 push @etc_dirs, $RT::EtcPath, @INC;
915 local @INC = @etc_dirs;
916 require $args{'File'};
919 return 1 if $is_site && $@ =~ /^Can't locate \Q$args{File}/;
920 if ( $is_site || $@ !~ /^Can't locate \Q$args{File}/ ) {
921 die qq{Couldn't load RT config file $args{'File'}:\n\n$@};
924 my $username = getpwuid($>);
925 my $group = getgrgid($();
927 my ( $file_path, $fileuid, $filegid );
928 foreach ( $RT::LocalEtcPath, $RT::EtcPath, @INC ) {
929 my $tmp = File::Spec->catfile( $_, $args{File} );
930 ( $fileuid, $filegid ) = ( stat($tmp) )[ 4, 5 ];
931 if ( defined $fileuid ) {
936 unless ($file_path) {
938 qq{Couldn't load RT config file $args{'File'} as user $username / group $group.\n}
939 . qq{The file couldn't be found in $RT::LocalEtcPath and $RT::EtcPath.\n$@};
944 RT couldn't load RT config file %s as:
948 The file is owned by user %s and group %s.
950 This usually means that the user/group your webserver is running
951 as cannot read the file. Be careful not to make the permissions
952 on this file too liberal, because it contains database passwords.
953 You may need to put the webserver user in the appropriate group
954 (%s) or change permissions be able to run succesfully.
957 my $fileusername = getpwuid($fileuid);
958 my $filegroup = getgrgid($filegid);
959 my $errormessage = sprintf( $message,
960 $file_path, $fileusername, $filegroup, $filegroup );
961 die "$errormessage\n$@";
968 foreach my $o ( grep $META{$_}{'PostLoadCheck'}, $self->Options( Overridable => undef ) ) {
969 $META{$o}->{'PostLoadCheck'}->( $self, $self->Get($o) );
975 Returns list of config files found in local etc, plugins' etc
976 and main etc directories.
984 foreach my $path ( $RT::LocalEtcPath, RT->PluginDirs('etc'), $RT::EtcPath ) {
985 my $mask = File::Spec->catfile( $path, "*_Config.pm" );
986 my @files = glob $mask;
987 @files = grep !/^RT_Config\.pm$/,
988 grep $_ && /^\w+_Config\.pm$/,
989 map { s/^.*[\\\/]//; $_ } @files;
990 push @configs, sort @files;
994 @configs = grep !$seen{$_}++, @configs;
1000 Takes name of the option as argument and returns its current value.
1002 In the case of a user-overridable option, first checks the user's
1003 preferences before looking for site-wide configuration.
1005 Returns values from RT_SiteConfig, RT_Config and then the %META hash
1006 of configuration variables's "Default" for this config variable,
1009 Returns different things in scalar and array contexts. For scalar
1010 options it's not that important, however for arrays and hash it's.
1011 In scalar context returns references to arrays and hashes.
1013 Use C<scalar> perl's op to force context, especially when you use
1014 C<(..., Argument => RT->Config->Get('ArrayOpt'), ...)>
1015 as perl's '=>' op doesn't change context of the right hand argument to
1016 scalar. Instead use C<(..., Argument => scalar RT->Config->Get('ArrayOpt'), ...)>.
1018 It's also important for options that have no default value(no default
1019 in F<etc/RT_Config.pm>). If you don't force scalar context then you'll
1020 get empty list and all your named args will be messed up. For example
1021 C<(arg1 => 1, arg2 => RT->Config->Get('OptionDoesNotExist'), arg3 => 3)>
1022 will result in C<(arg1 => 1, arg2 => 'arg3', 3)> what is most probably
1023 unexpected, or C<(arg1 => 1, arg2 => RT->Config->Get('ArrayOption'), arg3 => 3)>
1024 will result in C<(arg1 => 1, arg2 => 'element of option', 'another_one' => ..., 'arg3', 3)>.
1029 my ( $self, $name, $user ) = @_;
1032 if ( $user && $user->id && $META{$name}->{'Overridable'} ) {
1033 $user = $user->UserObj if $user->isa('RT::CurrentUser');
1034 my $prefs = $user->Preferences($RT::System);
1035 $res = $prefs->{$name} if $prefs;
1037 $res = $OPTIONS{$name} unless defined $res;
1038 $res = $META{$name}->{'Default'} unless defined $res;
1039 return $self->_ReturnValue( $res, $META{$name}->{'Type'} || 'SCALAR' );
1042 =head2 GetObfuscated
1044 the same as Get, except it returns Obfuscated value via Obfuscate sub
1050 my ( $name, $user ) = @_;
1051 my $obfuscate = $META{$name}->{Obfuscate};
1053 # we use two Get here is to simplify the logic of the return value
1054 # configs need obfuscation are supposed to be less, so won't be too heavy
1056 return $self->Get(@_) unless $obfuscate;
1058 my $res = $self->Get(@_);
1059 $res = $obfuscate->( $self, $res, $user );
1060 return $self->_ReturnValue( $res, $META{$name}->{'Type'} || 'SCALAR' );
1065 Set option's value to new value. Takes name of the option and new value.
1068 The new value should be scalar, array or hash depending on type of the option.
1069 If the option is not defined in meta or the default RT config then it is of
1075 my ( $self, $name ) = ( shift, shift );
1077 my $old = $OPTIONS{$name};
1078 my $type = $META{$name}->{'Type'} || 'SCALAR';
1079 if ( $type eq 'ARRAY' ) {
1080 $OPTIONS{$name} = [@_];
1081 { no warnings 'once'; no strict 'refs'; @{"RT::$name"} = (@_); }
1082 } elsif ( $type eq 'HASH' ) {
1083 $OPTIONS{$name} = {@_};
1084 { no warnings 'once'; no strict 'refs'; %{"RT::$name"} = (@_); }
1086 $OPTIONS{$name} = shift;
1087 {no warnings 'once'; no strict 'refs'; ${"RT::$name"} = $OPTIONS{$name}; }
1089 $META{$name}->{'Type'} = $type;
1090 return $self->_ReturnValue( $old, $type );
1094 my ( $self, $res, $type ) = @_;
1095 return $res unless wantarray;
1097 if ( $type eq 'ARRAY' ) {
1098 return @{ $res || [] };
1099 } elsif ( $type eq 'HASH' ) {
1100 return %{ $res || {} };
1118 unless ( $args{'File'} ) {
1119 ( $args{'Package'}, $args{'File'}, $args{'Line'} ) = caller(1);
1122 my $opt = $args{'Option'};
1125 my $name = $self->__GetNameByRef($opt);
1131 $type = $META{$name}->{'Type'} || 'SCALAR';
1134 # if option is already set we have to check where
1135 # it comes from and may be ignore it
1136 if ( exists $OPTIONS{$name} ) {
1137 if ( $type eq 'HASH' ) {
1139 @{ $args{'Value'} },
1140 @{ $args{'Value'} }%2? (undef) : (),
1141 $self->Get( $name ),
1143 } elsif ( $args{'SiteConfig'} && $args{'Extension'} ) {
1144 # if it's site config of an extension then it can only
1145 # override options that came from its main config
1146 if ( $args{'Extension'} ne $META{$name}->{'Source'}{'Extension'} ) {
1147 my %source = %{ $META{$name}->{'Source'} };
1149 "Change of config option '$name' at $args{'File'} line $args{'Line'} has been ignored."
1150 ." This option earlier has been set in $source{'File'} line $source{'Line'}."
1151 ." To overide this option use ". ($source{'Extension'}||'RT')
1156 } elsif ( !$args{'SiteConfig'} && $META{$name}->{'Source'}{'SiteConfig'} ) {
1157 # if it's core config then we can override any option that came from another
1158 # core config, but not site config
1160 my %source = %{ $META{$name}->{'Source'} };
1161 if ( $source{'Extension'} ne $args{'Extension'} ) {
1162 # as a site config is loaded earlier then its base config
1163 # then we warn only on different extensions, for example
1164 # RTIR's options is set in main site config
1166 "Change of config option '$name' at $args{'File'} line $args{'Line'} has been ignored."
1167 ." It may be ok, but we want you to be aware."
1168 ." This option has been set earlier in $source{'File'} line $source{'Line'}."
1176 $META{$name}->{'Type'} = $type;
1177 foreach (qw(Package File Line SiteConfig Extension)) {
1178 $META{$name}->{'Source'}->{$_} = $args{$_};
1180 $self->Set( $name, @{ $args{'Value'} } );
1185 our %REF_SYMBOLS = (
1195 sub __GetNameByRef {
1199 if ( !$pack && $last_pack ) {
1200 my $tmp = $self->__GetNameByRef( $ref, $last_pack );
1201 return $tmp if $tmp;
1204 $pack .= '::' unless substr( $pack, -2 ) eq '::';
1209 # scan $pack's nametable(hash)
1210 foreach my $k ( keys %{$pack} ) {
1212 # The hash for main:: has a reference to itself
1213 next if $k eq 'main::';
1215 # if the entry has a trailing '::' then
1216 # it is a link to another name space
1217 if ( substr( $k, -2 ) eq '::') {
1218 $name = $self->__GetNameByRef( $ref, $k );
1219 return $name if $name;
1222 # entry of the table with references to
1223 # SCALAR, ARRAY... and other types with
1225 my $entry = ${$pack}{$k};
1228 # get entry for type we are looking for
1229 # XXX skip references to scalars or other references.
1230 # Otherwie 5.10 goes boom. maybe we should skip any
1232 next if ref($entry) eq 'SCALAR' || ref($entry) eq 'REF';
1233 my $entry_ref = *{$entry}{ ref($ref) };
1234 next unless $entry_ref;
1236 # if references are equal then we've found
1237 if ( $entry_ref == $ref ) {
1239 return ( $REF_SYMBOLS{ ref($ref) } || '*' ) . $pack . $k;
1254 return $META{ $_[1] };
1262 map $_->{'Section'} || 'General',
1269 my %args = ( Section => undef, Overridable => 1, Sorted => 1, @_ );
1270 my @res = keys %META;
1272 @res = grep( ( $META{$_}->{'Section'} || 'General' ) eq $args{'Section'},
1274 ) if defined $args{'Section'};
1276 if ( defined $args{'Overridable'} ) {
1278 = grep( ( $META{$_}->{'Overridable'} || 0 ) == $args{'Overridable'},
1282 if ( $args{'Sorted'} ) {
1284 ($META{$a}->{SortOrder}||9999) <=> ($META{$b}->{SortOrder}||9999)
1288 @res = sort { $a cmp $b } @res;
1293 =head2 AddOption( Name => '', Section => '', ... )
1304 Widget => '/Widgets/Form/String',
1305 WidgetArguments => {},
1309 unless ( $args{Name} ) {
1310 $RT::Logger->error("Need Name to add a new config");
1314 unless ( $args{Section} ) {
1315 $RT::Logger->error("Need Section to add a new config option");
1319 $META{ delete $args{Name} } = \%args;
1322 =head2 DeleteOption( Name => '' )
1332 if ( $args{Name} ) {
1333 delete $META{$args{Name}};
1336 $RT::Logger->error("Need Name to remove a config option");
1341 =head2 UpdateOption( Name => '' ), Section => '', ... )
1350 Overridable => undef,
1353 WidgetArguments => undef,
1357 my $name = delete $args{Name};
1360 $RT::Logger->error("Need Name to update a new config");
1364 unless ( exists $META{$name} ) {
1365 $RT::Logger->error("Config $name doesn't exist");
1369 for my $type ( keys %args ) {
1370 next unless defined $args{$type};
1371 $META{$name}{$type} = $args{$type};
1376 RT::Base->_ImportOverlays();