From cc0c6be1aa795f85d05f15a3e8568fcef2bbd380 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 18 Jul 2007 18:07:38 +0000 Subject: [PATCH] config in database cleanup, editing, and agent-specific config (452, 1419) --- FS/FS/Conf.pm | 77 ++++--- httemplate/browse/agent.cgi | 22 ++ httemplate/config/config-delete.cgi | 15 ++ httemplate/config/config-download.cgi | 18 +- httemplate/config/config-process.cgi | 109 +++++---- httemplate/config/config-view.cgi | 57 ++++- httemplate/config/config.cgi | 423 ++++++++++++++++++---------------- 7 files changed, 421 insertions(+), 300 deletions(-) create mode 100644 httemplate/config/config-delete.cgi diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 1851c4d08..b8fd27eb2 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -74,9 +74,11 @@ sub base_dir { $1; } -=item config KEY +=item config KEY [ AGENTNUM ] Returns the configuration value or values (depending on context) for key. +The optional agent number selects an agent specific value instead of the +global default if one is present. =cut @@ -89,15 +91,13 @@ sub _usecompat { } sub _config { - my($self,$name,$agent)=@_; + my($self,$name,$agentnum)=@_; my $hashref = { 'name' => $name }; - if (defined($agent) && $agent) { - $hashref->{agent} = $agent; - } + $hashref->{agentnum} = $agentnum; local $FS::Record::conf = undef; # XXX evil hack prevents recursion my $cv = FS::Record::qsearchs('conf', $hashref); - if (!$cv && exists($hashref->{agent})) { - delete($hashref->{agent}); + if (!$cv && defined($agentnum)) { + $hashref->{agentnum} = ''; $cv = FS::Record::qsearchs('conf', $hashref); } return $cv; @@ -107,8 +107,8 @@ sub config { my $self = shift; return $self->_usecompat('config', @_) if use_confcompat; - my($name,$agent)=@_; - my $cv = $self->_config($name, $agent) or return; + my($name,$agentnum)=@_; + my $cv = $self->_config($name, $agentnum) or return; if ( wantarray ) { my $v = $cv->value; @@ -119,7 +119,7 @@ sub config { } } -=item config_binary KEY +=item config_binary KEY [ AGENTNUM ] Returns the exact scalar value for key. @@ -129,12 +129,12 @@ sub config_binary { my $self = shift; return $self->_usecompat('config_binary', @_) if use_confcompat; - my($name,$agent)=@_; - my $cv = $self->_config($name, $agent) or return; + my($name,$agentnum)=@_; + my $cv = $self->_config($name, $agentnum) or return; decode_base64($cv->value); } -=item exists KEY +=item exists KEY [ AGENTNUM ] Returns true if the specified key exists, even if the corresponding value is undefined. @@ -145,17 +145,18 @@ sub exists { my $self = shift; return $self->_usecompat('exists', @_) if use_confcompat; - my($name,$agent)=@_; - defined($self->_config($name, $agent)); + my($name,$agentnum)=@_; + defined($self->_config($name, $agentnum)); } -=item config_orbase KEY SUFFIX - -Returns the configuration value or values (depending on context) for -KEY_SUFFIX, if it exists, otherwise for KEY - -=cut +#=item config_orbase KEY SUFFIX +# +#Returns the configuration value or values (depending on context) for +#KEY_SUFFIX, if it exists, otherwise for KEY +# +#=cut +# outmoded as soon as we shift to agentnum based config values sub config_orbase { my $self = shift; return $self->_usecompat('config_orbase', @_) if use_confcompat; @@ -168,7 +169,7 @@ sub config_orbase { } } -=item touch KEY +=item touch KEY [ AGENT ]; Creates the specified configuration key if it does not exist. @@ -178,13 +179,13 @@ sub touch { my $self = shift; return $self->_usecompat('touch', @_) if use_confcompat; - my($name, $agent) = @_; - unless ( $self->exists($name, $agent) ) { - $self->set($name, '', $agent); + my($name, $agentnum) = @_; + unless ( $self->exists($name, $agentnum) ) { + $self->set($name, '', $agentnum); } } -=item set KEY VALUE +=item set KEY VALUE [ AGENTNUM ]; Sets the specified configuration key to the given value. @@ -194,15 +195,15 @@ sub set { my $self = shift; return $self->_usecompat('set', @_) if use_confcompat; - my($name, $value, $agent) = @_; + my($name, $value, $agentnum) = @_; $value =~ /^(.*)$/s; $value = $1; warn "[FS::Conf] SET $name\n" if $DEBUG; - my $old = FS::Record::qsearchs('conf', {name => $name, agent => $agent}); + my $old = FS::Record::qsearchs('conf', {name => $name, agentnum => $agentnum}); my $new = new FS::conf { $old ? $old->hash - : ('name' => $name, 'agent' => $agent) + : ('name' => $name, 'agentnum' => $agentnum) }; $new->value($value); @@ -218,7 +219,7 @@ sub set { } -=item set_binary KEY VALUE +=item set_binary KEY VALUE [ AGENTNUM ] Sets the specified configuration key to an exact scalar value which can be retrieved with config_binary. @@ -229,11 +230,11 @@ sub set_binary { my $self = shift; return if use_confcompat; - my($name, $value, $agent)=@_; - $self->set($name, encode_base64($value), $agent); + my($name, $value, $agentnum)=@_; + $self->set($name, encode_base64($value), $agentnum); } -=item delete KEY +=item delete KEY [ AGENTNUM ]; Deletes the specified configuration key. @@ -243,9 +244,9 @@ sub delete { my $self = shift; return $self->_usecompat('delete', @_) if use_confcompat; - my($name, $agent) = @_; - if ( my $cv = FS::Record::qsearchs('conf', {name => $name, agent => $agent}) ) { - warn "[FS::Conf] DELETE $file\n"; + my($name, $agentnum) = @_; + if ( my $cv = FS::Record::qsearchs('conf', {name => $name, agentnum => $agentnum}) ) { + warn "[FS::Conf] DELETE $name\n"; my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; @@ -1335,6 +1336,7 @@ httemplate/docs/config.html 'section' => '', 'description' => 'Template file for welcome email. Welcome emails are sent to the customer email invoice destination(s) each time a svc_acct record is created. See the Text::Template documentation for details on the template substitution language. The following variables are available', 'type' => 'textarea', + 'per_agent' => 1, }, { @@ -1342,6 +1344,7 @@ httemplate/docs/config.html 'section' => '', 'description' => 'From: address header for welcome email', 'type' => 'text', + 'per_agent' => 1, }, { @@ -1349,6 +1352,7 @@ httemplate/docs/config.html 'section' => '', 'description' => 'Subject: header for welcome email', 'type' => 'text', + 'per_agent' => 1, }, { @@ -1357,6 +1361,7 @@ httemplate/docs/config.html 'description' => 'MIME type for welcome email', 'type' => 'select', 'select_enum' => [ 'text/plain', 'text/html' ], + 'per_agent' => 1, }, { diff --git a/httemplate/browse/agent.cgi b/httemplate/browse/agent.cgi index 063f259de..83e79a2f3 100755 --- a/httemplate/browse/agent.cgi +++ b/httemplate/browse/agent.cgi @@ -38,6 +38,7 @@ full offerings (via their type).

% } Payment Gateway Overrides + Configuration Overrides Freq. Prog. @@ -344,6 +345,27 @@ Unused + + +% foreach my $override ( +% qsearch('conf', { 'agentnum' => $agent->agentnum } ) +% ) { +% + + + + +% } + + + + +
+ <% $override->name %> + (delete) +
(add override)
+ + +% } elsif ( $config_item->editlist_parts->[$pnum]{type} eq 'immutable' ) { - -% } elsif ( $type eq 'editlist' ) { - - - - "> + -
- - -
- <% itable() %> -% if ( defined $i->editlist_parts ) { -% my $pnum=0; foreach my $part ( @{$i->editlist_parts} ) { +% foreach my $line ( $conf->config($key, $agentnum) ) { - -% if ( $part->{type} eq 'text' ) { + - "> -% } elsif ( $part->{type} eq 'immutable' ) { +% } - <% $part->{value} %>" value="<% $part->{value} %>"> -% } elsif ( $part->{type} eq 'select' ) { +
+ ()"> + +
<% itable() %> - -% } else { +% if ( $part->{type} eq 'text' ) { - unknown type <% $part->type %> -% } + "> - -% $pnum++; } -% } else { +% } elsif ( $part->{type} eq 'immutable' ) { - -% } + <% $part->{value} %> + " value="<% $part->{value} %>"> - - -% } else { +% } elsif ( $part->{type} eq 'select' ) { + -

-% } +% } else { + + unknown type <% $part->type %> + +% } + + + +% $pnum++; +% } +% } else { + > - +% } + + (this.form)"> + + +% } else { + + unknown type $type + +% } +% $n++; +% } + + <% $description %> + + + + + +<%once> +my $conf = new FS::Conf; +my %confitems = map { $_->key => $_ } $conf->config_items; + - <%init> die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my($agentnum, $agent, $title, $action, $key, $value, $config_item, + $description, $type); + +$action = 'Set'; + +if ($cgi->param('agentnum') =~ /(\d+)$/) { + $agentnum=$1; +} + +if ($agentnum) { + $agent = qsearchs('agent', { 'agentnum' => $1 } ); + die "Agent $agentnum not found!" unless $agent; + + $title = "$action configuration override for ". $agent->agent; +} else { + $title = "$action global configuration"; +} + +$cgi->param('key') =~ /^([-.\w]+)$/ or die "illegal configuration item"; +$key=$1; +$value = $conf->config($key); +$config_item = $confitems{$key}; + +$description = $config_item->description; +$type = $config_item->type; + -- 2.11.0