Skip to content

Commit

Permalink
revised cmd.cgi functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmatifa committed Jun 14, 2017
1 parent af5a35c commit 2298cb4
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 40 deletions.
48 changes: 26 additions & 22 deletions cmd.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,41 @@ if ($in{'cmd'} =~ "setzfs") {
$in{'confirm'} = "yes";
if (($in{'set'} =~ "inherit") && ($config{'zfs_properties'} =~ /1/)) { $cmd = "zfs inherit $in{'property'} $in{'zfs'}";
} elsif ($config{'zfs_properties'} =~ /1/) { $cmd = "zfs set $in{'property'}=$in{'set'} $in{'zfs'}"; }
print ui_cmd("set zfs property $in{'property'} to $in{'set'} in $in{'zfs'}", $cmd);
#print $text{'cmd_setzfs'}." $in{'property'} to $in{'set'} on $in{'zfs'} $text{'cmd_with'}<br /><i>".$cmd."</i>";
ui_cmd("$in{'property'} to $in{'set'} on $in{'zfs'}", $cmd);
}
elsif ($in{'cmd'} =~ "setpool") {
$in{'confirm'} = "yes";
if ($in{'property'} =~ 'comment') { $in{'set'} = '"'.$in{'set'}.'"'; }
my $cmd = ($config{'pool_properties'} =~ /1/) ? "zpool set $in{'property'}=$in{'set'} $in{'pool'}": undef;
print ui_cmd("set pool property $in{'property'} to $in{'set'} in $in{'pool'}", $cmd);
ui_cmd("$in{'property'} to $in{'set'} in $in{'pool'}", $cmd);
}
elsif ($in{'cmd'} =~ "snapshot") {
my $cmd = ($config{'snap_properties'} =~ /1/) ? "zfs snapshot ".$in{'zfs'}."@".$in{'snap'} : undef;
$in{'confirm'} = "yes";
print ui_cmd("create snapshot $in{'snap'}", $cmd);
ui_cmd($in{'snap'}, $cmd);
print "", (!$result[1]) ? ui_list_snapshots($in{'zfs'}."@".$in{'snap'}) : undef;
}
elsif ($in{'cmd'} =~ "send") {
if (!$in{'dest'}) {
print "Please select destination: $in{'snap'}... <br />";
print "Send snapshot: $in{'snap'} to gzip file <br />";
print "<br />";
print ui_form_start('cmd.cgi', 'post');
print ui_hidden('cmd', $in{'cmd'});
print ui_hidden('snap', $in{'snap'});
#my %comp = ('none1', 'gzip', 'bzip');
#print "<b>Compression: </b>".ui_select('comp', 'gzip', [%comp])."</br>";
print "<b>Destination: </b>".ui_filebox('dest', undef, 25, undef, undef, 0)."<br>";
my $newfile = $in{'snap'} =~ s![/@]!_!gr;
print "<b>Destination: </b>".ui_filebox('dest', undef, 35, undef, undef, undef, 1)."<br />";
print "<b>Filename: </b>".ui_textbox('file', $newfile.'.gz', 50)."<br />";
print ui_submit("Continue", undef, undef);
print ui_form_end();
} else {
$in{'confirm'} = "yes";
my $cmd = ($config{'snap_properties'} =~ /1/) ? "zfs send ".$in{'snap'}." | gzip > ".$in{'dest'} : undef;
print ui_cmd("send snapshot $in{'snap'}", $cmd);
my $cmd = ($config{'snap_properties'} =~ /1/) ? "zfs send ".$in{'snap'}." | gzip > ".$in{'dest'}."/".$in{'file'} : undef;
ui_cmd($in{'snap'}, $cmd);
#print "<br />";
print `ls -al $in{'dest'}'."/".$in{'file'}`;
}
}
elsif ($in{'cmd'} =~ "createzfs") {
Expand All @@ -70,7 +75,7 @@ elsif ($in{'cmd'} =~ "createzfs") {
#else { $in{'zfs'} = $in{'parent'}."/".$in{'zfs'}; }
my $cmd = (($in{'parent'}) && ($config{'zfs_properties'} =~ /1/)) ? cmd_create_zfs($in{'parent'}."/".$in{'zfs'}, \%options) : undef;
$in{'confirm'} = "yes";
print ui_cmd("create filesystem $in{'parent'}/$in{'zfs'}", $cmd);
ui_cmd("$in{'parent'}/$in{'zfs'}", $cmd);
#print "", (!$result[1]) ? ui_zfs_list($in{'zfs'}) : undef;
#^^^this doesn't work for some reason
@footer = ("status.cgi?zfs=".$in{'parent'}, $in{'parent'});
Expand All @@ -88,7 +93,7 @@ elsif ($in{'cmd'} =~ "clone") {
if ($in{'mountpoint'}) { $opts .= ' -o mountpoint='.$in{'mountpoint'}; }
$in{'confirm'} = "yes";
my $cmd = ($config{'zfs_properties'} =~ /1/) ? "zfs clone ".$in{'clone'}." ".$in{'parent'}.'/'.$in{'zfs'}." ".$opts : undef;
print ui_cmd("clone ".$in{'clone'}, $cmd);
ui_cmd($in{'clone'}, $cmd);
@footer = ("status.cgi?snap=".$in{'clone'}, $in{'clone'})
#$in{'snap'} = $in{'clone'};
}
Expand All @@ -110,7 +115,7 @@ elsif ($in{'cmd'} =~ "rename") {
#$in{'parent'} = undef;
$cmd = ($config{'zfs_properties'} =~ /1/) ? "zfs rename ".$in{'force'}.$in{'prnt'}.$in{'zfs'}." ".$in{'parent'}.'/'.$in{'name'} : undef;
}
print ui_cmd("rename ".$in{'zfs'}." to ".$in{'name'}, $cmd);
ui_cmd($in{'zfs'}." to ".$in{'name'}, $cmd);
}
elsif ($in{'cmd'} =~ "createzpool") {
#if ($in{'add'}) { redirect('create.cgi?srl='.serialise_variable(%in)); }
Expand All @@ -132,48 +137,48 @@ elsif ($in{'cmd'} =~ "createzpool") {
%poolopts = ( 'version' => $in{'version'} );
my $cmd = (($config{'pool_properties'} =~ /1/)) ? cmd_create_zpool($in{'pool'}, $in{'vdev'}.$in{'devs'}, \%options, \%poolopts, $in{'force'}) : undef;
$in{'confirm'} = "yes";
print ui_cmd("create pool $in{'pool'}", $cmd);
ui_cmd($in{'pool'}, $cmd);
#print "", (!$result[1]) ? ui_zfs_list($in{'zfs'}) : undef;
#^^^this doesn't work for some reason
}
elsif ($in{'cmd'} =~ "vdev") {
$in{'confirm'} = "yes";
my $cmd = ($config{'pool_properties'} =~ /1/) ? "zpool $in{'action'} $in{'pool'} $in{'vdev'}": undef;
print ui_cmd("$in{'action'} $in{'vdev'}", $cmd);
ui_cmd("$in{'action'} $in{'vdev'}", $cmd);
}
elsif ($in{'cmd'} =~ "promote") {
my $cmd = ($config{'zfs_properties'} =~ /1/) ? "zfs promote $in{'zfs'}": undef;
print ui_cmd("promote $in{'zfs'}", $cmd);
ui_cmd($in{'zfs'}, $cmd);
}
elsif ($in{'cmd'} =~ "scrub") {
$in{'confirm'} = "yes";
if ($in{'stop'}) { $in{'stop'} = "-s"; }
my $cmd = ($config{'pool_properties'} =~ /1/) ? "zpool scrub $in{'stop'} $in{'pool'}" : undef;
print ui_cmd("scrub pool $in{'pool'}", $cmd);
ui_cmd($in{'pool'}, $cmd);
}
elsif ($in{'cmd'} =~ "upgrade") {
print "<p>".$text{'zpool_upgrade_msg'}."</p>";
#$in{'confirm'} = "yes";
my $cmd = ($config{'pool_properties'} =~ /1/) ? "zpool upgrade $in{'pool'}" : undef;
print ui_cmd("upgrade pool $in{'pool'}", $cmd);
ui_cmd($in{'pool'}, $cmd);
}
elsif ($in{'cmd'} =~ "export") {
#$in{'confirm'} = "yes";
my $cmd = ($config{'pool_properties'} =~ /1/) ? "zpool export $in{'pool'}" : undef;
print ui_cmd("scrub pool $in{'pool'}", $cmd);
ui_cmd($in{'pool'}, $cmd);
@footer = ("index.cgi?mode=pools", $text{'index_return'});
}
elsif ($in{'cmd'} =~ "import") {
my $dir = ();
if ($in{'dir'}) { $dir .= " -d ".$in{'dir'}; }
if ($in{'destroyed'}) { $dir .= " -D -f "; }
my $cmd = ($config{'pool_properties'} =~ /1/ ) ? "zpool import".$dir." ".$in{'import'}: undef;
print ui_cmd("import pool $in{'import'}", $cmd);
ui_cmd($in{'import'}, $cmd);
@footer = ("index.cgi?mode=pools", $text{'index_return'});
}
elsif ($in{'cmd'} =~ "zfsact") {
my $cmd = ($config{'zfs_properties'} =~ /1/) ? "zfs $in{'action'} $in{'zfs'}" : undef;
print ui_cmd("$in{'action'} $in{'zfs'}", $cmd);
ui_cmd("$in{'action'} $in{'zfs'}", $cmd);
}
elsif ($in{'cmd'} =~ "zfsdestroy") {
my $cmd = ($config{'zfs_destroy'} =~ /1/) ? "zfs destroy $in{'force'} $in{'zfs'}" : undef;
Expand All @@ -195,9 +200,8 @@ elsif ($in{'cmd'} =~ "zfsdestroy") {
print "<br /><br />";
print ui_submit("Continue", undef, undef);
print ui_form_end();
#print ui_cmd("destroy $in{'zfs'}", $cmd);
} else {
print ui_cmd("destroy $in{'zfs'}", $cmd);
ui_cmd($in{'zfs'}, $cmd);
}
@footer = ("index.cgi?mode=zfs", $text{'zfs_return'});
}
Expand All @@ -221,7 +225,7 @@ elsif ($in{'cmd'} =~ "snpdestroy") {
print ui_form_end();

} else {
print ui_cmd("destroy $in{'snapshot'}", $cmd);
ui_cmd($in{'snapshot'}, $cmd);
}
print ui_form_end();
@footer = ("index.cgi?mode=snapshot", $text{'snapshot_return'});
Expand All @@ -248,7 +252,7 @@ my $cmd = ($config{'pool_destroy'} =~ /1/) ? "zpool destroy $in{'pool'}" : undef
print "<br /><br />";
print ui_submit("Continue", undef, undef);
} else {
print ui_cmd("destroy $in{'pool'}", $cmd);
ui_cmd($in{'pool'}, $cmd);
}
@footer = ("index.cgi?mode=pools", $text{'index_return'});
}
Expand Down
2 changes: 1 addition & 1 deletion create.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ if ($in{'create'} =~ "zpool")
print ui_table_start("Import Zpool", 'width=100%');
print ui_form_start("create.cgi", "post");
print ui_hidden('import', '1');
print ui_table_row(undef, "Import search directory (blank for default):".ui_filebox('dir', $in{'dir'}, 25, undef, undef, 1));
print ui_table_row(undef, "Import search directory (blank for default):".ui_filebox('dir', $in{'dir'}, 25, undef, undef, undef, 1));
print ui_table_row(undef, ui_checkbox('destroyed', '-D', 'Search for destroyed pools', undef ));
#print "<br />";
print ui_table_row(undef, ui_submit('Search'));
Expand Down
22 changes: 21 additions & 1 deletion lang/en
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
index_title=ZFS Manager
index_root=The root directory is $1.
index_version=testing alpha 0.0.5a
index_version=testing alpha 0.0.6
index_return=pool list
snapshot_return=snapshot list
zfs_return=file system list
Expand All @@ -13,6 +13,26 @@ select_title=Select a device for new vdev
diff_title=Snapshot Differences

