From 05074a272afe59851788c3dd7c7a925fbfbc75ed Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 6 Aug 2015 14:35:48 +0545 Subject: Systen Patches package code style --- config/systempatches/patches.inc | 23 ++- config/systempatches/system_patches.php | 247 +++++++++++++++------------ config/systempatches/system_patches_edit.php | 28 +-- config/systempatches/systempatches.xml | 15 +- pkg_config.10.xml | 2 +- 5 files changed, 176 insertions(+), 139 deletions(-) diff --git a/config/systempatches/patches.inc b/config/systempatches/patches.inc index 60c9a391..f47324c4 100644 --- a/config/systempatches/patches.inc +++ b/config/systempatches/patches.inc @@ -55,10 +55,11 @@ function patch_commit($patch, $action, $test=false, $fulldetail=false) { $full_patch_command = "{$patch_cmd} --directory={$directory} {$force} {$pathstrip} {$filename} {$check} {$direction} {$whitespace}"; conf_mount_rw(); patch_write($patch); - if (!$fulldetail) + if (!$fulldetail) { $output = (mwexec($full_patch_command, true) == 0); - else + } else { $output = $full_patch_command . "\n\n" . shell_exec($full_patch_command . ' 2>&1'); + } patch_erase($patch); conf_mount_ro(); return $output; @@ -158,8 +159,9 @@ function bootup_apply_patches() { foreach ($a_patches as $patch) { /* Skip the patch if it should not be automatically applied. */ - if (!isset($patch['autoapply'])) + if (!isset($patch['autoapply'])) { continue; + } /* If the patch can be reverted it is already applied, so skip it. */ if (!patch_test_revert($patch)) { /* Only attempt to apply if it can be applied. */ @@ -173,12 +175,15 @@ function bootup_apply_patches() { function patch_add_shellcmd() { global $config; $a_earlyshellcmd = &$config['system']['earlyshellcmd']; - if (!is_array($a_earlyshellcmd)) + if (!is_array($a_earlyshellcmd)) { $a_earlyshellcmd = array(); + } $found = false; - foreach ($a_earlyshellcmd as $idx => $cmd) - if (stristr($cmd, "apply_patches.php")) + foreach ($a_earlyshellcmd as $idx => $cmd) { + if (stristr($cmd, "apply_patches.php")) { $found = true; + } + } if (!$found) { $a_earlyshellcmd[] = "/usr/local/bin/php -f /usr/local/bin/apply_patches.php"; write_config("System Patches package added a shellcmd"); @@ -188,8 +193,9 @@ function patch_add_shellcmd() { function patch_remove_shellcmd() { global $config; $a_earlyshellcmd = &$config['system']['earlyshellcmd']; - if (!is_array($a_earlyshellcmd)) + if (!is_array($a_earlyshellcmd)) { $a_earlyshellcmd = array(); + } $removed = false; foreach ($a_earlyshellcmd as $idx => $cmd) { if (stristr($cmd, "apply_patches.php")) { @@ -197,8 +203,9 @@ function patch_remove_shellcmd() { $removed = true; } } - if ($removed) + if ($removed) { write_config("System Patches package removed a shellcmd"); + } } ?> diff --git a/config/systempatches/system_patches.php b/config/systempatches/system_patches.php index 43c8c22b..feeee07e 100644 --- a/config/systempatches/system_patches.php +++ b/config/systempatches/system_patches.php @@ -41,14 +41,16 @@ require_once("functions.inc"); require_once("itemid.inc"); require_once("patches.inc"); -if (!is_array($config['installedpackages']['patches']['item'])) +if (!is_array($config['installedpackages']['patches']['item'])) { $config['installedpackages']['patches']['item'] = array(); +} $a_patches = &$config['installedpackages']['patches']['item']; /* if a custom message has been passed along, lets process it */ -if ($_GET['savemsg']) +if ($_GET['savemsg']) { $savemsg = $_GET['savemsg']; +} if ($_POST) { $pconfig = $_POST; @@ -116,26 +118,31 @@ if (isset($_POST['del_x'])) { /* copy all patches < $movebtn and not selected */ for ($i = 0; $i < $movebtn; $i++) { - if (!in_array($i, $_POST['patch'])) + if (!in_array($i, $_POST['patch'])) { $a_patches_new[] = $a_patches[$i]; + } } /* copy all selected patches */ for ($i = 0; $i < count($a_patches); $i++) { - if ($i == $movebtn) + if ($i == $movebtn) { continue; - if (in_array($i, $_POST['patch'])) + } + if (in_array($i, $_POST['patch'])) { $a_patches_new[] = $a_patches[$i]; + } } /* copy $movebtn patch */ - if ($movebtn < count($a_patches)) + if ($movebtn < count($a_patches)) { $a_patches_new[] = $a_patches[$movebtn]; + } /* copy all patches > $movebtn and not selected */ for ($i = $movebtn+1; $i < count($a_patches); $i++) { - if (!in_array($i, $_POST['patch'])) + if (!in_array($i, $_POST['patch'])) { $a_patches_new[] = $a_patches[$i]; + } } $a_patches = $a_patches_new; write_config(); @@ -164,41 +171,47 @@ include("head.inc");
- + - + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + - -
- -

- -

+
+ +

+ +

-
Output of full patch test: -
-Close

+
Output of full patch test: +
+ Close

-
  - - - + + + + + + + + + + + + -
- - " border="0" alt="delete" /> - - " onclick="return confirm('')" /> - - " alt="add" />
  + + + + + +
+ + " border="0" alt="delete" /> + + " onclick="return confirm('')" /> + + " alt="add" />
+
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
" height="17" type="image" width="17" border="0" />" alt="edit" />
')">" alt="delete" />
-
- - - + + + + + + + + + + - - + + -
" border="0" alt="move" />" border="0" alt="move" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
" height="17" type="image" width="17" border="0" />" alt="edit" />
')">" alt="delete" />
+
- - " border="0" alt="delete" /> - - " onclick="return confirm('')" /> - - " alt="add" /> + + + + + + + + +
" border="0" alt="move" />" border="0" alt="move" />
+ + " border="0" alt="delete" /> + + " onclick="return confirm('')" /> + + " alt="add" />
+
-
+ +

+ +
- -

- -
+
diff --git a/config/systempatches/system_patches_edit.php b/config/systempatches/system_patches_edit.php index 3e63038e..9e1f7a49 100644 --- a/config/systempatches/system_patches_edit.php +++ b/config/systempatches/system_patches_edit.php @@ -46,8 +46,9 @@ if (!is_array($config['installedpackages']['patches']['item'])) { $a_patches = &$config['installedpackages']['patches']['item']; $id = $_GET['id']; -if (isset($_POST['id'])) +if (isset($_POST['id'])) { $id = $_POST['id']; +} if (isset($_GET['dup'])) { $id = $_GET['dup']; @@ -69,8 +70,9 @@ if (isset($id) && $a_patches[$id]) { $pconfig['ignorewhitespace'] = true; } -if (isset($_GET['dup'])) +if (isset($_GET['dup'])) { unset($id); +} unset($input_errors); @@ -87,10 +89,11 @@ if ($_POST) { } $pf_version=substr(trim(file_get_contents("/etc/version")),0,3); - if ($pf_version < 2.1) + if ($pf_version < 2.1) { $input_errors = eval('do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); return $input_errors;'); - else + } else { do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); + } if (!empty($_POST['location']) && !is_commit_id($_POST['location']) && !is_URL($_POST['location'])) { $input_errors[] = gettext("The supplied commit ID/URL appears to be invalid."); @@ -111,10 +114,11 @@ if ($_POST) { /* Strip DOS style carriage returns from textarea input */ $thispatch['patch'] = base64_encode(str_replace("\r", "", $_POST['patch'])); } - if (is_github_url($thispatch['location']) && ($_POST['pathstrip'] == 0)) + if (is_github_url($thispatch['location']) && ($_POST['pathstrip'] == 0)) { $thispatch['pathstrip'] = 1; - else + } else { $thispatch['pathstrip'] = $_POST['pathstrip']; + } $thispatch['basedir'] = empty($_POST['basedir']) ? "/" : $_POST['basedir']; $thispatch['ignorewhitespace'] = isset($_POST['ignorewhitespace']); $thispatch['autoapply'] = isset($_POST['autoapply']); @@ -125,18 +129,20 @@ if ($_POST) { } // Update the patch entry now - if (isset($id) && $a_patches[$id]) + if (isset($id) && $a_patches[$id]) { $a_patches[$id] = $thispatch; - else { - if (is_numeric($after)) + } else { + if (is_numeric($after)) { array_splice($a_patches, $after+1, 0, array($thispatch)); - else + } else { $a_patches[] = $thispatch; + } } write_config(); - if ($thispatch['autoapply']) + if ($thispatch['autoapply']) { patch_add_shellcmd(); + } header("Location: system_patches.php"); return; } diff --git a/config/systempatches/systempatches.xml b/config/systempatches/systempatches.xml index 3cc1354a..ad7f5953 100644 --- a/config/systempatches/systempatches.xml +++ b/config/systempatches/systempatches.xml @@ -10,17 +10,18 @@ part of pfSense (http://www.pfSense.com) Copyright (C) 2012 Jim Pingle All rights reserved. +*/ /* ========================================================================== */ /* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. - 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. + 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 @@ -32,7 +33,7 @@ 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. - */ +*/ /* ========================================================================== */ ]]> @@ -40,7 +41,7 @@ None Applies patches supplied by the user to the firewall. System Patches - 1.0.3 + 1.0.4 System: Patches /usr/local/pkg/patches.inc diff --git a/pkg_config.10.xml b/pkg_config.10.xml index 60f28e41..ff9e676d 100644 --- a/pkg_config.10.xml +++ b/pkg_config.10.xml @@ -1352,7 +1352,7 @@ System_Patches A package to apply and maintain custom system patches. jimp@pfsense.org - 1.0.3 + 1.0.4 System RELEASE https://packages.pfsense.org/packages/config/systempatches/systempatches.xml -- cgit v1.2.3