Work on iscsi options form

This commit is contained in:
Jamie Cameron
2012-09-08 22:30:21 -07:00
parent a0583a234b
commit a8f4e5ac61
8 changed files with 189 additions and 7 deletions

View File

@@ -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 },

View File

@@ -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

View File

@@ -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

View File

@@ -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'});

View File

@@ -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();

View File

@@ -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 </dev/null");
my $str = &get_iscsi_options_string();
my $out = &backquote_logged("$config{'iscsi_server'} -f $config{'targets_file'} $str 2>&1 </dev/null");
return $? ? $out : undef;
}
@@ -374,5 +375,63 @@ foreach my $n (@names) {
return @rv;
}
# get_iscsi_options_string()
# Returns all flags as a string
sub get_iscsi_options_string
{
my %env;
&read_env_file($config{'opts_file'}, \%env);
return $env{'NETBSD_ISCSI_OPTS'};
}
# 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*\-(b|f|p|m|t|v)\s+(\S+)(.*)/) {
$str = $3;
$opts{$1} = $2;
}
elsif ($str =~ /^\s*\-((4|6|D|V)+)(.*)/) {
$str = $3;
foreach my $o (split(//, $1)) {
$opts{$o} = "";
}
}
else {
&error("Unknown option $str");
}
}
return \%opts;
}
# save_iscsi_options(&opts)
# Update the options file or init script and built-in config
sub save_iscsi_options
{
my ($opts) = @_;
my @str;
foreach my $o (keys %$opts) {
if ($opts->{$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;

View File

@@ -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

View File

@@ -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("");