[ Avaa Bypassed ]




Upload:

Command:

www-data@18.224.202.121: ~ $
# Functions for editing the Open-iSCSI configuration file

BEGIN { push(@INC, ".."); };
use strict;
use warnings;
no warnings 'redefine';
no warnings 'uninitialized';
use WebminCore;
&init_config();
&foreign_require("fdisk");
&foreign_require("mount");
&foreign_require("lvm");
our (%text, %config, %gconfig, $module_config_file);

# check_config()
# Returns undef if the Open-iSCSI client is installed, or an error message if
# missing
sub check_config
{
return &text('check_econfig', "<tt>$config{'config_file'}</tt>")
	if (!-r $config{'config_file'});
return &text('check_eisciadm', "<tt>$config{'iscsiadm'}</tt>")
	if (!&has_command($config{'iscsiadm'}));
return undef;
}

# get_iscsi_config()
# Parses the iscsi client config file into an array ref of directives
sub get_iscsi_config
{
my @rv;
my $fh = "CONFIG";
my $lnum = 0;
&open_readfile($fh, $config{'config_file'}) || return [ ];
while(<$fh>) {
        s/\r|\n//g;
        s/#.*$//;
	if (/^(\S+)\s*=\s*(.*)/) {
		my $dir = { 'name' => $1,
			    'value' => $2,
			    'line' => $lnum };
		push(@rv, $dir);
		}
	$lnum++;
	}
close($fh);
return \@rv;
}

# find(&config, name)
# Returns all config objects with the given name
sub find
{
my ($conf, $name) = @_;
my @t = grep { $_->{'name'} eq $name } @$conf;
return wantarray ? @t : $t[0];
}

# find_value(&config, name)
# Returns all config values with the given name
sub find_value
{
my ($conf, $name) = @_;
my @rv = map { $_->{'value'} } &find($conf, $name);
return wantarray ? @rv : $rv[0];
}

# save_directive(&config, name, value)
# Creates, updates or deletes some directive
sub save_directive
{
my ($conf, $name, $value) = @_;
my $lref = &read_file_lines($config{'config_file'});
my $line = defined($value) ? $name." = ".$value : undef;
my $o = &find($conf, $name);
if ($o && defined($value)) {
	# Update a line
	$lref->[$o->{'line'}] = $line;
	$o->{'value'} = $value;
	}
elsif ($o && !defined($value)) {
	# Commenting out a line
	$lref->[$o->{'line'}] = "# ".$lref->[$o->{'line'}];
	}
elsif (!$o && defined($value)) {
	# Check if exists, but commented out
	my $cline;
	my $clnum = 0;
	foreach my $l (@$lref) {
		if ($l =~ /^#+\s*\Q$name\E\s*=/) {
			$cline = $clnum;
			last;
			}
		$clnum++;
		}
	my $dir = { 'name' => $name,
		    'value' => $value };
	if (defined($cline)) {
		# Comment back in
		$dir->{'line'} = $cline;
		$lref->[$cline] = $line;
		}
	else {
		# Add at end
		$dir->{'line'} = scalar(@$lref);
		push(@$lref, $line);
		}
	push(@$conf, $dir);
	}
}

