Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shellcmd package cleanup/fixes #311

Merged
merged 3 commits into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sysutils/pfSense-pkg-Shellcmd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

PORTNAME= pfSense-pkg-Shellcmd
PORTVERSION= 1.0.2
PORTREVISION= 2
PORTREVISION= 3
CATEGORIES= sysutils
MASTER_SITES= # empty
DISTFILES= # empty
Expand Down
41 changes: 21 additions & 20 deletions sysutils/pfSense-pkg-Shellcmd/files/usr/local/pkg/shellcmd.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
function shellcmd_install_command() {
global $config;

/* Remove garbage left over by previous broken package versions */
unlink_if_exists("/usr/local/etc/rc.d/shellcmd.sh");
if (is_dir("/usr/local/www/packages/shellcmd")) {
mwexec("/bin/rm -rf /usr/local/www/packages/shellcmd/");
}

shellcmd_import_config();
shellcmd_sync_package();

Expand All @@ -53,7 +47,6 @@ function shellcmd_delete_php_command() {
}

/* First check for a couple of special cases that we do NOT want deleted */
/* TODO: Create a function for these checks */
$pkg = '';
/* pfBlockerNG - function to restore archived aliastables on nanobsd (see pfblockerng.inc) */
$pfbcmd = "/usr/local/pkg/pfblockerng/pfblockerng.sh";
Expand All @@ -74,7 +67,7 @@ function shellcmd_delete_php_command() {
}
}
/* System Patches auto-apply patch feature (see patches.inc) */
$spcmd = "/usr/local/bin/php-cgi -f /usr/local/bin/apply_patches.php";
$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) {
Expand Down Expand Up @@ -114,16 +107,20 @@ 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 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 an item is added to shellcmd package configuration, make sure */
/* we add corresponding 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'];
Expand Down Expand Up @@ -183,13 +180,15 @@ function shellcmd_import_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 */
/*
* 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";
$spcmd = "/usr/local/bin/php-cgi -f /usr/local/bin/apply_patches.php";
$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}")) {
Expand Down Expand Up @@ -224,8 +223,11 @@ 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 */
/*
* 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";
Expand Down Expand Up @@ -286,9 +288,8 @@ function shellcmd_validate_input($post, &$input_errors) {
// 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!";
$input_errors[] = "Only one afterfilterchangeshellcmd may be configured. Delete the existing entry and try again.";
}
}
}
Expand Down
44 changes: 17 additions & 27 deletions sysutils/pfSense-pkg-Shellcmd/files/usr/local/pkg/shellcmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* shellcmd.xml
*
* part of pfSense (https://www.pfsense.org)
* Copyright (c) 2015 Rubicon Communications, LLC (Netgate)
* Copyright (c) 2015-2017 Rubicon Communications, LLC (Netgate)
* Copyright (C) 2008 Mark J Crane
* All rights reserved.
*
Expand Down Expand Up @@ -58,7 +58,6 @@
<fields>
<field>
<type>listtopic</type>
<fieldname>none</fieldname>
<name>Shellcmd Configuration</name>
</field>
<field>
Expand All @@ -74,43 +73,34 @@
<fieldname>cmdtype</fieldname>
<type>select</type>
<options>
<option>
<name>shellcmd</name>
<value>shellcmd</value>
</option>
<option>
<name>earlyshellcmd</name>
<value>earlyshellcmd</value>
</option>
<option>
<name>afterfilterchangeshellcmd</name>
<value>afterfilterchangeshellcmd</value>
</option>
<option>
<name>disabled</name>
<value>disabled</value>
</option>
<option><name>shellcmd</name><value>shellcmd</value></option>
<option><name>earlyshellcmd</name><value>earlyshellcmd</value></option>
<option><name>afterfilterchangeshellcmd</name><value>afterfilterchangeshellcmd</value></option>
<option><name>disabled</name><value>disabled</value></option>
</options>
<description>
<![CDATA[
Choose the shellcmd type.<br /><br />
<strong>shellcmd</strong> will run the command specified towards the end of the boot process.<br />
<strong>earlyshellcmd</strong> will run the command specified at the beginning of the boot process.<br />
<strong>afterfilterchangeshellcmd</strong> will run after each filter_configure() call.
See /etc/inc/filter.inc source code for "documentation".
<span class="errmsg">N.B.: Only one entry of this type can be configured!</span><br />
<strong>disabled</strong> will save the command in package configuration but it will NOT run on boot.<br /><br />
Choose the shellcmd type. Click Info for details.
<div class="infoblock">
<dl class="dl-horizontal responsive">
<dt>shellcmd</dt><dd>Will run the command specified towards the end of the boot process.</dd>
<dt>earlyshellcmd</dt><dd>Will run the command specified at the beginning of the boot process.</dd>
<dt>afterfilterchangeshellcmd</dt><dd>Will run after each <code>filter_configure()</code> call.
See <code>/etc/inc/filter.inc</code> source code for "documentation".<br/>
<span class="text-danger">Note:</span> Only one entry of this type can be configured!</dd>
<dt>disabled</dt><dd>Will save the command in package configuration but it will NOT run on boot.</dd>
</dl>
See <a href="https://doc.pfsense.org/index.php/Executing_commands_at_boot_time">Executing commands at boot time</a> for detailed explanation.
</div>
]]>
</description>
<required/>
</field>
<field>
<fielddescr>Description</fielddescr>
<fieldname>description</fieldname>
<description>Enter a description for this command.</description>
<description>Enter a description for this command. (This is for your reference only.)</description>
<type>input</type>
<typehint>(This is for your reference only.)</typehint>
<size>60</size>
</field>
</fields>
Expand Down