From c79cec7933f3a3906ef8903ca5ddcf28be30d1f2 Mon Sep 17 00:00:00 2001 From: PiBa-NL Date: Sun, 1 Nov 2015 02:30:39 +0100 Subject: haproxy-devel, user gui permissions, show backend usage, use-server action --- config/haproxy-devel/haproxy.priv.inc | 50 ++++++++++++++++++ config/haproxy-devel/haproxy.xml | 4 ++ config/haproxy-devel/pkg/haproxy.inc | 8 ++- config/haproxy-devel/pkg/haproxy_htmllist.inc | 16 +++--- config/haproxy-devel/www/haproxy_listeners.php | 60 ++++++++++------------ .../haproxy-devel/www/haproxy_listeners_edit.php | 4 +- 6 files changed, 98 insertions(+), 44 deletions(-) create mode 100644 config/haproxy-devel/haproxy.priv.inc diff --git a/config/haproxy-devel/haproxy.priv.inc b/config/haproxy-devel/haproxy.priv.inc new file mode 100644 index 00000000..e4914db8 --- /dev/null +++ b/config/haproxy-devel/haproxy.priv.inc @@ -0,0 +1,50 @@ + \ No newline at end of file diff --git a/config/haproxy-devel/haproxy.xml b/config/haproxy-devel/haproxy.xml index ddafe45d..784e0034 100644 --- a/config/haproxy-devel/haproxy.xml +++ b/config/haproxy-devel/haproxy.xml @@ -146,6 +146,10 @@ /usr/local/www/javascript/ https://packages.pfsense.org/packages/config/haproxy-devel/www/javascript/haproxy_geturl.js + + /etc/inc/priv/ + https://packages.pfsense.org/packages/config/haproxy-devel/haproxy.priv.inc + haproxy_custom_php_install_command(); diff --git a/config/haproxy-devel/pkg/haproxy.inc b/config/haproxy-devel/pkg/haproxy.inc index ba36c089..d9f8242e 100644 --- a/config/haproxy-devel/pkg/haproxy.inc +++ b/config/haproxy-devel/pkg/haproxy.inc @@ -241,10 +241,14 @@ $a_filestype['writetodisk'] = array('name' => "Write to disk"); global $a_action; $a_action = array(); // -$a_action["use_backend"] = array('name' => "Use Backend", 'mode' => '', 'syntax' => 'use_backend {backend}', +$a_action["use_backend"] = array('name' => "Use Backend", 'mode' => '', 'syntax' => 'use_backend {backend}', 'usage' => 'frontend', 'fields' => array( 'backend' => array('name'=>"backend",'columnheader'=>"Backend",'type'=>"select",'size'=>"50",'mask'=>'backend') )); +$a_action["use_server"] = array('name' => "Use Server", 'mode' => '', 'syntax' => 'use-server {server}', 'usage' => 'backend', + 'fields' => array( + 'server' => array('name'=>"server",'columnheader'=>"Server",'type'=>"select",'size'=>"50",'mask'=>'server') + )); // $a_action["custom"] = array('name' => "Custom", 'mode' => '', 'fields' => array( @@ -356,7 +360,7 @@ $a_action["tcp-response_content_accept"] = array('name' => "tcp-response content $a_action["tcp-response_content_close"] = array('name' => "tcp-response content close", 'mode'=> '', 'syntax' => 'tcp-response content close'); $a_action["tcp-response_content_reject"] = array('name' => "tcp-response content reject", 'mode'=> '', 'syntax' => 'tcp-response content reject'); if (haproxy_version() >= '1.6') { - $a_action["tcp-response_content_lua"] = array('name' => "tcp-response content lua script", 'mode'=> '', 'syntax' => 'tcp-response content lua.{lua-function}', + $a_action["tcp-response_content_lua"] = array('name' => "tcp-response content lua script", 'mode'=> '', 'syntax' => 'tcp-response content lua.{lua-function}', 'usage' => 'backend', 'fields' => array( 'lua-function' => array('name'=>"lua-function",'columnheader'=>"lua function",'type'=>"textbox",'size'=>"50",'mask'=>'lua-function') )); diff --git a/config/haproxy-devel/pkg/haproxy_htmllist.inc b/config/haproxy-devel/pkg/haproxy_htmllist.inc index 4abfedd8..4e8ce428 100644 --- a/config/haproxy-devel/pkg/haproxy_htmllist.inc +++ b/config/haproxy-devel/pkg/haproxy_htmllist.inc @@ -88,20 +88,21 @@ class HaproxyHtmlList } if ($add_item) { if ($this->keyfield != "") { - if (isset($_POST[$this->tablename."_key".$x])) + if (isset($_POST[$this->tablename."_key".$x])) { $key = $_POST[$this->tablename."_key".$x]; - else { + } else { $key = $_POST[$this->tablename.$this->keyfield.$x]; - } + } } else { $key = ""; } $index = $_POST[$this->tablename."_rowindex".$x]; $value['_index'] = $index; - if (isset($values[$key])) + if (isset($values[$key])) { $values[] = $value; - else + } else { $values[$key] = $value; + } } } usort($values, 'sort_index'); @@ -195,13 +196,12 @@ class HaproxyHtmlList - "; - if (empty($this->keyfield)) { + if (empty($this->noindex)) { echo " @@ -237,7 +237,7 @@ class HaproxyHtmlList "; - if (empty($this->keyfield)) { + if (empty($this->noindex)) { echo " diff --git a/config/haproxy-devel/www/haproxy_listeners.php b/config/haproxy-devel/www/haproxy_listeners.php index 5aef0a82..c7288e7d 100644 --- a/config/haproxy-devel/www/haproxy_listeners.php +++ b/config/haproxy-devel/www/haproxy_listeners.php @@ -93,6 +93,28 @@ if ($_GET['act'] == "del") { } } +function haproxy_userlist_backend_servers($backendname) { + //used for hint title text when hovering mouse over a backend name + global $a_servermodes; + $backend_servers = ""; + $backend = get_backend($backendname); + if ($backend && is_array($backend['ha_servers']) && is_array($backend['ha_servers']['item'])){ + $servers = $backend['ha_servers']['item']; + $backend_servers = sprintf(gettext("Servers in \"%s\" pool:"), $backendname); + if (is_array($servers)){ + foreach($servers as $server){ + $srvstatus = $server['status']; + $status = $a_servermodes[$srvstatus]['sign']; + if (isset($server['forwardto']) && $server['forwardto'] != "") + $backend_servers .= "\n{$status}[{$server['forwardto']}]"; + else + $backend_servers .= "\n{$status}{$server['address']}:{$server['port']}"; + } + } + } + return $backend_servers; +} + $pgtitle = "Services: HAProxy: Frontends"; include("head.inc"); haproxy_css(); @@ -238,24 +260,6 @@ function js_callback(req) { if ($frontend['advanced']) $isadvset .= "Advanced pass thru setting used\r\n"; if ($isadvset) echo ""; - - $backend_serverpool_hint = ""; - $backend_serverpool = $frontend['backend_serverpool']; - $backend = get_backend($backend_serverpool); - if ($backend && is_array($backend['ha_servers']) && is_array($backend['ha_servers']['item'])){ - $servers = $backend['ha_servers']['item']; - $backend_serverpool_hint = gettext("Servers in pool:"); - if (is_array($servers)){ - foreach($servers as $server){ - $srvstatus = $server['status']; - $status = $a_servermodes[$srvstatus]['sign']; - if (isset($server['forwardto']) && $server['forwardto'] != "") - $backend_serverpool_hint .= "\n{$status}[{$server['forwardto']}]"; - else - $backend_serverpool_hint .= "\n{$status}{$server['address']}:{$server['port']}"; - } - } - } ?> @@ -296,37 +300,29 @@ function js_callback(req) { ?> -
"; - } $backend = $actionitem['use_backendbackend']; + $hint = haproxy_userlist_backend_servers($backend); + echo "
"; echo "{$backend}"; - if (!empty($actionitem['acl'])) { echo " if({$actionitem['acl']})"; } + echo "
"; } } } + $hint = haproxy_userlist_backend_servers($frontend['backend_serverpool']); $backend = $frontend['backend_serverpool']; if (!empty($backend)) { - if ($first) { - $first = false; - } else { - echo "
"; - } + echo "
"; echo "{$backend} (default)"; + echo "
"; } ?> -
diff --git a/config/haproxy-devel/www/haproxy_listeners_edit.php b/config/haproxy-devel/www/haproxy_listeners_edit.php index 799cb3cd..9d2b0b05 100644 --- a/config/haproxy-devel/www/haproxy_listeners_edit.php +++ b/config/haproxy-devel/www/haproxy_listeners_edit.php @@ -253,11 +253,11 @@ $htmllist_extaddr->editmode = true; $htmllist_acls = new HaproxyHtmlList("table_acls", $fields_aclSelectionList); $htmllist_acls->fields_details = $fields_acl_details; -$htmllist_acls->editmode = true; +//$htmllist_acls->editmode = true; $htmllist_actions = new HaproxyHtmlList("table_actions", $fields_actions); $htmllist_actions->fields_details = $fields_actions_details; -$htmllist_actions->keyfield = "name"; +//$htmllist_actions->keyfield = "name"; //$htmllist_actions->editmode = true; $htmllist_sslCertificates = new HaproxyHtmlList("tbl_sslCerts", $fields_sslCertificates); -- cgit v1.2.3