# list_iscsi_connections()
# Returns a list of hash refs with details of active sessions
sub list_iscsi_connections
{
my @rv;
&clean_language();
my $out = &backquote_command(
		"$config{'iscsiadm'} -m session -o show -P 3 -S 2>/dev/null");
&reset_environment();
my @lines = split(/\r?\n/, $out);
if ($?/256 == 21) {
	# Code 21 means no sessions
	return [ ];
	}
if ($?) {
	return $lines[0];
	}
my $conn;
foreach my $l (@lines) {
	if ($l =~ /^Target:\s+(\S+):(\S+)/) {
		$conn = { 'name' => $1,
			  'target' => $2 };
		push(@rv, $conn);
		}
	elsif ($l =~ /Current\s+Portal:\s+(\S+):(\d+)/) {
		$conn->{'ip'} = $1;
		$conn->{'port'} = $2;
		}
	elsif ($l =~ /SID:\s+(\d+)/) {
		$conn->{'num'} = $1;
		}
	elsif ($l =~ /Iface\s+Name:\s+(\S+)/) {
		$conn->{'iface'} = $1;
		}
	elsif ($l =~ /Iface\s+Transport:\s+(\S+)/) {
		$conn->{'proto'} = $1;
		}
	elsif ($l =~ /Iface\s+Initiatorname:\s+(\S+)/) {
		$conn->{'initiator'} = $1;
		}
	elsif ($l =~ /iSCSI\s+Connection\s+State:\s+(\S+)/) {
		$conn->{'connection'} = $1;
		}
	elsif ($l =~ /iSCSI\s+Session\s+State:\s+(\S+)/) {
		$conn->{'session'} = $1;
		}
	elsif ($l =~ /scsi(\d+)\s+Channel\s+(\d+)\s+Id\s+(\d+)\s+Lun:\s+(\d+)/) {
		$conn->{'scsihost'} = $1;
		$conn->{'scsichannel'} = $2;
		$conn->{'scsiid'} = $3;
		$conn->{'scsilun'} = $4;
		}
	elsif ($l =~ /Attached\s+scsi\s+disk\s+(\S+)/) {
		$conn->{'device'} = "/dev/$1";
		}
	elsif ($l =~ /(username|password|username_in|password_in):\s+(\S+)/ &&
	       $2 ne "<empty>") {
		$conn->{$1} = $2;
		}
	}
foreach my $c (@rv) {
	my $dev = "/dev/disk/by-path/ip-$c->{'ip'}:$c->{'port'}-".
		  "iscsi-$c->{'name'}:$c->{'target'}-lun-$c->{'scsilun'}";
	if (-e $dev) {
		$c->{'longdevice'} = $dev;
		}
	}
return \@rv;
}

# list_iscsi_targets(host, [port], [iface])
# Returns an array ref listing available targets on some host, or an error 
# message string
sub list_iscsi_targets
{
my ($host, $port, $iface) = @_;
my $cmd = "$config{'iscsiadm'} -m discovery -t sendtargets -p ".
	  quotemeta($host).($port ? ":".quotemeta($port) : "").
	  ($iface ? " -I ".quotemeta($iface) : "");
&clean_language();
my $out = &backquote_command("$cmd 2>&1");
&reset_environment();
my @lines = split(/\r?\n/, $out);
if ($? || $out =~ /Could not perform SendTargets discovery/i) {
	return $lines[0];
	}
my @rv;
foreach my $l (@lines) {
	if ($l =~ /^(\S+):(\d+),([0-9\-]+)\s+(\S+):(\S+)/) {
		push(@rv, { 'ip' => $1,
			    'port' => $2,
			    'name' => $4,
			    'target' => $5 });
		}
	}
return \@rv;
}

# 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, $method, $user, $pass) = @_;

# Re-discover targets, so that this function works when called remotely
&list_iscsi_targets($host, $port, $iface);

my $cmd = "$config{'iscsiadm'} -m node".
	  ($target ? " -T ".quotemeta($target->{'name'}).":".
			    quotemeta($target->{'target'}) : "").
	  " -p ".quotemeta($host).($port ? ":".quotemeta($port) : "").
	  ($iface ? " -I ".quotemeta($iface) : "");

# Create the session
&clean_language();
my $out = &backquote_logged("$cmd 2>&1");
&reset_environment();
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();
	$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();
$out = &backquote_logged("$cmd --login 2>&1");
&reset_environment();
return $out if ($?);

return undef;
}

# delete_iscsi_connection(&connection)
# Remove an existing connection to some target
sub delete_iscsi_connection
{
my ($conn) = @_;
my $cmd = "$config{'iscsiadm'} -m node".
	  " -T ".quotemeta($conn->{'name'}).":".quotemeta($conn->{'target'}).
	  " -p ".quotemeta($conn->{'ip'}).":".quotemeta($conn->{'port'}).
	  " --logout";
&clean_language();
my $out = &backquote_logged("$cmd 2>&1");
&reset_environment();
return $? ? $out : undef;
}

# get_connection_users(&conn, [include-unused])
# Returns a list of partitions in the device for some connection, and their
# users (like raid, mount, lvm)
sub get_connection_users
{
my ($conn, $unused) = @_;
return ( ) if (!$conn->{'device'});
my @users;
my @disks = &fdisk::list_disks_partitions();
my ($disk) = grep { $_->{'device'} eq $conn->{'device'} } @disks;
next if (!$disk);
foreach my $part (@{$disk->{'parts'}}) {
	my @st = &fdisk::device_status($part->{'device'});
	if (@st || $unused) {
		push(@users, [ $conn, $part, @st ]);
		}
	}
return @users;
}

