net/relayd: merge version 2.0 from master

This commit is contained in:
Franco Fichtner 2018-06-05 14:44:37 +02:00
parent 00f0cc8a76
commit 85a0f2fbc9
41 changed files with 3163 additions and 2811 deletions

View file

@ -1,5 +1,4 @@
Copyright (c) 2015-2016 Ad Schellevis
Copyright (c) 2005-2008 Bill Marquette <bill.marquette@gmail.com>
Copyright (c) 2005-2006 Colin Smith <ethethlay@gmail.com>
Copyright (c) 2011 Dan Myers
Copyright (c) 2017-2018 David Harrigan
@ -10,20 +9,17 @@ Copyright (c) 2006 Eric Friesen
Copyright (c) 2008-2010 Ermal Luçi
Copyright (c) 2017-2018 Fabian Franz
Copyright (c) 2014-2018 Franco Fichtner <franco@opnsense.org>
Copyright (c) 2016-2017 Frank Wall
Copyright (c) 2016-2018 Frank Wall
Copyright (c) 2017 Giuseppe De Marco <giuseppe.demarco@unical.it>
Copyright (c) 2010 Jim Pingle <jimp@pfsense.org>
Copyright (c) 2004-2005 Jonathan Watt <jwatt@jwatt.org>
Copyright (c) 2015 Jos Schellevis
Copyright (c) 2003-2006 Manuel Kasper <mk@neon1.net>
Copyright (c) 2017-2018 Michael Muenz
Copyright (c) 2012 Pierre POMES <pierre.pomes@gmail.com>
Copyright (c) 2004-2012 Scott Ullrich <sullrich@gmail.com>
Copyright (c) 2010 Seth Mos <seth.mos@dds.nl>
Copyright (c) 2008 Shrew Soft Inc.
Copyright (c) 2017 Smart-Soft
Copyright (c) 2013 Stanley P. Miller \ stan-qaz
Copyright (c) 2004-2005 T. Lechat <dev@lechat.org>
Copyright (c) 2010 Yehuda Katz
All rights reserved.

View file

@ -1,6 +1,5 @@
PLUGIN_NAME= relayd
PLUGIN_VERSION= 1.2
PLUGIN_VERSION= 1
PLUGIN_VERSION= 2.0
PLUGIN_DEPENDS= relayd
PLUGIN_COMMENT= Relayd Load Balancer
PLUGIN_MAINTAINER= frank.brendel@eurolog.com

View file

@ -1,38 +1,38 @@
<?php
/*
Copyright (C) 2016 Franco Fichtner <franco@opnsense.org>
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.
*/
* Copyright (C) 2018 EURO-LOG AG
* Copyright (C) 2016 Franco Fichtner <franco@opnsense.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.
*/
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']);
return isset($config['OPNsense']['relayd']['general']['enabled']) &&
$config['OPNsense']['relayd']['general']['enabled'] == 1;
}
function relayd_firewall($fw)
@ -53,12 +53,15 @@ function relayd_services()
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;
$services[] = array(
'description' => gettext('Relayd Load Balancer'),
'configd' => array(
'restart' => array('relayd restart'),
'start' => array('relayd start'),
'stop' => array('relayd stop'),
),
'name' => 'relayd',
);
return $services;
}
@ -69,7 +72,8 @@ function relayd_xmlrpc_sync()
$result[] = array(
'description' => gettext('Relayd Load Balancer'),
'section' => 'load_balancer',
'section' => 'OPNsense.relayd',
/* kept for backwards compat: */
'id' => 'lb',
);
@ -84,450 +88,3 @@ function relayd_syslog()
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']] = "check {$type['type']} ";
$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;
default:
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";
}
if (isset($vs_a[$i]['sessiontimeout'])) {
$conf .= " session timeout {$vs_a[$i]['sessiontimeout']} \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";
}
if (isset($vs_a[$i]['sessiontimeout'])) {
$conf .= " session timeout {$vs_a[$i]['sessiontimeout']} \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);
}

View file

@ -1,3 +0,0 @@
dns protocol "dns" {
tcp { nodelay, sack, socket buffer 1024, backlog 1000 }
}

View file

@ -1,3 +0,0 @@
protocol "tcp" {
tcp { nodelay, socket buffer 65536 }
}

113
net/relayd/src/etc/rc.d/os-relayd Executable file
View file

@ -0,0 +1,113 @@
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: os-relayd
# REQUIRE: NETWORKING syslogd
# BEFORE: DAEMON
# KEYWORD: shutdown
. /etc/rc.subr
name="osrelayd"
rcvar="osrelayd_enable"
load_rc_config $name
: ${relayd_enable="NO"}
command="/usr/local/sbin/relayd"
cmd_string="relayd: parent"
relayctl="/usr/local/sbin/relayctl"
pidfile="/var/run/osrelayd.pid"
relayd_start () {
relayd_status
if [ $? -eq 0 ]; then
debug "relayd_start: relayd ist already running"
return 0
fi
debug "relayd_start: start relayd"
run_rc_command "start"
if [ $? -eq 0 ]; then
i=0
status="nok"
# give relayd some time to start
while [ $i -ne 3 ]; do
ps_pid=`ps ax -o pid= -o command= | grep "$cmd_string" | grep -v grep | awk '{ print $1 }'`
if [ -z "$ps_pid" ]; then
status="Cannot get pid for $command"
else
status="ok"
break
fi
echo $status
sleep 1
i=$(( $i + 1 ))
done
if [ $status != 'ok' ]; then
err 1 "$status"
fi
echo $ps_pid > $pidfile
return $?
fi
return 1
}
relayd_stop () {
relayd_status
if [ $? -eq 1 ]; then
return 0
fi
run_rc_command "stop"
if [ $? -ne 0 ]; then
err 1 "Cannot stop relayd with pid from $pidfile"
fi
rm -f $pidfile
return $?
}
relayd_restart () {
relayd_stop
if [ $? -ne 0 ]; then
return $?
fi
sleep 1
relayd_start
return $?
}
relayd_status () {
run_rc_command "status"
return $?
}
relayd_reload () {
$relayctl reload
}
case $1 in
start)
relayd_start
exit $?
;;
stop)
relayd_stop
exit $?
;;
restart)
relayd_restart
exit $?
;;
status)
relayd_status
exit $?
;;
reload)
relayd_reload;
exit $?
;;
esac

View file

@ -0,0 +1,141 @@
<?php
/*
* Copyright (C) 2018 EURO-LOG AG
* 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.
*/
namespace OPNsense\Relayd\Api;
use \OPNsense\Base\ApiMutableServiceControllerBase;
use \OPNsense\Core\Backend;
use \OPNsense\Relayd\Relayd;
/**
* Class ServiceController
* @package OPNsense\relayd
*/
class ServiceController extends ApiMutableServiceControllerBase
{
static protected $internalServiceClass = '\OPNsense\Relayd\Relayd';
static protected $internalServiceEnabled = 'general.enabled';
static protected $internalServiceTemplate = 'OPNsense/Relayd';
static protected $internalServiceName = 'relayd';
private $internalLockHandle = null;
/**
* simple lock mechanism
*/
private function lock($release = null)
{
if ($release != null) {
flock($this->internalLockHandle, LOCK_UN);
fclose($this->internalLockHandle);
return true;
}
$this->internalLockHandle = fopen("/tmp/relayd.lock", "w+");
if ($this->internalLockHandle != null && flock($this->internalLockHandle, LOCK_EX)) {
return true;
}
return false;
}
/**
* test relayd configuration
* @return array
*/
public function configtestAction()
{
if ($this->request->isPost()) {
$result['status'] = 'ok';
$this->sessionClose();
$backend = new Backend();
$result['function'] = "configtest";
$result['template'] = trim($backend->configdRun('template reload OPNsense/Relayd'));
if ($result['template'] != 'OK') {
$result['result'] = "Template error: " . $result['template'];
return $result;
}
$result['result'] = trim($backend->configdRun('relayd configtest'));
return $result;
} else {
return array('status' => 'failed');
}
}
/**
* reconfigure relayd
* @return array
*/
public function reconfigureAction()
{
if ($this->request->isPost()) {
if ($this->lock()) {
$this->sessionClose();
$result['function'] = "reconfigure";
$result['status'] = 'failed';
$mdlRelayd = new Relayd();
$backend = new Backend();
$status = $this->statusAction();
if ($mdlRelayd->general->enabled->__toString() == 1) {
$result = $this->configtestAction();
if ($result['template'] == 'OK' && preg_match('/configuration OK$/', $result['result']) == 1) {
if ($status['status'] != 'running') {
$result['result'] = trim($backend->configdRun('relayd start'));
} else {
$result['result'] = trim($backend->configdRun('relayd reload'));
}
} else {
return $result;
}
} else {
if ($status['status'] == 'running') {
$result['result'] = trim($backend->configdRun('relayd stop'));
}
}
$this->lock(1);
$mdlRelayd = new Relayd();
if ($mdlRelayd->configClean()) {
$result['status'] = 'ok';
}
return $result;
} else {
throw new \Exception("Cannot get lock");
}
} else {
return array('status' => 'failed');
}
}
/**
* avoid restarting Relayd on reconfigure
*/
protected function reconfigureForceRestart()
{
return 0;
}
}

View file

