From cc0c6be1aa795f85d05f15a3e8568fcef2bbd380 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 18 Jul 2007 18:07:38 +0000 Subject: config in database cleanup, editing, and agent-specific config (452, 1419) --- 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 ++++++++++++++++++---------------- 5 files changed, 358 insertions(+), 264 deletions(-) create mode 100644 httemplate/config/config-delete.cgi (limited to 'httemplate/config') diff --git a/httemplate/config/config-delete.cgi b/httemplate/config/config-delete.cgi new file mode 100644 index 000000000..cdac434fa --- /dev/null +++ b/httemplate/config/config-delete.cgi @@ -0,0 +1,15 @@ +<%init> +die "access denied\n" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +die "No configuration item specified (bad URL)!" unless $cgi->keywords; +my ($query) = $cgi->keywords; +$query =~ /^(\d+)$/; +my $confnum = $1; + +my $conf = qsearchs('conf', {'confnum' => $confnum}); +die "Configuration not found!" unless $conf; +$conf->delete; + + +<% $cgi->redirect(popurl(2) . "browse/agent.cgi") %> diff --git a/httemplate/config/config-download.cgi b/httemplate/config/config-download.cgi index 95a172a51..6979246db 100644 --- a/httemplate/config/config-download.cgi +++ b/httemplate/config/config-download.cgi @@ -5,14 +5,24 @@ %http_header('Content-Type' => 'application/x-unknown' ); % %die "No configuration variable specified (bad URL)!" # umm -% unless $cgi->keywords; -%my($query) = $cgi->keywords; -%$query =~ /^([\w -\)+-\/@;:?=[\]]+)$/; +% unless $cgi->param('key'); +%$cgi->param('key') =~ /^([-\w.]+)$/; %my $name = $1; % +%my $agentnum; +%if ($cgi->param('agentnum') =~ /^(\d+)$/) { +% $agentnum = $1; +%} +% %http_header('Content-Disposition' => "attachment; filename=$name" ); -% print $conf->config_binary($name); +% print $conf->config_binary($name, $agentnum); <%init> die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $agentnum; +if ($cgi->param('agentnum') =~ /^(\d+)$/) { + $agentnum = $1; +} + diff --git a/httemplate/config/config-process.cgi b/httemplate/config/config-process.cgi index 3e49b4f99..0210d85a7 100644 --- a/httemplate/config/config-process.cgi +++ b/httemplate/config/config-process.cgi @@ -2,69 +2,66 @@ die "access denied\n" unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); -# errant GET/POST protection -my $Vars = scalar($cgi->Vars); -my $num_Vars = scalar(keys %$Vars); -die "only received $num_Vars params; errant or truncated GET/POST?". - " aborting - not updating config\n" - unless $num_Vars > 100; - my $conf = new FS::Conf; $FS::Conf::DEBUG = 1; my @config_items = $conf->config_items; +my %confitems = map { $_->key => $_ } $conf->config_items; -foreach my $i ( @config_items ) { - my @touch = (); - my @delete = (); - my $n = 0; - foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) { - if ( $type eq '' ) { - } elsif ( $type eq 'textarea' ) { - if ( $cgi->param($i->key. $n) ne '' ) { - my $value = $cgi->param($i->key. $n); - $value =~ s/\r\n/\n/g; #browsers? - $conf->set($i->key, $value); - } else { - $conf->delete($i->key); - } - } elsif ( $type eq 'binary' ) { - if ( defined($cgi->param($i->key. $n)) && $cgi->param($i->key. $n) ) { - my $fh = $cgi->upload($i->key. $n); - if (defined($fh)) { - local $/; - $conf->set_binary($i->key, <$fh>); - } - }else{ - warn "Condition failed for " . $i->key; - } - } elsif ( $type eq 'checkbox' ) { -# if ( defined($cgi->param($i->key. $n)) && $cgi->param($i->key. $n) ) { - if ( defined $cgi->param($i->key. $n) ) { - #$conf->touch($i->key); - push @touch, $i->key; - } else { - #$conf->delete($i->key); - push @delete, $i->key; - } - } elsif ( $type eq 'text' || $type eq 'select' || $type eq 'select-sub' ) { - if ( $cgi->param($i->key. $n) ne '' ) { - $conf->set($i->key, $cgi->param($i->key. $n)); - } else { - $conf->delete($i->key); - } - } elsif ( $type eq 'editlist' || $type eq 'selectmultiple' ) { - if ( scalar(@{[ $cgi->param($i->key. $n) ]}) ) { - $conf->set($i->key, join("\n", @{[ $cgi->param($i->key. $n) ]} )); - } else { - $conf->delete($i->key); +my $agentnum = $cgi->param('agentnum'); +my $key = $cgi->param('key'); +my $i = $confitems{$key}; + +my @touch = (); +my @delete = (); +my $n = 0; +foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) { + if ( $type eq '' ) { + } elsif ( $type eq 'textarea' ) { + if ( $cgi->param($i->key.$n) ne '' ) { + my $value = $cgi->param($i->key.$n); + $value =~ s/\r\n/\n/g; #browsers? + $conf->set($i->key, $value, $agentnum); + } else { + $conf->delete($i->key, $agentnum); + } + } elsif ( $type eq 'binary' ) { + if ( defined($cgi->param($i->key.$n)) && $cgi->param($i->key.$n) ) { + my $fh = $cgi->upload($i->key.$n); + if (defined($fh)) { + local $/; + $conf->set_binary($i->key, <$fh>, $agentnum); } + }else{ + warn "Condition failed for " . $i->key; + } + } elsif ( $type eq 'checkbox' ) { + if ( defined $cgi->param($i->key.$n) ) { + push @touch, $i->key; + } else { + push @delete, $i->key; + } + } elsif ( $type eq 'text' || $type eq 'select' || $type eq 'select-sub' ) { + if ( $cgi->param($i->key.$n) ne '' ) { + $conf->set($i->key, $cgi->param($i->key.$n), $agentnum); } else { + $conf->delete($i->key, $agentnum); + } + } elsif ( $type eq 'editlist' || $type eq 'selectmultiple' ) { + if ( scalar(@{[ $cgi->param($i->key.$n) ]}) ) { + $conf->set($i->key, join("\n", @{[ $cgi->param($i->key.$n) ]} ), $agentnum); + } else { + $conf->delete($i->key, $agentnum); } - $n++; } - # warn @touch; - $conf->touch($_) foreach @touch; - $conf->delete($_) foreach @delete; + $n++; } +# warn @touch; +$conf->touch($_, $agentnum) foreach @touch; +$conf->delete($_, $agentnum) foreach @delete; + -<% $cgi->redirect("config-view.cgi") %> +<% header('Configuration set') %> + + diff --git a/httemplate/config/config-view.cgi b/httemplate/config/config-view.cgi index 7f2a1b293..5f2166320 100644 --- a/httemplate/config/config-view.cgi +++ b/httemplate/config/config-view.cgi @@ -1,6 +1,22 @@ -<% include("/elements/header.html",'View Configuration', menubar( 'Main Menu' => $p, - 'Edit Configuration' => 'config.cgi' ) ) %> -% my $conf = new FS::Conf; my @config_items = $conf->config_items; +<% include("/elements/header.html", + $title, + menubar( + 'Main Menu' => $p, + 'View all agents' => $p.'browse/agent.cgi', + ) + ) +%> + + + + + + +% if ($FS::UID::use_confcompat) { + + CONFIGURATION NOT STORED IN DATABASE -- USING COMPATIBILITY MODE

