Skip to content

Commit

Permalink
Merge pull request #535 from PiBa-NL/20180709-haproxy-0.57b
Browse files Browse the repository at this point in the history
  • Loading branch information
rbgarga committed Jul 12, 2018
2 parents d6f8c6c + 0ddb027 commit c5dfeeb
Show file tree
Hide file tree
Showing 11 changed files with 563 additions and 267 deletions.
3 changes: 1 addition & 2 deletions net/pfSense-pkg-haproxy-devel/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# $FreeBSD$

PORTNAME= pfSense-pkg-haproxy-devel
PORTVERSION= 0.58
PORTREVISION= 5
PORTVERSION= 0.59
CATEGORIES= net
MASTER_SITES= # empty
DISTFILES= # empty
Expand Down
275 changes: 224 additions & 51 deletions net/pfSense-pkg-haproxy-devel/files/usr/local/pkg/haproxy/haproxy.inc

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class HaproxyHtmlList
} else {
$result .= htmlspecialchars($itemvalue);
}
$result = "<div id='".$itemnamenr."_disp'>".$result."</div>";
}
return $result;
}
Expand All @@ -176,6 +177,9 @@ class HaproxyHtmlList
<tr>
<th><!-- checkbox --></th>";
foreach($items as $item){
if ($item['type'] == 'hidden') {
continue;
}
$result .= "<th>{$item['columnheader']}</th>";
}
$result .= "<th>Actions</th>
Expand Down Expand Up @@ -205,9 +209,12 @@ class HaproxyHtmlList