@ -0,0 +1,388 @@
<?php
/**
* Copyright (C) 2018 EURO-LOG AG
*
* 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.
*
*/
namespace OPNsense\Relayd\Api;
use \OPNsense\Base\ApiControllerBase;
use \OPNsense\Core\Config;
use \OPNsense\Relayd\Relayd;
use \OPNsense\Base\UIModelGrid;
/**
* Class SettingsController
* @package OPNsense\Relayd
*/
class SettingsController extends ApiControllerBase
{
static protected $internalModelName = 'relayd';
static protected $internalModelClass = '\OPNsense\Relayd\Relayd';
public $mdlRelayd = null;
/**
* list with valid model node types
*/
private $nodeTypes = array('general', 'host', 'tablecheck', 'table', 'protocol', 'virtualserver');
/**
* initialize object properties
*/
public function onConstruct()
{
$this->mdlRelayd = new Relayd();
}
/**
* check if changes to the relayd settings were made
* @return result array
*/
public function dirtyAction()
{
$result = array('status' => 'ok');
$result['relayd']['dirty'] = $this->mdlRelayd->configChanged();
return $result;
}
/**
* query relayd settings
* @param $nodeType
* @param $uuid
* @return result array
*/
public function getAction($nodeType = null, $uuid = null)
{
$result = array("result" => "failed");
if ($this->request->isGet() && $nodeType != null) {
$this->validateNodeType($nodeType);
if ($nodeType == 'general') {
$node = $this->mdlRelayd->getNodeByReference($nodeType);
} else {
if ($uuid != null) {
$node = $this->mdlRelayd->getNodeByReference($nodeType . '.' . $uuid);
} else {
$node = $this->mdlRelayd->$nodeType->Add();
}
}
if ($node != null) {
$result['relayd'] = array($nodeType => $node->getNodes());
$result['status'] = 'ok';
}
}
return $result;
}
/**
* set relayd properties
* @param $nodeType
* @param $uuid
* @param $action set or add node
* @return status array
*/
public function setAction($nodeType = null, $uuid = null)
{
$result = array('result' => 'failed', 'validations' => array());
if ($this->request->isPost() && $this->request->hasPost('relayd') && $nodeType != null) {
$this->validateNodeType($nodeType);
if ($nodeType == 'general') {
$node = $this->mdlRelayd->getNodeByReference($nodeType);
} else {
if ($uuid != null) {
$node = $this->mdlRelayd->getNodeByReference($nodeType . '.' . $uuid);
} else {
$node = $this->mdlRelayd->$nodeType->Add();
}
}
if ($node != null) {
$relaydInfo = $this->request->getPost('relayd');
// perform plugin specific validations
if ($nodeType == 'virtualserver') {
// preset defaults for validations
if (empty($relaydInfo[$nodeType]['type'])) {
$relaydInfo[$nodeType]['type'] = $node->type->__toString();
}
if (empty($relaydInfo[$nodeType]['transport_tablemode'])) {
$relaydInfo[$nodeType]['transport_tablemode'] = $node->transport_tablemode->__toString();
}
if (empty($relaydInfo[$nodeType]['backuptransport_tablemode'])) {
$relaydInfo[$nodeType]['backuptransport_tablemode'] =
$node->backuptransport_tablemode->__toString();
}
if ($relaydInfo[$nodeType]['type'] == 'redirect') {
if ($relaydInfo[$nodeType]['transport_tablemode'] != 'least-states' &&
$relaydInfo[$nodeType]['transport_tablemode'] != 'roundrobin') {
$result['validations']['relayd.virtualserver.transport_tablemode'] = sprintf(
gettext('Scheduler "%s" not supported for redirects.'),
$relaydInfo[$nodeType]['transport_tablemode']
);
}
if ($relaydInfo[$nodeType]['backuptransport_tablemode'] != 'least-states' &&
$relaydInfo[$nodeType]['backuptransport_tablemode'] != 'roundrobin') {
$result['validations']['relayd.virtualserver.backuptransport_tablemode'] = sprintf(
gettext('Scheduler "%s" not supported for redirects.'),
$relaydInfo[$nodeType]['backuptransport_tablemode']
);
}
}
if ($relaydInfo[$nodeType]['type'] == 'relay') {
if ($relaydInfo[$nodeType]['transport_tablemode'] == 'least-states') {
$result['validations']['relayd.virtualserver.transport_tablemode'] = sprintf(
gettext('Scheduler "%s" not supported for relays.'),
$relaydInfo[$nodeType]['transport_tablemode']
);
}
if ($relaydInfo[$nodeType]['backuptransport_tablemode'] == 'least-states') {
$result['validations']['relayd.virtualserver.backuptransport_tablemode'] = sprintf(
gettext('Scheduler "%s" not supported for relays.'),
$relaydInfo[$nodeType]['backuptransport_tablemode']
);
}
}
} elseif ($nodeType == 'tablecheck') {
switch ($relaydInfo[$nodeType]['type']) {
case 'send':
if (empty($relaydInfo[$nodeType]['expect'])) {
$result['validations']['relayd.tablecheck.expect'] =
gettext('Expect Pattern cannot be empty.');
}
break;
case 'script':
if (empty($relaydInfo[$nodeType]['path'])) {
$result['validations']['relayd.tablecheck.path'] =
gettext('Script path cannot be empty.');
}
break;
case 'http':
if (empty($relaydInfo[$nodeType]['path'])) {
$result['validations']['relayd.tablecheck.path'] =
gettext('Path cannot be empty.');
}
if (empty($relaydInfo[$nodeType]['code']) && empty($relaydInfo[$nodeType]['digest'])) {
$result['validations']['relayd.tablecheck.code'] =
gettext('Provide one of Response Code or Message Digest.');
$result['validations']['relayd.tablecheck.digest'] =
gettext('Provide one of Response Code or Message Digest.');
}
break;
}
}
$node->setNodes($relaydInfo[$nodeType]);
$valMsgs = $this->mdlRelayd->performValidation();
foreach ($valMsgs as $field => $msg) {
$fieldnm = str_replace($node->__reference, "relayd." . $nodeType, $msg->getField());
$result["validations"][$fieldnm] = $msg->getMessage();
}
if (empty($result["validations"])) {
unset($result["validations"]);
$this->mdlRelayd->serializeToConfig();
$cfgRelayd = Config::getInstance()->save();
if ($this->mdlRelayd->configDirty()) {
$result['status'] = 'ok';
}
}
}
}
return $result;
}
/**
* delete relayd settings
* @param $nodeType
* @param $uuid
* @return status array
*/
public function delAction($nodeType = null, $uuid = null)
{
$result = array("result" => "failed");
if ($nodeType != null) {
$this->validateNodeType($nodeType);
if ($uuid != null) {
$node = $this->mdlRelayd->getNodeByReference($nodeType . '.' . $uuid);
if ($node != null) {
$nodeName = $this->mdlRelayd->getNodeByReference($nodeType . '.' . $uuid . '.name')->__toString();
if ($this->mdlRelayd->$nodeType->del($uuid) == true) {
// delete relations
switch ($nodeType) {
case 'host':
$this->deleteRelations(
'table',
'hosts',
$uuid,
'host',
$nodeName,
$this->mdlRelayd
);
break;
case 'tablecheck':
$this->deleteRelations(
'virtualserver',
'transport_tablecheck',
$uuid,
'tablecheck',
$nodeName,
$this->mdlRelayd
);
$this->deleteRelations(
'virtualserver',
'backuptransport_tablecheck',
$uuid,
'tablecheck',
$nodeName,
$this->mdlRelayd
);
break;
case 'table':
$this->deleteRelations(
'virtualserver',
'transport_table',
$uuid,
'table',
$nodeName,
$this->mdlRelayd
);
$this->deleteRelations(
'virtualserver',
'backuptransport_table',
$uuid,
'table',
$nodeName,
$this->mdlRelayd
);
break;
case 'protocol':
$this->deleteRelations(
'virtualserver',
'protocol',
$uuid,
'protocol',
$nodeName,
$this->mdlRelayd
);
break;
}
$this->mdlRelayd->serializeToConfig();
Config::getInstance()->save();
if ($this->mdlRelayd->configDirty()) {
$result['status'] = 'ok';
}
}
}
}
}
return $result;
}
/**
* search relayd settings
* @param $nodeType
* @return result array
*/
public function searchAction($nodeType = null)
{
$this->sessionClose();
if ($this->request->isPost() && $nodeType != null) {
$this->validateNodeType($nodeType);
$grid = new UIModelGrid($this->mdlRelayd->$nodeType);
$fields = array();
switch ($nodeType) {
case 'host':
$fields = array('name', 'address');
break;
case 'tablecheck':
$fields = array('name', 'type');
break;
case 'table':
$fields = array('enabled', 'name');
break;
case 'protocol':
$fields = array('name', 'type');
break;
case 'virtualserver':
$fields = array('enabled', 'name', 'type');
break;
}
$result = $grid->fetchBindRequest($this->request, $fields);
$result['dirty'] = $this->mdlRelayd->configChanged();
return $result;
}
}
/**
* validate nodeType
* @param $nodeType
* @throws \Exception
*/
private function validateNodeType($nodeType = null)
{
if (array_search($nodeType, $this->nodeTypes) === false) {
throw new \Exception('unknown nodeType: ' . $nodeType);
}
}
/**
* delete relations
* @param $nodeType
* @param $uuid
* @param $relNodeType
* @param &$mdlRelayd
* @throws \Exception
*/
private function deleteRelations(
$nodeType = null,
$nodeField = null,
$relUuid = null,
$relNodeType = null,
$relNodeName = null
) {
$nodes = $this->mdlRelayd->$nodeType->getNodes();
// get nodes with relations
foreach ($nodes as $nodeUuid => $node) {
// get relation uuids
foreach ($node[$nodeField] as $fieldUuid => $field) {
// remove uuid from field
if ($fieldUuid == $relUuid) {
$refField = $nodeType . '.' . $nodeUuid . '.' . $nodeField;
$relNode = $this->mdlRelayd->getNodeByReference($refField);
$nodeRels = str_replace($relUuid, '', $relNode->__toString());
$nodeRels = str_replace(',,', ',', $nodeRels);
$nodeRels = rtrim($nodeRels, ',');
$nodeRels = ltrim($nodeRels, ',');
$this->mdlRelayd->setNodeByReference($refField, $nodeRels);
if ($relNode->isEmptyAndRequired()) {
$nodeName = $this->mdlRelayd->getNodeByReference("{$nodeType}.{$nodeUuid}.name")->__toString();
throw new \Exception("Cannot delete $relNodeType '$relNodeName' from $nodeType '$nodeName'");
}
}
}
}
}
}

View file

@ -0,0 +1,124 @@
<?php
/**
* Copyright (C) 2018 EURO-LOG AG
*
* 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.
*
*/
namespace OPNsense\Relayd\Api;
use \OPNsense\Base\ApiControllerBase;
use \OPNsense\Core\Backend;
use \OPNsense\Relayd\Relayd;
/**
* Class StatusController
* @package OPNsense\Relayd
*/
class StatusController extends ApiControllerBase
{
/**
* get relayd summary
*/
public function sumAction()
{
$result = array("result" => "failed");
$backend = new Backend();
$output = array();
$output = explode("\n", trim($backend->configdRun('relayd summary')));
if (empty($output[0])) {
return $result;
}
$result["result"] = 'ok';
$virtualServerId = 0;
$virtualServerType = '';
$tableId = 0;
$virtualserver = array();
$rows = array();
foreach ($output as $line) {
$words = explode("\t", $line);
$id = trim($words[0]);
$type = trim($words[1]);
if ($type == 'redirect' || $type == 'relay') {
// new virtual server id/type means new record
if (($id != $virtualServerId && $virtualServerId > 0) ||
($type != $virtualServerType && strlen($virtualServerType) > 5)) {
$rows[] = $virtualserver;
$virtualserver = array();
}
$virtualServerId = $id;
$virtualServerType = $type;
$virtualserver['id'] = $id;
$virtualserver['type'] = $type;
$virtualserver['name'] = trim($words[2]);
$virtualserver['status'] = trim($words[4]);
}
if ($type == 'table') {
$tableId = $id;
$virtualserver['tables'][$tableId]['name'] = trim($words[2]);
$virtualserver['tables'][$tableId]['status'] = trim($words[4]);
}
if ($type == 'host') {
$hostId = trim($words[0]);
$virtualserver['tables'][$tableId]['hosts'][$hostId]['name'] = trim($words[2]);
$virtualserver['tables'][$tableId]['hosts'][$hostId]['avlblty'] = trim($words[3]);
$virtualserver['tables'][$tableId]['hosts'][$hostId]['status'] = trim($words[4]);
}
}
$rows[] = $virtualserver;
$result["rows"] = $rows;
return $result;
}
/**
* enable/disable relayd objects
*/
public function toggleAction($nodeType = null, $id = null, $action = null)
{
if ($this->request->isPost()) {
$this->sessionClose();
}
$result = array("result" => "failed", "function" => "toggle");
if ($nodeType != null &&
($nodeType == 'redirect' ||
$nodeType == 'table' ||
$nodeType == 'host')) {
if ($action != null &&
($action == 'enable' ||
$action == 'disable')) {
if ($id != null && $id > 0) {
$backend = new Backend();
$result["output"] = $backend->configdRun("relayd toggle $nodeType $action $id");
if (isset($result["output"])) {
$result["result"] = 'ok';
}
$result["output"] = trim($result["output"]);
}
}
}
return $result;
}
}

View file

@ -0,0 +1,53 @@
<?php
/**
* Copyright (C) 2018 EURO-LOG AG
*
* 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.
*
*/
namespace OPNsense\Relayd;
/**
* Class IndexController
* @package OPNsense\Relayd
*/
class IndexController extends \OPNsense\Base\IndexController
{
/**
* relayd index page
* @throws \Exception
*/
public function indexAction()
{
$this->view->formGeneralSettings = $this->getForm("general");
$this->view->formDialogEditHost = $this->getForm("host");
$this->view->formDialogEditTableCheck = $this->getForm("tablecheck");
$this->view->formDialogEditTable = $this->getForm("table");
$this->view->formDialogEditProtocol = $this->getForm("protocol");
$this->view->formDialogEditVirtualServer = $this->getForm("virtualserver");
$this->view->pick('OPNsense/Relayd/index');
}
}

View file

@ -0,0 +1,47 @@
<?php
/**
* Copyright (C) 2018 EURO-LOG AG
*
* 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.
*
*/
namespace OPNsense\Relayd;
/**
* Class StatusController
* @package OPNsense\Relayd
*/
class StatusController extends \OPNsense\Base\IndexController
{
/**
* relayd status page
* @throws \Exception
*/
public function indexAction()
{
$this->view->pick('OPNsense/Relayd/status');
}
}

View file

