From 324b781a6a3378995bdd0eb181e94ce1957d49f5 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Thu, 11 Oct 2012 21:45:01 -0700 Subject: [PATCH] Page to edit server IP address --- iscsi-target/config | 1 + iscsi-target/config.info | 1 + iscsi-target/edit_addr.cgi | 36 ++++++++++++++ iscsi-target/index.cgi | 6 +++ iscsi-target/iscsi-target-lib.pl | 82 ++++++++++++++++++++++++++++++++ iscsi-target/lang/en | 16 +++++++ iscsi-target/save_addr.cgi | 40 ++++++++++++++++ 7 files changed, 182 insertions(+) create mode 100644 iscsi-target/edit_addr.cgi create mode 100644 iscsi-target/save_addr.cgi diff --git a/iscsi-target/config b/iscsi-target/config index 068fe0f9d..185b3abdf 100644 --- a/iscsi-target/config +++ b/iscsi-target/config @@ -2,3 +2,4 @@ config_file=/etc/ietd.conf ietadm=ietadm pid_file=/var/run/iscsi_trgt.pid init_name=iscsitarget +opts_file=/etc/sysconfig/iscsi-target diff --git a/iscsi-target/config.info b/iscsi-target/config.info index 11183e28b..50b7bb265 100644 --- a/iscsi-target/config.info +++ b/iscsi-target/config.info @@ -2,3 +2,4 @@ config_file=iSCSI target configuration file,0 ietadm=Full path to ietadm command,0 pid_file=Full path to PID file,0 init_name=Bootup script name,0 +opts_file=File containing command line flags,0 diff --git a/iscsi-target/edit_addr.cgi b/iscsi-target/edit_addr.cgi new file mode 100644 index 000000000..88080be79 --- /dev/null +++ b/iscsi-target/edit_addr.cgi @@ -0,0 +1,36 @@ +#!/usr/local/bin/perl +# Show port and address options + +use strict; +use warnings; +require './iscsi-target-lib.pl'; +our (%text); +my $opts = &get_iscsi_options(); + +&ui_print_header(undef, $text{'addr_title'}, ""); + +print &ui_form_start("save_addr.cgi", "post"); +print &ui_table_start($text{'addr_header'}, undef, 2); + +# Listen on address +my $addr = $opts->{'a'} || $opts->{'address'}; +print &ui_table_row($text{'addr_addr'}, + &ui_opt_textbox("addr", $addr, 30, + $text{'addr_any'}, $text{'addr_ip'})); + +# Listen on port +my $port = $opts->{'p'} || $opts->{'port'}; +print &ui_table_row($text{'addr_port'}, + &ui_opt_textbox("port", $port, 30, $text{'default'}." (3260)")); + +# Debug level +my $debug = $opts->{'d'} || $opts->{'debug'}; +print &ui_table_row($text{'addr_debug'}, + &ui_opt_textbox("debug", $debug, 5, $text{'addr_debugnone'})); + + +print &ui_table_end(); +print &ui_form_end([ [ undef, $text{'save'} ] ]); + +&ui_print_footer("", $text{'index_return'}); + diff --git a/iscsi-target/index.cgi b/iscsi-target/index.cgi index 0b6ec4c27..df8390fc4 100755 --- a/iscsi-target/index.cgi +++ b/iscsi-target/index.cgi @@ -64,14 +64,20 @@ print &ui_hr(); my @links = ( "edit_auth.cgi", "edit_conn.cgi", "edit_timeout.cgi", + "edit_addr.cgi", + "list_clients.cgi", "edit_manual.cgi" ); my @titles = ( $text{'auth_title'}, $text{'conn_title'}, $text{'timeout_title'}, + $text{'addr_title'}, + $text{'clients_title'}, $text{'manual_title'} ); my @icons = ( "images/auth.gif", "images/conn.gif", "images/timeout.gif", + "images/addr.gif", + "images/clients.gif", "images/manual.gif" ); &icons_table(\@links, \@titles, \@icons); diff --git a/iscsi-target/iscsi-target-lib.pl b/iscsi-target/iscsi-target-lib.pl index 312ad5dbb..6b134e35a 100644 --- a/iscsi-target/iscsi-target-lib.pl +++ b/iscsi-target/iscsi-target-lib.pl @@ -270,4 +270,86 @@ my ($ok, $out) = &init::restart_action($config{'init_name'}); return $ok ? undef : $out; } +# get_iscsi_options_file() +# Returns the file containing command-line options, for use when locking +sub get_iscsi_options_file +{ +return $config{'opts_file'}; +} + +# get_iscsi_options_string() +# Returns all flags as a string +sub get_iscsi_options_string +{ +my $file = &get_iscsi_options_file(); +my %env; +&read_env_file($file, \%env); +return $env{'OPTIONS'}; +} + +# get_iscsi_options() +# Returns a hash ref of command line options +sub get_iscsi_options +{ +my $str = &get_iscsi_options_string(); +my %opts; +while($str =~ /\S/) { + if ($str =~ /^\s*\-(c|d|g|a|p|u)\s+(\S+)(.*)/) { + # Short arg, like -p 123 + $str = $3; + $opts{$1} = $2; + } + elsif ($str =~ /^\s*\--(config|debug|address|port)=(\S+)(.*)/) { + # Long arg, like --address=5.5.5.5 + $str = $3; + $opts{$1} = $2; + } + elsif ($str =~ /^\s*\-((f)+)(.*)/) { + # Arg with no value, like -f + $str = $3; + foreach my $o (split(//, $1)) { + $opts{$o} = ""; + } + } + else { + &error("Unknown option $str"); + } + } +return \%opts; +} + +# save_iscsi_options_string(str) +# Update the options file with command line options from a string +sub save_iscsi_options_string +{ +my ($str) = @_; +my $file = &get_iscsi_options_file(); +my %env; +&read_env_file($file, \%env); +$env{'OPTIONS'} = $str; +&write_env_file($file, \%env); +} + +# save_iscsi_options(&opts) +# Update the options file with command line options from a hash +sub save_iscsi_options +{ +my ($opts) = @_; +my @str; +foreach my $o (keys %$opts) { + if ($opts->{$o} eq "") { + push(@str, "-".$o); + } + elsif (length($o) == 1) { + push(@str, "-".$o." ".$opts->{$o}); + } + else { + push(@str, "--".$o."=".$opts->{$o}); + } + } +&save_iscsi_options_string(join(" ", @str)); +} + + + 1; diff --git a/iscsi-target/lang/en b/iscsi-target/lang/en index a98076c62..14229ba8c 100644 --- a/iscsi-target/lang/en +++ b/iscsi-target/lang/en @@ -104,6 +104,21 @@ timeout_secs=seconds timeout_nopt=Time to wait for ping response timeout_noptnone=Same as ping time +addr_title=Server Address +addr_header=iSCSI server networking options +addr_addr=Listen on IP address +addr_any=Any address +addr_ip=IP +addr_port=Listen on port +addr_debug=Debug level +addr_debugnone=Debugging disabled +addr_err=Failed to save server address +addr_eaddr=Address to listen on must be an IP address +addr_eport=Port to listen on must be a number +addr_edebug=Debug level must be a number + +clients_title=Client Connections + manual_title=Edit Configuration File manual_desc=Use the text box below to edit the iSCSI server configuration file $1. Be careful, as no validation will be performed on your input! manual_err=Failed to save configuration file @@ -127,3 +142,4 @@ log_manual=Manually edited configuration file log_auth=Changed global authentication settings log_conn=Changed global connection settings log_timeout=Changed global timeout settings +log_addr=Changed server address diff --git a/iscsi-target/save_addr.cgi b/iscsi-target/save_addr.cgi new file mode 100644 index 000000000..896a71b6c --- /dev/null +++ b/iscsi-target/save_addr.cgi @@ -0,0 +1,40 @@ +#!/usr/local/bin/perl +# Save networking options + +use strict; +use warnings; +require './iscsi-target-lib.pl'; +our (%text, %in, %config); +&ReadParse(); +&error_setup($text{'addr_err'}); +&lock_file($config{'opts_file'}); +my $opts = &get_iscsi_options(); + +# Listen on address +delete($opts->{'a'}); +delete($opts->{'address'}); +if (!$in{'addr_def'}) { + &check_ipaddress($in{'addr'}) || &error($text{'addr_eaddr'}); + $opts->{'a'} = $in{'addr'}; + } + +# Listen on port +delete($opts->{'p'}); +delete($opts->{'port'}); +if (!$in{'port_def'}) { + $in{'port'} =~ /^\d+$/ || &error($text{'addr_eport'}); + $opts->{'p'} = $in{'port'}; + } + +# Debug level +delete($opts->{'d'}); +delete($opts->{'debug'}); +if (!$in{'debug_def'}) { + $in{'debug'} =~ /^\d+$/ || &error($text{'addr_edebug'}); + $opts->{'d'} = $in{'debug'}; + } + +&save_iscsi_options($opts); +&unlock_file($config{'opts_file'}); +&webmin_log('addr'); +&redirect("");