Command to run before editing a file

This commit is contained in:
Jamie Cameron
2011-08-12 22:03:30 -07:00
parent 18fe6b417e
commit ffb007bea0
8 changed files with 24 additions and 2 deletions

View File

@@ -35,3 +35,5 @@ Added an option for custom commands to have their output displayed without any W
---- Changes since 1.550 ----
A default value for each custom command parameter can now be entered on the Edit Command form. Defaults can also be read from a file or shell command, if this behavior is enabled on the Module Config page. Thanks to Sart Cole for suggesting this feature.
A command can now be configured to not display any output at all, and instead return to the module index after being run.
---- Changes since 1.560 ----
Added an option to the file editor to run a command before the file is displayed, thanks to a suggestion from Sart Cole.

View File

@@ -50,6 +50,7 @@ while($f = readdir(DIR)) {
$cmd{'order'} = int($cmd{'order'});
chop($cmd{'usermin'} = <FILE>);
chop($cmd{'envs'} = <FILE>);
chop($cmd{'beforeedit'} = <FILE>);
}
elsif ($f =~ /^(\d+)\.sql$/) {
# Read SQL file
@@ -150,6 +151,7 @@ if ($c->{'edit'}) {
&print_tempfile(FILE, $c->{'order'},"\n");
&print_tempfile(FILE, $c->{'usermin'},"\n");
&print_tempfile(FILE, $c->{'envs'},"\n");
&print_tempfile(FILE, $c->{'beforeedit'},"\n");
}
elsif ($c->{'sql'}) {
# Save an SQL command

View File

@@ -53,6 +53,8 @@ print &ui_table_row(&hlink($text{'file_perms'}, "perms"),
$text{'file_set'}));
# Commands to run before and after
print &ui_table_row(&hlink($text{'file_beforeedit'}, "beforeedit"),
&ui_textbox("beforeedit", $edit->{'beforeedit'}, 60));
print &ui_table_row(&hlink($text{'file_before'}, "before"),
&ui_textbox("before", $edit->{'before'}, 60));
print &ui_table_row(&hlink($text{'file_after'}, "after"),

View File

@@ -0,0 +1,9 @@
<header>Command to run before editing</header>
Whatever command is entered here will be run as <tt>root</tt> before
the contents of the file are displayed for editing. This could be used for
example to copy the file in from another system, and the <b>Command to run
after saving</b> could be used to copy it back. <p>
<hr>

View File

@@ -115,6 +115,7 @@ file_group=Group
file_leave=Leave as is
file_perms=File permissions
file_set=Set to octal
file_beforeedit=Command to run before editing
file_before=Command to run before saving
file_after=Command to run after saving
file_err=Failed to save file editor

View File

@@ -26,7 +26,7 @@ if ($edit->{'envs'} || @{$edit->{'args'}}) {
# Run the before-command
if ($edit->{'before'}) {
&system_logged("$edit->{'before'} >/dev/null 2>&1 </dev/null");
&system_logged("($edit->{'before'}) >/dev/null 2>&1 </dev/null");
}
# Save the file
@@ -48,7 +48,7 @@ if ($edit->{'perms'}) {
# Run the after-command
if ($edit->{'after'}) {
&system_logged("$edit->{'after'} >/dev/null 2>&1 </dev/null");
&system_logged("($edit->{'after'}) >/dev/null 2>&1 </dev/null");
}
&webmin_log("save", "edit", $cmd->{'id'}, $edit);

View File

@@ -48,6 +48,7 @@ else {
$in{'perms'} =~ /^[0-7]{3}$/ || &error($text{'file_eperms'});
$edit->{'perms'} = $in{'perms'};
}
$edit->{'beforeedit'} = $in{'beforeedit'};
$edit->{'before'} = $in{'before'};
$edit->{'after'} = $in{'after'};
$edit->{'order'} = $in{'order_def'} ? 0 : int($in{'order'});

View File

@@ -24,6 +24,11 @@ if ($edit->{'envs'} || @{$edit->{'args'}}) {
chop($file = `echo "$file"`);
}
# Run any before-edit command
if ($edit->{'beforeedit'}) {
&system_logged("($edit->{'beforeedit'}) >/dev/null 2>&1 </dev/null");
}
# Show the editor form
&ui_print_header(undef, $text{'view_title'}, "");