@ -0,0 +1,45 @@
<form>
<field>
<id>relayd.general.enabled</id>
<label>Enable Relayd</label>
<type>checkbox</type>
<help><![CDATA[Enable or disable Relayd.]]></help>
</field>
<field>
<id>relayd.general.interval</id>
<label>Global Check Interval</label>
<type>text</type>
<help><![CDATA[
Set the interval in seconds at which the hosts will be checked.<br>
The default interval is 10 seconds.]]>
</help>
</field>
<field>
<id>relayd.general.log</id>
<label>State Notification</label>
<type>dropdown</type>
<help><![CDATA[
Log state notifications after completed host checks. Either only<br>
log the updates to new states or log all state notifications,<br>
even if the state didn't change.]]>
</help>
</field>
<field>
<id>relayd.general.prefork</id>
<label>Number Of Processes</label>
<type>text</type>
<help><![CDATA[
When using relays, run the specified number of processes to<br>
handle relayed connections.]]>
</help>
</field>
<field>
<id>relayd.general.timeout</id>
<label>Global Check Timeout</label>
<type>text</type>
<help><![CDATA[
Set the global timeout in milliseconds for checks. This can be<br>
overridden by the timeout value in the table definitions.]]>
</help>
</field>
</form>

View file

@ -0,0 +1,46 @@
<form>
<field>
<id>relayd.host.name</id>
<label>Name</label>
<type>text</type>
<help><![CDATA[
The name of the host.]]></help>
</field>
<field>
<id>relayd.host.address</id>
<label>Address</label>
<type>text</type>
<help><![CDATA[
The backend host address.]]>
</help>
</field>
<field>
<id>relayd.host.ipTTL</id>
<label>IP TTL</label>
<type>text</type>
<help><![CDATA[
Change the default time-to-live value in the IP headers for host checks.]]>
</help>
<advanced>true</advanced>
</field>
<field>
<id>relayd.host.priority</id>
<label>Route Priority</label>
<type>text</type>
<help><![CDATA[
Change the route priority used when adding a route.]]>
</help>
<advanced>true</advanced>
</field>
<field>
<id>relayd.host.retry</id>
<label>Retry Number</label>
<type>text</type>
<help><![CDATA[
The optional retry option adds a tolerance for failed host checks;
the check will be retried for this number more times before setting the
host state to down.]]>
</help>
<advanced>true</advanced>
</field>
</form>

View file

@ -0,0 +1,25 @@
<form>
<field>
<id>relayd.protocol.name</id>
<label>Name</label>
<type>text</type>
<help><![CDATA[
The name of the protocol definition.]]></help>
</field>
<field>
<id>relayd.protocol.type</id>
<label>Type</label>
<type>dropdown</type>
<help><![CDATA[
The type of the protocol definition.]]>
</help>
</field>
<field>
<id>relayd.protocol.options</id>
<label>Options</label>
<type>textbox</type>
<help><![CDATA[
The protocol options.]]>
</help>
</field>
</form>

View file

@ -0,0 +1,25 @@
<form>
<field>
<id>relayd.table.name</id>
<label>Name</label>
<type>text</type>
<help><![CDATA[
The name of the table.]]></help>
</field>
<field>
<id>relayd.table.enabled</id>
<label>Enable</label>
<type>checkbox</type>
<help><![CDATA[
If unchecked start the table disabled.]]>
</help>
</field>
<field>
<id>relayd.table.hosts</id>
<label>Hosts</label>
<type>select_multiple</type>
<help><![CDATA[
This is a list with backend hosts]]>
</help>
</field>
</form>

View file

@ -0,0 +1,80 @@
<form>
<field>
<id>relayd.tablecheck.name</id>
<label>Name</label>
<type>text</type>
<help><![CDATA[
The name of the table check.]]>
</help>
</field>
<field>
<id>relayd.tablecheck.type</id>
<label>Type</label>
<type>dropdown</type>
<help><![CDATA[<ul>
<li>ICMP - Ping hosts in this table to determine whether they are up or not.</li>
<li>TCP - Use a simple TCP connect to check that hosts are up.</li>
<li>SSL - Perform a complete SSL handshake with each host to check their availability.</li>
<li>SEND - Create a TCP connection, send data and check the response.</li>
<li>SCRIPT - Execute an external program to check the host state.</li>
<li>HTTP(S) - Check response code or message digest from a http(s) request.</li>
</ul>]]>
</help>
</field>
<field>
<id>relayd.tablecheck.path</id>
<label>Path</label>
<type>text</type>
<help><![CDATA[
The URL path for HTTP(S) or the script path for SCRIPT checks.]]>
</help>
</field>
<field>
<id>relayd.tablecheck.host</id>
<label>Host</label>
<type>text</type>
<help><![CDATA[
The HTTP 'Host' header value.]]>
</help>
</field>
<field>
<id>relayd.tablecheck.code</id>
<label>Response Code</label>
<type>text</type>
<help><![CDATA[
The expected response code.]]>
</help>
</field>
<field>
<id>relayd.tablecheck.digest</id>
<label>Message Digest</label>
<type>text</type>
<help><![CDATA[
The expected response message digest.]]>
</help>
</field>
<field>
<id>relayd.tablecheck.data</id>
<label>Send Data</label>
<type>text</type>
<help><![CDATA[
Send data.]]>
</help>
</field>
<field>
<id>relayd.tablecheck.expect</id>
<label>Expect Pattern</label>
<type>text</type>
<help><![CDATA[
Match response against pattern.]]>
</help>
</field>
<field>
<id>relayd.tablecheck.ssl</id>
<label>SSL</label>
<type>checkbox</type>
<help><![CDATA[
Use SSL.]]>
</help>
</field>
</form>

View file

@ -0,0 +1,199 @@
<form>
<field>
<id>relayd.virtualserver.name</id>
<label>Name</label>
<type>text</type>
<help><![CDATA[
The name of the virtual server.]]></help>
</field>
<field>
<id>relayd.virtualserver.enabled</id>
<label>Enable</label>
<type>checkbox</type>
<help><![CDATA[
If unchecked start the virtual server disabled.]]>
</help>
</field>
<field>
<id>relayd.virtualserver.type</id>
<label>Server Type</label>
<type>dropdown</type>
<help><![CDATA[
<b>Redirections</b><br>
&nbsp;&nbsp;&nbsp;Redirections are translated to pf(4) rdr-to rules for stateful<br>
&nbsp;&nbsp;&nbsp;forwarding to a target host from a health-checked table on layer 3.<br><br>
<b>Relays</b><br>
&nbsp;&nbsp;&nbsp;Relays allow application layer load balancing, SSL acceleration,<br>
&nbsp;&nbsp;&nbsp;and general purpose TCP proxying on layer 7.]]>
</help>
</field>
<field>
<id>relayd.virtualserver.listen_address</id>
<label>Listen Address</label>
<type>text</type>
<help><![CDATA[
Specify an address to listen on.]]>
</help>
</field>
<field>
<id>relayd.virtualserver.listen_startport</id>
<label>Listen Port</label>
<type>text</type>
<help><![CDATA[
Specify the port to listen on.]]>
</help>
</field>
<field>
<id>relayd.virtualserver.listen_endport</id>
<label>Listen End Port</label>
<type>text</type>
<help><![CDATA[
Specify the end of a port range.]]>
</help>
<advanced>true</advanced>
</field>
<field>
<id>relayd.virtualserver.listen_interface</id>
<label>Interface</label>
<type>dropdown</type>
<help><![CDATA[
The Interface to listen on. Leave it unset to listen on all interfaces.]]>
</help>
<advanced>true</advanced>
</field>
<field>
<id>relayd.virtualserver.transport_type</id>
<label>Transport Type</label>
<type>dropdown</type>
<help><![CDATA[
<b>Forward</b> or <b>Route</b> packets to the backend hosts.]]>
</help>
<advanced>true</advanced>
</field>
<field>
<id>relayd.virtualserver.transport_table</id>
<label>Table</label>
<type>dropdown</type>
<help><![CDATA[
Specify the table of target hosts to be used.]]>
</help>
</field>
<field>
<id>relayd.virtualserver.transport_port</id>
<label>Port</label>
<type>text</type>
<help><![CDATA[
Specify the destination port.]]>
</help>
<advanced>true</advanced>
</field>
<field>
<id>relayd.virtualserver.transport_interval</id>
<label>Check Interval</label>
<type>text</type>
<help><![CDATA[
Override the global interval. I must be a multiple of the global interval.]]>
</help>
<advanced>true</advanced>
</field>
<field>
<id>relayd.virtualserver.transport_timeout</id>
<label>Check Timeout</label>
<type>text</type>
<help><![CDATA[
Override the global check timeout.]]>
</help>
<advanced>true</advanced>
</field>
<field>
<id>relayd.virtualserver.transport_tablemode</id>
<label>Scheduler</label>
<type>dropdown</type>
<help><![CDATA[
Set the scheduling algorithm to select a host from the table.]]>
</help>
</field>
<field>
<id>relayd.virtualserver.transport_tablecheck</id>
<label>Table Check</label>
<type>dropdown</type>
<help><![CDATA[
Specify the table check.]]>
</help>
</field>
<field>
<id>relayd.virtualserver.backuptransport_table</id>
<label>Backup Table</label>
<type>dropdown</type>
<help><![CDATA[
Specify the table of target hosts to be used.]]>
</help>
<advanced>true</advanced>
</field>
<field>
<id>relayd.virtualserver.backuptransport_interval</id>
<label>Backup Check Interval</label>
<type>text</type>
<help><![CDATA[
Override the global interval. I must be a multiple of the global interval.]]>
</help>
<advanced>true</advanced>
</field>
<field>
<id>relayd.virtualserver.backuptransport_timeout</id>
<label>Backup Check Timeout</label>
<type>text</type>
<help><![CDATA[
Override the global check timeout.]]>
</help>
<advanced>true</advanced>
</field>
<field>
<id>relayd.virtualserver.backuptransport_tablemode</id>
<label>Backup Table Scheduler</label>
<type>dropdown</type>
<help><![CDATA[
Set the scheduling algorithm to select a host from the table.]]>
</help>
<advanced>true</advanced>
</field>
<field>
<id>relayd.virtualserver.backuptransport_tablecheck</id>
<label>Backup Table Check</label>
<type>dropdown</type>
<help><![CDATA[
Specify the table check.]]>
</help>
<advanced>true</advanced>
</field>
<field>
<id>relayd.virtualserver.sessiontimeout</id>
<label>Session Timeout</label>
<type>text</type>
<help><![CDATA[
Specify the inactivity timeout in seconds for established<br>
redirections. The default timeout is 600 seconds (10 minutes).<br>
The maximum is 2147483647 seconds (68 years).]]>
</help>
<advanced>true</advanced>
</field>
<field>
<id>relayd.virtualserver.stickyaddress</id>
<label>Sticky Address</label>
<type>checkbox</type>
<help><![CDATA[
It will ensure that multiple connections<br>
from the same source are mapped to the same redirection address.]]>
</help>
<advanced>true</advanced>
</field>
<field>
<id>relayd.virtualserver.protocol</id>
<label>Protocol</label>
<type>dropdown</type>
<help><![CDATA[
Use the specified protocol definition for the relay.]]>
</help>
<advanced>true</advanced>
</field>
</form>

View file

@ -1,62 +1,11 @@
<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>
<page-services-relayd>
<name>Services: Relayd</name>
<description>Allow access to the 'Services: Relayd' page.</description>
<patterns>
<pattern>ui/relayd/*</pattern>
<pattern>api/relayd/*</pattern>
<pattern>diag_logs_relayd.php*</pattern>
</patterns>
</page-services-relayd>
</acl>

View file

@ -1,19 +1,9 @@
<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>
<Services>
<Relayd cssClass="fa fa-truck fa-fw">
<Settings url="/ui/relayd/"/>
<Status url="/ui/relayd/status/"/>
<Log VisibleName="Log File" order="100" url="/diag_logs_relayd.php"/>
</Relayd>
</Services>
</menu>

View file

@ -0,0 +1,241 @@
<?php
/*
* Copyright (C) 2018 EURO-LOG AG
* 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.
*/
namespace OPNsense\Relayd\Migrations;
use OPNsense\Base\BaseModelMigration;
use OPNsense\Core\Config;
class M1_0_0 extends BaseModelMigration
{
public function run($model)
{
$cfg = Config::getInstance();
$cfgObj = $cfg->object();
$hosts = array();
$tableChecks = array();
$tables = array();
$protocols = array();
$sticky = 0;
/* load_balancer setting */
if (!empty($cfgObj->load_balancer->setting->timeout)) {
$model->general->timeout = $cfgObj->load_balancer->setting->timeout;
}
if (!empty($cfgObj->load_balancer->setting->interval)) {
$model->general->interval = $cfgObj->load_balancer->setting->interval;
}
if (!empty($cfgObj->load_balancer->setting->prefork)) {
$model->general->prefork = $cfgObj->load_balancer->setting->prefork;
}
if (!empty($cfgObj->load_balancer->setting->lb_use_sticky)) {
$sticky = $cfgObj->load_balancer->setting->lb_use_sticky;
}
/* load_balancer monitor_type */
if (!empty($cfgObj->load_balancer->monitor_type) && count($cfgObj->load_balancer->monitor_type)) {
foreach ($cfgObj->load_balancer->monitor_type as $monitorType) {
if (!empty($monitorType->name)) {
$name = $monitorType->name->__toString();
switch ($monitorType->type) {
case 'http':
case 'https':
if (!empty($monitorType->options->path) &&
!empty($monitorType->options->code)) {
$setting = array(
'name' => $name,
'path' => $monitorType->options->path,
'code' => $monitorType->options->code,
'type' => 'http');
if ($monitorType->type == 'https') {
$setting['ssl'] = 1;
}
if (!empty($monitorType->options->host)) {
$setting['host'] = $monitorType->options->host;
}
if (!empty($setting)) {
$node = $model->tablecheck->Add();
$node->setNodes($setting);
$tableChecks[$name]['uuid'] = $node->getAttributes()['uuid'];
}
}
break;
case 'send':
if (!empty($monitorType->options->expect)) {
$setting = array(
'name' => $name,
'type' => 'send',
'expect' => $monitorType->options->expect);
}
if (!empty($monitorType->options->data)) {
$setting['data'] = $monitorType->options->data;
}
if (!empty($setting)) {
$node = $model->tablecheck->Add();
$node->setNodes($setting);
$tableChecks[$name]['uuid'] = $node->getAttributes()['uuid'];
}
break;
default:
$node = $model->tablecheck->Add();
$node->setNodes(array('name' => $name, 'type' => $monitorType->type));
$tableChecks[$name]['uuid'] = $node->getAttributes()['uuid'];
break;
}
}
}
}
/* load_balancer lbpool */
if (!empty($cfgObj->load_balancer->lbpool) && count($cfgObj->load_balancer->lbpool)) {
foreach ($cfgObj->load_balancer->lbpool as $lbpool) {
if (!empty($lbpool->name) &&
!empty($lbpool->servers &&
!empty($lbpool->monitor))) {
$name = $lbpool->name->__toString();
$tableSetting = array(
'enabled' => 1,
'name' => $lbpool->name,
'hosts' => ''
);
/* cannot import 'serversdisabled' */
foreach ($lbpool->servers as $server) {
$serverName = $server->__toString();
/* add new host */
if (empty($hosts) || !isset($hosts[$serverName])) {
$hostSetting = array(
'name' => $serverName,
'address' => $serverName);
if (!empty($lbpool->retry)) {
$hostSetting['retry'] = $lbpool->retry;
}
$hostNode = $model->host->Add();
$hostNode->setNodes($hostSetting);
$hosts[$serverName]['uuid'] = $hostNode->getAttributes()['uuid'];
}
$tableSetting['hosts'] .= $hosts[$serverName]['uuid'] . ',';
}
$tableSetting['hosts'] = rtrim($tableSetting['hosts'], ',');
$tableNode = $model->table->Add();
$tableNode->setNodes($tableSetting);
$tables[$name]['uuid'] = $tableNode->getAttributes()['uuid'];
if (!empty($lbpool->mode) && $lbpool->mode == 'loadbalance') {
$tables[$name]['mode'] = 'loadbalance';
}
$monitor = $lbpool->monitor->__toString();
$tables[$name]['monitor'] = $tableChecks[$monitor]['uuid'];
if (!empty($lbpool->port)) {
$tables[$name]['port'] = $lbpool->port;
}
}
}
}
/* protocol definitions */
$protocolDir = '/usr/local/etc/inc/plugins.inc.d/relayd';
if (is_dir($protocolDir)) {
$protocolFiles = glob($protocolDir . '/*.proto');
foreach ($protocolFiles as $protocolFile) {
$content = file_get_contents($protocolFile);
preg_match('/^([^\{]*)\{((.|\n|\r)*)\}((\s|\n|\r)*)$/', $content, $acontent);
if (preg_match('/^protocol\s+/', trim($acontent[1]))) {
preg_match('/^([^\s]*)\s+([^\s]*)/', trim($acontent[1]), $protocol);
} else {
preg_match('/^([^\s]*)\s+([^\s]*)\s+([^\s]*)/', trim($acontent[1]), $protocol);
}
$type = trim($protocol[1]);
if (count($protocol) == 3 && $type == 'protocol') {
$type = 'tcp';
$name = trim($protocol[2]);
} else {
$name = trim($protocol[3]);
}
$name = trim($name, '"');
$protocolSetting = array(
'name' => $name,
'type' => $type,
'options' => trim($acontent[2])
);
$protocolNode = $model->protocol->Add();
$protocolNode->setNodes($protocolSetting);
$protocols[$name]['uuid'] = $protocolNode->getAttributes()['uuid'];
}
}
/* load_balancer virtual_server */
if (!empty($cfgObj->load_balancer->virtual_server) && count($cfgObj->load_balancer->virtual_server)) {
foreach ($cfgObj->load_balancer->virtual_server as $virtual_server) {
if (!empty($virtual_server->name) &&
!empty($virtual_server->ipaddr) &&
!empty($virtual_server->port) &&
!empty($virtual_server->poolname)) {
$poolname = $virtual_server->poolname->__toString();
$vserverSetting = array(
'enabled' => 1,
'name' => $virtual_server->name,
'listen_address' => $virtual_server->ipaddr,
'listen_startport' => $virtual_server->port,
'transport_type' => 'forward',
'transport_table' => $tables[$poolname]['uuid'],
'transport_tablecheck' => $tables[$poolname]['monitor']
);
if (!empty($virtual_server->mode)) {
$vserverSetting['type'] = $virtual_server->mode;
if (!empty($sticky) && $vserverSetting['type'] == 'redirect') {
$vserverSetting['stickyaddress'] = 1;
}
}
if (!empty($tables[$poolname]['port'])) {
$vserverSetting['transport_port'] = $tables[$poolname]['port'];
}
if (!empty($tables[$poolname]['mode'])) {
$vserverSetting['transport_tablemode'] = $tables[$poolname]['mode'];
}
if (!empty($virtual_server->sitedown)) {
$sitedown = $virtual_server->sitedown->__toString();
$vserverSetting['backuptransport_table'] = $tables[$sitedown]['uuid'];
$vserverSetting['backuptransport_tablecheck'] = $vserverSetting['transport_tablecheck'];
if (!empty($vserverSetting['transport_tablemode'])) {
$vserverSetting['backuptransport_tablemode'] = $vserverSetting['transport_tablemode'];
}
}
if (!empty($virtual_server->sessiontimeout)) {
$vserverSetting['sessiontimeout'] = $virtual_server->sessiontimeout;
}
if (!empty($virtual_server->relay_protocol)) {
$relay_protocol = $virtual_server->relay_protocol->__toString();
$vserverSetting['protocol'] = $protocols[$relay_protocol]['uuid'];
}
$vserverNode = $model->virtualserver->Add();
$vserverNode->setNodes($vserverSetting);
}
}
}
}
}

View file

@ -0,0 +1,67 @@
<?php
/**
* Copyright (C) 2018 EURO-LOG AG
*
* 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.
*
*/
namespace OPNsense\Relayd;
use OPNsense\Base\BaseModel;
/**
* Class Relayd
* @package OPNsense\Relayd
*/
class Relayd extends BaseModel
{
/**
* get configuration state
* @return bool
*/
public function configChanged()
{
return file_exists("/tmp/relayd.dirty");
}
/**
* mark configuration as changed
* @return bool
*/
public function configDirty()
{
return @touch("/tmp/relayd.dirty");
}
/**
* mark configuration as consistent with the running config
* @return bool
*/
public function configClean()
{
return @unlink("/tmp/relayd.dirty");
}
}

View file

@ -0,0 +1,326 @@
<model>
<mount>//OPNsense/relayd</mount>
<version>1.0.0</version>
<description>Relayd settings</description>
<items>
<general>
<enabled type="BooleanField">
<default>0</default>
<Required>Y</Required>
</enabled>
<interval type="IntegerField">
<default>10</default>
<Required>N</Required>
<MinimumValue>1</MinimumValue>
<ValidationMessage>Check interval must be greater than 0</ValidationMessage>
</interval>
<log type="OptionField">
<Required>N</Required>
<OptionValues>
<updates>new states</updates>
<all>all states</all>
</OptionValues>
</log>
<prefork type="IntegerField">
<default>3</default>
<Required>N</Required>
<MinimumValue>1</MinimumValue>
<ValidationMessage>Number of processes must be greater than 0</ValidationMessage>
</prefork>
<timeout type="IntegerField">
<default>200</default>
<Required>N</Required>
<MinimumValue>1</MinimumValue>
<ValidationMessage>The timeout must be greater than 0</ValidationMessage>
</timeout>
</general>
<host type="ArrayField">
<name type="TextField">
<Required>Y</Required>
<mask>/^([0-9a-zA-Z\._\- ]){1,255}$/u</mask>
<ValidationMessage>Should be a string between 1 and 255 characters. Allowed characters are letters and numbers as well as underscore, minus, dot and space.</ValidationMessage>
</name>
<address type="TextField">
<Required>Y</Required>
<mask>/^([0-9a-zA-Z\.,_\-:]){0,1024}$/u</mask>
<ChangeCase>lower</ChangeCase>
<ValidationMessage>Please specify a valid servername or IP address.</ValidationMessage>
</address>
<ipTTL type="IntegerField">
<Required>N</Required>
<MinimumValue>1</MinimumValue>
<ValidationMessage>The IP TTL must be greater than 0</ValidationMessage>
</ipTTL>
<priority type="IntegerField">
<Required>N</Required>
<MinimumValue>1</MinimumValue>
<ValidationMessage>The route priority must be greater than 0</ValidationMessage>
</priority>
<retry type="IntegerField">
<Required>N</Required>
<MinimumValue>1</MinimumValue>
<ValidationMessage>The number of retries must be greater than 0</ValidationMessage>
</retry>
</host>
<table type="ArrayField">
<name type="TextField">
<Required>Y</Required>
<mask>/^([0-9a-zA-Z\._\- ]){1,255}$/u</mask>
<ValidationMessage>Should be a string between 1 and 255 characters. Allowed characters are letters and numbers as well as underscore, minus, dot and space.</ValidationMessage>
</name>
<enabled type="BooleanField">
<default>0</default>
<Required>Y</Required>
</enabled>
<hosts type="ModelRelationField">
<Model>
<template>
<source>OPNsense.relayd.relayd</source>
<items>host</items>
<display>name</display>
</template>
</Model>
<ValidationMessage>Host not found</ValidationMessage>
<multiple>Y</multiple>
<Required>Y</Required>
</hosts>
</table>
<tablecheck type="ArrayField">
<name type="TextField">
<Required>Y</Required>
<mask>/^([0-9a-zA-Z\._\- ]){1,255}$/u</mask>
<ValidationMessage>Should be a string between 1 and 255 characters. Allowed characters are letters and numbers as well as underscore, minus, dot and space.</ValidationMessage>
</name>
<type type="OptionField">
<default>icmp</default>
<Required>Y</Required>
<OptionValues>
<icmp>ICMP</icmp>
<tcp>TCP</tcp>
<ssl>SSL</ssl>
<send>SEND</send>
<script>SCRIPT</script>
<http>HTTP</http>
</OptionValues>
</type>
<path type="TextField">
<Required>N</Required>
</path>
<host type="TextField">
<mask>/^([0-9a-zA-Z\.,_\-:]){0,1024}$/u</mask>
<ChangeCase>lower</ChangeCase>
<ValidationMessage>Please specify a valid servername or IP address.</ValidationMessage>
<Required>N</Required>
</host>
<code type="IntegerField">
<Required>N</Required>
<ValidationMessage>Expected return code must be a number.</ValidationMessage>
</code>
<digest type="TextField">
<Required>N</Required>
</digest>
<data type="TextField">
<Required>N</Required>
</data>
<expect type="TextField">
<Required>N</Required>
</expect>
<ssl type="BooleanField">
<Required>N</Required>
</ssl>
</tablecheck>
<virtualserver type="ArrayField">
<name type="TextField">
<Required>Y</Required>
<mask>/^([0-9a-zA-Z\._\- ]){1,255}$/u</mask>
<ValidationMessage>Should be a string between 1 and 255 characters. Allowed characters are letters and numbers as well as underscore, minus, dot and space.</ValidationMessage>
</name>
<enabled type="BooleanField">
<default>0</default>
<Required>Y</Required>
</enabled>
<type type="OptionField">
<default>relay</default>
<Required>Y</Required>
<OptionValues>
<relay>Relay</relay>
<redirect>Redirection</redirect>
</OptionValues>
</type>
<listen_address type="TextField">
<Required>Y</Required>
<mask>/^([0-9a-zA-Z\.,_\-:]){0,1024}$/u</mask>
<ChangeCase>lower</ChangeCase>
<ValidationMessage>Please specify a valid servername or IP address.</ValidationMessage>
</listen_address>
<listen_startport type="PortField">
<Required>Y</Required>
<MinimumValue>1</MinimumValue>
<MaximumValue>65535</MaximumValue>
<ValidationMessage>A valid Port number must be specified.</ValidationMessage>
</listen_startport>
<listen_endport type="PortField">
<Required>N</Required>
<MinimumValue>1</MinimumValue>
<MaximumValue>65535</MaximumValue>
<ValidationMessage>A valid Port number must be specified.</ValidationMessage>
</listen_endport>
<listen_interface type="InterfaceField">
<Required>N</Required>
<multiple>N</multiple>
<filters>
<enable>/^(?!0).*$/</enable>
<ipaddr>/^((?!dhcp).)*$/</ipaddr>
</filters>
</listen_interface>
<transport_type type="OptionField">
<default>forward</default>
<Required>Y</Required>
<OptionValues>
<forward>Forward</forward>
<route>Route</route>
</OptionValues>
</transport_type>
<transport_table type="ModelRelationField">
<Model>
<template>
<source>OPNsense.relayd.relayd</source>
<items>table</items>
<display>name</display>
</template>
</Model>
<ValidationMessage>Table not found</ValidationMessage>
<multiple>N</multiple>
<Required>Y</Required>
</transport_table>
<transport_port type="PortField">
<Required>N</Required>
<MinimumValue>1</MinimumValue>
<MaximumValue>65535</MaximumValue>
<ValidationMessage>A valid Port number must be specified.</ValidationMessage>
</transport_port>
<transport_interval type="IntegerField">
<Required>N</Required>
<MinimumValue>2</MinimumValue>
<ValidationMessage>Check interval must be a multiple of the global interval.</ValidationMessage>
</transport_interval>
<transport_timeout type="IntegerField">
<Required>N</Required>
<MinimumValue>1</MinimumValue>
<ValidationMessage>The timeout must be greater than 0</ValidationMessage>
</transport_timeout>
<transport_tablemode type="OptionField">
<default>roundrobin</default>
<Required>N</Required>
<OptionValues>
<hash>Hash</hash>
<least-states>Least States</least-states>
<loadbalance>Load Balance</loadbalance>
<random>Random</random>
<roundrobin>Round Robin</roundrobin>
<source-hash>Source Hash</source-hash>
</OptionValues>
</transport_tablemode>
<transport_tablecheck type="ModelRelationField">
<Model>
<template>
<source>OPNsense.relayd.relayd</source>
<items>tablecheck</items>
<display>name</display>
</template>
</Model>
<ValidationMessage>Table check not found</ValidationMessage>
<multiple>N</multiple>
<Required>Y</Required>
</transport_tablecheck>
<backuptransport_table type="ModelRelationField">
<Model>
<template>
<source>OPNsense.relayd.relayd</source>
<items>table</items>
<display>name</display>
</template>
</Model>
<ValidationMessage>Table not found</ValidationMessage>
<multiple>N</multiple>
<Required>N</Required>
</backuptransport_table>
<backuptransport_interval type="IntegerField">
<Required>N</Required>
<MinimumValue>2</MinimumValue>
<ValidationMessage>Check interval must be a multiple of the global interval.</ValidationMessage>
</backuptransport_interval>
<backuptransport_timeout type="IntegerField">
<Required>N</Required>
<MinimumValue>1</MinimumValue>
<ValidationMessage>The timeout must be greater than 0</ValidationMessage>
</backuptransport_timeout>
<backuptransport_tablecheck type="ModelRelationField">
<Model>
<template>
<source>OPNsense.relayd.relayd</source>
<items>tablecheck</items>
<display>name</display>
</template>
</Model>
<ValidationMessage>Table check not found</ValidationMessage>
<multiple>N</multiple>
<Required>N</Required>
</backuptransport_tablecheck>
<backuptransport_tablemode type="OptionField">
<default>roundrobin</default>
<Required>N</Required>
<OptionValues>
<hash>Hash</hash>
<least-states>Least States</least-states>
<loadbalance>Load Balance</loadbalance>
<random>Random</random>
<roundrobin>Round Robin</roundrobin>
<source-hash>Source Hash</source-hash>
</OptionValues>
</backuptransport_tablemode>
<sessiontimeout type="IntegerField">
<default>600</default>
<Required>N</Required>
<MinimumValue>1</MinimumValue>
<MaximumValue>2147483647</MaximumValue>
<ValidationMessage>The timeout must be a number between 1 and 2147483647.</ValidationMessage>
</sessiontimeout>
<stickyaddress type="BooleanField">
<default>0</default>
<Required>N</Required>
</stickyaddress>
<protocol type="ModelRelationField">
<Model>
<template>
<source>OPNsense.relayd.relayd</source>
<items>protocol</items>
<display>name</display>
</template>
</Model>
<ValidationMessage>Protocol not found</ValidationMessage>
<multiple>N</multiple>
<Required>N</Required>
</protocol>-->
</virtualserver>
<protocol type="ArrayField">
<name type="TextField">
<Required>Y</Required>
<mask>/^([0-9a-zA-Z\._\- ]){1,255}$/u</mask>
<ValidationMessage>Should be a string between 1 and 255 characters. Allowed characters are letters and numbers as well as underscore, minus, dot and space.</ValidationMessage>
</name>
<type type="OptionField">
<default>tcp</default>
<Required>Y</Required>
<OptionValues>
<tcp>TCP</tcp>
<dns>DNS</dns>
<http>HTTP</http>
</OptionValues>
</type>
<options type="TextField">
<Required>N</Required>
</options>
</protocol>
</items>
</model>

View file

@ -0,0 +1,359 @@
{#
Copyright © 2018 by EURO-LOG AG
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.
#}
<script>
$( document ).ready(function() {
/**
* get the isSubsystemDirty value and print a notice
*/
function isSubsystemDirty() {
ajaxGet(url="/api/relayd/settings/dirty", sendData={}, callback=function(data,status) {
if (status == "success") {
if (data.relayd.dirty === true) {
$("#configChangedMsg").removeClass("hidden");
} else {
$("#configChangedMsg").addClass("hidden");
}
}
});
}
/**
* chain std_bootgrid_reload from opnsense_bootgrid_plugin.js
* to get the isSubsystemDirty state on "UIBootgrid" changes
*/
var opn_std_bootgrid_reload = std_bootgrid_reload;
std_bootgrid_reload = function(gridId) {
opn_std_bootgrid_reload(gridId);
isSubsystemDirty();
};
/**
* apply changes and reload relayd
*/
$('#btnApplyConfig').unbind('click').click(function(){
$('#btnApplyConfigProgress').addClass("fa fa-spinner fa-pulse");
ajaxCall(url="/api/relayd/service/reconfigure", sendData={}, callback=function(data,status) {
$("#responseMsg").addClass("hidden");
isSubsystemDirty();
updateServiceControlUI('relayd');
if (data.result) {
$("#responseMsg").html(data['result']);
$("#responseMsg").removeClass("hidden");
}
$('#btnApplyConfigProgress').removeClass("fa fa-spinner fa-pulse");
$('#btnApplyConfig').blur();
});
});
/**
* general settings
*/
mapDataToFormUI({'frm_GeneralSettings':"/api/relayd/settings/get/general/"}).done(function() {
$("#responseMsg").addClass("hidden");
formatTokenizersUI();
$('#relayd\\.general\\.log').selectpicker('refresh');
updateServiceControlUI('relayd');
isSubsystemDirty();
});
$('#btnSaveGeneral').unbind('click').click(function() {
$("#btnSaveGeneralProgress").addClass("fa fa-spinner fa-pulse");
var frm_id = 'frm_GeneralSettings';
saveFormToEndpoint(url = "/api/relayd/settings/set/general/",formid=frm_id,callback_ok=function() {
$("#responseMsg").addClass("hidden");
updateServiceControlUI('relayd');
isSubsystemDirty();
$("#btnSaveGeneralProgress").removeClass("fa fa-spinner fa-pulse");
$("#btnSaveGeneral").blur();
});
});
['host', 'tablecheck', 'table', 'protocol', 'virtualserver'].forEach(function(element) {
$("#grid-" + element).UIBootgrid({
'search': '/api/relayd/settings/search/' + element + '/',
'get': '/api/relayd/settings/get/' + element + '/',
'set': '/api/relayd/settings/set/' + element + '/',
'add': '/api/relayd/settings/set/' + element + '/',
'del': '/api/relayd/settings/del/' + element + '/'
});
});
// show/hide options depending on other options
function ShowHideVSFields(){
var servertype = $('#relayd\\.virtualserver\\.type').val();
var backuptransport_table = $('#relayd\\.virtualserver\\.backuptransport_table').val();
$('tr[id="row_relayd.virtualserver.transport_type"]').addClass('hidden');
$('tr[id="row_relayd.virtualserver.stickyaddress"]').addClass('hidden');
$('tr[id="row_relayd.virtualserver.protocol"]').addClass('hidden');
$('tr[id="row_relayd.virtualserver.backuptransport_tablemode"]').addClass('hidden');
$('tr[id="row_relayd.virtualserver.backuptransport_timeout"]').addClass('hidden');
$('tr[id="row_relayd.virtualserver.backuptransport_interval"]').addClass('hidden');
$('tr[id="row_relayd.virtualserver.backuptransport_tablecheck"]').addClass('hidden');
$('#relayd\\.virtualserver\\.transport_tablemode').empty().append('<option value="roundrobin">Round Robin </option>');
$('#relayd\\.virtualserver\\.backuptransport_tablemode').empty().append('<option value="roundrobin">Round Robin </option>');
if(servertype == 'redirect'){
$('tr[id="row_relayd.virtualserver.transport_type"]').removeClass('hidden');
$('tr[id="row_relayd.virtualserver.stickyaddress"]').removeClass('hidden');
$('#relayd\\.virtualserver\\.transport_tablemode').append('<option value="least-states">Least States </option>');
$('#relayd\\.virtualserver\\.backuptransport_tablemode').append('<option value="least-states">Least States </option>');
$('#relayd\\.virtualserver\\.transport_tablemode').val('roundrobin');
$('#relayd\\.virtualserver\\.backuptransport_tablemode').val('roundrobin');
} else {
$('tr[id="row_relayd.virtualserver.protocol"]').removeClass('hidden');
$('#relayd\\.virtualserver\\.transport_tablemode').append('<option value="hash">Hash </option>');
$('#relayd\\.virtualserver\\.backuptransport_tablemode').append('<option value="hash">Hash </option>');
$('#relayd\\.virtualserver\\.transport_tablemode').append('<option value="loadbalance">Load Balance </option>');
$('#relayd\\.virtualserver\\.backuptransport_tablemode').append('<option value="loadbalance">Load Balance </option>');
$('#relayd\\.virtualserver\\.transport_tablemode').append('<option value="random">Random </option>');
$('#relayd\\.virtualserver\\.backuptransport_tablemode').append('<option value="random">Random </option>');
$('#relayd\\.virtualserver\\.transport_tablemode').append('<option value="source-hash">Source Hash </option>');
$('#relayd\\.virtualserver\\.backuptransport_tablemode').append('<option value="source-hash">Source Hash </option>');
$('#relayd\\.virtualserver\\.transport_tablemode').val('roundrobin');
$('#relayd\\.virtualserver\\.backuptransport_tablemode').val('roundrobin');
}
$('#relayd\\.virtualserver\\.transport_tablemode').selectpicker('refresh');
$('#relayd\\.virtualserver\\.backuptransport_tablemode').selectpicker('refresh');
if(backuptransport_table !== '') {
$('tr[id="row_relayd.virtualserver.backuptransport_tablemode"]').removeClass('hidden');
$('tr[id="row_relayd.virtualserver.backuptransport_tablecheck"]').removeClass('hidden');
$('tr[id="row_relayd.virtualserver.backuptransport_timeout"]').removeClass('hidden');
$('tr[id="row_relayd.virtualserver.backuptransport_interval"]').removeClass('hidden');
}
};
$('#DialogEditVirtualServer').on('shown.bs.modal', function() {ShowHideVSFields();});
$('#relayd\\.virtualserver\\.type').on('changed.bs.select', function(e) {ShowHideVSFields();});
$('#relayd\\.virtualserver\\.backuptransport_table').on('changed.bs.select', function(e) {ShowHideVSFields();});
function ShowHideTCFields(){
var tablechecktype = $('#relayd\\.tablecheck\\.type').val();
$('tr[id="row_relayd.tablecheck.path"]').addClass('hidden');
$('tr[id="row_relayd.tablecheck.host"]').addClass('hidden');
$('tr[id="row_relayd.tablecheck.code"]').addClass('hidden');
$('tr[id="row_relayd.tablecheck.digest"]').addClass('hidden');
$('tr[id="row_relayd.tablecheck.data"]').addClass('hidden');
$('tr[id="row_relayd.tablecheck.expect"]').addClass('hidden');
$('tr[id="row_relayd.tablecheck.ssl"]').addClass('hidden');
switch (tablechecktype) {
case 'send':
$('tr[id="row_relayd.tablecheck.data"]').removeClass('hidden');
$('tr[id="row_relayd.tablecheck.expect"]').removeClass('hidden');
$('tr[id="row_relayd.tablecheck.ssl"]').removeClass('hidden');
break;
case 'script':
$('tr[id="row_relayd.tablecheck.path"]').removeClass('hidden');
break;
case 'http':
var code = $('#relayd\\.tablecheck\\.code').val();
var digest = $('#relayd\\.tablecheck\\.digest').val();
$('tr[id="row_relayd.tablecheck.path"]').removeClass('hidden');
$('tr[id="row_relayd.tablecheck.host"]').removeClass('hidden');
if (code !== '') {
$('tr[id="row_relayd.tablecheck.code"]').removeClass('hidden');
$('tr[id="row_relayd.tablecheck.digest"]').addClass('hidden');
} else if (digest !== '') {
$('tr[id="row_relayd.tablecheck.code"]').addClass('hidden');
$('tr[id="row_relayd.tablecheck.digest"]').removeClass('hidden');
} else {
$('tr[id="row_relayd.tablecheck.code"]').removeClass('hidden');
$('tr[id="row_relayd.tablecheck.digest"]').removeClass('hidden');
}
$('tr[id="row_relayd.tablecheck.ssl"]').removeClass('hidden');
break;
}
};
$('#DialogEditTableCheck').on('shown.bs.modal', function() {ShowHideTCFields();});
$('#relayd\\.tablecheck\\.type').on('changed.bs.select', function(e) {ShowHideTCFields();});
$('#relayd\\.tablecheck\\.code').on('input', function() {ShowHideTCFields();});
$('#relayd\\.tablecheck\\.digest').on('input', function() {ShowHideTCFields();});
});
</script>
<div class="alert alert-info hidden" role="alert" id="configChangedMsg">
<button class="btn btn-primary pull-right" id="btnApplyConfig" type="button"><b>{{ lang._('Apply changes') }}</b> <i id="btnApplyConfigProgress"></i></button>
{{ lang._('The Relayd configuration has been changed') }} <br /> {{ lang._('You must apply the changes in order for them to take effect.')}}
</div>
<div class="alert alert-info hidden" role="alert" id="responseMsg"></div>
<ul class="nav nav-tabs" role="tablist" id="maintabs">
<li class="active"><a data-toggle="tab" href="#general">{{ lang._('General Settings') }}</a></li>
<li><a data-toggle="tab" href="#host">{{ lang._('Backend Hosts') }}</a></li>
<li><a data-toggle="tab" href="#tablecheck">{{ lang._('Table Checks') }}</a></li>
<li><a data-toggle="tab" href="#table">{{ lang._('Tables') }}</a></li>
<li><a data-toggle="tab" href="#protocol">{{ lang._('Protocols') }}</a></li>
<li><a data-toggle="tab" href="#virtualserver">{{ lang._('Virtual Server') }}</a></li>
</ul>
<div class="tab-content content-box tab-content">
<div id="general" class="tab-pane fade in active">
{{ partial("layout_partials/base_form",['fields':formGeneralSettings,'id':'frm_GeneralSettings'])}}
<div class="table-responsive">
<table class="table table-striped table-condensed table-responsive">
<tr>
<td>
<button class="btn btn-primary" id="btnSaveGeneral" type="button"><b>{{ lang._('Save changes') }}</b> <i id="btnSaveGeneralProgress"></i></button>
</td>
</tr>
</table>
</div>
</div>
<div id="host" class="tab-pane fade in">
<table id="grid-host" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="DialogEditHost">
<thead>
<tr>
<th data-column-id="name" data-type="string">{{ lang._('Name') }}</th>
<th data-column-id="address" data-type="string">{{ lang._('Address') }}</th>
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
<th data-column-id="commands" data-width="7em" data-formatter="commands" data-sortable="false">{{ lang._('Edit') }} | {{ lang._('Delete') }}</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td></td>
<td>
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
<button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button>
</td>
</tr>
</tfoot>
</table>
</div>
<div id="tablecheck" class="tab-pane fade in">
<table id="grid-tablecheck" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="DialogEditTableCheck">
<thead>
<tr>
<th data-column-id="name" data-type="string">{{ lang._('Name') }}</th>
<th data-column-id="type" data-type="string">{{ lang._('Type') }}</th>
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
<th data-column-id="commands" data-width="7em" data-formatter="commands" data-sortable="false">{{ lang._('Edit') }} | {{ lang._('Delete') }}</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td></td>
<td>
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
<button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button>
</td>
</tr>
</tfoot>
</table>
</div>
<div id="table" class="tab-pane fade in">
<table id="grid-table" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="DialogEditTable">
<thead>
<tr>
<th data-column-id="enabled" data-width="6em" data-type="string" data-formatter="boolean">{{ lang._('Enabled') }}</th>
<th data-column-id="name" data-type="string">{{ lang._('Name') }}</th>
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
<th data-column-id="commands" data-width="7em" data-formatter="commands" data-sortable="false">{{ lang._('Edit') }} | {{ lang._('Delete') }}</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td></td>
<td>
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
<button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button>
</td>
</tr>
</tfoot>
</table>
</div>
<div id="protocol" class="tab-pane fade in">
<table id="grid-protocol" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="DialogEditProtocol">
<thead>
<tr>
<th data-column-id="name" data-type="string">{{ lang._('Name') }}</th>
<th data-column-id="type" data-type="string">{{ lang._('Type') }}</th>
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
<th data-column-id="commands" data-width="7em" data-formatter="commands" data-sortable="false">{{ lang._('Edit') }} | {{ lang._('Delete') }}</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td></td>
<td>
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
<button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button>
</td>
</tr>
</tfoot>
</table>
</div>
<div id="virtualserver" class="tab-pane fade in">
<table id="grid-virtualserver" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="DialogEditVirtualServer">
<thead>
<tr>
<th data-column-id="enabled" data-width="6em" data-type="string" data-formatter="boolean">{{ lang._('Enabled') }}</th>
<th data-column-id="name" data-type="string">{{ lang._('Name') }}</th>
<th data-column-id="type" data-type="string">{{ lang._('Type') }}</th>
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
<th data-column-id="commands" data-width="7em" data-formatter="commands" data-sortable="false">{{ lang._('Edit') }} | {{ lang._('Delete') }}</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td></td>
<td>
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
<button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button>
</td>
</tr>
</tfoot>
</table>
</div>
<!-- <div class="col-md-12">
<hr/>
<button class="btn btn-primary" id="btnApplyConfig" type="button"><b>{{ lang._('Apply Configuration') }}</b> <i id="btnApplyConfigProgress"></i></button>
<br/>
<br/>
</div>
-->
</div>
{# include dialogs #}
{{ partial("layout_partials/base_dialog",['fields':formDialogEditHost, 'id':'DialogEditHost', 'label':'Edit Host'])}}
{{ partial("layout_partials/base_dialog",['fields':formDialogEditTableCheck, 'id':'DialogEditTableCheck', 'label':'Edit Table Check'])}}
{{ partial("layout_partials/base_dialog",['fields':formDialogEditTable, 'id':'DialogEditTable', 'label':'Edit Table'])}}
{{ partial("layout_partials/base_dialog",['fields':formDialogEditProtocol, 'id':'DialogEditProtocol', 'label':'Edit Protocol'])}}
{{ partial("layout_partials/base_dialog",['fields':formDialogEditVirtualServer,'id':'DialogEditVirtualServer', 'label':'Edit Virtual Server'])}}

View file

@ -0,0 +1,154 @@
{#
Copyright © 2018 by EURO-LOG AG
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.
#}
<script type="text/javascript">
$( document ).ready(function() {
updateServiceControlUI('relayd');
// get status and build the table body
$('#btnRefresh').unbind('click').click(function() {
ajaxCall(url = "/api/relayd/status/sum", sendData={}, callback = function(result, status) {
if (status == "success" && result.result === 'ok') {
$('#tableStatus > tbody').empty();
$('#tableStatus > tbody').attr('style', 'display:none;');
/* create a table row for each host and combine
virtualserver/table fields afterwards via rowspan */
$.each(result.rows, function (vkey, virtualserver) {
var vrowspan = 0;
var trowspan = [];
var html = '<tr class="vrow"><td id="virtualServer' + vkey + '">';
html += getControlButtons(virtualserver.status, virtualserver.id, virtualserver.type);
html += virtualserver.name + ' (' + virtualserver.type + '): ' + virtualserver.status + '</td>';
var tfirst = true;
$.each(virtualserver.tables, function(tkey, table) {
trowspan[tkey] = 0;
if (tfirst == true) {
tfirst = false;
} else {
html += '<tr>';
}
html += '<td id="table' + tkey + '">';
html += getControlButtons(table.status, tkey, 'table');
html += table.name + ' ' + table.status + '</td>';
var hfirst = true;
$.each(table.hosts, function(hkey, host) {
if (hfirst == true) {
hfirst = false;
} else {
html += '<tr>';
}
vrowspan++;
trowspan[tkey]++;
html += '<td>';
html += getControlButtons(host.status, hkey, 'host');
html += host.name + ' ' + host.status + '</td></tr>';
});
// dummy host for disabled tables
if (hfirst == true) {
vrowspan++;
html += '<td></td>';
}
});
$('#tableStatus > tbody').append(html);
$('#virtualServer' + vkey).attr('rowspan', vrowspan);
$.each(trowspan, function(tid, trowspan) {
$('#table' + tid).attr('rowspan', trowspan);
});
$('#tableStatus > tbody > tr.vrow > td').css('border-top', '2px solid #ddd');
$('#tableStatus > tbody').fadeIn();
});
} else {
$("#tableStatus").html("<tr><td><br/>{{ lang._('The status could not be fetched. Is Relayd running?') }}</td></tr>");
}
$('#btnRefresh').blur();
});
});
// initial load
$("#btnRefresh").click();
});
// create status and start/stop buttons
function getControlButtons(status, id, nodeType) {
var statusClass = "btn btn-xs glyphicon ";
var controlClass = "btn btn-xs btn-default glyphicon ";
var action;
if (status.substring(0, 6) === 'active' || status === 'up') {
statusClass += "btn-success glyphicon-play";
controlClass += "glyphicon-stop";
controlTitle = "Stop this " + nodeType;
action = 'onclick="toggleNode(\'' + nodeType + '\', ' + id + ', \'disable\')""';
} else if (status === 'disabled') {
statusClass += "btn-danger glyphicon-stop";
controlClass += "glyphicon-play";
controlTitle = "Start this " + nodeType;
action = 'onclick="toggleNode(\'' + nodeType + '\', ' + id + ', \'enable\')"';
} else {
statusClass += "btn-danger glyphicon-stop";
controlClass += "glyphicon-play";
action = 'disabled="disabled"';
}
// no action for relays; see relayctl(8)
if (nodeType === 'relay') {
action = 'disabled="disabled"';
}
var html = '<span class="' + statusClass + '" style="cursor: default;"> </span>&nbsp;';
html += '<span ' + action + ' class="' + controlClass + '" title="' + controlTitle + '"> </span>&nbsp;';
return html;
};
// enable/disable redirects, tables or hosts
function toggleNode(nodeType, id, action) {
ajaxCall(url = "/api/relayd/status/toggle/" + nodeType + "/" + id + "/" + action, callback = function(result, status) {
$("#btnRefresh").click();
});
};
</script>
<div class="content-box">
<table id="tableStatus" class="table table-condensed">
<thead><tr><th>{{ lang._('Virtual Server') }}</th><th>{{ lang._('Table') }}</th><th>{{ lang._('Host') }}</th></tr></thead>
<tbody style="display:none;"></tbody>
</table>
<div class="col-sm-12">
<div class="row">
<table class="table">
<tr>
<td>
<div class="pull-right">
<button class="btn btn-primary" id="btnRefresh" type="button"><b>{{ lang._('Refresh') }}</b> <span id="btnRefreshProgress" class="fa fa-refresh"> </span></button>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>

View file

@ -0,0 +1,469 @@
<?php
/*
* Copyright (C) 2018 EURO-LOG AG
* 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.
*/
namespace tests\OPNsense\Relayd\Api;
use \OPNsense\Core\Config;
class RelaydTest extends \PHPUnit\Framework\TestCase
{
/**
* list with model node types
*/
private $nodeTypes = array('host', 'tablecheck', 'table', 'protocol', 'virtualserver');
// holds the SettingsController object
protected static $setRelayd;
public static function setUpBeforeClass()
{
self::$setRelayd = new \OPNsense\Relayd\Api\SettingsController;
}
private function cleanupNodes($nodeType = null)
{
$nodes = self::$setRelayd->mdlRelayd->$nodeType->getNodes();
foreach ($nodes as $nodeUuid => $node) {
self::$setRelayd->mdlRelayd->$nodeType->del($nodeUuid);
}
}
/**
* test getAction
*/
public function testGet()
{
$this->assertInstanceOf('\OPNsense\Relayd\Api\SettingsController', self::$setRelayd);
$this->expectException(\Exception::class);
$response = self::$setRelayd->getAction('wrong_node_type');
$testConfig = [];
$response = self::$setRelayd->getAction('general');
$testConfig['general'] = $response['relayd']['general'];
$this->assertEquals($response['status'], 'ok');
$this->assertArrayHasKey('enabled', $response['relayd']['general']);
return $testConfig;
}
/**
* test searchAction
* @depends testGet
*/
public function testSearch($testConfig)
{
$_SERVER['REQUEST_METHOD'] = 'POST';
$_POST = array('current' => '1', 'rowCount' => '7');
foreach ($this->nodeTypes as $nodeType) {
$response = self::$setRelayd->searchAction($nodeType);
$this->assertArrayHasKey('total', $response);
$testConfig[$nodeType] = $response['rows'];
}
return $testConfig;
}
/**
* test delAction
* not really a test if the config is empty, but we will delete something later
* @depends testSearch
*/
public function testReset($testConfig)
{
$_SERVER['REQUEST_METHOD'] = 'POST';
foreach (array_reverse($this->nodeTypes) as $nodeType) {
foreach ($testConfig[$nodeType] as $node) {
$response = self::$setRelayd->delAction($nodeType, $node['uuid']);
$this->assertEquals($response['status'], 'ok');
}
}
// need an assertion here to succeed this test on empty config
$this->assertTrue(true);
}
/**
* test setAction general
* @depends testReset
*/
public function testSetGeneral()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
// interval too small
$_POST = array('relayd' => ['general' => ['interval' => '0']]);
$response = self::$setRelayd->setAction('general');
$this->assertCount(1, $response['validations']);
$this->assertEquals($response['result'], 'failed');
$this->assertNotEmpty($response['validations']['relayd.general.interval']);
// set correct interval and incorrect timeout (s. testServiceController)
$_POST = array('relayd' => ['general' => ['interval' => '10', 'timeout' => 86400, 'enabled' => '0']]);
$response = self::$setRelayd->setAction('general');
$this->assertEquals($response['status'], 'ok');
}
/**
* test dirtyAction
* @depends testSetGeneral
*/
public function testDirtyAction()
{
$this->assertInstanceOf('\OPNsense\Relayd\Api\SettingsController', self::$setRelayd);
$response = self::$setRelayd->dirtyAction();
$this->assertEquals($response['status'], 'ok');
$this->assertEquals($response['relayd']['dirty'], true);
}
/**
* test setAction for hosts
* @depends testReset
*/
public function testSetHost()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
// empty host name
$_POST = array('relayd' => ['host' => ['address' => '127.0.0.1']]);
$response = self::$setRelayd->setAction('host');
$this->assertCount(1, $response['validations']);
$this->assertEquals($response['result'], 'failed');
$this->assertNotEmpty($response['validations']['relayd.host.name']);
$this->cleanupNodes('host');
// check mask
$_POST = array('relayd' => ['host' => ['name' => 'test$Host', 'address' => '127.0.0.$']]);
$response = self::$setRelayd->setAction('host');
$this->assertCount(2, $response['validations']);
$this->assertEquals($response['result'], 'failed');
$this->assertNotEmpty($response['validations']['relayd.host.name']);
$this->assertNotEmpty($response['validations']['relayd.host.address']);
$this->cleanupNodes('host');
// create host for ServiceControllerTest
$_POST = array('relayd' => ['host' => ['name' => 'testHost', 'address' => '127.0.0.1']]);
$response = self::$setRelayd->setAction('host');
$this->assertEquals($response['status'], 'ok');
}
/**
* test setAction for tables
* @depends testSetHost
*/
public function testSetTable()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
// check mask and missing host
$_POST = array('relayd' => ['table' => ['name' => 'test$Table', 'hosts' => 'aaa-111-bbb-222']]);
$response = self::$setRelayd->setAction('table');
$this->assertCount(2, $response['validations']);
$this->assertEquals($response['result'], 'failed');
$this->assertNotEmpty($response['validations']['relayd.table.name']);
$this->assertNotEmpty($response['validations']['relayd.table.hosts']);
$this->cleanupNodes('table');
// create table for ServiceControllerTest
$_POST = array('current' => '1', 'rowCount' => '7', 'searchPhrase' => 'testHost');
$response = self::$setRelayd->searchAction('host');
$this->assertArrayHasKey('total', $response);
$_POST = array('relayd' => [
'table' => ['name' => 'testTable', 'enabled' => 1, 'hosts' => $response['rows'][0]['uuid']]
]);
$response = self::$setRelayd->setAction('table');
}
/**
* test setAction for tablechecks
* @depends testSearch
* @depends testReset
*/
public function testSetTableCheck()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
// wrong option
$_POST = array('relayd' => ['tablecheck' => ['name' => 'test$Check', 'type' => 'ABCXYZ']]);
$response = self::$setRelayd->setAction('tablecheck');
$this->assertCount(2, $response['validations']);
$this->assertEquals($response['result'], 'failed');
$this->assertNotEmpty($response['validations']['relayd.tablecheck.name']);
$this->assertNotEmpty($response['validations']['relayd.tablecheck.type']);
$this->cleanupNodes('tablecheck');
// type 'send' without 'expect'
$_POST = array('relayd' => ['tablecheck' => ['name' => 'testSend', 'type' => 'send']]);
$response = self::$setRelayd->setAction('tablecheck');
$this->assertCount(1, $response['validations']);
$this->assertEquals($response['result'], 'failed');
$this->assertNotEmpty($response['validations']['relayd.tablecheck.expect']);
$this->cleanupNodes('tablecheck');
// type 'script' without 'path'
$_POST = array('relayd' => ['tablecheck' => ['name' => 'testScript', 'type' => 'script']]);
$response = self::$setRelayd->setAction('tablecheck');
$this->assertCount(1, $response['validations']);
$this->assertEquals($response['result'], 'failed');
$this->assertNotEmpty($response['validations']['relayd.tablecheck.path']);
$this->cleanupNodes('tablecheck');
// type 'http' without 'code' and 'digest'
$_POST = array('relayd' => [
'tablecheck' => ['name' => 'testTableCheck', 'type' => 'http', 'path' => 'http://www.example.com']
]);
$response = self::$setRelayd->setAction('tablecheck');
$this->assertCount(2, $response['validations']);
$this->assertEquals($response['result'], 'failed');
$this->assertNotEmpty($response['validations']['relayd.tablecheck.code']);
$this->assertNotEmpty($response['validations']['relayd.tablecheck.digest']);
$this->cleanupNodes('tablecheck');
// create tablecheck for ServiceControllerTest
$_POST = array('relayd' => [
'tablecheck' => [
'name' => 'testTableCheck',
'type' => 'http',
'path' => '/',
'host' => 'localhost',
'code' => '403',
'ssl' => '1']]);
$response = self::$setRelayd->setAction('tablecheck');
$this->assertEquals($response['status'], 'ok');
}
/**
* test setAction for protocols
* @depends testSearch
* @depends testReset
*/
public function testSetProtocol()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
// missing 'name' wrong 'type'
$_POST = array('relayd' => ['protocol' => ['name' => 'test$Protocol', 'type' => 'ABCXYZ']]);
$response = self::$setRelayd->setAction('protocol');
$this->assertCount(2, $response['validations']);
$this->assertEquals($response['result'], 'failed');
$this->assertNotEmpty($response['validations']['relayd.protocol.name']);
$this->assertNotEmpty($response['validations']['relayd.protocol.type']);
$this->cleanupNodes('protocol');
// create protocol for ServiceControllerTest
$_POST = array('relayd' => [
'protocol' => ['name' => 'testProtocol', 'type' => 'tcp', 'options' => 'nodelay, socket buffer 65536']
]);
$response = self::$setRelayd->setAction('protocol');
$this->assertEquals($response['status'], 'ok');
}
/**
* test setAction for virtualservers
* @depends testSearch
* @depends testReset
*/
public function testSetVirtualServer()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
// search table and tablecheck
$_POST = array('current' => '1', 'rowCount' => '7', 'searchPhrase' => 'testTable');
$response = self::$setRelayd->searchAction('table');
$this->assertArrayHasKey('total', $response);
$tableUuid = $response['rows'][0]['uuid'];
$_POST = array('current' => '1', 'rowCount' => '7', 'searchPhrase' => 'testTableCheck');
$response = self::$setRelayd->searchAction('tablecheck');
$this->assertArrayHasKey('total', $response);
$tableCheckUuid = $response['rows'][0]['uuid'];
$_POST = array('current' => '1', 'rowCount' => '7', 'searchPhrase' => 'testProtocol');
$response = self::$setRelayd->searchAction('protocol');
$this->assertArrayHasKey('total', $response);
$protocolUuid = $response['rows'][0]['uuid'];
// check mask, misisng table, tablecheck, wrong/missing listen port/address
$_POST = array('relayd' => [
'virtualserver' => [
'name' => 'test{}VirtualServer',
'listen_startport' => '123456',
]]);
$response = self::$setRelayd->setAction('virtualserver');
$this->assertCount(5, $response['validations']);
$this->assertEquals($response['result'], 'failed');
$this->assertNotEmpty($response['validations']['relayd.virtualserver.name']);
$this->assertNotEmpty($response['validations']['relayd.virtualserver.listen_address']);
$this->assertNotEmpty($response['validations']['relayd.virtualserver.listen_startport']);
$this->assertNotEmpty($response['validations']['relayd.virtualserver.transport_table']);
$this->assertNotEmpty($response['validations']['relayd.virtualserver.transport_tablecheck']);
$this->cleanupNodes('virtualserver');
// wrong tablemodes, missing ModelRelationField targets
$_POST = array('relayd' => [
'virtualserver' => [
'name' => 'testVirtualServer',
'listen_address' => '127.0.0.1',
'listen_startport' => '444',
'transport_table' => $tableUuid,
'transport_tablemode' => 'least-states',
'transport_tablecheck' => $tableCheckUuid,
]]);
$response = self::$setRelayd->setAction('virtualserver');
$this->assertCount(1, $response['validations']);
$this->assertEquals($response['result'], 'failed');
$this->assertNotEmpty($response['validations']['relayd.virtualserver.transport_tablemode']);
$this->cleanupNodes('virtualserver');
// wron scheduler, missing protocol
$_POST = array('relayd' => [
'virtualserver' => [
'name' => 'testVirtualServer',
'type' => 'redirect',
'listen_address' => '127.0.0.1',
'listen_startport' => '444',
'transport_table' => $tableUuid,
'transport_tablemode' => 'least-states',
'transport_tablecheck' => $tableCheckUuid,
'backuptransport_table' => $tableUuid,
'backuptransport_tablemode' => 'random',
'backuptransport_tablecheck' => $tableCheckUuid,
'protocol' => 'aaa-bbb-123-456'
]]);
$response = self::$setRelayd->setAction('virtualserver');
$this->assertCount(2, $response['validations']);
$this->assertEquals($response['result'], 'failed');
$this->assertNotEmpty($response['validations']['relayd.virtualserver.backuptransport_tablemode']);
$this->assertNotEmpty($response['validations']['relayd.virtualserver.protocol']);
$this->cleanupNodes('virtualserver');
// create virtualserver for ServiceControllerTest
$_POST = array('relayd' => [
'virtualserver' => [
'name' => 'testVirtualServer',
'enabled' => '1',
'listen_address' => '127.0.0.1',
'listen_startport' => '444',
'transport_table' => $tableUuid,
'transport_port' => '443',
'transport_tablecheck' => $tableCheckUuid,
'protocol' => $protocolUuid
]]);
$response = self::$setRelayd->setAction('virtualserver');
$this->assertEquals($response['status'], 'ok');
}
/**
* ServiceControllerTest
* @depends testSetGeneral
* @depends testSetHost
* @depends testSetTable
* @depends testSetTableCheck
* @depends testSetProtocol
* @depends testSetVirtualServer
*/
public function testServiceController()
{
$svcRelayd = new \OPNsense\Relayd\Api\ServiceController;
$_SERVER['REQUEST_METHOD'] = 'POST';
// stop possibly running service
$response = $svcRelayd->stopAction();
$this->assertEquals($response['response'], "OK\n\n");
// generate template and test it by Relayd
$response = $svcRelayd->configtestAction();
$this->assertEquals($response['template'], 'OK');
$this->assertEquals(
$response['result'],
"global timeout exceeds interval\ntable timeout exceeds interval: testTable:443"
);
$_POST = array('relayd' => ['general' => ['timeout' => '200']]);
$response = self::$setRelayd->setAction('general');
$this->assertEquals($response['status'], 'ok');
$response = $svcRelayd->configtestAction();
$this->assertEquals($response['template'], 'OK');
$this->assertEquals($response['result'], 'configuration OK');
// status
$response = $svcRelayd->statusAction();
$this->assertEquals($response['status'], 'disabled');
// enable
$_POST = array('relayd' => ['general' => ['enabled' => '1']]);
$response = self::$setRelayd->setAction('general');
$this->assertEquals($response['status'], 'ok');
// reconfigure
$response = $svcRelayd->reconfigureAction();
$this->assertEquals($response['status'], 'ok');
// status
$response = $svcRelayd->statusAction();
$this->assertEquals($response['status'], 'running');
}
/**
* StatusControllerTest
* @depends testServiceController
*/
public function testStatusController()
{
$statRelayd = new \OPNsense\Relayd\Api\StatusController;
$response = $statRelayd->sumAction();
$this->assertEquals($response['result'], 'ok');
$this->assertEquals($response['rows'][0]['type'], 'relay');
$this->assertEquals($response['rows'][0]['name'], 'testVirtualServer');
$this->assertEquals($response['rows'][0]['tables'][1]['name'], 'testTable:443');
$this->assertEquals($response['rows'][0]['tables'][1]['status'], 'active (1 hosts)');
$this->assertEquals($response['rows'][0]['tables'][1]['hosts'][1]['name'], '127.0.0.1');
$response = $statRelayd->toggleAction('table', 1, 'disable');
$this->assertEquals($response['result'], 'ok');
$this->assertEquals($response['output'], 'command succeeded');
}
/**
* cleanup config
* @depends testStatusController
*/
public function testCleanup()
{
$svcRelayd = new \OPNsense\Relayd\Api\ServiceController;
$response = $svcRelayd->stopAction();
$this->assertEquals($response['response'], "OK\n\n");
foreach (array_reverse($this->nodeTypes) as $nodeType) {
$this->cleanupNodes($nodeType);
}
$general = self::$setRelayd->mdlRelayd->getNodeByReference('general');
$general->setNodes(array('enabled' => '0'));
self::$setRelayd->mdlRelayd->serializeToConfig();
Config::getInstance()->save();
$this->assertTrue(true);
}
}

