diff options
Diffstat (limited to 'httemplate/config')
-rw-r--r-- | httemplate/config/config-delete.cgi | 15 | ||||
-rw-r--r-- | httemplate/config/config-download.cgi | 28 | ||||
-rw-r--r-- | httemplate/config/config-image.cgi | 19 | ||||
-rw-r--r-- | httemplate/config/config-process.cgi | 105 | ||||
-rw-r--r-- | httemplate/config/config-view.cgi | 177 | ||||
-rw-r--r-- | httemplate/config/config.cgi | 331 |
6 files changed, 675 insertions, 0 deletions
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; + +</%init> +<% $cgi->redirect(popurl(2) . "browse/agent.cgi") %> diff --git a/httemplate/config/config-download.cgi b/httemplate/config/config-download.cgi new file mode 100644 index 000000000..6979246db --- /dev/null +++ b/httemplate/config/config-download.cgi @@ -0,0 +1,28 @@ +% +% +%my $conf=new FS::Conf; +% +%http_header('Content-Type' => 'application/x-unknown' ); +% +%die "No configuration variable specified (bad URL)!" # umm +% 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, $agentnum); +<%init> +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $agentnum; +if ($cgi->param('agentnum') =~ /^(\d+)$/) { + $agentnum = $1; +} + +</%init> diff --git a/httemplate/config/config-image.cgi b/httemplate/config/config-image.cgi new file mode 100644 index 000000000..892f7c65b --- /dev/null +++ b/httemplate/config/config-image.cgi @@ -0,0 +1,19 @@ +<% $conf->config_binary($name, $agentnum) %> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $conf = new FS::Conf; + +http_header( 'Content-Type' => 'image/png' ); #just png for now + +$cgi->param('key') =~ /^([-\w.]+)$/ or die "illegal config option"; +my $name = $1; + +my $agentnum = ''; +if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) { + $agentnum = $1; +} + +</%init> diff --git a/httemplate/config/config-process.cgi b/httemplate/config/config-process.cgi new file mode 100644 index 000000000..84bfdefcb --- /dev/null +++ b/httemplate/config/config-process.cgi @@ -0,0 +1,105 @@ +<%init> +die "access denied\n" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $conf = new FS::Conf; +$FS::Conf::DEBUG = 1; +my @config_items = grep { $_->key != ~/^invoice_(html|latex|template)/ } + $conf->config_items; +my %confitems = map { $_->key => $_ } $conf->config_items; + +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' || $type eq 'image' ) { + 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($_, $agentnum) foreach @touch; +$conf->delete($_, $agentnum) foreach @delete; + +</%init> +<% header('Configuration set') %> + <SCRIPT TYPE="text/javascript"> +% my $n = 0; +% foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) { + var configCell = window.top.document.getElementById('<% $i->key. $n %>'); + //alert('found cell ' + configCell); +% if ( $type eq 'textarea' +% || $type eq 'editlist' +% || $type eq 'selectmultiple' ) { + configCell.innerHTML = + '<font size="-2"><pre>' + "\n" + + <% encode_entities(join("\n", + map { length($_) > 88 ? substr($_,0,88).'...' : $_ } + $conf->config($i->key, $agentnum) + ) ) + |js_string %> + + '</pre></font>'; + +% } elsif ( $type eq 'checkbox' ) { +% if ( $conf->exists($i->key, $agentnum) ) { + configCell.style.backgroundColor = '#00ff00'; + configCell.innerHTML = 'YES'; +% } else { + configCell.style.backgroundColor = '#ff0000'; + configCell.innerHTML = 'NO'; +% } +% } elsif ( $type eq 'text' || $type eq 'select' ) { + configCell.innerHTML = <% $conf->exists($i->key, $agentnum) ? $conf->config($i->key, $agentnum) : '' |js_string %>; +% } elsif ( $type eq 'select-sub' ) { + configCell.innerHTML = + <% $conf->config($i->key, $agentnum) |js_string %> + ': ' + + <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) |js_string %>; +% } else { + //alert('unknown type <% $type %>'); + window.top.location.reload(); +% } + +% $n++; +% } + parent.cClick(); + </SCRIPT> + </BODY></HTML> diff --git a/httemplate/config/config-view.cgi b/httemplate/config/config-view.cgi new file mode 100644 index 000000000..0f5fd6213 --- /dev/null +++ b/httemplate/config/config-view.cgi @@ -0,0 +1,177 @@ +<% include("/elements/header.html", $title, menubar(@menubar)) %> + +Click on a configuration value to change it. +<BR><BR> + +<% include('/elements/init_overlib.html') %> + +% if ($FS::UID::use_confcompat) { + <FONT SIZE="+1" COLOR="#ff0000">CONFIGURATION NOT STORED IN DATABASE -- USING COMPATIBILITY MODE</FONT><BR><BR> +%} + +% foreach my $section (@sections) { + + <A NAME="<% $section || 'unclassified' %>"></A> + <FONT SIZE="-2"> + +% foreach my $nav_section (@sections) { +% +% if ( $section eq $nav_section ) { + [<A NAME="not<% $nav_section || 'unclassified' %>" style="background-color: #cccccc"><% ucfirst($nav_section || 'unclassified') %></A>] +% } else { + [<A HREF="#<% $nav_section || 'unclassified' %>"><% ucfirst($nav_section || 'unclassified') %></A>] +% } +% +% } + + </FONT><BR> + <TABLE BGCOLOR="#cccccc" BORDER=1 CELLSPACING=0 CELLPADDING=0 BORDERCOLOR="#999999"> + <tr> + <th colspan="2" bgcolor="#dcdcdc"> + <% ucfirst($section || 'unclassified') %> configuration options + </th> + </tr> +% foreach my $i (@{ $section_items{$section} }) { +% my @types = ref($i->type) ? @{$i->type} : ($i->type); +% my( $width, $height ) = ( 522, 336 ); +% if ( grep $_ eq 'textarea', @types ) { +% #800x600 +% $width = 763; +% $height = 408; +% #1024x768 +% #$width = +% #$height = +% } + + <tr> + <td><% include('/elements/popup_link.html', + 'action' => 'config.cgi?key='. $i->key. + ';agentnum='. $agentnum, + 'width' => $width, + 'height' => $height, + 'actionlabel' => 'Enter configuration value', + 'label' => '<b>'. $i->key. '</b>', + 'aname' => $i->key, + ) + %>: <% $i->description %> + </td> + <td><table border=0> + +% my $n = 0; +% foreach my $type (@types) { + +% if ( $type eq '' ) { + + <tr> + <td><font color="#ff0000">no type</font></td> + </tr> + +% } elsif ( $type eq 'image' ) { + + <tr> + + <% $conf->exists($i->key, $agentnum) + ? '<img src="config-image.cgi?key='. $i->key. + ';agentnum='. $agentnum. '">' + : 'empty' + %> + </tr> + +% } elsif ( $type eq 'binary' ) { + + <tr> + + <% $conf->exists($i->key, $agentnum) + ? qq!<a href="config-download.cgi?key=!. $i->key. ';agentnum='. $agentnum. qq!">download</a>! + : 'empty' + %> + </tr> + +% } elsif ( $type eq 'textarea' +% || $type eq 'editlist' +% || $type eq 'selectmultiple' ) { + + <tr> + <td id="<% $i->key.$n %>" bgcolor="#ffffff"> +<font size="-2"><pre> +<% encode_entities(join("\n", + map { length($_) > 88 ? substr($_,0,88).'...' : $_ } + $conf->config($i->key, $agentnum) + ) ) +%> +</pre></font> + </td> + </tr> +% } elsif ( $type eq 'checkbox' ) { + + <tr> + <td id="<% $i->key.$n %>" bgcolor="#<% $conf->exists($i->key, $agentnum) ? '00ff00">YES' : 'ff0000">NO' %></td> + </tr> +% } elsif ( $type eq 'text' || $type eq 'select' ) { + + <tr> + <td id="<% $i->key.$n %>" bgcolor="#ffffff"> + <% $conf->exists($i->key, $agentnum) ? $conf->config($i->key, $agentnum) : '' %> + </td></tr> +% } elsif ( $type eq 'select-sub' ) { + + <tr> + <td id="<% $i->key.$n %>" bgcolor="#ffffff"> + <% $conf->config($i->key, $agentnum) %>: + <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) %> + </td> + </tr> +% } else { + + <tr><td> + <font color="#ff0000">unknown type <% $type %></font> + </td></tr> +% } +% $n++; +% } + + </table></td> + </tr> +% } + + </table><br><br> +% } + + +</body></html> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $agentnum = ''; +my $title; +my @menubar = (); +if ($cgi->param('agentnum') =~ /^(\d+)$/) { + $agentnum = $1; + my $agent = qsearchs('agent', { 'agentnum' => $agentnum } ); + die "Agent $agentnum not found!" unless $agent; + + push @menubar, 'View all agents' => $p.'browse/agent.cgi'; + $title = 'Agent Configuration for '. $agent->agent; +} else { + $title = 'Global Configuration'; +} + +my $conf = new FS::Conf; + +my @config_items = grep { $agentnum ? $_->per_agent : 1 } + grep { $_->key != ~/^invoice_(html|latex|template)/ } + $conf->config_items; + +my @sections = qw(required billing username password UI session shell BIND ); +push @sections, '', 'deprecated'; + +my %section_items = (); +foreach my $section (@sections) { + $section_items{$section} = [ grep $_->section eq $section, @config_items ]; +} + +@sections = grep scalar( @{ $section_items{$_} } ), @sections; + +</%init> diff --git a/httemplate/config/config.cgi b/httemplate/config/config.cgi new file mode 100644 index 000000000..f390c64a3 --- /dev/null +++ b/httemplate/config/config.cgi @@ -0,0 +1,331 @@ +<% include("/elements/header-popup.html", $title) %> + +<SCRIPT> +var gSafeOnload = new Array(); +var gSafeOnsubmit = new Array(); +window.onload = SafeOnload; +function SafeAddOnLoad(f) { + gSafeOnload[gSafeOnload.length] = f; +} +function SafeOnload() { + for (var i=0;i<gSafeOnload.length;i++) + gSafeOnload[i](); +} +function SafeAddOnSubmit(f) { + gSafeOnsubmit[gSafeOnsubmit.length] = f; +} +function SafeOnsubmit() { + for (var i=0;i<gSafeOnsubmit.length;i++) + gSafeOnsubmit[i](); +} +</SCRIPT> + +<% include('/elements/error.html') %> + +<FORM NAME="OneTrueForm" ACTION="config-process.cgi" METHOD="POST" enctype="multipart/form-data" onSubmit="SafeOnsubmit()"> +<INPUT TYPE="hidden" NAME="agentnum" VALUE="<% $agentnum %>"> +<INPUT TYPE="hidden" NAME="key" VALUE="<% $key %>"> + +Setting <b><% $key %></b> + +% my $description_printed = 0; +% if ( grep $_ eq 'textarea', @types ) { +% $description_printed = 1; + + - <% $description %> + +% } + +<table><tr><td> + +% my $n = 0; +% foreach my $type (@types) { +% if ( $type eq '' ) { + + <font color="#ff0000">no type</font> + +% } elsif ( $type eq 'image' ) { + + <% $conf->exists($key, $agentnum) + ? 'Current image<br>'. + '<img src="config-image.cgi?key='. $key. + ';agentnum='. $agentnum. '"><br>' + : '' + %> + + <BR> + New image filename <input type="file" name="<% "$key$n" %>"> + +% } elsif ( $type eq 'binary' ) { + + Filename <input type="file" name="<% "$key$n" %>"> + +% } elsif ( $type eq 'textarea' ) { + + <textarea name="<% "$key$n" %>" rows=12 cols=78 wrap="off"><% join("\n", $conf->config($key, $agentnum)) |h %></textarea> + +% } elsif ( $type eq 'checkbox' ) { + + <input name="<% "$key$n" %>" type="checkbox" value="1" + <% $conf->exists($key, $agentnum) ? 'CHECKED' : '' %> > + +% } elsif ( $type eq 'text' ) { + + <input name="<% "$key$n" %>" type="text" value="<% $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '' |h %>"> + +% } elsif ( $type eq 'select' || $type eq 'selectmultiple' ) { + + <select name="<% "$key$n" %>" <% $type eq 'selectmultiple' ? 'MULTIPLE' : '' %>> + +% +% my %hash = (); +% if ( $config_item->select_enum ) { +% tie %hash, 'Tie::IxHash', +% '' => '', map { $_ => $_ } @{ $config_item->select_enum }; +% } elsif ( $config_item->select_hash ) { +% if ( ref($config_item->select_hash) eq 'ARRAY' ) { +% tie %hash, 'Tie::IxHash', +% '' => '', @{ $config_item->select_hash }; +% } else { +% tie %hash, 'Tie::IxHash', +% '' => '', %{ $config_item->select_hash }; +% } +% } else { +% %hash = ( '' => 'WARNING: neither select_enum nor select_hash specified in Conf.pm for configuration option "'. $key. '"' ); +% } +% +% my %saw = (); +% foreach my $value ( keys %hash ) { +% local($^W)=0; next if $saw{$value}++; +% my $label = $hash{$value}; +% + + <option value="<% $value %>" + +% if ( $value eq $conf->config($key, $agentnum) +% || ( $type eq 'selectmultiple' +% && grep { $_ eq $value } $conf->config($key, $agentnum) ) ) { + + SELECTED + +% } + + ><% $label %> + +% } +% my $curvalue = $conf->config($key, $agentnum); +% if ( $conf->exists($key, $agentnum) && $curvalue && ! $hash{$curvalue} ) { + + <option value="<% $curvalue %>" SELECTED> + +% if ( exists( $hash{ $conf->config($key, $agentnum) } ) ) { + + <% $hash{ $conf->config($key, $agentnum) } %> + +% }else{ + + <% $curvalue %> + +% } +% } + + </select> + +% } elsif ( $type eq 'select-sub' ) { + + <select name="<% "$key$n" %>"><option value=""> + +% 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}++; + + <option value="<% $value %>" <% $value eq $conf->config($key, $agentnum) ? 'SELECTED' : '' %>><% $value %>: <% $options{$value} %> + +% } +% my $curvalue = $conf->config($key, $agentnum); +% if ( $conf->exists($key, $agentnum) && $curvalue && ! $options{$curvalue} ) { + + <option value="<% $curvalue %>" SELECTED> <% $curvalue %>: <% &{ $config_item->option_sub }( $curvalue ) %> + +% } + + </select> + +% } elsif ( $type eq 'editlist' ) { +% + <script> + function doremove<% "$key$n" %>() { + fromObject = document.OneTrueForm.<% "$key$n" %>; + for (var i=fromObject.options.length-1;i>-1;i--) { + if (fromObject.options[i].selected) + deleteOption<% "$key$n" %>(fromObject,i); + } + } + function deleteOption<% "$key$n" %>(object,index) { + object.options[index] = null; + } + function selectall<% "$key$n" %>() { + fromObject = document.OneTrueForm.<% "$key$n" %>; + for (var i=fromObject.options.length-1;i>-1;i--) { + fromObject.options[i].selected = true; + } + } + function doadd<% "$key$n" %>(object) { + var myvalue = ""; + +% if ( defined($config_item->editlist_parts) ) { +% foreach my $pnum ( 0 .. scalar(@{$config_item->editlist_parts})-1 ) { + + if ( myvalue != "" ) { myvalue = myvalue + " "; } + +% if ( $config_item->editlist_parts->[$pnum]{type} eq 'select' ) { + + myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.options[object.add<% "$key${n}_$pnum" %>.selectedIndex].value + <!-- #RESET SELECT?? maybe not... --> + +% } elsif ( $config_item->editlist_parts->[$pnum]{type} eq 'immutable' ) { + + myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value + +% } else { + + myvalue = myvalue + object.add<% "$key${n}_$pnum" %>.value + object.add<% "$key${n}_$pnum" %>.value = "" + +% } +% } +% } else { + + myvalue = object.add<% "$key${n}_1" %>.value + +% } + + var optionName = new Option(myvalue, myvalue); + var length = object.<% "$key$n" %>.length; + object.<% "$key$n" %>.options[length] = optionName; + } + </script> + <select multiple size=5 name="<% "$key$n" %>"> + <option selected>----------------------------------------------------------------</option> + +% foreach my $line ( $conf->config($key, $agentnum) ) { + + <option value="<% $line %>"><% $line %></option> + +% } + + </select><br> + <input type="button" value="remove selected" onClick="doremove<% "$key$n" %>()"> + <script>SafeAddOnLoad(doremove<% "$key$n" %>); + SafeAddOnSubmit(selectall<% "$key$n" %>); + </script> + <br><% itable() %><tr> + +% if ( defined $config_item->editlist_parts ) { +% my $pnum=0; +% foreach my $part ( @{$config_item->editlist_parts} ) { + + <td> + +% if ( $part->{type} eq 'text' ) { + + <input type="text" name="add<% "$key${n}_$pnum" %>"> + +% } elsif ( $part->{type} eq 'immutable' ) { + + <% $part->{value} %> + <input type="hidden" name="add<% "$key${n}_$pnum" %>" value="<% $part->{value} %>"> + +% } elsif ( $part->{type} eq 'select' ) { + + <select name="add<% qq!$key${n}_$pnum! %>"> + +% foreach my $key ( keys %{$part->{select_enum}} ) { + + <option value="<% $key %>"><% $part->{select_enum}{$key} %></option> + +% } + + </select> + +% } else { + + <font color="#ff0000">unknown type <% $part->type %> </font> + +% } + + </td> + +% $pnum++; +% } +% } else { + + <td><input type="text" name="add<% "$key${n}_0" %>></td> + +% } + + <td><input type="button" value="add" onClick="doadd<% "$key$n" %>(this.form)"></td> + </tr></table> + +% } else { + + <font color="#ff0000">unknown type <% $type %></font> + +% } +% $n++; +% } + + </td> +% unless ( $description_printed ) { + <td><% $description %></td> +% } +</tr> +</table> +<INPUT TYPE="submit" VALUE="<% $title %>"> +</FORM> + +</BODY> +</HTML> +<%once> + +my $conf = new FS::Conf; +my @config_items = grep { $_->key != ~/^invoice_(html|latex|template)/ } + $conf->config_items; +my %confitems = map { $_->key => $_ } @config_items; + +</%once> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $action = 'Set'; + +my $agentnum = ''; +if ($cgi->param('agentnum') =~ /(\d+)$/) { + $agentnum=$1; +} + +my $agent = ''; +my $title; +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"; +my $key = $1; +my $value = $conf->config($key); +my $config_item = $confitems{$key}; + +my $description = $config_item->description; +my $config_type = $config_item->type; +my @types = ref($config_type) ? @$config_type : ($config_type); + +</%init> |