From ffb007bea07142884007aab5327eb2c19f92ef2f Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Fri, 12 Aug 2011 22:03:30 -0700 Subject: [PATCH] Command to run before editing a file --- custom/CHANGELOG | 2 ++ custom/custom-lib.pl | 2 ++ custom/edit_file.cgi | 2 ++ custom/help/beforeedit.html | 9 +++++++++ custom/lang/en | 1 + custom/save.cgi | 4 ++-- custom/save_file.cgi | 1 + custom/view.cgi | 5 +++++ 8 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 custom/help/beforeedit.html diff --git a/custom/CHANGELOG b/custom/CHANGELOG index a96f7d379..0e3a68786 100644 --- a/custom/CHANGELOG +++ b/custom/CHANGELOG @@ -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. diff --git a/custom/custom-lib.pl b/custom/custom-lib.pl index 90c16641a..07c86f9e4 100755 --- a/custom/custom-lib.pl +++ b/custom/custom-lib.pl @@ -50,6 +50,7 @@ while($f = readdir(DIR)) { $cmd{'order'} = int($cmd{'order'}); chop($cmd{'usermin'} = ); chop($cmd{'envs'} = ); + chop($cmd{'beforeedit'} = ); } 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 diff --git a/custom/edit_file.cgi b/custom/edit_file.cgi index a829d6df4..80b5fb54b 100755 --- a/custom/edit_file.cgi +++ b/custom/edit_file.cgi @@ -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"), diff --git a/custom/help/beforeedit.html b/custom/help/beforeedit.html new file mode 100644 index 000000000..135df8046 --- /dev/null +++ b/custom/help/beforeedit.html @@ -0,0 +1,9 @@ +
Command to run before editing
+ +Whatever command is entered here will be run as root 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 Command to run +after saving could be used to copy it back.

+ +


+ diff --git a/custom/lang/en b/custom/lang/en index 20f4a097a..d7b29a483 100644 --- a/custom/lang/en +++ b/custom/lang/en @@ -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 diff --git a/custom/save.cgi b/custom/save.cgi index c3a4f9d69..b7c38cbaa 100755 --- a/custom/save.cgi +++ b/custom/save.cgi @@ -26,7 +26,7 @@ if ($edit->{'envs'} || @{$edit->{'args'}}) { # Run the before-command if ($edit->{'before'}) { - &system_logged("$edit->{'before'} >/dev/null 2>&1 {'before'}) >/dev/null 2>&1 {'perms'}) { # Run the after-command if ($edit->{'after'}) { - &system_logged("$edit->{'after'} >/dev/null 2>&1 {'after'}) >/dev/null 2>&1 {'id'}, $edit); diff --git a/custom/save_file.cgi b/custom/save_file.cgi index 428edb644..cd668c2ae 100755 --- a/custom/save_file.cgi +++ b/custom/save_file.cgi @@ -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'}); diff --git a/custom/view.cgi b/custom/view.cgi index b7330a523..5b7c063f8 100755 --- a/custom/view.cgi +++ b/custom/view.cgi @@ -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