View file

@ -0,0 +1,38 @@
[start]
command:/usr/local/etc/rc.d/os-relayd start
type:script
message:starting relayd
[stop]
command:/usr/local/etc/rc.d/os-relayd stop
type:script
message:stopping relayd
[status]
command:/usr/local/etc/rc.d/os-relayd status; exit 0
type:script_output
message:get relayd status
[restart]
command:/usr/local/etc/rc.d/os-relayd restart
type:script
message:restarting relayd
[reload]
command:/usr/local/etc/rc.d/os-relayd reload
type:script
message:reload relayd configuration
[configtest]
command: /usr/local/sbin/relayd -n 2>&1; exit 0
type:script_output
message:testing relayd configuration
[summary]
command: /usr/local/sbin/relayctl show summary; exit 0
type:script_output
[toggle]
command: /usr/local/sbin/relayctl
parameters:%s %s %s
type:script_output

View file

@ -0,0 +1,2 @@
relayd.conf:/usr/local/etc/relayd.conf
rc.conf.d:/etc/rc.conf.d/osrelayd

View file

@ -0,0 +1,6 @@
# DO NOT EDIT THIS FILE -- OPNsense auto-generated file
{% if helpers.exists('OPNsense.relayd.general.enabled') and OPNsense.relayd.general.enabled|default("0") == "1" %}
osrelayd_enable="YES"
{% else %}
osrelayd_enable="NO"
{% endif %}

