---- 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.
$cmd{'order'} = int($cmd{'order'});
chop($cmd{'usermin'} = <FILE>);
chop($cmd{'envs'} = <FILE>);
+ chop($cmd{'beforeedit'} = <FILE>);
}
elsif ($f =~ /^(\d+)\.sql$/) {
# Read SQL file
&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
$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"),
--- /dev/null
+<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>
+
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
# 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
# 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);
$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'});
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'}, "");