diff --git a/iscsi-client/add_conn.cgi b/iscsi-client/add_conn.cgi index 2e6da5239..92720c8a2 100755 --- a/iscsi-client/add_conn.cgi +++ b/iscsi-client/add_conn.cgi @@ -18,9 +18,17 @@ if ($in{'target'}) { $target || &error(&text('add_etarget', $in{'target'})); } +# Validate username and password +my @auth; +if (!$in{'auth_def'}) { + $in{'authuser'} =~ /\S/ || &error($text{'auth_eusername'}); + $in{'authpass'} =~ /\S/ || &error($text{'auth_epassword'}); + @auth = ( $in{'authmethod'}, $in{'authuser'}, $in{'authpass'} ); + } + # Try to make the connection my $err = &create_iscsi_connection($in{'host'}, $in{'port'}, - $in{'iface'}, $target); + $in{'iface'}, $target, @auth); &error($err) if ($err); &webmin_log("add", "connection", $in{'host'}, diff --git a/iscsi-client/add_form.cgi b/iscsi-client/add_form.cgi index ee0b9e719..38af87f29 100755 --- a/iscsi-client/add_form.cgi +++ b/iscsi-client/add_form.cgi @@ -41,6 +41,7 @@ print &ui_table_row($text{'conns_port'}, print &ui_table_row($text{'conns_iface'}, $in{'iface'} || "$text{'conns_ifacedef'}"); +# Target to mount print &ui_table_row($text{'add_target'}, &ui_select("target", undef, [ [ "", "<".$text{'add_alltargets'}.">" ], @@ -53,6 +54,17 @@ print &ui_table_row($text{'add_target'}, : " (".$text{'add_used'}.")"), ] } @$targets ])); +# Username, password and authentication method +print &ui_table_row($text{'add_auth'}, + &ui_radio("auth_def", 1, + [ [ 1, $text{'add_auth1'}."
" ], + [ 0, &text('add_auth0', + &ui_select("authmethod", "CHAP", + [ [ "None", $text{'auth_method_none'} ], + [ "CHAP" ] ]), + &ui_textbox("authuser", undef, 15), + &ui_textbox("authpass", undef, 15)) ] ])); + print &ui_table_end(); print &ui_form_end([ [ undef, $text{'add_ok'} ] ]); diff --git a/iscsi-client/images/smallicon.gif b/iscsi-client/images/smallicon.gif new file mode 100644 index 000000000..18bf9f3da Binary files /dev/null and b/iscsi-client/images/smallicon.gif differ diff --git a/iscsi-client/iscsi-client-lib.pl b/iscsi-client/iscsi-client-lib.pl index 54b55b111..3b96a002f 100644 --- a/iscsi-client/iscsi-client-lib.pl +++ b/iscsi-client/iscsi-client-lib.pl @@ -205,21 +205,50 @@ foreach my $l (@lines) { return \@rv; } -# create_iscsi_connection(host, [port], [iface], [&target]) +# create_iscsi_connection(host, [port], [iface], [&target], +# [method, username, password]) # Attempts to connect to an iscsi server for the given target (or all targets) sub create_iscsi_connection { -my ($host, $port, $iface, $target) = @_; +my ($host, $port, $iface, $target, $method, $user, $pass) = @_; my $cmd = "$config{'iscsiadm'} -m node". ($target ? " -T ".quotemeta($target->{'name'}).":". quotemeta($target->{'target'}) : ""). " -p ".quotemeta($host).($port ? ":".quotemeta($port) : ""). - ($iface ? " -I ".quotemeta($iface) : ""). - " --login"; + ($iface ? " -I ".quotemeta($iface) : ""); + +# Create the session &clean_language(); my $out = &backquote_logged("$cmd 2>&1"); &reset_environment(); -return $? ? $out : undef; +return $out if ($?); + +# Set session username and password +if ($method) { + &clean_language(); + my $out = &backquote_logged("$cmd --op=update --name=node.session.auth.authmethod --value=$method 2>&1"); + &reset_environment(); + return $out if ($?); + } +if ($user) { + &clean_language(); + my $out = &backquote_logged("$cmd --op=update --name=node.session.auth.username --value=".quotemeta($user)." 2>&1"); + &reset_environment(); + return $out if ($?); + + &clean_language(); + my $out = &backquote_logged("$cmd --op=update --name=node.session.auth.password --value=".quotemeta($pass)." 2>&1"); + &reset_environment(); + return $out if ($?); + } + +# Connect the session with --login +&clean_language(); +my $out = &backquote_logged("$cmd --login 2>&1"); +&reset_environment(); +return $out if ($?); + +return undef; } # delete_iscsi_connection(&connection) diff --git a/iscsi-client/lang/en b/iscsi-client/lang/en index ba1b3c5ff..02e287ceb 100644 --- a/iscsi-client/lang/en +++ b/iscsi-client/lang/en @@ -135,6 +135,9 @@ add_etarget=No target $1 found add_dev=Connected as $1 add_used=Already connected add_on=$1 on $2 +add_auth=Login to server +add_auth1=Use default authentication method +add_auth0=Login as $2 with password $3 using method $1 dconns_err=Failed to disconnect connections dconns_enone=None selected