Add fields to allow per-session login and password

This commit is contained in:
Jamie Cameron
2012-10-21 17:20:16 -07:00
parent 9020f4253a
commit d46633f769
5 changed files with 58 additions and 6 deletions

View File

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

View File

@@ -41,6 +41,7 @@ print &ui_table_row($text{'conns_port'},
print &ui_table_row($text{'conns_iface'},
$in{'iface'} || "<i>$text{'conns_ifacedef'}</i>");
# Target to mount
print &ui_table_row($text{'add_target'},
&ui_select("target", undef,
[ [ "", "&lt;".$text{'add_alltargets'}."&gt;" ],
@@ -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'}."<br>" ],
[ 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'} ] ]);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

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

View File

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