$leftitem = true;
foreach($items as $item) {
$result .= "<td>";
$itemname = $item['name'];
$itemvalue = $value[$itemname];
if ($item['type'] == 'hidden') {
continue;
}
$result .= "<td>";
if (isset($item['customdrawcell'])) {
$result .= $item['customdrawcell']($this, $item, $itemvalue, false, $itemname, $counter);
} else {
Expand All @@ -218,17 +225,19 @@ class HaproxyHtmlList

}
$result .= "
<td class='action-icons'>
<td class='action-buttons'>
<a onclick='editRow({$counter}); return false;'>".haproxyicon('edit','edit entry')."</a>
<a onclick='deleteRow({$counter}, \"{$tablename}\"); return false;'>".haproxyicon('delete','delete entry')."</a>
<a onclick='dupRow({$counter}, \"{$tablename}\"); return false;'>".haproxyicon('clone','duplicate entry')."</a>
";
if (empty($this->noindex)) {
/* // shouldnt need this anymore.. the checkbox+anchor is implemented everywhere..
* if (empty($this->noindex)) {
$result .= "
<a onclick='moveRowUp({$counter}, \"{$tablename}\"); return false;'>".haproxyicon('moveup','move row up')."</a>
<a onclick='moveRowDown({$counter}, \"{$tablename}\"); return false;'>".haproxyicon('movedown','move row down')."</a>
";
}
*/
$result .= "
</td>";
$result .= "</tr>";
Expand All @@ -239,9 +248,15 @@ class HaproxyHtmlList
<input type='checkbox' id='frec{$counter}' onClick='fr_toggle_two({$counter},this)' name='{$tablename}_row[]' value='{$counter}'/>
<a class='fa fa-anchor' id='Xmove_{$counter}' onClick='moveRowUpAboveAnchor({$counter}, \"{$tablename}\")' title='".gettext("Move checked entries to here")."'></a>
</td>";
$hiddenitems = "";
foreach($items as $item){
$itemname = $item['name'];
$itemvalue = $value[$itemname];
if ($item['type'] == 'hidden') {
$rowitemname = $this->tablename . $itemname . $counter;
$hiddenitems .= "<input name='{$rowitemname}' type='hidden' value='{$itemvalue}' />";
continue;
}
$result .= "<td>".$key;
if (isset($item['customdrawcell'])) {
$result .= $item['customdrawcell']($this, $item, $itemvalue, true, $itemname, $counter);
Expand All @@ -252,17 +267,12 @@ class HaproxyHtmlList
$key = "";
}
$result .= "
<td class='action-icons'>
<td class='action-buttons'>
{$hiddenitems}
<input name='{$tablename}_rowindex[]' id='{$tablename}_rowindex{$counter}' class='hidden' value='{$counter}' />
<a onclick='deleteRow({$counter}, \"{$tablename}\"); return false;' >".haproxyicon('delete','delete entry')."</a>
<a onclick='dupRow({$counter}, \"{$tablename}\"); return false;' >".haproxyicon('clone','duplicate entry')."</a>
";
if (empty($this->noindex)) {
$result .= "
<a onclick='moveRowUp({$counter}, \"{$tablename}\"); return false;' >".haproxyicon('moveup','move row up')."</a>
<a onclick='moveRowDown({$counter}, \"{$tablename}\"); return false;' >".haproxyicon('movedown','move row down')."</a>
";
}
$result .= "
</td>";
$result .= "</tr>";
Expand All @@ -282,6 +292,7 @@ EOT
$leftitem = true;
foreach($itemdetails as $item) {
$itemname = $item['name'];
$itemid = "{$tablename}{$itemname}{$counter}";
$itemvalue = $value[$itemname];
if ($this->fields_details_showfieldfunction != null) {
// filter context un-related items through customizable function.
Expand All @@ -293,7 +304,7 @@ EOT
if (empty($itemvalue)) {
continue;
}
$result .= "<div style='float: left;padding-right: 2px;'>";
$result .= "<div style='float: left;padding-right: 2px;' id='".$itemid."_disp'>";
$tdclass = "";
if (!$leftitem) {
$result .= ", ";
Expand Down Expand Up @@ -451,14 +462,17 @@ function haproxy_htmllist_js(){
tr.appendChild(td);

for (var i in items) {
if (items[i]['type']=='hidden') {
continue;//dont copy hidden fields.. like a id field that should stay unique
}
fieldhtml = createFieldHtml(tableId, items[i], totalrows);
td = d.createElement("td");
td.innerHTML = fieldhtml;
tr.appendChild(td);
fieldcount += 1;
}
td = d.createElement("td");
td.setAttribute("class","action-icons");
td.setAttribute("class","action-buttons");

// Recreate the action icons.
var actions = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,104 @@ function haproxy_upgrade_config() {
}
$configversion = "00.32";
}
if ($configversion < "00.57") {
$haproxycfg = &$config['installedpackages']['haproxy'];
$a_frontend = &$haproxycfg['ha_backends']['item'];
// - assign unique ID's to all backends and servers for saving/loading server-state file
//
// - the backend nolonger automaticaly 'guesses' the desired backend ssl/check-ssl flags..
// so to keep existing behaviour the backends that are used multiple times
// are automatically duplicated with different ssl/checkssl options
// with settings being explicitly this allows for the user to control when ssl is or isnt used
// also for tcp frontend/backend combinations where for example ldaps could pass along

$id = 100;
$newbackends = array();
foreach($haproxycfg['ha_pools']['item'] as &$backend) {
$id++;
$backend['id'] = $id;

$fes = find_frontends_using_backend($backend['name']);
$httpfrontend = false;
$tcpfrontend = false;
foreach($fes as $fename) {
$frontend = $a_frontend[get_frontend_id($fename)];
if ($frontend['type'] == "http") {
$httpfrontend = true;
} else {
$tcpfrontend = true;
}
}
if ($httpfrontend && $tcpfrontend) {
// we have both types.. so duplicate it once for the ssl one..
$newbackend = $backend;
$oldvalue = $newbackend['name'];
$newbackend['name'] = $newbackend['name'] . "_ssl";
$newvalue = $newbackend['name'];
$id++;
$newbackend['id'] = $id;
if (is_array($newbackend['ha_servers']['item'])) {
foreach($newbackend['ha_servers']['item'] as &$server) {
$id++;
$server['id'] = $id;
if ($tcpfrontend && $server['ssl'] == 'yes') {
// https frontend used to automatically switch to using the check-ssl setting..
unset($server['ssl']);
$server['checkssl'] = 'yes';
}
}
}
$newbackends[] = $newbackend;

// rename backend references where required.
$a_frontends = &$config['installedpackages']['haproxy']['ha_backends']['item'];
foreach ($a_frontends as &$frontend) {
if ($frontend['type'] == 'http') {
continue;
}
if ($frontend['backend_serverpool'] == $oldvalue) {
$frontend['backend_serverpool'] = $newvalue;
}
if (is_array($frontend['a_actionitems']['item'])) {
foreach($frontend['a_actionitems']['item'] as &$item) {
if ($item['action'] == "use_backend") {
if ($item['use_backendbackend'] == $oldvalue) {
$item['use_backendbackend'] = $newvalue;
}
}
}
}
}
unset($frontend);

} else {
// only https/tcp frontends to this backend..
if (is_array($backend['ha_servers']['item'])) {
foreach($backend['ha_servers']['item'] as &$server) {
$id++;
$server['id'] = $id;
if (!$httpfrontend && $server['ssl'] == 'yes') {
// https frontend used to automatically switch to using the check-ssl setting..
unset($server['ssl']);
$server['checkssl'] = true;
}
}
}
}
}
unset($backend);
// add duplicated backends to the config.
foreach($newbackends as $newbackend) {
$haproxycfg['ha_pools']['item'][] = $newbackend;
}
$configversion = "00.57";
}

$writeconfigupdate = $config['installedpackages']['haproxy']['configversion'] <> $configversion;
if ($writeconfigupdate) {
$config['installedpackages']['haproxy']['configversion'] = $configversion;
$static_output .= "HAProxy, write updated config to version: $configversion\n";
update_output_window($static_output);
write_config("HAProxy, update xml config version");
write_config("HAProxy, update xml config version to version: ". $configversion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ if(!function_exists('is_arrayset')){
}
}

function &getarraybyref(&$array) {
if (!isset($array)) {
return false;
}
$item = &$array;
$arg = func_get_args();
for($i = 1; $i < count($arg); $i++) {
$itemindex = $arg[$i];
if (!is_array($item[$itemindex])) {
$item[$itemindex] = array();
}
$item = &$item[$itemindex];
}
return $item;
}

function haproxy_compareByName($a, $b) {
return strcasecmp($a['name'], $b['name']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ function xmlrpc_sync_execute($syncinfo) {
}

function xmlrpc_sync_execute_24($sync_logname, $xml, $sync_include,$sync_function) {
global $config;
if (!is_array($config['hasync']) || empty($config['hasync']['synchronizetoip'])) {
syslog(LOG_NOTICE, "haproxy: cannot sync configuration (no ip/host configured to sync to on this machine), disable sync to avoid this message.");
return;
}

require_once("xmlrpc_client.inc");

$rpc_client = new pfsense_xmlrpc_client();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,8 @@

$changedesc = "Services: HAProxy: Frontends";

if (!is_array($config['installedpackages']['haproxy'])) {
$config['installedpackages']['haproxy'] = array();
}

if (!is_array($config['installedpackages']['haproxy']['ha_backends'])) {
$config['installedpackages']['haproxy']['ha_backends'] = array();
}
haproxy_config_init();

if (!is_array($config['installedpackages']['haproxy']['ha_backends']['item'])) {
$config['installedpackages']['haproxy']['ha_backends']['item'] = array();
}
$a_frontend = &$config['installedpackages']['haproxy']['ha_backends']['item'];

function array_moveitemsbefore(&$items, $before, $selected) {
Expand Down Expand Up @@ -435,7 +426,7 @@ function sort_sharedfrontends(&$a, &$b) {
}
?>
</td>
<td class="action-icons">
<td class="action-buttons">
<button style="display: none;" class="btn btn-default btn-xs" type="submit" id="move_<?=$frontendname?>" name="move_<?=$frontendname?>" value="move_<?=$frontendname?>"></button>
<a href="haproxy_listeners_edit.php?id=<?=$frontendname;?>">
<?=haproxyicon("edit", gettext("edit frontend"))?>
Expand Down
Loading

0 comments on commit c5dfeeb

Please sign in to comment.