From 0919224fbd27505f35b94f4dd8a8070ceac153aa Mon Sep 17 00:00:00 2001 From: Bill Marquette Date: Thu, 28 Aug 2008 21:21:50 +0000 Subject: Bring in relay options for inbound load balancer More work pending, this seems to generate proper configs needs much more testing though --- usr/local/www/load_balancer_relay_action_edit.php | 566 ++++++++++++++++++++++ 1 file changed, 566 insertions(+) create mode 100755 usr/local/www/load_balancer_relay_action_edit.php (limited to 'usr/local/www/load_balancer_relay_action_edit.php') 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 @@ +. + 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"); + +?> + + + + + + + + "HTTP", "tcp" => "TCP", "dns" => "DNS"); +?> + + + + + +
+ + + + + + + + + + + + + + + + + + + > + + + + + + > + + + + > + + + + > + + + + + + + + + + + +
Name + size="16" maxlength="16"> +
Protocol + +
Direction + + +
Type + $v) { + echo" +
Action + +
+ + + + + + +
Value size="20">
Key size="20">
ID size="20">
+
Options + XXX: TODO +
Options + XXX: TODO + +
Description + size="64"> +
  + + + + +
+
+
+ + + -- cgit v1.1