aboutsummaryrefslogtreecommitdiffstats
path: root/config/shellcmd
diff options
context:
space:
mode:
authordoktornotor <notordoktor@gmail.com>2015-08-22 22:48:59 +0200
committerdoktornotor <notordoktor@gmail.com>2015-08-22 22:48:59 +0200
commit4424d5f6afb3319c50def0262427c7030cb94ab1 (patch)
tree4de966c3fc1bbeb8d3dec67c38c90f6da83fe5fa /config/shellcmd
parent3de8cde76a4e55ea867049ef699b0cb5811b5300 (diff)
downloadpfsense-packages-4424d5f6afb3319c50def0262427c7030cb94ab1.tar.gz
pfsense-packages-4424d5f6afb3319c50def0262427c7030cb94ab1.tar.bz2
pfsense-packages-4424d5f6afb3319c50def0262427c7030cb94ab1.zip
shellcmd - add support for afterfilterchangeshellcmd
Since it apparently still works and some users need it. Like https://forum.pfsense.org/index.php?topic=65004.msg353454#msg353454
Diffstat (limited to 'config/shellcmd')
-rw-r--r--config/shellcmd/shellcmd.inc39
1 files changed, 36 insertions, 3 deletions
diff --git a/config/shellcmd/shellcmd.inc b/config/shellcmd/shellcmd.inc
index 1dc52a50..8135bae8 100644
--- a/config/shellcmd/shellcmd.inc
+++ b/config/shellcmd/shellcmd.inc
@@ -123,13 +123,16 @@ function shellcmd_sync_package() {
$cmdtype = '';
$a_shellcmd = array();
$a_earlyshellcmd = array();
+ /* afterfilterchangeshellcmd is NOT treated as an array, it's a string! */
+ /* See /etc/inc/xmlparse.inc and /etc/inc/xmlreader.inc */
+ $afterfilterchangeshellcmd = '';
$a_shellcmd_config = &$config['installedpackages']['shellcmdsettings']['config'];
if (!is_array($a_shellcmd_config)) {
$a_shellcmd_config = array();
}
$i = 0;
- /* When shellcmd/earlyshellcmd is added to shellcmd package configuration, make sure */
- /* we add corresponding shellcmd/earlyshellcmd entry to $config['system'] as well */
+ /* When an item is added to shellcmd package configuration, make sure */
+ /* we add corresponding entry to $config['system'] as well */
foreach ($a_shellcmd_config as $item) {
/* Get the command from package configuration here */
$cmd = $a_shellcmd_config[$i]['cmd'];
@@ -143,6 +146,10 @@ function shellcmd_sync_package() {
} elseif ($cmdtype == "earlyshellcmd") {
$a_earlyshellcmd[] = $cmd;
$i++;
+ /* afterfilterchangeshellcmd */
+ } elseif ($cmdtype == "afterfilterchangeshellcmd") {
+ $afterfilterchangeshellcmd = $cmd;
+ $i++;
/* Either disabled, or possibly someone messing with config.xml manually?! */
} else {
$i++;
@@ -154,6 +161,8 @@ function shellcmd_sync_package() {
$config['system']['shellcmd'] = $a_shellcmd;
unset($config['system']['earlyshellcmd']);
$config['system']['earlyshellcmd'] = $a_earlyshellcmd;
+ unset($config['system']['afterfilterchangeshellcmd']);
+ $config['system']['afterfilterchangeshellcmd'] = $afterfilterchangeshellcmd;
write_config("[shellcmd] Successfully (re)synced shellcmd configuration.");
}
@@ -224,6 +233,15 @@ function shellcmd_import_config() {
}
}
+ /* Import afterfilterchangeshellcmd entry which was created manually (if there is any in config.xml) */
+ /* afterfilterchangeshellcmd is NOT treated as an array, it's a string! See /etc/inc/xmlparse.inc and /etc/inc/xmlreader.inc */
+ if ($config['system']['afterfilterchangeshellcmd'] != '') {
+ $shellcmd_config[$i]['cmd'] = $config['system']['afterfilterchangeshellcmd'];
+ $shellcmd_config[$i]['cmdtype'] = "afterfilterchangeshellcmd";
+ $shellcmd_config[$i]['description'] = $shellcmd_config[$i]['description'] ?: "Imported afterfilterchangeshellcmd";
+ $i++;
+ }
+
/* Write the new config.xml when import is finished */
write_config("[shellcmd] Successfully imported package configuration from config.xml.");
@@ -243,9 +261,11 @@ function shellcmd_validate_input($post, &$input_errors) {
if (!is_array($a_shellcmd_config)) {
$a_shellcmd_config = array();
}
+ /* afterfilterchangeshellcmd is NOT an array */
+ $afterfilterchangeshellcmd = $config['system']['afterfilterchangeshellcmd'];
/* Make sure we don't add the same command twice as it's just pointless */
- if (($post['cmd']) != '') {
+ if (($post['cmd']) != '') {
$id = $post['id'];
if ($post['cmdtype'] == "shellcmd") {
if (in_array($post['cmd'], $a_shellcmd)) {
@@ -267,6 +287,19 @@ function shellcmd_validate_input($post, &$input_errors) {
}
}
}
+ /* Only ONE item of this type may be configured */
+ if ($post['cmdtype'] == "afterfilterchangeshellcmd") {
+ // Not yet configured, OK
+ if ($afterfilterchangeshellcmd == '') {
+ return;
+ // Allow changing description
+ } elseif ((($post['cmd']) == $a_shellcmd_config[$id]['cmd']) && (($post['cmdtype']) == $a_shellcmd_config[$id]['cmdtype'])) {
+ return;
+ // Tired of input validation... Needs something better in future.
+ } else {
+ $input_errors[] = "Only ONE afterfilterchangeshellcmd may be configured! Delete the existing entry and try again!";
+ }
+ }
}
}