From 966c44e63d204906efaefebc66c9611f910486cb Mon Sep 17 00:00:00 2001 From: jim-p Date: Fri, 4 May 2012 16:52:03 -0400 Subject: Add a System Patches package to apply and maintain patches on a box. Should make it easier to test and deliver fixes. --- config/systempatches/patches.inc | 140 ++++++++++++++ config/systempatches/system_patches.php | 272 +++++++++++++++++++++++++++ config/systempatches/system_patches_edit.php | 211 +++++++++++++++++++++ config/systempatches/systempatches.xml | 66 +++++++ 4 files changed, 689 insertions(+) create mode 100644 config/systempatches/patches.inc create mode 100644 config/systempatches/system_patches.php create mode 100644 config/systempatches/system_patches_edit.php create mode 100644 config/systempatches/systempatches.xml (limited to 'config/systempatches') diff --git a/config/systempatches/patches.inc b/config/systempatches/patches.inc new file mode 100644 index 00000000..78cc35f2 --- /dev/null +++ b/config/systempatches/patches.inc @@ -0,0 +1,140 @@ + 0); + } +} + +function patch_erase($patch) { + global $patch_dir, $patch_suffix; + if (!file_exists($patch_dir)) { + return true; + } + $filename = $patch_dir . '/' . $patch['uniqid'] . $patch_suffix; + return @unlink($filename); +} + +/* Detect a github URL or commit ID and fix it up */ +function patch_fixup_url($url) { + global $git_root_url, $patch_suffix; + // If it's a commit id then prepend git url, and add .patch + if (is_commit_id($url)) { + $url = $git_root_url . $url . $patch_suffix; + } elseif (is_URL($url)) { + $urlbits = explode("/", $url); + if (substr($urlbits[2], -10) == "github.com") { + // If it's a github url and does not already end in .patch, add it + if (substr($url, -strlen($patch_suffix)) != $patch_suffix) { + // Make sure it's really a URL to a commit id before adding .patch + if (is_commit_id(array_pop($urlbits))) { + $url .= $patch_suffix; + } + } + } + } + return $url; +} + +function is_commit_id($str) { + return preg_match("/^[0-9a-f]{5,40}$/", $str); +} + +function is_github_url($url) { + $urlbits = explode("/", $url); + return (substr($urlbits[2], -10) == "github.com"); +} +?> \ No newline at end of file diff --git a/config/systempatches/system_patches.php b/config/systempatches/system_patches.php new file mode 100644 index 00000000..181db150 --- /dev/null +++ b/config/systempatches/system_patches.php @@ -0,0 +1,272 @@ +"; + $savemsg .= patch_test_revert($a_patches[$_GET['id']]) ? gettext("Patch can be reverted cleanly") : gettext("Patch can NOT be reverted cleanly"); +} +if (($_GET['act'] == "apply") && ($a_patches[$_GET['id']])) { + $savemsg = patch_apply($a_patches[$_GET['id']]) ? gettext("Patch applied successfully") : gettext("Patch could NOT be applied!"); +} +if (($_GET['act'] == "revert") && ($a_patches[$_GET['id']])) { + $savemsg = patch_revert($a_patches[$_GET['id']]) ? gettext("Patch reverted successfully") : gettext("Patch could NOT be reverted!"); +} + + +if (isset($_POST['del_x'])) { + /* delete selected patches */ + if (is_array($_POST['patch']) && count($_POST['patch'])) { + foreach ($_POST['patch'] as $patchi) { + unset($a_patches[$patchi]); + } + write_config(); + header("Location: system_patches.php"); + exit; + } +} else { + /* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */ + unset($movebtn); + foreach ($_POST as $pn => $pd) { + if (preg_match("/move_(\d+)_x/", $pn, $matches)) { + $movebtn = $matches[1]; + break; + } + } + /* move selected patches before this patch */ + if (isset($movebtn) && is_array($_POST['patch']) && count($_POST['patch'])) { + $a_patches_new = array(); + + /* copy all patches < $movebtn and not selected */ + for ($i = 0; $i < $movebtn; $i++) { + 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) + continue; + if (in_array($i, $_POST['patch'])) + $a_patches_new[] = $a_patches[$i]; + } + + /* copy $movebtn patch */ + 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'])) + $a_patches_new[] = $a_patches[$i]; + } + $a_patches = $a_patches_new; + write_config(); + header("Location: system_patches.php"); + return; + } +} + +$pgtitle = array(gettext("System"),gettext("Patches")); +include("head.inc"); + +echo ""; +echo ""; +echo ""; +echo ""; + +?> + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +

+ +

+
  + + + + +
+ + " border="0"> + + " onclick="return confirm('')"> + + ">
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
" height="17" type="image" width="17" border="0">">
')">">
+
+ + + + + + + + +
" border="0">" border="0">
+ + " border="0"> + + " onclick="return confirm('')"> + + ">
+
+ +

+ +
+
+
+ + + diff --git a/config/systempatches/system_patches_edit.php b/config/systempatches/system_patches_edit.php new file mode 100644 index 00000000..7983a081 --- /dev/null +++ b/config/systempatches/system_patches_edit.php @@ -0,0 +1,211 @@ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+ +
+ +
+ > +
+ +
 Patch id:
  + "> " onclick="history.back()"> + + + + +
+
+ + + diff --git a/config/systempatches/systempatches.xml b/config/systempatches/systempatches.xml new file mode 100644 index 00000000..3730c84f --- /dev/null +++ b/config/systempatches/systempatches.xml @@ -0,0 +1,66 @@ + + + + + + + + System Patches + None + Applies patches supplied by the user to the firewall. + System Patches + 0.5 + System: Patches + + Patches + +
System
+ /system_patches.php +
+ + /usr/local/www/ + 644 + http://www.pfsense.com/packages/config/systempatches/system_patches.php + + + /usr/local/www/ + 644 + http://www.pfsense.com/packages/config/systempatches/system_patches_edit.php + + + /usr/local/pkg/ + 644 + http://www.pfsense.com/packages/config/systempatches/patches.inc + +
\ No newline at end of file -- cgit v1.2.3