View file

@ -0,0 +1,157 @@
# DO NOT EDIT THIS FILE -- OPNsense auto-generated file
{% from 'OPNsense/Macros/interface.macro' import physical_interface %}
{% if helpers.exists('OPNsense.relayd.general') %}
{% if helpers.exists('OPNsense.relayd.general.interval') %}
interval {{ OPNsense.relayd.general.interval }}
{% endif %}
{% if helpers.exists('OPNsense.relayd.general.log') %}
log {{ OPNsense.relayd.general.log }}
{% endif %}
{% if helpers.exists('OPNsense.relayd.general.prefork') %}
prefork {{ OPNsense.relayd.general.prefork }}
{% endif %}
{% if helpers.exists('OPNsense.relayd.general.timeout') %}
timeout {{ OPNsense.relayd.general.timeout }}
{% endif %}
{% endif %}
{% if helpers.exists('OPNsense.relayd.table') %}
{% for table in helpers.toList('OPNsense.relayd.table') %}
{% set name = table.name %}
{% set disable = '' %}
{% set hosts = '' %}
{% if table.enabled|default('1') == '0' %}
{% set disable = ' disable' %}
{% endif %}
table <{{ name }}>{{ disable }} {
{% for host in table.hosts.split(",") %}
{% set host = helpers.getUUID(host) %}
{% set ipTTL = " ip ttl " ~ host.ipTTL if host.ipTTL is defined %}
{% set priority = " priority " ~ host.priority if host.priority is defined %}
{% set retry = " retry " ~ host.retry if host.retry is defined %}
{{ host.address }}{{ ipTTL }}{{ priority }}{{ retry }}
{% endfor %}
}
{% endfor %}
{% endif %}
{% if helpers.exists('OPNsense.relayd.protocol') %}
{% for protocol in helpers.toList('OPNsense.relayd.protocol') %}
protocol "{{protocol.name}}" {
{{ protocol.type }} { {{ protocol.options }} }
}
{% endfor %}
{% endif %}
{% if helpers.exists('OPNsense.relayd.virtualserver') %}
{% for virtualserver in helpers.toList('OPNsense.relayd.virtualserver') %}
{{ virtualserver.type }} "{{virtualserver.name}}" {
{% if virtualserver.enabled|default('1') == '0' %}
disable
{% endif %}
{% set listen = "listen on " ~ virtualserver.listen_address %}
{% if virtualserver.listen_startport is defined %}
{% set listen = listen ~ " port " ~ virtualserver.listen_startport %}
{% if virtualserver.listen_endport is defined and virtualserver.type == 'redirect'%}
{% set listen = listen ~ ":" ~ virtualserver.listen_endport %}
{% endif %}
{% endif %}
{% if virtualserver.listen_interface is defined and virtualserver.type == 'redirect' %}
{% set listen = listen ~ " interface " ~ physical_interface(virtualserver.listen_interface) %}
{% endif %}
{{ listen }}
{% set transport_type = 'forward' %}
{% if virtualserver.type == 'redirect' %}
{% set transport_type = virtualserver.transport_type %}
{% endif %}
{% set table = helpers.getUUID(virtualserver.transport_table) %}
{% set tablecheck = helpers.getUUID(virtualserver.transport_tablecheck) %}
{% set _tablecheck = '' %}
{% if tablecheck.type == 'http' %}
{% if tablecheck.path is defined %}
{% if tablecheck.ssl|default('0') == '1' %}
{% set _tablecheck = 'check ' ~ tablecheck.type ~ 's' %}
{% endif %}
{% set _tablecheck = _tablecheck ~ ' "' ~ tablecheck.path ~ '"' %}
{% if tablecheck.host is defined %}
{% set _tablecheck = _tablecheck ~ ' host ' ~ tablecheck.host %}
{% endif %}
{% if tablecheck.code is defined %}
{% set _tablecheck = _tablecheck ~ ' code ' ~ tablecheck.code %}
{% elif tablecheck.digest is defined %}
{% set _tablecheck = _tablecheck ~ ' digest "' ~ tablecheck.digest ~ '"' %}
{% else %}
{% set _tablecheck = '' %}
{% endif %}
{% endif %}
{% elif tablecheck.type == 'script' %}
{% if tablecheck.path is defined %}
{% set _tablecheck = 'check ' ~ tablecheck.type ~ ' "' ~ tablecheck.path ~ '"' %}
{% endif %}
{% elif tablecheck.type == 'send' %}
{% if tablecheck.expect is defined %}
{% set _tablecheck = 'check ' ~ tablecheck.type ~ ' "' ~ tablecheck.data ~ '" expect "' ~ tablecheck.expect ~ '"' %}
{% if tablecheck.ssl|default('0') == '1' %}
{% set _tablecheck = _tablecheck ~ ' ssl' %}
{% endif %}
{% endif %}
{% else %}
{% set _tablecheck = 'check ' ~ tablecheck.type %}
{% endif %}
{% set port = " port " ~ virtualserver.transport_port if virtualserver.transport_port is defined %}
{% set timeout = " timeout " ~ virtualserver.transport_timeout if virtualserver.transport_timeout is defined %}
{% set interval = " interval " ~ virtualserver.transport_interval if virtualserver.transport_interval is defined %}
{{ transport_type }} to <{{ table.name }}>{{ port }} mode {{ virtualserver.transport_tablemode }}{{ timeout }} {{ interval }} {{ _tablecheck }}
{% if virtualserver.backuptransport_table is defined and virtualserver.transport_type == 'forward' %}
{% set backuptable = helpers.getUUID(virtualserver.backuptransport_table) %}
{% set backuptablecheck = helpers.getUUID(virtualserver.backuptransport_tablecheck) if virtualserver.backuptransport_tablecheck is defined %}
{% set _backuptablecheck = '' %}
{% if backuptablecheck.type == 'http' %}
{% if backuptablecheck.path is defined %}
{% if backuptablecheck.ssl|default('0') == '1' %}
{% set _backuptablecheck = 'check ' ~ backuptablecheck.type ~ 's' %}
{% endif %}
{% set _backuptablecheck = _backuptablecheck ~ ' "' ~ backuptablecheck.path ~ '"' %}
{% if backuptablecheck.host is defined %}
{% set _backuptablecheck = _backuptablecheck ~ ' host ' ~ backuptablecheck.host %}
{% endif %}
{% if backuptablecheck.code is defined %}
{% set _backuptablecheck = _backuptablecheck ~ ' code ' ~ backuptablecheck.code %}
{% elif backuptablecheck.digest is defined %}
{% set _backuptablecheck = _backuptablecheck ~ ' digest "' ~ backuptablecheck.digest ~ '"' %}
{% else %}
{% set _backuptablecheck = '' %}
{% endif %}
{% endif %}
{% elif backuptablecheck.type == 'script' %}
{% if backuptablecheck.path is defined %}
{% set _backuptablecheck = 'check ' ~ backuptablecheck.type ~ ' "' ~ backuptablecheck.path ~ '"' %}
{% endif %}
{% elif backuptablecheck.type == 'send' %}
{% if backuptablecheck.expect is defined %}
{% set _backuptablecheck = 'check ' ~ backuptablecheck.type ~ ' "' ~ backuptablecheck.data ~ '" expect "' ~ backuptablecheck.expect ~ '"' %}
{% if backuptablecheck.ssl|default('0') == '1' %}
{% set _backuptablecheck = _backuptablecheck ~ ' ssl' %}
{% endif %}
{% endif %}
{% else %}
{% set _backuptablecheck = 'check ' ~ backuptablecheck.type %}
{% endif %}
{% set backuptimeout = " timeout " ~ virtualserver.backuptransport_timeout if virtualserver.backuptransport_timeout is defined %}
{% set backupinterval = " interval " ~ virtualserver.backuptransport_interval if virtualserver.backuptransport_interval is defined %}
{{ transport_type }} to <{{ backuptable.name }}>{{ port }} mode {{ virtualserver.transport_tablemode }}{{ backuptimeout }} {{ backupinterval }} {{ _backuptablecheck }}
{% endif %}
{% if virtualserver.sessiontimeout is defined %}
session timeout {{ virtualserver.sessiontimeout }}
{% endif %}
{% if virtualserver.stickyaddress|default('0') == '1' and virtualserver.type == 'redirect' %}
sticky-address
{% endif %}
{% if virtualserver.protocol is defined and virtualserver.type == 'relay' %}
{% set protocol = helpers.getUUID(virtualserver.protocol) %}
protocol "{{ protocol.name }}"
{% endif %}
}
{% endfor %}
{% endif %}

