Commit fadc0ab5 authored by Franco Fichtner's avatar Franco Fichtner

load balancer (relayd): remove from core

parent 44e4ae85
......@@ -135,7 +135,6 @@ CORE_DEPENDS?= apinger \
py${CORE_PY}-ujson \
radvd \
rate \
relayd \
rrdtool12 \
samplicator \
squid \
......
......@@ -51,9 +51,6 @@
/usr/local/etc/inc/plugins.inc.d/netflow.inc
/usr/local/etc/inc/plugins.inc.d/ntpd.inc
/usr/local/etc/inc/plugins.inc.d/pf.inc
/usr/local/etc/inc/plugins.inc.d/relayd.inc
/usr/local/etc/inc/plugins.inc.d/relayd/dns.proto
/usr/local/etc/inc/plugins.inc.d/relayd/tcp.proto
/usr/local/etc/inc/plugins.inc.d/squid.inc
/usr/local/etc/inc/plugins.inc.d/suricata.inc
/usr/local/etc/inc/plugins.inc.d/unbound.inc
......@@ -456,8 +453,6 @@
/usr/local/opnsense/mvc/app/models/OPNsense/Proxy/Migrations/M1_0_0.php
/usr/local/opnsense/mvc/app/models/OPNsense/Proxy/Proxy.php
/usr/local/opnsense/mvc/app/models/OPNsense/Proxy/Proxy.xml
/usr/local/opnsense/mvc/app/models/OPNsense/Relayd/ACL/ACL.xml
/usr/local/opnsense/mvc/app/models/OPNsense/Relayd/Menu/Menu.xml
/usr/local/opnsense/mvc/app/models/OPNsense/TrafficShaper/ACL/ACL.xml
/usr/local/opnsense/mvc/app/models/OPNsense/TrafficShaper/Menu/Menu.xml
/usr/local/opnsense/mvc/app/models/OPNsense/TrafficShaper/Migrations/M1_0_0.php
......@@ -954,7 +949,6 @@
/usr/local/www/diag_logs_openvpn.php
/usr/local/www/diag_logs_ppp.php
/usr/local/www/diag_logs_proxy.php
/usr/local/www/diag_logs_relayd.php
/usr/local/www/diag_logs_resolver.php
/usr/local/www/diag_logs_routing.php
/usr/local/www/diag_logs_settings.php
......@@ -1022,13 +1016,6 @@
/usr/local/www/javascript/wizard/disablekeys.js
/usr/local/www/javascript/wizard/suggestions.js
/usr/local/www/license.php
/usr/local/www/load_balancer_monitor.php
/usr/local/www/load_balancer_monitor_edit.php
/usr/local/www/load_balancer_pool.php
/usr/local/www/load_balancer_pool_edit.php
/usr/local/www/load_balancer_setting.php
/usr/local/www/load_balancer_virtual_server.php
/usr/local/www/load_balancer_virtual_server_edit.php
/usr/local/www/reboot.php
/usr/local/www/reporting_settings.php
/usr/local/www/services_dhcp.php
......@@ -1063,8 +1050,6 @@
/usr/local/www/status_graph.php
/usr/local/www/status_habackup.php
/usr/local/www/status_interfaces.php
/usr/local/www/status_lb_pool.php
/usr/local/www/status_lb_vs.php
/usr/local/www/status_ntpd.php
/usr/local/www/status_openvpn.php
/usr/local/www/status_services.php
......@@ -1118,7 +1103,6 @@
/usr/local/www/widgets/include/interface_statistics.inc
/usr/local/www/widgets/include/interfaces.inc
/usr/local/www/widgets/include/ipsec.inc
/usr/local/www/widgets/include/load_balancer.inc
/usr/local/www/widgets/include/log.inc
/usr/local/www/widgets/include/ntp_status.inc
/usr/local/www/widgets/include/openvpn.inc
......@@ -1132,7 +1116,6 @@
/usr/local/www/widgets/widgets/interface_list.widget.php
/usr/local/www/widgets/widgets/interface_statistics.widget.php
/usr/local/www/widgets/widgets/ipsec.widget.php
/usr/local/www/widgets/widgets/load_balancer_status.widget.php
/usr/local/www/widgets/widgets/log.widget.php
/usr/local/www/widgets/widgets/ntp_status.widget.php
/usr/local/www/widgets/widgets/openvpn.widget.php
......
<?php
/*
Copyright (C) 2016 Franco Fichtner <franco@opnsense.org>
Copyright (C) 2005-2008 Bill Marquette
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
function relayd_enabled()
{
global $config;
return isset($config['load_balancer']['lbpool']) && count($config['load_balancer']['lbpool']) &&
isset($config['load_balancer']['virtual_server']) && count($config['load_balancer']['virtual_server']);
}
function relayd_firewall($fw)
{
if (!relayd_enabled()) {
return;
}
$fw->registerAnchor('relayd/*', 'rdr');
$fw->registerAnchor('relayd/*', 'fw');
}
function relayd_services()
{
$services = array();
if (!relayd_enabled()) {
return $services;
}
$pconfig = array();
$pconfig['name'] = 'relayd';
$pconfig['description'] = gettext('Relayd Load Balancer');
$pconfig['php']['restart'] = array('relayd_configure_do');
$pconfig['php']['start'] = array('relayd_configure_do');
$services[] = $pconfig;
return $services;
}
function relayd_xmlrpc_sync()
{
$result = array();
$result[] = array(
'description' => gettext('Relayd Load Balancer'),
'section' => 'load_balancer',
'id' => 'lb',
);
return $result;
}
function relayd_syslog()
{
$logfacilities = array();
$logfacilities['relayd'] = array('facility' => array('relayd'), 'remote' => 'relayd');
return $logfacilities;
}
function relayd_subnetv4_expand($subnet)
{
$result = array();
list ($ip, $bits) = explode("/", $subnet);
$net = ip2long($ip);
$mask = (0xffffffff << (32 - $bits));
$net &= $mask;
$size = round(exp(log(2) * (32 - $bits)));
for ($i = 0; $i < $size; $i += 1) {
$result[] = long2ip($net | $i);
}
return $result;
}
function relayd_configure()
{
return array(
'bootup' => array('relayd_configure_do'),
'remote' => array('relayd_configure_do'),
);
}
function relayd_configure_do($kill_first = false)
{
global $config;
if (isset($config['load_balancer']['virtual_server']) && is_array($config['load_balancer']['virtual_server'])) {
$vs_a = $config['load_balancer']['virtual_server'];
} else {
$vs_a = array();
}
if (isset($config['load_balancer']['lbpool']) && is_array($config['load_balancer']['lbpool'])) {
$pool_a = $config['load_balancer']['lbpool'];
} else {
$pool_a = array();
}
if (isset($config['load_balancer']['setting']) && is_array($config['load_balancer']['setting'])) {
$setting = $config['load_balancer']['setting'];
} else {
$setting = array();
}
if (isset($config['load_balancer']['monitor_type']) && is_array($config['load_balancer']['monitor_type'])) {
$monitors_a = $config['load_balancer']['monitor_type'];
} else {
$monitors_a = array();
}
$check_a = array();
foreach ($monitors_a as $type) {
$type['options'] = isset($type['options']) ? $type['options'] : array();
switch($type['type']) {
case 'icmp':
case 'tcp':
$check_a[$type['name']] = 'check ' . $type['type'];
break;
case 'http':
case 'https':
$check_a[$type['name']] = 'check ' . $type['type']. " ";
if (!empty($type['options']['path'])) {
$check_a[$type['name']] .= "'".$type['options']['path'] . "' ";
}
if (!empty($type['options']['host'])) {
$check_a[$type['name']] .= "host ".$type['options']['host'] . " ";
}
$check_a[$type['name']] .= "code " . $type['options']['code'];
break;
case 'send':
$check_a[$type['name']] = "send ";
$check_a[$type['name']] .= !empty($type['options']['send']) ? "\"{$type['options']['send']}\"" : "\"\"" ;
$check_a[$type['name']] .= " expect ";
$check_a[$type['name']] .= !empty($type['options']['expect']) ? "\"{$type['options']['expect']}\"" : "\"\"" ;
break;
}
}
$fd = fopen('/var/etc/relayd.conf', 'w');
$conf = "log updates \n";
if (!empty($setting['timeout'])) {
$conf .= "timeout ".$setting['timeout']." \n";
} else {
$conf .= "timeout 1000 \n";
}
if (!empty($setting['interval'])) {
$conf .= "interval ".$setting['interval']." \n";
}
if (!empty($setting['prefork'])) {
$conf .= "prefork ".$setting['prefork']." \n";
}
/* reindex pools by name as we loop through the pools array */
$pools = array();
/* Virtual server pools */
for ($i = 0; isset($pool_a[$i]); $i++) {
if (is_array($pool_a[$i]['servers'])) {
if (!empty($pool_a[$i]['retry'])) {
$retrytext = " retry {$pool_a[$i]['retry']}";
} else {
$retrytext = "";
}
$conf .= "table <{$pool_a[$i]['name']}> {\n";
foreach ($pool_a[$i]['servers'] as $server) {
if (is_subnetv4($server)) {
foreach (relayd_subnetv4_expand($server) as $ip) {
$conf .= "\t{$ip}{$retrytext}\n";
}
} else {
$conf .= "\t{$server}{$retrytext}\n";
}
}
$conf .= "}\n";
/* Index by name for easier fetching when we loop through the virtual servers */
$pools[$pool_a[$i]['name']] = $pool_a[$i];
}
}
// collect used protocols
$used_protocols = array();
foreach ($vs_a as $vs) {
if (isset($vs['relay_protocol']) && !in_array($vs['relay_protocol'], $used_protocols)) {
$used_protocols[] = $vs['relay_protocol'];
if (is_file('/usr/local/etc/inc/plugins.inc.d/relayd/'.basename($vs['relay_protocol']).'.proto')) {
$conf .= file_get_contents('/usr/local/etc/inc/plugins.inc.d/relayd/'.basename($vs['relay_protocol']).'.proto')."\n";
}
}
}
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 {
$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;
} elseif ($vs_a[$i]['port']) {
$src_port_array = array($vs_a[$i]['port']);
} else {
$src_port_array = $dest_port_array;
}
$append_ip_to_name = false;
if (is_alias($vs_a[$i]['ipaddr'])) {
$ip_list = array();
foreach (filter_expand_alias_array($vs_a[$i]['ipaddr']) as $item) {
log_error("item is $item");
if (is_subnetv4($item)) {
$ip_list = array_merge($ip_list, relayd_subnetv4_expand($item));
} else {
$ip_list[] = $item;
}
}
$append_ip_to_name = true;
} elseif (is_subnetv4($vs_a[$i]['ipaddr'])) {
$ip_list = relayd_subnetv4_expand($vs_a[$i]['ipaddr']);
$append_ip_to_name = true;
} else {
$ip_list = array($vs_a[$i]['ipaddr']);
}
for ($j = 0; $j < count($ip_list); $j += 1) {
$ip = $ip_list[$j];
for ($k = 0; $k < count($src_port_array) && $k < count($dest_port_array); $k += 1) {
$src_port = $src_port_array[$k];
$dest_port = $dest_port_array[$k];
$name = $vs_a[$i]['name'];
if ($append_ip_to_name) {
$name .= "_" . $j;
}
if ($append_port_to_name) {
$name .= "_" . $src_port;
}
if ($vs_a[$i]['mode'] == 'relay') {
// relay mode
$conf .= "relay \"{$name}\" {\n";
$conf .= " listen on {$ip} port {$src_port} \n";
$conf .= " protocol \"{$vs_a[$i]['relay_protocol']}\"\n";
$lbmode = "";
if ($pools[$vs_a[$i]['poolname']]['mode'] == "loadbalance") {
$lbmode = "mode loadbalance";
}
$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')) {
$conf .= " forward to <{$vs_a[$i]['sitedown']}> port {$dest_port} {$lbmode} {$check_a[$pools[$vs_a[$i]['poolname']]['monitor']]} \n";
}
$conf .= "}\n";
} else {
// redirect mode
$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['load_balancer']['setting']['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')) {
$conf .= " forward to <{$vs_a[$i]['sitedown']}> port {$dest_port} {$check_a[$pools[$vs_a[$i]['sitedown']]['monitor']]} \n";
}
$conf .= "}\n";
}
}
}
}
fwrite($fd, $conf);
fclose($fd);
if (is_process_running('relayd')) {
if (! empty($vs_a)) {
if ($kill_first) {
killbyname('relayd');
/* Remove all active relayd anchors now that relayd is no longer running. */
relayd_cleanup_lb_anchor('*');
mwexec('/usr/local/sbin/relayd -f /var/etc/relayd.conf');
} else {
// it's running and there is a config, just reload
mwexec('/usr/local/sbin/relayctl reload');
}
} else {
/*
* XXX: Something breaks our control connection with relayd
* and makes 'relayctl stop' not work
* rule reloads are the current suspect
* mwexec('/usr/local/sbin/relayctl stop');
* returns "command failed"
*/
killbyname('relayd');
/* Remove all active relayd anchors now that relayd is no longer running. */
relayd_cleanup_lb_anchor("*");
}
} elseif (!empty($vs_a)) {
// not running and there is a config, start it
/* Remove all active relayd anchors so it can start fresh. */
relayd_cleanup_lb_anchor('*');
mwexec('/usr/local/sbin/relayd -f /var/etc/relayd.conf');
}
}
function relayd_get_lb_redirects()
{
/*
# relayctl show summary
Id Type Name Avlblty Status
1 redirect testvs2 active
5 table test2:80 active (3 hosts up)
11 host 192.168.1.2 91.55% up
10 host 192.168.1.3 100.00% up
9 host 192.168.1.4 88.73% up
3 table test:80 active (1 hosts up)
7 host 192.168.1.2 66.20% down
6 host 192.168.1.3 97.18% up
0 redirect testvs active
3 table test:80 active (1 hosts up)
7 host 192.168.1.2 66.20% down
6 host 192.168.1.3 97.18% up
4 table testvs-sitedown:80 active (1 hosts up)
8 host 192.168.1.4 84.51% up
# relayctl show redirects
Id Type Name Avlblty Status
1 redirect testvs2 active
0 redirect testvs active
# relayctl show redirects
Id Type Name Avlblty Status
1 redirect testvs2 active
total: 2 sessions
last: 2/60s 2/h 2/d sessions
average: 1/60s 0/h 0/d sessions
0 redirect testvs active
*/
$rdr_a = array();
exec('/usr/local/sbin/relayctl show redirects 2>&1', $rdr_a);
$relay_a = array();
exec('/usr/local/sbin/relayctl show relays 2>&1', $relay_a);
$vs = array();
$cur_entry = "";
for ($i = 0; isset($rdr_a[$i]); $i++) {
$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)) {
$cur_entry = trim($regs[1]);
$vs[trim($regs[1])] = array();
$vs[trim($regs[1])]['status'] = trim($regs[2]);
}
} elseif (($x = preg_match("/^\s+total:\s(.*)\ssessions/", $line, $regs)) && !empty($cur_entry)) {
$vs[$cur_entry]['total'] = trim($regs[1]);
} elseif (($x = preg_match("/^\s+last:\s(.*)\ssessions/", $line, $regs)) && !empty($cur_entry)) {
$vs[$cur_entry]['last'] = trim($regs[1]);
} elseif (($x = preg_match("/^\s+average:(.*)\ssessions/", $line, $regs)) && !empty($cur_entry)) {
$vs[$cur_entry]['average'] = trim($regs[1]);
}
}
$cur_entry = "";
for ($i = 0; isset($relay_a[$i]); $i++) {
$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)) {
$cur_entry = trim($regs[1]);
$vs[trim($regs[1])] = array();
$vs[trim($regs[1])]['status'] = trim($regs[2]);
}
} elseif (($x = preg_match("/^\s+total:\s(.*)\ssessions/", $line, $regs)) && !empty($cur_entry)) {
$vs[$cur_entry]['total'] = trim($regs[1]);
} elseif (($x = preg_match("/^\s+last:\s(.*)\ssessions/", $line, $regs)) && !empty($cur_entry)) {
$vs[$cur_entry]['last'] = trim($regs[1]);
} elseif (($x = preg_match("/^\s+average:(.*)\ssessions/", $line, $regs)) && !empty($cur_entry)) {
$vs[$cur_entry]['average'] = trim($regs[1]);
}
}
return $vs;
}
function relayd_get_lb_summary()
{
$relayctl = array();
exec('/usr/local/sbin/relayctl show summary 2>&1', $relayctl);
$relay_hosts=Array();
foreach( (array) $relayctl as $line) {
$t = explode("\t", $line);
if (isset($t[1])) {
switch (trim($t[1])) {
case "table":
$curpool=trim($t[2]);
break;
case "host":
$curhost=trim($t[2]);
if (!isset($relay_hosts[$curpool])) {
$relay_hosts[$curpool] = array();
}
if (!isset($relay_hosts[$curpool][$curhost])) {
$relay_hosts[$curpool][$curhost]['avail'] = array();
}
$relay_hosts[$curpool][$curhost]['avail']=trim($t[3]);
$relay_hosts[$curpool][$curhost]['state']=trim($t[4]);
break;
}
}
}
return $relay_hosts;
}
/*
* 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 relayd_cleanup_lb_anchor($anchorname = "*")
{
/* NOTE: These names come back prepended with "relayd/" e.g. "relayd/MyVSName" */
$lbanchors = explode("\n", trim(`/sbin/pfctl -sA -a relayd | /usr/bin/awk '{print $1;}'`));
foreach ($lbanchors as $lba) {
if (($anchorname == "*") || ($lba == "relayd/{$anchorname}")) {
/* Flush both the NAT and the Table for the anchor, so it will be completely removed by pf. */
mwexecf('/sbin/pfctl -a %s -F nat', $lba);
mwexecf('/sbin/pfctl -a %s -F Tables', $lba);
}
}
}
/* Mark an anchor for later cleanup. This will allow us to remove an old VS name */
function relayd_cleanup_lb_mark_anchor($name)
{
/* Nothing to do! */
if (empty($name)) {
return;
}
$filename = '/tmp/relayd_anchors_remove';
$cleanup_anchors = array();
/* Read in any currently unapplied name changes */
if (file_exists($filename)) {
$cleanup_anchors = explode("\n", file_get_contents($filename));
}
/* Only add the anchor to the list if it's not already there. */
if (!in_array($name, $cleanup_anchors)) {
$cleanup_anchors[] = $name;
}
file_put_contents($filename, implode("\n", $cleanup_anchors));
}
function relayd_cleanup_lb_marked()
{
global $config;
$filename = '/tmp/relayd_anchors_remove';
$cleanup_anchors = array();
/* Nothing to do! */
if (!file_exists($filename)) {
return;
} else {
$cleanup_anchors = explode("\n", file_get_contents($filename));
/* Nothing to do! */
if (empty($cleanup_anchors)) {
return;
}
}
/* Load current names so we can make sure we don't remove an anchor that is still in use. */
$active_vsnames = array();
if (isset($config['load_balancer']['virtual_server'])) {
foreach ($config['load_balancer']['virtual_server'] as $vs) {
$active_vsnames[] = $vs['name'];
}
}
foreach ($cleanup_anchors as $anchor) {
/* Only cleanup an anchor if it is not still active. */
if (!in_array($anchor, $active_vsnames)) {
relayd_cleanup_lb_anchor($anchor);
}
}
@unlink($filename);
}
dns protocol "dns" {
tcp { nodelay, sack, socket buffer 1024, backlog 1000 }
}
protocol "tcp" {
tcp { nodelay, socket buffer 65536 }
}
<acl>
<page-services-loadbalancer-monitor-edit>
<name>Services: Load Balancer: Monitor: Edit</name>
<patterns>
<pattern>load_balancer_monitor_edit.php*</pattern>
</patterns>
</page-services-loadbalancer-monitor-edit>
<page-services-loadbalancer-monitor>
<name>Services: Load Balancer: Monitors</name>
<patterns>
<pattern>load_balancer_monitor.php*</pattern>
</patterns>
</page-services-loadbalancer-monitor>
<page-services-loadbalancer-setting>
<name>Services: Load Balancer: setting</name>
<patterns>
<pattern>load_balancer_setting.php*</pattern>
</patterns>
</page-services-loadbalancer-setting>
<page-services-loadbalancer-virtualservers>
<name>Services: Load Balancer: Virtual Servers</name>
<patterns>
<pattern>load_balancer_virtual_server.php*</pattern>
</patterns>
</page-services-loadbalancer-virtualservers>
<page-status-loadbalancer-pool>
<name>Status: Load Balancer: Pool</name>
<patterns>
<pattern>status_lb_pool.php*</pattern>
</patterns>
</page-status-loadbalancer-pool>
<page-status-loadbalancer-virtualserver>
<name>Status: Load Balancer: Virtual Server</name>
<patterns>
<pattern>status_lb_vs.php*</pattern>
</patterns>
</page-status-loadbalancer-virtualserver>
<page-status-systemlogs-loadbalancer>
<name>Status: System logs: Load Balancer</name>
<patterns>
<pattern>diag_logs_relayd.php*</pattern>
</patterns>
</page-status-systemlogs-loadbalancer>
<page-loadbalancer-pool>
<name>Load Balancer: Pool</name>
<patterns>
<pattern>load_balancer_pool.php*</pattern>
</patterns>
</page-loadbalancer-pool>
<page-loadbalancer-pool-edit>
<name>Load Balancer: Pool: Edit</name>
<patterns>
<pattern>load_balancer_pool_edit.php*</pattern>
</patterns>
</page-loadbalancer-pool-edit>
<page-loadbalancer-virtualserver-edit>
<name>Load Balancer: Virtual Server: Edit</name>
<patterns>
<pattern>load_balancer_virtual_server_edit.php*</pattern>
</patterns>
</page-loadbalancer-virtualserver-edit>
</acl>
<menu>
<Services>
<LoadBalancer VisibleName="Load Balancer" cssClass="fa fa-truck fa-fw">
<Monitors order="10" url="/load_balancer_monitor.php">
<Edit url="/load_balancer_monitor_edit.php*" visibility="hidden"/>
</Monitors>
<PoolSetup order="20" VisibleName="Pool Setup" url="/load_balancer_pool.php">
<Edit url="/load_balancer_pool_edit.php*" visibility="hidden"/>
</PoolSetup>
<VirtualServer order="30" VisibleName="Virtual Server Setup" url="/load_balancer_virtual_server.php">
<Edit url="/load_balancer_virtual_server_edit.php*" visibility="hidden"/>
</VirtualServer>
<Settings order="40" url="/load_balancer_setting.php"/>
<PoolStatus order="50" VisibleName="Pool Status" url="/status_lb_pool.php"/>
<VirtualServerStatus order="60" VisibleName="Virtual Server Status" url="/status_lb_vs.php"/>
<Log VisibleName="Log File" order="100" url="/diag_logs_relayd.php"/>
</LoadBalancer>
</Services>
</menu>
<?php
$logfile = '/var/log/relayd.log';
$logclog = true;
require_once 'diag_logs_template.inc';
<?php
/*
Copyright (C) 2014-2016 Deciso B.V.
Copyright (C) 2008 Bill Marquette <bill.marquette@gmail.com>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("guiconfig.inc");
require_once("filter.inc");
require_once("services.inc");
require_once("plugins.inc.d/relayd.inc");
require_once("interfaces.inc");
if (empty($config['load_balancer']['monitor_type']) || !is_array($config['load_balancer']['monitor_type'])) {
$config['load_balancer']['monitor_type'] = array();
}
$a_monitor = &$config['load_balancer']['monitor_type'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['act']) && $_POST['act'] == "del") {
if (isset($_POST['id']) && !empty($a_monitor[$_POST['id']])){
$input_errors = array();
/* make sure no pools reference this entry */
if (is_array($config['load_balancer']['lbpool'])) {
foreach ($config['load_balancer']['lbpool'] as $pool) {
if ($pool['monitor'] == $a_monitor[$_GET['id']]['name']) {
$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by at least one pool.");
break;
}
}
}
if (count($input_errors) == 0) {
unset($a_monitor[$_POST['id']]);
write_config();
mark_subsystem_dirty('loadbalancer');
} else {
echo implode('\n', $input_errors);
}
}
exit;
} elseif (!empty($_POST['apply'])) {
relayd_configure_do();
filter_configure();
clear_subsystem_dirty('loadbalancer');
header(url_safe('Location: /load_balancer_monitor.php'));
exit;
}
}
$service_hook = 'relayd';
include("head.inc");
legacy_html_escape_form_data($a_monitor);
$main_buttons = array(
array('label'=>gettext('Add'), 'href'=>'load_balancer_monitor_edit.php'),
);
?>
<body>
<script type="text/javascript">
$( document ).ready(function() {
// delete host action
$(".act_delete").click(function(event){
event.preventDefault();
var id = $(this).data("id");
// delete single
BootstrapDialog.show({
type:BootstrapDialog.TYPE_DANGER,
title: "<?= gettext("Load Balancer: Monitors");?>",
message: "<?=gettext("Do you really want to delete this entry?");?>",
buttons: [{
label: "<?= gettext("No");?>",
action: function(dialogRef) {
dialogRef.close();
}}, {
label: "<?= gettext("Yes");?>",
action: function(dialogRef) {
$.post(window.location, {act: 'del', id:id}, function(data) {
if (data == "") {
// no errors
location.reload();
} else {
dialogRef.close();
BootstrapDialog.show({
type:BootstrapDialog.TYPE_DANGER,
title: "<?= gettext("Load Balancer: Monitors");?>",
message: data
});
}
});
}
}]
});
});
});
//]]>
</script>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (is_subsystem_dirty('loadbalancer')): ?><br/>
<?php print_info_box_apply(gettext("The load balancer configuration has been changed") . ".<br />" . gettext("You must apply the changes in order for them to take effect."));?><br />
<?php endif; ?>
<section class="col-xs-12">
<div class="tab-content content-box col-xs-12">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th><?=gettext("Name");?></th>
<th><?=gettext("Type");?></th>
<th><?=gettext("Description");?></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach ($a_monitor as $monitor): ?>
<tr>
<td><?=$monitor['name'];?></td>
<td><?=$monitor['type'];?></td>
<td><?=$monitor['descr'];?></td>
<td>
<a href="load_balancer_monitor_edit.php?act=edit&amp;id=<?=$i;?>" class="btn btn-default btn-xs">
<span class="glyphicon glyphicon-pencil"></span>
</a>
<a data-id="<?=$i;?>" class="act_delete btn btn-default btn-xs">
<span class="fa fa-trash text-muted"></span>
</a>
</td>
</tr>
<?php
++$i;
endforeach;?>
</tbody>
</table>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc"); ?>
<?php
/*
Copyright (C) 2014-2016 Deciso B.V.
Copyright (C) 2008 Bill Marquette <bill.marquette@gmail.com>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("guiconfig.inc");
require_once("services.inc");
require_once("interfaces.inc");
$rfc2616 = array(
100 => "100 Continue",
101 => "101 Switching Protocols",
200 => "200 OK",
201 => "201 Created",
202 => "202 Accepted",
203 => "203 Non-Authoritative Information",
204 => "204 No Content",
205 => "205 Reset Content",
206 => "206 Partial Content",
300 => "300 Multiple Choices",
301 => "301 Moved Permanently",
302 => "302 Found",
303 => "303 See Other",
304 => "304 Not Modified",
305 => "305 Use Proxy",
306 => "306 (Unused)",
307 => "307 Temporary Redirect",
400 => "400 Bad Request",
401 => "401 Unauthorized",
402 => "402 Payment Required",
403 => "403 Forbidden",
404 => "404 Not Found",
405 => "405 Method Not Allowed",
406 => "406 Not Acceptable",
407 => "407 Proxy Authentication Required",
408 => "408 Request Timeout",
409 => "409 Conflict",
410 => "410 Gone",
411 => "411 Length Required",
412 => "412 Precondition Failed",
413 => "413 Request Entity Too Large",
414 => "414 Request-URI Too Long",
415 => "415 Unsupported Media Type",
416 => "416 Requested Range Not Satisfiable",
417 => "417 Expectation Failed",
500 => "500 Internal Server Error",
501 => "501 Not Implemented",
502 => "502 Bad Gateway",
503 => "503 Service Unavailable",
504 => "504 Gateway Timeout",
505 => "505 HTTP Version Not Supported"
);
if (empty($config['load_balancer']['monitor_type']) || !is_array($config['load_balancer']['monitor_type'])) {
$config['load_balancer']['monitor_type'] = array();
}
$a_monitor = &$config['load_balancer']['monitor_type'];
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (isset($_GET['id']) && !empty($a_monitor[$_GET['id']])) {
$id = $_GET['id'];
}
$pconfig = array();
foreach (array('name', 'type', 'descr') as $fieldname) {
if (isset($id) && isset($a_monitor[$id][$fieldname])) {
$pconfig[$fieldname] = $a_monitor[$id][$fieldname];
} else {
$pconfig[$fieldname] = null;
}
}
if (isset($id)) {
$pconfig['options_send'] = isset($a_monitor[$id]['options']['send']) ? $a_monitor[$id]['options']['send'] : null;
$pconfig['options_expect'] = isset($a_monitor[$id]['options']['expect']) ? $a_monitor[$id]['options']['expect'] : null;
$pconfig['options_path'] = isset($a_monitor[$id]['options']['path']) ? $a_monitor[$id]['options']['path'] : null;
$pconfig['options_host'] = isset($a_monitor[$id]['options']['host']) ? $a_monitor[$id]['options']['host'] : null;
$pconfig['options_code'] = isset($a_monitor[$id]['options']['code']) ? $a_monitor[$id]['options']['code'] : null;
} else {
/* option defaults */
$pconfig['options_send'] = null;
$pconfig['options_expect'] = null;
$pconfig['options_path'] = '/';
$pconfig['options_code'] = 200;
$pconfig['options_host'] = null;
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['id']) && !empty($a_monitor[$_POST['id']])) {
$id = $_POST['id'];
}
$pconfig = $_POST;
$input_errors = array();
/* input validation */
$reqdfields = explode(" ", "name type descr");
$reqdfieldsn = array(gettext("Name"),gettext("Type"),gettext("Description"));
do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors);
/* Ensure that our monitor names are unique */
for ($i=0; isset($config['load_balancer']['monitor_type'][$i]); $i++) {
if ($pconfig['name'] == $config['load_balancer']['monitor_type'][$i]['name'] && $i != $id) {
$input_errors[] = gettext("This monitor name has already been used. Monitor names must be unique.");
}
}
if (strpos($pconfig['name'], " ") !== false) {
$input_errors[] = gettext("You cannot use spaces in the 'name' field.");
}
switch($pconfig['type']) {
case 'icmp':
case 'tcp':
break;
case 'http':
case 'https':
if (!empty($pconfig['options_host']) && !is_hostname($pconfig['options_host'])) {
$input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'.");
}
if (!empty($pconfig['options_code']) && !isset($rfc2616[$pconfig['options_code']])) {
$input_errors[] = gettext("HTTP(S) codes must be from RFC 2616.");
}
if (empty($pconfig['options_path'])) {
$input_errors[] = gettext("The path to monitor must be set.");
}
break;
case 'send':
break;
}
if (count($input_errors) == 0) {
$monent = array();
$monent['name'] = $pconfig['name'];
$monent['type'] = $pconfig['type'];
$monent['descr'] = $pconfig['descr'];
$monent['options'] = array();
if($pconfig['type'] == "http" || $pconfig['type'] == "https") {
$monent['options']['path'] = $pconfig['options_path'];
$monent['options']['host'] = $pconfig['options_host'];
$monent['options']['code'] = $pconfig['options_code'];
} elseif ($pconfig['type'] == "send") {
$monent['options']['send'] = $pconfig['options_send'];
$monent['options']['expect'] = $pconfig['options_expect'];
}
if (isset($id)) {
/* modify all pools with this name */
for ($i = 0; isset($config['load_balancer']['lbpool'][$i]); $i++) {
if ($config['load_balancer']['lbpool'][$i]['monitor'] == $a_monitor[$id]['name']) {
$config['load_balancer']['lbpool'][$i]['monitor'] = $monent['name'];
}
}
$a_monitor[$id] = $monent;
} else {
$a_monitor[] = $monent;
}
mark_subsystem_dirty('loadbalancer');
write_config();
header(url_safe('Location: /load_balancer_monitor.php'));
exit;
}
}
$service_hook = 'relayd';
include("head.inc");
legacy_html_escape_form_data($pconfig);
$types = array("icmp" => gettext("ICMP"), "tcp" => gettext("TCP"), "http" => gettext("HTTP"), "https" => gettext("HTTPS"), "send" => gettext("Send/Expect"));
?>
<body>
<?php include("fbegin.inc"); ?>
<script type="text/javascript">
$( document ).ready(function() {
$("#monitor_type").change(function(){
switch ($(this).val()) {
case 'http':
case 'https':
$("#type_details_send").hide();
$("#type_details_http").show();
$("#type_details").show();
break;
case 'send':
$("#type_details_send").show();
$("#type_details_http").hide();
$("#type_details").show();
break;
default:
$("#type_details").hide();
break;
}
});
$("#monitor_type").change();
});
</script>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
<section class="col-xs-12">
<div class="content-box">
<form name="iform" method="post" id="iform">
<div class="table-responsive">
<table class="table table-striped opnsense_standard_table_form">
<tr>
<td width="22%"><strong><?=gettext("Edit Monitor entry"); ?></strong></td>
<td width="78%" align="right">
<small><?=gettext("full help"); ?> </small>
<i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_page" type="button"></i>
</td>
</tr>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Name"); ?></td>
<td>
<input name="name" type="text" value="<?=$pconfig['name'];?>" />
</td>
</tr>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Description"); ?></td>
<td>
<input name="descr" type="text" value="<?=$pconfig['descr'];?>"/>
</td>
</tr>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Type"); ?></td>
<td>
<select id="monitor_type" name="type" class="selectpicker">
<option value="icmp" <?=$pconfig['type'] == "icmp" ? " selected=\"selected\"" : "";?> >
<?=gettext("ICMP");?>
</option>
<option value="tcp" <?=$pconfig['type'] == "tcp" ? " selected=\"selected\"" : "";?> >
<?=gettext("TCP");?>
</option>
<option value="http" <?=$pconfig['type'] == "http" ? " selected=\"selected\"" : "";?> >
<?=gettext("HTTP");?>
</option>
<option value="https" <?=$pconfig['type'] == "https" ? " selected=\"selected\"" : "";?> >
<?=gettext("HTTPS");?>
</option>
<option value="send" <?=$pconfig['type'] == "send" ? " selected=\"selected\"" : "";?> >
<?=gettext("Send/Expect");?>
</option>
</select>
</td>
</tr>
<tr id="type_details" style="display:none;">
<td></td>
<td>
<div id="type_details_send">
<table class="table table-condensed">
<tr>
<td><?=gettext("Send string"); ?></td>
<td>
<input name="options_send" type="text" value="<?=$pconfig['options_send'];?>"/>
</td>
</tr>
<tr>
<td><?=gettext("Expect string"); ?></td>
<td>
<input name="options_expect" type="text" value="<?=$pconfig['options_expect'];?>"/>
</td>
</tr>
</table>
</div>
<div id="type_details_http">
<table class="table table-condensed">
<tr>
<td><?=gettext("Path"); ?></td>
<td>
<input name="options_path" type="text" value="<?=$pconfig['options_path'];?>"/>
</td>
</tr>
<tr>
<td><?=gettext("Host"); ?></td>
<td>
<input name="options_host" type="text" value="<?=$pconfig['options_host'];?>" />
<small><?=gettext("Hostname for Host: header if needed."); ?></small>
</td>
</tr>
<tr>
<td><?=gettext("HTTP Code"); ?></td>
<td>
<select name="options_code">
<?php
foreach($rfc2616 as $code => $message):?>
<option value="<?=$code;?>" <?=$pconfig['options_code'] == $code ? " selected=\"selected\"" :"" ;?>>
<?=$message;?>
</option>
<?php
endforeach;?>
</select>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td valign="top">&nbsp;</td>
<td width="78%">
<input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" />
<input type="button" class="btn btn-default" value="<?=gettext("Cancel");?>" onclick="window.location.href='/load_balancer_monitor.php'" />
<?php if (isset($id)): ?>
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
<?php endif; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc"); ?>
<?php
/*
Copyright (C) 2014-2016 Deciso B.V.
Copyright (C) 2005-2008 Bill Marquette <bill.marquette@gmail.com>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("guiconfig.inc");
require_once("filter.inc");
require_once("services.inc");
require_once("plugins.inc.d/relayd.inc");
require_once("interfaces.inc");
if (empty($config['load_balancer']['lbpool']) || !is_array($config['load_balancer']['lbpool'])) {
$config['load_balancer']['lbpool'] = array();
}
$a_pool = &$config['load_balancer']['lbpool'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['act']) && $_POST['act'] == "del") {
if (isset($_POST['id']) && !empty($a_pool[$_POST['id']])){
$input_errors = array();
/* make sure no virtual servers reference this entry */
if (is_array($config['load_balancer']['virtual_server'])) {
foreach ($config['load_balancer']['virtual_server'] as $vs) {
if ($vs['poolname'] == $a_pool[$_POST['id']]['name']) {
$input_errors[] = gettext("This entry cannot be deleted because it is still referenced by at least one virtual server.");
break;
}
}
}
if (count($input_errors) == 0) {
unset($a_pool[$_POST['id']]);
write_config();
mark_subsystem_dirty('loadbalancer');
} else {
echo implode('\n', $input_errors);
}
}
exit;
} elseif (!empty($_POST['apply'])) {
relayd_configure_do();
filter_configure();
clear_subsystem_dirty('loadbalancer');
header(url_safe('Location: /load_balancer_monitor.php'));
exit;
}
}
/* Index monitor_type array for easy hyperlinking */
$mondex = array();
for ($i = 0; isset($config['load_balancer']['monitor_type'][$i]); $i++) {
$mondex[$config['load_balancer']['monitor_type'][$i]['name']] = $i;
}
$service_hook = 'relayd';
include("head.inc");
legacy_html_escape_form_data($a_pool);
$main_buttons = array(
array('label'=>gettext('Add'), 'href'=>'load_balancer_pool_edit.php'),
);
?>
<body>
<script type="text/javascript">
$( document ).ready(function() {
// delete host action
$(".act_delete").click(function(event){
event.preventDefault();
var id = $(this).data("id");
// delete single
BootstrapDialog.show({
type:BootstrapDialog.TYPE_DANGER,
title: "<?= gettext("Load Balancer: Monitors");?>",
message: "<?=gettext("Do you really want to delete this entry?");?>",
buttons: [{
label: "<?= gettext("No");?>",
action: function(dialogRef) {
dialogRef.close();
}}, {
label: "<?= gettext("Yes");?>",
action: function(dialogRef) {
$.post(window.location, {act: 'del', id:id}, function(data) {
if (data == "") {
// no errors
location.reload();
} else {
dialogRef.close();
BootstrapDialog.show({
type:BootstrapDialog.TYPE_DANGER,
title: "<?= gettext("Load Balancer: Monitors");?>",
message: data
});
}
});
}
}]
});
});
});
//]]>
</script>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (is_subsystem_dirty('loadbalancer')): ?><br/>
<?php print_info_box_apply(sprintf(gettext("The load balancer configuration has been changed%sYou must apply the changes in order for them to take effect."), "<br />"));?><br />
<?php endif; ?>
<section class="col-xs-12">
<div class="tab-content content-box col-xs-12">
<form method="post" name="iform" id="iform">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th><?=gettext("Name");?></th>
<th><?=gettext("Mode");?></th>
<th><?=gettext("Servers");?></th>
<th><?=gettext('Port');?></th>
<th><?=gettext('Monitor');?></th>
<th><?=gettext("Description");?></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach ($a_pool as $pool): ?>
<tr>
<td><?=$pool['name'];?></td>
<td><?=$pool['mode'];?></td>
<td><?= !empty($pool['servers']) ? implode('<br/>', $pool['servers']) : '' ?></td>
<td><?=$pool['port'];?></td>
<td>
<a href="load_balancer_monitor_edit.php?id=<?=$mondex[$pool['monitor']];?>"><?=$pool['monitor'];?></a>
</td>
<td><?=$pool['descr'];?></td>
<td>
<a href="load_balancer_pool_edit.php?id=<?=$i;?>" class="btn btn-default btn-xs">
<span class="glyphicon glyphicon-pencil"></span>
</a>
<a data-id="<?=$i;?>" class="act_delete btn btn-default btn-xs">
<span class="fa fa-trash text-muted"></span>
</a>
<a href="load_balancer_pool_edit.php?act=dup&id=<?=$i;?>" class="btn btn-default btn-xs" data-toggle="tooltip" title="<?=gettext("clone rule");?>">
<span class="fa fa-clone text-muted"></span>
</a>
</td>
</tr>
<?php
++$i;
endforeach;?>
</tbody>
<tfoot>
<tr>
<td colspan="7">
<?= sprintf(gettext('This feature is intended for server load balancing, not multi-WAN. For load balancing or failover for multiple WANs, use %sGateway Groups%s.'), '<a href="/system_gateway_groups.php">', '</a>'); ?>
</td>
</tr>
</tfoot>
</table>
</div>
</form>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc"); ?>
<?php
/*
Copyright (C) 2014-2016 Deciso B.V.
Copyright (C) 2005-2008 Bill Marquette <bill.marquette@gmail.com>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("guiconfig.inc");
require_once("services.inc");
require_once("interfaces.inc");
if (empty($config['load_balancer']['lbpool']) || !is_array($config['load_balancer']['lbpool'])) {
$config['load_balancer']['lbpool'] = array();
}
$a_pool = &$config['load_balancer']['lbpool'];
$copy_fields = array('name', 'mode', 'descr', 'port', 'retry', 'monitor', 'servers', 'serversdisabled');
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (isset($_GET['id']) && !empty($a_pool[$_GET['id']])) {
$id = $_GET['id'];
}
$pconfig = array();
// copy fields
foreach ($copy_fields as $fieldname) {
if (isset($id) && isset($a_pool[$id][$fieldname])) {
$pconfig[$fieldname] = $a_pool[$id][$fieldname];
} else {
$pconfig[$fieldname] = null;
}
}
// init arrays
$pconfig['servers'] = is_array($pconfig['servers']) ? $pconfig['servers'] : array();
$pconfig['serversdisabled'] = is_array($pconfig['serversdisabled']) ? $pconfig['serversdisabled'] : array();
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['id']) && !empty($a_pool[$_POST['id']])) {
$id = $_POST['id'];
}
$pconfig = $_POST;
$input_errors = array();
/* input validation */
$reqdfields = explode(" ", "name mode port monitor servers");
$reqdfieldsn = array(gettext("Name"),gettext("Mode"),gettext("Port"),gettext("Monitor"),gettext("Server List"));
do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors);
/* Ensure that our pool names are unique */
for ($i=0; isset($config['load_balancer']['lbpool'][$i]); $i++) {
if ($pconfig['name'] == $config['load_balancer']['lbpool'][$i]['name'] && $i != $id) {
$input_errors[] = gettext("This pool name has already been used. Pool names must be unique.");
}
}
if (strpos($pconfig['name'], " ") !== false) {
$input_errors[] = gettext("You cannot use spaces in the 'name' field.");
}
if (in_array($pconfig['name'], $reserved_table_names)) {
$input_errors[] = sprintf(gettext("The name '%s' is a reserved word and cannot be used."), $_POST['name']);
}
if (is_alias($pconfig['name'])) {
$input_errors[] = sprintf(gettext("Sorry, an alias is already named %s."), $_POST['name']);
}
if (!is_portoralias($pconfig['port'])) {
$input_errors[] = gettext("The port must be an integer between 1 and 65535, or a port alias.");
}
// May as well use is_port as we want a positive integer and such.
if (!empty($pconfig['retry']) && !is_port($pconfig['retry'])) {
$input_errors[] = gettext("The retry value must be an integer between 1 and 65535.");
}
if (is_array($pconfig['servers'])) {
foreach($pconfig['servers'] as $svrent) {
if (!is_ipaddr($svrent) && !is_subnetv4($svrent)) {
$input_errors[] = sprintf(gettext("%s is not a valid IP address or IPv4 subnet (in \"enabled\" list)."), $svrent);
} elseif (is_subnetv4($svrent) && subnet_size($svrent) > 64) {
$input_errors[] = sprintf(gettext("%s is a subnet containing more than 64 IP addresses (in \"enabled\" list)."), $svrent);
}
}
}
if (is_array($pconfig['serversdisabled'])) {
foreach($pconfig['serversdisabled'] as $svrent) {
if (!is_ipaddr($svrent) && !is_subnetv4($svrent)) {
$input_errors[] = sprintf(gettext("%s is not a valid IP address or IPv4 subnet (in \"disabled\" list)."), $svrent);
} elseif (is_subnetv4($svrent) && subnet_size($svrent) > 64) {
$input_errors[] = sprintf(gettext("%s is a subnet containing more than 64 IP addresses (in \"disabled\" list)."), $svrent);
}
}
}
$m = array();
for ($i=0; isset($config['load_balancer']['monitor_type'][$i]); $i++) {
$m[$config['load_balancer']['monitor_type'][$i]['name']] = $config['load_balancer']['monitor_type'][$i];
}
if (!isset($m[$pconfig['monitor']])) {
$input_errors[] = gettext("Invalid monitor chosen.");
}
if (count($input_errors) == 0) {
$poolent = array();
foreach ($copy_fields as $fieldname) {
$poolent[$fieldname] = $pconfig[$fieldname];
}
if (isset($id)) {
/* modify all virtual servers with this name */
for ($i = 0; isset($config['load_balancer']['virtual_server'][$i]); $i++) {
if ($config['load_balancer']['virtual_server'][$i]['lbpool'] == $a_pool[$id]['name']) {
$config['load_balancer']['virtual_server'][$i]['lbpool'] = $poolent['name'];
}
}
$a_pool[$id] = $poolent;
} else {
$a_pool[] = $poolent;
}
mark_subsystem_dirty('loadbalancer');
write_config();
header(url_safe('Location: /load_balancer_pool.php'));
exit;
}
}
$service_hook = 'relayd';
legacy_html_escape_form_data($pconfig);
include("head.inc");
?>
<body>
<!-- push all available (nestable) aliases in a hidden select box -->
<select class="hidden" id="aliases">
<?php
if (!empty($config['aliases']['alias'])):
foreach ($config['aliases']['alias'] as $alias):
if ($alias['type'] == 'port'):?>
<option data-type="<?=$alias['type'];?>" value="<?=htmlspecialchars($alias['name']);?>"><?=htmlspecialchars($alias['name']);?></option>
<?php
endif;
endforeach;
endif;
?>
</select>
<?php include("fbegin.inc"); ?>
<script type="text/javascript">
$( document ).ready(function() {
// init port type ahead
var all_aliases = [];
$("#aliases > option").each(function(){
all_aliases.push($(this).val())
});
$("#port").typeahead({ source: all_aliases });
$("#mode").change(function(event){
event.preventDefault();
if ($('#mode').val() == 'failover' && $('#servers option').length > 1){
$('#servers option:not(:first)').remove().appendTo('#serversdisabled');
}
});
$("#btn_add_to_pool").click(function(event){
event.preventDefault();
if ($('#mode').val() != 'failover' || $('#servers option').length == 0){
$('#servers').append($('<option>', { value : $("#ipaddr").val() }).text($("#ipaddr").val()));
} else {
$('#serversdisabled').append($('<option>', { value : $("#ipaddr").val() }).text($("#ipaddr").val()));
}
});
$("#moveToEnabled").click(function(event){
event.preventDefault();
if ($('#mode').val() != 'failover' ||
($('#servers option').length == 0 && $('#serversdisabled option:selected').length == 1))
{
$('#serversdisabled option:selected').remove().appendTo('#servers');
}
});
$("#moveToDisabled").click(function(event){
event.preventDefault();
$('#servers option:selected').remove().appendTo('#serversdisabled');
});
$("#btn_del_serversdisabled").click(function(event){
event.preventDefault();
$('#serversdisabled option:selected').remove();
});
$("#btn_del_servers").click(function(event){
event.preventDefault();
$('#servers option:selected').remove();
});
$("#save").click(function(){
$('#servers option').prop('selected', true);
$('#serversdisabled option').prop('selected', true);
});
});
</script>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
<section class="col-xs-12">
<div class="content-box">
<form method="post" name="iform" id="iform">
<div class="table-responsive">
<table class="table table-striped opnsense_standard_table_form">
<tr>
<td>
<strong><?=gettext("Add/edit - Pool entry"); ?></strong>
</td>
<td align="right">
<small><?=gettext("full help"); ?> </small>
<i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_page" type="button"></i>
</td>
</tr>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Name"); ?></td>
<td>
<input name="name" type="text" value="<?=$pconfig['name'];?>" />
</td>
</tr>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Mode"); ?></td>
<td>
<select id="mode" name="mode">
<option value="loadbalance" <?=$pconfig['mode'] == "loadbalance" ? "selected=\"selected\"" : "";?>>
<?=gettext("Load Balance");?>
</option>
<option value="failover" <?=$pconfig['mode'] == "failover" ? "selected=\"selected\"" : "";?>>
<?=gettext("Manual Failover");?>
</option>
</select>
</td>
</tr>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Description"); ?></td>
<td>
<input name="descr" type="text" <?php if(isset($pconfig['descr'])) echo "value=\"{$pconfig['descr']}\"";?> size="64" />
</td>
</tr>
<tr>
<td><a id="help_for_port" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Port"); ?></td>
<td>
<input type="text" id="port" name="port" value="<?=$pconfig['port'];?>"/>
<div class="hidden" for="help_for_port">
<?=gettext("This is the port your servers are listening on."); ?><br />
<?=gettext("You may also specify a port alias listed in Firewall -&gt; Aliases here."); ?>
</div>
</td>
</tr>
<tr>
<td><a id="help_for_retry" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Retry"); ?></td>
<td>
<input name="retry" type="text" value="<?=$pconfig['retry'];?>"/>
<div for="help_for_retry" class="hidden">
<?=gettext("Optionally specify how many times to retry checking a server before declaring it down."); ?>
</div>
</td>
</tr>
<tr>
<td colspan="2"><strong><?=gettext("Add item to pool"); ?></strong></td>
</tr>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Monitor"); ?></td>
<td>
<select id="monitor" name="monitor">
<?php
if (!empty($config['load_balancer']['monitor_type'])):
foreach ($config['load_balancer']['monitor_type'] as $monitor):?>
<option value="<?=$monitor['name'];?>" <?=$monitor['name'] == $pconfig['monitor'] ? "selected=\"selected\"" : "";?>>
<?=$monitor['name'];?>
</option>
<?php
endforeach;
endif;?>
</select>
</td>
</tr>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Server IP Address"); ?></td>
<td>
<div class="input-group">
<span class="input-group-btn">
<button class="btn btn-default" id="btn_add_to_pool" type="button"><?=gettext("Add to pool");?></button>
</span>
<input class="form-control" id="ipaddr" type="text">
</div>
</td>
</tr>
<tr>
<td colspan="2"><strong><?=gettext("Current Pool Members"); ?></strong></td>
</tr>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Members"); ?></td>
<td>
<table class="table table-condensed">
<thead>
<tr>
<th><?=gettext("Pool Disabled"); ?></th>
<th></th>
<th><?=gettext("Enabled (default)"); ?></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<select id="serversdisabled" name="serversdisabled[]" multiple="multiple">
<?php
if (is_array($pconfig['serversdisabled'])):
foreach ($pconfig['serversdisabled'] as $svrent):?>
<option value="<?=$svrent;?>"><?=$svrent;?> </option>
<?php
endforeach;
endif; ?>
</select>
<hr/>
<button id="btn_del_serversdisabled" class="btn btn-default btn-xs" data-toggle="tooltip"><span class="fa fa-trash text-muted"></span></button>
</td>
<td>
<button class="btn btn-default btn-xs" id="moveToDisabled"><span class="glyphicon glyphicon-arrow-left"></span></button><br />
<button class="btn btn-default btn-xs" id="moveToEnabled"><span class="glyphicon glyphicon-arrow-right"></span></button>
</td>
<td>
<select id="servers" name="servers[]" multiple="multiple">
<?php
if (is_array($pconfig['servers'])):
foreach ($pconfig['servers'] as $svrent):?>
<option value="<?=$svrent;?>"><?=$svrent;?> </option>
<?php
endforeach;
endif;?>
</select>
<hr/>
<button id="btn_del_servers" class="btn btn-default btn-xs" data-toggle="tooltip"><span class="fa fa-trash text-muted"></span></button>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td width="78%">
<br />
<input id="save" name="save" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>"/>
<input type="button" class="btn btn-default" value="<?=gettext("Cancel");?>" onclick="window.location.href='/load_balancer_pool.php'" />
<?php if (isset($id) && (empty($_GET['act']) || $_GET['act'] != 'dup')): ?>
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
<?php endif; ?>
</td>
</tr>
</table>
</div>
</form>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc"); ?>
<?php
/*
Copyright (C) 2014-2016 Deciso B.V.
Copyright (C) 2008 Bill Marquette <bill.marquette@gmail.com>
Copyright (C) 2012 Pierre POMES <pierre.pomes@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("guiconfig.inc");
require_once("filter.inc");
require_once("services.inc");
require_once("plugins.inc.d/relayd.inc");
require_once("interfaces.inc");
if (empty($config['load_balancer']) || !is_array($config['load_balancer'])) {
$config['load_balancer'] = array();
}
if (empty($config['load_balancer']['setting']) || !is_array($config['load_balancer']['setting'])) {
$config['load_balancer']['setting'] = array();
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig = array();
$pconfig['timeout'] = !empty($config['load_balancer']['setting']['timeout']) ? $config['load_balancer']['setting']['timeout'] : null;
$pconfig['interval'] = !empty($config['load_balancer']['setting']['interval']) ? $config['load_balancer']['setting']['interval'] : null;
$pconfig['prefork'] = !empty($config['load_balancer']['setting']['prefork']) ? $config['load_balancer']['setting']['prefork'] : null;
$pconfig['lb_use_sticky'] = isset($config['load_balancer']['setting']['lb_use_sticky']);
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
$pconfig = $_POST;
$input_errors = array();
if (!empty($pconfig['apply'])) {
relayd_configure_do();
filter_configure();
clear_subsystem_dirty('loadbalancer');
header(url_safe('Location: /load_balancer_setting.php'));
exit;
} else {
/* input validation */
if (!empty($pconfig['timeout']) && !is_numeric($pconfig['timeout'])) {
$input_errors[] = gettext("Timeout must be a numeric value");
}
if (!empty($pconfig['interval']) && !is_numeric($pconfig['interval'])) {
$input_errors[] = gettext("Interval must be a numeric value");
}
if (!empty($pconfig['prefork'])) {
if (!is_numeric($pconfig['prefork'])) {
$input_errors[] = gettext("Prefork must be a numeric value");
} elseif ($pconfig['prefork']<=0 || $pconfig['prefork']>32) {
$input_errors[] = gettext("Prefork value must be between 1 and 32");
}
}
if (count($input_errors) == 0) {
$config['load_balancer']['setting']['timeout'] = $pconfig['timeout'];
$config['load_balancer']['setting']['interval'] = $pconfig['interval'];
$config['load_balancer']['setting']['prefork'] = $pconfig['prefork'];
if (!empty($pconfig['lb_use_sticky'])) {
$config['load_balancer']['setting']['lb_use_sticky'] = true;
} elseif (isset($config['load_balancer']['setting']['lb_use_sticky'])) {
unset($config['load_balancer']['setting']['lb_use_sticky']);
}
write_config();
mark_subsystem_dirty('loadbalancer');
header(url_safe('Location: /load_balancer_setting.php'));
exit;
}
}
}
$service_hook = 'relayd';
legacy_html_escape_form_data($pconfig);
include("head.inc");
?>
<body>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
<?php if (is_subsystem_dirty('loadbalancer')): ?><br/>
<?php print_info_box_apply(gettext("The load balancer configuration has been changed") . ".<br />" . gettext("You must apply the changes in order for them to take effect."));?><br />
<?php endif; ?>
<section class="col-xs-12">
<div class="tab-content content-box col-xs-12">
<form method="post" name="iform" id="iform">
<div class="table-responsive">
<table class="table table-striped opnsense_standard_table_form">
<tr>
<td width="22%">
<strong><?=gettext("Global settings"); ?></strong>
</td>
<td width="78%" align="right">
<small><?=gettext("full help"); ?> </small>
<i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_page" type="button"></i>
</td>
</tr>
<tr>
<td><a id="help_for_timeout" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Timeout") ; ?></td>
<td>
<input type="text" name="timeout" id="timeout" value="<?=$pconfig['timeout'];?>" />
<div class="hidden" for="help_for_timeout">
<?=gettext("Set the global timeout in milliseconds for checks. Leave blank to use the default value of 1000 ms "); ?>
</div>
</td>
</tr>
<tr>
<td><a id="help_for_interval" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Interval") ; ?></td>
<td>
<input type="text" name="interval" id="interval" value="<?=$pconfig['interval']; ?>"/>
<div class="hidden" for="help_for_interval">
<?=gettext("Set the interval in seconds at which the member of a pool will be checked. Leave blank to use the default interval of 10 seconds"); ?>
</div>
</td>
</tr>
<tr>
<td><a id="help_for_prefork" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Prefork") ; ?></td>
<td>
<input type="text" name="prefork" id="prefork" value="<?=$pconfig['prefork']; ?>"/>
<div class="hidden" for="help_for_prefork">
<?=gettext("Number of processes used by relayd for dns protocol. Leave blank to use the default value of 5 processes"); ?>
</div>
</td>
</tr>
<tr>
<td><a id="help_for_lb_use_sticky" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Sticky connections");?> </td>
<td>
<input name="lb_use_sticky" type="checkbox" id="lb_use_sticky" value="yes" <?= !empty($pconfig['lb_use_sticky']) ? 'checked="checked"' : '';?>/>
<strong><?=gettext("Use sticky connections"); ?></strong><br />
<div class="hidden" for="help_for_lb_use_sticky">
<?=gettext("Successive connections will be redirected to the servers " .
"in a round-robin manner with connections from the same " .
"source being sent to the same web server. This 'sticky " .
"connection' will exist as long as there are states that " .
"refer to this connection. Once the states expire, so will " .
"the sticky connection. Further connections from that host " .
"will be redirected to the next web server in the round-robin."); ?>
</div>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save");?>" />
</td>
</tr>
</table>
</div>
</form>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc"); ?>
<?php
/*
Copyright (C) 2014-2016 Deciso B.V.
Copyright (C) 2005-2008 Bill Marquette <bill.marquette@gmail.com>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("guiconfig.inc");
require_once("filter.inc");
require_once("plugins.inc.d/relayd.inc");
require_once("services.inc");
require_once("interfaces.inc");
if (empty($config['load_balancer']['virtual_server']) || !is_array($config['load_balancer']['virtual_server'])) {
$config['load_balancer']['virtual_server'] = array();
}
$a_vs = &$config['load_balancer']['virtual_server'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['act']) && $_POST['act'] == "del") {
if (isset($_POST['id']) && !empty($a_vs[$_POST['id']])){
relayd_cleanup_lb_mark_anchor($a_vs[$_POST['id']]['name']);
unset($a_vs[$_POST['id']]);
write_config();
mark_subsystem_dirty('loadbalancer');
}
exit;
} elseif (!empty($_POST['apply'])) {
relayd_configure_do();
filter_configure();
/* Wipe out old relayd anchors no longer in use. */
relayd_cleanup_lb_marked();
clear_subsystem_dirty('loadbalancer');
header(url_safe('Location: /load_balancer_virtual_server.php'));
exit;
}
}
/* Index lbpool array for easy hyperlinking */
$poodex = array();
for ($i = 0; isset($config['load_balancer']['lbpool'][$i]); $i++) {
$poodex[$config['load_balancer']['lbpool'][$i]['name']] = $i;
}
$service_hook = 'relayd';
include("head.inc");
legacy_html_escape_form_data($a_vs);
$main_buttons = array(
array('label'=>gettext('Add'), 'href'=>'load_balancer_virtual_server_edit.php'),
);
?>
<body>
<script type="text/javascript">
$( document ).ready(function() {
// delete host action
$(".act_delete").click(function(event){
event.preventDefault();
var id = $(this).data("id");
// delete single
BootstrapDialog.show({
type:BootstrapDialog.TYPE_DANGER,
title: "<?= gettext("Load Balancer: Virtual Server Setup");?>",
message: "<?=gettext("Do you really want to delete this entry?");?>",
buttons: [{
label: "<?= gettext("No");?>",
action: function(dialogRef) {
dialogRef.close();
}}, {
label: "<?= gettext("Yes");?>",
action: function(dialogRef) {
$.post(window.location, {act: 'del', id:id}, function(data) {
location.reload();
});
}
}]
});
});
});
//]]>
</script>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (is_subsystem_dirty('loadbalancer')): ?><br/>
<?php print_info_box_apply(gettext("The virtual server configuration has been changed") . ".<br />" . gettext("You must apply the changes in order for them to take effect."));?><br />
<?php endif; ?>
<section class="col-xs-12">
<div class="tab-content content-box col-xs-12">
<form method="post" name="iform" id="iform">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th><?=gettext("Name");?></th>
<th><?=gettext("Protocol");?></th>
<th><?=gettext("IP Address");?></th>
<th><?=gettext('Port');?></th>
<th><?=gettext('Pool');?></th>
<th><?=gettext('Fall Back Pool');?></th>
<th><?=gettext("Description");?></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$i=0;
foreach ($a_vs as $vs):?>
<tr>
<td><?=$vs['name'];?></td>
<td><?=$vs['relay_protocol'];?></td>
<td><?=$vs['ipaddr'];?></td>
<td><?=$vs['port'];?></td>
<td>
<a href="load_balancer_pool_edit.php?id=<?=$poodex[$vs['poolname']];?>">
<?=$vs['poolname'];?>
</a>
<td>
<?php
if(!empty($vs['sitedown'])):?>
<a href="load_balancer_pool_edit.php?id=<?=$poodex[$vs['sitedown']];?>">
<?=$vs['sitedown'];?>
</a>
<?php
else:?>
<?=gettext("none");?>
<?php
endif;?>
<td><?=$vs['descr'];?></td>
<td>
<a href="load_balancer_virtual_server_edit.php?id=<?=$i;?>" class="btn btn-default btn-xs">
<span class="glyphicon glyphicon-pencil"></span>
</a>
<a data-id="<?=$i;?>" class="act_delete btn btn-default btn-xs">
<span class="fa fa-trash text-muted"></span>
</a>
<a href="load_balancer_virtual_server_edit.php?act=dup&id=<?=$i;?>" class="btn btn-default btn-xs" data-toggle="tooltip" title="<?=gettext("clone rule");?>">
<span class="fa fa-clone text-muted"></span>
</a>
</td>
</tr>
<?php
++$i;
endforeach;?>
</tbody>
</table>
</div>
</form>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc"); ?>
<?php
/*
Copyright (C) 2014-2016 Deciso B.V.
Copyright (C) 2005-2008 Bill Marquette <bill.marquette@gmail.com>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("guiconfig.inc");
require_once("services.inc");
require_once("plugins.inc.d/relayd.inc");
require_once("interfaces.inc");
if (empty($config['load_balancer']) || !is_array($config['load_balancer'])) {
$config['load_balancer'] = array();
}
if (empty($config['load_balancer']['virtual_server']) || !is_array($config['load_balancer']['virtual_server'])) {
$config['load_balancer']['virtual_server'] = array();
}
$a_vs = &$config['load_balancer']['virtual_server'];
$copy_fields=array('name', 'descr', 'poolname', 'port', 'sitedown', 'ipaddr', 'mode', 'relay_protocol');
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (isset($_GET['id']) && !empty($a_vs[$_GET['id']])) {
$id = $_GET['id'];
}
$pconfig = array();
// copy fields
foreach ($copy_fields as $fieldname) {
if (isset($id) && isset($a_vs[$id][$fieldname])) {
$pconfig[$fieldname] = $a_vs[$id][$fieldname];
} else {
$pconfig[$fieldname] = null;
}
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['id']) && !empty($a_vs[$_POST['id']])) {
$id = $_POST['id'];
}
$pconfig = $_POST;
$input_errors = array();
/* input validation */
switch($pconfig['mode']) {
case "redirect":
$reqdfields = explode(" ", "ipaddr name mode");
$reqdfieldsn = array(gettext("IP Address"),gettext("Name"),gettext("Mode"));
break;
case "relay":
$reqdfields = explode(" ", "ipaddr name mode relay_protocol");
$reqdfieldsn = array(gettext("IP Address"),gettext("Name"),gettext("Relay Protocol"));
break;
}
do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors);
for ($i=0; isset($config['load_balancer']['virtual_server'][$i]); $i++) {
if (($pconfig['name'] == $config['load_balancer']['virtual_server'][$i]['name']) && ($i != $id)) {
$input_errors[] = gettext("This virtual server name has already been used. Virtual server names must be unique.");
}
}
if (preg_match('/[ \/]/', $pconfig['name'])) {
$input_errors[] = gettext("You cannot use spaces or slashes in the 'name' field.");
}
if ($pconfig['port'] != "" && !is_portoralias($pconfig['port'])) {
$input_errors[] = gettext("The port must be an integer between 1 and 65535, a port alias, or left blank.");
}
if (!is_ipaddroralias($pconfig['ipaddr']) && !is_subnetv4($pconfig['ipaddr'])) {
$input_errors[] = sprintf(gettext("%s is not a valid IP address, IPv4 subnet, or alias."), $_POST['ipaddr']);
} elseif (is_subnetv4($pconfig['ipaddr']) && subnet_size($pconfig['ipaddr']) > 64) {
$input_errors[] = sprintf(gettext("%s is a subnet containing more than 64 IP addresses."), $pconfig['ipaddr']);
}
if ((strtolower($pconfig['relay_protocol']) == "dns") && !empty($pconfig['sitedown'])) {
$input_errors[] = gettext("You cannot select a Fall Back Pool when using the DNS relay protocol.");
}
if (count($input_errors) == 0) {
$vsent = array();
foreach ($copy_fields as $fieldname) {
$vsent[$fieldname] = $pconfig[$fieldname];
}
if ($vsent['sitedown'] == "") {
unset($vsent['sitedown']);
}
if ($vsent['mode'] != 'relay'){
// relay protocol only applies to relay
unset($vsent['relay_protocol']);
}
if (isset($id)) {
if ($a_vs[$id]['name'] != $pconfig['name']) {
/* Because the VS name changed, mark the old name for cleanup. */
relayd_cleanup_lb_mark_anchor($a_vs[$id]['name']);
}
$a_vs[$id] = $vsent;
} else {
$a_vs[] = $vsent;
}
mark_subsystem_dirty('loadbalancer');
write_config();
header(url_safe('Location: /load_balancer_virtual_server.php'));
exit;
}
}
$service_hook = 'relayd';
legacy_html_escape_form_data($pconfig);
include("head.inc");
?>
<body>
<script type="text/javascript">
$( document ).ready(function() {
// collect all known aliases per type
var all_aliases = {};
$("#aliases > option").each(function(){
if (all_aliases[$(this).data('type')] == undefined) {
all_aliases[$(this).data('type')] = [];
}
all_aliases[$(this).data('type')].push($(this).val())
});
$("#ipadd").typeahead({ source: all_aliases['host'] });
$("#port").typeahead({ source: all_aliases['port'] });
$("#mode").change(function(){
if ($(this).val() == 'redirect') {
$("#protocol").hide();
} else {
$("#protocol").show();
}
});
$("#mode").change();
});
</script>
<!-- push all available (nestable) aliases in a hidden select box -->
<select class="hidden" id="aliases">
<?php
if (!empty($config['aliases']['alias'])):
foreach ($config['aliases']['alias'] as $alias):
if ($alias['type'] == 'host' || $alias['type'] == 'port'):?>
<option data-type="<?=$alias['type'];?>" value="<?=htmlspecialchars($alias['name']);?>">
<?=htmlspecialchars($alias['name']);?>
</option>
<?php
endif;
endforeach;
endif;
?>
</select>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
<section class="col-xs-12">
<div class="content-box">
<form method="post" name="iform" id="iform">
<div class="table-responsive">
<table class="table table-striped opnsense_standard_table_form">
<tr>
<td width="22%">
<strong><?=gettext("Add/edit - Virtual Server entry"); ?></strong>
</td>
<td width="78%" align="right">
<small><?=gettext("full help"); ?> </small>
<i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_page" type="button"></i>
</td>
</tr>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Name"); ?></td>
<td>
<input name="name" type="text" value="<?=$pconfig['name'];?>"/>
</td>
</tr>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Description"); ?></td>
<td>
<input name="descr" type="text" value="<?=$pconfig['descr'];?>"/>
</td>
</tr>
<tr>
<td><a id="help_for_ipaddr" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("IP Address"); ?></td>
<td>
<input type="text" id="ipadd" name="ipaddr" value="<?=$pconfig['ipaddr'];?>" />
<div class="hidden" for="help_for_ipaddr">
<?=gettext("This is normally the WAN IP address that you would like the server to listen on. All connections to this IP and port will be forwarded to the pool cluster."); ?>
<br /><?=gettext("You may also specify a host alias listed in Firewall -&gt; Aliases here."); ?>
</div>
</td>
</tr>
<tr>
<td><a id="help_for_port" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Port"); ?></td>
<td>
<input type="text" name="port" id="port" value="<?=$pconfig['port'];?>" />
<div class="hidden" for="help_for_port">
<?=gettext("This is the port that the clients will connect to. All connections to this port will be forwarded to the pool cluster."); ?>
<br /><?=gettext("If left blank, listening ports from the pool will be used."); ?>
<br /><?=gettext("You may also specify a port alias listed in Firewall -&gt; Aliases here."); ?>
</div>
</td>
</tr>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Virtual Server Pool"); ?></td>
<td>
<?php
if(count($config['load_balancer']['lbpool']) == 0): ?>
<b><?=gettext("NOTE:"); ?></b> <?=gettext("Please add a pool on the Pools tab to use this feature."); ?>
<?php
else: ?>
<select id="poolname" name="poolname">
<?php
foreach($config['load_balancer']['lbpool'] as $pool):?>
<option value="<?=htmlspecialchars($pool['name']);?>" <?=$pool['name'] == $pconfig['poolname'] ? " selected=\"selected\"" : "";?>>
<?=htmlspecialchars($pool['name']);?>
</option>
<?php
endforeach;?>
</select>
<?php
endif; ?>
</td>
</tr>
<tr>
<td><a id="help_for_sitedown" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Fall Back Pool"); ?></td>
<td>
<?php
if(empty($config['load_balancer']['lbpool']) || count($config['load_balancer']['lbpool']) == 0): ?>
<b><?=gettext("NOTE:"); ?></b> <?=gettext("Please add a pool on the Pools tab to use this feature."); ?>
<?php
else: ?>
<select id="sitedown" name="sitedown">
<option value=""<?=empty($pconfig['sitedown']) ? "selected=\"selected\"" : ''?>>
<?=gettext("none"); ?>
</option>
<?php
foreach($config['load_balancer']['lbpool'] as $pool):?>
<option value="<?=htmlspecialchars($pool['name']);?>" <?=$pool['name'] == $pconfig['sitedown'] ? " selected=\"selected\"" : "";?>>
<?=htmlspecialchars($pool['name']);?>
</option>
<?php
endforeach;?>
</select>
<?php
endif; ?>
<div class="hidden" for="help_for_sitedown">
<?=gettext("The server pool to which clients will be redirected if *ALL* servers in the Virtual Server Pool are offline."); ?>
<br /><?=gettext("This option is NOT compatible with the DNS relay protocol."); ?>
</div>
</td>
</tr>
<tr>
<td><a id="help_for_mode" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Mode");?></td>
<td>
<select name="mode" id="mode">
<option value="redirect" <?=$pconfig['mode'] != 'relay' ? " selected=\"selected\"" : ""?>>
<?=gettext("Redirect");?>
</option>
<option value="relay" <?=$pconfig['mode'] == 'relay' ? " selected=\"selected\"" : ""?>>
<?=gettext("Relay");?>
</option>
</select>
<div class="hidden" for="help_for_mode">
<strong><?=gettext("Redirect");?></strong><br/>
<?=gettext("Redirections are translated to pf(4) rdr-to rules for stateful forwarding to a target host from a health-checked table on layer 3.");?>
<strong><?=gettext("Relay");?></strong><br/>
<?=gettext("Relays allow application layer load balancing, TLS acceleration, and general purpose TCP proxying on layer 7.");?>
</div>
</td>
</tr>
<tr id="protocol">
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Relay Protocol"); ?></td>
<td>
<select name="relay_protocol">
<option value="tcp" <?=$pconfig['relay_protocol'] == "tcp" ? " selected=\"selected\"" : "";?>>
<?=gettext("TCP");?>
</option>
<option value="dns" <?=$pconfig['relay_protocol'] == "dns" ? " selected=\"selected\"" : "";?>>
<?=gettext("DNS");?>
</option>
</select>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input name="Save" type="submit" class="btn btn-primary" value="<?=gettext("Submit"); ?>" />
<input type="button" class="btn btn-default" value="<?=gettext("Cancel");?>" onclick="window.location.href='/load_balancer_virtual_server.php'" />
<?php if (isset($id) && (empty($_GET['act'] ) || $_GET['act'] != 'dup')): ?>
<input name="id" type="hidden" value="<?=$id;?>" />
<?php endif; ?>
</td>
</tr>
<tfoot>
<tr>
<td colspan="2">
<span class="text-danger"><strong><?=gettext("Note:"); ?></strong></span>
<?=gettext("Don't forget to add a firewall rule for the virtual server/pool after you're finished setting it up."); ?>
</td>
</tr>
</tfoot>
</table>
</div>
</form>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc"); ?>
<?php
/*
Copyright (C) 2014-2016 Deciso B.V.
Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("guiconfig.inc");
require_once("filter.inc");
require_once("plugins.inc.d/relayd.inc");
require_once("services.inc");
require_once("interfaces.inc");
if (empty($config['load_balancer']) || !is_array($config['load_balancer'])) {
$config['load_balancer'] = array();
}
if (empty($config['load_balancer']['lbpool']) || !is_array($config['load_balancer']['lbpool'])) {
$config['load_balancer']['lbpool'] = array();
}
$a_pool = &$config['load_balancer']['lbpool'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!empty($_POST['apply'])) {
relayd_configure_do();
filter_configure();
clear_subsystem_dirty('loadbalancer');
header(url_safe('Location: /status_lb_pool.php'));
exit;
} else {
// change pool configuration (enabled/disabled servers)
$pconfig = $_POST;
if (!empty($pconfig['pools'])) {
foreach ($pconfig['pools'] as $form_pool) {
foreach ($a_pool as & $pool) {
if ($pool['name'] == $form_pool) {
$all_ips = array_merge((array) $pool['servers'], (array) $pool['serversdisabled']);
$new_disabled = array_diff($all_ips, (array)$pconfig[$form_pool]);
$new_enabled = (array)$pconfig[$form_pool];
$pool['servers'] = $new_enabled;
$pool['serversdisabled'] = $new_disabled;
}
}
}
mark_subsystem_dirty('loadbalancer');
write_config("Updated load balancer pools via status screen.");
}
header(url_safe('Location: /status_lb_pool.php'));
exit;
}
}
$service_hook = 'relayd';
include("head.inc");
$relay_hosts = relayd_get_lb_summary();
legacy_html_escape_form_data($a_pool);
legacy_html_escape_form_data($relay_hosts);
?>
<body>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (is_subsystem_dirty('loadbalancer')): ?><br/>
<?php print_info_box_apply(sprintf(gettext("The load balancer configuration has been changed%sYou must apply the changes in order for them to take effect."), "<br />"));?>
<?php endif; ?>
<section class="col-xs-12">
<div class="tab-content content-box col-xs-12">
<form method="post">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th><?=gettext("Name");?></th>
<th><?=gettext("Mode");?></th>
<th><?=gettext("Servers");?></th>
<th><?=gettext("Monitor");?></th>
<th><?=gettext("Description");?></th>
</tr>
</thead>
<tbody>
<?php
foreach ($a_pool as & $pool): ?>
<tr>
<td><?=$pool['name'];?></td>
<td>
<?php
switch($pool['mode']) {
case "loadbalance":
echo "Load balancing";
break;
case "failover":
echo "Manual failover";
break;
default:
echo "(default)";
}?>
</td>
<td>
<input type="hidden" name="pools[]" value="<?=$pool['name'];?>">
<table class="table table-condensed">
<?php
$pool_hosts=array();
$svr = array();
foreach ((array) $pool['servers'] as $server) {
$svr['addr']=$server;
$svr['state']=$relay_hosts[$pool['name'].":".$pool['port']][$server]['state'];
$svr['avail']=$relay_hosts[$pool['name'].":".$pool['port']][$server]['avail'];
$svr['bgcolor'] = $svr['state'] == 'up' ? "#90EE90" : "#F08080";
$pool_hosts[]=$svr;
}
foreach ((array) $pool['serversdisabled'] as $server) {
$svr['addr']="$server";
$svr['state']='disabled';
$svr['avail']='disabled';
$svr['bgcolor']='white';
$pool_hosts[]=$svr;
}
asort($pool_hosts);
foreach ($pool_hosts as $server):?>
<tr>
<td>
<input type="<?=$pool['mode'] == "loadbalance" ? "checkbox" : "radio";?>"
name="<?=$pool['name'];?>[]" value="<?=$server['addr'];?>"
<?=$server['state'] != 'disabled' ? "checked=\"checked\"" : "";?>
/>
</td>
<td style="background:<?=$server['bgcolor'];?>"><?="{$server['addr']}:{$pool['port']}";?></td>
<td style="background:<?=$server['bgcolor'];?>"><?=!empty($server['avail']) ? " ({$server['avail']}) " : "";?></td>
</tr>
<?php
endforeach;?>
</table>
</td>
<td><?=$pool['monitor']; ?></td>
<td><?=$pool['descr'];?></td>
</tr>
<?php
endforeach; ?>
<tr>
<td colspan="5">
<input name="Submit" type="submit" class="btn btn-primary" value="<?= gettext("Save"); ?>" />
</td>
</tr>
</tbody>
</table>
</div>
</form>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc"); ?>
<?php
/*
Copyright (C) 2014-2016 Deciso B.V.
Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("guiconfig.inc");
require_once("filter.inc");
require_once("services.inc");
require_once("plugins.inc.d/relayd.inc");
if (empty($config['load_balancer']['lbpool']) || !is_array($config['load_balancer']['lbpool'])) {
$a_pool = array();
} else {
$a_pool = &$config['load_balancer']['lbpool'];
}
if (empty($config['load_balancer']['virtual_server']) || !is_array($config['load_balancer']['virtual_server'])) {
$a_vs = array();
} else {
$a_vs = &$config['load_balancer']['virtual_server'];
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!empty($_POST['apply'])) {
relayd_configure_do();
filter_configure();
clear_subsystem_dirty('loadbalancer');
header(url_safe('Location: /status_lb_vs.php'));
exit;
}
}
$rdr_a = relayd_get_lb_redirects();
$service_hook = 'relayd';
legacy_html_escape_form_data($a_vs);
legacy_html_escape_form_data($a_pool);
legacy_html_escape_form_data($rdr_a);
include("head.inc");
?>
<body>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (is_subsystem_dirty('loadbalancer')): ?><br/>
<?php print_info_box_apply(sprintf(gettext("The load balancer configuration has been changed%sYou must apply the changes in order for them to take effect."), "<br />"));?>
<?php endif; ?>
<section class="col-xs-12">
<div class="tab-content content-box col-xs-12">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<td><?=gettext("Name"); ?></td>
<td><?=gettext("Address"); ?></td>
<td><?=gettext("Servers"); ?></td>
<td><?=gettext("Status"); ?></td>
<td><?=gettext("Description"); ?></td>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach ($a_vs as $vsent): ?>
<tr>
<td><?=$vsent['name'];?></td>
<td><?=$vsent['ipaddr']." : ".$vsent['port'];?></td>
<td>
<?php
foreach ($a_pool as $vipent):
if ($vipent['name'] == $vsent['poolname']):?>
<?=implode('<br/>',$vipent['servers']);?>
<?php
endif;
endforeach;?>
</td>
<?php
switch (trim($rdr_a[$vsent['name']]['status'])) {
case 'active':
$bgcolor = "#90EE90"; // lightgreen
$rdr_a[$vsent['name']]['status'] = "Active";
break;
case 'down':
$bgcolor = "#F08080"; // lightcoral
$rdr_a[$vsent['name']]['status'] = "Down";
break;
default:
$bgcolor = "#D3D3D3"; // lightgray
$rdr_a[$vsent['name']]['status'] = 'Unknown - relayd not running?';
}
?>
<td>
<table border="0" cellpadding="3" cellspacing="2" summary="status">
<tr><td bgcolor="<?=$bgcolor?>"><?=$rdr_a[$vsent['name']]['status']?> </td></tr>
</table>
<?=!empty($rdr_a[$vsent['name']]['total']) ? "Total Sessions: {$rdr_a[$vsent['name']]['total']}" : "";?>
<?=!empty($rdr_a[$vsent['name']]['last']) ? "<br />Last: {$rdr_a[$vsent['name']]['last']}" : "";?>
<?=!empty($rdr_a[$vsent['name']]['average']) ? "<br />Average: {$rdr_a[$vsent['name']]['average']}" : "";?>
</td>
<td><?=$vsent['descr'];?></td>
</tr>
<?php
$i++;
endforeach; ?>
</tbody>
</table>
</div>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc"); ?>
<?php
$load_balancer_status_title = gettext('Load Balancer');
$load_balancer_status_title_link = 'status_lb_pool.php';
<?php
/*
Copyright (C) 2014 Deciso B.V.
Copyright (C) 2010 Jim Pingle
Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>
Copyright (C) 2005-2008 Bill Marquette
Copyright (C) 2004-2005 T. Lechat <dev@lechat.org>, Manuel Kasper <mk@neon1.net>
and Jonathan Watt <jwatt@jwatt.org>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("guiconfig.inc");
require_once("filter.inc");
require_once("plugins.inc.d/relayd.inc");
$now = time();
$year = date("Y");
if (!is_array($config['load_balancer'])) {
$config['load_balancer'] = array();
}
if (!is_array($config['load_balancer']['lbpool'])) {
$config['load_balancer']['lbpool'] = array();
}
if (!is_array($config['load_balancer']['virtual_server'])) {
$config['load_balancer']['virtual_server'] = array();
}
$a_vs = &$config['load_balancer']['virtual_server'];
$a_pool = &$config['load_balancer']['lbpool'];
$rdr_a = relayd_get_lb_redirects();
$relay_hosts = relayd_get_lb_summary();
$lb_logfile = '/var/log/relayd.log';
$nentries = isset($config['syslog']['nentries']) ? $config['syslog']['nentries'] : 50;
?>
<table class="table table-striped table-condensed">
<thead>
<tr>
<th width="10%" class="listhdrr"><?= gettext('Server') ?></th>
<th width="10%" class="listhdrr"><?= gettext('Pool') ?></th>
<th width="30%" class="listhdr"><?= gettext('Description') ?></th>
</tr>
</thead>
<?php $i = 0; foreach ($a_vs as $vsent) :
?>
<tr>
<?php
switch (trim($rdr_a[$vsent['name']]['status'])) {
case 'active':
$bgcolor = "#90EE90"; // lightgreen
$rdr_a[$vsent['name']]['status'] = gettext("Active");
break;
case 'down':
$bgcolor = "#F08080"; // lightcoral
$rdr_a[$vsent['name']]['status'] = gettext("Down");
break;
default:
$bgcolor = "#D3D3D3"; // lightgray
$rdr_a[$vsent['name']]['status'] = gettext('Unknown - relayd not running?');
}
?>
<td class="listlr">
<?=$vsent['name'];?><br />
<span style="background-color: <?=$bgcolor?>; display: block"><i><?= $rdr_a[$vsent['name']]['status'] ?></i></span>
<?=$vsent['ipaddr'].":".$vsent['port'];?><br />
</td>
<td class="listr" align="center" >
<table>
<?php
foreach ($a_pool as $pool) {
if ($pool['name'] == $vsent['poolname']) {
$pool_hosts=array();
foreach ((array) $pool['servers'] as $server) {
$svr['ip']['addr']=$server;
$svr['ip']['state']=$relay_hosts[$pool['name'].":".$pool['port']][$server]['state'];
$svr['ip']['avail']=$relay_hosts[$pool['name'].":".$pool['port']][$server]['avail'];
$pool_hosts[]=$svr;
}
foreach ((array) $pool['serversdisabled'] as $server) {
$svr['ip']['addr']="$server";
$svr['ip']['state']='disabled';
$svr['ip']['avail']='disabled';
$pool_hosts[]=$svr;
}
asort($pool_hosts);
foreach ((array) $pool_hosts as $server) {
if ($server['ip']['addr']!="") {
switch ($server['ip']['state']) {
case 'up':
$bgcolor = "#90EE90"; // lightgreen
$checked = "checked";
break;
case 'disabled':
$bgcolor = "#FFFFFF"; // white
$checked = "";
break;
default:
$bgcolor = "#F08080"; // lightcoral
$checked = "checked";
}
echo "<tr>";
echo "<td bgcolor=\"{$bgcolor}\">&nbsp;{$server['ip']['addr']}:{$pool['port']}&nbsp;</td><td bgcolor=\"{$bgcolor}\">&nbsp;";
if ($server['ip']['avail']) {
echo " ({$server['ip']['avail']}) ";
}
echo "&nbsp;</td></tr>";
}
}
}
}
?>
</table>
</td>
<td class="listbg" >
<?=$vsent['descr'];?>
</td>
</tr>
<?php $i++;
endforeach; ?>
</table>
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