summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-02-05 15:30:38 +0000
committersasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-02-05 15:30:38 +0000
commit5450c96c9fc01213b27cd834ae038494cc631232 (patch)
tree8882df2ad024337d62d87dd2a96bfd78da4eec99
parent77bdb06094a060ab2def03ce9973c5331e27e9da (diff)
downloadzabbix-5450c96c9fc01213b27cd834ae038494cc631232.tar.gz
zabbix-5450c96c9fc01213b27cd834ae038494cc631232.tar.xz
zabbix-5450c96c9fc01213b27cd834ae038494cc631232.zip
- [DEV-108] Configuration GUI
git-svn-id: svn://svn.zabbix.com/trunk@5322 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r--frontends/php/hosts.php193
-rw-r--r--frontends/php/include/audit.inc.php1
-rw-r--r--frontends/php/include/defines.inc.php1
-rw-r--r--frontends/php/include/forms.inc.php68
-rw-r--r--frontends/php/include/hosts.inc.php82
-rw-r--r--frontends/php/include/locales/en_gb.inc.php12
6 files changed, 354 insertions, 3 deletions
diff --git a/frontends/php/hosts.php b/frontends/php/hosts.php
index e1dca557..ad7553ed 100644
--- a/frontends/php/hosts.php
+++ b/frontends/php/hosts.php
@@ -56,13 +56,14 @@ include_once "include/page_header.php";
<?php
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
$fields=array(
- // 0 - hosts; 1 - groups; 2 - linkages; 3 - templates; 4 - applications
- "config"=> array(T_ZBX_INT, O_OPT, P_SYS, IN("0,1,2,3,4"), NULL),
+ // 0 - hosts; 1 - groups; 2 - linkages; 3 - templates; 4 - applications; 5 - Proxies
+ "config"=> array(T_ZBX_INT, O_OPT, P_SYS, IN("0,1,2,3,4,5"), NULL),
/* ARAYS */
"hosts"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL),
"groups"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL),
"applications"=>array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL),
+ "proxies"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL),
/* host */
"hostid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, '(isset({config})&&({config}==0))&&(isset({form})&&({form}=="update"))'),
"host"=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, 'isset({config})&&({config}==0||{config}==3)&&isset({save})'),
@@ -113,6 +114,10 @@ include_once "include/page_header.php";
"delete"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
"delete_and_clear"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
"cancel"=> array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL),
+/* proxy */
+ "proxyid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, '(isset({config})&&({config}==5))&&(isset({form})&&({form}=="update"))'),
+ "pname"=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, '(isset({config})&&({config}==5))&&isset({save})'),
+
/* other */
"form"=> array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL),
"form_refresh"=>array(T_ZBX_STR, O_OPT, NULL, NULL, NULL)
@@ -538,7 +543,112 @@ include_once "include/page_header.php";
}
(isset($_REQUEST["activate"]))?show_messages($result, S_ITEMS_ACTIVATED, null):show_messages($result, S_ITEMS_DISABLED, null);
}
-
+ elseif($_REQUEST["config"]==5 && isset($_REQUEST["save"]))
+ {
+ $hosts = get_request("hosts",array());
+ if(isset($_REQUEST["proxyid"]))
+ {
+ $result = update_proxy($_REQUEST["proxyid"], $_REQUEST["pname"], $hosts);
+ $action = AUDIT_ACTION_UPDATE;
+ $msg_ok = S_PROXY_UPDATED;
+ $msg_fail = S_CANNOT_UPDATE_PROXY;
+ $proxyid = $_REQUEST["proxyid"];
+ } else {
+ if(count(get_accessible_nodes_by_user($USER_DETAILS,PERM_READ_WRITE,PERM_MODE_LT,PERM_RES_IDS_ARRAY,get_current_nodeid())))
+ access_deny();
+
+ $proxyid = add_proxy($_REQUEST["pname"], $hosts);
+ $action = AUDIT_ACTION_ADD;
+ $msg_ok = S_PROXY_ADDED;
+ $msg_fail = S_CANNOT_ADD_PROXY;
+ $result = $proxyid;
+ }
+ show_messages($result, $msg_ok, $msg_fail);
+ if ($result) {
+ add_audit($action,
+ AUDIT_RESOURCE_PROXY,
+ "[".$_REQUEST["pname"]." ] [".$proxyid."]");
+
+ unset($_REQUEST["form"]);
+ }
+ unset($_REQUEST["save"]);
+ }
+ elseif($_REQUEST["config"]==5 && isset($_REQUEST["delete"]))
+ {
+ $result = false;
+
+ if(isset($_REQUEST["proxyid"])){
+ if ($proxy = get_proxy_by_proxyid($_REQUEST["proxyid"]))
+ $result = delete_proxy($_REQUEST["proxyid"]);
+
+ if ($result)
+ add_audit(AUDIT_ACTION_DELETE,
+ AUDIT_RESOURCE_PROXY,
+ "[".$proxy["name"]." ] [".$proxy['proxyid']."]");
+
+ unset($_REQUEST["form"]);
+
+ show_messages($result, S_PROXY_DELETED, S_CANNOT_DELETE_PROXY);
+
+ unset($_REQUEST["proxyid"]);
+ } else {
+ $proxies = get_request("proxies",array());
+
+ foreach ($proxies as $proxyid) {
+ $proxy = get_proxy_by_proxyid($proxyid);
+
+ if (false == ($result = delete_proxy($proxyid)))
+ break;
+
+ add_audit(AUDIT_ACTION_DELETE,
+ AUDIT_RESOURCE_PROXY,
+ "[".$proxy["name"]." ] [".$proxy['proxyid']."]");
+ }
+
+ show_messages($result, S_PROXY_DELETED, NULL);
+ }
+ unset($_REQUEST["delete"]);
+ }
+ elseif($_REQUEST["config"]==5 && isset($_REQUEST["clone"]) && isset($_REQUEST["proxyid"]))
+ {
+ unset($_REQUEST["proxyid"]);
+ $_REQUEST["form"] = "clone";
+ }
+ elseif($_REQUEST["config"]==5 && (isset($_REQUEST["activate"]) || isset($_REQUEST["disable"])))
+ {
+ $result = false;
+
+ $status = isset($_REQUEST["activate"]) ? HOST_STATUS_MONITORED : HOST_STATUS_NOT_MONITORED;
+
+ $proxies = get_request("proxies",array());
+
+ foreach ($proxies as $proxyid) {
+ $db_hosts = DBselect("select hostid,status from hosts where".
+ " proxyid=".$proxyid." and ".DBin_node('hostid'));
+ while ($db_host = DBfetch($db_hosts)) {
+ $old_status = $db_host["status"];
+ if ($old_status == $status)
+ continue;
+
+ if (false == ($result = update_host_status($db_host["hostid"], $status)))
+ continue;
+
+ $result = 1;
+
+ add_audit(AUDIT_ACTION_UPDATE,
+ AUDIT_RESOURCE_HOST,
+ "Old status [".$old_status."] "."New status [".$status."] [".$db_host["hostid"]."]");
+ }
+ }
+ show_messages($result, S_HOST_STATUS_UPDATED, NULL);
+
+ if (isset($_REQUEST["activate"]))
+ unset($_REQUEST["activate"]);
+ else
+ unset($_REQUEST["disable"]);
+ }
+
+
$available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_WRITE,null,null,get_current_nodeid()); /* update available_hosts after ACTIONS */
?>
<?php
@@ -548,6 +658,7 @@ include_once "include/page_header.php";
$cmbConf = new CComboBox("config",$_REQUEST["config"],"submit()");
$cmbConf->AddItem(0,S_HOSTS);
$cmbConf->AddItem(3,S_TEMPLATES);
+ $cmbConf->AddItem(5,S_PROXIES);
$cmbConf->AddItem(1,S_HOST_GROUPS);
$cmbConf->AddItem(2,S_TEMPLATE_LINKAGE);
$cmbConf->AddItem(4,S_APPLICATIONS);
@@ -561,6 +672,9 @@ include_once "include/page_header.php";
$btn = new CButton("form",S_CREATE_TEMPLATE);
$frmForm->AddVar("groupid",get_request("groupid",0));
break;
+ case 5:
+ $btn = new CButton("form",S_CREATE_PROXY);
+ break;
case 1:
$btn = new CButton("form",S_CREATE_GROUP);
break;
@@ -1034,6 +1148,79 @@ include_once "include/page_header.php";
$form->Show();
}
}
+ elseif($_REQUEST["config"]==5) /* Proxies */
+ {
+ if(isset($_REQUEST["form"]))
+ {
+ insert_proxies_form(get_request("proxyid",NULL));
+ } else {
+ show_table_header(S_PROXIES_BIG);
+
+ $form = new CForm('hosts.php');
+ $form->SetMethod('get');
+
+ $form->SetName('proxies');
+ $form->AddVar("config",get_request("config",0));
+
+ $table = new CTableInfo(S_NO_PROXIES_DEFINED);
+
+ $table->setHeader(array(
+ array( new CCheckBox("all_proxies",NULL,
+ "CheckAll('".$form->GetName()."','all_proxies');"),
+ SPACE,
+ make_sorting_link(S_NAME,'g.name')),
+ ' # ',
+ S_MEMBERS));
+
+ $available_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_WRITE,null,null,get_current_nodeid());
+
+ $db_proxies=DBselect('SELECT proxyid,name '.
+ ' FROM proxies'.
+ order_by('name'));
+ while($db_proxy=DBfetch($db_proxies))
+ {
+ $db_hosts = DBselect('SELECT DISTINCT host,status'.
+ ' FROM hosts'.
+ ' WHERE proxyid='.$db_proxy['proxyid'].
+ ' AND hostid in ('.$available_hosts.')'.
+ ' AND status not in ('.HOST_STATUS_DELETED.') '.
+ ' order by host'
+ );
+
+ $hosts = array();
+ $count = 0;
+ while($db_host=DBfetch($db_hosts)){
+ $style = $db_host["status"]==HOST_STATUS_MONITORED ? NULL: (
+ $db_host["status"]==HOST_STATUS_TEMPLATE ? "unknown" :
+ "on");
+ array_push($hosts, empty($hosts) ? '' : ',', new CSpan($db_host["host"], $style));
+ $count++;
+ }
+
+ $table->AddRow(array(
+ array(
+ new CCheckBox("proxies[]", NULL, NULL, $db_proxy["proxyid"]),
+ SPACE,
+ new CLink($db_proxy["name"],
+ "hosts.php?form=update&proxyid=".$db_proxy["proxyid"].url_param("config"),
+ 'action')
+ ),
+ $count,
+ $hosts
+ ));
+ }
+ $table->SetFooter(new CCol(array(
+ new CButtonQMessage('activate',S_ACTIVATE_SELECTED,S_ACTIVATE_SELECTED_HOSTS_Q),
+ SPACE,
+ new CButtonQMessage('disable',S_DISABLE_SELECTED,S_DISABLE_SELECTED_HOSTS_Q),
+ SPACE,
+ new CButtonQMessage('delete',S_DELETE_SELECTED,S_DELETE_SELECTED_GROUPS_Q)
+ )));
+
+ $form->AddItem($table);
+ $form->Show();
+ }
+ }
?>
<?php
diff --git a/frontends/php/include/audit.inc.php b/frontends/php/include/audit.inc.php
index cde2d697..662aaf76 100644
--- a/frontends/php/include/audit.inc.php
+++ b/frontends/php/include/audit.inc.php
@@ -42,6 +42,7 @@
$str_resource[AUDIT_RESOURCE_SCENARIO] = S_SCENARIO;
$str_resource[AUDIT_RESOURCE_DISCOVERY_RULE] = S_DISCOVERY_RULE;
$str_resource[AUDIT_RESOURCE_SLIDESHOW] = S_SLIDESHOW;
+ $str_resource[AUDIT_RESOURCE_PROXY] = S_PROXY;
if(isset($str_resource[$resource_type]))
return $str_resource[$resource_type];
diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php
index 77939cd8..7a7a1db7 100644
--- a/frontends/php/include/defines.inc.php
+++ b/frontends/php/include/defines.inc.php
@@ -110,6 +110,7 @@
define('AUDIT_RESOURCE_DISCOVERY_RULE', 23);
define('AUDIT_RESOURCE_SLIDESHOW', 24);
define('AUDIT_RESOURCE_SCRIPT', 25);
+ define('AUDIT_RESOURCE_PROXY', 26);
define('CONDITION_TYPE_HOST_GROUP', 0);
define('CONDITION_TYPE_HOST', 1);
diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php
index 6a895cef..d68bb578 100644
--- a/frontends/php/include/forms.inc.php
+++ b/frontends/php/include/forms.inc.php
@@ -4480,6 +4480,74 @@ include_once 'include/discovery.inc.php';
$frmHostG->Show();
}
+ # Insert form for Proxies
+ function insert_proxies_form()
+ {
+ global $_REQUEST;
+ global $USER_DETAILS;
+
+ $hosts = array();
+ $frm_title = S_PROXY;
+ if(isset($_REQUEST["proxyid"]))
+ {
+ $proxy = get_proxy_by_proxyid($_REQUEST["proxyid"]);
+ $frm_title = S_PROXY." \"".$proxy["name"]."\"";
+ }
+ if(isset($_REQUEST["proxyid"]) && !isset($_REQUEST["form_refresh"]))
+ {
+ $name=$proxy["name"];
+ $db_hosts=DBselect("SELECT hostid FROM hosts".
+ " WHERE status not in (".HOST_STATUS_DELETED.") ".
+ " AND proxyid=".$_REQUEST["proxyid"]);
+ while($db_host=DBfetch($db_hosts))
+ array_push($hosts, $db_host["hostid"]);
+ }
+ else
+ {
+ $name=get_request("pname","");
+ }
+ $frmHostG = new CFormTable($frm_title,"hosts.php");
+ $frmHostG->SetHelp("web.proxy.php");
+ $frmHostG->AddVar("config",get_request("config",5));
+ if(isset($_REQUEST["proxyid"]))
+ {
+ $frmHostG->AddVar("proxyid",$_REQUEST["proxyid"]);
+ }
+
+ $frmHostG->AddRow(S_PROXY_NAME,new CTextBox("pname",$name,30));
+
+ $cmbHosts = new CListBox("hosts[]",$hosts,10);
+ $db_hosts=DBselect("SELECT hostid,proxyid,host FROM hosts".
+ " WHERE status not in (".HOST_STATUS_DELETED.") ".
+ " AND hostid in (".get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,null,null,get_current_nodeid()).")".
+ " order by host");
+ while($db_host=DBfetch($db_hosts))
+ {
+ $cmbHosts->AddItem(
+ $db_host["hostid"],
+ get_node_name_by_elid($db_host["hostid"]).$db_host["host"],
+ NULL,
+ $db_host["proxyid"] == 0 || (isset($_REQUEST["proxyid"]) && $db_host["proxyid"] == $_REQUEST["proxyid"]));
+ }
+ $frmHostG->AddRow(S_HOSTS,$cmbHosts);
+
+ $frmHostG->AddItemToBottomRow(new CButton("save",S_SAVE));
+ if(isset($_REQUEST["proxyid"]))
+ {
+ $frmHostG->AddItemToBottomRow(SPACE);
+ $frmHostG->AddItemToBottomRow(new CButton("clone",S_CLONE));
+ $frmHostG->AddItemToBottomRow(SPACE);
+ $frmHostG->AddItemToBottomRow(
+ new CButtonDelete("Delete selected proxy?",
+ url_param("form").url_param("config").url_param("proxyid")
+ )
+ );
+ }
+ $frmHostG->AddItemToBottomRow(SPACE);
+ $frmHostG->AddItemToBottomRow(new CButtonCancel(url_param("config")));
+ $frmHostG->Show();
+ }
+
# Insert host profile ReadOnly form
function insert_host_profile_form()
{
diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php
index 0c8b47d8..adac2801 100644
--- a/frontends/php/include/hosts.inc.php
+++ b/frontends/php/include/hosts.inc.php
@@ -493,6 +493,88 @@ require_once "include/items.inc.php";
return false;
}
+ function db_save_proxy($name,$proxyid=null)
+ {
+ if(!is_string($name)){
+ error("incorrect parameters for 'db_save_proxy'");
+ return false;
+ }
+
+ if($proxyid==null)
+ $result = DBselect("select * from proxies where ".DBin_node('proxyid')." AND name=".zbx_dbstr($name));
+ else
+ $result = DBselect("select * from proxies where ".DBin_node('proxyid')." AND name=".zbx_dbstr($name).
+ " and proxyid<>$proxyid");
+
+ if(DBfetch($result))
+ {
+ error("Group '$name' already exists");
+ return false;
+ }
+ if($proxyid==null)
+ {
+ $proxyid=get_dbid("proxies","proxyid");
+ if(!DBexecute("insert into proxies (proxyid,name) values (".$proxyid.",".zbx_dbstr($name).")"))
+ return false;
+ return $proxyid;
+
+ }
+ else
+ return DBexecute("update proxies set name=".zbx_dbstr($name)." where proxyid=$proxyid");
+ }
+
+ function delete_proxy($proxyid)
+ {
+ if(!DBexecute("update hosts set proxyid=0 where proxyid=$proxyid"))
+ return false;
+
+ return DBexecute("delete from proxies where proxyid=$proxyid");
+ }
+
+ function update_hosts_by_proxyid($proxyid,$hosts=array())
+ {
+ DBexecute('update hosts set proxyid=0 where proxyid='.$proxyid);
+
+ foreach($hosts as $hostid)
+ {
+ DBexecute('update hosts set proxyid='.$proxyid.' where hostid='.$hostid);
+ }
+ }
+
+ function add_proxy($name,$hosts=array())
+ {
+ $proxyid = db_save_proxy($name);
+ if(!$proxyid)
+ return $proxyid;
+
+ update_hosts_by_proxyid($proxyid,$hosts);
+
+ return $proxyid;
+ }
+
+ function update_proxy($proxyid,$name,$hosts)
+ {
+ $result = db_save_proxy($name,$proxyid);
+ if(!$result)
+ return $result;
+
+ update_hosts_by_proxyid($proxyid,$hosts);
+
+ return $result;
+ }
+
+ function get_proxy_by_proxyid($proxyid)
+ {
+ $result=DBselect("select * from proxies where proxyid=".$proxyid);
+ $row=DBfetch($result);
+ if($row)
+ {
+ return $row;
+ }
+ error("No proxies with proxyid=[$proxyid]");
+ return false;
+ }
+
function get_host_by_itemid($itemid)
{
$sql="select h.* from hosts h, items i where i.hostid=h.hostid and i.itemid=$itemid";
diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php
index 3422f27c..42056e0a 100644
--- a/frontends/php/include/locales/en_gb.inc.php
+++ b/frontends/php/include/locales/en_gb.inc.php
@@ -636,6 +636,7 @@
'S_NO_LINKAGES_DEFINED'=> 'No linkages defined',
'S_NO_HOSTS_DEFINED'=> 'No hosts defined',
'S_NO_TEMPLATES_DEFINED'=> 'No templates defined',
+ 'S_NO_PROXIES_DEFINED'=> 'No proxies defined',
'S_HOSTS_BIG'=> 'HOSTS',
'S_HOST'=> 'Host',
'S_HOST_BIG'=> 'HOST',
@@ -671,6 +672,11 @@
'S_AVAILABILITY'=> 'Availability',
'S_AVAILABLE'=> 'Available',
'S_NOT_AVAILABLE'=> 'Not available',
+ 'S_PROXIES'=> 'Proxies',
+ 'S_PROXIES_BIG'=> 'PROXIES',
+ 'S_PROXY'=> 'Proxy',
+ 'S_CREATE_PROXY'=> 'Create Proxy',
+ 'S_PROXY_NAME'=> 'Proxy name',
// Host profiles
'S_HOST_PROFILE'=> 'Host profile',
'S_DEVICE_TYPE'=> 'Device type',
@@ -1296,6 +1302,12 @@
'S_CANNOT_UPDATE_GROUP'=> 'Cannot update group',
'S_GROUP_DELETED'=> 'Group deleted',
'S_CANNOT_DELETE_GROUP'=> 'Cannot delete group',
+ 'S_PROXY_ADDED'=> 'Proxy added',
+ 'S_CANNOT_ADD_PROXY'=> 'Cannot add proxy',
+ 'S_PROXY_UPDATED'=> 'Proxy updated',
+ 'S_CANNOT_UPDATE_PROXY'=> 'Cannot update proxy',
+ 'S_PROXY_DELETED'=> 'Proxy deleted',
+ 'S_CANNOT_DELETE_PROXY'=> 'Cannot delete proxy',
'S_USER_CANNOT_DISABLE_ITSELF'=> 'User cannot disable itself',
'S_USER_CANNOT_CHANGE_STATUS'=> 'User cannot change status to itself',
'S_USER_CANNOT_CHANGE_GUI_ACCESS'=> 'User cannot change GUI access to itself',