View file

@ -3,4 +3,6 @@
$logfile = '/var/log/relayd.log';
$logclog = true;
$service_hook = 'relayd';
require_once 'diag_logs_template.inc';

View file

@ -1,165 +0,0 @@
<?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");
$a_monitor = &config_read_array('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>
$( 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"); ?>

View file

@ -1,336 +0,0 @@
<?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"
);
$a_monitor = &config_read_array('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>
$( 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 style="width:22%"><strong><?=gettext("Edit Monitor entry"); ?></strong></td>
<td style="width:78%; text-align:right">
<small><?=gettext("full help"); ?> </small>
<i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_page"></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 style="vertical-align:top">&nbsp;</td>
<td style="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"); ?>

View file

@ -1,193 +0,0 @@
<?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");
$a_pool = &config_read_array('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>
$( 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"); ?>

View file

@ -1,386 +0,0 @@
<?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");
$a_pool = &config_read_array('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>
$( 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 style="text-align:right">
<small><?=gettext("full help"); ?> </small>
<i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_page"></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" data-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 class="hidden" data-for="help_for_retry">
<?=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 style="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"); ?>

View file

@ -1,178 +0,0 @@
<?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");
config_read_array('load_balancer', 'setting');
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 style="width:22%">
<strong><?=gettext("Global settings"); ?></strong>
</td>
<td style="width:78%; text-align:right">
<small><?=gettext("full help"); ?> </small>
<i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_page"></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" data-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" data-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" data-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" data-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"); ?>

View file

@ -1,178 +0,0 @@
<?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");
$a_vs = &config_read_array('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>
$( 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"); ?>

View file

@ -1,356 +0,0 @@
<?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");
$a_vs = &config_read_array('load_balancer', 'virtual_server');
$copy_fields=array('name', 'descr', 'poolname', 'port', 'sitedown', 'ipaddr', 'mode', 'relay_protocol', 'sessiontimeout');
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 (isset($pconfig['sessiontimeout']) && $pconfig['sessiontimeout'] !== '' &&
((string)((int)$pconfig['sessiontimeout']) != $pconfig['sessiontimeout'] ||
$pconfig['sessiontimeout'] < 1 || $pconfig['sessiontimeout'] > 2147483647)) {
$input_errors[] = gettext('The session timeout must be a number greater than zero or left blank.');
}
if (count($input_errors) == 0) {
$vsent = array();
foreach ($copy_fields as $fieldname) {
$vsent[$fieldname] = $pconfig[$fieldname];
}
if ($vsent['sitedown'] == '') {
unset($vsent['sitedown']);
}
if ($vsent['sessiontimeout'] == '') {
unset($vsent['sessiontimeout']);
} else {
$vsent['sessiontimeout'] = (int)$vsent['sessiontimeout'];
}
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>
$( 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 style="width:22%">
<strong><?=gettext("Add/edit - Virtual Server entry"); ?></strong>
</td>
<td style="width:78%; text-align:right">
<small><?=gettext("full help"); ?> </small>
<i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_page"></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" data-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" data-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" data-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" data-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>
<tr>
<td><a id="help_for_sessiontimeout" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Session Timeout"); ?></td>
<td>
<input type="text" name="sessiontimeout" id="sessiontimeout" value="<?=$pconfig['sessiontimeout'];?>" />
<div class="hidden" data-for="help_for_sessiontimeout">
<?= sprintf(gettext('This is the timeout in seconds for idle sessions. The default timeout is %s, the maximum is %s (%s years).'), 600, 2147483647, (int)(2147483647 / 60 / 60 / 24 / 365)) ?>
</div>
</td>
</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"); ?>

View file

@ -1,173 +0,0 @@
<?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");
$a_pool = &config_read_array('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"); ?>

View file

@ -1,134 +0,0 @@
<?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");
$a_pool = &config_read_array('load_balancer', 'lbpool');
$a_vs = &config_read_array('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 style="border:0; cellpadding:3; cellspacing:2">
<tr><td style="background-color:<?=$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"); ?>

View file

@ -1,4 +0,0 @@
<?php
$load_balancer_status_title = gettext('Load Balancer');
$load_balancer_status_title_link = 'status_lb_pool.php';

View file

@ -1,137 +0,0 @@
<?php
/*
Copyright (C) 2014 Deciso B.V.
Copyright (C) 2010 Jim Pingle <jimp@pfsense.org>
Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>
Copyright (C) 2005-2008 Bill Marquette <bill.marquette@gmail.com>
Copyright (C) 2004-2005 T. Lechat <dev@lechat.org>
Copyright (C) 2004-2005 Manuel Kasper <mk@neon1.net>
Copyright (C) 2004-2005 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");
$a_vs = &config_read_array('load_balancer', 'virtual_server');
$a_pool = &config_read_array('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 style="width:10%" class="listhdrr"><?= gettext('Server') ?></th>
<th style="width:10%" class="listhdrr"><?= gettext('Pool') ?></th>
<th style="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" style="text-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 style=\"background-color:{$bgcolor}\">&nbsp;{$server['ip']['addr']}:{$pool['port']}&nbsp;</td><td style=\"background-color:{$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>