cmd_title=Issuing Command
cmd_with=with command...
cmd_setzfs=Attempting to set zfs property
cmd_setpool=Attempting to set pool property
cmd_snapshot=Attempting to create snapshot
cmd_send=Attempting to send snapshot
cmd_createzfs=Attempting to create filesystem
cmd_clone=Attempting to clone
cmd_rename=Attempting to rename
cmd_createzpool=Attempting to create pool
cmd_vdev=Attempting to
cmd_promote=Attempting to promote
cmd_scrub=Attempting to scrub pool
cmd_upgrade=Attempting to upgrade pool
cmd_export=Attempting to export pool
cmd_import=Attempting to import pool
cmd_zfsact=Attempting to
cmd_zfsdestroy=Attempting to destroy filesystem
cmd_snpdestroy=Attempting to destroy snapshot
cmd_pooldestroy=Attempting to destroy pool
cmd_multisnap=Attempting to destroy multiple snapshots...

snapshot_title=Snapshot
snapshot_create=Create Snapshot
Expand Down
61 changes: 45 additions & 16 deletions zfsmanager-lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -510,39 +510,68 @@ sub ui_create_snapshot

sub ui_cmd
{
#my ($message, @result) = @_;
my ($message, $cmd) = @_;
$rv = "Attempting to $message with command... <br />\n";
$rv .= "<i># ".$cmd."</i><br /><br />\n";
print "$text{'cmd_'.$in{'cmd'}} $message $text{'cmd_with'}<br />\n";
print "<i># ".$cmd."</i><br /><br />\n";
if (!$in{'confirm'}) {
$rv .= ui_form_start('cmd.cgi', 'post');
print ui_form_start('cmd.cgi', 'post');
foreach $key (keys %in) {
$rv .= ui_hidden($key, $in{$key});
print ui_hidden($key, $in{$key});
}
$rv .= "<h3>Would you lke to continue?</h3>\n";
$rv .= ui_submit("yes", "confirm", 0)."<br />";
#$rv .= ui_submit("yes", "confirm", 0, "style='background-color: transparent;border: none;color: blue;cursor: pointer;'")." | <a href='status.cgi?zfs=".$in{'zfs'}."'>no</a>";
$rv .= ui_form_end();
#$rv .= "confirm=".$confirm."</br>";
print "<h3>Would you lke to continue?</h3>\n";
print ui_submit("yes", "confirm", 0)."<br />";
print ui_form_end();
} else {
@result = (`$cmd 2>&1`);
if (!$result[0])
{
#$rv .= $result[1]."<br />\n";
$rv .= "Success! <br />\n";
print "Success! <br />\n";
} else {
#$result[1] =~ s/\R/ /g;
$rv .= "<b>error: </b>".$result[0]."<br />\n";
print "<b>error: </b>".$result[0]."<br />\n";
foreach $key (@result[1..@result]) {
$rv .= $key."<br />\n";
print $key."<br />\n";
}
#print Dumper(@result);
}
}
print "<br />";
}

