]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1218457 - Allow localconfig to override (force) certain data/params values
authorDylan William Hardison <dylan@hardison.net>
Sat, 31 Oct 2015 01:03:58 +0000 (21:03 -0400)
committerDylan William Hardison <dylan@hardison.net>
Sat, 31 Oct 2015 01:06:57 +0000 (21:06 -0400)
Bugzilla.pm
Bugzilla/DB.pm
Bugzilla/Install/Localconfig.pm
Bugzilla/Memcached.pm
Bugzilla/Util.pm
editparams.cgi
t/013remote_ip.t
template/en/default/admin/params/common.html.tmpl
template/en/default/setup/strings.txt.pl

index b14b92e0d5c58cd2946482a682264c55718da5b0..96f7cd0d22803f38ec745ba064ad4309e4f2582c 100644 (file)
@@ -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;
 }
index f201124a874736add9aada4f679febd37d7be30b..cc2826f5562935b04a9bdf5339f28521b8d75f03 100644 (file)
@@ -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 {
index 1544e6fac6cbb4c33661f347af54a9ec98f6c669..dbc0624d355d900a0706da5d0ef0221852a9b3f5 100644 (file)
@@ -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 {
index fdafa0014d5a6f4af30c935eac24f81531276e53..1339a119ce06a0ee6674e8d9a198f7607f04f801 100644 (file)
@@ -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},
             });
     }
index f793ed727116ae9a1af5947895168b0fe7ba8a4f..19444082fb69c4c7e450dbc2dd244f5743719ef4 100644 (file)
@@ -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;
index 8eb117a26710bea640d61fd30cd224d668486d07..0731e5ee3d4958cb76219e11da14829a072606a3 100755 (executable)
@@ -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,
     };
index 1cc832a9b1c99c7b16bbc4071d3af751274ba6a4..4bba7c95e2ceea9e746ae76c87cfc4745717ca49 100644 (file)
@@ -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';
index d86da0dcdcb6cf9fc1adb73231aae793ee693dfd..6458ba419383197dac557e06c3a22b095d8e173b 100644 (file)
 
 <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 %]">
index d73d29a26c36050f4684ff08e17435549f178631..72ffb4a4d27317c77e3a021013af7ac500607fa8 100644 (file)
@@ -239,6 +239,11 @@ validation of encrypted tokens. These tokens are used to implement
 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.