diff --git a/iscsi-server/atboot.cgi b/iscsi-server/atboot.cgi index 6f24627d9..f14071caf 100644 --- a/iscsi-server/atboot.cgi +++ b/iscsi-server/atboot.cgi @@ -12,9 +12,14 @@ our (%text, %config, %in); my $old = &init::action_status($config{'init_name'}); if ($old != 2 && $in{'boot'}) { # Enable at boot + if (!-r $config{'opts_file'}) { + my $fh = "OPTS"; + &open_tempfile($fh, ">$config{'opts_file'}"); + &close_tempfile($fh); + } &init::enable_at_boot($config{'init_name'}, "Start or stop the iSCSI server", - "$config{'iscsi_server'} -f $config{'targets_file'}", + "source $config{'opts_file'} ; $config{'iscsi_server'} -f $config{'targets_file'} \$NETBSD_ISCSI_OPTS", "kill `cat $config{'pid_file'}`", undef, { 'fork' => 1 }, diff --git a/iscsi-server/config b/iscsi-server/config index 30f07b7d5..03990a3d3 100644 --- a/iscsi-server/config +++ b/iscsi-server/config @@ -2,3 +2,4 @@ targets_file=/etc/iscsi/targets iscsi_server=/usr/sbin/iscsi-target pid_file=/var/run/iscsi-target.pid init_name=netbsd-iscsi +opts_file=/etc/sysconfig/netbsd-iscsi diff --git a/iscsi-server/config.info b/iscsi-server/config.info index 9ae76a703..4b6eedbc9 100644 --- a/iscsi-server/config.info +++ b/iscsi-server/config.info @@ -2,3 +2,4 @@ targets_file=iSCSI server targets file,0 iscsi_server=Full path to iSCSI server,0 pid_file=Full path to PID file,0 init_name=Bootup script name,0 +opts_file=File listing command line options,0 diff --git a/iscsi-server/edit_opts.cgi b/iscsi-server/edit_opts.cgi new file mode 100644 index 000000000..0b48667ed --- /dev/null +++ b/iscsi-server/edit_opts.cgi @@ -0,0 +1,36 @@ +#!/usr/local/bin/perl +# Show a form for editing command-line options + +use strict; +use warnings; +require './iscsi-server-lib.pl'; +our (%text, %config); + +&ui_print_header(undef, $text{'opts_title'}, ""); + +my $opts = &get_iscsi_options(); +print &ui_form_start("save_opts.cgi"); +print &ui_table_start($text{'opts_header'}, undef, 2); + +# IPv4 / 6 mode +print &ui_table_row($text{'opts_ip4'}, + &ui_yesno_radio("ip4", defined($opts->{'4'}))); +print &ui_table_row($text{'opts_ip6'}, + &ui_yesno_radio("ip6", defined($opts->{'6'}))); + +# Hostname +print &ui_table_row($text{'opts_name'}, + &ui_opt_textbox("name", $opts->{'t'}, 30, $text{'opts_namedef'})); + +# Port number +print &ui_table_row($text{'opts_port'}, + &ui_opt_textbox("port", $opts->{'p'}, 5, $text{'default'}." (3260)")); + +# Max sessions +print &ui_table_row($text{'opts_sess'}, + &ui_opt_textbox("sess", $opts->{'s'}, 5, $text{'default'})); + +print &ui_table_end(); +print &ui_form_end([ [ undef, $text{'save'} ] ]); + +&ui_print_footer("", $text{'index_return'}); diff --git a/iscsi-server/index.cgi b/iscsi-server/index.cgi index 41f2f558c..8a7c48a73 100644 --- a/iscsi-server/index.cgi +++ b/iscsi-server/index.cgi @@ -15,12 +15,15 @@ if ($err) { } my @links = ( "list_extents.cgi", "list_devices.cgi", - "list_targets.cgi", "edit_manual.cgi" ); + "list_targets.cgi", "edit_opts.cgi", + "edit_manual.cgi" ); my @titles = ( $text{'extents_title'}, $text{'devices_title'}, - $text{'targets_title'}, $text{'manual_title'} ); + $text{'targets_title'}, $text{'opts_title'}, + $text{'manual_title'} ); my @icons = ( "images/extents.gif", "images/devices.gif", - "images/targets.gif", "images/manual.gif" ); -&icons_table(\@links, \@titles, \@icons); + "images/targets.gif", "images/opts.gif", + "images/manual.gif" ); +&icons_table(\@links, \@titles, \@icons, 5); print &ui_hr(); print &ui_buttons_start(); diff --git a/iscsi-server/iscsi-server-lib.pl b/iscsi-server/iscsi-server-lib.pl index 02dbb1388..62a85e6c2 100644 --- a/iscsi-server/iscsi-server-lib.pl +++ b/iscsi-server/iscsi-server-lib.pl @@ -10,7 +10,7 @@ use WebminCore; &foreign_require("fdisk"); &foreign_require("lvm"); &foreign_require("mount"); -our (%text, %config); +our (%text, %config, $module_config_file); # check_config() # Returns undef if the iSCSI server is installed, or an error message if @@ -232,7 +232,8 @@ return &check_pid_file($config{'pid_file'}); # Launch the iscsi server process, and return undef if successful sub start_iscsi_server { -my $out = &backquote_logged("$config{'iscsi_server'} -f $config{'targets_file'} 2>&1 &1 {$o} eq "") { + push(@str, "-".$o); + } + else { + push(@str, "-".$o." ".$opts->{$o}); + } + } +my $str = join(" ", @str); + +# Save in an environment file +my %env; +&lock_file($config{'opts_file'}); +&read_env_file($config{'opts_file'}, \%env); +$env{'NETBSD_ISCSI_OPTS'} = $str; +&write_env_file($config{'opts_file'}, \%env); +&unlock_file($config{'opts_file'}); +} + 1; diff --git a/iscsi-server/lang/en b/iscsi-server/lang/en index 74a14eff1..f7e3d23c2 100644 --- a/iscsi-server/lang/en +++ b/iscsi-server/lang/en @@ -120,8 +120,23 @@ target_sure=Delete Target target_enetwork=Missing or invalid network to share with target_emask=Missing or invalid netmask to share with +opts_title=iSCSI Server Options +opts_header=Options for all iSCSI targets +opts_ip4=Accept IPv4 connections +opts_ip6=Accept IPv6 connections +opts_name=Name visible to clients +opts_namedef=Default (system hostname) +opts_port=Listen on port +opts_sess=Maximum concurrent sessions +opts_err=Failed to save options +opts_ename=Missing or invalid name - only letters, numbers, dash, dot and underscore are allowed +opts_eport=Missing or non-numeric port number +opts_esess=Missing or non-numeric maximum sessions + 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 +manual_edata=No contents entered! desc_extent=Device to share $1 desc_device=Device combination $1 diff --git a/iscsi-server/save_opts.cgi b/iscsi-server/save_opts.cgi new file mode 100644 index 000000000..afb1f70de --- /dev/null +++ b/iscsi-server/save_opts.cgi @@ -0,0 +1,62 @@ +#!/usr/local/bin/perl +# Show a form for editing command-line options + +use strict; +use warnings; +require './iscsi-server-lib.pl'; +our (%text, %config); +&error_setup($text{'opts_err'}); + +my $opts = &get_iscsi_options(); + +# IPv4 enabled? +if ($in{'ip4'}) { + $opts->{'4'} = ''; + } +else { + delete($opts->{'4'}); + } + +# IPv6 enabled? +if ($in{'ip6'}) { + $opts->{'6'} = ''; + } +else { + delete($opts->{'6'}); + } + +# Hostname +if ($in{'name_def'}) { + delete($opts->{'t'}); + } +else { + $in{'name'} =~ /^[A-Za-z0-9\.\_\-]+$/ || + &error($text{'opts_ename'}); + $opts->{'t'} = $in{'name'}; + } + +# Port number +if ($in{'port_def'}) { + delete($opts->{'p'}); + } +else { + $in{'port'} =~ /^\d+$/ || $in{'port'} > 0 && $in{'port'} < 65536 || + &error($text{'opts_eport'}); + $opts->{'p'} = $in{'port'}; + } + +# Port number +if ($in{'sess_def'}) { + delete($opts->{'s'}); + } +else { + $in{'sess'} =~ /^\d+$/ || $in{'sess'} > 0 || + &error($text{'opts_esess'}); + $opts->{'s'} = $in{'sess'}; + } + +# XXX locking? +&save_iscsi_options($opts); +&webmin_log("opts"); +&redirect(""); +