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 aileron."
215 $self->Set('WebDefaultStylesheet', 'aileron');
218 UseSideBySideLayout => {
219 Section => 'Ticket composition',
222 Widget => '/Widgets/Form/Boolean',
224 Description => 'Use a two column layout for create and update forms?' # loc
227 MessageBoxRichText => {
228 Section => 'Ticket composition',
231 Widget => '/Widgets/Form/Boolean',
233 Description => 'WYSIWYG message composer' # loc
236 MessageBoxRichTextHeight => {
237 Section => 'Ticket composition',
240 Widget => '/Widgets/Form/Integer',
242 Description => 'WYSIWYG composer height', # loc
246 Section => 'Ticket composition',
249 Widget => '/Widgets/Form/Integer',
251 Description => 'Message box width', #loc
254 MessageBoxHeight => {
255 Section => 'Ticket composition',
258 Widget => '/Widgets/Form/Integer',
260 Description => 'Message box height', #loc
264 Section => 'Ticket composition', #loc
267 Widget => '/Widgets/Form/Select',
269 Description => 'Message box wrapping', #loc
270 Values => [qw(SOFT HARD)],
271 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
274 DefaultTimeUnitsToHours => {
275 Section => 'Ticket composition', #loc
278 Widget => '/Widgets/Form/Boolean',
280 Description => 'Enter time in hours by default', #loc
281 Hints => 'Only for entry, not display', #loc
284 SearchResultsRefreshInterval => {
285 Section => 'General', #loc
288 Widget => '/Widgets/Form/Select',
290 Description => 'Search results refresh interval', #loc
291 Values => [qw(0 120 300 600 1200 3600 7200)],
293 0 => "Don't refresh search results.", #loc
294 120 => "Refresh search results every 2 minutes.", #loc
295 300 => "Refresh search results every 5 minutes.", #loc
296 600 => "Refresh search results every 10 minutes.", #loc
297 1200 => "Refresh search results every 20 minutes.", #loc
298 3600 => "Refresh search results every 60 minutes.", #loc
299 7200 => "Refresh search results every 120 minutes.", #loc
304 # User overridable options for RT at a glance
305 DefaultSummaryRows => {
306 Section => 'RT at a glance', #loc
309 Widget => '/Widgets/Form/Integer',
311 Description => 'Number of search results', #loc
314 HomePageRefreshInterval => {
315 Section => 'RT at a glance', #loc
318 Widget => '/Widgets/Form/Select',
320 Description => 'Home page refresh interval', #loc
321 Values => [qw(0 120 300 600 1200 3600 7200)],
323 0 => "Don't refresh home page.", #loc
324 120 => "Refresh home page every 2 minutes.", #loc
325 300 => "Refresh home page every 5 minutes.", #loc
326 600 => "Refresh home page every 10 minutes.", #loc
327 1200 => "Refresh home page every 20 minutes.", #loc
328 3600 => "Refresh home page every 60 minutes.", #loc
329 7200 => "Refresh home page every 120 minutes.", #loc
334 # User overridable options for Ticket displays
336 Section => 'Ticket display', #loc
339 Widget => '/Widgets/Form/Integer',
341 Description => 'Maximum inline message length', #loc
343 "Length in characters; Use '0' to show all messages inline, regardless of length" #loc
346 OldestTransactionsFirst => {
347 Section => 'Ticket display',
350 Widget => '/Widgets/Form/Boolean',
352 Description => 'Show oldest history first', #loc
355 DeferTransactionLoading => {
356 Section => 'Ticket display',
359 Widget => '/Widgets/Form/Boolean',
361 Description => 'Hide ticket history by default', #loc
364 ShowUnreadMessageNotifications => {
365 Section => 'Ticket display',
368 Widget => '/Widgets/Form/Boolean',
370 Description => 'Notify me of unread messages', #loc
375 Section => 'Ticket display',
378 Widget => '/Widgets/Form/Boolean',
380 Description => 'add <pre> tag around plain text attachments', #loc
381 Hints => "Use this to protect the format of plain text" #loc
385 Section => 'Ticket display',
388 Widget => '/Widgets/Form/Boolean',
390 Description => 'display wrapped and formatted plain text attachments', #loc
391 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
394 DisplayAfterQuickCreate => {
395 Section => 'Ticket display',
398 Widget => '/Widgets/Form/Boolean',
400 Description => 'On Quick Create, redirect to ticket display', #loc
404 MoreAboutRequestorTicketList => {
405 Section => 'Ticket display', #loc
408 Widget => '/Widgets/Form/Select',
410 Description => q|What tickets to display in the 'More about requestor' box|, #loc
411 Values => [qw(Active Inactive All None)],
413 Active => "Show the Requestor's 10 highest priority open tickets", #loc
414 Inactive => "Show the Requestor's 10 highest priority closed tickets", #loc
415 All => "Show the Requestor's 10 highest priority tickets", #loc
416 None => "Show no tickets for the Requestor", #loc
420 SimplifiedRecipients => {
421 Section => 'Ticket display', #loc
424 Widget => '/Widgets/Form/Boolean',
426 Description => q|Show simplified recipient list on ticket update|, #loc
429 DisplayTicketAfterQuickCreate => {
430 Section => 'Ticket display',
433 Widget => '/Widgets/Form/Boolean',
435 Description => q{Display ticket after "Quick Create"}, #loc
439 # User overridable locale options
441 Section => 'Locale', #loc
443 Widget => '/Widgets/Form/Select',
445 Description => 'Date format', #loc
446 Callback => sub { my $ret = { Values => [], ValuesLabel => {}};
447 my $date = RT::Date->new($HTML::Mason::Commands::session{'CurrentUser'});
449 foreach my $value ($date->Formatters) {
450 push @{$ret->{Values}}, $value;
451 $ret->{ValuesLabel}{$value} = $date->$value();
460 PostLoadCheck => sub {
462 my $value = $self->Get('RTAddressRegexp');
465 'The RTAddressRegexp option is not set in the config.'
466 .' Not setting this option results in additional SQL queries to'
467 .' check whether each address belongs to RT or not.'
468 .' It is especially important to set this option if RT recieves'
469 .' emails on addresses that are not in the database or config.'
471 } elsif (ref $value and ref $value eq "Regexp") {
472 # Ensure that the regex is case-insensitive; while the
473 # local part of email addresses is _technically_
474 # case-sensitive, most MTAs don't treat it as such.
475 $RT::Logger->warning(
476 'RTAddressRegexp is set to a case-sensitive regular expression.'
477 .' This may lead to mail loops with MTAs which treat the'
478 .' local part as case-insensitive -- which is most of them.'
479 ) if "$value" =~ /^\(\?[a-z]*-([a-z]*):/ and "$1" =~ /i/;
483 # User overridable mail options
485 Section => 'Mail', #loc
487 Default => 'Individual messages',
488 Widget => '/Widgets/Form/Select',
490 Description => 'Email delivery', #loc
492 'Individual messages', #loc
494 'Weekly digest', #loc
500 Section => 'Mail', #loc
503 Widget => '/Widgets/Form/Boolean',
505 Description => 'Outgoing mail', #loc
506 Hints => 'Should RT send you mail for ticket updates you make?', #loc
510 # this tends to break extensions that stash links in ticket update pages
513 PostLoadCheck => sub {
514 my ($self,$value) = @_;
515 $RT::Logger->error("your \$Organization setting ($value) appears to contain whitespace. Please fix this.")
520 # Internal config options
523 PostLoadCheck => sub {
525 my $v = $self->Get('FullTextSearch');
526 return unless $v->{Enable} and $v->{Indexed};
527 my $dbtype = $self->Get('DatabaseType');
528 if ($dbtype eq 'Oracle') {
529 if (not $v->{IndexName}) {
530 $RT::Logger->error("No IndexName set for full-text index; disabling");
531 $v->{Enable} = $v->{Indexed} = 0;
533 } elsif ($dbtype eq 'Pg') {
535 if (not $v->{'Column'}) {
536 $RT::Logger->error("No Column set for full-text index; disabling");
537 $v->{Enable} = $v->{Indexed} = 0;
538 } elsif ($v->{'Column'} eq "Content"
539 and (not $v->{'Table'} or $v->{'Table'} eq "Attachments")) {
540 $RT::Logger->error("Column for full-text index is set to Content, not tsvector column; disabling");
541 $v->{Enable} = $v->{Indexed} = 0;
543 } elsif ($dbtype eq 'mysql') {
544 if (not $v->{'Table'}) {
545 $RT::Logger->error("No Table set for full-text index; disabling");
546 $v->{Enable} = $v->{Indexed} = 0;
547 } elsif ($v->{'Table'} eq "Attachments") {
548 $RT::Logger->error("Table for full-text index is set to Attachments, not SphinxSE table; disabling");
549 $v->{Enable} = $v->{Indexed} = 0;
550 } elsif (not $v->{'MaxMatches'}) {
551 $RT::Logger->warn("No MaxMatches set for full-text index; defaulting to 10000");
552 $v->{MaxMatches} = 10_000;
555 $RT::Logger->error("Indexed full-text-search not supported for $dbtype");
562 PostLoadCheck => sub {
566 return if $INC{'GraphViz.pm'};
568 return if eval {require GraphViz; 1};
569 $RT::Logger->debug("You've enabled GraphViz, but we couldn't load the module: $@");
570 $self->Set( DisableGraphViz => 1 );
575 PostLoadCheck => sub {
579 return if $INC{'GD.pm'};
581 return if eval {require GD; 1};
582 $RT::Logger->debug("You've enabled GD, but we couldn't load the module: $@");
583 $self->Set( DisableGD => 1 );
586 MailPlugins => { Type => 'ARRAY' },
589 PostLoadCheck => sub {
591 my $value = $self->Get('Plugins');
592 # XXX Remove in RT 4.2
593 return unless $value and grep {$_ eq "RT::FM"} @{$value};
594 warn 'RTFM has been integrated into core RT, and must be removed from your @Plugins';
597 GnuPG => { Type => 'HASH' },
598 GnuPGOptions => { Type => 'HASH',
599 PostLoadCheck => sub {
601 my $gpg = $self->Get('GnuPG');
602 return unless $gpg->{'Enable'};
603 my $gpgopts = $self->Get('GnuPGOptions');
604 unless (-d $gpgopts->{homedir} && -r _ ) { # no homedir, no gpg
606 "RT's GnuPG libraries couldn't successfully read your".
607 " configured GnuPG home directory (".$gpgopts->{homedir}
608 ."). PGP support has been disabled");
609 $gpg->{'Enable'} = 0;
614 require RT::Crypt::GnuPG;
615 unless (RT::Crypt::GnuPG->Probe()) {
617 "RT's GnuPG libraries couldn't successfully execute gpg.".
618 " PGP support has been disabled");
619 $gpg->{'Enable'} = 0;
623 ReferrerWhitelist => { Type => 'ARRAY' },
624 ResolveDefaultUpdateType => {
625 PostLoadCheck => sub {
628 return unless $value;
629 $RT::Logger->info('The ResolveDefaultUpdateType config option has been deprecated. '.
630 'You can change the site default in your %Lifecycles config.');
634 PostLoadCheck => sub {
638 # "In most cases, you should leave $WebPath set to '' (an empty value)."
639 return unless $value;
641 # try to catch someone who assumes that you shouldn't leave this empty
643 $RT::Logger->error("For the WebPath config option, use the empty string instead of /");
647 # $WebPath requires a leading / but no trailing /, or it can be blank.
648 return if $value =~ m{^/.+[^/]$};
650 if ($value =~ m{/$}) {
651 $RT::Logger->error("The WebPath config option requires no trailing slash");
654 if ($value !~ m{^/}) {
655 $RT::Logger->error("The WebPath config option requires a leading slash");
660 PostLoadCheck => sub {
665 $RT::Logger->error("You must set the WebDomain config option");
669 if ($value =~ m{^(\w+://)}) {
670 $RT::Logger->error("The WebDomain config option must not contain a scheme ($1)");
674 if ($value =~ m{(/.*)}) {
675 $RT::Logger->error("The WebDomain config option must not contain a path ($1)");
679 if ($value =~ m{:(\d*)}) {
680 $RT::Logger->error("The WebDomain config option must not contain a port ($1)");
686 PostLoadCheck => sub {
691 $RT::Logger->error("You must set the WebPort config option");
695 if ($value !~ m{^\d+$}) {
696 $RT::Logger->error("The WebPort config option must be an integer");
701 PostLoadCheck => sub {
706 $RT::Logger->error("You must set the WebBaseURL config option");
710 if ($value !~ m{^https?://}i) {
711 $RT::Logger->error("The WebBaseURL config option must contain a scheme (http or https)");
714 if ($value =~ m{/$}) {
715 $RT::Logger->error("The WebBaseURL config option requires no trailing slash");
718 if ($value =~ m{^https?://.+?(/[^/].*)}i) {
719 $RT::Logger->error("The WebBaseURL config option must not contain a path ($1)");
724 PostLoadCheck => sub {
729 $RT::Logger->error("You must set the WebURL config option");
733 if ($value !~ m{^https?://}i) {
734 $RT::Logger->error("The WebURL config option must contain a scheme (http or https)");
737 if ($value !~ m{/$}) {
738 $RT::Logger->error("The WebURL config option requires a trailing slash");
742 EmailInputEncodings => {
744 PostLoadCheck => sub {
746 my $value = $self->Get('EmailInputEncodings');
747 return unless $value && @$value;
750 foreach my $encoding ( grep defined && length, splice @$value ) {
751 next if $seen{ $encoding }++;
752 if ( $encoding eq '*' ) {
753 unshift @$value, '*';
757 my $canonic = Encode::resolve_alias( $encoding );
758 unless ( $canonic ) {
759 warn "Unknown encoding '$encoding' in \@EmailInputEncodings option";
761 elsif ( $seen{ $canonic }++ ) {
765 push @$value, $canonic;
773 PostLoadCheck => sub {
776 # XXX Remove in RT 4.2
778 The ActiveStatus configuration has been replaced by the new Lifecycles
779 functionality. You should set the 'active' property of the 'default'
780 lifecycle and add transition rules; see RT_Config.pm for documentation.
786 PostLoadCheck => sub {
789 # XXX Remove in RT 4.2
791 The InactiveStatus configuration has been replaced by the new Lifecycles
792 functionality. You should set the 'inactive' property of the 'default'
793 lifecycle and add transition rules; see RT_Config.pm for documentation.
804 Object constructor returns new object. Takes no arguments.
810 my $class = ref($proto) ? ref($proto) : $proto;
811 my $self = bless {}, $class;
828 my %args = ( File => '', @_ );
829 $args{'File'} =~ s/(?<=Config)(?=\.pm$)/Meta/;
835 Load all configs. First of all load RT's config then load
836 extensions' config files in alphabetical order.
844 $self->InitConfig( File => 'RT_Config.pm' );
845 $self->LoadConfig( File => 'RT_Config.pm' );
847 my @configs = $self->Configs;
848 $self->InitConfig( File => $_ ) foreach @configs;
849 $self->LoadConfig( File => $_ ) foreach @configs;
855 Takes param hash with C<File> field.
856 First, the site configuration file is loaded, in order to establish
857 overall site settings like hostname and name of RT instance.
858 Then, the core configuration file is loaded to set fallback values
859 for all settings; it bases some values on settings from the site
862 B<Note> that core config file don't change options if site config
863 has set them so to add value to some option instead of
864 overriding you have to copy original value from core config file.
870 my %args = ( File => '', @_ );
871 $args{'File'} =~ s/(?<!Site)(?=Config\.pm$)/Site/;
872 if ( $args{'File'} eq 'RT_SiteConfig.pm'
873 and my $site_config = $ENV{RT_SITE_CONFIG} )
875 $self->_LoadConfig( %args, File => $site_config );
877 $self->_LoadConfig(%args);
879 $args{'File'} =~ s/Site(?=Config\.pm$)//;
880 $self->_LoadConfig(%args);
886 my %args = ( File => '', @_ );
888 my ($is_ext, $is_site);
889 if ( $args{'File'} eq ($ENV{RT_SITE_CONFIG}||'') ) {
890 ($is_ext, $is_site) = ('', 1);
892 $is_ext = $args{'File'} =~ /^(?!RT_)(?:(.*)_)(?:Site)?Config/ ? $1 : '';
893 $is_site = $args{'File'} =~ /SiteConfig/ ? 1 : 0;
898 local *Set = sub(\[$@%]@) {
899 my ( $opt_ref, @args ) = @_;
900 my ( $pack, $file, $line ) = caller;
901 return $self->SetFromConfig(
907 SiteConfig => $is_site,
908 Extension => $is_ext,
911 my @etc_dirs = ($RT::LocalEtcPath);
912 push @etc_dirs, RT->PluginDirs('etc') if $is_ext;
913 push @etc_dirs, $RT::EtcPath, @INC;
914 local @INC = @etc_dirs;
915 require $args{'File'};
918 return 1 if $is_site && $@ =~ /^Can't locate \Q$args{File}/;
919 if ( $is_site || $@ !~ /^Can't locate \Q$args{File}/ ) {
920 die qq{Couldn't load RT config file $args{'File'}:\n\n$@};
923 my $username = getpwuid($>);
924 my $group = getgrgid($();
926 my ( $file_path, $fileuid, $filegid );
927 foreach ( $RT::LocalEtcPath, $RT::EtcPath, @INC ) {
928 my $tmp = File::Spec->catfile( $_, $args{File} );
929 ( $fileuid, $filegid ) = ( stat($tmp) )[ 4, 5 ];
930 if ( defined $fileuid ) {
935 unless ($file_path) {
937 qq{Couldn't load RT config file $args{'File'} as user $username / group $group.\n}
938 . qq{The file couldn't be found in $RT::LocalEtcPath and $RT::EtcPath.\n$@};
943 RT couldn't load RT config file %s as:
947 The file is owned by user %s and group %s.
949 This usually means that the user/group your webserver is running
950 as cannot read the file. Be careful not to make the permissions
951 on this file too liberal, because it contains database passwords.
952 You may need to put the webserver user in the appropriate group
953 (%s) or change permissions be able to run succesfully.
956 my $fileusername = getpwuid($fileuid);
957 my $filegroup = getgrgid($filegid);
958 my $errormessage = sprintf( $message,
959 $file_path, $fileusername, $filegroup, $filegroup );
960 die "$errormessage\n$@";
967 foreach my $o ( grep $META{$_}{'PostLoadCheck'}, $self->Options( Overridable => undef ) ) {
968 $META{$o}->{'PostLoadCheck'}->( $self, $self->Get($o) );
974 Returns list of config files found in local etc, plugins' etc
975 and main etc directories.
983 foreach my $path ( $RT::LocalEtcPath, RT->PluginDirs('etc'), $RT::EtcPath ) {
984 my $mask = File::Spec->catfile( $path, "*_Config.pm" );
985 my @files = glob $mask;
986 @files = grep !/^RT_Config\.pm$/,
987 grep $_ && /^\w+_Config\.pm$/,
988 map { s/^.*[\\\/]//; $_ } @files;
989 push @configs, sort @files;
993 @configs = grep !$seen{$_}++, @configs;
999 Takes name of the option as argument and returns its current value.
1001 In the case of a user-overridable option, first checks the user's
1002 preferences before looking for site-wide configuration.
1004 Returns values from RT_SiteConfig, RT_Config and then the %META hash
1005 of configuration variables's "Default" for this config variable,
1008 Returns different things in scalar and array contexts. For scalar
1009 options it's not that important, however for arrays and hash it's.
1010 In scalar context returns references to arrays and hashes.
1012 Use C<scalar> perl's op to force context, especially when you use
1013 C<(..., Argument => RT->Config->Get('ArrayOpt'), ...)>
1014 as perl's '=>' op doesn't change context of the right hand argument to
1015 scalar. Instead use C<(..., Argument => scalar RT->Config->Get('ArrayOpt'), ...)>.
1017 It's also important for options that have no default value(no default
1018 in F<etc/RT_Config.pm>). If you don't force scalar context then you'll
1019 get empty list and all your named args will be messed up. For example
1020 C<(arg1 => 1, arg2 => RT->Config->Get('OptionDoesNotExist'), arg3 => 3)>
1021 will result in C<(arg1 => 1, arg2 => 'arg3', 3)> what is most probably
1022 unexpected, or C<(arg1 => 1, arg2 => RT->Config->Get('ArrayOption'), arg3 => 3)>
1023 will result in C<(arg1 => 1, arg2 => 'element of option', 'another_one' => ..., 'arg3', 3)>.
1028 my ( $self, $name, $user ) = @_;
1031 if ( $user && $user->id && $META{$name}->{'Overridable'} ) {
1032 $user = $user->UserObj if $user->isa('RT::CurrentUser');
1033 my $prefs = $user->Preferences($RT::System);
1034 $res = $prefs->{$name} if $prefs;
1036 $res = $OPTIONS{$name} unless defined $res;
1037 $res = $META{$name}->{'Default'} unless defined $res;
1038 return $self->_ReturnValue( $res, $META{$name}->{'Type'} || 'SCALAR' );
1041 =head2 GetObfuscated
1043 the same as Get, except it returns Obfuscated value via Obfuscate sub
1049 my ( $name, $user ) = @_;
1050 my $obfuscate = $META{$name}->{Obfuscate};
1052 # we use two Get here is to simplify the logic of the return value
1053 # configs need obfuscation are supposed to be less, so won't be too heavy
1055 return $self->Get(@_) unless $obfuscate;
1057 my $res = $self->Get(@_);
1058 $res = $obfuscate->( $self, $res, $user );
1059 return $self->_ReturnValue( $res, $META{$name}->{'Type'} || 'SCALAR' );
1064 Set option's value to new value. Takes name of the option and new value.
1067 The new value should be scalar, array or hash depending on type of the option.
1068 If the option is not defined in meta or the default RT config then it is of
1074 my ( $self, $name ) = ( shift, shift );
1076 my $old = $OPTIONS{$name};
1077 my $type = $META{$name}->{'Type'} || 'SCALAR';
1078 if ( $type eq 'ARRAY' ) {
1079 $OPTIONS{$name} = [@_];
1080 { no warnings 'once'; no strict 'refs'; @{"RT::$name"} = (@_); }
1081 } elsif ( $type eq 'HASH' ) {
1082 $OPTIONS{$name} = {@_};
1083 { no warnings 'once'; no strict 'refs'; %{"RT::$name"} = (@_); }
1085 $OPTIONS{$name} = shift;
1086 {no warnings 'once'; no strict 'refs'; ${"RT::$name"} = $OPTIONS{$name}; }
1088 $META{$name}->{'Type'} = $type;
1089 return $self->_ReturnValue( $old, $type );
1093 my ( $self, $res, $type ) = @_;
1094 return $res unless wantarray;
1096 if ( $type eq 'ARRAY' ) {
1097 return @{ $res || [] };
1098 } elsif ( $type eq 'HASH' ) {
1099 return %{ $res || {} };
1117 unless ( $args{'File'} ) {
1118 ( $args{'Package'}, $args{'File'}, $args{'Line'} ) = caller(1);
1121 my $opt = $args{'Option'};
1124 my $name = $self->__GetNameByRef($opt);
1130 $type = $META{$name}->{'Type'} || 'SCALAR';
1133 # if option is already set we have to check where
1134 # it comes from and may be ignore it
1135 if ( exists $OPTIONS{$name} ) {
1136 if ( $type eq 'HASH' ) {
1138 @{ $args{'Value'} },
1139 @{ $args{'Value'} }%2? (undef) : (),
1140 $self->Get( $name ),
1142 } elsif ( $args{'SiteConfig'} && $args{'Extension'} ) {
1143 # if it's site config of an extension then it can only
1144 # override options that came from its main config
1145 if ( $args{'Extension'} ne $META{$name}->{'Source'}{'Extension'} ) {
1146 my %source = %{ $META{$name}->{'Source'} };
1148 "Change of config option '$name' at $args{'File'} line $args{'Line'} has been ignored."
1149 ." This option earlier has been set in $source{'File'} line $source{'Line'}."
1150 ." To overide this option use ". ($source{'Extension'}||'RT')
1155 } elsif ( !$args{'SiteConfig'} && $META{$name}->{'Source'}{'SiteConfig'} ) {
1156 # if it's core config then we can override any option that came from another
1157 # core config, but not site config
1159 my %source = %{ $META{$name}->{'Source'} };
1160 if ( $source{'Extension'} ne $args{'Extension'} ) {
1161 # as a site config is loaded earlier then its base config
1162 # then we warn only on different extensions, for example
1163 # RTIR's options is set in main site config
1165 "Change of config option '$name' at $args{'File'} line $args{'Line'} has been ignored."
1166 ." It may be ok, but we want you to be aware."
1167 ." This option has been set earlier in $source{'File'} line $source{'Line'}."
1175 $META{$name}->{'Type'} = $type;
1176 foreach (qw(Package File Line SiteConfig Extension)) {
1177 $META{$name}->{'Source'}->{$_} = $args{$_};
1179 $self->Set( $name, @{ $args{'Value'} } );
1184 our %REF_SYMBOLS = (
1194 sub __GetNameByRef {
1198 if ( !$pack && $last_pack ) {
1199 my $tmp = $self->__GetNameByRef( $ref, $last_pack );
1200 return $tmp if $tmp;
1203 $pack .= '::' unless substr( $pack, -2 ) eq '::';
1208 # scan $pack's nametable(hash)
1209 foreach my $k ( keys %{$pack} ) {
1211 # The hash for main:: has a reference to itself
1212 next if $k eq 'main::';
1214 # if the entry has a trailing '::' then
1215 # it is a link to another name space
1216 if ( substr( $k, -2 ) eq '::') {
1217 $name = $self->__GetNameByRef( $ref, $k );
1218 return $name if $name;
1221 # entry of the table with references to
1222 # SCALAR, ARRAY... and other types with
1224 my $entry = ${$pack}{$k};
1227 # get entry for type we are looking for
1228 # XXX skip references to scalars or other references.
1229 # Otherwie 5.10 goes boom. maybe we should skip any
1231 next if ref($entry) eq 'SCALAR' || ref($entry) eq 'REF';
1232 my $entry_ref = *{$entry}{ ref($ref) };
1233 next unless $entry_ref;
1235 # if references are equal then we've found
1236 if ( $entry_ref == $ref ) {
1238 return ( $REF_SYMBOLS{ ref($ref) } || '*' ) . $pack . $k;
1253 return $META{ $_[1] };
1261 map $_->{'Section'} || 'General',
1268 my %args = ( Section => undef, Overridable => 1, Sorted => 1, @_ );
1269 my @res = keys %META;
1271 @res = grep( ( $META{$_}->{'Section'} || 'General' ) eq $args{'Section'},
1273 ) if defined $args{'Section'};
1275 if ( defined $args{'Overridable'} ) {
1277 = grep( ( $META{$_}->{'Overridable'} || 0 ) == $args{'Overridable'},
1281 if ( $args{'Sorted'} ) {
1283 ($META{$a}->{SortOrder}||9999) <=> ($META{$b}->{SortOrder}||9999)
1287 @res = sort { $a cmp $b } @res;
1292 =head2 AddOption( Name => '', Section => '', ... )
1303 Widget => '/Widgets/Form/String',
1304 WidgetArguments => {},
1308 unless ( $args{Name} ) {
1309 $RT::Logger->error("Need Name to add a new config");
1313 unless ( $args{Section} ) {
1314 $RT::Logger->error("Need Section to add a new config option");
1318 $META{ delete $args{Name} } = \%args;
1321 =head2 DeleteOption( Name => '' )
1331 if ( $args{Name} ) {
1332 delete $META{$args{Name}};
1335 $RT::Logger->error("Need Name to remove a config option");
1340 =head2 UpdateOption( Name => '' ), Section => '', ... )
1349 Overridable => undef,
1352 WidgetArguments => undef,
1356 my $name = delete $args{Name};
1359 $RT::Logger->error("Need Name to update a new config");
1363 unless ( exists $META{$name} ) {
1364 $RT::Logger->error("Config $name doesn't exist");
1368 for my $type ( keys %args ) {
1369 next unless defined $args{$type};
1370 $META{$name}{$type} = $args{$type};
1375 RT::Base->_ImportOverlays();