Commit f6786b4a authored by Nigel Kukard's avatar Nigel Kukard

Merge branch 'admininterfacefixes' into 'master'

Admininterfacefixes

See merge request !12
parents 784dbbb8 589c6390
......@@ -194,15 +194,40 @@ sub loadFile
}
# Open file
if (!open(FH,"< ".$parms->{'file'})) {
if (!open(FH,"<",$parms->{'file'})) {
print($OUT " => Failed to open '".$parms->{'file'}."': $!\n");
return -1;
}
# Process lines
printf($OUT " => Loading file '%s'",$parms->{'file'});
# Grab number of lines to process
my $line_total = 0;
while (<FH>) { $line_total++ }
# Reset back to beginning of file and re-read
seek(<FH>,0,0);
my $line_current = 0;
my $percent_last = "";
while (my $cmdline = <FH>) {
# Nuke \n
# Bump line number
$line_current++;
# Grab percent done
my $percent_done = sprintf('%5.1f',($line_current / $line_total) * 100);
# If its changed, output and save
if ($percent_done ne $perecent_last) {
sprintf($OUT " Progress: %s",$percent_done);
$percent_last = $percent_done;
}
# Nuke whitespaces at end
chomp($cmdline);
# Short circuit blank lines
next if ($cmdline eq "");
# Process
if ((my $res = processCommand($OUT,$cmdline)) < 0) {
print($OUT " => Failed to execute command: $cmdline\n");
......@@ -329,8 +354,13 @@ sub processCommand
# If whitespace only or comment
return 0 if ($cmdline =~ /^\s*$/ || $cmdline =~ /^\s*#/);
# Optimize by removing spaces from beginning and end of line
$cmdline =~ s/^\s+//;
chomp($cmdline);
# Check for special: ..
if ($cmdline =~ /^\s*\.\.$/) {
if ($cmdline eq "..") {
# If we have history, shift it in
if (@cmdHistory > 0) {
$cmdMap = pop(@cmdHistory);
......@@ -343,7 +373,7 @@ sub processCommand
# Check for special: help
} elsif ($cmdline =~ /^\s*help\s*$/i) {
} elsif ($cmdline eq "help") {
print($OUT "Valid commands...\n");
# Loop commands
......@@ -368,7 +398,7 @@ sub processCommand
return 0;
# Check for special: help <command>
} elsif (my ($cmd) = ($cmdline =~ /^\s*help\s*(\S+)\s*$/i)) {
} elsif (my ($cmd) = ($cmdline =~ /^help\s*(\S+)$/i)) {
my $res = 0;
# Loop with commands
foreach my $i (@{$cmdMap->{'Children'}}) {
......@@ -423,7 +453,7 @@ sub processCommand
my $substitution = $i->{'Substitute'} ? defined($i->{'Substitute'}) : "";
(my $fcmd = $cmdline) =~ s/^\s*$i->{'Regex'}\s*/$substitution/i;
print($OUT "Found '".$i->{'Regex'}."', dest '".$fcmd."'\n");
# print($OUT "Found '".$i->{'Regex'}."', dest '".$fcmd."'\n");
# Pull args
my @args = shellwords($fcmd);
......@@ -441,13 +471,14 @@ sub processCommand
}
}
# If no command, give error
if (!defined($res)) {
return 0;
} elsif ($res == 0) {
print($OUT " => Ok!\n");
# print($OUT " => Ok!\n");
} elsif ($res > 0) {
print($OUT " => Ok! (res: $res)\n");
# print($OUT " => Ok! (res: $res)\n");
} elsif ($res == -103) {
print($OUT " => ERROR - Not authorized to access this function\n");
} elsif ($res == -200) {
......@@ -458,6 +489,7 @@ sub processCommand
print($OUT "Usage Error...\n");
print($OUT " ".$matchedCmd->{'Help'}."\n");
} else {
print($OUT " => ERROR - Processing line: $cmdline\n");
print($OUT " => ERROR - Unknown result: $res\n");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment