From 66dd6e02ac43b83742fc38b117725e5e92c34acc Mon Sep 17 00:00:00 2001 From: doktornotor Date: Fri, 21 Aug 2015 20:21:08 +0200 Subject: Delete shellcmd.php --- config/shellcmd/shellcmd.php | 179 ------------------------------------------- 1 file changed, 179 deletions(-) delete mode 100644 config/shellcmd/shellcmd.php diff --git a/config/shellcmd/shellcmd.php b/config/shellcmd/shellcmd.php deleted file mode 100644 index fd386910..00000000 --- a/config/shellcmd/shellcmd.php +++ /dev/null @@ -1,179 +0,0 @@ - - - - - -

Shellcmd: Settings

- -
- - -
- -
- - - - - -
- -
-"; -//print_info_box_np("This is an info box."); -//echo"
"; -//endif; - -?> - - - - -

- The shellcmd utility is used to manage commands on system startup. -

- -

-
- - - - - - - - - - 0) { - foreach ($$category_config as $ent) { - // previous versions of shellcmd stored the command in an additional -xmltag, this unnests this for backwards compatibility - if (is_array($ent)) { $ent = $ent['command']; } - - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " "; - $i++; - } - } - } - - -?> - - - - - - - - - - - -
CommandType - - - - - - -
- -
\n"; - echo " ".$ent."\n"; - echo " \n"; - echo " ".$category."\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
- - - - - -
-
- -
- - -
-
-
-
-
-
-
-
- -
- -
- - - - - -- cgit v1.2.3 From 92ab0fed73ebb1f5a03d3950ae27ca2cdca25a2b Mon Sep 17 00:00:00 2001 From: doktornotor Date: Fri, 21 Aug 2015 20:22:07 +0200 Subject: Delete shellcmd_edit.php --- config/shellcmd/shellcmd_edit.php | 303 -------------------------------------- 1 file changed, 303 deletions(-) delete mode 100644 config/shellcmd/shellcmd_edit.php diff --git a/config/shellcmd/shellcmd_edit.php b/config/shellcmd/shellcmd_edit.php deleted file mode 100644 index 5ae466d5..00000000 --- a/config/shellcmd/shellcmd_edit.php +++ /dev/null @@ -1,303 +0,0 @@ -0) { - $id = $_POST['id']; -} - -$type = $_GET['t']; -if (strlen($_POST['t'])>0) { - $type = $_POST['t']; -} - -if ($_GET['act'] == "del") { - if ($_GET['type'] == 'cmd') { - - switch (htmlspecialchars($type)) { - case "earlyshellcmd": - $a_earlyshellcmd = &$config['system']['earlyshellcmd']; - unset($a_earlyshellcmd[$_GET['id']]); - write_config(); - shellcmd_sync_package(); - header("Location: shellcmd.php"); - exit; - break; - case "shellcmd": - $a_shellcmd = &$config['system']['shellcmd']; - unset($a_shellcmd[$_GET['id']]); - write_config(); - shellcmd_sync_package(); - header("Location: shellcmd.php"); - exit; - break; - case "afterfilterchangeshellcmd": - // $a_afterfilterchangeshellcmd = &$config['system']['afterfilterchangeshellcmd']; - // unset($a_afterfilterchangeshellcmd[$_GET['id']]); - // write_config(); - // shellcmd_sync_package(); - // header("Location: shellcmd.php"); - // exit; - break; - default: - break; - } - - } -} - -//get value for the form edit value -if (strlen($id) > 0) { - - switch (htmlspecialchars($type)) { - case "earlyshellcmd": - $a_earlyshellcmd = &$config['system']['earlyshellcmd']; - if ($a_earlyshellcmd[$id]) { - $pconfig['command'] = $a_earlyshellcmd[$id]; - } - break; - case "shellcmd": - $a_shellcmd = &$config['system']['shellcmd']; - if ($a_shellcmd[$id]) { - $pconfig['command'] = $a_shellcmd[$id]; - } - break; - case "afterfilterchangeshellcmd": - //$a_afterfilterchangeshellcmd = &$config['system']['afterfilterchangeshellcmd']; - //if ($a_afterfilterchangeshellcmd[$id]) { - // $pconfig['command'] = $a_afterfilterchangeshellcmd[$id]; - //} - break; - default: - break; - } - - // previous version of shellcmd wrapped all commands in a -xmltag, unnesting this for backwards compatibility - if (is_array($pconfig['command'])) $pconfig['command'] = $pconfig['command']['command']; - -} - -if ($_POST) { - - unset($input_errors); - - if (!$input_errors) { - if (strlen($_POST['command']) > 0) { - - $ent = $_POST['command']; - - if (strlen($id)>0) { - //update - - switch (htmlspecialchars($type)) { - case "earlyshellcmd": - $a_earlyshellcmd = &$config['system']['earlyshellcmd']; - if ($a_earlyshellcmd[$id]) { - $a_earlyshellcmd[$id] = $ent; - } - break; - case "shellcmd": - $a_shellcmd = &$config['system']['shellcmd']; - if ($a_shellcmd[$id]) { - $a_shellcmd[$id] = $ent; - } - break; - case "afterfilterchangeshellcmd": - //$a_afterfilterchangeshellcmd = &$config['system']['afterfilterchangeshellcmd']; - //if ($a_afterfilterchangeshellcmd[$id]) { - // $a_afterfilterchangeshellcmd[$id] = $ent; - //} - break; - default: - break; - } - - } - else { - //add - switch (htmlspecialchars($type)) { - case "earlyshellcmd": - $a_earlyshellcmd = &$config['system']['earlyshellcmd']; - $a_earlyshellcmd[] = $ent; - break; - case "shellcmd": - $a_shellcmd = &$config['system']['shellcmd']; - $a_shellcmd[] = $ent; - break; - case "afterfilterchangeshellcmd": - //$a_afterfilterchangeshellcmd = &$config['system']['afterfilterchangeshellcmd']; - //$a_afterfilterchangeshellcmd[] = $ent; - break; - default: - break; - } - - } - - write_config(); - shellcmd_sync_package(); - } - - header("Location: shellcmd.php"); - exit; - } -} - -include("head.inc"); - -?> - - - - - -

Shellcmd: Edit

- - -
- - -
- -
- - - - -
- - -
- - -
- - - - - - - - - - - - - - - - - - -
Command - -
Type - \n"; - echo " \n"; - switch (htmlspecialchars($type)) { - case "earlyshellcmd": - echo " \n"; - echo " \n"; - //echo " \n"; - break; - case "shellcmd": - echo " \n"; - echo " \n"; - //echo " \n"; - break; - case "afterfilterchangeshellcmd": - //echo " \n"; - //echo " \n"; - //echo " \n"; - break; - default: - echo " \n"; - echo " \n"; - echo " \n"; - //echo " \n"; - break; - } - echo " \n"; - ?> -
  - 0) { ?> - - - -
-
- -
-
-
-
-
-
- -
- -
- - - - -- cgit v1.2.3 From 8fda71b59dc62210f038a30cbf22abc7ff585c09 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Fri, 21 Aug 2015 20:22:58 +0200 Subject: shellcmd - rewrite from scratch --- config/shellcmd/shellcmd.xml | 185 +++++++++++++++++++++++++------------------ 1 file changed, 107 insertions(+), 78 deletions(-) diff --git a/config/shellcmd/shellcmd.xml b/config/shellcmd/shellcmd.xml index 094c3d30..4becdf89 100644 --- a/config/shellcmd/shellcmd.xml +++ b/config/shellcmd/shellcmd.xml @@ -1,115 +1,144 @@ - - + + - - + - - Shellcmd - Describe your package requirements here - Currently there are no FAQ items provided. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ +/* ====================================================================================== */ + ]]> + Shellcmd Settings - 0.4 - Settings + 1.0 + Shellcmd Settings /usr/local/pkg/shellcmd.inc + /pkg.php?xml=shellcmd.xml + [shellcmd] Successfully created/modified custom (early)shellcmd. + [shellcmd] Successfully deleted custom (early)shellcmd. Shellcmd - shellcmd settings.
Services
shellcmd.xml - /packages/shellcmd/shellcmd.php + /pkg.php?xml=shellcmd.xml
Settings - /pkg_edit.php?xml=shellcmd.xml&id=0 + /pkg.php?xml=shellcmd.xml - - Settings - /packages/shellcmd/shellcmd.php - - - installedpackages->package->$packagename->configuration->shellcmd /usr/local/pkg/ - 0755 - https://packages.pfsense.org/packages/config/shellcmd/shellcmd.xml - - - /usr/local/pkg/ - 0755 https://packages.pfsense.org/packages/config/shellcmd/shellcmd.inc - - /usr/local/www/packages/shellcmd/ - 0755 - https://packages.pfsense.org/packages/config/shellcmd/shellcmd.php - - - /usr/local/www/packages/shellcmd/ - 0755 - https://packages.pfsense.org/packages/config/shellcmd/shellcmd_edit.php - + + + Command + cmd + + + Shellcmd Type + cmdtype + + + Description + description + + Add a new (early)shellcmd entry + Edit this (early)shellcmd entry + Delete this (early)shellcmd entry + - Variable One - var1 - Enter the variable one here. + listtopic + none + Shellcmd Configuration + + + Command + cmd input + 60 + Enter the command to run. + + + + Shellcmd Type + cmdtype + select + + + + + +
+ shellcmd will run the command specified towards the end of the boot process.
+ earlyshellcmd will run the command specified at the beginning of the boot process.

+ See Executing commands at boot time for detailed explanation. + ]]> +
+
- Variable Two - var1 - Enter the variable one here. + Description + description + Enter a description for this command. input + (This is for your reference only.) + 60 -
- - + + + shellcmd_import_config(); + shellcmd_sync_package(); - - shellcmd_sync_package(); + + shellcmd_delete_php_command(); - - shellcmd_install_command(); - - - shellcmd_deinstall_command(); - + + shellcmd_validate_input($_POST, $input_errors); +
-- cgit v1.2.3 From 2a79f3394083fffb8e81360b3de23e116d5921b4 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Fri, 21 Aug 2015 20:23:44 +0200 Subject: shellcmd - rewrite from scratch --- config/shellcmd/shellcmd.inc | 246 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 201 insertions(+), 45 deletions(-) diff --git a/config/shellcmd/shellcmd.inc b/config/shellcmd/shellcmd.inc index 04cbf3d6..ef81050d 100644 --- a/config/shellcmd/shellcmd.inc +++ b/config/shellcmd/shellcmd.inc @@ -1,14 +1,11 @@ $value) { + if (in_array($pfbcmd, $value)) { + $cnta++; + } + } + /* ... the user has deleted this protected entry. */ + if ($cnta === 0) { + $pkg .= "[pfBlockerNG]"; + /* Force reimport. */ + shellcmd_forced_restore($pkg); + } + } + /* System Patches auto-apply patch feature (see patches.inc) */ + $spcmd = "/usr/local/bin/php -f /usr/local/bin/apply_patches.php"; + if (in_array($spcmd, $a_earlyshellcmd)) { + $cntb = 0; + foreach ($a_shellcmd_config as $item => $value) { + if (in_array($spcmd, $value)) { + $cntb++; + } + } + if ($cntb === 0) { + $pkg .= "[System Patches]"; + shellcmd_forced_restore($pkg); + } + } + + /* Otherwise, sync package and system configuration normally */ + shellcmd_sync_package(); + } +} + +/* Force restore of protected (early)shellcmds from system config */ +function shellcmd_forced_restore($pkg) { + log_error("[shellcmd] Refused to delete {$pkg} earlyshellcmd. Use {$pkg} to configure this entry."); + shellcmd_import_config(); + write_config("[shellcmd] Restore of {$pkg} earlyshellcmd forced."); + /* Send the user back to settings */ + header("Location: pkg.php?xml=shellcmd.xml"); + exit; } - -function shellcmd_install_command() -{ +function shellcmd_sync_package() { global $config; conf_mount_rw(); - shellcmd_sync_package(); - conf_mount_ro(); + + $cmd = ''; + $cmdtype = ''; + $a_shellcmd = array(); + $a_earlyshellcmd = array(); + $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 */ + foreach ($a_shellcmd_config as $item) { + /* Get the command from package configuration here */ + $cmd = $a_shellcmd_config[$i]['cmd']; + /* Lets see what type of command we are adding first... */ + $cmdtype = $a_shellcmd_config[$i]['cmdtype']; + /* shellcmd */ + if ($cmdtype == "shellcmd") { + $a_shellcmd[] = $cmd; + $i++; + /* earlyshellcmd */ + } elseif ($cmdtype == "earlyshellcmd") { + $a_earlyshellcmd[] = $cmd; + $i++; + /* Should never happen; someone messing with config.xml manually?! */ + } else { + return; + $i++; + } + } + + /* Write the new system configuration to config.xml from scratch when done */ + unset($config['system']['shellcmd']); + $config['system']['shellcmd'] = $a_shellcmd; + unset($config['system']['earlyshellcmd']); + $config['system']['earlyshellcmd'] = $a_earlyshellcmd; + write_config("[shellcmd] Successfully (re)synced shellcmd configuration."); } -function shellcmd_deinstall_command() -{ +function shellcmd_import_config() { + global $config; - conf_mount_rw(); - $handle = popen("/usr/local/etc/rc.d/shellcmd.sh stop", "r"); - //unlink_if_exists("/usr/local/etc/rc.d/shellcmd.sh"); - conf_mount_ro(); + /* Import earlyshellcmd entries which were either created by previous package versions, */ + /* or manually, or added by some other package(s) (if there are any in config.xml) */ + /* Two currently known special cases are handled here - System Patches and pfBlockerNG */ + $shellcmd_config = &$config['installedpackages']['shellcmdsettings']['config']; + if (!is_array($shellcmd_config)) { + $shellcmd_config = array(); + } + + $i = 0; + if (is_array($config['system']['earlyshellcmd'])) { + $earlyshellcmds = &$config['system']['earlyshellcmd']; + $pfbcmd = "/usr/local/pkg/pfblockerng/pfblockerng.sh"; + $spcmd = "/usr/local/bin/php -f /usr/local/bin/apply_patches.php"; + foreach ($earlyshellcmds as $earlyshellcmd) { + /* pfBlockerNG - function to restore archived aliastables on nanobsd (see pfblockerng.inc) */ + if (stristr($earlyshellcmd, "{$pfbcmd}")) { + $shellcmd_config[$i]['cmd'] = $earlyshellcmd; + $shellcmd_config[$i]['cmdtype'] = "earlyshellcmd"; + $shellcmd_config[$i]['description'] = "pfBlockerNG default earlyshellcmd. DO NOT EDIT/DELETE!"; + $i++; + /* System Patches auto-apply patch feature (see patches.inc) */ + } elseif (stristr($earlyshellcmd, "{$spcmd}")) { + $shellcmd_config[$i]['cmd'] = $earlyshellcmd; + $shellcmd_config[$i]['cmdtype'] = "earlyshellcmd"; + $shellcmd_config[$i]['description'] = "System Patches default earlyshellcmd. DO NOT EDIT/DELETE!"; + $i++; + /* Other manually added earlyshellcmd entries */ + } else { + $shellcmd_config[$i]['cmd'] = $earlyshellcmd; + $shellcmd_config[$i]['cmdtype'] = "earlyshellcmd"; + $shellcmd_config[$i]['description'] = "Imported earlyshellcmd ({$i})"; + $i++; + } + + } + } + /* Import shellcmd entries which were created manually (if there are any in config.xml) */ + if (is_array($config['system']['shellcmd'])) { + $shellcmds = &$config['system']['shellcmd']; + foreach ($shellcmds as $shellcmd) { + $shellcmd_config[$i]['cmd'] = $shellcmd; + $shellcmd_config[$i]['cmdtype'] = "shellcmd"; + $shellcmd_config[$i]['description'] = "Imported shellcmd ({$i})"; + $i++; + } + } + + /* Write the new config.xml when import is finished */ + write_config("[shellcmd] Successfully imported package configuration from config.xml."); + +} + +function shellcmd_validate_input($post, &$input_errors) { + global $config; + $a_shellcmd = &$config['system']['shellcmd']; + if (!is_array($a_shellcmd)) { + $a_shellcmd = array(); + } + $a_earlyshellcmd = &$config['system']['earlyshellcmd']; + if (!is_array($a_earlyshellcmd)) { + $a_earlyshellcmd = array(); + } + + /* Make sure we don't add the same command twice as it's just pointless */ + if (($post['cmd']) != '') { + if ($post['cmdtype'] == "shellcmd") { + if (in_array($post['cmd'], $a_shellcmd)) { + $input_errors[] = "{$post['cmd']} already exists as shellcmd."; + } + } + if ($post['cmdtype'] == "earlyshellcmd") { + if (in_array($post['cmd'], $a_earlyshellcmd)) { + $input_errors[] = "{$post['cmd']} already exists as earlyshellcmd."; + } + } + } } -- cgit v1.2.3 From 414beb57ad19c01bb01d8ecd106c52cc23d4688a Mon Sep 17 00:00:00 2001 From: doktornotor Date: Fri, 21 Aug 2015 20:24:39 +0200 Subject: Bump shellcmd package version --- pkg_config.10.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg_config.10.xml b/pkg_config.10.xml index 0ecde95c..af9bc952 100644 --- a/pkg_config.10.xml +++ b/pkg_config.10.xml @@ -1281,7 +1281,7 @@ The shellcmd utility is used to manage commands on system startup. Services https://packages.pfsense.org/packages/config/shellcmd/shellcmd.xml - 0.6 + 1.0 Beta 2.2 markjcrane@gmail.com -- cgit v1.2.3 From f0064564bce1b9ab24807648c67ab61bec351539 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Sat, 22 Aug 2015 17:00:07 +0200 Subject: shellcmd - add support for disabled items, fix to allow editing descriptions --- config/shellcmd/shellcmd.inc | 50 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/config/shellcmd/shellcmd.inc b/config/shellcmd/shellcmd.inc index ef81050d..1dc52a50 100644 --- a/config/shellcmd/shellcmd.inc +++ b/config/shellcmd/shellcmd.inc @@ -102,6 +102,7 @@ function shellcmd_delete_php_command() { } } + /* Force restore of protected (early)shellcmds from system config */ function shellcmd_forced_restore($pkg) { log_error("[shellcmd] Refused to delete {$pkg} earlyshellcmd. Use {$pkg} to configure this entry."); @@ -142,9 +143,8 @@ function shellcmd_sync_package() { } elseif ($cmdtype == "earlyshellcmd") { $a_earlyshellcmd[] = $cmd; $i++; - /* Should never happen; someone messing with config.xml manually?! */ + /* Either disabled, or possibly someone messing with config.xml manually?! */ } else { - return; $i++; } } @@ -162,15 +162,30 @@ function shellcmd_sync_package() { function shellcmd_import_config() { global $config; - /* Import earlyshellcmd entries which were either created by previous package versions, */ - /* or manually, or added by some other package(s) (if there are any in config.xml) */ - /* Two currently known special cases are handled here - System Patches and pfBlockerNG */ $shellcmd_config = &$config['installedpackages']['shellcmdsettings']['config']; if (!is_array($shellcmd_config)) { $shellcmd_config = array(); } $i = 0; + + /* First, preserve any disabled items */ + $a_shellcmd_config = &$shellcmd_config; + foreach ($a_shellcmd_config as $item => $value) { + $cmd = $value['cmd']; + $cmdtype = $value['cmdtype']; + $description = $value['description']; + if ($cmdtype == "disabled") { + $shellcmd_config[$i]['cmd'] = $cmd; + $shellcmd_config[$i]['cmdtype'] = "disabled"; + $shellcmd_config[$i]['description'] = $description ?: "Imported disabled item ({$i})"; + $i++; + } + } + + /* Import earlyshellcmd entries which were either created by previous package versions, */ + /* or manually, or added by some other package(s) (if there are any in config.xml) */ + /* Two currently known special cases are handled here - System Patches and pfBlockerNG */ if (is_array($config['system']['earlyshellcmd'])) { $earlyshellcmds = &$config['system']['earlyshellcmd']; $pfbcmd = "/usr/local/pkg/pfblockerng/pfblockerng.sh"; @@ -192,7 +207,7 @@ function shellcmd_import_config() { } else { $shellcmd_config[$i]['cmd'] = $earlyshellcmd; $shellcmd_config[$i]['cmdtype'] = "earlyshellcmd"; - $shellcmd_config[$i]['description'] = "Imported earlyshellcmd ({$i})"; + $shellcmd_config[$i]['description'] = $shellcmd_config[$i]['description'] ?: "Imported earlyshellcmd ({$i})"; $i++; } @@ -204,7 +219,7 @@ function shellcmd_import_config() { foreach ($shellcmds as $shellcmd) { $shellcmd_config[$i]['cmd'] = $shellcmd; $shellcmd_config[$i]['cmdtype'] = "shellcmd"; - $shellcmd_config[$i]['description'] = "Imported shellcmd ({$i})"; + $shellcmd_config[$i]['description'] = $shellcmd_config[$i]['description'] ?: "Imported shellcmd ({$i})"; $i++; } } @@ -224,17 +239,32 @@ function shellcmd_validate_input($post, &$input_errors) { if (!is_array($a_earlyshellcmd)) { $a_earlyshellcmd = array(); } + $a_shellcmd_config = &$config['installedpackages']['shellcmdsettings']['config']; + if (!is_array($a_shellcmd_config)) { + $a_shellcmd_config = array(); + } /* 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)) { - $input_errors[] = "{$post['cmd']} already exists as shellcmd."; + /* Allow changing description */ + if ((($post['cmd']) == $a_shellcmd_config[$id]['cmd']) && (($post['cmdtype']) == $a_shellcmd_config[$id]['cmdtype'])) { + return; + } else { + $input_errors[] = "{$post['cmd']} already exists as shellcmd."; + } } } if ($post['cmdtype'] == "earlyshellcmd") { if (in_array($post['cmd'], $a_earlyshellcmd)) { - $input_errors[] = "{$post['cmd']} already exists as earlyshellcmd."; + /* Allow changing description */ + if ((($post['cmd']) == $a_shellcmd_config[$id]['cmd']) && (($post['cmdtype']) == $a_shellcmd_config[$id]['cmdtype'])) { + return; + } else { + $input_errors[] = "{$post['cmd']} already exists as earlyshellcmd."; + } } } } -- cgit v1.2.3 From 3de8cde76a4e55ea867049ef699b0cb5811b5300 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Sat, 22 Aug 2015 17:01:29 +0200 Subject: shellcmd - add support for disabled items --- config/shellcmd/shellcmd.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/config/shellcmd/shellcmd.xml b/config/shellcmd/shellcmd.xml index 4becdf89..05f72f7a 100644 --- a/config/shellcmd/shellcmd.xml +++ b/config/shellcmd/shellcmd.xml @@ -61,6 +61,7 @@ + ['installedpackages']['shellcmdsettings']['config'] /usr/local/pkg/ https://packages.pfsense.org/packages/config/shellcmd/shellcmd.inc @@ -109,12 +110,17 @@ earlyshellcmd earlyshellcmd +
shellcmd will run the command specified towards the end of the boot process.
- earlyshellcmd will run the command specified at the beginning of the boot process.

+ earlyshellcmd will run the command specified at the beginning of the boot process.
+ disabled will save the command in package configuration but it will NOT run on boot.

See Executing commands at boot time for detailed explanation. ]]>
-- cgit v1.2.3 From 4424d5f6afb3319c50def0262427c7030cb94ab1 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Sat, 22 Aug 2015 22:48:59 +0200 Subject: 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 --- config/shellcmd/shellcmd.inc | 39 ++++++++++++++++++++++++++++++++++++--- 1 file 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!"; + } + } } } -- cgit v1.2.3 From 7d64d9d2a8a5cecb8400d4ab445ce3023fee50a9 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Sat, 22 Aug 2015 22:51:15 +0200 Subject: shellcmd - add support for afterfilterchangeshellcmd --- config/shellcmd/shellcmd.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config/shellcmd/shellcmd.xml b/config/shellcmd/shellcmd.xml index 05f72f7a..f6b34ee4 100644 --- a/config/shellcmd/shellcmd.xml +++ b/config/shellcmd/shellcmd.xml @@ -110,6 +110,10 @@ earlyshellcmd earlyshellcmd +