# get_initiator_name()
# Returns the local iSCSI initiator name
sub get_initiator_name
{
my $data = &read_file_contents($config{'initiator_file'});
return $data =~ /InitiatorName=(\S+)/ ? $1 : undef;
}

# save_initiator_name(name)
# Writes out the initiator name file
sub save_initiator_name
{
my ($name) = @_;
my $fh = "INIT";
&open_tempfile($fh, ">$config{'initiator_file'}");
&print_tempfile($fh, "InitiatorName=$name\n");
&close_tempfile($fh);
}

# generate_initiator_name()
# Create a new initiator name with the iscsi-iname command
sub generate_initiator_name
{
my $out = &backquote_command("$config{'iscsiiname'} 2>/dev/null");
$out =~ s/\r?\n//;
return $out;
}

# list_iscsi_ifaces()
# Returns an array ref of details of all existing interfaces
sub list_iscsi_ifaces
{
&clean_language();
my $errtemp = &transname();
my $out = &backquote_command(
		"$config{'iscsiadm'} -m iface -o show -P 1 2>$errtemp");
&reset_environment();
my @lines = split(/\r?\n/, $out);
my $err = &read_file_contents($errtemp);
if ($?) {
	return "Interfaces are not supported by this OpenISCSI version"
		if ($err =~ /Invalid\s+info\s+level/);
	return $err || $lines[0];
	}
my @rv;
my ($iface, $target);
foreach my $l (@lines) {
	if ($l =~ /^Iface:\s+(\S+)/) {
		$iface = { 'name' => $1,
			   'builtin' => ($1 eq "default" || $1 eq "iser"),
			   'targets' => [ ] };
		push(@rv, $iface);
		}
	elsif ($l =~ /Target:\s+(\S+):(\S+)/) {
		$target = { 'name' => $1,
			    'target' => $2 };
		push(@{$iface->{'targets'}}, $target);
		}
	elsif ($l =~ /Portal:\s+(\S+):(\d+)/) {
		$target->{'ip'} = $1;
		$target->{'port'} = $2;
		}
	}
# Fetch more info for each interface
foreach my $iface (@rv) {
	&clean_language();
	my $out = &backquote_command(
		"$config{'iscsiadm'} -m iface -I $iface->{'name'} 2>/dev/null");
	&reset_environment();
	foreach my $il (split(/\r?\n/, $out)) {
		if ($il !~ /^#/ && $il =~ /^(iface.\S+)\s*=\s*(\S+)/) {
			$iface->{$1} = $2 eq "<empty>" ? undef : $2;
			}
		}
	}
return \@rv;
}

# create_iscsi_interface(&iface)
# Create a new interface from the given hash
sub create_iscsi_interface
{
my ($iface) = @_;

# Create the initial interface
my $cmd = "$config{'iscsiadm'} -m iface -o new".
	  " -I ".quotemeta($iface->{'name'});
&clean_language();
my $out = &backquote_logged("$cmd 2>&1");
&reset_environment();
return $out if ($?);

# Apply various params
foreach my $k (grep { /^iface\./ } keys %$iface) {
	my $cmd = "$config{'iscsiadm'} -m iface -o update".
          " -I ".quotemeta($iface->{'name'}).
	  " -n ".quotemeta($k)." -v ".quotemeta($iface->{$k});
	&clean_language();
	my $out = &backquote_logged("$cmd 2>&1");
	&reset_environment();
	return "Failed to set $k : $out" if ($?);
	}

return undef;
}

# delete_iscsi_iface(&iface)
# Delete one iSCSI interface
sub delete_iscsi_iface
{
my ($iface) = @_;
my $cmd = "$config{'iscsiadm'} -m iface -o delete".
	  " -I ".quotemeta($iface->{'name'});
&clean_language();
my $out = &backquote_logged("$cmd 2>&1");
&reset_environment();
return $? ? $out : undef;
}

1;

Filemanager

