summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/inc/vslb.inc82
-rw-r--r--etc/inc/xmlparse.inc26
-rwxr-xr-xusr/local/www/guiconfig.inc28
-rwxr-xr-xusr/local/www/load_balancer_monitor.php2
-rwxr-xr-xusr/local/www/load_balancer_monitor_edit.php2
-rwxr-xr-xusr/local/www/load_balancer_pool.php2
-rwxr-xr-xusr/local/www/load_balancer_pool_edit.php2
-rwxr-xr-xusr/local/www/load_balancer_relay_action.php150
-rwxr-xr-xusr/local/www/load_balancer_relay_action_edit.php566
-rwxr-xr-xusr/local/www/load_balancer_relay_protocol.php146
-rw-r--r--usr/local/www/load_balancer_relay_protocol_edit.js56
-rwxr-xr-xusr/local/www/load_balancer_relay_protocol_edit.php275
-rwxr-xr-xusr/local/www/load_balancer_virtual_server.php3
-rwxr-xr-xusr/local/www/load_balancer_virtual_server_edit.php91
14 files changed, 1397 insertions, 34 deletions
diff --git a/etc/inc/vslb.inc b/etc/inc/vslb.inc
index d2488d9..e3a9566 100644
--- a/etc/inc/vslb.inc
+++ b/etc/inc/vslb.inc
@@ -118,13 +118,51 @@ class SendMonitor extends Monitor {
}
}
-
+function echo_lbaction($action) {
+ global $config;
+
+ // Index actions by name
+ $actions_a = array();
+ for ($i=0; isset($config['load_balancer']['lbaction'][$i]); $i++)
+ $actions_a[$config['load_balancer']['lbaction'][$i]['name']] = $config['load_balancer']['lbaction'][$i];
+
+ $ret = "";
+ $ret .= "{$actions_a[$action]['direction']} {$actions_a[$action]['type']} {$actions_a[$action]['action']}";
+ switch($actions_a[$action]['action']) {
+ case 'append': {
+ $ret .= " \"{$actions_a[$action]['options']['value']}\" to \"{$actions_a[$action]['options']['akey']}\"";
+ break;
+ }
+ case 'change': {
+ $ret .= " \"{$actions_a[$action]['options']['akey']}\" to \"{$actions_a[$action]['options']['value']}\"";
+ break;
+ }
+ case 'expect': {
+ $ret .= " \"{$actions_a[$action]['options']['value']}\" from \"{$actions_a[$action]['options']['akey']}\"";
+ break;
+ }
+ case 'filter': {
+ $ret .= " \"{$actions_a[$action]['options']['value']}\" from \"{$actions_a[$action]['options']['akey']}\"";
+ break;
+ }
+ case 'hash': {
+ $ret .= " \"{$actions_a[$action]['options']['akey']}\"";
+ break;
+ }
+ case 'log': {
+ $ret .= " \"{$actions_a[$action]['options']['akey']}\"";
+ break;
+ }
+ }
+ return $ret;
+}
function relayd_configure() {
global $config, $g;
$vs_a = &$config['load_balancer']['virtual_server'];
$pool_a = &$config['load_balancer']['lbpool'];
+ $protocol_a = &$config['load_balancer']['lbprotocol'];
$check_a = array();
@@ -170,16 +208,42 @@ function relayd_configure() {
}
}
}
-
+ if(is_array($protocol_a)) {
+ for ($i = 0; isset($protocol_a[$i]); $i++) {
+ $conf .= "protocol \"{$protocol_a[$i]['name']}\" {\n";
+ if(is_array($protocol_a[$i]['lbaction'])) {
+ for ($a = 0; isset($protocol_a[$i]['lbaction'][$a]); $a++) {
+ $conf .= " " . echo_lbaction($protocol_a[$i]['lbaction'][$a]) . "\n";
+ }
+ }
+ $conf .= "}\n";
+ }
+ }
if(is_array($vs_a)) {
for ($i = 0; isset($vs_a[$i]); $i++) {
- $conf .= "redirect \"{$vs_a[$i]['name']}\" {\n";
- $conf .= " listen on {$vs_a[$i]['ipaddr']} port {$vs_a[$i]['port']}\n";
- $conf .= " forward to <{$vs_a[$i]['pool']}> port {$pools[$vs_a[$i]['pool']]['port']} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} timeout 1000\n";
-
- if (isset($vs_a[$i]['sitedown']) && $vs_a[$i]['sitedown'] != "")
- $conf .= " forward to <{$vs_a[$i]['sitedown']}> port {$pools[$vs_a[$i]['pool']]['port']} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} timeout 1000\n";
- $conf .= "}\n";
+ switch($vs_a[$i]['mode']) {
+ case 'redirect': {
+ $conf .= "redirect \"{$vs_a[$i]['name']}\" {\n";
+ $conf .= " listen on {$vs_a[$i]['ipaddr']} port {$vs_a[$i]['port']}\n";
+ $conf .= " forward to <{$vs_a[$i]['pool']}> port {$pools[$vs_a[$i]['pool']]['port']} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} timeout 1000\n";
+
+ if (isset($vs_a[$i]['sitedown']) && $vs_a[$i]['sitedown'] != "")
+ $conf .= " forward to <{$vs_a[$i]['sitedown']}> port {$pools[$vs_a[$i]['pool']]['port']} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} timeout 1000\n";
+ $conf .= "}\n";
+ break;
+ }
+ case 'relay': {
+ $conf .= "relay \"{$vs_a[$i]['name']}\" {\n";
+ $conf .= " listen on {$vs_a[$i]['ipaddr']} port {$vs_a[$i]['port']}\n";
+ $conf .= " protocol \"{$vs_a[$i]['relay_protocol']}\"\n";
+ $conf .= " forward to <{$vs_a[$i]['pool']}> port {$pools[$vs_a[$i]['pool']]['port']} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} timeout 1000\n";
+
+ if (isset($vs_a[$i]['sitedown']) && $vs_a[$i]['sitedown'] != "")
+ $conf .= " forward to <{$vs_a[$i]['sitedown']}> port {$pools[$vs_a[$i]['pool']]['port']} {$check_a[$pools[$vs_a[$i]['pool']]['monitor']]} timeout 1000\n";
+ $conf .= "}\n";
+ break;
+ }
+ }
}
}
fwrite($fd, $conf);
diff --git a/etc/inc/xmlparse.inc b/etc/inc/xmlparse.inc
index 1f5b24c..f4a9e12 100644
--- a/etc/inc/xmlparse.inc
+++ b/etc/inc/xmlparse.inc
@@ -32,18 +32,22 @@
/* The following items will be treated as arrays in config.xml */
function listtags() {
+ /* Please keep this list alpha sorted and no longer than 80 characters
+ * I know it's a pain, but it's a pain to find stuff too if it's not
+ */
$ret = explode(" ",
- "element alias aliasurl allowedip cacert config columnitem disk ".
- "dnsserver domainoverrides earlyshellcmd encryption-algorithm-option ".
- "field fieldname hash-algorithm-option hosts group member ca cert ".
- "interface_array item key lbpool menu mobilekey monitor_type ".
- "mount onetoone option ppp package passthrumac phase1 phase2 priv ".
- "proxyarpnet queue pages pipe route row rule schedule service ".
- "servernat servers serversdisabled earlyshellcmd shellcmd staticmap ".
- "subqueue timerange tunnel user authserver vip virtual_server vlan ".
- "winsserver ntpserver wolentry widget depends_on_package ".
- "gateway_item gateway_group dyndns dnsupdate gre gif bridged lagg ".
- "openvpn-server openvpn-client openvpn-csc");
+ "alias aliasurl allowedip authserver bridged ca cacert cert config ".
+ "columnitem depends_on_package disk dnsserver dnsupdate domainoverrides ".
+ "dyndns earlyshellcmd element encryption-algorithm-option field ".
+ "fieldname hash-algorithm-option gateway_item gateway_group gif gre ".
+ "group hosts member interface_array item key lagg lbaction lbpool ".
+ "lbprotocol member menu mobilekey monitor_type mount ntpserver onetoone ".
+ "openvpn-server openvpn-client openvpn-csc" .
+ "option ppp package passthrumac phase1 phase2 priv proxyarpnet queue ".
+ "pages pipe route row rule schedule service servernat servers ".
+ "serversdisabled earlyshellcmd shellcmd staticmap subqueue timerange ".
+ "tunnel user vip virtual_server vlan winsserver wolentry widget "
+ );
return $ret;
}
diff --git a/usr/local/www/guiconfig.inc b/usr/local/www/guiconfig.inc
index 66094b3..289787a 100755
--- a/usr/local/www/guiconfig.inc
+++ b/usr/local/www/guiconfig.inc
@@ -947,4 +947,32 @@ function print_rfc2616_select($tag, $current){
}
}
+// Useful debugging function, much cleaner than print_r
+function echo_array($array,$return_me=false){
+ if(is_array($array) == false){
+ $return = "The provided variable is not an array.";
+ }else{
+ foreach($array as $name=>$value){
+ if(is_array($value)){
+ $return .= "";
+ $return .= "['<b>$name</b>'] {<div style='margin-left:10px;'>\n";
+ $return .= echo_array($value,true);
+ $return .= "</div>}";
+ $return .= "\n\n";
+ }else{
+ if(is_string($value)){
+ $value = "\"$value\"";
+ }
+ $return .= "['<b>$name</b>'] = $value\n\n";
+ }
+ }
+ }
+ if($return_me == true){
+ return $return;
+ }else{
+ echo "<pre>".$return."</pre>";
+ }
+}
+
+
?>
diff --git a/usr/local/www/load_balancer_monitor.php b/usr/local/www/load_balancer_monitor.php
index 3a37c04..736abee 100755
--- a/usr/local/www/load_balancer_monitor.php
+++ b/usr/local/www/load_balancer_monitor.php
@@ -101,6 +101,8 @@ include("head.inc");
$tab_array[] = array("Pools", false, "load_balancer_pool.php");
$tab_array[] = array("Virtual Servers", false, "load_balancer_virtual_server.php");
$tab_array[] = array("Monitors", true, "load_balancer_monitor.php");
+ $tab_array[] = array("Relay Protocols", false, "load_balancer_relay_protocol.php");
+ $tab_array[] = array("Relay Actions", false, "load_balancer_relay_action.php");
display_top_tabs($tab_array);
?>
</td></tr>
diff --git a/usr/local/www/load_balancer_monitor_edit.php b/usr/local/www/load_balancer_monitor_edit.php
index 88c022c..937cc0b 100755
--- a/usr/local/www/load_balancer_monitor_edit.php
+++ b/usr/local/www/load_balancer_monitor_edit.php
@@ -33,7 +33,7 @@
##|*IDENT=page-services-loadbalancer-monitor-edit
##|*NAME=Services: Load Balancer: Monitor: Edit page
##|*DESCR=Allow access to the 'Services: Load Balancer: Monitor: Edit' page.
-##|*MATCH=load_balancer_monitor.php*
+##|*MATCH=load_balancer_monitor_edit.php*
##|-PRIV
require("guiconfig.inc");
diff --git a/usr/local/www/load_balancer_pool.php b/usr/local/www/load_balancer_pool.php
index 77f1035..9b5452b 100755
--- a/usr/local/www/load_balancer_pool.php
+++ b/usr/local/www/load_balancer_pool.php
@@ -112,6 +112,8 @@ include("head.inc");
$tab_array[] = array("Pools", true, "load_balancer_pool.php");
$tab_array[] = array("Virtual Servers", false, "load_balancer_virtual_server.php");
$tab_array[] = array("Monitors", false, "load_balancer_monitor.php");
+ $tab_array[] = array("Relay Protocols", false, "load_balancer_relay_protocol.php");
+ $tab_array[] = array("Relay Actions", false, "load_balancer_relay_action.php");
display_top_tabs($tab_array);
?>
</td></tr>
diff --git a/usr/local/www/load_balancer_pool_edit.php b/usr/local/www/load_balancer_pool_edit.php
index a527265..c7c5506 100755
--- a/usr/local/www/load_balancer_pool_edit.php
+++ b/usr/local/www/load_balancer_pool_edit.php
@@ -252,7 +252,7 @@ echo "</select>";
<td width="22%" valign="top">&nbsp;</td>
<td width="78%">
<input name="Submit" type="submit" class="formbtn" value="Save" onClick="AllServers('serversSelect', true); AllServers('serversDisabledSelect', true);"><input type="button" class="formbtn" value="Cancel" onclick="history.back()">
- <?php if (isset($id) && $a_pool[$id]): ?>
+ <?php if (isset($id) && $a_pool[$id] && $_GET['act'] != 'dup'): ?>
<input name="id" type="hidden" value="<?=$id;?>">
<?php endif; ?>
</td>
diff --git a/usr/local/www/load_balancer_relay_action.php b/usr/local/www/load_balancer_relay_action.php
new file mode 100755
index 0000000..55763a3
--- /dev/null
+++ b/usr/local/www/load_balancer_relay_action.php
@@ -0,0 +1,150 @@
+<?php
+/* $Id$ */
+/*
+ load_balancer_protocol.php
+ part of pfSense (http://www.pfsense.com/)
+
+ 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.
+*/
+
+##|+PRIV
+##|*IDENT=page-services-loadbalancer-relay-action
+##|*NAME=Services: Load Balancer: Relay Actions page
+##|*DESCR=Allow access to the 'Services: Load Balancer: Relay Actions' page.
+##|*MATCH=load_balancer_relay_action.php*
+##|-PRIV
+
+require("guiconfig.inc");
+
+if (!is_array($config['load_balancer']['lbaction'])) {
+ $config['load_balancer']['lbaction'] = array();
+}
+$a_action = &$config['load_balancer']['lbaction'];
+
+
+if ($_POST) {
+
+ $pconfig = $_POST;
+
+ if ($_POST['apply']) {
+ $retval = 0;
+
+ config_lock();
+ $retval |= filter_configure();
+ $retval |= relayd_configure();
+ config_unlock();
+
+ $savemsg = get_std_save_message($retval);
+ unlink_if_exists($d_vsconfdirty_path);
+ }
+}
+
+if ($_GET['act'] == "del") {
+ if ($a_action[$_GET['id']]) {
+ /* make sure no relay protocols reference this entry */
+ if (is_array($config['load_balancer']['lbprotocol'])) {
+ foreach ($config['load_balancer']['lbprotocol'] as $lbp) {
+ foreach($lbp['lbaction'] as $lba) {
+ if ($lba['name'] == $a_action[$_GET['id']]['name']) {
+ $input_errors[] = "This entry cannot be deleted because it is still referenced by at least one relay protocol.";
+ break;
+ }
+ }
+ }
+ }
+
+ if (!$input_errors) {
+ unset($a_action[$_GET['id']]);
+ write_config();
+ touch($d_vsconfdirty_path);
+ header("Location: load_balancer_relay_action.php");
+ exit;
+ }
+ }
+}
+
+/* Index lbpool array for easy hyperlinking */
+/* for ($i = 0; isset($config['load_balancer']['lbprotocol'][$i]); $i++) {
+ for ($o = 0; isset($config['load_balancer']['lbprotocol'][$i]['options'][$o]); o++) {
+ $a_vs[$i]['options'][$o] = "
+ $a_vs[$i]['pool'] = "<a href=\"/load_balancer_pool_edit.php?id={$poodex[$a_vs[$i]['pool']]}\">{$a_vs[$i]['pool']}</a>";
+ if ($a_vs[$i]['sitedown'] != '') {
+ $a_vs[$i]['sitedown'] = "<a href=\"/load_balancer_pool_edit.php?id={$poodex[$a_vs[$i]['sitedown']]}\">{$a_vs[$i]['sitedown']}</a>";
+ } else {
+ $a_vs[$i]['sitedown'] = 'none';
+ }
+}
+*/
+
+$pgtitle = array("Load Balancer","Relay Action");
+include("head.inc");
+
+?>
+<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
+<?php include("fbegin.inc"); ?>
+<form action="load_balancer_relay_action.php" method="post">
+<?php if ($input_errors) print_input_errors($input_errors); ?>
+<?php if ($savemsg) print_info_box($savemsg); ?>
+<?php if (file_exists($d_vsconfdirty_path)): ?><p>
+<?php print_info_box_np("The load balancer configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
+<?php endif; ?>
+<table width="100%" border="0" cellpadding="0" cellspacing="0">
+ <tr><td class="tabnavtbl">
+ <?php
+ /* active tabs */
+ $tab_array = array();
+ $tab_array[] = array("Pools", false, "load_balancer_pool.php");
+ $tab_array[] = array("Virtual Servers", false, "load_balancer_virtual_server.php");
+ $tab_array[] = array("Monitors", false, "load_balancer_monitor.php");
+ $tab_array[] = array("Relay Protocols", false, "load_balancer_relay_protocol.php");
+ $tab_array[] = array("Relay Actions", true, "load_balancer_relay_action.php");
+ display_top_tabs($tab_array);
+ ?>
+ </td></tr>
+ <tr>
+ <td>
+ <div id="mainarea">
+<?
+ $t = new MainTable();
+ $t->edit_uri('load_balancer_relay_action_edit.php');
+ $t->my_uri('load_balancer_relay_action.php');
+ $t->add_column('Name','name',20);
+ $t->add_column('Type','type',10);
+ $t->add_column('Options','options',30);
+ $t->add_column('Description','desc',30);
+ $t->add_button('edit');
+ $t->add_button('dup');
+ $t->add_button('del');
+ $t->add_content_array($a_action);
+ $t->display();
+?>
+ </div>
+ </td>
+ </tr>
+</table>
+</form>
+<?php include("fend.inc"); ?>
+</body>
+</html>
diff --git a/usr/local/www/load_balancer_relay_action_edit.php b/usr/local/www/load_balancer_relay_action_edit.php
new file mode 100755
index 0000000..95f5a4f
--- /dev/null
+++ b/usr/local/www/load_balancer_relay_action_edit.php
@@ -0,0 +1,566 @@
+<?php
+/* $Id$ */
+/*
+ load_balancer_protocol_edit.php
+ part of pfSense (http://www.pfsense.com/)
+
+ 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.
+*/
+
+##|+PRIV
+##|*IDENT=page-services-loadbalancer-relay-action-edit
+##|*NAME=Services: Load Balancer: Relay Action: Edit page
+##|*DESCR=Allow access to the 'Services: Load Balancer: Relay Action: Edit' page.
+##|*MATCH=load_balancer_relay_action_edit.php*
+##|-PRIV
+
+require("guiconfig.inc");
+if (!is_array($config['load_balancer']['lbaction'])) {
+ $config['load_balancer']['lbaction'] = array();
+}
+$a_action = &$config['load_balancer']['lbaction'];
+
+if (isset($_POST['id']))
+ $id = $_POST['id'];
+else
+ $id = $_GET['id'];
+
+if (isset($id) && $a_action[$id]) {
+ $pconfig = array();
+ $pconfig = $a_action[$id];
+} else {
+ // XXX - TODO, this isn't sane for this page :)
+ /* Some sane page defaults */
+ $pconfig['protocol'] = 'http';
+ $pconfig['direction'] = 'request';
+ $pconfig['type'] = 'cookie';
+ $pconfig['action'] = 'change';
+}
+
+$changedesc = "Load Balancer: Relay Action: ";
+$changecount = 0;
+
+$kv = array('key', 'value');
+$vk = array('value', 'key');
+$hr_actions = array();
+$hr_actions['append'] = $vk;
+$hr_actions['change'] = $kv;
+$hr_actions['expect'] = $vk;
+$hr_actions['filter'] = $vk;
+$hr_actions['hash'] = 'key';
+$hr_actions['log'] = 'key';
+// mark is disabled until I can figure out how to make the display clean
+//$hr_actions['mark'] = array('value', 'key', 'id');
+//$hr_actions[] = 'label';
+//$hr_actions[] = 'no label';
+$hr_actions['remove'] = 'key';
+//$hr_actions[] = 'return error';
+/* Setup decision tree */
+$action = array();
+$actions['protocol']['http'] = 'HTTP';
+$actions['protocol']['tcp'] = 'TCP';
+$actions['protocol']['dns'] = 'DNS';
+$actions['direction'] = array();
+$actions['direction']['request'] = array();
+$actions['direction']['request']['cookie'] = $hr_actions;
+$actions['direction']['request']['header'] = $hr_actions;
+$actions['direction']['request']['path'] = $hr_actions;
+$actions['direction']['request']['query'] = $hr_actions;
+$actions['direction']['request']['url'] = $hr_actions;
+$actions['direction']['response'] = array();
+$actions['direction']['response']['cookie'] = $hr_actions;
+$actions['direction']['response']['header'] = $hr_actions;
+//$action['http']['tcp'] = array();
+//$action['http']['ssl'] = array();
+
+
+
+if ($_POST) {
+ $changecount++;
+
+ unset($input_errors);
+ $pconfig = $_POST;
+
+ // Peel off the action and type from the post and fix $pconfig
+ $action = explode('_', $pconfig['action']);
+ $pconfig['action'] = $action[2];
+ $pconfig['type'] = $action[1];
+ unset($pconfig["type_{$pconfig['direction']}"]);
+
+ /* input validation */
+ $reqdfields = explode(" ", "name protocol direction action desc");
+ $reqdfieldsn = explode(",", "Name,Protocol,Direction,Action,Description");
+
+ do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
+
+ /* Ensure that our monitor names are unique */
+ for ($i=0; isset($config['load_balancer']['lbactions'][$i]); $i++)
+ if (($_POST['name'] == $config['load_balancer']['lbactions'][$i]['name']) && ($i != $id))
+ $input_errors[] = "This action name has already been used. Action names must be unique.";
+
+
+ if (!$input_errors) {
+ $actent = array();
+ if(isset($id) && $a_action[$id])
+ $actent = $a_action[$id];
+ if($actent['name'] != "")
+ $changedesc .= " modified '{$actent['name']}' action:";
+
+ update_if_changed("name", $actent['name'], $pconfig['name']);
+ update_if_changed("protocol", $actent['protocol'], $pconfig['protocol']);
+ update_if_changed("type", $actent['type'], $pconfig['type']);
+ update_if_changed("direction", $actent['direction'], $pconfig['direction']);
+ update_if_changed("description", $actent['desc'], $pconfig['desc']);
+ update_if_changed("action", $actent['action'], $pconfig['action']);
+ switch ($pconfig['action']) {
+ case "append":
+ case "change":
+ case "expect":
+ case "filter": {
+ update_if_changed("value", $actent['options']['value'], $pconfig['option_action_value']);
+ update_if_changed("key", $actent['options']['akey'], $pconfig['option_action_key']);
+ break;
+ }
+ case "hash":
+ case "log": {
+ update_if_changed("key", $actent['options']['akey'], $pconfig['option_action_key']);
+ break;
+ }
+ }
+
+ if (isset($id) && $a_action[$id]) {
+// XXX - TODO
+ /* 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]['protocol'] == $a_protocol[$id]['name'])
+// $config['load_balancer']['virtual_server'][$i]['protocol'] = $protent['name'];
+// }
+ $a_action[$id] = $actent;
+ } else {
+ $a_action[] = $actent;
+ }
+ if ($changecount > 0) {
+ /* Mark config dirty */
+ conf_mount_rw();
+ touch($d_vsconfdirty_path);
+ write_config($changedesc);
+ }
+
+ header("Location: load_balancer_relay_action.php");
+ exit;
+ }
+}
+
+$pgtitle = array("Load Balancer","Relay Action","Edit");
+include("head.inc");
+
+?>
+
+<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
+<!-- <script type="text/javascript" language="javascript" src="mon.js"></script> -->
+
+<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
+<script src="/javascript/scriptaculous/scriptaculous.js" type="text/javascript"></script>
+
+<?php
+ $types = array("http" => "HTTP", "tcp" => "TCP", "dns" => "DNS");
+?>
+
+<script language="javascript">
+
+function updateProtocol(m) {
+ // Default to HTTP
+ if (m == "") {
+ m = "http";
+ }
+ switch (m) {
+ case "dns": {
+ $('type_row').hide();
+ $('tcp_options_row').hide();
+ $('ssl_options_row').hide();
+ $('direction_row').hide();
+ $('action_row').hide();
+ break;
+ }
+ case "tcp": {
+ $('type_row').hide();
+ $('tcp_options_row').appear();
+ $('ssl_options_row').hide();
+ $('direction_row').hide();
+ $('action_row').hide();
+ break;
+ }
+ case "http": {
+ $('type_row').appear();
+ $('tcp_options_row').hide();
+ $('ssl_options_row').appear();
+ $('direction_row').appear();
+ $('direction').enable();
+ $('type_' + $('direction').getValue()).enable();
+ $('type_' + $('direction').getValue()).appear();
+ $('action_row').appear();
+<?
+ /* Generate lots of .appear() entries for the action row select list
+ * based on what's been either preconfigured or "defaults"
+ * This really did have to be done in PHP.
+ */
+ if (isset($pconfig['type'])) {
+ $dtype = $pconfig['type'];
+ $ddir = $pconfig['direction'];
+ } else {
+ $dtype = "cookie";
+ $ddir = "request";
+ }
+ foreach ($actions['direction'][$ddir] as $type => $tv) {
+ foreach ($actions['direction'][$ddir][$type] as $action => $av ) {
+ if($dtype == $type) {
+ echo "$('{$ddir}_{$type}_{$action}').appear();";
+ }
+ }
+ }
+?>
+
+ break;
+ }
+ }
+}
+
+function updateDirection(d) {
+ // Default to request
+ if (d == "") {
+ d = "request";
+ }
+
+ switch (d) {
+ case "request": {
+ $('type_response').disable();
+ $('type_response').hide();
+ $('type_request').enable();
+ $('type_request').appear();
+ break;
+ }
+ case "response": {
+ $('type_request').disable();
+ $('type_request').hide();
+ $('type_response').enable();
+ $('type_response').appear();
+ break;
+ }
+ }
+}
+
+
+function updateType(t){
+ // Default to action_row
+ // XXX - does this actually make any sense?
+ if (t == "") {
+ t = "action_row";
+ }
+
+ switch(t) {
+<?php
+ /* OK, so this is sick using php to generate javascript, but it needed to be done */
+ foreach ($types as $key => $val) {
+ echo " case \"{$key}\": {\n";
+ $t = $types;
+ foreach ($t as $k => $v) {
+ if ($k != $key) {
+ echo " $('{$k}').hide();\n";
+ }
+ }
+ echo " }\n";
+ }
+?>
+ }
+ $(t).appear();
+}
+
+
+function updateAction(a) {
+ // Default to change
+ if (a == "") {
+ a = "change";
+ }
+
+ switch(a) {
+ case "append": {
+ $('input_action_value').appear();
+ $('option_action_value').enable();
+ $('input_action_key').appear();
+ $('option_action_key').enable();
+ $('input_action_id').hide();
+ $('option_action_id').disable();
+ $('action_action_value').update("&nbsp;to&nbsp;");
+ $('action_action_id').update("");
+ break;
+ }
+ case "change": {
+ $('input_action_value').appear();
+ $('option_action_value').enable();
+ $('input_action_key').appear();
+ $('option_action_key').enable();
+ $('input_action_id').hide();
+ $('option_action_id').disable();
+ $('action_action_value').update("&nbsp;of&nbsp;");
+ $('action_action_id').update("");
+ break;
+ }
+ case "expect": {
+ $('input_action_value').appear();
+ $('option_action_value').enable();
+ $('input_action_key').appear();
+ $('option_action_key').enable();
+ $('input_action_id').hide();
+ $('option_action_id').disable();
+ $('action_action_value').update("&nbsp;from&nbsp;");
+ $('action_action_id').update("");
+ break;
+ }
+ case "filter": {
+ $('input_action_value').appear();
+ $('option_action_value').enable();
+ $('input_action_key').appear();
+ $('option_action_key').enable();
+ $('input_action_id').hide();
+ $('option_action_id').disable();
+ $('action_action_value').update("&nbsp;from&nbsp;");
+ $('action_action_id').update("");
+ break;
+ }
+ case "hash": {
+ $('input_action_value').hide();
+ $('option_action_value').disable();
+ $('input_action_key').appear();
+ $('option_action_key').enable();
+ $('input_action_id').hide();
+ $('option_action_id').disable();
+ $('action_action_value').update("");
+ $('action_action_id').update("");
+ break;
+ }
+ case "log": {
+ $('input_action_value').hide();
+ $('option_action_value').disable();
+ $('input_action_key').appear();
+ $('option_action_key').enable();
+ $('input_action_id').hide();
+ $('option_action_id').disable();
+ $('action_action_value').update("");
+ $('action_action_id').update("");
+ break;
+ }
+ case "mark": {
+ $('input_action_value').appear();
+ $('option_action_value').enable();
+ $('input_action_key').appear();
+ $('option_action_key').enable();
+ $('input_action_id').appear();
+ $('option_action_id').enable();
+ $('action_action_value').update("&nbsp;from&nbsp;");
+ $('action_action_id').update("&nbsp;with&nbsp;");
+ break;
+ }
+ }
+}
+
+
+function num_options() {
+ return $('options_table').childElements().length - 1;
+}
+
+
+document.observe("dom:loaded", function() {
+alert('fu');
+ updateProtocol('<?=$pconfig['protocol']?>');
+ updateDirection('<?=$pconfig['direction']?>');
+ updateType('<?=$pconfig['type']?>');
+ updateAction('<?=$pconfig['action']?>');
+});
+
+</script>
+
+<?php include("fbegin.inc"); ?>
+<?php if ($input_errors) print_input_errors($input_errors); ?>
+ <form action="load_balancer_relay_action_edit.php" method="post" name="iform" id="iform">
+ <table width="100%" border="0" cellpadding="6" cellspacing="0">
+ <tr align="left" id="name">
+ <td width="22%" valign="top" class="vncellreq">Name</td>
+ <td width="78%" class="vtable" colspan="2">
+ <input name="name" type="text" <?if(isset($pconfig['name'])) echo "value=\"{$pconfig['name']}\"";?> size="16" maxlength="16">
+ </td>
+ </tr>
+<!-- Protocol -->
+ <tr align="left" id="protocol_row">
+ <td width="22%" valign="top" class="vncellreq">Protocol</td>
+ <td width="78%" class="vtable" colspan="2">
+ <select id="protocol" name="protocol">
+<?
+ foreach ($actions['protocol'] as $key => $val) {
+ if(isset($pconfig['protocol']) && $pconfig['protocol'] == $key) {
+ $selected = " selected";
+ } else {
+ $selected = "";
+ }
+ echo "<option value=\"{$key}\" onclick=\"updateProtocol('{$key}');\"{$selected}>{$val}</option>\n";
+ }
+?>
+ </select>
+ </td>
+ </tr>
+
+<!-- Direction -->
+ <tr align="left" id="direction_row">
+ <td width="22%" valign="top" class="vncellreq">Direction</td>
+ <td width="78%" class="vtable" colspan="2">
+ <select id="direction" name="direction" style="disabled">
+<?
+ foreach ($actions['direction'] as $key => $val) {
+ if(isset($pconfig['direction']) && $pconfig['direction'] == $key) {
+ $selected = " selected";
+ } else {
+ $selected = "";
+ }
+ echo "<option value=\"{$key}\" onclick=\"updateDirection('{$key}');\"{$selected}>{$key}</option>\n";
+ }
+?>
+ </select>
+
+ </td>
+ </tr>
+
+<!-- Type -->
+ <tr align="left" id="type_row"<?= $pconfig['protocol'] == "http" ? "" : " style=\"display:none;\""?>>
+ <td width="22%" valign="top" class="vncellreq">Type</td>
+ <td width="78%" class="vtable" colspan="2">
+<?
+ foreach ($actions['direction'] as $dir => $v) {
+ echo" <select id=\"type_{$dir}\" name=\"type_{$dir}\" style=\"display:none; disabled;\">";
+ foreach ($actions['direction'][$dir] as $key => $val) {
+ if(isset($pconfig['type']) && $pconfig['type'] == $key) {
+ $selected = " selected";
+ } else {
+ $selected = "";
+ }
+ echo "<option value=\"{$key}\" onclick=\"updateDirection('$key');\"{$selected}>{$key}</option>\n";
+ }
+ }
+?>
+ </select>
+ </td>
+ </tr>
+
+<!-- Action -->
+ <tr align="left" id="action_row"<?= $pconfig['protocol'] == "http" ? "" : " style=\"display:none;\""?>>
+ <td width="22%" valign="top" class="vncellreq">Action</td>
+ <td width="78%" class="vtable" colspan="2">
+ <select id="action" name="action" style=\"display: none;\">
+<?
+ foreach ($actions['direction'] as $dir => $dv) {
+ foreach ($actions['direction'][$dir] as $type => $tv) {
+ foreach ($actions['direction'][$dir][$type] as $action => $av ) {
+ if(isset($pconfig['action']) && $pconfig['action'] == $action) {
+ $selected = " selected";
+ } else if ($action == "change" ){
+ $selected = " selected";
+ } else {
+ $selected = "";
+ }
+ echo "<option id=\"{$dir}_{$type}_{$action}\" value=\"{$dir}_{$type}_{$action}\" onClick=\"updateAction('$action');\" style=\"display: none;\"{$selected}>{$action}</option>\n";
+ }
+ }
+ }
+?>
+ </select>
+<br/>
+<table><tr>
+<td><div id="input_action_value">Value&nbsp;<input id="option_action_value" name="option_action_value" type="text" <?if(isset($pconfig['options']['value'])) echo "value=\"{$pconfig['options']['value']}\"";?>size="20"></div></td>
+<td><div id="action_action_value"></div></td>
+<td><div id="input_action_key">Key&nbsp;<input id="option_action_key" name="option_action_key" type="text" <?if(isset($pconfig['options']['akey'])) echo "value=\"{$pconfig['options']['akey']}\"";?>size="20"></div></td>
+<td><div id="action_action_id"></div></td>
+<td><div id="input_action_id">ID&nbsp;<input id="option_action_id" name="option_action_id" type="text" <?if(isset($pconfig['options']['id'])) echo "value=\"{$pconfig['options']['id']}\"";?>size="20"></div></td>
+</tr></table>
+ </td>
+ </tr>
+ <tr align="left" id="tcp_options_row"<?= $pconfig['protocol'] == "tcp" ? "" : " style=\"display:none;\""?>>
+ <td width="22%" valign="top" class="vncellreq">Options</td>
+ <td width="78%" class="vtable" colspan="2">
+ XXX: TODO
+ <select id="options" name="options">
+<!-- XXX TODO >
+<?
+ foreach ($types as $key => $val) {
+ if(isset($pconfig['protocol']) && $pconfig['protocol'] == $key) {
+ $selected = " selected";
+ } else {
+ $selected = "";
+ }
+ echo "<option value=\"{$key}\" onclick=\"updateType('{$key}');\"{$selected}>{$val}</option>\n";
+ }
+?>
+ </select>
+< XXX TODO -->
+ </td>
+ </tr>
+ <tr align="left" id="ssl_options_row"<?= $pconfig['protocol'] == "http" ? "" : " style=\"display:none;\""?>>
+ <td width="22%" valign="top" class="vncellreq">Options</td>
+ <td width="78%" class="vtable" colspan="2">
+ XXX: TODO
+<!-- XXX TODO >
+ <select id="options" name="options">
+<?
+ foreach ($types as $key => $val) {
+ if(isset($pconfig['protocol']) && $pconfig['protocol'] == $key) {
+ $selected = " selected";
+ } else {
+ $selected = "";
+ }
+ echo "<option value=\"{$key}\" onclick=\"updateType('{$key}');\"{$selected}>{$val}</option>\n";
+ }
+?>
+ </select>
+< XXX TODO -->
+ </td>
+ </tr>
+ <tr align="left">
+ <td width="22%" valign="top" class="vncellreq">Description</td>
+ <td width="78%" class="vtable" colspan="2">
+ <input name="desc" type="text" <?if(isset($pconfig['desc'])) echo "value=\"{$pconfig['desc']}\"";?>size="64">
+ </td>
+ </tr>
+ <tr align="left">
+ <td width="22%" valign="top">&nbsp;</td>
+ <td width="78%">
+ <input name="Submit" type="submit" class="formbtn" value="Save"><input type="button" class="formbtn" value="Cancel" onclick="history.back()">
+ <?php if (isset($id) && $a_action[$id] && $_GET['act'] != 'dup'): ?>
+ <input name="id" type="hidden" value="<?=$id;?>">
+ <?php endif; ?>
+ </td>
+ </tr>
+ </table>
+ </form>
+<br>
+<?php include("fend.inc"); ?>
+</body>
+</html>
diff --git a/usr/local/www/load_balancer_relay_protocol.php b/usr/local/www/load_balancer_relay_protocol.php
new file mode 100755
index 0000000..560d8d8
--- /dev/null
+++ b/usr/local/www/load_balancer_relay_protocol.php
@@ -0,0 +1,146 @@
+<?php
+/* $Id$ */
+/*
+ load_balancer_relay_protocol.php
+ part of pfSense (http://www.pfsense.com/)
+
+ 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.
+*/
+
+##|+PRIV
+##|*IDENT=page-services-loadbalancer-relay-protocol
+##|*NAME=Services: Load Balancer: Relay Protocols page
+##|*DESCR=Allow access to the 'Services: Load Balancer: Relay Protocols' page.
+##|*MATCH=load_balancer_relay_protocol.php*
+##|-PRIV
+
+require("guiconfig.inc");
+
+if (!is_array($config['load_balancer']['lbprotocol'])) {
+ $config['load_balancer']['lbprotocol'] = array();
+}
+$a_protocol = &$config['load_balancer']['lbprotocol'];
+
+if ($_POST) {
+ $pconfig = $_POST;
+
+ if ($_POST['apply']) {
+ $retval = 0;
+
+ config_lock();
+ $retval |= filter_configure();
+ $retval |= relayd_configure();
+ config_unlock();
+
+ $savemsg = get_std_save_message($retval);
+ unlink_if_exists($d_vsconfdirty_path);
+ }
+}
+
+if ($_GET['act'] == "del") {
+ if ($a_protocol[$_GET['id']]) {
+ /* 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['protocol'] == $a_protocol[$_GET['id']]['name']) {
+ $input_errors[] = "This entry cannot be deleted because it is still referenced by at least one virtual server.";
+ break;
+ }
+ }
+ }
+
+ if (!$input_errors) {
+ unset($a_protocol[$_GET['id']]);
+ write_config();
+ touch($d_vsconfdirty_path);
+ header("Location: load_balancer_relay_protocol.php");
+ exit;
+ }
+ }
+}
+
+/* Index lbpool array for easy hyperlinking */
+/* for ($i = 0; isset($config['load_balancer']['lbprotocol'][$i]); $i++) {
+ for ($o = 0; isset($config['load_balancer']['lbprotocol'][$i]['options'][$o]); o++) {
+ $a_vs[$i]['options'][$o] = "
+ $a_vs[$i]['pool'] = "<a href=\"/load_balancer_pool_edit.php?id={$poodex[$a_vs[$i]['pool']]}\">{$a_vs[$i]['pool']}</a>";
+ if ($a_vs[$i]['sitedown'] != '') {
+ $a_vs[$i]['sitedown'] = "<a href=\"/load_balancer_pool_edit.php?id={$poodex[$a_vs[$i]['sitedown']]}\">{$a_vs[$i]['sitedown']}</a>";
+ } else {
+ $a_vs[$i]['sitedown'] = 'none';
+ }
+}
+*/
+
+$pgtitle = array("Load Balancer","Relay Protocol");
+include("head.inc");
+
+?>
+<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
+<?php include("fbegin.inc"); ?>
+<form action="load_balancer_relay_protocol.php" method="post">
+<?php if ($input_errors) print_input_errors($input_errors); ?>
+<?php if ($savemsg) print_info_box($savemsg); ?>
+<?php if (file_exists($d_vsconfdirty_path)): ?><p>
+<?php print_info_box_np("The load balancer configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
+<?php endif; ?>
+<table width="100%" border="0" cellpadding="0" cellspacing="0">
+ <tr><td class="tabnavtbl">
+ <?php
+ /* active tabs */
+ $tab_array = array();
+ $tab_array[] = array("Pools", false, "load_balancer_pool.php");
+ $tab_array[] = array("Virtual Servers", false, "load_balancer_virtual_server.php");
+ $tab_array[] = array("Monitors", false, "load_balancer_monitor.php");
+ $tab_array[] = array("Relay Protocols", true, "load_balancer_relay_protocol.php");
+ $tab_array[] = array("Relay Actions", false, "load_balancer_relay_action.php");
+ display_top_tabs($tab_array);
+ ?>
+ </td></tr>
+ <tr>
+ <td>
+ <div id="mainarea">
+<?
+ $t = new MainTable();
+ $t->edit_uri('load_balancer_relay_protocol_edit.php');
+ $t->my_uri('load_balancer_relay_protocol.php');
+ $t->add_column('Name','name',20);
+ $t->add_column('Type','type',10);
+ $t->add_column('Options','options',30);
+ $t->add_column('Description','desc',30);
+ $t->add_button('edit');
+ $t->add_button('dup');
+ $t->add_button('del');
+ $t->add_content_array($a_protocol);
+ $t->display();
+?>
+ </div>
+ </td>
+ </tr>
+</table>
+</form>
+<?php include("fend.inc"); ?>
+</body>
+</html>
diff --git a/usr/local/www/load_balancer_relay_protocol_edit.js b/usr/local/www/load_balancer_relay_protocol_edit.js
new file mode 100644
index 0000000..fcf67ce
--- /dev/null
+++ b/usr/local/www/load_balancer_relay_protocol_edit.js
@@ -0,0 +1,56 @@
+/*
+ pool.js
+ part of pfSense (http://www.pfsense.com/)
+
+ 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.
+*/
+
+/*
+ * This code makes use of prototype shortcuts and will not work
+ * without prototype being loaded prior to it.
+ */
+
+function copyOption(theSrc, theDst)
+{
+ var selOption = theSrc[theSrc.selectedIndex];
+ theDst.options[theDst.length] = new Option(selOption.text, selOption.value);
+}
+
+function deleteOption(theSel)
+{
+ var theIndex = theSel.selectedIndex;
+ var selLength = theSel.length;
+ if(selLength>0)
+ {
+ theSel.options[theIndex] = null;
+ }
+}
+
+function AllOptions(el, selectAll) {
+ el.select('option').each(function(opt) {
+ opt.selected = selectAll;
+ });
+}
+
diff --git a/usr/local/www/load_balancer_relay_protocol_edit.php b/usr/local/www/load_balancer_relay_protocol_edit.php
new file mode 100755
index 0000000..ca8522e
--- /dev/null
+++ b/usr/local/www/load_balancer_relay_protocol_edit.php
@@ -0,0 +1,275 @@
+<?php
+/* $Id$ */
+/*
+ load_balancer_protocol_edit.php
+ part of pfSense (http://www.pfsense.com/)
+
+ 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.
+*/
+
+##|+PRIV
+##|*IDENT=page-services-loadbalancer-relay-protocol-edit
+##|*NAME=Services: Load Balancer: Relay Protocol: Edit page
+##|*DESCR=Allow access to the 'Services: Load Balancer: Relay Protocol: Edit' page.
+##|*MATCH=load_balancer_relay_protocol_edit.php*
+##|-PRIV
+
+require("guiconfig.inc");
+if (!is_array($config['load_balancer']['lbprotocol'])) {
+ $config['load_balancer']['lbprotocol'] = array();
+}
+$a_protocol = &$config['load_balancer']['lbprotocol'];
+
+if (isset($_POST['id']))
+ $id = $_POST['id'];
+else
+ $id = $_GET['id'];
+
+if (isset($id) && $a_protocol[$id]) {
+ $pconfig = $a_protocol[$id];
+ $pconfig['type'] = $a_protocol[$id]['type'];
+ $pconfig['desc'] = $a_protocol[$id]['desc'];
+ $pconfig['lbaction'] = array();
+ $pconfig['options'] = $a_protocol[$id]['options'];
+} else {
+ /* Some sane page defaults */
+ $pconfig['type'] = 'http';
+}
+
+$changedesc = "Load Balancer: Relay Protocol: ";
+$changecount = 0;
+
+
+
+if ($_POST) {
+ $changecount++;
+
+ unset($input_errors);
+ $pconfig = $_POST;
+
+
+ /* input validation */
+ $reqdfields = explode(" ", "name type desc");
+ $reqdfieldsn = explode(",", "Name,Type,Description");
+
+ do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
+
+ /* Ensure that our monitor names are unique */
+ for ($i=0; isset($config['load_balancer']['lbprotocol'][$i]); $i++)
+ if (($_POST['name'] == $config['load_balancer']['lbprotocol'][$i]['name']) && ($i != $id))
+ $input_errors[] = "This protocol name has already been used. Protocol names must be unique.";
+
+ switch($_POST['type']) {
+ case 'tcp':
+ case 'http':
+ case 'https':
+ case 'dns': {
+ break;
+ }
+ }
+
+ if (!$input_errors) {
+ $protent = array();
+ if(isset($id) && $a_protocol[$id])
+ $protent = $a_protocol[$id];
+ if($protent['name'] != "")
+ $changedesc .= " modified '{$protent['name']}' load balancing protocol:";
+
+ update_if_changed("name", $protent['name'], $pconfig['name']);
+ update_if_changed("type", $protent['type'], $pconfig['type']);
+ update_if_changed("description", $protent['desc'], $pconfig['desc']);
+ update_if_changed("type", $protent['type'], $pconfig['type']);
+ update_if_changed("action", $protent['lbaction'], $pconfig['lbaction']);
+
+ if (isset($id) && $a_protocol[$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]['protocol'] == $a_protocol[$id]['name'])
+ $config['load_balancer']['virtual_server'][$i]['protocol'] = $protent['name'];
+ }
+*/
+ $a_protocol[$id] = $protent;
+ } else {
+ $a_protocol[] = $protent;
+ }
+
+ if ($changecount > 0) {
+ /* Mark config dirty */
+ conf_mount_rw();
+ touch($d_vsconfdirty_path);
+ write_config($changedesc);
+ }
+
+ header("Location: load_balancer_relay_protocol.php");
+ exit;
+ }
+}
+
+$pgtitle = array("Load Balancer","Relay Protocol","Edit");
+include("head.inc");
+
+?>
+
+<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
+<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
+<script src="/javascript/scriptaculous/scriptaculous.js" type="text/javascript"></script>
+<script type="text/javascript" language="javascript" src="load_balancer_relay_protocol_edit.js"></script>
+
+
+<?php
+ $types = array("http" => "HTTP", "tcp" => "TCP", "dns" => "DNS");
+?>
+
+<script language="javascript">
+function updateType(t){
+ switch(t) {
+<?php
+ /* OK, so this is sick using php to generate javascript, but it needed to be done */
+ foreach ($types as $key => $val) {
+ echo " case \"{$key}\": {\n";
+ $t = $types;
+ foreach ($t as $k => $v) {
+ if ($k != $key) {
+ echo " $('{$k}').hide();\n";
+ }
+ }
+ echo " }\n";
+ }
+?>
+ }
+ $(t).appear();
+}
+
+function num_options() {
+ return $('options_table').childElements().length - 1;
+}
+
+/*
+document.observe('dom:loaded', function(){
+ $$('.action').each(function(action) {
+ new Draggable(action, {revert: true, ghosting: true});
+ });
+ Droppables.add('actions', {
+ accept: 'action', onDrop: function(action) {
+ var new_action = new Element('li');
+ new Draggable(new_action, {revert: true});
+ $('action_list').appendChild(new_action);
+ }
+ });
+});
+*/
+</script>
+
+<?php include("fbegin.inc"); ?>
+<?php if ($input_errors) print_input_errors($input_errors); ?>
+ <form action="load_balancer_relay_protocol_edit.php" method="post" name="iform" id="iform">
+ <table width="100%" border="0" cellpadding="6" cellspacing="0">
+ <tr align="left">
+ <td width="22%" valign="top" class="vncellreq">Name</td>
+ <td width="78%" class="vtable" colspan="2">
+ <input name="name" type="text" <?if(isset($pconfig['name'])) echo "value=\"{$pconfig['name']}\"";?> size="16" maxlength="16">
+ </td>
+ </tr>
+ <tr align="left">
+ <td width="22%" valign="top" class="vncellreq">Type</td>
+ <td width="78%" class="vtable" colspan="2">
+ <select id="type" name="type">
+<?
+ foreach ($types as $key => $val) {
+ if(isset($pconfig['type']) && $pconfig['type'] == $key) {
+ $selected = " selected";
+ } else {
+ $selected = "";
+ }
+ echo "<option value=\"{$key}\" onclick=\"updateType('{$key}');\"{$selected}>{$val}</option>\n";
+ }
+?>
+ </select>
+ </td>
+ </tr>
+ <tr align="left" id="actions">
+ <td width="22%" valign="top" class="vncellreq">Actions</td>
+ <td width="78%" class="vtable" colspan="2">
+ <table>
+ <tbody>
+ <tr>
+ <td>
+ Available Actions<br/>
+ <select id="available_action" name="available_action[]" multiple="true" size="5">
+<?php
+if (is_array($config['load_balancer']['lbaction'])) {
+ foreach($config['load_balancer']['lbaction'] as $actent) {
+ if($actent != '') echo " <option value=\"{$actent['name']}\">{$actent['name']}</option>\n";
+ }
+}
+echo "</select>";
+?>
+ <br/>
+ </td>
+ <td valign="middle">
+ <input class="formbtn" type="button" name="copyToEnabled" value=">" onclick="copyOption($('available_action'), $('lbaction'));" /><br/>
+ <input class="formbtn" type="button" name="removeFromEnabled" value="X" onclick="deleteOption($('lbaction'));" />
+ </td>
+
+ <td>
+ Enabled Actions<br/>
+ <select id="lbaction" name="lbaction[]" multiple="true" size="5">
+<?php
+if (is_array($pconfig['lbaction'])) {
+ foreach($pconfig['lbaction'] as $actent) {
+ echo " <option value=\"{$actent}\">{$actent}</option>\n";
+ }
+}
+echo "</select>";
+?>
+ <br/>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+ <tr align="left">
+ <td width="22%" valign="top" class="vncellreq">Description</td>
+ <td width="78%" class="vtable" colspan="2">
+ <input name="desc" type="text" <?if(isset($pconfig['desc'])) echo "value=\"{$pconfig['desc']}\"";?>size="64">
+ </td>
+ </tr>
+ <tr align="left">
+ <td width="22%" valign="top">&nbsp;</td>
+ <td width="78%">
+ <input name="Submit" type="submit" class="formbtn" value="Save" onClick="AllOptions($('lbaction'), true); AllOptions($('available_action'), false);"><input type="button" class="formbtn" value="Cancel" onclick="history.back()">
+ <?php if (isset($id) && $a_protocol[$id] && $_GET['act'] != 'dup'): ?>
+ <input name="id" type="hidden" value="<?=$id;?>">
+ <?php endif; ?>
+ </td>
+ </tr>
+ </table>
+ </form>
+<br>
+<?php include("fend.inc"); ?>
+</body>
+</html>
diff --git a/usr/local/www/load_balancer_virtual_server.php b/usr/local/www/load_balancer_virtual_server.php
index 4a4f98d..f7d61a9 100755
--- a/usr/local/www/load_balancer_virtual_server.php
+++ b/usr/local/www/load_balancer_virtual_server.php
@@ -107,6 +107,8 @@ include("head.inc");
$tab_array[] = array("Pools", false, "load_balancer_pool.php");
$tab_array[] = array("Virtual Servers", true, "load_balancer_virtual_server.php");
$tab_array[] = array("Monitors", false, "load_balancer_monitor.php");
+ $tab_array[] = array("Relay Protocols", false, "load_balancer_relay_protocol.php");
+ $tab_array[] = array("Relay Actions", false, "load_balancer_relay_action.php");
display_top_tabs($tab_array);
?>
</td></tr>
@@ -118,6 +120,7 @@ include("head.inc");
$t->edit_uri('load_balancer_virtual_server_edit.php');
$t->my_uri('load_balancer_virtual_server.php');
$t->add_column('Name','name',10);
+ $t->add_column('Mode','mode',10);
$t->add_column('IP Address','ipaddr',15);
$t->add_column('Port','port',10);
$t->add_column('Pool','pool',15);
diff --git a/usr/local/www/load_balancer_virtual_server_edit.php b/usr/local/www/load_balancer_virtual_server_edit.php
index e6c7f0e..07b7350 100755
--- a/usr/local/www/load_balancer_virtual_server_edit.php
+++ b/usr/local/www/load_balancer_virtual_server_edit.php
@@ -49,12 +49,10 @@ else
$id = $_GET['id'];
if (isset($id) && $a_vs[$id]) {
- $pconfig['ipaddr'] = $a_vs[$id]['ipaddr'];
- $pconfig['port'] = $a_vs[$id]['port'];
- $pconfig['pool'] = $a_vs[$id]['pool'];
- $pconfig['desc'] = $a_vs[$id]['desc'];
- $pconfig['name'] = $a_vs[$id]['name'];
- $pconfig['sitedown'] = $a_vs[$id]['sitedown'];
+ $pconfig = $a_vs[$id];
+} else {
+ // Sane defaults
+ $pconfig['mode'] = 'redirect';
}
$changedesc = "Load Balancer: Virtual Server: ";
@@ -65,8 +63,18 @@ if ($_POST) {
$pconfig = $_POST;
/* input validation */
- $reqdfields = explode(" ", "ipaddr name port");
- $reqdfieldsn = explode(",", "IP Address, Name, Port");
+ switch($pconfig['mode']) {
+ case "redirect": {
+ $reqdfields = explode(" ", "ipaddr name port mode");
+ $reqdfieldsn = explode(",", "IP Address, Name, Port, Mode");
+ break;
+ }
+ case "relay": {
+ $reqdfields = explode(" ", "ipaddr name port mode relay_protocol");
+ $reqdfieldsn = explode(",", "IP Address, Name, Port, Relay Protocol");
+ break;
+ }
+ }
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
@@ -95,6 +103,8 @@ if ($_POST) {
update_if_changed("port", $vsent['port'], $_POST['port']);
update_if_changed("sitedown", $vsent['sitedown'], $_POST['sitedown']);
update_if_changed("ipaddr", $vsent['ipaddr'], $_POST['ipaddr']);
+ update_if_changed("mode", $vsent['mode'], $_POST['mode']);
+ update_if_changed("relay protocol", $vsent['relay_protocol'], $_POST['relay_protocol']);
if (isset($id) && $a_vs[$id])
$a_vs[$id] = $vsent;
@@ -119,11 +129,42 @@ include("head.inc");
?>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
+<script src="/javascript/scriptaculous/prototype.js" type="text/javascript"></script>
+<script src="/javascript/scriptaculous/scriptaculous.js" type="text/javascript"></script>
+<script language="javascript" type="text/javascript">
+function updateRelay(m) {
+ switch (m) {
+ case "relay": {
+ $('relay_protocol').enable();
+ $('relay').appear();
+ break;
+ }
+ case "redirect": {
+ $('relay_protocol').disable();
+ $('relay').hide();
+ break;
+ }
+ }
+}
+
+document.observe("dom:loaded", function() {
+ // Setup some observers
+ $('redirect_mode').observe('click', function(){
+ updateRelay('redirect');
+ });
+ $('relay_mode').observe('click', function(){
+ updateRelay('relay');
+ });
+
+ // Go ahead and disable the relay stuff, we'll trigger
+ updateRelay("<?=$pconfig['mode'];?>");
+
+});
+
+</script>
<?php include("fbegin.inc"); ?>
<?php if ($input_errors) print_input_errors($input_errors); ?>
<form action="load_balancer_virtual_server_edit.php" method="post" name="iform" id="iform">
-<script type="text/javascript" language="javascript" src="pool.js">
-</script>
<table width="100%" border="0" cellpadding="6" cellspacing="0">
<tr align="left">
@@ -171,7 +212,7 @@ include("head.inc");
<td width="22%" valign="top" class="vncellreq">Fall Back Pool</td>
<td width="78%" class="vtable" colspan="2">
<select id="sitedown" name="sitedown">
- <option value=""<?="selected" ? $pconfig['sitedown'] == '' : ''?>>none</option>
+ <option value=""<?=$pconfig['sitedown'] == '' ? ' selected' : ''?>>none</option>
<?php
for ($i = 0; isset($config['load_balancer']['lbpool'][$i]); $i++) {
$selected = "";
@@ -185,9 +226,35 @@ include("head.inc");
</td>
</tr>
<tr align="left">
+ <td width="22%" valign="top" class="vncellreq">Mode</td>
+ <td width="78%" class="vtable" colspan="2">
+ <input id="redirect_mode" type="radio" name="mode" value="redirect"<?=$pconfig['mode'] == 'redirect' ? ' checked="checked"': ''?>> Redirect
+ <input id="relay_mode" type="radio" name="mode" value="relay"<?=$pconfig['mode'] == 'relay' ? ' checked="checked"': ''?>> Relay
+
+ <br>
+ </td>
+ </tr>
+ <tr id="relay" align="left" style="display:none;">
+ <td width="22%" valign="top" class="vncellreq">Relay Protocol</td>
+ <td width="78%" class="vtable" colspan="2">
+ <select id="relay_protocol" name="relay_protocol">
+ <?php
+ for ($i = 0; isset($config['load_balancer']['lbprotocol'][$i]); $i++) {
+ $selected = "";
+ if ( $config['load_balancer']['lbprotocol'][$i]['name'] == $pconfig['lbprotocol'] )
+ $selected = " SELECTED";
+ echo "<option value=\"{$config['load_balancer']['lbprotocol'][$i]['name']}\"{$selected}>{$config['load_balancer']['lbprotocol'][$i]['name']}</option>";
+ }
+ ?>
+ </select>
+ <br>
+ </td>
+ </tr>
+
+ <tr align="left">
<td align="left" valign="bottom">
<input name="Submit" type="submit" class="formbtn" value="Submit"><input type="button" class="formbtn" value="Cancel" onclick="history.back()">
- <?php if (isset($id) && $a_vs[$id]): ?>
+ <?php if (isset($id) && $a_vs[$id] && $_GET['act'] != 'dup'): ?>
<input name="id" type="hidden" value="<?=$id;?>">
<?php endif; ?>
</td>
OpenPOWER on IntegriCloud