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

haproxy, haproxy-devel, cleanup old pfSense 2.2/2.1 compatibility checks in code #245

Merged
merged 1 commit into from
Jan 4, 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 net/pfSense-pkg-haproxy-devel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

PORTNAME= pfSense-pkg-haproxy-devel
PORTVERSION= 0.52
PORTREVISION= 3
PORTREVISION= 4
CATEGORIES= net
MASTER_SITES= # empty
DISTFILES= # empty
Expand Down
101 changes: 11 additions & 90 deletions net/pfSense-pkg-haproxy-devel/files/usr/local/pkg/haproxy/haproxy.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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']) {
Expand Down Expand Up @@ -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')){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("'", "&#39;", $title);

$faicon = $haproxy_icons[$iconname]["faicon"];
if (pf_version() < "2.3") {
$icon = $haproxy_icons[$iconname]["icon"];
$iconsize = $haproxy_icons[$iconname]["iconsize"];
return "<img src='/themes/{$g['theme']}/images/icons/$icon' title='$title' width='$iconsize' height='$iconsize' border='0' />";
} else {
return "<i class='fa $faicon' title='$title'></i>";
}
return "<i class='fa $faicon' title='$title'></i>";
}

class Form_Section_class extends Form_Section {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,7 @@ function control_haproxy(act,be,srv) {
getURL(url+"?"+pars, getstatusgetupdate);
}
</script>
<?php
if (pf_version() < "2.3") {
echo '<div id="haproxy-settings" class="widgetconfigdiv" style="display:none;">';
} else {
echo '<div id="widget-haproxy_panel-footer" class="panel-footer collapse">';
}
?>
<div id="widget-haproxy_panel-footer" class="panel-footer collapse">
<form action="/widgets/widgets/haproxy.widget.php" method="post" name="iform" id="iform">
<table>
<tr><td>
Expand Down
2 changes: 1 addition & 1 deletion net/pfSense-pkg-haproxy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

PORTNAME= pfSense-pkg-haproxy
PORTVERSION= 0.52
PORTREVISION= 3
PORTREVISION= 4
CATEGORIES= net
MASTER_SITES= # empty
DISTFILES= # empty
Expand Down
Loading