diff options
-rw-r--r-- | etc/inc/vslb.inc | 127 | ||||
-rw-r--r-- | etc/inc/xmlparse.inc | 2 | ||||
-rw-r--r-- | usr/local/www/classes/maintable.inc | 190 | ||||
-rwxr-xr-x | usr/local/www/guiconfig.inc | 77 | ||||
-rwxr-xr-x | usr/local/www/load_balancer_monitor.php | 130 | ||||
-rwxr-xr-x | usr/local/www/load_balancer_monitor_edit.php | 361 | ||||
-rwxr-xr-x | usr/local/www/load_balancer_pool.php | 105 | ||||
-rwxr-xr-x | usr/local/www/load_balancer_pool_edit.php | 63 | ||||
-rwxr-xr-x | usr/local/www/load_balancer_virtual_server.php | 94 | ||||
-rwxr-xr-x | usr/local/www/load_balancer_virtual_server_edit.php | 26 | ||||
-rwxr-xr-x | usr/local/www/pool.js | 24 |
11 files changed, 979 insertions, 220 deletions
diff --git a/etc/inc/vslb.inc b/etc/inc/vslb.inc index 86cd2a5..0f2e3cf 100644 --- a/etc/inc/vslb.inc +++ b/etc/inc/vslb.inc @@ -28,17 +28,133 @@ */ +/* DISABLE_PHP_LINT_CHECKING */ + /* include all configuration functions */ require_once("functions.inc"); require_once("pkg-utils.inc"); require_once("notices.inc"); +class Monitor { + private $conf = array(); + function __construct($config) { + $this->conf = $config; + } + + public function p() { + return "check {$this->get('proto')}"; + } + private function get($var) { + return isset($this->$var) ? $this->$var : ""; + } + protected function config($element) { + return isset($this->conf[$element]) ? $this->conf[$element] : ""; + } +} + +class TCPMonitor extends Monitor { + protected $proto = 'tcp'; +} + +class SSLMonitor extends Monitor { + protected $proto = 'ssl'; +} + +class ICMPMonitor extends Monitor { + protected $proto = 'icmp'; +} + +class HTTPMonitor extends Monitor { + protected $proto = 'http'; + function __construct($config) { + parent::__construct($config); + } + public function p() { + $method = ($this->code() != "") ? $this->code() : $this->digest(); + return "check {$this->proto} {$this->path()} {$this->host()} {$method}"; + } + + private function path() { + return $this->config('path') != "" ? "'{$this->config('path')}'" : ""; + } + + private function host() { + return $this->config('host') != "" ? "host {$this->config('host')}" : ""; + } + + private function code() { + return $this->config('code') != "" ? "code {$this->config('code')}" : ""; + } + + private function digest() { + return $this->config('digest') != "" ? "digest {$this->config('digest')}" : ""; + } +} + +class HTTPSMonitor extends HTTPMonitor { + protected $proto = 'https'; +} + +class SendMonitor extends Monitor { + private $proto = 'send'; + function __construct($config) { + parent::__construct($config); + } + public function p() { + return "check {$this->proto} {$this->data()} expect {$this->pattern()} {$this->ssl()}"; + } + + + private function data() { + return $this->config('send') != "" ? "{$this->config('send')}" : ""; + } + + private function pattern() { + return $this->config('expect') != "" ? "{$this->config('expect')}" : ""; + } + + private function ssl() { + return $this->config('ssl') == true ? "ssl" : ""; + } +} + + + function relayd_configure() { global $config, $g; $vs_a = &$config['load_balancer']['virtual_server']; $pool_a = &$config['load_balancer']['lbpool']; + $check_a = array(); + + foreach ($config['load_balancer']['monitor_type'] as $type) { + switch($type['type']) { + case 'icmp': { + $mon = new ICMPMonitor($type['options']); + break; + } + case 'tcp': { + $mon = new TCPMonitor($type['options']); + break; + } + case 'http': { + $mon = new HTTPMonitor($type['options']); + break; + } + case 'https': { + $mon = new HTTPSMonitor($type['options']); + break; + } + case 'send': { + $mon = new SendMonitor($type['options']); + break; + } + } + $check_a[$type['name']] = $mon->p(); + } + + $fd = fopen("{$g['varetc_path']}/relayd.conf", "w"); /* reindex pools by name as we loop through the pools array */ @@ -46,10 +162,6 @@ function relayd_configure() { /* Virtual server pools */ if(is_array($pool_a)) { for ($i = 0; isset($pool_a[$i]); $i++) { - /* Don't deal with gateway pools - XXX remove me after gateways are converted */ - if ($pool_a[$i]['type'] == "gateway") - continue; - if(is_array($pool_a[$i]['servers'])) { $srvtxt = implode(", ", $pool_a[$i]['servers']); $conf .= "table <{$pool_a[$i]['name']}> { $srvtxt }\n"; @@ -59,14 +171,15 @@ function relayd_configure() { } } +print_r($check_a); 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 tcp timeout 1000\n"; - /* XXX - this needs to use the backup pool aka sitedown - but that isn't converted yet */ + $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 tcp timeout 1000\n"; + $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"; } } diff --git a/etc/inc/xmlparse.inc b/etc/inc/xmlparse.inc index f21050d..93a6c0b 100644 --- a/etc/inc/xmlparse.inc +++ b/etc/inc/xmlparse.inc @@ -34,7 +34,7 @@ function listtags() { $ret = explode(" ", "element alias aliasurl allowedip cacert config columnitem disk dnsserver domainoverrides " . "earlyshellcmd encryption-algorithm-option field fieldname hash-algorithm-option " . - "hosts group member interface_array item key lbpool menu mobilekey mount onetoone option ppp package passthrumac phase1 phase2 priv proxyarpnet " . + "hosts group member 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 bridge lagg"); return $ret; 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 @@ +<?php +/* $Id$ */ +/* + 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. +*/ + +/* 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 "<!-- begin content table -->\n"; + echo "<table class=\"tabcont\" width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n"; + echo " <!-- begin content table header -->\n"; + echo $this->display_header(); + echo " <!-- end content table header -->\n"; + echo " <!-- begin content table rows -->\n"; + echo $this->display_rows(); + echo " <!-- end content table rows -->\n"; + echo " <!-- begin content table footer -->\n"; + echo $this->display_footer(); + echo " <!-- end content table footer -->\n"; + echo "</table>\n"; + echo "<!-- end content table -->\n"; + } + + private function display_header() { + global $g; + echo "<tr>\n"; + for ($col = 0; $col < $this->columns - 1; $col++) { + echo " <td width=\"{$this->width[$col]}%\" class=\"listhdrr\">{$this->headers[$col]}</td>\n"; + } + echo " <td width=\"{$this->width[$this->columns - 1]}%\" class=\"listhdr\">{$this->headers[$this->columns - 1]}</td>\n"; + echo " <td width=\"10%\" class=\"list\">\n"; + echo " <table border=\"0\" cellspacing=\"0\" cellpadding=\"1\">\n"; + echo " <tr>\n"; + echo " <td width=\"17\"></td>\n"; + echo " <td valign=\"middle\"><a href=\"{$this->edit_uri}\"><img src=\"/themes/{$g['theme']}/images/icons/icon_plus.gif\" width=\"17\" height=\"17\" border=\"0\"></a></td>\n"; + echo " </tr>\n"; + echo " </table>\n"; + echo " </td>\n"; + echo "</tr>\n"; + + } + private function display_rows() { + global $g; + $cur_row = 0; + foreach ($this->content as $row) { + echo "<tr>\n"; + for ($col = 0; $col < $this->columns - 1; $col++) { + if ($col == 0) { + $cl = 'listlr'; + } else { + $cl = 'listr'; + } + echo " <td class=\"{$cl}\" onClick=\"fr_toggle({$cur_row})\" id=\"frd{$cur_row}\" ondblclick=\"document.location=\'{$this->edit_uri}?id={$cur_row}\'\">\n"; + if (is_array($row[$this->cname[$col]])) { + foreach ($row[$this->cname[$col]] as $data) { + echo " {$data}<br/>\n"; + } + } else { + echo " " . $row[$this->cname[$col]] . "\n"; + } + echo " </td>\n"; + } + echo " <td class=\"listbg\" onClick=\"fr_toggle({$cur_row})\" id=\"frd{$cur_row}\" ondblclick=\"document.location=\'{$this->edit_uri}?id={$cur_row}\'\">\n"; + echo " <font color=\"#FFFFFF\">{$row[$this->cname[$this->columns - 1]]}</font>\n"; + echo " </td>\n"; + echo " <td class=\"list\" nowrap>\n"; + $this->display_buttons($cur_row); + echo " </td>\n"; + echo "</tr>\n"; + + $cur_row++; + } + } + private function display_footer() { + global $g; + echo "<tr>\n"; + echo " <td class=\"list\" colspan=\"{$this->columns}\"></td>\n"; + echo " <td class=\"list\">\n"; + echo " <table border=\"0\" cellspacing=\"0\" cellpadding=\"1\">\n"; + echo " <tr>\n"; + echo " <td width=\"17\"></td>\n"; + echo " <td valign=\"middle\"><a href=\"{$this->edit_uri}\"><img src=\"/themes/{$g['theme']}/images/icons/icon_plus.gif\" width=\"17\" height=\"17\" border=\"0\"></a></td>\n"; + echo " </tr>\n"; + echo " </table>\n"; + echo " </td>\n"; + echo "</tr>\n"; + } + private function display_buttons($row) { + echo " <table border=\"0\" cellspacing=\"0\" cellpadding=\"1\">\n"; + echo " <tr>\n"; + if ($this->buttons['move']) + echo $this->display_button('move', $row); + if ($this->buttons['edit']) + echo $this->display_button('edit', $row); + echo " <tr>\n"; + if ($this->buttons['del']) + echo $this->display_button('del', $row); + if ($this->buttons['dup']) + echo $this->display_button('dup', $row); + echo " </tr>\n"; + echo " </table>\n"; + } + private function display_button($button, $row) { + global $g; + echo "<td valign=\"middle\">"; + switch ($button) { + case "move": { + echo "<input name=\"move_{$row}\" type=\"image\" src=\"./themes/{$g['theme']}/images/icons/icon_left.gif\" width=\"17\" height=\"17\" title=\"Move selected entries before this entry\" onMouseOver=\"fr_insline({$row}, true)\" onMouseOut=\"fr_insline({$row}, false)\">"; + break; + } + case "edit": { + echo "<a href=\"{$this->edit_uri}?id={$row}\"><img src=\"/themes/{$g['theme']}/images/icons/icon_e.gif\" width=\"17\" height=\"17\" border=\"0\" title=\"Edit entry\"></a>"; + break; + } + case "del": { + echo "<a href=\"{$this->my_uri}?act=del&id={$row}\" onclick=\"return confirm(\'Do you really want to delete this entry?\')\"><img src=\"/themes/{$g['theme']}/images/icons/icon_x.gif\" width=\"17\" height=\"17\" border=\"0\" title=\"Delete entry\"></a>"; + break; + } + case "dup": { + echo "<a href=\"{$this->edit_uri}?act=dup&id={$row}\"><img src=\"/themes/{$g['theme']}/images/icons/icon_plus.gif\" width=\"17\" height=\"17\" border=\"0\" title=\"Duplicate entry\"></a>"; + break; + } + } + echo "</td>"; + } + +} +?> 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 "<select id=\"{$tag}\" name=\"{$tag}\">\n"; + foreach($rfc2616 as $code => $message) { + if ($code == $current) { + $sel = " selected"; + } else { + $sel = ""; + } + echo "<option value=\"{$code}\"{$sel}>{$message}</option>\n"; + } +} + +?> diff --git a/usr/local/www/load_balancer_monitor.php b/usr/local/www/load_balancer_monitor.php new file mode 100755 index 0000000..3a37c04 --- /dev/null +++ b/usr/local/www/load_balancer_monitor.php @@ -0,0 +1,130 @@ +<?php +/* $Id$ */ +/* + load_balancer_monitor.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-monitor +##|*NAME=Services: Load Balancer: Monitors page +##|*DESCR=Allow access to the 'Services: Load Balancer: Monitors' page. +##|*MATCH=load_balancer_monitor.php* +##|-PRIV + +require("guiconfig.inc"); + +if (!is_array($config['load_balancer']['monitor_type'])) { + $config['load_balancer']['monitor_type'] = array(); +} +$a_monitor = &$config['load_balancer']['monitor_type']; + +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_monitor[$_GET['id']]) { + /* make sure no pools reference this entry */ + if (is_array($config['load_balancer']['lbpool'])) { + foreach ($config['load_balancer']['pool'] as $pool) { + if ($pool['monitor'] == $a_monitor[$_GET['id']]['name']) { + $input_errors[] = "This entry cannot be deleted because it is still referenced by at least one pool."; + break; + } + } + } + + if (!$input_errors) { + unset($a_monitor[$_GET['id']]); + write_config(); + touch($d_vsconfdirty_path); + header("Location: load_balancer_monitor.php"); + exit; + } + } +} + +$pgtitle = array("Load Balancer","Monitor"); +include("head.inc"); + +?> +<body link="#0000CC" vlink="#0000CC" alink="#0000CC"> +<?php include("fbegin.inc"); ?> +<form action="load_balancer_monitor.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", true, "load_balancer_monitor.php"); + display_top_tabs($tab_array); + ?> + </td></tr> + <tr> + <td> + <div id="mainarea"> +<? + $t = new MainTable(); + $t->edit_uri('load_balancer_monitor_edit.php'); + $t->my_uri('load_balancer_monitor.php'); + $t->add_column('Name','name',20); + $t->add_column('Type','type',10); + $t->add_column('Description','desc',30); + $t->add_button('edit'); + $t->add_button('dup'); + $t->add_button('del'); + $t->add_content_array($a_monitor); + $t->display(); +?> + </div> + </td> + </tr> +</table> +</form> +<?php include("fend.inc"); ?> +</body> +</html> diff --git a/usr/local/www/load_balancer_monitor_edit.php b/usr/local/www/load_balancer_monitor_edit.php new file mode 100755 index 0000000..88c022c --- /dev/null +++ b/usr/local/www/load_balancer_monitor_edit.php @@ -0,0 +1,361 @@ +<?php +/* $Id$ */ +/* + load_balancer_monitor_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-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* +##|-PRIV + +require("guiconfig.inc"); +if (!is_array($config['load_balancer']['monitor_type'])) { + $config['load_balancer']['monitor_type'] = array(); +} +$a_monitor = &$config['load_balancer']['monitor_type']; + +if (isset($_POST['id'])) + $id = $_POST['id']; +else + $id = $_GET['id']; + +if (isset($id) && $a_monitor[$id]) { + $pconfig['name'] = $a_monitor[$id]['name']; + $pconfig['type'] = $a_monitor[$id]['type']; + $pconfig['desc'] = $a_monitor[$id]['desc']; + $pconfig['options'] = array(); + $pconfig['options'] = $a_monitor[$id]['options']; +} else { + /* Some sane page defaults */ + $pconfig['options']['path'] = '/'; + $pconfig['options']['code'] = 200; +} + +$changedesc = "Load Balancer: Monitor: "; +$changecount = 0; + +if ($_POST) { + $changecount++; + + unset($input_errors); + $pconfig = $_POST; + + /* turn $_POST['http_options_*'] into $pconfig['options'][*] */ + foreach($_POST as $key => $val) { + if (stristr($key, 'options') !== false) { + if (stristr($key, $pconfig['type'].'_') !== false) { + $opt = explode('_',$key); + $pconfig['options'][$opt[2]] = $val; + } + unset($pconfig[$key]); + } + } + + /* 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']['monitor_type'][$i]); $i++) + if (($_POST['name'] == $config['load_balancer']['monitor_type'][$i]['name']) && ($i != $id)) + $input_errors[] = "This monitor name has already been used. Monitor names must be unique."; + + switch($_POST['type']) { + case 'icmp': { + break; + } + case 'tcp': { + break; + } + case 'http': + case 'https': { + if (is_array($pconfig['options'])) { + if (isset($pconfig['options']['host']) && $pconfig['options']['host'] != "") { + if (!is_hostname($pconfig['options']['host'])) { + $input_errors[] = "Invalid hostname."; + } + } + if (isset($pconfig['options']['code']) && $pconfig['options']['code'] != "") { + // Check code + if(!is_rfc2616_code($pconfig['options']['code'])) { + $input_errors[] = "HTTP(s) codes must be from RFC2616."; + } + } + if (!isset($pconfig['options']['path']) || $pconfig['options']['path'] == "") { + $input_errors[] = "The path to monitor must be set."; + } + } + break; + } + case 'send': { + if (is_array($pconfig['options'])) { + if (isset($pconfig['options']['send']) && $pconfig['options']['send'] != "") { + // Check send + } + if (isset($pconfig['options']['expect']) && $pconfig['options']['expect'] != "") { + // Check expect + } + } + break; + } + } + + if (!$input_errors) { + $monent = array(); + if(isset($id) && $a_monitor[$id]) + $monent = $a_monitor[$id]; + if($monent['name'] != "") + $changedesc .= " modified '{$monent['name']}' monitor:"; + + update_if_changed("name", $monent['name'], $pconfig['name']); + update_if_changed("type", $monent['type'], $pconfig['type']); + update_if_changed("description", $monent['desc'], $pconfig['desc']); + if($pconfig['type'] == "http" || $pconfig['type'] == "https" ) { + /* log updates, then clear array and reassign - dumb, but easiest way to have a clear array */ + update_if_changed("path", $monent['options']['path'], $pconfig['options']['path']); + update_if_changed("host", $monent['options']['host'], $pconfig['options']['host']); + update_if_changed("code", $monent['options']['code'], $pconfig['options']['code']); + $monent['options'] = array(); + $monent['options']['path'] = $pconfig['options']['path']; + $monent['options']['host'] = $pconfig['options']['host']; + $monent['options']['code'] = $pconfig['options']['code']; + } + if($pconfig['type'] == "send" ) { + /* log updates, then clear array and reassign - dumb, but easiest way to have a clear array */ + update_if_changed("send", $monent['options']['send'], $pconfig['options']['send']); + update_if_changed("expect", $monent['options']['expect'], $pconfig['options']['expect']); + $monent['options'] = array(); + $monent['options']['send'] = $pconfig['options']['send']; + $monent['options']['expect'] = $pconfig['options']['expect']; + } + if($pconfig['type'] == "tcp" || $pconfig['type'] == "icmp") { + $monent['options'] = array(); + } + + if (isset($id) && $a_monitor[$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; + + if ($changecount > 0) { + /* Mark config dirty */ + conf_mount_rw(); + touch($d_vsconfdirty_path); + write_config($changedesc); + } + + header("Location: load_balancer_monitor.php"); + exit; + } +} + +$pgtitle = array("Load Balancer","Monitor","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("icmp" => "ICMP", "tcp" => "TCP", "http" => "HTTP", "https" => "HTTPS", "send" => "Send/Expect"); +?> + +<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(); +} +</script> + +<?php include("fbegin.inc"); ?> +<?php if ($input_errors) print_input_errors($input_errors); ?> + + <form action="load_balancer_monitor_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="icmp"<?= $pconfig['type'] == "icmp" ? "" : " style=\"display:none;\""?>> + </tr> + <tr align="left" id="tcp"<?= $pconfig['type'] == "tcp" ? "" : " style=\"display:none;\""?>> + </tr> + <tr align="left" id="http"<?= $pconfig['type'] == "http" ? "" : " style=\"display:none;\""?>> + <td width="22%" valign="top" class="vncellreq">HTTP</td> + <td width="78%" class="vtable" colspan="2"> + <table width="100%" border="0" cellpadding="6" cellspacing="0"> + <tr align="left"> + <td width="22%" valign="top" class="vncellreq">Path</td> + <td width="78%" class="vtable" colspan="2"> + <input name="http_options_path" type="text" <?if(isset($pconfig['options']['path'])) echo "value=\"{$pconfig['options']['path']}\"";?>size="64"> + </td> + </tr> + <tr align="left"> + <td width="22%" valign="top" class="vncell">Host</td> + <td width="78%" class="vtable" colspan="2"> + <input name="http_options_host" type="text" <?if(isset($pconfig['options']['host'])) echo "value=\"{$pconfig['options']['host']}\"";?>size="64"><br/>Hostname for Host: header if needed. + </td> + </td> + <tr align="left"> + <td width="22%" valign="top" class="vncellreq">HTTP Code</td> + <td width="78%" class="vtable" colspan="2"> + <?= print_rfc2616_select("http_options_code", $pconfig['options']['code']); ?> + </td> + </tr> +<!-- BILLM: XXX not supported digest checking just yet + <tr align="left"> + <td width="22%" valign="top" class="vncell">MD5 Page Digest</td> + <td width="78%" class="vtable" colspan="2"> + <input name="digest" type="text" <?if(isset($pconfig['digest'])) echo "value=\"{$pconfig['digest']}\"";?>size="32"><br /><b>TODO: add fetch functionality here</b> + </td> + </tr> +--> + </table> + </td> + </tr> + <tr align="left" id="https"<?= $pconfig['type'] == "https" ? "" : " style=\"display:none;\""?>> + <td width="22%" valign="top" class="vncellreq">HTTPS</td> + <td width="78%" class="vtable" colspan="2"> + <table width="100%" border="0" cellpadding="6" cellspacing="0"> + <tr align="left"> + <td width="22%" valign="top" class="vncellreq">Path</td> + <td width="78%" class="vtable" colspan="2"> + <input name="https_options_path" type="text" <?if(isset($pconfig['options']['path'])) echo "value=\"{$pconfig['options']['path']}\"";?>size="64"> + </td> + </tr> + <tr align="left"> + <td width="22%" valign="top" class="vncellreq">Host</td> + <td width="78%" class="vtable" colspan="2"> + <input name="https_options_host" type="text" <?if(isset($pconfig['options']['host'])) echo "value=\"{$pconfig['options']['host']}\"";?>size="64"><br/>Hostname for Host: header if needed. + </td> + </td> + <tr align="left"> + <td width="22%" valign="top" class="vncellreq">HTTP Code</td> + <td width="78%" class="vtable" colspan="2"> + <?= print_rfc2616_select("https_options_code", $pconfig['options']['code']); ?> + </td> + </tr> +<!-- BILLM: XXX not supported digest checking just yet + + <tr align="left"> + <td width="22%" valign="top" class="vncellreq">MD5 Page Digest</td> + <td width="78%" class="vtable" colspan="2"> + <input name="digest" type="text" <?if(isset($pconfig['digest'])) echo "value=\"{$pconfig['digest']}\"";?>size="32"><br /><b>TODO: add fetch functionality here</b> + </td> + </tr> +--> + </table> + </td> + </tr> + <tr align="left" id="send"<?= $pconfig['type'] == "send" ? "" : " style=\"display:none;\""?>> + <td width="22%" valign="top" class="vncellreq">Send/Expect</td> + <td width="78%" class="vtable" colspan="2"> + <table width="100%" border="0" cellpadding="6" cellspacing="0"> + <tr align="left"> + <td width="22%" valign="top" class="vncellreq">Send string</td> + <td width="78%" class="vtable" colspan="2"> + <input name="send_options_send" type="text" <?if(isset($pconfig['options']['send'])) echo "value=\"{$pconfig['options']['send']}\"";?>size="64"> + </td> + </tr> + <tr align="left"> + <td width="22%" valign="top" class="vncellreq">Expect string</td> + <td width="78%" class="vtable" colspan="2"> + <input name="send_options_expect" type="text" <?if(isset($pconfig['options']['expect'])) echo "value=\"{$pconfig['options']['expect']}\"";?>size="64"> + </td> + </tr> + </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"> </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_monitor[$id]): ?> + <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_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 <bill.marquette@gmail.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 @@ -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 href=\"/load_balancer_monitor_edit.php?id={$mondex[$a_pool[$i]['monitor']]}\">{$a_pool[$i]['monitor']}</a>"; +} + $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); ?> </td></tr> <tr> <td> <div id="mainarea"> - <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0"> - <tr> - <td width="10%" class="listhdrr">Name</td> - <td width="10%" class="listhdrr">Type</td> - <td width="15%" class="listhdrr">Servers/Gateways</td> - <td width="10%" class="listhdrr">Port</td> - <td width="15%" class="listhdrr">Monitor</td> - <td width="30%" class="listhdr">Description</td> - <td width="10%" class="list"> - <table border="0" cellspacing="0" cellpadding="1"> - <tr> - <td width="17"></td> - <td valign="middle"><a href="load_balancer_pool_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td> - </tr> - </table> - </td> - </tr> - <?php $i = 0; foreach ($a_pool as $vipent): ?> - <tr> - <td class="listlr" ondblclick="document.location='load_balancer_pool_edit.php?id=<?=$i;?>';"> - <?=$vipent['name'];?> - </td> - <td class="listr" align="center" ondblclick="document.location='load_balancer_pool_edit.php?id=<?=$i;?>';"> - <?=$vipent['type'];?> - <br /> - (<?=$vipent['behaviour'];?>) - </td> - <td class="listr" align="center" ondblclick="document.location='load_balancer_pool_edit.php?id=<?=$i;?>';"> - <?php - foreach ((array) $vipent['servers'] as $server) { - $svr = split("\|", $server); - echo "{$svr[0]}<br />"; - } - ?> - </td> - <td class="listr" ondblclick="document.location='load_balancer_pool_edit.php?id=<?=$i;?>';"> - <?=$vipent['port'];?> - </td> - <td class="listr" ondblclick="document.location='load_balancer_pool_edit.php?id=<?=$i;?>';"> - <?php - echo $vipent['monitor']; - ?> - </td> - <td class="listbg" ondblclick="document.location='load_balancer_pool_edit.php?id=<?=$i;?>';"> - <font color="#FFFFFF"><?=$vipent['desc'];?></font> - </td> - <td class="list" nowrap> - <table border="0" cellspacing="0" cellpadding="1"> - <tr> - <td valign="middle"><a href="load_balancer_pool_edit.php?id=<?=$i;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td> - <td valign="middle"><a href="load_balancer_pool.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this entry?')"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td> - </tr> - </table> - </td> - </tr> - <?php $i++; endforeach; ?> - <tr> - <td class="list" colspan="6"></td> - <td class="list"> - <table border="0" cellspacing="0" cellpadding="1"> - <tr> - <td width="17"></td> - <td valign="middle"><a href="load_balancer_pool_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td> - </tr> - </table> - </td> - </tr> - </table> - </div> - </table> - </form> +<? + $t = new MainTable(); + $t->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(); +?> + + </div> + </td> + </tr> +</table> +</form> <?php include("fend.inc"); ?> </body> </html> 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 <bill.marquette@gmail.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 @@ -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(){ </tr> <tr align="left"> - <td width="22%" valign="top" class="vncellreq"><?=gettext("Behavior");?></td> - <td width="78%" class="vtable" colspan="2"> - <input type="radio" name="behaviour" id="behaviour" value="balance"<?php if($pconfig['behaviour'] == -"balance") echo " CHECKED"; ?>><?=gettext("Load Balancing");?><br> - <input type="radio" name="behaviour" id="behaviour" value="failover"<?php if($pconfig['behaviour'] == -"failover") echo " CHECKED"; ?>><?=gettext("Failover");?><br> - Load Balancing: both active. Failover order: top -> down. - </td> - </tr> - - <tr align="left"> <td width="22%" valign="top" id="monitorport_text" class="vncellreq">Port</td> <td width="78%" class="vtable" colspan="2"> <input name="port" type="text" <?if(isset($pconfig['port'])) echo "value=\"{$pconfig['port']}\"";?> size="16" maxlength="16"><br> @@ -202,26 +181,24 @@ function clearcombo(){ <td width="22%" valign="top" class="vncellreq">Monitor</td> <td width="78%" class="vtable" colspan="2"> <select id="monitor" name="monitor"> - <option value="TCP"<?php if($pconfig['monitor'] == "TCP") echo " SELECTED"; ?>>TCP</option> - <option value="ICMP"<?php if($pconfig['monitor'] == "ICMP") echo " SELECTED"; ?>>ICMP</option> - <!-- billm - XXX: add HTTP/HTTPS here --> + <? + foreach ($config['load_balancer']['monitor_type'] as $monitor) { + if ($monitor['name'] == $pconfig['monitor']) { + $selected=" selected"; + } else { + $selected = ""; + } + echo "<option value=\"{$monitor['name']}\"{$selected}>{$monitor['name']}</option>"; + } + ?> </select> </td> </tr> <tr align="left"> - <td width="22%" valign="top" id="monitorip_text" class="vncell">Monitor IP</td> - <td width="78%" class="vtable" colspan="2"> - <div style="float: none;"> - <input size="16" id="monitorip" name="monitorip" value="<?php echo $pconfig['monitorip']; ?>" style="float: left;"> - </div> - </td> - </tr> - <tr align="left"> - <td width="22%" valign="top" class="vncellreq"><div id="interfacename_text"></div></td> + <td width="22%" valign="top" class="vncellreq"></td> <td width="78%" class="vtable" colspan="2"> <input name="ipaddr" type="text" size="16" style="float: left;"> <input class="formbtn" type="button" name="button1" value="Add to pool" onclick="AddServerToPool(document.iform);"><br> - <div id="interfacename_desc"></div> </td> </tr> <tr> @@ -266,10 +243,6 @@ echo "</select>"; <br/> <input class="formbtn" type="button" name="removeEnabled" value="Remove" onclick="RemoveServerFromPool(document.iform, 'servers[]');" /> </td> - <td valign="top"> - <input class="formbtn" type="button" name="moveUp" value="Move up" onclick="up(document.iform.serversSelect);" /><br/> - <input class="formbtn" type="button" name="moveDown" value="Move down" onclick="down(document.iform.serversSelect);" /> - </td> </tr> </tbody> </table> @@ -278,7 +251,7 @@ echo "</select>"; <tr align="left"> <td width="22%" valign="top"> </td> <td width="78%"> - <input name="Submit" type="submit" class="formbtn" value="Save" onClick="AllServers('serversSelect', true); AllServers('serversDisabledSelect', true);"> + <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]): ?> <input name="id" type="hidden" value="<?=$id;?>"> <?php endif; ?> 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 <bill.marquette@gmail.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 @@ -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 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("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); ?> </td></tr> <tr> <td> <div id="mainarea"> - <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0"> - <tr> - <td width="10%" class="listhdrr">Name</td> - <td width="20%" class="listhdrr">Server address</td> - <td width="10%" class="listhdrr">Port</td> - <td width="20%" class="listhdrr">Pool</td> - <td width="30%" class="listhdr">Description</td> - <td width="10%" class="list"> - <table border="0" cellspacing="0" cellpadding="1"> - <tr> - <td width="17"></td> - <td valign="middle"><a href="load_balancer_virtual_server_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td> - </tr> - </table> - </td> - </tr> - <?php $i = 0; foreach ($a_vs as $vsent): ?> - <tr> - <td class="listlr" ondblclick="document.location='load_balancer_virtual_server_edit.php?id=<?=$i;?>';"> - <?=$vsent['name'];?> - </td> - <td class="listr" ondblclick="document.location='load_balancer_virtual_server_edit.php?id=<?=$i;?>';"> - <?=$vsent['ipaddr'];?> - </td> - <td class="listr" ondblclick="document.location='load_balancer_virtual_server_edit.php?id=<?=$i;?>';"> - <?=$vsent['port'];?> - <td class="listr" align="center" ondblclick="document.location='load_balancer_virtual_server_edit.php?id=<?=$i;?>';"> - <?=$vsent['pool'];?> - </td> - <td class="listbg" ondblclick="document.location='load_balancer_virtual_server_edit.php?id=<?=$i;?>';"> - <font color="#FFFFFF"><?=htmlspecialchars($vsent['desc']);?> - </td> - <td class="list" nowrap> - <table border="0" cellspacing="0" cellpadding="1"> - <tr> - <td valign="middle"><a href="load_balancer_virtual_server_edit.php?id=<?=$i;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td> - <td valign="middle"><a href="load_balancer_virtual_server.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this entry?')"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td> - </tr> - </table> - </td> - </tr> - <?php $i++; endforeach; ?> - <tr> - <td class="list" colspan="5"></td> - <td class="list"> - <table border="0" cellspacing="0" cellpadding="1"> - <tr> - <td width="17"></td> - <td valign="middle"><a href="load_balancer_virtual_server_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td> - </tr> - </table> - </td> - </tr> - </table> +<? + $t = new MainTable(); + $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('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(); +?> </div> - </table> - </form> + </td> + </tr> +</table> +</form> <?php include("fend.inc"); ?> </body> </html> 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 <bill.marquette@gmail.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 @@ -158,30 +158,26 @@ include("head.inc"); <select id="pool" name="pool"> <?php for ($i = 0; isset($config['load_balancer']['lbpool'][$i]); $i++) { - if ($config['load_balancer']['lbpool'][$i]['type'] == "server") { - $selected = ""; - if ( $config['load_balancer']['lbpool'][$i]['name'] == $pconfig['pool'] ) - $selected = " SELECTED"; - echo "<option value=\"{$config['load_balancer']['lbpool'][$i]['name']}\"{$selected}>{$config['load_balancer']['lbpool'][$i]['name']}</option>"; - } + $selected = ""; + if ( $config['load_balancer']['lbpool'][$i]['name'] == $pconfig['pool'] ) + $selected = " SELECTED"; + echo "<option value=\"{$config['load_balancer']['lbpool'][$i]['name']}\"{$selected}>{$config['load_balancer']['lbpool'][$i]['name']}</option>"; } ?> </select> </td> </tr> <tr align="left"> - <td width="22%" valign="top" class="vncellreq">Pool Down Server</td> + <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> <?php for ($i = 0; isset($config['load_balancer']['lbpool'][$i]); $i++) { - if ($config['load_balancer']['lbpool'][$i]['type'] == "server") { - $selected = ""; - if ( $config['load_balancer']['lbpool'][$i]['name'] == $pconfig['sitedown'] ) - $selected = " SELECTED"; - echo "<option value=\"{$config['load_balancer']['lbpool'][$i]['name']}\"{$selected}>{$config['load_balancer']['lbpool'][$i]['name']}</option>"; - } + $selected = ""; + if ( $config['load_balancer']['lbpool'][$i]['name'] == $pconfig['sitedown'] ) + $selected = " SELECTED"; + echo "<option value=\"{$config['load_balancer']['lbpool'][$i]['name']}\"{$selected}>{$config['load_balancer']['lbpool'][$i]['name']}</option>"; } ?> </select> @@ -190,7 +186,7 @@ include("head.inc"); </tr> <tr align="left"> <td align="left" valign="bottom"> - <input name="Submit" type="submit" class="formbtn" value="Submit"> + <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]): ?> <input name="id" type="hidden" value="<?=$id;?>"> <?php endif; ?> 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 <bill.marquette@gmail.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 @@ -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); } |