summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Install/Localconfig.pm
diff options
context:
space:
mode:
Diffstat (limited to 'Bugzilla/Install/Localconfig.pm')
-rw-r--r--Bugzilla/Install/Localconfig.pm577
1 files changed, 255 insertions, 322 deletions
diff --git a/Bugzilla/Install/Localconfig.pm b/Bugzilla/Install/Localconfig.pm
index 6650eca27..fad7404d8 100644
--- a/Bugzilla/Install/Localconfig.pm
+++ b/Bugzilla/Install/Localconfig.pm
@@ -36,276 +36,206 @@ use Sys::Hostname qw(hostname);
use parent qw(Exporter);
our @EXPORT_OK = qw(
- read_localconfig
- update_localconfig
- ENV_KEYS
+ read_localconfig
+ update_localconfig
+ ENV_KEYS
);
# might want to change this for upstream
-use constant ENV_PREFIX => 'BMO_';
-use constant PARAM_OVERRIDE => qw( use_mailer_queue mail_delivery_method shadowdb shadowdbhost shadowdbport shadowdbsock );
+use constant ENV_PREFIX => 'BMO_';
+use constant PARAM_OVERRIDE =>
+ qw( use_mailer_queue mail_delivery_method shadowdb shadowdbhost shadowdbport shadowdbsock );
sub _sensible_group {
- return '' if ON_WINDOWS;
- return scalar getgrgid($EGID);
+ return '' if ON_WINDOWS;
+ return scalar getgrgid($EGID);
}
sub _migrate_param {
- my ( $name, $fallback_value ) = @_;
-
- return sub {
- if ( Bugzilla->can('params') ) {
- return Bugzilla->params->{$name} // $fallback_value;
- }
- else {
- return $fallback_value;
- }
- };
+ my ($name, $fallback_value) = @_;
+
+ return sub {
+ if (Bugzilla->can('params')) {
+ return Bugzilla->params->{$name} // $fallback_value;
+ }
+ else {
+ return $fallback_value;
+ }
+ };
}
use constant LOCALCONFIG_VARS => (
- {
- name => 'create_htaccess',
- default => 1,
- },
- {
- name => 'webservergroup',
- default => \&_sensible_group,
- },
- {
- name => 'use_suexec',
- default => 0,
- },
- {
- name => 'db_driver',
- default => 'mysql',
- },
- {
- name => 'db_host',
- default => 'localhost',
- },
- {
- name => 'db_name',
- default => 'bugs',
- },
- {
-
- name => 'db_user',
- default => 'bugs',
- },
- {
- name => 'db_pass',
- default => '',
- },
- {
- name => 'db_port',
- default => 0,
- },
- {
- name => 'db_sock',
- default => '',
- },
- {
- name => 'db_check',
- default => 1,
- },
- {
- name => 'index_html',
- default => 0,
- },
- {
- name => 'cvsbin',
- default => sub { bin_loc('cvs') },
- },
- {
- name => 'interdiffbin',
- default => sub { bin_loc('interdiff') },
- },
- {
- name => 'diffpath',
- default => sub { dirname( bin_loc('diff') ) },
- },
- {
- name => 'tct_bin',
- default => sub { bin_loc('tct') },
- },
- {
- name => 'site_wide_secret',
-
- # 64 characters is roughly the equivalent of a 384-bit key, which
- # is larger than anybody would ever be able to brute-force.
- default => sub { generate_random_password(64) },
- },
- {
- name => 'param_override',
- default => {
- use_mailer_queue => undef,
- mail_delivery_method => undef,
- shadowdb => undef,
- shadowdbhost => undef,
- shadowdbport => undef,
- shadowdbsock => undef,
- },
- },
- {
- name => 'apache_size_limit',
- default => 600000,
- },
- {
- name => 'memcached_servers',
- default => _migrate_param( "memcached_servers", "" ),
- },
- {
- name => 'memcached_namespace',
- default => _migrate_param( "memcached_namespace", "bugzilla:" ),
- },
- {
- name => 'urlbase',
- default => _migrate_param( "urlbase", "" ),
- },
- {
- name => 'canonical_urlbase',
- default => '',
- },
- {
- name => 'attachment_base',
- default => _migrate_param( "attachment_base", '' ),
- },
- {
- name => 'ses_username',
- default => '',
- },
- {
- name => 'ses_password',
- default => '',
- },
- {
- name => 'inbound_proxies',
- default => _migrate_param( 'inbound_proxies', '' ),
- },
- {
- name => 'shadowdb_user',
- default => '',
- },
- {
- name => 'shadowdb_pass',
- default => '',
- },
- {
- name => 'datadog_host',
- default => '',
- },
- {
- name => 'datadog_port',
- default => 8125,
+ {name => 'create_htaccess', default => 1,},
+ {name => 'webservergroup', default => \&_sensible_group,},
+ {name => 'use_suexec', default => 0,},
+ {name => 'db_driver', default => 'mysql',},
+ {name => 'db_host', default => 'localhost',},
+ {name => 'db_name', default => 'bugs',},
+ {
+
+ name => 'db_user',
+ default => 'bugs',
+ },
+ {name => 'db_pass', default => '',},
+ {name => 'db_port', default => 0,},
+ {name => 'db_sock', default => '',},
+ {name => 'db_check', default => 1,},
+ {name => 'index_html', default => 0,},
+ {name => 'cvsbin', default => sub { bin_loc('cvs') },},
+ {name => 'interdiffbin', default => sub { bin_loc('interdiff') },},
+ {name => 'diffpath', default => sub { dirname(bin_loc('diff')) },},
+ {name => 'tct_bin', default => sub { bin_loc('tct') },},
+ {
+ name => 'site_wide_secret',
+
+ # 64 characters is roughly the equivalent of a 384-bit key, which
+ # is larger than anybody would ever be able to brute-force.
+ default => sub { generate_random_password(64) },
+ },
+ {
+ name => 'param_override',
+ default => {
+ use_mailer_queue => undef,
+ mail_delivery_method => undef,
+ shadowdb => undef,
+ shadowdbhost => undef,
+ shadowdbport => undef,
+ shadowdbsock => undef,
},
+ },
+ {name => 'apache_size_limit', default => 600000,},
+ {
+ name => 'memcached_servers',
+ default => _migrate_param("memcached_servers", ""),
+ },
+ {
+ name => 'memcached_namespace',
+ default => _migrate_param("memcached_namespace", "bugzilla:"),
+ },
+ {name => 'urlbase', default => _migrate_param("urlbase", ""),},
+ {name => 'canonical_urlbase', default => '',},
+ {name => 'attachment_base', default => _migrate_param("attachment_base", ''),},
+ {name => 'ses_username', default => '',},
+ {name => 'ses_password', default => '',},
+ {name => 'inbound_proxies', default => _migrate_param('inbound_proxies', ''),},
+ {name => 'shadowdb_user', default => '',},
+ {name => 'shadowdb_pass', default => '',},
+ {name => 'datadog_host', default => '',},
+ {name => 'datadog_port', default => 8125,},
);
use constant ENV_KEYS => (
- (map { ENV_PREFIX . $_->{name} } LOCALCONFIG_VARS),
- (map { ENV_PREFIX . $_ } PARAM_OVERRIDE),
+ (map { ENV_PREFIX . $_->{name} } LOCALCONFIG_VARS),
+ (map { ENV_PREFIX . $_ } PARAM_OVERRIDE),
);
sub _read_localconfig_from_env {
- my %localconfig;
-
- foreach my $var ( LOCALCONFIG_VARS ) {
- my $name = $var->{name};
- my $key = ENV_PREFIX . $name;
- if ($name eq 'param_override') {
- foreach my $override (PARAM_OVERRIDE) {
- my $o_key = ENV_PREFIX . $override;
- $localconfig{param_override}{$override} = $ENV{$o_key};
- untaint($localconfig{param_override}{$override});
- }
- }
- elsif (exists $ENV{$key}) {
- $localconfig{$name} = $ENV{$key};
- untaint($localconfig{$name});
- }
- else {
- my $default = $var->{default};
- $localconfig{$name} = ref($default) eq 'CODE' ? $default->() : $default;
- untaint($localconfig{$name});
- }
+ my %localconfig;
+
+ foreach my $var (LOCALCONFIG_VARS) {
+ my $name = $var->{name};
+ my $key = ENV_PREFIX . $name;
+ if ($name eq 'param_override') {
+ foreach my $override (PARAM_OVERRIDE) {
+ my $o_key = ENV_PREFIX . $override;
+ $localconfig{param_override}{$override} = $ENV{$o_key};
+ untaint($localconfig{param_override}{$override});
+ }
+ }
+ elsif (exists $ENV{$key}) {
+ $localconfig{$name} = $ENV{$key};
+ untaint($localconfig{$name});
}
+ else {
+ my $default = $var->{default};
+ $localconfig{$name} = ref($default) eq 'CODE' ? $default->() : $default;
+ untaint($localconfig{$name});
+ }
+ }
- return \%localconfig;
+ return \%localconfig;
}
sub _read_localconfig_from_file {
- my ($include_deprecated) = @_;
- my $filename = bz_locations()->{'localconfig'};
-
- my %localconfig;
- if (-e $filename) {
- my $s = new Safe;
- # Some people like to store their database password in another file.
- $s->permit('dofile');
-
- $s->rdo($filename);
- if ($@ || $!) {
- my $err_msg = $@ ? $@ : $!;
- die install_string('error_localconfig_read',
- { error => $err_msg, localconfig => $filename }), "\n";
- }
-
- my @read_symbols;
- if ($include_deprecated) {
- # First we have to get the whole symbol table
- my $safe_root = $s->root;
- my %safe_package;
- { no strict 'refs'; %safe_package = %{$safe_root . "::"}; }
- # And now we read the contents of every var in the symbol table.
- # However:
- # * We only include symbols that start with an alphanumeric
- # character. This excludes symbols like "_<./localconfig"
- # that show up in some perls.
- # * We ignore the INC symbol, which exists in every package.
- # * Perl 5.10 imports a lot of random symbols that all
- # contain "::", and we want to ignore those.
- @read_symbols = grep { /^[A-Za-z0-1]/ and !/^INC$/ and !/::/ }
- (keys %safe_package);
- }
- else {
- @read_symbols = map($_->{name}, LOCALCONFIG_VARS);
- }
- foreach my $var (@read_symbols) {
- my $glob = $s->varglob($var);
- # We can't get the type of a variable out of a Safe automatically.
- # We can only get the glob itself. So we figure out its type this
- # way, by trying first a scalar, then an array, then a hash.
- #
- # The interesting thing is that this converts all deprecated
- # array or hash vars into hashrefs or arrayrefs, but that's
- # fine since as I write this all modern localconfig vars are
- # actually scalars.
- if (defined $$glob) {
- $localconfig{$var} = $$glob;
- }
- elsif (@$glob) {
- $localconfig{$var} = \@$glob;
- }
- elsif (%$glob) {
- $localconfig{$var} = \%$glob;
- }
- }
+ my ($include_deprecated) = @_;
+ my $filename = bz_locations()->{'localconfig'};
+
+ my %localconfig;
+ if (-e $filename) {
+ my $s = new Safe;
+
+ # Some people like to store their database password in another file.
+ $s->permit('dofile');
+
+ $s->rdo($filename);
+ if ($@ || $!) {
+ my $err_msg = $@ ? $@ : $!;
+ die install_string(
+ 'error_localconfig_read', {error => $err_msg, localconfig => $filename}
+ ),
+ "\n";
+ }
+
+ my @read_symbols;
+ if ($include_deprecated) {
+
+ # First we have to get the whole symbol table
+ my $safe_root = $s->root;
+ my %safe_package;
+ { no strict 'refs'; %safe_package = %{$safe_root . "::"}; }
+
+ # And now we read the contents of every var in the symbol table.
+ # However:
+ # * We only include symbols that start with an alphanumeric
+ # character. This excludes symbols like "_<./localconfig"
+ # that show up in some perls.
+ # * We ignore the INC symbol, which exists in every package.
+ # * Perl 5.10 imports a lot of random symbols that all
+ # contain "::", and we want to ignore those.
+ @read_symbols
+ = grep { /^[A-Za-z0-1]/ and !/^INC$/ and !/::/ } (keys %safe_package);
}
+ else {
+ @read_symbols = map($_->{name}, LOCALCONFIG_VARS);
+ }
+ foreach my $var (@read_symbols) {
+ my $glob = $s->varglob($var);
+
+ # We can't get the type of a variable out of a Safe automatically.
+ # We can only get the glob itself. So we figure out its type this
+ # way, by trying first a scalar, then an array, then a hash.
+ #
+ # The interesting thing is that this converts all deprecated
+ # array or hash vars into hashrefs or arrayrefs, but that's
+ # fine since as I write this all modern localconfig vars are
+ # actually scalars.
+ if (defined $$glob) {
+ $localconfig{$var} = $$glob;
+ }
+ elsif (@$glob) {
+ $localconfig{$var} = \@$glob;
+ }
+ elsif (%$glob) {
+ $localconfig{$var} = \%$glob;
+ }
+ }
+ }
- return \%localconfig;
+ return \%localconfig;
}
sub read_localconfig {
- my ($include_deprecated) = @_;
- my $config = $ENV{LOCALCONFIG_ENV}
- ? _read_localconfig_from_env()
- : _read_localconfig_from_file($include_deprecated);
+ my ($include_deprecated) = @_;
+ my $config
+ = $ENV{LOCALCONFIG_ENV}
+ ? _read_localconfig_from_env()
+ : _read_localconfig_from_file($include_deprecated);
- # Use the site's URL as the default Canonical URL
- $config->{canonical_urlbase} //= $config->{urlbase};
+ # Use the site's URL as the default Canonical URL
+ $config->{canonical_urlbase} //= $config->{urlbase};
- return $config;
+ return $config;
}
#
@@ -333,96 +263,99 @@ sub read_localconfig {
# Cute, ey?
#
sub update_localconfig {
- my ($params) = @_;
-
- if ($ENV{LOCALCONFIG_ENV}) {
- require Carp;
- Carp::croak("update_localconfig() called with LOCALCONFIG_ENV enabled");
+ my ($params) = @_;
+
+ if ($ENV{LOCALCONFIG_ENV}) {
+ require Carp;
+ Carp::croak("update_localconfig() called with LOCALCONFIG_ENV enabled");
+ }
+
+ my $output = $params->{output} || 0;
+ my $answer = Bugzilla->installation_answers;
+ my $localconfig = read_localconfig('include deprecated');
+
+ my @new_vars;
+ foreach my $var (LOCALCONFIG_VARS) {
+ my $name = $var->{name};
+ my $value = $localconfig->{$name};
+
+ # Regenerate site_wide_secret if it was made by our old, weak
+ # generate_random_password. Previously we used to generate
+ # a 256-character string for site_wide_secret.
+ $value = undef
+ if ($name eq 'site_wide_secret' and defined $value and length($value) == 256);
+
+ if (!defined $value) {
+ push(@new_vars, $name);
+ $var->{default} = &{$var->{default}} if ref($var->{default}) eq 'CODE';
+ if (exists $answer->{$name}) {
+ $localconfig->{$name} = $answer->{$name};
+ }
+ else {
+ $localconfig->{$name} = $var->{default};
+ }
}
+ }
- my $output = $params->{output} || 0;
- my $answer = Bugzilla->installation_answers;
- my $localconfig = read_localconfig('include deprecated');
-
- my @new_vars;
- foreach my $var (LOCALCONFIG_VARS) {
- my $name = $var->{name};
- my $value = $localconfig->{$name};
- # Regenerate site_wide_secret if it was made by our old, weak
- # generate_random_password. Previously we used to generate
- # a 256-character string for site_wide_secret.
- $value = undef if ($name eq 'site_wide_secret' and defined $value
- and length($value) == 256);
-
- if (!defined $value) {
- push(@new_vars, $name);
- $var->{default} = &{$var->{default}} if ref($var->{default}) eq 'CODE';
- if (exists $answer->{$name}) {
- $localconfig->{$name} = $answer->{$name};
- }
- else {
- $localconfig->{$name} = $var->{default};
- }
- }
- }
+ if (!$localconfig->{'interdiffbin'} && $output) {
+ print "\n", install_string('patchutils_missing'), "\n";
+ }
- if (!$localconfig->{'interdiffbin'} && $output) {
- print "\n", install_string('patchutils_missing'), "\n";
- }
+ my @old_vars;
+ foreach my $var (keys %$localconfig) {
+ push(@old_vars, $var) if !grep($_->{name} eq $var, LOCALCONFIG_VARS);
+ }
- my @old_vars;
- foreach my $var (keys %$localconfig) {
- push(@old_vars, $var) if !grep($_->{name} eq $var, LOCALCONFIG_VARS);
- }
+ my $filename = bz_locations->{'localconfig'};
- my $filename = bz_locations->{'localconfig'};
-
- # Ensure output is sorted and deterministic
- local $Data::Dumper::Sortkeys = 1;
-
- # Move any custom or old variables into a separate file.
- if (scalar @old_vars) {
- my $filename_old = "$filename.old";
- open(my $old_file, ">>:utf8", $filename_old)
- or die "$filename_old: $!";
- local $Data::Dumper::Purity = 1;
- foreach my $var (@old_vars) {
- print $old_file Data::Dumper->Dump([$localconfig->{$var}],
- ["*$var"]) . "\n\n";
- }
- close $old_file;
- my $oldstuff = join(', ', @old_vars);
- print install_string('lc_old_vars',
- { localconfig => $filename, old_file => $filename_old,
- vars => $oldstuff }), "\n";
- }
+ # Ensure output is sorted and deterministic
+ local $Data::Dumper::Sortkeys = 1;
- # Re-write localconfig
- open(my $fh, ">:utf8", $filename) or die "$filename: $!";
- foreach my $var (LOCALCONFIG_VARS) {
- my $name = $var->{name};
- my $desc = install_string("localconfig_$name", { root => ROOT_USER });
- chomp($desc);
- # Make the description into a comment.
- $desc =~ s/^/# /mg;
- print $fh $desc, "\n",
- Data::Dumper->Dump([$localconfig->{$name}],
- ["*$name"]), "\n";
- }
-
- if (@new_vars) {
- my $newstuff = join(', ', @new_vars);
- print "\n";
- print colored(install_string('lc_new_vars', { localconfig => $filename,
- new_vars => wrap_hard($newstuff, 70) }),
- COLOR_ERROR), "\n";
- exit unless $params->{use_defaults};
+ # Move any custom or old variables into a separate file.
+ if (scalar @old_vars) {
+ my $filename_old = "$filename.old";
+ open(my $old_file, ">>:utf8", $filename_old) or die "$filename_old: $!";
+ local $Data::Dumper::Purity = 1;
+ foreach my $var (@old_vars) {
+ print $old_file Data::Dumper->Dump([$localconfig->{$var}], ["*$var"]) . "\n\n";
}
-
- # Reset the cache for Bugzilla->localconfig so that it will be re-read
- delete Bugzilla->process_cache->{localconfig};
-
- return { old_vars => \@old_vars, new_vars => \@new_vars };
+ close $old_file;
+ my $oldstuff = join(', ', @old_vars);
+ print install_string('lc_old_vars',
+ {localconfig => $filename, old_file => $filename_old, vars => $oldstuff}),
+ "\n";
+ }
+
+ # Re-write localconfig
+ open(my $fh, ">:utf8", $filename) or die "$filename: $!";
+ foreach my $var (LOCALCONFIG_VARS) {
+ my $name = $var->{name};
+ my $desc = install_string("localconfig_$name", {root => ROOT_USER});
+ chomp($desc);
+
+ # Make the description into a comment.
+ $desc =~ s/^/# /mg;
+ print $fh $desc, "\n", Data::Dumper->Dump([$localconfig->{$name}], ["*$name"]),
+ "\n";
+ }
+
+ if (@new_vars) {
+ my $newstuff = join(', ', @new_vars);
+ print "\n";
+ print colored(
+ install_string(
+ 'lc_new_vars', {localconfig => $filename, new_vars => wrap_hard($newstuff, 70)}
+ ),
+ COLOR_ERROR
+ ),
+ "\n";
+ exit unless $params->{use_defaults};
+ }
+
+ # Reset the cache for Bugzilla->localconfig so that it will be re-read
+ delete Bugzilla->process_cache->{localconfig};
+
+ return {old_vars => \@old_vars, new_vars => \@new_vars};
}
1;