From da0b5e1083d3235aa29bcb70a18424714bf88924 Mon Sep 17 00:00:00 2001 From: PiBa-NL Date: Mon, 2 Jan 2017 22:34:32 +0100 Subject: [PATCH] haproxy, haproxy-devel, cleanup old pfSense 2.2/2.1 compatibility checks in code --- net/pfSense-pkg-haproxy-devel/Makefile | 2 +- .../files/usr/local/pkg/haproxy/haproxy.inc | 101 ++---------------- .../usr/local/pkg/haproxy/haproxy_gui.inc | 96 ++++------------- .../www/haproxy/haproxy_listeners_edit.php | 1 - .../www/widgets/widgets/haproxy.widget.php | 8 +- net/pfSense-pkg-haproxy/Makefile | 2 +- .../files/usr/local/pkg/haproxy/haproxy.inc | 101 ++---------------- .../usr/local/pkg/haproxy/haproxy_gui.inc | 96 ++++------------- .../www/haproxy/haproxy_listeners_edit.php | 1 - .../www/widgets/widgets/haproxy.widget.php | 8 +- 10 files changed, 68 insertions(+), 348 deletions(-) diff --git a/net/pfSense-pkg-haproxy-devel/Makefile b/net/pfSense-pkg-haproxy-devel/Makefile index 3ca1f092e3e7..0d2d6c697013 100644 --- a/net/pfSense-pkg-haproxy-devel/Makefile +++ b/net/pfSense-pkg-haproxy-devel/Makefile @@ -2,7 +2,7 @@ PORTNAME= pfSense-pkg-haproxy-devel PORTVERSION= 0.52 -PORTREVISION= 3 +PORTREVISION= 4 CATEGORIES= net MASTER_SITES= # empty DISTFILES= # empty diff --git a/net/pfSense-pkg-haproxy-devel/files/usr/local/pkg/haproxy/haproxy.inc b/net/pfSense-pkg-haproxy-devel/files/usr/local/pkg/haproxy/haproxy.inc index c24df8603ffd..6bb98f5fcd3b 100644 --- a/net/pfSense-pkg-haproxy-devel/files/usr/local/pkg/haproxy/haproxy.inc +++ b/net/pfSense-pkg-haproxy-devel/files/usr/local/pkg/haproxy/haproxy.inc @@ -373,60 +373,6 @@ if (haproxy_version() >= '1.6') { #end - -if (!function_exists('group_ports')) { -// function group_ports() is present in pfSense 2.2 in util.inc -/* create ranges of sequential port numbers (200:215) and remove duplicates */ -function group_ports($ports) { - if (!is_array($ports) || empty($ports)) { - return; - } - - $uniq = array(); - foreach ($ports as $port) { - if (is_portrange($port)) { - list($begin, $end) = explode(":", $port); - if ($begin > $end) { - $aux = $begin; - $begin = $end; - $end = $aux; - } - for ($i = $begin; $i <= $end; $i++) - if (!in_array($i, $uniq)) - $uniq[] = $i; - } elseif (is_port($port)) { - if (!in_array($port, $uniq)) - $uniq[] = $port; - } - } - sort($uniq, SORT_NUMERIC); - - $result = array(); - foreach ($uniq as $idx => $port) { - if ($idx == 0) { - $result[] = $port; - continue; - } - - $last = end($result); - if (is_portrange($last)) { - list($begin, $end) = explode(":", $last); - } else { - $begin = $end = $last; - } - - if ($port == ($end+1)) { - $end++; - $result[count($result)-1] = "{$begin}:{$end}"; - } else { - $result[] = $port; - } - } - - return $result; -} -} - global $haproxy_version; function haproxy_version() { global $haproxy_version; @@ -536,12 +482,7 @@ function haproxy_custom_php_install_command() { $static_output .= "HAProxy, running haproxy_custom_php_install_command()\n"; update_output_window($static_output); - $pf_version=substr(trim(file_get_contents("/etc/version")),0,3); - if ($pf_version == "2.1" || $pf_version == "2.2") { - $haproxy_binary = "/usr/pbi/haproxy-devel-" . php_uname("m") . "/sbin/haproxy"; - } else { - $haproxy_binary = "/usr/local/sbin/haproxy"; - } + $haproxy_binary = "/usr/local/sbin/haproxy"; $static_output .= "HAProxy, create '/usr/local/etc/rc.d/haproxy.sh'\n"; update_output_window($static_output); @@ -2074,13 +2015,9 @@ function haproxy_generate_rules($type) { } function load_ipfw_rules() { - // On FreeBSD 8 pf does not support "divert-reply" so ipfw is needed. - global $g, $config; - if (haproxy_utils::$pf_version < 2.2) { - $ipfw_zone_haproxy = "haproxy"; - } else { - $ipfw_zone_haproxy = "4000"; // seems that 4000 is a safe zone number to avoid conflicts with captive portal.. and 4095 is the max? - } + // On FreeBSD 8/9/10/11 pf does not support "divert-reply" so ipfw is needed. + global $g; + $ipfw_zone_haproxy = "4000"; // seems that 4000 is a safe zone number to avoid conflicts with captive portal.. and 4095 is the max? haproxy_load_modules(); @@ -2094,19 +2031,10 @@ function load_ipfw_rules() { if (haproxy_utils::$pf_version < 2.4) { $rulenum = 64000; // why that high? captiveportal.inc also does it... - if (haproxy_utils::$pf_version < 2.2) { - // pfSense 2.1 FreeBSD 8.3 - mwexec("/usr/local/sbin/ipfw_context -a $ipfw_zone_haproxy", true); - - foreach($transparent_interfaces as $transparent_if => $value) { - mwexec("/usr/local/sbin/ipfw_context -a $ipfw_zone_haproxy -n $transparent_if", true); - } - } else { - // pfSense 2.2 FreeBSD 10 - mwexec("/sbin/ipfw zone $ipfw_zone_haproxy create", true); - foreach($transparent_interfaces as $transparent_if => $value) { - mwexec("/sbin/ipfw zone $ipfw_zone_haproxy madd $transparent_if", true); - } + // pfSense 2.2 FreeBSD 10 + mwexec("/sbin/ipfw zone $ipfw_zone_haproxy create", true); + foreach($transparent_interfaces as $transparent_if => $value) { + mwexec("/sbin/ipfw zone $ipfw_zone_haproxy madd $transparent_if", true); } } else { // pfSense 2.4, captive portal rules start at 1000 @@ -2127,9 +2055,6 @@ function load_ipfw_rules() { file_put_contents("{$g['tmp_path']}/ipfw_{$ipfw_zone_haproxy}.haproxy.rules", $rules); - if (haproxy_utils::$pf_version < 2.2) { - mwexec("/usr/local/sbin/ipfw_context -s $ipfw_zone_haproxy", true); - } if (haproxy_utils::$pf_version < 2.4) { mwexec("/sbin/ipfw -x $ipfw_zone_haproxy -q {$g['tmp_path']}/ipfw_{$ipfw_zone_haproxy}.haproxy.rules", true); } else { @@ -2183,7 +2108,7 @@ function haproxy_plugin_certificates($pluginparams) { $a_backends = $config['installedpackages']['haproxy']['ha_pools']['item']; if (is_array($a_backends)) { - foreach ($a_backends as &$backend) { + foreach ($a_backends as $backend) { if (is_array($backend['ha_servers']['item'])) { foreach($backend['ha_servers']['item'] as $srv) { if ($srv['ssl-server-clientcert']) { @@ -2272,12 +2197,8 @@ function haproxy_check_run($reload) { filter_configure(); load_ipfw_rules(); } else { - if (haproxy_utils::$pf_version < 2.2) { - mwexec("/usr/local/sbin/ipfw_context -d haproxy", true); - } else { - $ipfw_zone_haproxy = 4000; - mwexec("/sbin/ipfw zone $ipfw_zone_haproxy destroy", true); - } + $ipfw_zone_haproxy = 4000; + mwexec("/sbin/ipfw zone $ipfw_zone_haproxy destroy", true); } if (file_exists('/var/run/haproxy.pid')){ diff --git a/net/pfSense-pkg-haproxy-devel/files/usr/local/pkg/haproxy/haproxy_gui.inc b/net/pfSense-pkg-haproxy-devel/files/usr/local/pkg/haproxy/haproxy_gui.inc index 66cc6da8b85d..8f4f1dfca452 100644 --- a/net/pfSense-pkg-haproxy-devel/files/usr/local/pkg/haproxy/haproxy_gui.inc +++ b/net/pfSense-pkg-haproxy-devel/files/usr/local/pkg/haproxy/haproxy_gui.inc @@ -25,106 +25,52 @@ require_once("classes/autoload.inc.php"); $haproxy_icons = array( 'moveup' => array( - "faicon" => "fa-arrow-up", - "icon" => "icon_up.gif", - "iconsize" => 17), + "faicon" => "fa-arrow-up"), 'movedown' => array( - "faicon" => "fa-arrow-down", - "icon" => "icon_down.gif", - "iconsize" => 17), + "faicon" => "fa-arrow-down"), 'add' => array( - "faicon" => "fa-level-down", - "icon" => "icon_plus.gif", - "iconsize" => 17), + "faicon" => "fa-level-down"), 'delete' => array( - "faicon" => "fa-trash", - "icon" => "icon_x.gif", - "iconsize" => 17), + "faicon" => "fa-trash"), 'edit' => array( - "faicon" => "fa-pencil", - "icon" => "icon_e.gif", - "iconsize" => 17), + "faicon" => "fa-pencil"), 'clone' => array( - "faicon" => "fa-clone", - "icon" => "icon_plus.gif"), + "faicon" => "fa-clone"), 'acl' => array( - "faicon" => "fa-random", - "icon" => "icon_ts_rule.gif", - "iconsize" => 11), + "faicon" => "fa-random"), 'cert' => array( - "faicon" => "fa-lock", - "icon" => "icon_frmfld_cert.png", - "iconsize" => 11), + "faicon" => "fa-lock"), 'advanced' => array( - "faicon" => "fa-cog", - "icon" => "icon_advanced.gif", - "iconsize" => 11), + "faicon" => "fa-cog"), 'enabled' => array( - "faicon" => "fa-check", - "icon" => "icon_pass.gif", - "iconsize" => 11), + "faicon" => "fa-check"), 'disabled' => array( - "faicon" => "fa-ban", - "icon" => "icon_reject.gif", - "iconsize" => 11), + "faicon" => "fa-ban"), 'stats' => array( - "faicon" => "fa-tasks", - "icon" => "icon_log_s.gif", - "iconsize" => 11), + "faicon" => "fa-tasks"), 'stop' => array( - "faicon" => "fa-stop-circle-o", - "icon" => "icon_service_stop.gif", - "iconsize" => 17), + "faicon" => "fa-stop-circle-o"), 'start' => array( - "faicon" => "fa-play-circle", - "icon" => "icon_service_start.gif", - "iconsize" => 17), + "faicon" => "fa-play-circle"), 'up' => array( - "faicon" => "fa-check-circle", - "icon" => "icon_interface_up.gif", - "iconsize" => 11), + "faicon" => "fa-check-circle"), 'down' => array( - "faicon" => "fa-times-circle", - "icon" => "icon_interface_down.gif", - "iconsize" => 11), + "faicon" => "fa-times-circle"), 'resolvedns' => array( - "faicon" => "fa-info", - "icon" => "icon_log.gif", - "iconsize" => 11), + "faicon" => "fa-info"), 'help' => array( - "faicon" => "fa-info-circle", - "icon" => "icon_help.gif", - "iconsize" => 11), + "faicon" => "fa-info-circle"), 'expand' => array( - "faicon" => "fa-plus-square-o", - "icon" => "plus.gif", - "iconsize" => 11) - + "faicon" => "fa-plus-square-o") ); -global $pf_version; -$pf_version = substr(trim(file_get_contents("/etc/version")), 0, 3); - -if(!function_exists('pf_version')) { - function pf_version() { - global $pf_version; - return $pf_version; - } -} - function haproxyicon($iconname, $title) { - global $g, $haproxy_icons; + global $haproxy_icons; $title = htmlspecialchars($title); $title = str_replace("'", "'", $title); $faicon = $haproxy_icons[$iconname]["faicon"]; - if (pf_version() < "2.3") { - $icon = $haproxy_icons[$iconname]["icon"]; - $iconsize = $haproxy_icons[$iconname]["iconsize"]; - return ""; - } else { - return ""; - } + return ""; } class Form_Section_class extends Form_Section { diff --git a/net/pfSense-pkg-haproxy-devel/files/usr/local/www/haproxy/haproxy_listeners_edit.php b/net/pfSense-pkg-haproxy-devel/files/usr/local/www/haproxy/haproxy_listeners_edit.php index eb3f7f2aecc1..a348dc5348ed 100644 --- a/net/pfSense-pkg-haproxy-devel/files/usr/local/www/haproxy/haproxy_listeners_edit.php +++ b/net/pfSense-pkg-haproxy-devel/files/usr/local/www/haproxy/haproxy_listeners_edit.php @@ -335,7 +335,6 @@ function fields_actions_details_showfieldfunction($htmltable, $itemname, $values $reqdfieldsn = explode(",", "Name"); } - $pf_version=substr(trim(file_get_contents("/etc/version")), 0, 3); do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); if (preg_match("/[^a-zA-Z0-9\.\-_]/", $_POST['name'])) { diff --git a/net/pfSense-pkg-haproxy-devel/files/usr/local/www/widgets/widgets/haproxy.widget.php b/net/pfSense-pkg-haproxy-devel/files/usr/local/www/widgets/widgets/haproxy.widget.php index abec8e6846c3..064a2d976fd9 100644 --- a/net/pfSense-pkg-haproxy-devel/files/usr/local/www/widgets/widgets/haproxy.widget.php +++ b/net/pfSense-pkg-haproxy-devel/files/usr/local/www/widgets/widgets/haproxy.widget.php @@ -263,13 +263,7 @@ function control_haproxy(act,be,srv) { getURL(url+"?"+pars, getstatusgetupdate); } -'; -} else { - echo '