sub ui_cmd_old
{
my ($message, $cmd) = @_;
$rv = "Attempting to $message with command... <br />\n";
$rv .= "<i># ".$cmd."</i><br /><br />\n";
if (!$in{'confirm'}) {
$rv .= ui_form_start('cmd.cgi', 'post');
foreach $key (keys %in) {
$rv .= ui_hidden($key, $in{$key});
}
$rv .= "<h3>Would you lke to continue?</h3>\n";
$rv .= ui_submit("yes", "confirm", 0)."<br />";
#$rv .= ui_submit("yes", "confirm", 0, "style='background-color: transparent;border: none;color: blue;cursor: pointer;'")." |$
$rv .= ui_form_end();
#$rv .= "confirm=".$confirm."</br>";
} else {
@result = (`$cmd 2>&1`);
if (!$result[0])
{
#$rv .= $result[1]."<br />\n";
$rv .= "Success! <br />\n";
} else {
#$result[1] =~ s/\R/ /g;
$rv .= "<b>error: </b>".$result[0]."<br />\n";
foreach $key (@result[1..@result]) {
$rv .= $key."<br />\n";
}
#print Dumper(@result);
}
}

return $rv;
}



sub ui_popup_link
#deprecated
{
Expand Down

0 comments on commit 2298cb4

Please sign in to comment.