Commit 47b56236 authored by Ad Schellevis's avatar Ad Schellevis

(legacy) fix spacing and curly braces in vslb.inc

parent a1a8129f
......@@ -41,8 +41,8 @@ function subnetv4_expand($subnet) {
/* include all configuration functions */
class Monitor {
class Monitor
{
private $conf = array();
function __construct($config) {
$this->conf = $config;
......@@ -59,19 +59,23 @@ class Monitor {
}
}
class TCPMonitor extends Monitor {
class TCPMonitor extends Monitor
{
protected $proto = 'tcp';
}
class SSLMonitor extends Monitor {
class SSLMonitor extends Monitor
{
protected $proto = 'ssl';
}
class ICMPMonitor extends Monitor {
class ICMPMonitor extends Monitor
{
protected $proto = 'icmp';
}
class HTTPMonitor extends Monitor {
class HTTPMonitor extends Monitor
{
protected $proto = 'http';
function __construct($config) {
parent::__construct($config);
......@@ -98,7 +102,8 @@ class HTTPMonitor extends Monitor {
}
}
class HTTPSMonitor extends HTTPMonitor {
class HTTPSMonitor extends HTTPMonitor
{
protected $proto = 'https';
}
......@@ -111,7 +116,6 @@ class SendMonitor extends Monitor {
return "check {$this->proto} {$this->data()} expect {$this->pattern()} {$this->ssl()}";
}
private function data() {
return $this->config('send') != "" ? "\"{$this->config('send')}\"" : "\"\"";
}
......@@ -125,11 +129,6 @@ class SendMonitor extends Monitor {
}
}
function relady_configure_full()
{
relayd_configure(true);
}
function relayd_configure($kill_first = false)
{
global $config;
......@@ -170,7 +169,7 @@ function relayd_configure($kill_first = false)
$mon = new SendMonitor($type['options']);
break;
}
if($mon) {
if ($mon) {
$check_a[$type['name']] = $mon->p();
}
}
......@@ -200,9 +199,9 @@ function relayd_configure($kill_first = false)
/* reindex pools by name as we loop through the pools array */
$pools = array();
/* Virtual server pools */
if(is_array($pool_a)) {
if (is_array($pool_a)) {
for ($i = 0; isset($pool_a[$i]); $i++) {
if(is_array($pool_a[$i]['servers'])) {
if (is_array($pool_a[$i]['servers'])) {
if (!empty($pool_a[$i]['retry'])) {
$retrytext = " retry {$pool_a[$i]['retry']}";
} else {
......@@ -214,8 +213,7 @@ function relayd_configure($kill_first = false)
foreach (subnetv4_expand($server) as $ip) {
$conf .= "\t{$ip}{$retrytext}\n";
}
}
else {
} else {
$conf .= "\t{$server}{$retrytext}\n";
}
}
......@@ -230,25 +228,21 @@ function relayd_configure($kill_first = false)
$conf .= "\t" . "tcp { nodelay, sack, socket buffer 1024, backlog 1000 }\n";
$conf .= "}\n";
if(is_array($vs_a)) {
if (is_array($vs_a)) {
for ($i = 0; isset($vs_a[$i]); $i++) {
$append_port_to_name = false;
if (is_alias($pools[$vs_a[$i]['poolname']]['port'])) {
$dest_port_array = filter_expand_alias_array($pools[$vs_a[$i]['poolname']]['port']);
$append_port_to_name = true;
}
else {
} else {
$dest_port_array = array($pools[$vs_a[$i]['poolname']]['port']);
}
if (is_alias($vs_a[$i]['port'])) {
$src_port_array = filter_expand_alias_array($vs_a[$i]['port']);
$append_port_to_name = true;
}
else if ($vs_a[$i]['port']) {
} elseif ($vs_a[$i]['port']) {
$src_port_array = array($vs_a[$i]['port']);
}
else {
} else {
$src_port_array = $dest_port_array;
}
......@@ -259,18 +253,15 @@ function relayd_configure($kill_first = false)
log_error("item is $item");
if (is_subnetv4($item)) {
$ip_list = array_merge($ip_list, subnetv4_expand($item));
}
else {
} else {
$ip_list[] = $item;
}
}
$append_ip_to_name = true;
}
else if (is_subnetv4($vs_a[$i]['ipaddr'])) {
} elseif (is_subnetv4($vs_a[$i]['ipaddr'])) {
$ip_list = subnetv4_expand($vs_a[$i]['ipaddr']);
$append_ip_to_name = true;
}
else {
} else {
$ip_list = array($vs_a[$i]['ipaddr']);
}
......@@ -304,20 +295,23 @@ function relayd_configure($kill_first = false)
$conf .= " forward to <{$vs_a[$i]['poolname']}> port {$dest_port} {$lbmode} {$check_a[$pools[$vs_a[$i]['poolname']]['monitor']]} \n";
if (isset($vs_a[$i]['sitedown']) && strlen($vs_a[$i]['sitedown']) > 0 && ($vs_a[$i]['relay_protocol'] != 'dns'))
if (isset($vs_a[$i]['sitedown']) && strlen($vs_a[$i]['sitedown']) > 0 && ($vs_a[$i]['relay_protocol'] != 'dns')) {
$conf .= " forward to <{$vs_a[$i]['sitedown']}> port {$dest_port} {$lbmode} {$check_a[$pools[$vs_a[$i]['poolname']]['monitor']]} \n";
}
$conf .= "}\n";
} else {
$conf .= "redirect \"{$name}\" {\n";
$conf .= " listen on {$ip} port {$src_port}\n";
$conf .= " forward to <{$vs_a[$i]['poolname']}> port {$dest_port} {$check_a[$pools[$vs_a[$i]['poolname']]['monitor']]} \n";
if (isset($config['system']['lb_use_sticky']))
if (isset($config['system']['lb_use_sticky'])) {
$conf .= " sticky-address\n";
}
/* sitedown MUST use the same port as the primary pool - sucks, but it's a relayd thing */
if (isset($vs_a[$i]['sitedown']) && strlen($vs_a[$i]['sitedown']) > 0 && ($vs_a[$i]['relay_protocol'] != 'dns'))
if (isset($vs_a[$i]['sitedown']) && strlen($vs_a[$i]['sitedown']) > 0 && ($vs_a[$i]['relay_protocol'] != 'dns')) {
$conf .= " forward to <{$vs_a[$i]['sitedown']}> port {$dest_port} {$check_a[$pools[$vs_a[$i]['sitedown']]['monitor']]} \n";
}
$conf .= "}\n";
}
......@@ -351,17 +345,16 @@ function relayd_configure($kill_first = false)
/* Remove all active relayd anchors now that relayd is no longer running. */
cleanup_lb_anchor("*");
}
} else {
if (! empty($vs_a)) {
} elseif (!empty($vs_a)) {
// not running and there is a config, start it
/* Remove all active relayd anchors so it can start fresh. */
cleanup_lb_anchor('*');
mwexec('/usr/local/sbin/relayd -f /var/etc/relayd.conf');
}
}
}
function get_lb_redirects() {
function get_lb_redirects()
{
/*
# relayctl show summary
Id Type Name Avlblty Status
......@@ -401,7 +394,7 @@ Id Type Name Avlblty Status
$line = $rdr_a[$i];
if (preg_match("/^[0-9]+/", $line)) {
$regs = array();
if($x = preg_match("/^[0-9]+\s+redirect\s+([^\s]+)\s+([^\s]+)/", $line, $regs)) {
if ($x = preg_match("/^[0-9]+\s+redirect\s+([^\s]+)\s+([^\s]+)/", $line, $regs)) {
$cur_entry = trim($regs[1]);
$vs[trim($regs[1])] = array();
$vs[trim($regs[1])]['status'] = trim($regs[2]);
......@@ -419,7 +412,7 @@ Id Type Name Avlblty Status
$line = $relay_a[$i];
if (preg_match("/^[0-9]+/", $line)) {
$regs = array();
if($x = preg_match("/^[0-9]+\s+relay\s+([^\s]+)\s+([^\s]+)/", $line, $regs)) {
if ($x = preg_match("/^[0-9]+\s+relay\s+([^\s]+)\s+([^\s]+)/", $line, $regs)) {
$cur_entry = trim($regs[1]);
$vs[trim($regs[1])] = array();
$vs[trim($regs[1])]['status'] = trim($regs[2]);
......@@ -435,7 +428,8 @@ Id Type Name Avlblty Status
return $vs;
}
function get_lb_summary() {
function get_lb_summary()
{
$relayctl = array();
exec('/usr/local/sbin/relayctl show summary 2>&1', $relayctl);
$relay_hosts=Array();
......@@ -471,7 +465,8 @@ function get_lb_anchors() {
/* Remove NAT rules from a relayd anchor that is no longer in use.
$anchorname can either be * to clear all anchors or a specific anchor name.*/
function cleanup_lb_anchor($anchorname = "*") {
function cleanup_lb_anchor($anchorname = "*")
{
$lbanchors = get_lb_anchors();
foreach ($lbanchors as $lba) {
if (($anchorname == "*") || ($lba == "relayd/{$anchorname}")) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment