From 50d86c13771164ab18c0de426f434f55c9b0cdce Mon Sep 17 00:00:00 2001 From: Bill Marquette Date: Tue, 5 Aug 2008 05:03:55 +0000 Subject: Bring in new server load balancing code, this introduces: * The ability to create your own monitors (tcp, http, https, send/expect) * A new way of displaying 'standard tables' - MainTable class * monitor_type array type --- usr/local/www/classes/maintable.inc | 190 +++++++++++ usr/local/www/guiconfig.inc | 77 ++++- usr/local/www/load_balancer_monitor.php | 130 ++++++++ usr/local/www/load_balancer_monitor_edit.php | 361 +++++++++++++++++++++ usr/local/www/load_balancer_pool.php | 105 ++---- usr/local/www/load_balancer_pool_edit.php | 63 +--- usr/local/www/load_balancer_virtual_server.php | 94 +++--- .../www/load_balancer_virtual_server_edit.php | 26 +- usr/local/www/pool.js | 24 +- 9 files changed, 858 insertions(+), 212 deletions(-) create mode 100644 usr/local/www/classes/maintable.inc create mode 100755 usr/local/www/load_balancer_monitor.php create mode 100755 usr/local/www/load_balancer_monitor_edit.php (limited to 'usr/local') diff --git a/usr/local/www/classes/maintable.inc b/usr/local/www/classes/maintable.inc new file mode 100644 index 0000000..ecfbcf6 --- /dev/null +++ b/usr/local/www/classes/maintable.inc @@ -0,0 +1,190 @@ +. + 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. +*/ + +/* DISABLE_PHP_LINT_CHECKING */ + +class MainTable { + private $headers = array(); +// private $columns = array(); + private $columns = 0; + private $rows = 0; + private $content = array(); + private $edit_uri = ''; + private $my_uri = ''; + private $buttons = array('move' => false, 'edit' => false, 'del' => false, 'dup' => false); + + function add_column($header, $cname, $width) { +// $this->column[] = array('header' => $header, 'cname' => $cname, 'width' => $width) + $this->headers[] = $header; + $this->cname[] = $cname; + $this->width[] = $width; + $this->columns++; + } + + function add_content_array($rows) { + foreach($rows as $row) { + $this->content[] = $row; + $this->rows++; + } + } + function add_button($name) { + if (isset($this->buttons[$name])) { + $this->buttons[$name] = true; + } + } + function edit_uri($uri) { + $this->edit_uri = $uri; + } + + function my_uri($uri) { + $this->my_uri = $uri; + } + + function display() { + echo "\n"; + echo "\n"; + echo " \n"; + echo $this->display_header(); + echo " \n"; + echo " \n"; + echo $this->display_rows(); + echo " \n"; + echo " \n"; + echo $this->display_footer(); + echo " \n"; + echo "
\n"; + echo "\n"; + } + + private function display_header() { + global $g; + echo "\n"; + for ($col = 0; $col < $this->columns - 1; $col++) { + echo " width[$col]}%\" class=\"listhdrr\">{$this->headers[$col]}\n"; + } + echo " width[$this->columns - 1]}%\" class=\"listhdr\">{$this->headers[$this->columns - 1]}\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
edit_uri}\">
\n"; + echo " \n"; + echo "\n"; + + } + private function display_rows() { + global $g; + $cur_row = 0; + foreach ($this->content as $row) { + echo "\n"; + for ($col = 0; $col < $this->columns - 1; $col++) { + if ($col == 0) { + $cl = 'listlr'; + } else { + $cl = 'listr'; + } + echo " edit_uri}?id={$cur_row}\'\">\n"; + if (is_array($row[$this->cname[$col]])) { + foreach ($row[$this->cname[$col]] as $data) { + echo " {$data}
\n"; + } + } else { + echo " " . $row[$this->cname[$col]] . "\n"; + } + echo " \n"; + } + echo " edit_uri}?id={$cur_row}\'\">\n"; + echo " {$row[$this->cname[$this->columns - 1]]}\n"; + echo " \n"; + echo " \n"; + $this->display_buttons($cur_row); + echo " \n"; + echo "\n"; + + $cur_row++; + } + } + private function display_footer() { + global $g; + echo "\n"; + echo " columns}\">\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
edit_uri}\">
\n"; + echo " \n"; + echo "\n"; + } + private function display_buttons($row) { + echo " \n"; + echo " \n"; + if ($this->buttons['move']) + echo $this->display_button('move', $row); + if ($this->buttons['edit']) + echo $this->display_button('edit', $row); + echo " \n"; + if ($this->buttons['del']) + echo $this->display_button('del', $row); + if ($this->buttons['dup']) + echo $this->display_button('dup', $row); + echo " \n"; + echo "
\n"; + } + private function display_button($button, $row) { + global $g; + echo ""; + switch ($button) { + case "move": { + echo ""; + break; + } + case "edit": { + echo "edit_uri}?id={$row}\">"; + break; + } + case "del": { + echo "my_uri}?act=del&id={$row}\" onclick=\"return confirm(\'Do you really want to delete this entry?\')\">"; + break; + } + case "dup": { + echo "edit_uri}?act=dup&id={$row}\">"; + break; + } + } + echo ""; + } + +} +?> diff --git a/usr/local/www/guiconfig.inc b/usr/local/www/guiconfig.inc index 50fcd54..ae91288 100755 --- a/usr/local/www/guiconfig.inc +++ b/usr/local/www/guiconfig.inc @@ -47,6 +47,12 @@ require_once("authgui.inc"); require_once("config.inc"); require_once("functions.inc"); +/* Pull in all the gui related display classes) */ +foreach (scandir("/usr/local/www/classes/") as $file) { + if (stristr($file, ".inc") !== false) { + require_once("classes/{$file}"); + } +} /* * if user has selected a custom template, use it. * otherwise default to pfsense tempalte @@ -881,5 +887,74 @@ function outputCSSFileInline($css) { } } -?> +$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" +); + +function is_rfc2616_code($code) { + global $rfc2616; + if (isset($rfc2616[$code])) + return true; + else + return false; +} + +function print_rfc2616_select($tag, $current){ + global $rfc2616; + /* Default to 200 OK if not set */ + if ($current == "") + $current = 200; + + echo " size="16" maxlength="16"> + + + + Type + + + + + > + + > + + > + HTTP + + + + + + + + + + + + + + + +
Path + size="64"> +
Host + size="64">
Hostname for Host: header if needed. +
HTTP Code + +
+ + + > + HTTPS + + + + + + + + + + + + + + + +
Path + size="64"> +
Host + size="64">
Hostname for Host: header if needed. +
HTTP Code + +
+ + + > + Send/Expect + + + + + + + + + + +
Send string + size="64"> +
Expect string + size="64"> +
+ + + + Description + + size="64"> + + + +   + + + + + + + + + +
+ + + diff --git a/usr/local/www/load_balancer_pool.php b/usr/local/www/load_balancer_pool.php index 5b73862..77f1035 100755 --- a/usr/local/www/load_balancer_pool.php +++ b/usr/local/www/load_balancer_pool.php @@ -4,7 +4,7 @@ load_balancer_pool.php part of pfSense (http://www.pfsense.com/) - Copyright (C) 2005 Bill Marquette . + Copyright (C) 2005-2008 Bill Marquette . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -44,6 +44,7 @@ if (!is_array($config['load_balancer']['lbpool'])) { } $a_pool = &$config['load_balancer']['lbpool']; + if ($_POST) { $pconfig = $_POST; @@ -82,6 +83,15 @@ if ($_GET['act'] == "del") { } } +/* 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; +} +for ($i = 0; isset($config['load_balancer']['lbpool'][$i]); $i++) { + $a_pool[$i]['monitor'] = "{$a_pool[$i]['monitor']}"; +} + $pgtitle = array("Load Balancer","Pool"); include("head.inc"); @@ -101,83 +111,34 @@ include("head.inc"); $tab_array = array(); $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"); display_top_tabs($tab_array); ?>
- - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeServers/GatewaysPortMonitorDescription - - - - - -
-
- - - -
- () -
- "; - } - ?> - - - - - - - - - - - - -
-
- - - - - -
-
-
- - +edit_uri('load_balancer_pool_edit.php'); + $t->my_uri('load_balancer_pool.php'); + $t->add_column('Name','name',10); + $t->add_column('Servers','servers',15); + $t->add_column('Port','port',10); + $t->add_column('Monitor','monitor',15); + $t->add_column('Description','desc',30); + $t->add_button('edit'); + $t->add_button('dup'); + $t->add_button('del'); + $t->add_content_array($a_pool); + $t->display(); +?> + + + + + + diff --git a/usr/local/www/load_balancer_pool_edit.php b/usr/local/www/load_balancer_pool_edit.php index a6f5a82..a527265 100755 --- a/usr/local/www/load_balancer_pool_edit.php +++ b/usr/local/www/load_balancer_pool_edit.php @@ -4,7 +4,7 @@ load_balancer_pool_edit.php part of pfSense (http://www.pfsense.com/) - Copyright (C) 2005 Bill Marquette . + Copyright (C) 2005-2008 Bill Marquette . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -49,8 +49,6 @@ else $id = $_GET['id']; if (isset($id) && $a_pool[$id]) { - $pconfig['monitorip'] = $a_pool[$id]['monitorip']; - $pconfig['behaviour'] = $a_pool[$id]['behaviour']; $pconfig['name'] = $a_pool[$id]['name']; $pconfig['desc'] = $a_pool[$id]['desc']; $pconfig['port'] = $a_pool[$id]['port']; @@ -79,8 +77,7 @@ if ($_POST) { if (($_POST['name'] == $config['load_balancer']['lbpool'][$i]['name']) && ($i != $id)) $input_errors[] = "This pool name has already been used. Pool names must be unique."; if (!is_port($_POST['port'])) - if($_POST['type'] == "server") - $input_errors[] = "The port must be an integer between 1 and 65535."; + $input_errors[] = "The port must be an integer between 1 and 65535."; if (is_array($_POST['servers'])) { foreach($pconfig['servers'] as $svrent) { if (!is_ipaddr($svrent)) { @@ -95,14 +92,13 @@ if ($_POST) { } } } + $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 ($_POST['monitor'] != "TCP" && $_POST['monitor'] != "HTTP" && $_POST['monitor'] != "ICMP") + if (!isset($m[$_POST['monitor']])) $input_errors[] = "Invalid monitor chosen."; - if(!isset($_POST['behaviour'])) { - $input_errors[] = "No pool behaviour chosen."; - } - if (!$input_errors) { $poolent = array(); if(isset($id) && $a_pool[$id]) @@ -110,12 +106,6 @@ if ($_POST) { if($poolent['name'] != "") $changedesc .= " modified '{$poolent['name']}' pool:"; - /* kill off old static route */ - if(is_ipaddr($poolent['monitorip'])) - mwexec("route delete {$poolent['monitorip']}"); - - update_if_changed("behaviour", $poolent['behaviour'], $_POST['behaviour']); - update_if_changed("monitorip", $poolent['monitorip'], $_POST['monitorip']); update_if_changed("name", $poolent['name'], $_POST['name']); update_if_changed("description", $poolent['desc'], $_POST['desc']); update_if_changed("port", $poolent['port'], $_POST['port']); @@ -181,17 +171,6 @@ function clearcombo(){ - - - >
- >
- Load Balancing: both active. Failover order: top -> down. - - - - Port size="16" maxlength="16">
@@ -202,26 +181,24 @@ function clearcombo(){ Monitor - Monitor IP - -
- -
- - - -
+
-
@@ -266,10 +243,6 @@ echo "";
- -
- - @@ -278,7 +251,7 @@ echo "";   - + diff --git a/usr/local/www/load_balancer_virtual_server.php b/usr/local/www/load_balancer_virtual_server.php index 45ca5e9..4a4f98d 100755 --- a/usr/local/www/load_balancer_virtual_server.php +++ b/usr/local/www/load_balancer_virtual_server.php @@ -4,7 +4,7 @@ load_balancer_virtual_server.php part of pfSense (http://www.pfsense.com/) - Copyright (C) 2005 Bill Marquette . + Copyright (C) 2005-2008 Bill Marquette . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -72,6 +72,21 @@ if ($_GET['act'] == "del") { } } +/* 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; +} +for ($i = 0; isset($config['load_balancer']['virtual_server'][$i]); $i++) { + $a_vs[$i]['pool'] = "{$a_vs[$i]['pool']}"; + if ($a_vs[$i]['sitedown'] != '') { + $a_vs[$i]['sitedown'] = "{$a_vs[$i]['sitedown']}"; + } else { + $a_vs[$i]['sitedown'] = 'none'; + } +} + + $pgtitle = array("Services","Load Balancer","Virtual Servers"); include("head.inc"); @@ -91,69 +106,34 @@ include("head.inc"); $tab_array = array(); $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"); display_top_tabs($tab_array); ?>
- - - - - - - - - - - - - - - - - - - - - - -
NameServer addressPortPoolDescription - - - - - -
-
- - - - - - - - -   - - - - - - -
-
- - - - - -
-
+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('IP Address','ipaddr',15); + $t->add_column('Port','port',10); + $t->add_column('Pool','pool',15); + $t->add_column('Fall Back Pool','sitedown',15); + $t->add_column('Description','desc',30); + $t->add_button('edit'); + $t->add_button('dup'); + $t->add_button('del'); + $t->add_content_array($a_vs); + $t->display(); +?>
- - + + + + diff --git a/usr/local/www/load_balancer_virtual_server_edit.php b/usr/local/www/load_balancer_virtual_server_edit.php index e24cb63..e6c7f0e 100755 --- a/usr/local/www/load_balancer_virtual_server_edit.php +++ b/usr/local/www/load_balancer_virtual_server_edit.php @@ -4,7 +4,7 @@ load_balancer_virtual_server_edit.php part of pfSense (http://www.pfsense.com/) - Copyright (C) 2005 Bill Marquette . + Copyright (C) 2005-2008 Bill Marquette . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -158,30 +158,26 @@ include("head.inc"); - Pool Down Server + Fall Back Pool @@ -190,7 +186,7 @@ include("head.inc"); - + diff --git a/usr/local/www/pool.js b/usr/local/www/pool.js index 5a4b480..ab6303d 100755 --- a/usr/local/www/pool.js +++ b/usr/local/www/pool.js @@ -2,7 +2,7 @@ pool.js part of pfSense (http://www.pfsense.com/) - Copyright (C) 2005 Bill Marquette . + Copyright (C) 2005-2008 Bill Marquette . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -31,27 +31,7 @@ * operates on whatever form is passed to it */ function AddServerToPool(form) { - - var IntOrIp; - var enabledSel = form['servers[]']; - var disabledSel = form['serversdisabled[]']; - if (form.type.selectedIndex == 0) - IntOrIp = form.ipaddr; - else - IntOrIp = form.iface; - - if (form.type.selectedIndex == 1) { - if (!form.monitorip.value) { - alert("Monitor IP Required First!"); - return true; - } - } - - var ServerPort = IntOrIp.value; - if(form.type.selectedIndex == 0) - var ServerPort = IntOrIp.value; - else - var ServerPort = IntOrIp.value + "|" + form.monitorip.value; + var ServerPort = form.ipaddr.value; form['servers[]'].options[form['servers[]'].options.length] = new Option(ServerPort,ServerPort); } -- cgit v1.1