Name Type Size Permission Actions
help Folder 0755
images Folder 0755
lang Folder 0755
CHANGELOG File 108 B 0644
add_conn.cgi File 1.15 KB 0755
add_form.cgi File 2.39 KB 0755
add_iface.cgi File 1.18 KB 0755
atboot.cgi File 671 B 0755
backup_config.pl File 646 B 0755
config File 190 B 0644
config-debian-linux File 176 B 0644
config-gentoo-linux File 155 B 0644
config-openSUSE-Linux-15.0-ALL File 184 B 0644
config-suse-linux File 184 B 0644
config.info File 280 B 0644
config.info.ca File 335 B 0644
config.info.de File 299 B 0644
config.info.fr File 350 B 0644
config.info.no File 292 B 0644
delete_conns.cgi File 2.26 KB 0755
delete_ifaces.cgi File 1.96 KB 0755
edit_auth.cgi File 3.21 KB 0755
edit_iscsi.cgi File 1.2 KB 0755
edit_timeout.cgi File 1.57 KB 0755
index.cgi File 1.43 KB 0755
install_check.pl File 348 B 0755
iscsi-client-lib.pl File 10.28 KB 0644
list_conns.cgi File 2.07 KB 0755
list_ifaces.cgi File 2.45 KB 0755
log_parser.pl File 749 B 0755
module.info File 173 B 0644
module.info.af File 0 B 0644
module.info.af.auto File 115 B 0644
module.info.ar File 0 B 0644
module.info.ar.auto File 138 B 0644
module.info.be File 0 B 0644
module.info.be.auto File 162 B 0644
module.info.bg File 0 B 0644
module.info.bg.auto File 160 B 0644
module.info.ca File 118 B 0644
module.info.cs File 0 B 0644
module.info.cs.auto File 111 B 0644
module.info.da File 0 B 0644
module.info.da.auto File 118 B 0644
module.info.de File 112 B 0644
module.info.el File 0 B 0644
module.info.el.auto File 198 B 0644
module.info.es File 0 B 0644
module.info.es.auto File 116 B 0644
module.info.eu File 0 B 0644
module.info.eu.auto File 90 B 0644
module.info.fa File 0 B 0644
module.info.fa.auto File 146 B 0644
module.info.fi File 0 B 0644
module.info.fi.auto File 96 B 0644
module.info.fr File 0 B 0644
module.info.fr.auto File 117 B 0644
module.info.he File 0 B 0644
module.info.he.auto File 127 B 0644
module.info.hr File 0 B 0644
module.info.hr.auto File 106 B 0644
module.info.hu File 0 B 0644
module.info.hu.auto File 127 B 0644
module.info.it File 0 B 0644
module.info.it.auto File 112 B 0644
module.info.ja File 0 B 0644
module.info.ja.auto File 158 B 0644
module.info.ko File 0 B 0644
module.info.ko.auto File 139 B 0644
module.info.lt File 0 B 0644
module.info.lt.auto File 115 B 0644
module.info.lv File 0 B 0644
module.info.lv.auto File 107 B 0644
module.info.ms File 104 B 0644
module.info.mt File 0 B 0644
module.info.mt.auto File 104 B 0644
module.info.nl File 0 B 0644
module.info.nl.auto File 119 B 0644
module.info.no File 110 B 0644
module.info.pl File 0 B 0644
module.info.pl.auto File 110 B 0644
module.info.pt File 0 B 0644
module.info.pt.auto File 99 B 0644
module.info.pt_BR File 0 B 0644
module.info.pt_BR.auto File 105 B 0644
module.info.ro File 0 B 0644
module.info.ro.auto File 103 B 0644
module.info.ru File 0 B 0644
module.info.ru.auto File 167 B 0644
module.info.sk File 0 B 0644
module.info.sk.auto File 99 B 0644
module.info.sl File 0 B 0644
module.info.sl.auto File 95 B 0644
module.info.sv File 0 B 0644
module.info.sv.auto File 103 B 0644
module.info.th File 0 B 0644
module.info.th.auto File 208 B 0644
module.info.tr File 0 B 0644
module.info.tr.auto File 105 B 0644
module.info.uk File 0 B 0644
module.info.uk.auto File 170 B 0644
module.info.ur File 0 B 0644
module.info.ur.auto File 182 B 0644
module.info.vi File 0 B 0644
module.info.vi.auto File 113 B 0644
module.info.zh File 0 B 0644
module.info.zh.auto File 86 B 0644
module.info.zh_TW File 0 B 0644
module.info.zh_TW.auto File 92 B 0644
save_auth.cgi File 3.09 KB 0755
save_iscsi.cgi File 1.11 KB 0755
save_timeout.cgi File 1.26 KB 0755
view_conn.cgi File 2.56 KB 0755