+%} +% % foreach my $section ( qw(required billing username password UI session % shell BIND % ), @@ -31,7 +47,7 @@ % foreach my $i (grep $_->section eq $section, @config_items) { - + <% $i->key %> - <% $i->description %> @@ -45,8 +61,8 @@ % } elsif ( $type eq 'binary' ) { - <% $conf->exists($i->key) - ? qq!download! + <% $conf->exists($i->key, $agentnum) + ? qq!download! : 'empty' %> @@ -57,27 +73,27 @@ % } elsif ( $type eq 'checkbox' ) { - + % } elsif ( $type eq 'text' || $type eq 'select' ) { % } elsif ( $type eq 'select-sub' ) { % } else { @@ -100,4 +116,23 @@ <%init> die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my ($conf, $title, @config_items, $agentnum); + +if ($cgi->param('agentnum') =~ /^(\d+)$/) { + $agentnum = $1; +} + +if ($agentnum) { + my $agent = qsearchs('agent', { 'agentnum' => $agentnum } ); + die "Agent $agentnum not found!" unless $agent; + + $title = "Configuration for ". $agent->agent; +} else { + $title = 'Global Configuration'; +} + +$conf = new FS::Conf; +@config_items = grep { $agentnum ? $_->per_agent : 1 } $conf->config_items; + diff --git a/httemplate/config/config.cgi b/httemplate/config/config.cgi index df9af47a6..10bbadaf8 100644 --- a/httemplate/config/config.cgi +++ b/httemplate/config/config.cgi @@ -1,4 +1,5 @@ -<% include("/elements/header.html",'Edit Configuration', menubar( 'Main Menu' => $p ) ) %> +<% include("/elements/header-popup.html", $title) %> + -% my $conf = new FS::Conf; my @config_items = $conf->config_items; - - -% foreach my $section ( qw(required billing username password UI session -% shell BIND -% ), -% '', 'deprecated') { +% if ( $cgi->param('error') ) { + Error: <% $cgi->param('error') %> +

+% } - - -% foreach my $nav_section ( qw(required billing username password UI session -% shell BIND -% ), -% '', 'deprecated') { -% if ( $section eq $nav_section ) { + + + - [<% ucfirst($nav_section || 'unclassified') %>] -% } else { +Setting <% $key %> - [<% ucfirst($nav_section || 'unclassified') %>] -% } -% } +
-<% encode_entities(join("\n", $conf->config($i->key) ) ) %>
+<% encode_entities(join("\n", $conf->config($i->key, $agentnum) ) ) %>
 
YES' : 'ff0000">NO' %>YES' : 'ff0000">NO' %>
- <% $conf->exists($i->key) ? $conf->config($i->key) : '' %> + <% $conf->exists($i->key, $agentnum) ? $conf->config($i->key, $agentnum) : '' %>
- <% $conf->config($i->key) %>: - <% &{ $i->option_sub }( $conf->config($i->key) ) %> + <% $conf->config($i->key, $agentnum) %>: + <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) %>
- - -% foreach my $i (grep $_->section eq $section, @config_items) { - - - -% if ( defined $i->editlist_parts ) { -% my $pnum=0; foreach my $part ( @{$i->editlist_parts} ) { +% foreach my $line ( $conf->config($key, $agentnum) ) { - - -% $pnum++; } -% } else { +% } elsif ( $part->{type} eq 'immutable' ) { - -% } + <% $part->{value} %> + " value="<% $part->{value} %>"> - -
-
- <% table("#cccccc", 2) %> -
- <% ucfirst($section || 'unclassified') %> configuration options -
% my $n = 0; -% foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) { -% #warn $i->key unless defined($type); +% foreach my $type ( ref($config_item->type) ? @{$config_item->type} : $config_item->type ) { +% if ( $type eq '' ) { + + no type + +% } elsif ( $type eq 'binary' ) { + + Filename "> + +% } elsif ( $type eq 'textarea' ) { + + + +% } elsif ( $type eq 'checkbox' ) { + + " type="checkbox" value="1" + <% $conf->exists($key, $agentnum) ? 'CHECKED' : '' %> > + +% } elsif ( $type eq 'text' ) { + + " type="text" value="<% $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '' %>"> + +% } elsif ( $type eq 'select' || $type eq 'selectmultiple' ) { + + -% } elsif ( $type eq 'textarea' ) { + <% $hash{ $conf->config($key, $agentnum) } %> +% }else{ - -% } elsif ( $type eq 'checkbox' ) { + <% $curvalue %> +% } +% } - exists($i->key) ? ' CHECKED' : '' %>> -% } elsif ( $type eq 'text' ) { + +% } elsif ( $type eq 'select-sub' ) { - -% } elsif ( $type eq 'select' || $type eq 'selectmultiple' ) { + > -% -% my %hash = (); -% if ( $i->select_enum ) { -% tie %hash, 'Tie::IxHash', -% '' => '', map { $_ => $_ } @{ $i->select_enum }; -% } elsif ( $i->select_hash ) { -% if ( ref($i->select_hash) eq 'ARRAY' ) { -% tie %hash, 'Tie::IxHash', -% '' => '', @{ $i->select_hash }; -% } else { -% tie %hash, 'Tie::IxHash', -% '' => '', %{ $i->select_hash }; -% } -% } else { -% %hash = ( '' => 'WARNING: neither select_enum nor select_hash specified in Conf.pm for configuration option "'. $i->key. '"' ); -% } +% my %options = &{$config_item->options_sub}; +% my @options = sort { $a <=> $b } keys %options; +% my %saw; +% foreach my $value ( @options ) { +% local($^W)=0; next if $saw{$value}++; + + -
- - -
- <% itable() %>
-% 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 %> -% } + "> -
-% } 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; + -- cgit v1.2.1