diff options
author | Dylan William Hardison <dylan@hardison.net> | 2015-10-31 02:03:58 +0100 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2015-10-31 02:06:57 +0100 |
commit | 5852295860d51040f69bbaf957cc8ed6bfd7358b (patch) | |
tree | a0781afa608c45912a97c1b2ac3b75e0d8659f2b | |
parent | f03cb21e297f73fcfca9740ff8e2c525a745d7ad (diff) | |
download | bugzilla-5852295860d51040f69bbaf957cc8ed6bfd7358b.tar.gz bugzilla-5852295860d51040f69bbaf957cc8ed6bfd7358b.tar.xz |
Bug 1218457 - Allow localconfig to override (force) certain data/params values
-rw-r--r-- | Bugzilla.pm | 5 | ||||
-rw-r--r-- | Bugzilla/DB.pm | 16 | ||||
-rw-r--r-- | Bugzilla/Install/Localconfig.pm | 12 | ||||
-rw-r--r-- | Bugzilla/Memcached.pm | 9 | ||||
-rw-r--r-- | Bugzilla/Util.pm | 2 | ||||
-rwxr-xr-x | editparams.cgi | 2 | ||||
-rw-r--r-- | t/013remote_ip.t | 1 | ||||
-rw-r--r-- | template/en/default/admin/params/common.html.tmpl | 12 | ||||
-rw-r--r-- | template/en/default/setup/strings.txt.pl | 5 |
9 files changed, 49 insertions, 15 deletions
diff --git a/Bugzilla.pm b/Bugzilla.pm index b14b92e0d..96f7cd0d2 100644 --- a/Bugzilla.pm +++ b/Bugzilla.pm @@ -324,6 +324,11 @@ sub params { return $_[0]->request_cache->{params} ||= Bugzilla::Config::read_param_file(); } +sub get_param_with_override { + my ($class, $name) = @_; + return $class->localconfig->{param_override}{$name} // $class->params->{$name}; +} + sub user { return $_[0]->request_cache->{user} ||= new Bugzilla::User; } diff --git a/Bugzilla/DB.pm b/Bugzilla/DB.pm index f201124a8..cc2826f55 100644 --- a/Bugzilla/DB.pm +++ b/Bugzilla/DB.pm @@ -118,19 +118,19 @@ sub quote { sub connect_shadow { my $params = Bugzilla->params; - die "Tried to connect to non-existent shadowdb" - unless $params->{'shadowdb'}; + die "Tried to connect to non-existent shadowdb" + unless Bugzilla->get_param_with_override('shadowdb'); # Instead of just passing in a new hashref, we locally modify the # values of "localconfig", because some drivers access it while # connecting. - my %connect_params = %{ Bugzilla->localconfig }; - $connect_params{db_host} = $params->{'shadowdbhost'}; - $connect_params{db_name} = $params->{'shadowdb'}; - $connect_params{db_port} = $params->{'shadowdbport'}; - $connect_params{db_sock} = $params->{'shadowdbsock'}; + my $connect_params = dclone(Bugzilla->localconfig); + $connect_params->{db_host} = Bugzilla->get_param_with_override('shadowdbhost'); + $connect_params->{db_name} = Bugzilla->get_param_with_override('shadowdb'); + $connect_params->{db_port} = Bugzilla->get_param_with_override('shadowport'); + $connect_params->{db_sock} = Bugzilla->get_param_with_override('shadowsock'); - return _connect(\%connect_params); + return _connect($connect_params); } sub connect_main { diff --git a/Bugzilla/Install/Localconfig.pm b/Bugzilla/Install/Localconfig.pm index 1544e6fac..dbc0624d3 100644 --- a/Bugzilla/Install/Localconfig.pm +++ b/Bugzilla/Install/Localconfig.pm @@ -114,6 +114,18 @@ use constant LOCALCONFIG_VARS => ( # is larger than anybody would ever be able to brute-force. default => sub { generate_random_password(64) }, }, + { + name => 'param_override', + default => { + inbound_proxies => undef, + memcached_servers => undef, + memcached_namespace => undef, + shadowdb => undef, + shadowdbhost => undef, + shadowdbport => undef, + shadowdbsock => undef, + }, + }, ); sub read_localconfig { diff --git a/Bugzilla/Memcached.pm b/Bugzilla/Memcached.pm index fdafa0014..1339a119c 100644 --- a/Bugzilla/Memcached.pm +++ b/Bugzilla/Memcached.pm @@ -28,14 +28,13 @@ sub _new { # always return an object to simplify calling code when memcached is # disabled. - if (Bugzilla->feature('memcached') - && Bugzilla->params->{memcached_servers}) - { + my $servers = Bugzilla->get_param_with_override('memcached_servers'); + if (Bugzilla->feature('memcached') && $servers) { require Cache::Memcached; - $self->{namespace} = Bugzilla->params->{memcached_namespace} || ''; + $self->{namespace} = Bugzilla->get_param_with_override('memcached_namespace'); $self->{memcached} = Cache::Memcached->new({ - servers => [ split(/[, ]+/, Bugzilla->params->{memcached_servers}) ], + servers => [ split(/[, ]+/, $servers) ], namespace => $self->{namespace}, }); } diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm index f793ed727..19444082f 100644 --- a/Bugzilla/Util.pm +++ b/Bugzilla/Util.pm @@ -308,7 +308,7 @@ sub correct_urlbase { # Returns the real remote address of the client, sub remote_ip { my $remote_ip = $ENV{'REMOTE_ADDR'} || '127.0.0.1'; - my @proxies = split(/[\s,]+/, Bugzilla->params->{inbound_proxies}); + my @proxies = split(/[\s,]+/, Bugzilla->get_param_with_override('inbound_proxies')); my @x_forwarded_for = split(/[\s,]+/, $ENV{HTTP_X_FORWARDED_FOR} // ''); return $remote_ip unless @x_forwarded_for; diff --git a/editparams.cgi b/editparams.cgi index 8eb117a26..0731e5ee3 100755 --- a/editparams.cgi +++ b/editparams.cgi @@ -58,6 +58,7 @@ $current_panel = $1; my $current_module; my @panels = (); my $param_panels = Bugzilla::Config::param_panels(); +my $override = Bugzilla->localconfig->{param_override}; foreach my $panel (keys %$param_panels) { my $module = $param_panels->{$panel}; eval("require $module") || die $@; @@ -66,6 +67,7 @@ foreach my $panel (keys %$param_panels) { name => lc($panel), current => ($current_panel eq lc($panel)) ? 1 : 0, param_list => \@module_param_list, + param_override => { map { $_->{name} => $override->{$_->{name}} } @module_param_list }, sortkey => eval "\$${module}::sortkey;", module => $module, }; diff --git a/t/013remote_ip.t b/t/013remote_ip.t index 1cc832a9b..4bba7c95e 100644 --- a/t/013remote_ip.t +++ b/t/013remote_ip.t @@ -13,6 +13,7 @@ use Bugzilla; use Bugzilla::Util qw(remote_ip); my $params = Bugzilla->params; +local Bugzilla->localconfig->{param_override}{inbound_proxies} = undef; { local $params->{inbound_proxies} = '10.0.0.1,10.0.0.2'; diff --git a/template/en/default/admin/params/common.html.tmpl b/template/en/default/admin/params/common.html.tmpl index d86da0dcd..6458ba419 100644 --- a/template/en/default/admin/params/common.html.tmpl +++ b/template/en/default/admin/params/common.html.tmpl @@ -28,9 +28,19 @@ <dl> [% FOREACH param = panel.param_list %] - <dt id="[% param.name FILTER html %]_desc">[% param.name FILTER html %]</dt> + <dt id="[% param.name FILTER html %]_desc">[% param.name FILTER html %] + [% IF panel.param_override.${param.name}.defined %] + (localconfig override) + [% END %] + </dt> <dd>[% panel.param_descs.${param.name} FILTER none %] <p> + [% IF panel.param_override.${param.name}.defined %] + <input type="hidden" name="[% param.name FILTER html %] value="[% Param(param.name) FILTER html %]"> + <input type="text" size="80" readonly + id="[% param.name FILTER html %]" value="[% panel.param_override.${param.name} FILTER html %]"> + [% NEXT %] + [% END %] [% IF param.type == "t" %] <input type="text" size="80" name="[% param.name FILTER html %]" id="[% param.name FILTER html %]" value="[% Param(param.name) FILTER html %]"> diff --git a/template/en/default/setup/strings.txt.pl b/template/en/default/setup/strings.txt.pl index d73d29a26..72ffb4a4d 100644 --- a/template/en/default/setup/strings.txt.pl +++ b/template/en/default/setup/strings.txt.pl @@ -240,6 +240,11 @@ security features in Bugzilla, to protect against certain types of attacks. A random string is generated by default. It's very important that this key is kept secret. It also must be very long. END + localconfig_param_override => <<'END', +This hash is used by BMO to override select data/params values on a per-webhead +basis. Keys set to undef will default to the value in data/params. +Only the keys listed below can be overridden. +END localconfig_use_suexec => <<'END', Set this to 1 if Bugzilla runs in an Apache SuexecUserGroup environment. |