summaryrefslogtreecommitdiffstats
path: root/frontends/php/include
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-10-23 07:34:27 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-10-23 07:34:27 +0000
commit28a09ed13e41ddbe5e30d63e92a1f5fb3395ef89 (patch)
tree8281ccd48964ee0dd11c5ea689091fa3cef706fb /frontends/php/include
parent495799b2aa61aab23d74d7faa110a0cd09d59bf0 (diff)
downloadzabbix-28a09ed13e41ddbe5e30d63e92a1f5fb3395ef89.tar.gz
zabbix-28a09ed13e41ddbe5e30d63e92a1f5fb3395ef89.tar.xz
zabbix-28a09ed13e41ddbe5e30d63e92a1f5fb3395ef89.zip
- developed group permission system (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@3371 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
-rw-r--r--frontends/php/include/acknow.inc.php28
-rw-r--r--frontends/php/include/actions.inc.php117
-rw-r--r--frontends/php/include/audit.inc.php51
-rw-r--r--frontends/php/include/autoregistration.inc.php33
-rw-r--r--frontends/php/include/bulkloader.inc.php2
-rw-r--r--frontends/php/include/classes/cbutton.inc.php22
-rw-r--r--frontends/php/include/classes/cformtable.inc.php13
-rw-r--r--frontends/php/include/classes/clink.inc.php2
-rw-r--r--frontends/php/include/classes/clist.inc.php (renamed from frontends/php/include/classes/cpassbox.inc.php)45
-rw-r--r--frontends/php/include/classes/clistbox.inc.php25
-rw-r--r--frontends/php/include/classes/cserverinfo.mod.php2
-rw-r--r--frontends/php/include/classes/ctable.inc.php17
-rw-r--r--frontends/php/include/classes/ctag.inc.php55
-rw-r--r--frontends/php/include/classes/ctriggerinfo.mod.php87
-rw-r--r--frontends/php/include/classes/cvar.inc.php11
-rw-r--r--frontends/php/include/classes/graph.inc.php17
-rw-r--r--frontends/php/include/config.inc.php1794
-rw-r--r--frontends/php/include/copt.lib.php166
-rw-r--r--frontends/php/include/db.inc.php65
-rw-r--r--frontends/php/include/defines.inc.php54
-rw-r--r--frontends/php/include/escalations.inc.php160
-rw-r--r--frontends/php/include/events.inc.php63
-rw-r--r--frontends/php/include/forms.inc.php943
-rw-r--r--frontends/php/include/graphs.inc.php30
-rw-r--r--frontends/php/include/hosts.inc.php205
-rw-r--r--frontends/php/include/html.inc.php49
-rw-r--r--frontends/php/include/images.inc.php209
-rw-r--r--frontends/php/include/items.inc.php187
-rw-r--r--frontends/php/include/locales.inc.php12
-rw-r--r--frontends/php/include/locales/en_gb.inc.php38
-rw-r--r--frontends/php/include/locales/lv_lv.inc.php4
-rw-r--r--frontends/php/include/locales/ru_ru.inc.php6
-rw-r--r--frontends/php/include/maps.inc.php99
-rw-r--r--frontends/php/include/media.inc.php190
-rw-r--r--frontends/php/include/page_footer.php55
-rw-r--r--frontends/php/include/page_header.php380
-rw-r--r--frontends/php/include/perm.inc.php572
-rw-r--r--frontends/php/include/profiles.inc.php12
-rw-r--r--frontends/php/include/screens.inc.php112
-rw-r--r--frontends/php/include/services.inc.php51
-rw-r--r--frontends/php/include/triggers.inc.php317
-rw-r--r--frontends/php/include/users.inc.php297
-rw-r--r--frontends/php/include/validate.inc.php44
43 files changed, 3795 insertions, 2846 deletions
diff --git a/frontends/php/include/acknow.inc.php b/frontends/php/include/acknow.inc.php
index 943d376f..5d08ef03 100644
--- a/frontends/php/include/acknow.inc.php
+++ b/frontends/php/include/acknow.inc.php
@@ -19,30 +19,30 @@
**/
?>
<?php
- function get_last_alarm_by_triggerid($triggerid)
+ function get_last_event_by_triggerid($triggerid)
{
- $db_alarms = DBselect("select * from alarms where triggerid=$triggerid".
- " order by clock desc");
- $row=DBfetch($db_alarms,1);
- if(!$row) return FALSE;
- return $row;
+ $event_data = DBfetch(DBselect("select * from events where triggerid=$triggerid".
+ " order by clock desc", 1));
+ if(!$event_data)
+ return FALSE;
+ return $event_data;
}
- function get_acknowledges_by_alarmid($alarmid)
+ function get_acknowledges_by_eventid($eventid)
{
- return DBselect("select * from acknowledges where alarmid=$alarmid");
+ return DBselect("select * from acknowledges where eventid=$eventid");
}
- function add_acknowledge_coment($alarmid, $userid, $message)
+ function add_acknowledge_coment($eventid, $userid, $message)
{
- $result = set_alarm_acnowledged($alarmid);
+ $result = set_event_acnowledged($eventid);
if(!$result)
return $result;
$acknowledgeid = get_dbid("acknowledges","acknowledgeid");
- $result = DBexecute("insert into acknowledges (acknowledgeid,userid,alarmid,clock,message)".
- " values ($acknowledgeid,$userid,$alarmid,".time().",".zbx_dbstr($message).")");
+ $result = DBexecute("insert into acknowledges (acknowledgeid,userid,eventid,clock,message)".
+ " values ($acknowledgeid,$userid,$eventid,".time().",".zbx_dbstr($message).")");
if(!$result)
return $result;
@@ -50,8 +50,8 @@
return $acknowledgeid;
}
- function set_alarm_acnowledged($alarmid)
+ function set_event_acnowledged($eventid)
{
- return DBexecute("update alarms set acknowledged=1 where alarmid=$alarmid");
+ return DBexecute("update events set acknowledged=1 where eventid=$eventid");
}
?>
diff --git a/frontends/php/include/actions.inc.php b/frontends/php/include/actions.inc.php
index 272235a1..ca0e28bb 100644
--- a/frontends/php/include/actions.inc.php
+++ b/frontends/php/include/actions.inc.php
@@ -19,6 +19,54 @@
**/
?>
<?php
+ function action_accessiable($actionid,$perm)
+ {
+ global $USER_DETAILS;
+
+ $result = false;
+
+ if(DBselect("select actionid from actions where actionid=".$actionid.
+ " and ".DBid2nodeid('actionid')." in (".get_accessible_nodes_by_user($USER_DETAILS,$perm).")"))
+ {
+ $result = true;
+
+ $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, PERM_MODE_LT);
+ $denyed_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY, PERM_MODE_LT);
+
+ $db_result = DBselect("select * from conditions where actionid=".$actionid);
+ while(($ac_data = DBfetch($db_result)) && $result)
+ {
+ if($ac_data['operator'] != 0) continue;
+
+ switch($ac_data['conditiontype'])
+ {
+ case CONDITION_TYPE_GROUP:
+ if(in_array($ac_data['value'],explode(',',$denyed_groups)))
+ {
+ $result = false;
+ }
+ break;
+ case CONDITION_TYPE_HOST:
+ if(in_array($ac_data['value'],explode(',',$denyed_hosts)))
+ {
+ $result = false;
+ }
+ break;
+ case CONDITION_TYPE_TRIGGER:
+ if(!DBfetch(DBselect("select distinct t.*".
+ " from triggers t,items i,functions f".
+ " where f.itemid=i.itemid and t.triggerid=f.triggerid".
+ " and i.hostid not in (".$denyed_hosts.") and t.triggerid=".$ac_data['value'])))
+ {
+ $result = false;
+ }
+ break;
+ }
+ }
+ }
+ return $result;
+ }
+
function get_action_by_actionid($actionid)
{
$sql="select * from actions where actionid=$actionid";
@@ -91,39 +139,17 @@
return $result;
}
- # Delete Action by userid
-
- function delete_actions_by_userid( $userid )
- {
- $sql="select actionid from actions where userid=$userid";
- $result=DBexecute($sql);
- while($row=DBfetch($result))
- {
- delete_alert_by_actionid($row["actionid"]);
- }
-
- $sql="delete from actions where userid=$userid";
- return DBexecute($sql);
- }
-
- # Delete Conditions associated with actionid
-
- function delete_conditions_by_actionid($actionid)
- {
- $sql="delete from conditions where actionid=$actionid";
- return DBexecute($sql);
- }
-
# Delete Action
function delete_action( $actionid )
{
- delete_conditions_by_actionid($actionid);
- delete_alert_by_actionid($actionid);
+ $return = DBexecute('delete from conditions where actionid='.$actionid);
- $sql="delete from actions where actionid=$actionid";
- $result=DBexecute($sql);
+ if($return)
+ $result = DBexecute('delete from alerts where actionid='.$actionid);
+ if($return)
+ $result = DBexecute('delete from actions where actionid='.$actionid);
return $result;
}
@@ -407,21 +433,24 @@
function get_history_of_actions($start,$num)
{
- $sql="select a.alertid,a.clock,mt.description,a.sendto,a.subject,a.message,a.status,a.retries,".
- "a.error from alerts a,media_type mt where mt.mediatypeid=a.mediatypeid order by a.clock".
- " desc";
- $result=DBselect($sql,10*$start+$num);
+ global $USER_DETAILS;
+
+ $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_MODE_LT);
+
+ $result=DBselect("select a.alertid,a.clock,mt.description,a.sendto,a.subject,a.message,a.status,a.retries,".
+ "a.error from alerts a,media_type mt,functions f,items i ".
+ " where mt.mediatypeid=a.mediatypeid and a.triggerid=f.triggerid and f.itemid=i.itemid ".
+ " and i.hostid not in (".$denyed_hosts.")".
+ " order by a.clock".
+ " desc",
+ 10*$start+$num);
$table = new CTableInfo(S_NO_ACTIONS_FOUND);
- $table->setHeader(array(S_TIME, S_TYPE, S_STATUS, S_RECIPIENTS, S_SUBJECT, S_MESSAGE, S_ERROR));
+ $table->SetHeader(array(S_TIME, S_TYPE, S_STATUS, S_RECIPIENTS, S_SUBJECT, S_MESSAGE, S_ERROR));
$col=0;
$skip=$start;
while(($row=DBfetch($result))&&($col<$num))
{
- if(!check_anyright("Default permission","R"))
- {
- continue;
- }
if($skip > 0)
{
$skip--;
@@ -448,14 +477,14 @@
{
$error=new CSpan($row["error"],"on");
}
- $table->addRow(array(
- $time,
- $row["description"],
- $status,
- $sendto,
- $subject,
- $message,
- $error));
+ $table->AddRow(array(
+ $time,
+ $row["description"],
+ $status,
+ $sendto,
+ $subject,
+ $message,
+ $error));
$col++;
}
diff --git a/frontends/php/include/audit.inc.php b/frontends/php/include/audit.inc.php
index b36b56de..6b89c53d 100644
--- a/frontends/php/include/audit.inc.php
+++ b/frontends/php/include/audit.inc.php
@@ -19,17 +19,52 @@
**/
?>
<?php
+ function audit_resource2str($resource_type)
+ {
+ $str_resource[AUDIT_RESOURCE_USER] = S_USER;
+ $str_resource[AUDIT_RESOURCE_ZABBIX_CONFIG] = S_CONFIGURATION_OF_ZABBIX;
+ $str_resource[AUDIT_RESOURCE_MEDIA_TYPE] = S_MEDIA_TYPE;
+ $str_resource[AUDIT_RESOURCE_HOST] = S_HOST;
+ $str_resource[AUDIT_RESOURCE_ACTION] = S_ACTION;
+ $str_resource[AUDIT_RESOURCE_GRAPH] = S_GRAPH;
+ $str_resource[AUDIT_RESOURCE_GRAPH_ELEMENT] = S_GRAPH_ELEMENT;
+ $str_resource[AUDIT_RESOURCE_USER_GROUP] = S_USER_GROUP;
+ $str_resource[AUDIT_RESOURCE_APPLICATION] = S_APPLICATION;
+ $str_resource[AUDIT_RESOURCE_TRIGGER] = S_TRIGGER;
+ $str_resource[AUDIT_RESOURCE_HOST_GROUP] = S_HOST_GROUP;
+ $str_resource[AUDIT_RESOURCE_ITEM] = S_ITEM;
+ $str_resource[AUDIT_RESOURCE_IMAGE] = S_IMAGE;
+ $str_resource[AUDIT_RESOURCE_VALUE_MAP] = S_VALUE_MAP;
+ $str_resource[AUDIT_RESOURCE_IT_SERVICE] = S_IT_SERVICE;
+ $str_resource[AUDIT_RESOURCE_MAP] = S_MAP;
+ $str_resource[AUDIT_RESOURCE_SCREEN] = S_SCREEN;
+
+ if(isset($str_resource[$resource_type]))
+ return $str_resource[$resource_type];
+
+ return S_UNKNOWN_RESOURCE;
+ }
+
+ function add_audit_if($condition,$action,$resourcetype,$details)
+ {
+ if($condition)
+ return add_audit($action,$resourcetype,$details);
+
+ return false;
+ }
+
function add_audit($action,$resourcetype,$details)
{
global $USER_DETAILS;
- $userid=$USER_DETAILS["userid"];
- $clock=time();
- $auditlogid = get_dbid("auditlog","auditlogid");
- $sql="insert into auditlog (auditlogid,userid,clock,action,resourcetype,details) values ($auditlogid,$userid,$clock,$action,$resourcetype,".zbx_dbstr($details).")";
- $result = DBexecute($sql);
- if(!$result)
- return $result;
- return $auditlogid;
+ $auditid = get_dbid("auditlog","auditid");
+
+ if(($result = DBexecute("insert into auditlog (auditid,userid,clock,action,resourcetype,details) ".
+ " values ($auditid,".$USER_DETAILS["userid"].",".time().",$action,$resourcetype,".zbx_dbstr($details).")")))
+ {
+ $result = $auditid;
+ }
+
+ return $result;
}
?>
diff --git a/frontends/php/include/autoregistration.inc.php b/frontends/php/include/autoregistration.inc.php
index 1e1b87f0..364c3e0c 100644
--- a/frontends/php/include/autoregistration.inc.php
+++ b/frontends/php/include/autoregistration.inc.php
@@ -23,52 +23,31 @@
function add_autoregistration($pattern,$priority,$hostid)
{
- if(!check_right("Configuration of Zabbix","U",0))
- {
- error("Insufficient permissions");
- return 0;
- }
$autoregid = get_dbid("autoreg","autoregid");
- $sql="insert into autoreg (autoregid,pattern,priority,hostid) values ($autoregid,".zbx_dbstr($pattern).",$priority,$hostid)";
- $result=DBexecute($sql);
+ $result=DBexecute("insert into autoreg (autoregid,pattern,priority,hostid) ".
+ " values ($autoregid,".zbx_dbstr($pattern).",$priority,$hostid)");
if($result)
{
$host=get_host_by_hostid($hostid);
info("Added new autoregistration rule for $pattern");
+ $result = $autoregid;
}
- else return $result;
- return $autoregid;
+ return $result;
}
# Update Autoregistration rule
function update_autoregistration($id,$pattern,$priority,$hostid)
{
- if(!check_right("Configuration of Zabbix","U",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
- $sql="update autoreg set pattern=".zbx_dbstr($pattern).",priority=$priority,hostid=$hostid where id=$id";
-
- return DBexecute($sql);
+ return DBexecute("update autoreg set pattern=".zbx_dbstr($pattern).",priority=$priority,hostid=$hostid where id=$id");
}
# Delete Autoregistartion rule
function delete_autoregistration($id)
{
- if(!check_right("Configuration of Zabbix","U",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
- $sql="delete from autoreg where id=$id";
-
- return DBexecute($sql);
+ return DBexecute("delete from autoreg where id=$id");
}
?>
diff --git a/frontends/php/include/bulkloader.inc.php b/frontends/php/include/bulkloader.inc.php
index 1ab5abae..7db0f10c 100644
--- a/frontends/php/include/bulkloader.inc.php
+++ b/frontends/php/include/bulkloader.inc.php
@@ -17,7 +17,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
-include_once "include/config.inc.php";
+require_once "include/config.inc.php";
/*
** This include file contains all of the non-standard functions required
diff --git a/frontends/php/include/classes/cbutton.inc.php b/frontends/php/include/classes/cbutton.inc.php
index 22104147..ce63f5ce 100644
--- a/frontends/php/include/classes/cbutton.inc.php
+++ b/frontends/php/include/classes/cbutton.inc.php
@@ -27,7 +27,7 @@
parent::CTag('input','no');
$this->tag_body_start = '';
$this->options['type'] = 'submit';
- $this->options['value'] = $caption;
+ $this->AddOption('value', $caption);
// $this->options["type"] = "button";
$this->options['class'] = 'button';
$this->SetName($name);
@@ -36,11 +36,11 @@
}
function SetAction($value='submit()', $event='onClick')
{
- $this->options[$event] = $value;
+ $this->AddOption($event, $value);
}
function SetTitle($value='button title')
{
- $this->options['title'] = $value;
+ $this->AddOption('title', $value);
}
function SetAccessKey($value='B')
{
@@ -48,7 +48,7 @@
if(!isset($this->options['title']))
$this->SetTitle($this->options['value'].' [Alt+'.$value.']');
- return $this->options['accessKey'] = $value;
+ return $this->AddOption('accessKey', $value);
}
}
@@ -82,12 +82,14 @@
var $vars;
var $msg;
var $name;
+ var $do_redirect;
- function CButtonQMessage($name, $caption, $msg=NULL, $vars=NULL){
+ function CButtonQMessage($name, $caption, $msg=NULL, $vars=NULL, $do_redirect=true){
$this->name = $name;
parent::CButton($name,$caption);
$this->SetMessage($msg);
$this->SetVars($vars);
+ $this->do_redirect = $do_redirect;
}
function SetVars($value=NULL){
if(!is_string($value) && !is_null($value)){
@@ -113,7 +115,15 @@
global $page;
$confirmation = "Confirm('".$this->msg."')";
- $redirect = "Redirect('".$page["file"]."?".$this->name."=1".$this->vars."')";
+
+ if($this->do_redirect)
+ {
+ $redirect = "Redirect('".$page["file"]."?".$this->name."=1".$this->vars."')";
+ }
+ else
+ {
+ $redirect = 'true';
+ }
return parent::SetAction("if(".$confirmation.") return ".$redirect."; else return false;");
}
diff --git a/frontends/php/include/classes/cformtable.inc.php b/frontends/php/include/classes/cformtable.inc.php
index e2be6439..a0bf889d 100644
--- a/frontends/php/include/classes/cformtable.inc.php
+++ b/frontends/php/include/classes/cformtable.inc.php
@@ -56,7 +56,7 @@
$this->AddVar($form_variable, get_request($form_variable, 1));
$this->AddVar('form_refresh',get_request('form_refresh',0)+1);
- $this->bottom_items = new CCol(NULL,'form_row_last');
+ $this->bottom_items = new CCol(SPACE,'form_row_last');
$this->bottom_items->SetColSpan(2);
}
function SetAction($value)
@@ -127,6 +127,9 @@
if(is_string($item1))
$item1=nbsp($item1);
+ if(is_null($item1)) $item1 = SPACE;
+ if(is_null($item2)) $item2 = SPACE;
+
$row = new CRow(array(
new CCol($item1,'form_row_l'),
new CCol($item2,'form_row_r')
@@ -137,9 +140,15 @@
}
function AddSpanRow($value, $class=NULL)
{
+ if(is_string($value))
+ $item1=nbsp($value);
+
+ if(is_null($value)) $value = SPACE;
+ if(is_null($class)) $class = 'form_row_c';
+
$col = new CCol($value,$class);
$col->SetColSpan(2);
- array_push($this->center_items,new CRow($col,$class));
+ array_push($this->center_items,new CRow($col));
}
function AddItemToBottomRow($value)
{
diff --git a/frontends/php/include/classes/clink.inc.php b/frontends/php/include/classes/clink.inc.php
index 78c358eb..374453ca 100644
--- a/frontends/php/include/classes/clink.inc.php
+++ b/frontends/php/include/classes/clink.inc.php
@@ -40,7 +40,7 @@
if(is_null($value))
return $this->options['action'] = $page['file'];
- return $this->options['onClick'] = $value;
+ return $this->options['onClick'] = htmlspecialchars($value);
}
function SetUrl($value)
{
diff --git a/frontends/php/include/classes/cpassbox.inc.php b/frontends/php/include/classes/clist.inc.php
index 12a198cb..c5eb9b57 100644
--- a/frontends/php/include/classes/cpassbox.inc.php
+++ b/frontends/php/include/classes/clist.inc.php
@@ -19,9 +19,48 @@
**/
?>
<?php
+ class CListItem extends CTag
+ {
+/* public */
+ function CListItem($value)
+ {
+ parent::CTag('li','yes');
-// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-// TODO REMOVE THIS FILE FROM CVS
-// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ $this->AddItem($value);
+ }
+ }
+
+ class CList extends CTag
+ {
+/* public */
+ function CList($value=NULL,$class=NULL)
+ {
+ parent::CTag('ul','yes');
+ $this->tag_end = '';
+ $this->AddItem($value);
+ $this->SetClass($class);
+ }
+ function PrepareItem($value=NULL)
+ {
+ if(!is_null($value))
+ {
+ $value = new CListItem($value);
+ }
+ return $value;
+ }
+
+ function AddItem($value)
+ {
+ if(is_array($value))
+ {
+ foreach($value as $el)
+ parent::AddItem($this->PrepareItem($el));
+ }
+ else
+ {
+ parent::AddItem($this->PrepareItem($value));
+ }
+ }
+ }
?>
diff --git a/frontends/php/include/classes/clistbox.inc.php b/frontends/php/include/classes/clistbox.inc.php
deleted file mode 100644
index 311535b7..00000000
--- a/frontends/php/include/classes/clistbox.inc.php
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-/*
-** ZABBIX
-** Copyright (C) 2000-2005 SIA Zabbix
-**
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License as published by
-** the Free Software Foundation; either version 2 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-**/
-?>
-<?php
-// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-// TODO REMOVE THIS FILE FROM CVS !!!
-// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-?>
diff --git a/frontends/php/include/classes/cserverinfo.mod.php b/frontends/php/include/classes/cserverinfo.mod.php
index 4315c701..3ebe1765 100644
--- a/frontends/php/include/classes/cserverinfo.mod.php
+++ b/frontends/php/include/classes/cserverinfo.mod.php
@@ -66,7 +66,7 @@
new CSpan($status["triggers_count_unknown"],"unknown"),"/",
new CSpan($status["triggers_count_off"],"off"),"]"
)));
- $this->AddRow(S_NUMBER_OF_ALARMS.": ".$status["alarms_count"]);
+ $this->AddRow(S_NUMBER_OF_ALARMS.": ".$status["events_count"]);
$this->AddRow(S_NUMBER_OF_ALERTS.": ".$status["alerts_count"]);
return parent::BodyToString();
diff --git a/frontends/php/include/classes/ctable.inc.php b/frontends/php/include/classes/ctable.inc.php
index a0ab239c..10bb4d87 100644
--- a/frontends/php/include/classes/ctable.inc.php
+++ b/frontends/php/include/classes/ctable.inc.php
@@ -145,8 +145,7 @@
}
elseif(is_a($item,'crow'))
{
- if(isset($rowClass))
- $item->options['class'] = $rowClass;
+ $item->SetClass($rowClass);
}
else
{
@@ -154,9 +153,9 @@
}
if(!isset($item->options['class']))
{
- $item->options['class'] = ($this->rownum % 2) ?
- $this->evenRowClass:
- $this->oddRowClass;
+ $item->SetClass(($this->rownum % 2) ?
+ $this->oddRowClass:
+ $this->evenRowClass);
}/**/
return $item->ToString();
}
@@ -166,7 +165,7 @@
if(is_a($value,'crow'))
{
- if(isset($class)) $value->SetClass($class);
+ if(!is_null($class)) $value->SetClass($class);
}else{
$value = new CRow($value,$class);
}
@@ -181,13 +180,14 @@
}
function AddRow($item,$rowClass=NULL)
{
+ $item = $this->AddItem($this->PrepareRow($item,$rowClass));
++$this->rownum;
- return $this->AddItem($this->PrepareRow($item,$rowClass));
+ return $item;
}
function ShowRow($item,$rowClass=NULL)
{
- ++$this->rownum;
echo $this->PrepareRow($item,$rowClass);
+ ++$this->rownum;
}
/* protected */
function GetNumRows()
@@ -206,7 +206,6 @@
$ret = "";
if($this->rownum == 0 && isset($this->message))
{
- ++$this->rownum;
$ret = $this->PrepareRow(new CCol($this->message,'message'));
}
$ret .= $this->footer;
diff --git a/frontends/php/include/classes/ctag.inc.php b/frontends/php/include/classes/ctag.inc.php
index c0ac82e1..c5cfc7c8 100644
--- a/frontends/php/include/classes/ctag.inc.php
+++ b/frontends/php/include/classes/ctag.inc.php
@@ -19,6 +19,17 @@
**/
?>
<?php
+ function destroy_objects()
+ {
+ global $GLOBALS;
+
+ if(isset($GLOBALS)) foreach($GLOBALS as $name => $value)
+ {
+ if(!is_object($GLOBALS[$name])) continue;
+ unset($GLOBALS[$name]);
+ }
+ }
+
function unpack_object(&$item)
{
$res = "";
@@ -29,12 +40,13 @@
}
elseif(is_array($item))
{
- foreach($item as $i)
- $res .= unpack_object($i); // Attention, recursion !!!
+ foreach($item as $id => $dat)
+ $res .= unpack_object($item[$id]); // Attention, recursion !!!
}
elseif(!is_null($item))
{
$res = strval($item);
+ unset($item);
}
return $res;
}
@@ -42,6 +54,7 @@
class CTag
{
/* private */
+ var $destroyable_object;
var $tagname;
var $options = array();
var $paired;
@@ -78,7 +91,9 @@
function ShowStart() { echo $this->StartToString(); }
function ShowBody() { echo $this->BodyToString(); }
function ShowEnd() { echo $this->EndToString(); }
- function Show() { echo $this->ToString(); }
+ function Show($destroy=true) { echo $this->ToString($destroy); }
+
+ function Destroy() { $this = null; }
function StartToString()
{
@@ -103,11 +118,14 @@
$res .= $this->tag_end;
return $res;
}
- function ToString()
+ function ToString($destroy=true)
{
$res = $this->StartToString();
$res .= $this->BodyToString();
$res .= $this->EndToString();
+
+ if($destroy) $this->Destroy();
+
return $res;
}
function SetName($value)
@@ -122,7 +140,9 @@
}
function SetClass($value)
{
- return $this->options['class'] = $value;
+ if(isset($value))
+ $this->options['class'] = $value;
+ return $value;
}
function DelOption($name)
{
@@ -135,6 +155,31 @@
$ret =& $this->options[$name];
return $ret;
}
+
+ function SetHint($text, $width='', $class='')
+ {
+ if($width != '' || $class!= '')
+ {
+ $this->AddOption(
+ 'onMouseOver',
+ "show_hint_ext(this,'".$text."','".$width."','".$class."');"
+ );
+ }
+ else
+ {
+ $this->AddOption(
+ 'onMouseOver',
+ "show_hint(this,'".$text."');"
+ );
+ }
+
+ }
+
+ function OnClick($handle_code)
+ {
+ $this->AddOption('onClick', $handle_code);
+ }
+
function AddOption($name, $value)
{
$this->options[$name] = htmlspecialchars(strval($value));
diff --git a/frontends/php/include/classes/ctriggerinfo.mod.php b/frontends/php/include/classes/ctriggerinfo.mod.php
index 8c10ec93..aa016b83 100644
--- a/frontends/php/include/classes/ctriggerinfo.mod.php
+++ b/frontends/php/include/classes/ctriggerinfo.mod.php
@@ -22,10 +22,17 @@
class CTriggersInfo extends CTable
{
var $style;
+ var $show_header;
+ var $nodeid;
+
function CTriggersInfo($style = STYLE_HORISONTAL)
{
+ global $ZBX_CURNODEID;
+
parent::CTable(NULL,"triggers_info");
$this->SetOrientation($style);
+ $this->show_header = true;
+ $this->nodeid = $ZBX_CURNODEID;
}
function SetOrientation($value)
@@ -36,47 +43,69 @@
$this->style = $value;
}
+ function SetNodeid($nodeid)
+ {
+ $this->nodeid = (int)$nodeid;
+ }
+
+ function HideHeader()
+ {
+ $this->show_header = false;
+ }
+
function BodyToString()
{
- $this->CleanItems();
+ global $USER_DETAILS;
- $uncn = $info = $warn = $avg = $high = $dis = 0;
+ $this->CleanItems();
- $db_priority = DBselect("select t.priority,count(*) as cnt from triggers t,hosts h,items i,functions f".
- " where t.value=1 and t.status=0 and f.itemid=i.itemid and h.hostid=i.hostid".
- " and h.status=".HOST_STATUS_MONITORED." and t.triggerid=f.triggerid and i.status=0 group by priority");
+ $ok = $uncn = $info = $warn = $avg = $high = $dis = 0;
+ $db_priority = DBselect("select t.priority,t.value,count(*) as cnt from triggers t,hosts h,items i,functions f".
+ " where t.status=".TRIGGER_STATUS_ENABLED." and f.itemid=i.itemid ".
+ " and h.hostid=i.hostid and h.status=".HOST_STATUS_MONITORED." and t.triggerid=f.triggerid ".
+ " and i.status=".ITEM_STATUS_ACTIVE.
+ ' and h.hostid in ('.get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,
+ null, null, $this->nodeid).') '.
+ " group by priority");
while($row=DBfetch($db_priority))
{
- switch($row["priority"])
+ switch($row["value"])
{
- case 0: $uncn =$row["cnt"]; break;
- case 1: $info =$row["cnt"]; break;
- case 2: $warn =$row["cnt"]; break;
- case 3: $avg =$row["cnt"]; break;
- case 4: $high =$row["cnt"]; break;
- case 5: $dis =$row["cnt"]; break;
+ case TRIGGER_VALUE_TRUE:
+ switch($row["priority"])
+ {
+ case 1: $info += $row["cnt"]; break;
+ case 2: $warn += $row["cnt"]; break;
+ case 3: $avg += $row["cnt"]; break;
+ case 4: $high += $row["cnt"]; break;
+ case 5: $dis += $row["cnt"]; break;
+ default:
+ $uncn += $row["cnt"]; break;
+ }
+ break;
+ case TRIGGER_VALUE_FALSE:
+ $ok += $row["cnt"]; break;
+ default:
+ $uncn += $row["cnt"]; break;
}
}
- $db_ok_cnt = DBselect("select count(*) as cnt from triggers t,hosts h,items i,functions f".
- " where t.value=0 and t.status=0 and f.itemid=i.itemid and h.hostid=i.hostid".
- " and h.status=".HOST_STATUS_MONITORED." and t.triggerid=f.triggerid and i.status=0");
-
- $ok_cnt = DBfetch($db_ok_cnt);
-
- $header = new CCol(S_TRIGGERS_INFO,"header");
- if($this->style == STYLE_HORISONTAL)
- $header->SetColspan(7);
- $this->AddRow($header);
+ if($this->show_header)
+ {
+ $header = new CCol(S_TRIGGERS_INFO,"header");
+ if($this->style == STYLE_HORISONTAL)
+ $header->SetColspan(7);
+ $this->AddRow($header);
+ }
- $trok = new CCol($ok_cnt["cnt"]." ".S_OK, "trok");
- $uncn = new CCol($uncn." ".S_NOT_CLASSIFIED, "uncn");
- $info = new CCol($info." ".S_INFORMATION, "info");
- $warn = new CCol($warn." ".S_WARNING, "warn");
- $avg = new CCol($avg." ".S_AVERAGE, "avg");
- $high = new CCol($high." ".S_HIGH, "high");
- $dis = new CCol($dis." ".S_DISASTER, "dis");
+ $trok = new CCol($ok.SPACE.S_OK, "normal");
+ $uncn = new CCol($uncn.SPACE.S_NOT_CLASSIFIED,"uncnown");
+ $info = new CCol($info.SPACE.S_INFORMATION, "information");
+ $warn = new CCol($warn.SPACE.S_WARNING, "warning");
+ $avg = new CCol($avg.SPACE.S_AVERAGE, "average");
+ $high = new CCol($high.SPACE.S_HIGH, "high");
+ $dis = new CCol($dis.SPACE.S_DISASTER, "disaster");
if($this->style == STYLE_HORISONTAL)
diff --git a/frontends/php/include/classes/cvar.inc.php b/frontends/php/include/classes/cvar.inc.php
index 7a86d0bf..384bf607 100644
--- a/frontends/php/include/classes/cvar.inc.php
+++ b/frontends/php/include/classes/cvar.inc.php
@@ -53,17 +53,22 @@
if(is_null($value)) return;
+ $this->ParseValue($this->var_name, $value);
+ }
+
+ function ParseValue($name, $value)
+ {
if(is_array($value))
{
- foreach($value as $item)
+ foreach($value as $itemid => $item)
{
if( null == $item ) continue;
- array_push($this->var_container, new CVarTag($this->var_name.'[]', $item));
+ $this->ParseValue($name.'['.$itemid.']', $item);
}
return;
}
- array_push($this->var_container, new CVarTag($this->var_name, $value));
+ array_push($this->var_container, new CVarTag($name, $value));
}
function ToString()
diff --git a/frontends/php/include/classes/graph.inc.php b/frontends/php/include/classes/graph.inc.php
index 53e6fb6c..a7ab9537 100644
--- a/frontends/php/include/classes/graph.inc.php
+++ b/frontends/php/include/classes/graph.inc.php
@@ -19,6 +19,8 @@
**/
?>
<?php
+ require_once "include/items.inc.php";
+ require_once "include/hosts.inc.php";
define("GRAPH_DRAW_TYPE_LINE",0);
define("GRAPH_DRAW_TYPE_FILL",1);
@@ -526,18 +528,6 @@
}
- function checkPermissions()
- {
- if(!check_right("Item","R",$this->items[0]["itemid"]))
- {
- $this->drawGrid();
- ImageString($this->im, 2,$this->sizeX/2 -50,$this->sizeY+$this->shiftY+3, "NO PERMISSIONS" , $this->colors["Dark Red No Alpha"]);
- ImageOut($this->im);
- ImageDestroy($this->im);
- exit;
- }
- }
-
function drawLogo()
{
ImageStringUp($this->im,0,$this->fullSizeX-10,$this->fullSizeY-50, "http://www.zabbix.com", $this->colors["Gray"]);
@@ -1167,9 +1157,6 @@
// $this->noDataFound();
}
- $this->checkPermissions();
-
-
$this->drawWorkPeriod();
$this->drawGrid();
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php
index 6b4fd6d9..48107e47 100644
--- a/frontends/php/include/config.inc.php
+++ b/frontends/php/include/config.inc.php
@@ -18,18 +18,22 @@
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
-function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
+function SDI($msg="SDI") { echo "DEBUG INFO: "; if(is_array($msg)) print_r($msg); else echo($msg); echo BR; } // DEBUG INFO!!!
?>
<?php
- include_once("include/copt.lib.php");
+ require_once "include/html.inc.php";
+ require_once "include/copt.lib.php";
// GLOBALS
$USER_DETAILS = array();
$USER_RIGHTS = array();
$ERROR_MSG = array();
$INFO_MSG = array();
+
+
+ $ZBX_LOCALNODEID = 1; // Local node
// END OF GLOBALS
// if magic quotes on then get rid of them
@@ -40,67 +44,61 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
$_REQUEST= zbx_stripslashes($_REQUEST);
}
- include_once "include/defines.inc.php";
- include_once "include/db.inc.php";
- include_once "include/html.inc.php";
- include_once "include/locales.inc.php";
- include_once "include/perm.inc.php";
-
- include_once "include/audit.inc.php";
- include_once "include/acknow.inc.php";
- include_once "include/autoregistration.inc.php";
- include_once "include/escalations.inc.php";
- include_once "include/hosts.inc.php";
- include_once "include/users.inc.php";
- include_once "include/graphs.inc.php";
- include_once "include/items.inc.php";
- include_once "include/screens.inc.php";
- include_once "include/triggers.inc.php";
- include_once "include/actions.inc.php";
- include_once "include/events.inc.php";
- include_once "include/profiles.inc.php";
- include_once "include/services.inc.php";
- include_once "include/maps.inc.php";
- include_once "include/media.inc.php";
+ require_once "include/defines.inc.php";
+ require_once "include/db.inc.php";
+ require_once "include/locales.inc.php";
+ require_once "include/perm.inc.php";
+ require_once "include/audit.inc.php";
// Include Validation
- include_once "include/validate.inc.php";
+ require_once "include/validate.inc.php";
// Include Classes
- include_once("include/classes/ctag.inc.php");
- include_once("include/classes/cvar.inc.php");
- include_once("include/classes/cspan.inc.php");
- include_once("include/classes/cimg.inc.php");
- include_once("include/classes/clink.inc.php");
- include_once("include/classes/chelp.inc.php");
- include_once("include/classes/cbutton.inc.php");
- include_once("include/classes/ccombobox.inc.php");
- include_once("include/classes/ctable.inc.php");
- include_once("include/classes/ctableinfo.inc.php");
- include_once("include/classes/ctextarea.inc.php");
- include_once("include/classes/ctextbox.inc.php");
- include_once("include/classes/cpassbox.inc.php");
- include_once("include/classes/cform.inc.php");
- include_once("include/classes/cfile.inc.php");
- include_once("include/classes/ccheckbox.inc.php");
- include_once("include/classes/clistbox.inc.php");
- include_once("include/classes/cform.inc.php");
- include_once("include/classes/cformtable.inc.php");
- include_once("include/classes/cmap.inc.php");
- include_once("include/classes/cflash.inc.php");
- include_once("include/classes/ciframe.inc.php");
+ require_once("include/classes/ctag.inc.php");
+ require_once("include/classes/cvar.inc.php");
+ require_once("include/classes/cspan.inc.php");
+ require_once("include/classes/cimg.inc.php");
+ require_once("include/classes/clink.inc.php");
+ require_once("include/classes/chelp.inc.php");
+ require_once("include/classes/cbutton.inc.php");
+ require_once("include/classes/clist.inc.php");
+ require_once("include/classes/ccombobox.inc.php");
+ require_once("include/classes/ctable.inc.php");
+ require_once("include/classes/ctableinfo.inc.php");
+ require_once("include/classes/ctextarea.inc.php");
+ require_once("include/classes/ctextbox.inc.php");
+ require_once("include/classes/cform.inc.php");
+ require_once("include/classes/cfile.inc.php");
+ require_once("include/classes/ccheckbox.inc.php");
+ require_once("include/classes/cform.inc.php");
+ require_once("include/classes/cformtable.inc.php");
+ require_once("include/classes/cmap.inc.php");
+ require_once("include/classes/cflash.inc.php");
+ require_once("include/classes/ciframe.inc.php");
+ require_once("include/classes/graph.inc.php");
// Include Tactical Overview modules
+
include_once("include/classes/chostsinfo.mod.php");
include_once("include/classes/ctriggerinfo.mod.php");
include_once("include/classes/cserverinfo.mod.php");
include_once("include/classes/cflashclock.mod.php");
+ function access_deny()
+ {
+ include_once "include/page_header.php";
+
+ show_error_message(S_NO_PERMISSIONS);
+
+ include_once "include/page_footer.php";
+ }
function zbx_stripslashes($value){
if(is_array($value)){
- $value = array_map('zbx_stripslashes',$value);
+ foreach($value as $id => $data)
+ $value[$id] = zbx_stripslashes($data);
+ // $value = array_map('zbx_stripslashes',$value); /* don't use 'array_map' it buggy with indexes */
} elseif (is_string($value)){
$value = stripslashes($value);
}
@@ -142,29 +140,18 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
}
}
+ function fatal_error($msg)
+ {
+ error($msg);
+ include_once "include/page_footer.php";
+ }
+
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
- function iif($bool,$a,$b)
- {
- if($bool)
- {
- return $a;
- }
- else
- {
- return $b;
- }
- }
-
- function iif_echo($bool,$a,$b)
- {
- echo iif($bool,$a,$b);
- }
-
function convert_units($value,$units)
{
// Special processing for unix timestamps
@@ -304,68 +291,21 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
return "$s $u$units";
}
- function get_template_permission_str($num)
- {
- $str=SPACE;
- if(($num&1)==1) $str=$str.S_ADD.SPACE;
- if(($num&2)==2) $str=$str.S_UPDATE.SPACE;
- if(($num&4)==4) $str=$str.S_DELETE.SPACE;
- return $str;
- }
-
- function get_media_count_by_userid($userid)
- {
- $sql="select count(mediaid) as cnt from media where userid=$userid";
- $result=DBselect($sql);
- $row=DBfetch($result);
- return $row["cnt"];
- }
-
- function get_action_count_by_triggerid($triggerid)
- {
- $cnt=0;
-
- $sql="select count(actionid) as cnt from actions where triggerid=$triggerid and scope=0";
- $result=DBselect($sql);
- $row=DBfetch($result);
-
- $cnt=$cnt+$row["cnt"];
-
- $sql="select count(actionid) as cnt from actions where scope=2";
- $result=DBselect($sql);
- $row=DBfetch($result);
-
- $cnt=$cnt+$row["cnt"];
-
- $sql="select distinct h.hostid from hosts h,items i,triggers t,functions f where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid and t.triggerid=$triggerid";
- $result=DBselect($sql);
- while($row=DBfetch($result))
- {
- $sql="select count(*) as cnt from actions a,hosts h,items i,triggers t,functions f where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid and a.triggerid=".$row["hostid"]." and a.scope=1";
- $result2=DBselect($sql);
- $row2=DBfetch($result2);
- $cnt=$cnt+$row2["cnt"];
- }
-
- return $cnt;
- }
-
function play_sound($filename)
{
- echo '
+?>
<SCRIPT TYPE="text/javascript">
<!--
-var snd_tag = \'<BGSOUND SRC="'.$filename.'" LOOP=0/>\';
-
if (navigator.appName != "Microsoft Internet Explorer")
- snd_tag = \'<EMBED SRC="'.$filename.'" AUTOSTART=TRUE WIDTH=0 HEIGHT=0 LOOP=0><P/>\';
-
-document.writeln(snd_tag);
+ document.writeln('<EMBED SRC="<?php echo $filename; ?>" AUTOSTART=TRUE WIDTH=0 HEIGHT=0 LOOP=0><P/>');
+else
+ document.writeln('<BGSOUND SRC="<?php echo $filename; ?>" LOOP=0/>');
// -->
</SCRIPT>
<NOSCRIPT>
- <BGSOUND SRC="'.$filename.'"/>
-</NOSCRIPT>';
+ <BGSOUND SRC="<?php echo $filename; ?>"/>
+</NOSCRIPT>
+<?php
}
// The hash has form <md5sum of triggerid>,<sum of priorities>
@@ -380,7 +320,7 @@ document.writeln(snd_tag);
while($row=DBfetch($result))
{
- $ack = get_last_alarm_by_triggerid($row["triggerid"]);
+ $ack = get_last_event_by_triggerid($row["triggerid"]);
if($ack["acknowledged"] == 1) continue;
$triggerids="$triggerids,".$row["triggerid"];
@@ -395,44 +335,9 @@ document.writeln(snd_tag);
return "$priorities,$md5sum";
}
- function get_dbid($table,$field)
- {
- global $ZBX_CURNODEID;
-
- $sql="select max($field) as id from $table where mod($field,100)=$ZBX_CURNODEID";
- $result=DBselect($sql);
- $row=DBfetch($result);
- if($row && !is_null($row["id"]))
- {
- return $row["id"]+100;
- }
- else
- {
- return 100+$ZBX_CURNODEID;
- }
- }
-
- function get_function_by_functionid($functionid)
- {
- $sql="select * from functions where functionid=$functionid";
- $result=DBselect($sql);
- $row=DBfetch($result);
- if($row)
- {
- return $row;
- }
- else
- {
- error("No function with functionid=[$functionid]");
- }
- return $item;
- }
-
function select_config()
{
- $sql="select * from config";
- $result=DBselect($sql);
- $row=DBfetch($result);
+ $row=DBfetch(DBselect("select * from config"));
if($row)
{
return $row;
@@ -444,56 +349,121 @@ document.writeln(snd_tag);
return $row;
}
- function show_infomsg()
+ function show_messages($bool=TRUE,$okmsg=NULL,$errmsg=NULL)
{
- global $INFO_MSG;
global $ERROR_MSG;
- if(is_array($INFO_MSG) && count($INFO_MSG)>0)
- {
- echo "<p align=center class=\"info\">";
- while($val = array_shift($INFO_MSG))
- {
- echo $val.BR;
- }
- echo "</p>";
- }
- }
+ global $INFO_MSG;
+ global $page;
- function show_messages($bool=TRUE,$msg=NULL,$errmsg=NULL)
- {
- global $ERROR_MSG;
+ if(!isset($page["type"])) $page["type"] = PAGE_TYPE_HTML;
- if(!$bool)
- {
- if(!is_null($errmsg))
- $msg="ERROR:".$errmsg;
+ $message = array();
+ $width = 0;
+ $height= 0;
- $color="#AA0000";
- }
- else
- {
- $color="#223344";
- }
+ if(!$bool && !is_null($errmsg)) $msg="ERROR: ".$errmsg;
+ else if($bool && !is_null($okmsg)) $msg=$okmsg;
if(isset($msg))
{
- echo "<p align=center>";
- echo "<font color='$color'>";
- echo "<b>[$msg]</b>";
- echo "</font>";
- echo "</p>";
+ switch($page["type"])
+ {
+ case PAGE_TYPE_IMAGE:
+ array_push($message, array(
+ 'text' => $msg,
+ 'color' => (!$bool) ? array('R'=>255,'G'=>0,'B'=>0) : array('R'=>34,'G'=>51,'B'=>68),
+ 'font' => 4));
+ $width = max($width, ImageFontWidth(4) * strlen($msg) + 1);
+ $height += imagefontheight(4) + 1;
+ break;
+ case PAGE_TYPE_HTML:
+ default:
+ echo "<p align=center>";
+ echo "<font color='".((!$bool) ? "#AA0000" : "#223344")."'>";
+ echo "<b>[".htmlspecialchars($msg)."]</b>";
+ echo "</font>";
+ echo "</p>";
+ break;
+ }
}
- show_infomsg();
+ if(is_array($INFO_MSG) && count($INFO_MSG)>0)
+ {
+ switch($page["type"])
+ {
+ case PAGE_TYPE_IMAGE:
+ while($val = array_shift($INFO_MSG))
+ {
+ array_push($message, array(
+ 'text' => $val,
+ 'color' => array('R'=>155,'G'=>155,'B'=>55),
+ 'font' => 2));
+ $width = max($width, ImageFontWidth(2) * strlen($val) + 1);
+ $height += imagefontheight(2) + 1;
+ }
+ break;
+ case PAGE_TYPE_HTML:
+ echo "<p align=center class=\"info\">";
+ while($val = array_shift($INFO_MSG))
+ {
+ echo htmlspecialchars($val).BR;
+ }
+ echo "</p>";
+ break;
+ }
+ }
if(is_array($ERROR_MSG) && count($ERROR_MSG)>0)
{
- echo "<p align=center class=\"error\">";
- while($val = array_shift($ERROR_MSG))
+ switch($page["type"])
{
- echo $val.BR;
+ case PAGE_TYPE_IMAGE:
+ while($val = array_shift($ERROR_MSG))
+ {
+ array_push($message, array(
+ 'text' => $val,
+ 'color' => array('R'=>255,'G'=>55,'B'=>55),
+ 'font' => 2));
+ $width = max($width, ImageFontWidth(2) * strlen($val) + 1);
+ $height += imagefontheight(2) + 1;
+ }
+ break;
+ case PAGE_TYPE_HTML:
+ echo "<p align=center class=\"error\">";
+ while($val = array_shift($ERROR_MSG))
+ {
+ echo htmlspecialchars($val).BR;
+ }
+ echo "</p>";
+ break;
}
- echo "</p>";
+ }
+
+ if($page["type"] == PAGE_TYPE_IMAGE && count($message) > 0)
+ {
+ $width += 2;
+ $height += 2;
+ $canvas = imagecreate($width, $height);
+ ImageFilledRectangle($canvas,0,0,$width,$height, ImageColorAllocate($canvas, 255, 255, 255));
+
+ foreach($message as $id => $msg)
+ {
+ $message[$id]['y'] = 1 + (isset($previd) ? $message[$previd]['y'] + $message[$previd]['h'] : 0 );
+ $message[$id]['h'] = imagefontheight($msg['font']);
+
+ ImageString(
+ $canvas,
+ $msg['font'],
+ 1,
+ $message[$id]['y'],
+ $msg['text'],
+ ImageColorAllocate($canvas, $msg['color']['R'], $msg['color']['G'], $msg['color']['B'])
+ );
+
+ $previd = $id;
+ }
+ ImageOut($canvas);
+ ImageDestroy($canvas);
}
}
@@ -631,14 +601,6 @@ document.writeln(snd_tag);
function validate_period(&$str)
{
-/* // simple check
- $per_expr = '[1-7]-[1-7],[0-9]{1,2}:[0-9]{1,2}-[0-9]{1,2}:[0-9]{1,2}';
- $regexp = '^'.$per_expr.'(;'.$per_expr.')*[;]?$';
- if(!ereg($regexp, $str, $arr))
- return -1;
-
- return 0;
-*/
$str = trim($str,';');
$out = "";
$periods = split(';',$str);
@@ -772,350 +734,6 @@ document.writeln(snd_tag);
}
return 0;
}
-/*
- function validate_expression($expression)
- {
-// echo "Validating expression: $expression<br>";
-
- $ok=0;
-// Replace all {server:key.function(param)} with 0
- while($ok==0)
- {
-// echo "Expression:$expression<br>";
- $arr="";
- if (eregi('^((.)*)[ ]*(\{((.)*)\})[ ]*((.)*)$', $expression, $arr))
- {
-// for($i=0;$i<20;$i++)
-// {
-// if($arr[$i])
-// echo " $i: ",$arr[$i],"<br>";
-// }
- if(validate_simple_expression($arr[3])!=0)
- {
- return -1;
- }
- $expression=$arr[1]."0".$arr[6];
- }
- else
- {
- $ok=1;
- }
- }
-// echo "Result:$expression<br><hr>";
-
- $ok=0;
- while($ok==0)
- {
-// Replace all <float> <sign> <float> <K|M|G> with 0
-// echo "Expression:$expression<br>";
- $arr="";
- if (eregi('^((.)*)([0-9\.]+[A-Z]{0,1})[ ]*([\&\|\>\<\=\+\-\*\/\#]{1})[ ]*([0-9\.]+[A-Z]{0,1})((.)*)$', $expression, $arr))
- {
-// echo "OK<br>";
-// for($i=0;$i<50;$i++)
-// {
-// if($arr[$i]!="")
-// echo " $i: ",$arr[$i],"<br>";
-// }
- if(validate_float($arr[3])!=0)
- {
- error("[".$arr[3]."] is not a float");
- return -1;
- }
- if(validate_float($arr[5])!=0)
- {
- error("[".$arr[5]."] is not a float");
- return -1;
- }
- $expression=$arr[1]."(0)".$arr[6];
- }
- else
- {
- $ok=1;
- }
-
-
-// Replace all (float) with 0
-// echo "Expression2:[$expression]<br>";
- $arr="";
- if (eregi('^((.)*)(\(([ 0-9\.]+)\))((.)*)$', $expression, $arr))
- {
-// echo "OK<br>";
-// for($i=0;$i<30;$i++)
-// {
-// if($arr[$i]!="")
-// echo " $i: ",$arr[$i],"<br>";
-// }
- if(validate_float($arr[4])!=0)
- {
- error("[".$arr[4]."] is not a float");
- return -1;
- }
- $expression=$arr[1]."0".$arr[5];
- $ok=0;
- }
- else
- {
- $ok=1;
- }
-
-
-
- }
-// echo "Result:$expression<br><hr>";
-
- if($expression=="0")
- {
- return 0;
- }
-
- return 1;
- }
-/**/
-
- function cr()
- {
- echo "\n";
- }
-
- # Header for HTML pages
-
- function show_header($title,$dorefresh=0,$nomenu=0,$noauth=0)
- {
- global $page;
- global $USER_DETAILS;
-COpt::profiling_start("page");
-
- if($noauth==0)
- {
- global $TRANSLATION;
- if(!isset($TRANSLATION) || !is_array($TRANSLATION)) $TRANSLATION = array();
-
- check_authorisation();
- include_once "include/locales/".$USER_DETAILS["lang"].".inc.php";
- process_locales();
- }
- include_once "include/locales/en_gb.inc.php";
- process_locales();
-?>
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=<?php echo S_HTML_CHARSET; ?>">
-<meta name="Author" content="ZABBIX SIA (Alexei Vladishev, Eugene Grigorjev)">
-<link rel="stylesheet" href="css.css">
-<?php
-// if($USER_DETAILS['alias']=='guest')
-// {
-// $refresh=2*$refresh;
-// }
- if(defined($title)) $title=constant($title);
- if($dorefresh && $USER_DETAILS["refresh"])
- {
- echo " <meta http-equiv=\"refresh\" content=\"".$USER_DETAILS["refresh"]."\">\n";
- echo " <title>$title [refreshed every ".$USER_DETAILS["refresh"]." sec]</title>\n";
- }
- else
- {
- echo " <title>$title</title>\n";
- }
-
-?>
-</head>
-<body>
-<?php
- if($nomenu == 0)
- {
- $menu=array(
- "view"=>array(
- "label"=>S_MONITORING,
- "pages"=>array("overview.php","latest.php","tr_status.php","queue.php","events.php","actions.php","maps.php","charts.php","screens.php","srv_status.php","alarms.php","history.php","tr_comments.php","report3.php","profile.php","acknow.php"),
- "level2"=>array(
- array("label"=>S_OVERVIEW,"url"=>"overview.php"),
- array("label"=>S_LATEST_DATA,"url"=>"latest.php"),
- array("label"=>S_TRIGGERS,"url"=>"tr_status.php"),
- array("label"=>S_QUEUE,"url"=>"queue.php"),
- array("label"=>S_EVENTS,"url"=>"events.php"),
- array("label"=>S_ACTIONS,"url"=>"actions.php"),
- array("label"=>S_MAPS,"url"=>"maps.php"),
- array("label"=>S_GRAPHS,"url"=>"charts.php"),
- array("label"=>S_SCREENS,"url"=>"screens.php"),
- array("label"=>S_IT_SERVICES,"url"=>"srv_status.php")
- )
- ),
- "cm"=>array(
- "label"=>S_INVENTORY,
- "pages"=>array("hostprofiles.php"),
- "level2"=>array(
- array("label"=>S_HOSTS,"url"=>"hostprofiles.php")
- )
- ),
- "reports"=>array(
- "label"=>S_REPORTS,
- "pages"=>array("report1.php","report2.php","report4.php","report5.php"),
- "level2"=>array(
- array("label"=>S_STATUS_OF_ZABBIX,"url"=>"report1.php"),
- array("label"=>S_AVAILABILITY_REPORT,"url"=>"report2.php"),
- array("label"=>S_NOTIFICATIONS,"url"=>"report4.php"),
- array("label"=>S_TRIGGERS_TOP_100,"url"=>"report5.php"),
- )
- ),
- "configuration"=>array(
- "label"=>S_CONFIGURATION,
- "pages"=>array("config.php","users.php","audit.php","hosts.php","items.php","triggers.php","sysmaps.php","graphs.php","screenconf.php","services.php","sysmap.php","media.php","screenedit.php","graph.php","actionconf.php","bulkloader.php"),
- "level2"=>array(
- array("label"=>S_GENERAL,"url"=>"config.php"),
- array("label"=>S_USERS,"url"=>"users.php"),
- array("label"=>S_AUDIT,"url"=>"audit.php"),
- array("label"=>S_HOSTS,"url"=>"hosts.php"),
- array("label"=>S_ITEMS,"url"=>"items.php"),
- array("label"=>S_TRIGGERS,"url"=>"triggers.php"),
- array("label"=>S_ACTIONS,"url"=>"actionconf.php"),
- array("label"=>S_MAPS,"url"=>"sysmaps.php"),
- array("label"=>S_GRAPHS,"url"=>"graphs.php"),
- array("label"=>S_SCREENS,"url"=>"screenconf.php"),
- array("label"=>S_IT_SERVICES,"url"=>"services.php"),
- array("label"=>S_MENU_BULKLOADER,"url"=>"bulkloader.php")
- )
- ),
- "login"=>array(
- "label"=>S_LOGIN,
- "pages"=>array("index.php"),
- "level2"=>array(
- array("label"=>S_LOGIN,"url"=>"index.php"),
- )
- ),
- );
-
- $table = new CTable(NULL,"page_header");
- $table->SetCellSpacing(0);
- $table->SetCellPadding(5);
-
- $help = new CLink(S_HELP, "http://www.zabbix.com/manual/v1.1/index.php", "small_font");
- $help->SetTarget('_blank');
- $col_r = array($help);
- if($USER_DETAILS["alias"]!="guest") {
- array_push($col_r, "|");
- array_push($col_r, new CLink(S_PROFILE, "profile.php", "small_font"));
- }
-
- $logo = new CLink(new CImg("images/general/zabbix.png","ZABBIX"),"http://www.zabbix.com");
- $logo->SetTarget('_blank');
- $table->AddRow(array(new CCol($logo, "page_header_l"), new CCol($col_r, "page_header_r")));
-
- $table->Show();
-?>
-
-<table class="menu" cellspacing=0 cellpadding=5>
-<tr>
-<?php
- $i=0;
- foreach($menu as $label=>$sub)
- {
-// Check permissions
- if($label=="configuration")
- {
- if( !check_anyright("Configuration of Zabbix","U")
- &&!check_anyright("User","U")
- &&!check_anyright("Host","U")
- &&!check_anyright("Item","U")
- &&!check_anyright("Graph","U")
- &&!check_anyright("Screen","U")
- &&!check_anyright("Network map","U")
- &&!check_anyright("Service","U")
- )
- {
- continue;
- }
- if( !check_anyright("Default permission","R")
- &&!check_anyright("Host","R")
- )
- {
- continue;
- }
-
- }
-// End of check permissions
- $active=0;
- foreach($sub["pages"] as $label2)
- {
- if($page["file"]==$label2)
- {
- $active=1;
- $active_level1=$label;
- }
- }
- if($i==0) $url=get_profile("web.menu.view.last",0);
- else if($i==1) $url=get_profile("web.menu.cm.last",0);
- else if($i==2) $url=get_profile("web.menu.reports.last",0);
- else if($i==3) $url=get_profile("web.menu.config.last",0);
- else if($i==4) $url="0";
-
- if($url=="0") $url=$sub["level2"][0]["url"];
- if($active==1)
- {
- global $page;
- $class = "horizontal_menu";
- if(isset($page["menu.url"]))
- $url = $page["menu.url"];
- else
- $url = $page["file"];
- }
- else
- {
- $class = "horizontal_menu_n";
- }
-
- echo "<td class=\"$class\" height=24 colspan=9><b><a href=\"$url\" class=\"highlight\">".$sub["label"]."</a></b></td>\n";
- $i++;
- }
-?>
-</tr>
-</table>
-
-<table class="menu" width="100%" cellspacing=0 cellpadding=5>
-<tr><td class="horizontal_menu" height=24 colspan=9><b>
-<?php
- if(isset($active_level1))
- foreach($menu[$active_level1]["level2"] as $label=>$sub)
- {
-// Check permissions
- if(($sub["url"]=="latest.php")&&!check_anyright("Host","R")) continue;
- if(($sub["url"]=="overview.php")&&!check_anyright("Host","R")) continue;
- if(($sub["url"]=="tr_status.php?onlytrue=true&noactions=true&compact=true")&&!check_anyright("Host","R")) continue;
- if(($sub["url"]=="queue.php")&&!check_anyright("Host","R")) continue;
- if(($sub["url"]=="events.php")&&!check_anyright("Default permission","R")) continue;
- if(($sub["url"]=="actions.php")&&!check_anyright("Default permission","R")) continue;
- if(($sub["url"]=="maps.php")&&!check_anyright("Network map","R")) continue;
- if(($sub["url"]=="charts.php")&&!check_anyright("Graph","R")) continue;
- if(($sub["url"]=="screens.php")&&!check_anyright("Screen","R")) continue;
- if(($sub["url"]=="srv_status.php")&&!check_anyright("Service","R")) continue;
- if(($sub["url"]=="report1.php")&&!check_anyright("Default permission","R")) continue;
- if(($sub["url"]=="report2.php")&&!check_anyright("Host","R")) continue;
- if(($sub["url"]=="config.php")&&!check_anyright("Configuration of Zabbix","U")) continue;
- if(($sub["url"]=="users.php")&&!check_anyright("User","U")) continue;
- if(($sub["url"]=="media.php")&&!check_anyright("User","U")) continue;
- if(($sub["url"]=="audit.php")&&!check_anyright("Audit","U")) continue;
- if(($sub["url"]=="hosts.php")&&!check_anyright("Host","U")) continue;
- if(($sub["url"]=="items.php")&&!check_anyright("Item","U")) continue;
- if(($sub["url"]=="triggers.php")&&!check_anyright("Host","U")) continue;
- if(($sub["url"]=="sysmaps.php")&&!check_anyright("Network map","U")) continue;
- if(($sub["url"]=="sysmap.php")&&!check_anyright("Network map","U")) continue;
- if(($sub["url"]=="graphs.php")&&!check_anyright("Graph","U")) continue;
- if(($sub["url"]=="graph.php")&&!check_anyright("Graph","U")) continue;
- if(($sub["url"]=="screenedit.php")&&!check_anyright("Screen","U")) continue;
- if(($sub["url"]=="screenconf.php")&&!check_anyright("Screen","U")) continue;
- if(($sub["url"]=="services.php")&&!check_anyright("Service","U")) continue;
-
- echo "<a href=\"".$sub["url"]."\" class=\"highlight\">".$sub["label"]."</a><span class=\"divider\">".SPACE.SPACE."|".SPACE."</span>\n";
- }
-?>
-</b></td></tr>
-</table>
-<br/>
-<?php
- }
- }
# Show screen cell containing plain text values
function& get_screen_plaintext($itemid,$elements)
@@ -1172,293 +790,12 @@ COpt::profiling_start("page");
return $table;
}
- function get_image_by_name($name,$imagetype=NULL)
- {
- global $DB_TYPE;
-
- $sql="select image from images where name=".zbx_dbstr($name);
- if(isset($imagetype))
- $sql .= "and imagetype=".$imagetype;
-
- $result=DBselect($sql);
- $row=DBfetch($result);
- if($row)
- {
- if($DB_TYPE == "ORACLE")
- {
- if(!isset($row['image']))
- return 0;
-
- $row['image'] = $row['image']->load();
- }
- else if($DB_TYPE == "POSTGRESQL")
- {
- $row['image'] = pg_unescape_bytea($row['image']);
- }
-
- return $row;
- }
- else
- {
- return 0;
- }
- }
-
- function get_image_by_imageid($imageid)
- {
- global $DB_TYPE;
-
- $result=DBselect('select * from images where imageid='.$imageid);
- $row=DBfetch($result);
- if($row)
- {
- if($DB_TYPE == "ORACLE")
- {
- if(!isset($row['image']))
- return 0;
-
- $row['image'] = $row['image']->load();
- }
- else if($DB_TYPE == "POSTGRESQL")
- {
- $row['image'] = pg_unescape_bytea($row['image']);
-//SDI($row['image']);
- }
- return $row;
- }
- else
- {
- return 0;
- }
- }
-
- function add_image($name,$imagetype,$file)
- {
- global $DB_TYPE;
- global $DB;
-
- if(!is_null($file))
- {
- if($file["error"] != 0 || $file["size"]==0)
- {
- error("Incorrect Image");
- return FALSE;
- }
- if($file["size"]<1024*1024)
- {
- $image=fread(fopen($file["tmp_name"],"r"),filesize($file["tmp_name"]));
- if($DB_TYPE == "ORACLE")
- {
- $lobimage = OCINewDescriptor($DB, OCI_D_LOB);
-
- $imageid=get_dbid("images","imageid");
-
- $sql = "insert into images (imageid,name,imagetype,image)".
- " values ($imageid,".zbx_dbstr($name).",".$imagetype.",EMPTY_BLOB())".
- " return image into :image";
- $stid = OCIParse($DB, $sql);
- if(!$stid)
- {
- $e = ocierror($stid);
- error("Parse SQL error [".$e["message"]."] in [".$e["sqltext"]."]");
- return false;
- }
-
- OCIBindByName($stid, ':image', $lobimage, -1, OCI_B_BLOB);
-
- $result = OCIExecute($stid, OCI_DEFAULT);
- if(!$result){
- $e = ocierror($stid);
- error("Execute SQL error [".$e["message"]."] in [".$e["sqltext"]."]");
- return false;
- }
-
- if ($lobimage->save($image)) {
- OCICommit($DB);
- }
- else {
- OCIRollback($DB);
- error("Couldn't save image!\n");
- return false;
- }
-
- $lobimage->free();
- OCIFreeStatement($stid);
-
- return $stid;
- }
- else if($DB_TYPE == "POSTGRESQL")
- {
- $image = pg_escape_bytea($image);
-
- $sql = "insert into images (name,imagetype,image)".
- " values (".zbx_dbstr($name).",".$imagetype.",'".$image."')";
- return DBexecute($sql);
- }
- $sql = "insert into images (name,imagetype,image)".
- " values (".zbx_dbstr($name).",".$imagetype.",".zbx_dbstr($image).")";
- return DBexecute($sql);
- }
- else
- {
- error("Image size must be less than 1Mb");
- return false;
- }
- }
- else
- {
- error("Select image to download");
- return false;
- }
- }
-
- function update_image($imageid,$name,$imagetype,$file)
- {
- global $DB_TYPE;
- global $DB;
-
- if(!is_null($file))
- {
- if($file["error"] != 0 || $file["size"]==0)
- {
- error("Incorrect Image");
- return FALSE;
- }
- if($file["size"]<1024*1024)
- {
- $image=fread(fopen($file["tmp_name"],"r"),filesize($file["tmp_name"]));
-
- if($DB_TYPE == "ORACLE")
- {
-
- $result = DBexecute("update images set name=".zbx_dbstr($name).
- ",imagetype=".zbx_dbstr($imagetype).
- " where imageid=$imageid");
-
- if(!$result) return $result;
-
- $stid = OCIParse($DB, "select image from images where imageid=".$imageid." for update");
-
- $result = OCIExecute($stid, OCI_DEFAULT);
- if(!$result){
- $e = ocierror($stid);
- error("Execute SQL error [".$e["message"]."] in [".$e["sqltext"]."]");
- OCIRollback($DB);
- return false;
- }
-
- $row = DBfetch($stid);
-
- $lobimage = $row['image'];
-
-// if (!($lobimage->erase()))
-// {
-// OCIRollback($DB);
-// error("Failed to truncate LOB\n");
-// return false;
-// }
-
- if (!$lobimage->save($image)) {
- OCIRollback($DB);
- } else {
- OCICommit($DB);
- }
-
- $lobimage->free();
-
- return $stid;
- }
- else if($DB_TYPE == "POSTGRESQL")
- {
- $image = pg_escape_bytea($image);
- $sql="update images set name=".zbx_dbstr($name).",imagetype=".zbx_dbstr($imagetype).
- ",image='".$image."' where imageid=$imageid";
- return DBexecute($sql);
- }
-
- $sql="update images set name=".zbx_dbstr($name).",imagetype=".zbx_dbstr($imagetype).
- ",image=".zbx_dbstr($image)." where imageid=$imageid";
- return DBexecute($sql);
- }
- else
- {
- error("Image size must be less than 1Mb");
- return FALSE;
- }
- }
- else
- {
- $sql="update images set name=".zbx_dbstr($name).",imagetype=".zbx_dbstr($imagetype)." where imageid=$imageid";
- return DBexecute($sql);
- }
- }
-
- function delete_image($imageid)
- {
- $sql="delete from images where imageid=$imageid";
- return DBexecute($sql);
- }
-
- # Delete Alert by actionid
-
- function delete_alert_by_actionid( $actionid )
- {
- $sql="delete from alerts where actionid=$actionid";
- return DBexecute($sql);
- }
-
- function delete_rights_by_userid($userid )
- {
- $sql="delete from rights where userid=$userid";
- return DBexecute($sql);
- }
-
- # Delete from History
-
- function delete_history_by_itemid($itemid, $use_housekeeper=0)
- {
- $result = delete_trends_by_itemid($itemid,$use_housekeeper);
- if(!$result) return $result;
-
- if($use_housekeeper)
- {
- DBexecute("insert into housekeeper (tablename,field,value)".
- " values ('history_log','itemid',$itemid)");
- DBexecute("insert into housekeeper (tablename,field,value)".
- " values ('history_uint','itemid',$itemid)");
- DBexecute("insert into housekeeper (tablename,field,value)".
- " values ('history_str','itemid',$itemid)");
- DBexecute("insert into housekeeper (tablename,field,value)".
- " values ('history','itemid',$itemid)");
- return TRUE;
- }
-
- DBexecute("delete from history_log where itemid=$itemid");
- DBexecute("delete from history_uint where itemid=$itemid");
- DBexecute("delete from history_str where itemid=$itemid");
- DBexecute("delete from history where itemid=$itemid");
- return TRUE;
- }
-
- # Delete from Trends
-
- function delete_trends_by_itemid($itemid, $use_housekeeper=0)
- {
- if($use_housekeeper)
- {
- DBexecute("insert into housekeeper (tablename,field,value)".
- " values ('trends','itemid',$itemid)");
- return TRUE;
- }
- return DBexecute("delete from trends where itemid=$itemid");
- }
-
- # Add alarm
+ # Add event
- function get_alarm_by_alarmid($alarmid)
+ function get_event_by_eventid($eventid)
{
- $db_alarms = DBselect("select * from alarms where alarmid=$alarmid");
- return DBfetch($db_alarms);
+ $db_events = DBselect("select * from events where eventid=$eventid");
+ return DBfetch($db_events);
}
# Reset nextcheck for related items
@@ -1474,241 +811,19 @@ COpt::profiling_start("page");
}
}
- # Delete Media definition by mediatypeid
-
- function delete_media_by_mediatypeid($mediatypeid)
- {
- $sql="delete from media where mediatypeid=$mediatypeid";
- return DBexecute($sql);
- }
-
- # Delete alrtes by mediatypeid
-
- function delete_alerts_by_mediatypeid($mediatypeid)
- {
- $sql="delete from alerts where mediatypeid=$mediatypeid";
- return DBexecute($sql);
- }
-
- function get_mediatype_by_mediatypeid($mediatypeid)
- {
- $sql="select * from media_type where mediatypeid=$mediatypeid";
- $result=DBselect($sql);
- $row=DBfetch($result);
- if($row)
- {
- return $row;
- }
- else
- {
- error("No media type with with mediatypeid=[$mediatypeid]");
- }
- return $item;
- }
-
- # Delete media type
-
- function delete_mediatype($mediatypeid)
- {
-
- delete_media_by_mediatypeid($mediatypeid);
- delete_alerts_by_mediatypeid($mediatypeid);
- $sql="delete from media_type where mediatypeid=$mediatypeid";
- return DBexecute($sql);
- }
-
- # Update media type
-
- function update_mediatype($mediatypeid,$type,$description,$smtp_server,$smtp_helo,$smtp_email,$exec_path,$gsm_modem)
- {
- $ret = 0;
-
- $sql="select * from media_type where description=".zbx_dbstr($description)." and mediatypeid!=$mediatypeid";
- $result=DBexecute($sql);
- if(DBfetch($result))
- {
- error("An action type with description '$description' already exists.");
- }
- else
- {
- $sql="update media_type set type=$type,description=".zbx_dbstr($description).",smtp_server=".zbx_dbstr($smtp_server).",smtp_helo=".zbx_dbstr($smtp_helo).",smtp_email=".zbx_dbstr($smtp_email).",exec_path=".zbx_dbstr($exec_path).",gsm_modem=".zbx_dbstr($gsm_modem)." where mediatypeid=$mediatypeid";
- $ret = DBexecute($sql);
- }
- return $ret;
- }
-
- # Add Media type
-
- function add_mediatype($type,$description,$smtp_server,$smtp_helo,$smtp_email,$exec_path,$gsm_modem)
- {
- $ret = 0;
-
- if($description==""){
- error(S_INCORRECT_DESCRIPTION);
- return 0;
- }
-
- $sql="select * from media_type where description=".zbx_dbstr($description);
- $result=DBexecute($sql);
- if(DBfetch($result))
- {
- error("An action type with description '$description' already exists.");
- }
- else
- {
- $mediatypeid=get_dbid("media_type","mediatypeid");
- $sql="insert into media_type (mediatypeid,type,description,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem) values ($mediatypeid,$type,".zbx_dbstr($description).",".zbx_dbstr($smtp_server).",".zbx_dbstr($smtp_helo).",".zbx_dbstr($smtp_email).",".zbx_dbstr($exec_path).",".zbx_dbstr($gsm_modem).")";
- $ret = DBexecute($sql);
- if($ret) $ret = $mediatypeid;
- }
- return $ret;
- }
-
- # Add Media definition
-
- function add_media( $userid, $mediatypeid, $sendto, $severity, $active, $period)
- {
- if(validate_period($period) != 0)
- {
- error("Icorrect time period");
- return NULL;
- }
-
- $c=count($severity);
- $s=0;
- for($i=0;$i<$c;$i++)
- {
- $s=$s|pow(2,(int)$severity[$i]);
- }
- $mediaid=get_dbid("media","mediaid");
- $sql="insert into media (mediaid,userid,mediatypeid,sendto,active,severity,period) values ($mediaid,$userid,".zbx_dbstr($mediatypeid).",".zbx_dbstr($sendto).",$active,$s,".zbx_dbstr($period).")";
- $ret = DBexecute($sql);
- if($ret) $ret = $mediaid;
- return $ret;
- }
-
- # Update Media definition
-
- function update_media($mediaid, $userid, $mediatypeid, $sendto, $severity, $active, $period)
- {
- if(validate_period($period) != 0)
- {
- error("Icorrect time period");
- return NULL;
- }
-
- $c=count($severity);
- $s=0;
- for($i=0;$i<$c;$i++)
- {
- $s=$s|pow(2,(int)$severity[$i]);
- }
- $sql="update media set userid=$userid, mediatypeid=$mediatypeid, sendto=".zbx_dbstr($sendto).", active=$active,severity=$s,period=".zbx_dbstr($period)." where mediaid=$mediaid";
- return DBexecute($sql);
- }
-
- # Delete Media definition
-
- function delete_media($mediaid)
- {
- $sql="delete from media where mediaid=$mediaid";
- return DBexecute($sql);
- }
-
- # Delete Media definition by userid
-
- function delete_media_by_userid($userid)
- {
- $sql="delete from media where userid=$userid";
- return DBexecute($sql);
- }
-
- function delete_profiles_by_userid($userid)
- {
- $sql="delete from profiles where userid=$userid";
- return DBexecute($sql);
- }
-
# Update configuration
-// function update_config($smtp_server,$smtp_helo,$smtp_email,$alarm_history,$alert_history)
- function update_config($alarm_history,$alert_history,$refresh_unsupported,$work_period)
+ function update_config($event_history,$alert_history,$refresh_unsupported,$work_period)
{
- if(!check_right("Configuration of Zabbix","U",0))
- {
- error("Insufficient permissions");
- return 0;
- }
if(validate_period($work_period) != 0)
{
error("Icorrect work period");
return NULL;
}
-
-// $sql="update config set smtp_server='$smtp_server',smtp_helo='$smtp_helo',smtp_email='$smtp_email',alarm_history=$alarm_history,alert_history=$alert_history";
- $sql="update config set alarm_history=$alarm_history,alert_history=$alert_history,refresh_unsupported=$refresh_unsupported,".
- "work_period=".zbx_dbstr($work_period);
- return DBexecute($sql);
- }
-
-
- # Activate Media
-
- function activate_media($mediaid)
- {
- $sql="update media set active=0 where mediaid=$mediaid";
- return DBexecute($sql);
- }
-
- # Disactivate Media
-
- function disactivate_media($mediaid)
- {
- $sql="update media set active=1 where mediaid=$mediaid";
- return DBexecute($sql);
- }
-
- # Delete User permission
-
- function delete_permission($rightid)
- {
- $sql="delete from rights where rightid=$rightid";
- return DBexecute($sql);
- }
-
- # Delete User definition
-
- function delete_user($userid)
- {
- $sql="select * from users where userid=$userid and alias='guest'";
- $result=DBselect($sql);
- if(DBfetch($result))
- {
- error("Cannot delete user 'guest'");
- return 0;
- }
-
-
- delete_media_by_userid($userid);
- delete_actions_by_userid($userid);
- delete_rights_by_userid($userid);
- delete_profiles_by_userid($userid);
-
- // delete user permisions
- DBexecute('delete from rights where name=\'User\' and id='.$userid);
-
- $sql="delete from users_groups where userid=$userid";
- DBexecute($sql);
- $sql="delete from users where userid=$userid";
- return DBexecute($sql);
- }
-
- function show_header2($col1, $col2=SPACE, $before="", $after="")
- {
- echo $before;
- show_table_header($col1, $col2);
- echo $after;
+ return DBexecute("update config set event_history=$event_history,alert_history=$alert_history,".
+ " refresh_unsupported=$refresh_unsupported,".
+ " work_period=".zbx_dbstr($work_period));
}
function show_table_header($col1, $col2=SPACE)
@@ -1720,156 +835,6 @@ COpt::profiling_start("page");
$table->Show();
}
- function insert_time_navigator($itemid,$period,$from)
- {
- $descr=array("January","February","March","April","May","June",
- "July","August","September","October","November","December");
- $sql="select min(clock) as minn,max(clock) as maxx from history where itemid=$itemid";
- $result=DBselect($sql);
- $row=Dvfetch($result);
-
- if(!row)
- {
- $min=time(NULL);
- $max=time(NULL);
- }
- else
- {
- $min=$row["minn"];
- $max=$row["maxx"];
- }
-
- $now=time()-3600*$from-$period;
-
- $year_min=date("Y",$min);
- $year_max=date("Y",$max);
-
- $year_now=date("Y",$now);
- $month_now=date("m",$now);
- $day_now=date("d",$now);
- $hour_now=date("H",$now);
-
- echo "<form method=\"put\" action=\"history.php\">";
- echo "<input name=\"itemid\" type=\"hidden\" value=$itemid size=8>";
- echo "<input name=\"action\" type=\"hidden\" value=\"showgraph\" size=8>";
-
- echo "Year";
- echo "<select name=\"year\">";
- for($i=$year_min;$i<=$year_max;$i++)
- {
- if($i==$year_now)
- {
- echo "<option value=\"$i\" selected>$i";
- }
- else
- {
- echo "<option value=\"$i\">$i";
- }
- }
- echo "</select>";
-
- echo "Month";
- echo "<select name=\"month\">";
- for($i=1;$i<=12;$i++)
- {
- if($i==$month_now)
- {
- echo "<option value=\"$i\" selected>".$descr[$i-1];
- }
- else
- {
- echo "<option value=\"$i\">".$descr[$i-1];
- }
- }
- echo "</select>";
-
- echo "Day";
- echo "<select name=\"day\">";
- for($i=1;$i<=31;$i++)
- {
- if($i==$day_now)
- {
- echo "<option value=\"$i\" selected>$i";
- }
- else
- {
- echo "<option value=\"$i\">$i";
- }
- }
- echo "</select>";
-
- echo "Hour";
- echo "<select name=\"hour\">";
- for($i=0;$i<=23;$i++)
- {
- if($i==$hour_now)
- {
- echo "<option value=\"$i\" selected>$i";
- }
- else
- {
- echo "<option value=\"$i\">$i";
- }
- }
- echo "</select>";
-
- echo "Period:";
- echo "<select name=\"period\">";
- if($period==3600)
- {
- echo "<option value=\"3600\" selected>1 hour";
- }
- else
- {
- echo "<option value=\"3600\">1 hour";
- }
- if($period==10800)
- {
- echo "<option value=\"10800\" selected>3 hours";
- }
- else
- {
- echo "<option value=\"10800\">3 hours";
- }
- if($period==21600)
- {
- echo "<option value=\"21600\" selected>6 hours";
- }
- else
- {
- echo "<option value=\"21600\">6 hours";
- }
- if($period==86400)
- {
- echo "<option value=\"86400\" selected>24 hours";
- }
- else
- {
- echo "<option value=\"86400\">24 hours";
- }
- if($period==604800)
- {
- echo "<option value=\"604800\" selected>one week";
- }
- else
- {
- echo "<option value=\"604800\">one week";
- }
- if($period==2419200)
- {
- echo "<option value=\"2419200\" selected>one month";
- }
- else
- {
- echo "<option value=\"2419200\">one month";
- }
- echo "</select>";
-
- echo "<input class=\"button\" type=\"submit\" name=\"action\" value=\"showgraph\">";
-
- echo "</form>";
- }
-
# Show History Graph
function show_history($itemid,$from,$period)
@@ -1903,36 +868,6 @@ COpt::profiling_start("page");
echo "</center>";
}
- function show_page_footer()
- {
- global $USER_DETAILS;
-
- show_messages();
-
- echo BR;
- $table = new CTable(NULL,"page_footer");
- $table->SetCellSpacing(0);
- $table->SetCellPadding(1);
- $table->AddRow(array(
- new CCol(new CLink(
- S_ZABBIX_VER.SPACE.S_COPYRIGHT_BY.SPACE.S_SIA_ZABBIX,
- "http://www.zabbix.com", "highlight"),
- "page_footer_l"),
- new CCol(array(
- new CSpan(SPACE.SPACE."|".SPACE.SPACE,"divider"),
- S_CONNECTED_AS.SPACE.$USER_DETAILS["alias"]
- ),
- "page_footer_r")
- ));
- $table->Show();
-
-COpt::profiling_stop("page");
-COpt::profiling_stop("script");
-
- echo "</body>\n";
- echo "</html>\n";
- }
-
function get_status()
{
global $DB_TYPE;
@@ -1977,9 +912,9 @@ COpt::profiling_stop("script");
$row=DBfetch($result);
$status["trends_count"]=$row["cnt"];
}
-// alarms
- $row=DBfetch(DBselect("select count(alarmid) as cnt from alarms"));
- $status["alarms_count"]=$row["cnt"];
+// events
+ $row=DBfetch(DBselect("select count(eventid) as cnt from events"));
+ $status["events_count"]=$row["cnt"];
// alerts
$row=DBfetch(DBselect("select count(alertid) as cnt from alerts"));
$status["alerts_count"]=$row["cnt"];
@@ -2045,150 +980,6 @@ COpt::profiling_stop("script");
return $status;
}
- // If $period_start=$period_end=0, then take maximum period
- function calculate_availability($triggerid,$period_start,$period_end)
- {
- if(($period_start==0)&&($period_end==0))
- {
- $sql="select count(*) as cnt,min(clock) as minn,max(clock) as maxx from alarms where triggerid=$triggerid";
- }
- else
- {
- $sql="select count(*) as cnt,min(clock) as minn,max(clock) as maxx from alarms where triggerid=$triggerid and clock>=$period_start and clock<=$period_end";
- }
-// echo $sql,"<br>";
-
-
- $result=DBselect($sql);
- $row=DBfetch($result);
- if($row["cnt"]>0)
- {
- $min=$row["minn"];
- $max=$row["maxx"];
- }
- else
- {
- if(($period_start==0)&&($period_end==0))
- {
- $max=time();
- $min=$max-24*3600;
- }
- else
- {
- $ret["true_time"]=0;
- $ret["false_time"]=0;
- $ret["unknown_time"]=0;
- $ret["true"]=0;
- $ret["false"]=0;
- $ret["unknown"]=100;
- return $ret;
- }
- }
-
- $sql="select clock,value from alarms where triggerid=$triggerid and clock>=$min and clock<=$max";
-// echo " $sql<br>";
- $result=DBselect($sql);
-
-// echo $sql,"<br>";
-
-// -1,0,1
- $state=-1;
- $true_time=0;
- $false_time=0;
- $unknown_time=0;
- $time=$min;
- if(($period_start==0)&&($period_end==0))
- {
- $max=time();
- }
- $rows=0;
- while($row=DBfetch($result))
- {
- $clock=$row["clock"];
- $value=$row["value"];
-
- $diff=$clock-$time;
-
- $time=$clock;
-
- if($state==-1)
- {
- $state=$value;
- if($state == 0)
- {
- $false_time+=$diff;
- }
- if($state == 1)
- {
- $true_time+=$diff;
- }
- if($state == 2)
- {
- $unknown_time+=$diff;
- }
- }
- else if($state==0)
- {
- $false_time+=$diff;
- $state=$value;
- }
- else if($state==1)
- {
- $true_time+=$diff;
- $state=$value;
- }
- else if($state==2)
- {
- $unknown_time+=$diff;
- $state=$value;
- }
- $rows++;
- }
-
- if($rows==0)
- {
- $false_time=$max-$min;
- }
- else
- {
- if($state==0)
- {
- $false_time=$false_time+$max-$time;
- }
- elseif($state==1)
- {
- $true_time=$true_time+$max-$time;
- }
- elseif($state==3)
- {
- $unknown_time=$unknown_time+$max-$time;
- }
-
- }
-// echo "$true_time $false_time $unknown_time";
-
- $total_time=$true_time+$false_time+$unknown_time;
- if($total_time==0)
- {
- $ret["true_time"]=0;
- $ret["false_time"]=0;
- $ret["unknown_time"]=0;
- $ret["true"]=0;
- $ret["false"]=0;
- $ret["unknown"]=100;
- }
- else
- {
- $ret["true_time"]=$true_time;
- $ret["false_time"]=$false_time;
- $ret["unknown_time"]=$unknown_time;
- $ret["true"]=(100*$true_time)/$total_time;
- $ret["false"]=(100*$false_time)/$total_time;
- $ret["unknown"]=(100*$unknown_time)/$total_time;
- }
- return $ret;
- }
-
function get_resource_name($permission,$id)
{
$res="-";
@@ -2301,6 +1092,13 @@ COpt::profiling_stop("script");
return ($var == "" ? 0 : 1);
}
+ function get_cookie($name, $default_value)
+ {
+ if(isset($_COOKIE[$name])) return $_COOKIE[$name];
+ // else
+ return $default_value;
+ }
+
function get_profile($idx,$default_value,$type=PROFILE_TYPE_UNCNOWN)
{
global $USER_DETAILS;
@@ -2354,16 +1152,13 @@ COpt::profiling_stop("script");
default: $value = strval($value);
}
-
- $sql="select value from profiles where userid=".$USER_DETAILS["userid"]." and idx=".zbx_dbstr($idx);
-// echo $sql."<br>";
- $result=DBselect($sql);
- $row=DBfetch($result);
+ $row = DBfetch(DBselect("select value from profiles where userid=".$USER_DETAILS["userid"]." and idx=".zbx_dbstr($idx)));
if(!$row)
{
- $sql="insert into profiles (userid,idx,value,valuetype)".
- " values (".$USER_DETAILS["userid"].",".zbx_dbstr($idx).",".zbx_dbstr($value).",".$type.")";
+ $profileid = get_dbid('profiles', 'profileid');
+ $sql="insert into profiles (profileid,userid,idx,value,valuetype)".
+ " values (".$profileid.",".$USER_DETAILS["userid"].",".zbx_dbstr($idx).",".zbx_dbstr($value).",".$type.")";
DBexecute($sql);
}
else
@@ -2389,11 +1184,129 @@ COpt::profiling_stop("script");
return "Unknown";
}
+$SHOW_HINT_SCRIPT_ISERTTED = false; /* TODO rewrite with JS include */
+
+ function insert_showhint_javascript()
+ {
+ global $SHOW_HINT_SCRIPT_ISERTTED;
+
+ if($SHOW_HINT_SCRIPT_ISERTTED) return;
+ $SHOW_HINT_SCRIPT_ISERTTED = true;
+?>
+<script language="JavaScript" type="text/javascript">
+<!--
+
+function GetPos(obj)
+{
+ var left = obj.offsetLeft;
+ var top = obj.offsetTop;;
+ while (obj = obj.offsetParent)
+ {
+ left += obj.offsetLeft
+ top += obj.offsetTop
+ }
+ return [left,top];
+}
+
+var hint_box = null;
+
+function hide_hint()
+{
+ if(!hint_box) return;
+
+ hint_box.style.visibility="hidden"
+ //hint_box.style.width = "0px"
+ hint_box.style.left = "-" + hint_box.style.width;
+}
+
+function show_hint(obj, hint_text)
+{
+ show_hint_ext(obj, hint_text, "", "");
+}
+
+function show_hint_ext(obj, hint_text, width, class)
+{
+ if(!hint_box) return;
+
+ if(class != "")
+ {
+ hint_text = "<span class=" + class + ">" + hint_text + "</span>";
+ }
+
+ hint_box.innerHTML = hint_text;
+ hint_box.style.width = width;
+
+ var pos = GetPos(obj);
+
+ hint_box.x = pos[0];
+ hint_box.y = pos[1];
+
+ hint_box.style.left = hint_box.x + obj.offsetWidth + 10 + "px";
+ hint_box.style.top = hint_box.y + obj.offsetHeight + "px";
+
+ hint_box.style.visibility = "visible";
+ obj.onmouseout = hide_hint;
+}
+
+function create_hint_box()
+{
+ if(hint_box) return;
+
+ hint_box = document.createElement("div");
+ hint_box.setAttribute("id", "hint_box");
+ document.body.appendChild(hint_box);
+
+ hide_hint();
+}
+
+if (window.addEventListener)
+{
+ window.addEventListener("load", create_hint_box, false);
+}
+else if (window.attachEvent)
+{
+ window.attachEvent("onload", create_hint_box);
+}
+else if (document.getElementById)
+{
+ window.onload = create_hint_box;
+}
+//-->
+</script>
+<?php
+ }
+
function insert_confirm_javascript()
{
- echo "
-<script language=\"JavaScript\" type=\"text/javascript\">
+?>
+<script language="JavaScript" type="text/javascript">
<!--
+ function Redirect(url) {
+ window.location = url;
+ return false;
+ }
+
+ function create_var(form_name, var_name, var_val, submit)
+ {
+ var frmForm = document.forms[form_name];
+
+ if(!frmForm) return false;
+
+ var objVar = document.createElement('input');
+
+ if(!objVar) return false;
+
+ objVar.setAttribute('type', 'hidden');
+ objVar.setAttribute('name', var_name);
+ objVar.setAttribute('value', var_val);
+
+ frmForm.appendChild(objVar);
+ if(submit)
+ frmForm.submit();
+
+ return false;
+ }
+
function Confirm(msg)
{
if(confirm(msg,'title'))
@@ -2401,11 +1314,6 @@ COpt::profiling_stop("script");
else
return false;
}
- function Redirect(url)
- {
- window.location = url;
- return false;
- }
function PopUp(url,form_name,param)
{
window.open(url,form_name,param);
@@ -2426,66 +1334,29 @@ COpt::profiling_stop("script");
}
//-->
</script>
- ";
- }
- function insert_javascript_clock($form, $field)
- {
- echo "
-<script language=\"JavaScript\" type=\"text/javascript\">
-<!--
- function show_clock()
- {
- var thetime=new Date();
-
- var nhours=thetime.getHours();
- var nmins=thetime.getMinutes();
- var nsecn=thetime.getSeconds();
- var AorP=\" \";
-
- var year = thetime.getFullYear();
- var nmonth = thetime.getMonth()+1;
- var ndate = thetime.getDate();
-
- if (nhours>=12) AorP=\"PM\";
- else AorP=\"AM\";
-
- if (nhours>=13) nhours-=12;
- if (nhours==0) nhours=12;
-
- if (nsecn<10) nsecn=\"0\"+nsecn;
- if (nmins<10) nmins=\"0\"+nmins;
- if (nmonth<10) nmonth=\"0\"+nmonth;
- if (ndate<10) ndate=\"0\"+ndate;
-
- document.forms['$form'].elements['$field'].value=ndate+\"-\"+nmonth+\"-\"+year+\" \"+nhours+\":\"+nmins+\":\"+nsecn+\" \"+AorP;
-
- setTimeout('show_clock()',1000);
- }
-//-->
-</script>
-";
+<?php
}
- function start_javascript_clock()
+ function Redirect($url)
{
- echo "
-<script language=\"JavaScript\" type=\"text/javascript\">
+?>
+<script language="JavaScript" type="text/javascript">
<!--
- show_clock();
+ window.location = '<?php echo $url; ?>';
//-->
</script>
-";
+<?php
}
function SetFocus($frm_name, $fld_name)
{
- echo "
-<script language=\"JavaScript\" type=\"text/javascript\">
+?>
+<script language="JavaScript" type="text/javascript">
<!--
- document.forms['$frm_name'].elements['$fld_name'].focus();
+ document.forms["<?php echo $frm_name; ?>"].elements["<?php echo $fld_name; ?>"].focus();
//-->
</script>
-";
+<?php
}
/* Use ImageSetStyle+ImageLIne instead of bugged ImageDashedLine */
@@ -2655,20 +1526,16 @@ COpt::profiling_stop("script");
echo "</TABLE>";
}
- function ImageOut($image)
- {
-// ImageJPEG($image);
- ImagePNG($image);
- }
-
function add_mapping_to_valuemap($valuemapid, $mappings)
{
DBexecute("delete from mappings where valuemapid=$valuemapid");
foreach($mappings as $map)
{
- $result = DBexecute("insert into mappings (valuemapid, value, newvalue)".
- " values (".$valuemapid.",".zbx_dbstr($map["value"]).",".
+ $mappingid = get_dbid("mappings","mappingid");
+
+ $result = DBexecute("insert into mappings (mappingid,valuemapid, value, newvalue)".
+ " values (".$mappingid.",".$valuemapid.",".zbx_dbstr($map["value"]).",".
zbx_dbstr($map["newvalue"]).")");
if(!$result)
@@ -2691,6 +1558,10 @@ COpt::profiling_stop("script");
if(!$result){
delete_valuemap($valuemapid);
}
+ else
+ {
+ $result = $valuemapid;
+ }
return $result;
}
@@ -2734,13 +1605,13 @@ COpt::profiling_stop("script");
function Alert($msg)
{
- echo "
+?>
<script language=\"JavaScript\" type=\"text/javascript\">
<!--
- alert('$msg');
+ alert('<? echo $msg; ?>');
//-->
</script>
-";
+<?php
}
function natksort(&$array) {
@@ -2757,12 +1628,19 @@ COpt::profiling_stop("script");
return true;
}
- function set_image_header()
+ function set_image_header($format=IMAGE_FORMAT_DEFAULT)
{
- //Header( "Content-type: text/html");
-
- if(MAP_OUTPUT_FORMAT == "JPG") Header( "Content-type: image/jpeg");
- else Header( "Content-type: image/png");
+ if(IMAGE_FORMAT_JPEG == $format) Header( "Content-type: image/jpeg");
+ if(IMAGE_FORMAT_TEXT == $format) Header( "Content-type: text/html");
+ else Header( "Content-type: image/png");
Header( "Expires: Mon, 17 Aug 1998 12:51:50 GMT");
}
+
+ function ImageOut($image,$format=IMAGE_FORMAT_DEFAULT)
+ {
+ if(IMAGE_FORMAT_JPEG == $format)
+ ImageJPEG($image);
+ else
+ ImagePNG($image);
+ }
?>
diff --git a/frontends/php/include/copt.lib.php b/frontends/php/include/copt.lib.php
index ea3accf2..ba67f4f1 100644
--- a/frontends/php/include/copt.lib.php
+++ b/frontends/php/include/copt.lib.php
@@ -85,19 +85,25 @@
** Author:
** Eugene Grigorjev (eugene.grigorjev@zabbix.com)
**/
-
-// define("USE_PROFILING",1);
-// define("USE_TIME_PROF",1);
-// define("USE_MEM_PROF",1);
-// define("USE_SQLREQUEST_PROF",1);
-// define("SHOW_SQLREQUEST_DETAILS",1);
+// define("USE_PROFILING",1);
+ define("USE_VAR_MON",1);
+ define("USE_TIME_PROF",1);
+ define("USE_MEM_PROF",1);
+ define("USE_COUNTER_PROF",1);
+ define("USE_MENU_PROF",1);
+ //define("USE_MENU_DETAILS",1);
+ define("USE_SQLREQUEST_PROF",1);
+ //define("SHOW_SQLREQUEST_DETAILS",1);
+
if(defined('USE_PROFILING'))
{
$starttime=array();
$memorystamp=array();
- $sqlrequests=array();
+ $sqlrequests = defined('SHOW_SQLREQUEST_DETAILS') ? array() : 0;
$sqlmark = array();
+ $perf_counter = array();
+ $var_list = array();
class COpt
{
@@ -113,6 +119,15 @@ if(defined('USE_TIME_PROF')) {
}
+ /* public static */ function showmemoryusage($descr=null)
+ {
+if(defined('USE_MEM_PROF')) {
+ $memory_usage = COpt::getmemoryusage();
+ $memory_usage = $memory_usage.'b | '.($memory_usage>>10).'K | '.($memory_usage>>20).'M';
+ SDI('PHP memory usage ['.$descr.'] '.$memory_usage);
+}
+ }
+
/* protected static */ function getmemoryusage() {
if(defined('USE_MEM_PROF')) {
return memory_get_usage('memory_limit');
@@ -129,20 +144,48 @@ if(defined('USE_MEM_PROF')) {
return round($size, 6).$prefix;
}
+ /* public static */ function counter_up($type=NULL)
+ {
+if(defined('USE_COUNTER_PROF'))
+{
+ global $perf_counter;
+ global $starttime;
+
+ foreach(array_keys($starttime) as $keys)
+ {
+ if(!isset($perf_counter[$keys][$type]))
+ $perf_counter[$keys][$type]=1;
+ else
+ $perf_counter[$keys][$type]++;
+ }
+}
+ }
+
/* public static */ function profiling_start($type=NULL)
{
global $starttime;
global $memorystamp;
global $sqlmark;
global $sqlrequests;
+ global $var_list;
if(is_null($type)) $type='global';
$starttime[$type] = COpt::getmicrotime();
$memorystamp[$type] = COpt::getmemoryusage();
+if(defined('USE_VAR_MON'))
+{
+
+ $var_list[$type] = isset($GLOBALS) ? array_keys($GLOBALS) : array();
+}
if(defined('USE_SQLREQUEST_PROF'))
{
+ if(defined('SHOW_SQLREQUEST_DETAILS')){
$sqlmark[$type] = count($sqlrequests);
+ }
+ else {
+ $sqlmark[$type] = $sqlrequests;
+ }
}
}
@@ -151,7 +194,11 @@ if(defined('USE_SQLREQUEST_PROF'))
if(defined('USE_SQLREQUEST_PROF'))
{
global $sqlrequests;
+ if(defined('SHOW_SQLREQUEST_DETAILS')){
array_push($sqlrequests, $sql);
+ }else{
+ $sqlrequests++;
+ }
}
}
@@ -161,34 +208,60 @@ if(defined('USE_SQLREQUEST_PROF'))
global $memorystamp;
global $sqlrequests;
global $sqlmark;
+ global $perf_counter;
+ global $var_list;
$endtime = COpt::getmicrotime();
$memory = COpt::getmemoryusage();
if(is_null($type)) $type='global';
- echo "<br>\n";
+ echo "<br/>\n";
if(defined('USE_TIME_PROF'))
{
- echo "(".$type.") Time to execute: ".round($endtime - $starttime[$type],6)." seconds!\n<br>\n";
+ echo "(".$type.") Time to execute: ".round($endtime - $starttime[$type],6)." seconds!\n<br/>\n";
}
if(defined('USE_MEM_PROF'))
{
- echo "(".$type.") Memory limit : ".ini_get('memory_limit')."<br>\n";
- echo "(".$type.") Memory usage : ".COpt::mem2str($memorystamp[$type])." - ".COpt::mem2str($memory)."\n<br>\n";
- echo "(".$type.") Memory leak : ".COpt::mem2str($memory - $memorystamp[$type])."\n<br>\n";
+ echo "(".$type.") Memory limit : ".ini_get('memory_limit')."<br/>\n";
+ echo "(".$type.") Memory usage : ".COpt::mem2str($memorystamp[$type])." - ".COpt::mem2str($memory)."\n<br/>\n";
+ echo "(".$type.") Memory leak : ".COpt::mem2str($memory - $memorystamp[$type])."\n<br/>\n";
+}
+if(defined('USE_VAR_MON'))
+{
+ $curr_var_list = isset($GLOBALS) ? array_keys($GLOBALS) : array();
+ $var_diff = array_diff($curr_var_list, $var_list[$type]);
+ echo "(".$type.") Undeleted vars : ".count($var_diff)." [";
+ print_r(implode(', ',$var_diff));
+ echo "] <br/>";
+}
+if(defined('USE_COUNTER_PROF'))
+{
+ if(isset($perf_counter[$type]))
+ {
+ ksort($perf_counter[$type]);
+ foreach($perf_counter[$type] as $name => $value)
+ {
+ echo "(".$type.") Counter '".$name."' : ".$value."<br/>\n";
+ }
+ }
}
if(defined('USE_SQLREQUEST_PROF'))
{
- $requests_cnt = count($sqlrequests);
- echo "(".$type.") SQL requests count: ".($requests_cnt - $sqlmark[$type])."<br>\n";
if(defined('SHOW_SQLREQUEST_DETAILS'))
{
+ $requests_cnt = count($sqlrequests);
+ echo "(".$type.") SQL requests count: ".($requests_cnt - $sqlmark[$type])."<br/>\n";
+
for($i = $sqlmark[$type]; $i < $requests_cnt; $i++)
{
- echo "(".$type.") SQL request : ".$sqlrequests[$i]."<br>\n";;
+ echo "(".$type.") SQL request : ".$sqlrequests[$i]."<br/>\n";
}
}
+ else
+ {
+ echo "(".$type.") SQL requests count: ".($sqlrequests - $sqlmark[$type])."<br/>\n";
+ }
}
}
@@ -197,6 +270,66 @@ if(defined('USE_SQLREQUEST_PROF'))
{
ini_set('memory_limit',$limit);
}
+
+ /* public static */ function compare_files_with_menu($menu=null)
+ {
+if(defined('USE_MENU_PROF'))
+{
+ $files_list = glob('*.php');
+
+ $result = array();
+ foreach($files_list as $file)
+ {
+ $list = array();
+ foreach($menu as $label=>$sub)
+ {
+ foreach($sub['pages'] as $sub_pages)
+ {
+ if(!isset($sub_pages["label"])) $sub_pages["label"]=$sub_pages['url'];
+
+ $menu_path = $sub["label"].'->'.$sub_pages["label"];
+
+ if($sub_pages['url'] == $file)
+ {
+ array_push($list, $menu_path);
+ }
+ if(!in_array($sub_pages['url'], $files_list))
+ $result['error'][$sub_pages['url']] = array($menu_path);
+
+ if(isset($sub_pages['sub_pages'])) foreach($sub_pages['sub_pages'] as $page)
+ {
+ $menu_path = $sub["label"].'->'.$sub_pages["label"].'->sub_pages';
+
+ if(!in_array($page, $files_list))
+ $result['error'][$page] = array($menu_path);
+
+ if($page != $file) continue;
+ array_push($list, $menu_path);
+ }
+ }
+ }
+ if(count($list) != 1) $level = 'worning';
+ else $level = 'normal';
+
+ $result[$level][$file] = $list;
+ }
+ foreach($result as $level => $files_list)
+ {
+if(defined('USE_MENU_DETAILS'))
+{
+ echo '<br/>(menu check) ['.$level."]<br/>\n";
+ foreach($files_list as $file => $menu_list)
+ {
+ echo "(menu check)".SPACE.SPACE.SPACE.SPACE.$file.' {'.implode(',',$menu_list)."}<br/>\n";
+ }
+}
+else
+{
+ echo '<br/>(menu check) ['.$level."] = ".count($files_list)."<br/>\n";
+}
+ }
+}
+ }
}
COpt::set_memory_limit('8M');
@@ -209,6 +342,9 @@ else
/* public static */ function profiling_start($type=NULL) {}
/* public static */ function profiling_stop($type=NULL) {}
/* public static */ function savesqlrequest($sql) {}
+ /* public static */ function showmemoryusage($descr=null) {}
+ /* public static */ function compare_files_with_menu($menu=null) {}
+ /* public static */ function counter_up($type=NULL) {}
}
}
diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php
index bf8c7364..5bbd8952 100644
--- a/frontends/php/include/db.inc.php
+++ b/frontends/php/include/db.inc.php
@@ -26,16 +26,13 @@
// $DB_TYPE ="POSTGRESQL";
$DB_TYPE ="MYSQL";
$DB_SERVER ="localhost";
- $DB_DATABASE ="node4";
+ $DB_DATABASE ="1_3_rights1";
$DB_USER ="root";
$DB_PASSWORD ="";
// END OF DATABASE CONFIGURATION
global $USER_DETAILS;
- $ZBX_CURNODEID = 4; // Selected node
- $ZBX_LOCALNODEID = 4; // Local node
-
if($DB_TYPE == "MYSQL")
{
$DB=mysql_pconnect($DB_SERVER,$DB_USER,$DB_PASSWORD);
@@ -82,6 +79,25 @@
SELECT * FROM (SELECT ROWNUM as RN, * FROM tbl) WHERE RN BETWEEN 6 AND 15
*/
+ function DBstart()
+ {
+ /* TODO *//* start transaction */
+ }
+
+ function DBend($result)
+ {
+ /* end transaction *//* TODO */
+
+ if($result)
+ { // OK
+ /* commit TODO */
+ }
+ else
+ { // FAIL
+ /* rollback TODO */
+ }
+ }
+
function DBselect($query, $limit='NO')
{
global $DB,$DB_TYPE;
@@ -153,11 +169,11 @@ COpt::savesqlrequest($query);
error("Query: $query");
}
}
- if($DB_TYPE == "POSTGRESQL")
+ else if($DB_TYPE == "POSTGRESQL")
{
$result=pg_exec($DB,$query);
}
- if($DB_TYPE == "ORACLE")
+ else if($DB_TYPE == "ORACLE")
{
return DBselect($query);
@@ -229,6 +245,7 @@ COpt::savesqlrequest($query);
}
}
+/*
function DBinsert_id($result,$table,$field)
{
global $DB,$DB_TYPE;
@@ -241,25 +258,17 @@ COpt::savesqlrequest($query);
if($DB_TYPE == "POSTGRESQL")
{
$oid=pg_getlastoid($result);
-// echo "OID:$oid<br>";
$sql="select $field from $table where oid=$oid";
$result=DBselect($sql);
return get_field($result,0,0);
}
if($DB_TYPE == "ORACLE")
{
-/* $sql="select max($field) from $table";
- $parse=DBexecute($sql);
- while(OCIFetch($parse))
- {
- $colvalue = OCIResult($parse, 1);
- return $colvalue;
- }
-*/
$res = DBfetch(DBselect('select '.$table.'_'.$field.'.currval from dual'));
return $res[0];
}
}
+*/
/* string value prepearing */
if($DB_TYPE == "ORACLE") {
@@ -271,4 +280,30 @@ if($DB_TYPE == "ORACLE") {
return "'".addslashes($var)."'";
}
}
+
+ function DBid2nodeid($id_name)
+ {
+ return '('.$id_name.' div 100000000000000)';
+ }
+
+ function id2nodeid($id_var)
+ {
+ return (int)($id_var / 100000000000000);
+ }
+
+ function get_dbid($table,$field)
+ {
+ global $ZBX_CURNODEID;
+
+ $result=DBselect("select max($field) as id from $table where ".DBid2nodeid($field)." in (".$ZBX_CURNODEID.")");
+ $row=DBfetch($result);
+ if($row && !is_null($row["id"]))
+ {
+ return ++$row["id"];
+ }
+ else
+ {
+ return $ZBX_CURNODEID*100000000000000+1;
+ }
+ }
?>
diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php
index 7604be37..4eea71f4 100644
--- a/frontends/php/include/defines.inc.php
+++ b/frontends/php/include/defines.inc.php
@@ -19,6 +19,9 @@
**/
?>
<?php
+ define("PAGE_TYPE_HTML", 0);
+ define("PAGE_TYPE_IMAGE", 1);
+
define("T_ZBX_STR", 0);
define("T_ZBX_INT", 1);
define("T_ZBX_DBL", 2);
@@ -36,8 +39,13 @@
define("P_NZERO", 32);
// MISC PARAMETERS
- define("MAP_OUTPUT_FORMAT", "DEFAULT");
-# define("MAP_OUTPUT_FORMAT", "JPG");
+ define("IMAGE_FORMAT_PNG", "PNG");
+ define("IMAGE_FORMAT_JPEG", "JPEG");
+ define("IMAGE_FORMAT_TEXT", "JPEG");
+// define("IMAGE_FORMAT_DEFAULT", IMAGE_FORMAT_TEXT);
+ define("IMAGE_FORMAT_DEFAULT", IMAGE_FORMAT_PNG);
+ define("MAP_OUTPUT_FORMAT", IMAGE_FORMAT_PNG);
+// define("MAP_OUTPUT_FORMAT", IMAGE_FORMAT_JPEG);
// END OF MISC PARAMETERS
define("AUDIT_ACTION_ADD", 0);
@@ -47,16 +55,26 @@
define("AUDIT_ACTION_LOGOUT", 4);
define("AUDIT_RESOURCE_USER", 0);
- define("AUDIT_RESOURCE_ZABBIX", 1);
+// define("AUDIT_RESOURCE_ZABBIX", 1);
define("AUDIT_RESOURCE_ZABBIX_CONFIG", 2);
define("AUDIT_RESOURCE_MEDIA_TYPE", 3);
define("AUDIT_RESOURCE_HOST", 4);
define("AUDIT_RESOURCE_ACTION", 5);
define("AUDIT_RESOURCE_GRAPH", 6);
define("AUDIT_RESOURCE_GRAPH_ELEMENT", 7);
- define("AUDIT_RESOURCE_ESCALATION", 8);
- define("AUDIT_RESOURCE_ESCALATION_RULE",9);
- define("AUDIT_RESOURCE_AUTOREGISTRATION",10);
+// define("AUDIT_RESOURCE_ESCALATION", 8);
+// define("AUDIT_RESOURCE_ESCALATION_RULE",9);
+// define("AUDIT_RESOURCE_AUTOREGISTRATION",10);
+ define("AUDIT_RESOURCE_USER_GROUP", 11);
+ define("AUDIT_RESOURCE_APPLICATION", 12);
+ define("AUDIT_RESOURCE_TRIGGER", 13);
+ define("AUDIT_RESOURCE_HOST_GROUP", 14);
+ define("AUDIT_RESOURCE_ITEM", 15);
+ define("AUDIT_RESOURCE_IMAGE", 16);
+ define("AUDIT_RESOURCE_VALUE_MAP", 17);
+ define("AUDIT_RESOURCE_IT_SERVICE", 18);
+ define("AUDIT_RESOURCE_MAP", 19);
+ define("AUDIT_RESOURCE_SCREEN", 20);
define("CONDITION_TYPE_GROUP", 0);
define("CONDITION_TYPE_HOST", 1);
@@ -218,6 +236,30 @@
define("SERVICE_TIME_TYPE_DOWNTIME", 1);
define("SERVICE_TIME_TYPE_ONETIME_DOWNTIME", 2);
+ define("USER_TYPE_ZABBIX_USER", 1);
+ define("USER_TYPE_ZABBIX_ADMIN", 2);
+ define("USER_TYPE_SUPPER_ADMIN", 3);
+
+ define("PERM_MAX", 3);
+ define("PERM_READ_WRITE", 3);
+ define("PERM_READ_ONLY", 2);
+ define("PERM_READ_LIST", 1);
+ define("PERM_DENY", 0);
+
+ define("PERM_RES_STRING_LINE", 0); /* return string of nodes id - "1,2,3,4,5" */
+ define("PERM_RES_IDS_ARRAY", 1); /* return array of nodes id - array(1,2,3,4) */
+ define("PERM_RES_DATA_ARRAY", 2);
+
+ define("PERM_MODE_NE", 5);
+ define("PERM_MODE_EQ", 4);
+ define("PERM_MODE_GT", 3);
+ define("PERM_MODE_LT", 2);
+ define("PERM_MODE_LE", 1);
+ define("PERM_MODE_GE", 0);
+
+ define("RESOURCE_TYPE_NODE", 0);
+ define("RESOURCE_TYPE_GROUP", 1);
+
/* Support for PHP5. PHP5 does not have $HTTP_..._VARS */
if (!function_exists('version_compare'))
{
diff --git a/frontends/php/include/escalations.inc.php b/frontends/php/include/escalations.inc.php
deleted file mode 100644
index 3879d825..00000000
--- a/frontends/php/include/escalations.inc.php
+++ /dev/null
@@ -1,160 +0,0 @@
-<?php
-/*
-** ZABBIX
-** Copyright (C) 2000-2005 SIA Zabbix
-**
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License as published by
-** the Free Software Foundation; either version 2 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-**/
-?>
-<?php
- # Add escalation definition
-
- function add_escalation($name,$dflt)
- {
- if(!check_right("Configuration of Zabbix","U",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
- $sql="insert into escalations (name,dflt) values ('$name',$dflt)";
- $result=DBexecute($sql);
- if(!$result)
- {
- return $result;
- }
- $escalationid=DBinsert_id($result,"escalation","escalationid");
-
- if($dflt==1)
- {
- $sql="update escalations set dflt=0 where escalationid<>$escalationid";
- $result=DBexecute($sql);
- info("Default escalation is set to '$name'");
- }
-
- return $result;
- }
-
- # Update escalation definition
-
- function update_escalation($escalationid,$name,$dflt)
- {
- if(!check_right("Configuration of Zabbix","U",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
- $sql="update escalations set name='$name',dflt=$dflt where escalationid=$escalationid";
- $result=DBexecute($sql);
- if(!$result)
- {
- return $result;
- }
-
- if($dflt==1)
- {
- $sql="update escalations set dflt=0 where escalationid<>$escalationid";
- $result=DBexecute($sql);
- info("Default escalation is set to '$name'");
- }
-
- return $result;
- }
-
-
- # Delete escalation definition
-
- function delete_escalation($escalationid)
- {
- if(!check_right("Configuration of Zabbix","U",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
- $sql="delete from escalation_rules where escalationid=$escalationid";
- $result=DBexecute($sql);
- if(!$result)
- {
- return $result;
- }
-
- $sql="delete from escalations where escalationid=$escalationid";
- $result=DBexecute($sql);
- if(!$result)
- {
- return $result;
- }
-
- return $result;
- }
-
- # Add escalation rule definition
-
- function add_escalation_rule($escalationid,$level,$period,$delay,$actiontype)
- {
- if(!check_right("Configuration of Zabbix","U",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
- $sql="insert into escalation_rules (escalationid,level,period,delay,actiontype) values ($escalationid,$level,'$period',$delay,$actiontype)";
- $result=DBexecute($sql);
- if(!$result)
- {
- return $result;
- }
- $escalationruleid=DBinsert_id($result,"escalation_rules","escalationruleid");
-
- return $result;
- }
-
- # Update escalation rule definition
-
- function update_escalation_rule($escalationruleid,$level,$period,$delay,$actiontype)
- {
- if(!check_right("Configuration of Zabbix","U",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
- $sql="update escalation_rules set level=$level,period='$period',delay=$delay,actiontype=$actiontype where escalationruleid=$escalationruleid";
- $result=DBexecute($sql);
- return $result;
- }
-
- # Delete escalation rule definition
-
- function delete_escalation_rule($escalationruleid)
- {
- if(!check_right("Configuration of Zabbix","U",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
- $sql="delete from escalation_rules where escalationruleid=$escalationruleid";
- $result=DBexecute($sql);
- if(!$result)
- {
- return $result;
- }
-
- return $result;
- }
-?>
diff --git a/frontends/php/include/events.inc.php b/frontends/php/include/events.inc.php
index 9ba2239b..9e402ee1 100644
--- a/frontends/php/include/events.inc.php
+++ b/frontends/php/include/events.inc.php
@@ -20,39 +20,47 @@
?>
<?php
- function get_history_of_events($start,$num, $groupid=0, $hostid=0)
+ function get_history_of_events($start,$num, $groupid=0, $hostid=0, $nodeid=null)
{
+ global $ZBX_CURNODEID;
+ global $USER_DETAILS;
+
+ if(is_null($nodeid)) $nodeid = $ZBX_CURNODEID;
+
+ $sql_from = $sql_cond = "";
+
if($hostid > 0)
{
- $sql="select distinct a.clock,a.value,a.triggerid from alarms a,functions f,items i where a.triggerid=f.triggerid and f.itemid=i.itemid and i.hostid=".$hostid." order by clock desc";
+ $sql_cond = " and h.hostid=".$hostid;
}
elseif($groupid > 0)
{
- $sql="select distinct a.clock,a.value,a.triggerid from alarms a,functions f,items i where a.triggerid=f.triggerid and f.itemid=i.itemid and i.hostid=hg.hostid and hg.groupid=".$groupid." order by clock desc";
+ $sql_from = ", hosts_groups hg ";
+ $sql_cond = " and h.hostid=hg.hostid and hg.groupid=".$groupid;
}
- else
- {
- $sql="select distinct triggerid,clock,value from alarms order by clock desc";
- }
- $result=DBselect($sql,10*($start+$num));
+
+ $result = DBselect(" select t.triggerid,t.priority,t.description,h.host,e.clock,e.value ".
+ " from events e, triggers t, functions f, items i, hosts h ".$sql_from.
+ " where ".DBid2nodeid("t.triggerid")."=".$nodeid.
+ " and e.triggerid=t.triggerid and t.triggerid=f.triggerid and f.itemid=i.itemid ".
+ " and i.hostid=h.hostid ".$sql_cond." and h.status=".HOST_STATUS_MONITORED.
+ " and h.hostid not in (".get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_WRITE, PERM_MODE_LT).") ".
+ " order by e.clock desc,h.host,t.priority,t.description,t.triggerid ",
+ 10*($start+$num)
+ );
$table = new CTableInfo(S_NO_EVENTS_FOUND);
- $table->setHeader(array(S_TIME, S_DESCRIPTION, S_VALUE, S_SEVERITY));
+ $table->SetHeader(array(S_TIME, $hostid == 0 ? S_HOST : null, S_DESCRIPTION, S_VALUE, S_SEVERITY));
$col=0;
- $skip=$start;
- while(($row=DBfetch($result))&&($col<100))
+
+ $skip = $start;
+ while(($row=DBfetch($result))&&($col<$num))
{
- if(!check_right_on_trigger("R",$row["triggerid"]))
- {
- continue;
- }
if($skip > 0)
{
$skip--;
continue;
}
- $description=expand_trigger_description($row["triggerid"]);
- $description=new CLink($description,"alarms.php?triggerid=".$row["triggerid"],"action");
if($row["value"] == 0)
{
@@ -67,21 +75,12 @@
$value=new CCol(S_UNKNOWN_BIG,"unknown");
}
- $trigger = get_trigger_by_triggerid($row["triggerid"]);
-
- if($trigger["priority"]==0) $priority=S_NOT_CLASSIFIED;
- elseif($trigger["priority"]==1) $priority=new CCol(S_INFORMATION, "information");
- elseif($trigger["priority"]==2) $priority=new CCol(S_WARNING,"warning");
- elseif($trigger["priority"]==3) $priority=new CCol(S_AVERAGE,"average");
- elseif($trigger["priority"]==4) $priority=new CCol(S_HIGH,"high");
- elseif($trigger["priority"]==5) $priority=new CCol(S_DISASTER,"disaster");
- else $priority=$trigger["priority"];
-
- $table->addRow(array(
- date("Y.M.d H:i:s",$row["clock"]),
- $description,
- $value,
- $priority));
+ $table->AddRow(array(
+ date("Y.M.d H:i:s",$row["clock"]),
+ $hostid == 0 ? $row['host'] : null,
+ new CLink(expand_trigger_description_by_data($row),"tr_events.php?triggerid=".$row["triggerid"],"action"),
+ $value,
+ new CCol(get_severity_description($row["priority"]), get_severity_style($row["priority"]))));
$col++;
}
diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php
index a8b1044c..e7831b22 100644
--- a/frontends/php/include/forms.inc.php
+++ b/frontends/php/include/forms.inc.php
@@ -23,14 +23,20 @@
include_once "include/defines.inc.php";
include_once "include/classes/graph.inc.php";
+ include_once "include/users.inc.php";
include_once "include/db.inc.php";
+ function insert_node_form()
+ {
+ SDI('TODO'); /* TODO node form realization */
+ }
+
function insert_new_message_form()
{
global $USER_DETAILS;
global $_REQUEST;
- $db_acks = get_acknowledges_by_alarmid($_REQUEST["alarmid"]);
+ $db_acks = get_acknowledges_by_eventid($_REQUEST["eventid"]);
if(!DBfetch($db_acks))
{
$title = S_ACKNOWLEDGE_ALARM_BY;
@@ -44,15 +50,18 @@
$frmMsg= new CFormTable($title." \"".$USER_DETAILS["alias"]."\"");
$frmMsg->SetHelp("manual.php");
- $frmMsg->AddVar("alarmid",get_request("alarmid",0));
+ $frmMsg->AddVar("eventid",get_request("eventid",0));
$frmMsg->AddRow(S_MESSAGE, new CTextArea("message","",80,6));
$frmMsg->AddItemToBottomRow(new CButton("save",$btn_txt));
+ $frmMsg->AddItemToBottomRow(new CButton("cancel",S_CANCEL));
- $frmMsg->Show();
+ $frmMsg->Show(false);
SetFocus($frmMsg->GetName(),"message");
+
+ $frmMsg->Destroy();
}
# Insert form for User
@@ -61,6 +70,9 @@
$frm_title = S_USER;
if(isset($userid))
{
+ global $USER_DETAILS;
+ if($userid == $USER_DETAILS['userid']) $profile = 1;
+
$user=get_user_by_userid($userid);
$frm_title = S_USER." \"".$user["alias"]."\"";
}
@@ -70,41 +82,86 @@
$alias = $user["alias"];
$name = $user["name"];
$surname = $user["surname"];
- $password = "";
+ $password = null;
+ $password1 = null;
+ $password2 = null;
$url = $user["url"];
$autologout = $user["autologout"];
$lang = $user["lang"];
$refresh = $user["refresh"];
+ $user_type = $user["type"];
+
$user_groups = array();
+ $user_medias = array();
+
+ $db_user_groups = DBselect('select g.* from usrgrp g, users_groups ug'.
+ ' where ug.usrgrpid=g.usrgrpid and ug.userid='.$userid);
- $db_user_groups = DBselect('select g.* from usrgrp g, users_groups ug where ug.usrgrpid=g.usrgrpid and ug.userid='.$userid);
while($db_group = DBfetch($db_user_groups))
{
$user_groups[$db_group['usrgrpid']] = $db_group['name'];
}
+
+ $db_medias = DBselect('select m.* from media m where m.userid='.$userid);
+ while($db_media = DBfetch($db_medias))
+ {
+ array_push($user_medias,
+ array( 'mediatypeid' => $db_media['mediatypeid'],
+ 'period' => $db_media['period'],
+ 'sendto' => $db_media['sendto'],
+ 'severity' => $db_media['severity'],
+ 'active' => $db_media['active']
+ )
+ );
+ }
+
+ $new_group_id = 0;
+ $new_group_name = '';
}
else
{
$alias = get_request("alias","");
$name = get_request("name","");
$surname = get_request("surname","");
- $password = "";
+ $password = null;
+ $password1 = get_request("password1", null);
+ $password2 = get_request("password2", null);
$url = get_request("url","");
$autologout = get_request("autologout","900");
$lang = get_request("lang","en_gb");
$refresh = get_request("refresh","30");
+ $user_type = get_request("user_type",USER_TYPE_ZABBIX_USER);;
$user_groups = get_request("user_groups",array());
+ $change_password = get_request("change_password", null);
+
+ $user_medias = get_request("user_medias", array());
+
+ $new_group_id = get_request('new_group_id', 0);
+ $new_group_name = get_request('new_group_name', '');
+ }
+
+ $perm_details = get_request('perm_details',0);
+
+ $media_types = array();
+ $media_type_ids = array();
+ foreach($user_medias as $one_media) $media_type_ids[$one_media['mediatypeid']] = 1;
+
+ if(count($media_type_ids) > 0)
+ {
+ $db_media_types = DBselect('select mt.mediatypeid,mt.description from media_type mt'.
+ ' where mt.mediatypeid in ('.implode(',',array_keys($media_type_ids)).')');
+
+ while($db_media_type = DBfetch($db_media_types))
+ {
+ $media_types[$db_media_type['mediatypeid']] = $db_media_type['description'];
+ }
}
$frmUser = new CFormTable($frm_title);
+ $frmUser->SetName('user_form');
$frmUser->SetHelp("web.users.php");
$frmUser->AddVar("config",get_request("config",0));
- if($profile==0)
- $frmUser->SetAction("users.php");
- else
- $frmUser->SetAction("profile.php");
-
if(isset($userid)) $frmUser->AddVar("userid",$userid);
if($profile==0)
@@ -114,15 +171,92 @@
$frmUser->AddRow(S_SURNAME, new CTextBox("surname",$surname,20));
}
- $frmUser->AddRow(S_PASSWORD, new CPassBox("password1",$password,20));
- $frmUser->AddRow(S_PASSWORD_ONCE_AGAIN, new CPassBox("password2",$password,20));
+ if(!isset($userid) || isset($change_password))
+ {
+ $frmUser->AddRow(S_PASSWORD, new CPassBox("password1",$password1,20));
+ $frmUser->AddRow(S_PASSWORD_ONCE_AGAIN, new CPassBox("password2",$password2,20));
+ if(isset($change_password))
+ $frmUser->AddVar('change_password', $change_password);
+ }
+ else
+ {
+ $frmUser->AddRow(S_PASSWORD, new CButton("change_password", S_CHANGE_PASSWORD));
+ }
- foreach($user_groups as $groupid => $group_name)
+ if($profile==0)
{
- $frmUser->AddRow(S_GROUPS, $group_name);
+ global $USER_DETAILS;
+
+ $frmUser->AddVar('user_groups',$user_groups);
+
+ if(isset($userid) && ($USER_DETAILS['userid'] == $userid))
+ {
+ $frmUser->AddVar('user_type',$user_type);
+ }
+ else
+ {
+ $cmbUserType = new CComboBox('user_type', $user_type, $perm_details ? 'submit();' : null);
+ $cmbUserType->AddItem(USER_TYPE_ZABBIX_USER, user_type2str(USER_TYPE_ZABBIX_USER));
+ $cmbUserType->AddItem(USER_TYPE_ZABBIX_ADMIN, user_type2str(USER_TYPE_ZABBIX_ADMIN));
+ $cmbUserType->AddItem(USER_TYPE_SUPPER_ADMIN, user_type2str(USER_TYPE_SUPPER_ADMIN));
+ $frmUser->AddRow(S_USER_TYPE, $cmbUserType);
+ }
+
+ $lstGroups = new CListBox('user_groups_to_del[]');
+ $lstGroups->options['style'] = 'width: 270px';
+
+ foreach($user_groups as $groupid => $group_name)
+ {
+ $lstGroups->AddItem($groupid, $group_name);
+ }
+
+ $frmUser->AddRow(S_GROUPS,
+ array(
+ $lstGroups,
+ BR,
+ new CButton('add_group',S_ADD,
+ "return PopUp('popup_usrgrp.php?dstfrm=".$frmUser->GetName().
+ "&list_name=user_groups_to_del[]&var_name=user_groups','new_group',".
+ "'width=450,height=450,resizable=1,scrollbars=1');"),
+ SPACE,
+ (count($user_groups) > 0) ? new CButton('del_user_group',S_DELETE_SELECTED) : null
+ ));
+
+ $frmUser->AddVar('user_medias', $user_medias);
+
+ $media_table = new CTable(S_NO_MEDIA_DEFINED);
+ foreach($user_medias as $id => $one_media)
+ {
+ if(!isset($one_media["active"]) || $one_media["active"]==0)
+ {
+ $status = new CLink(S_ENABLED,'#','enabled');
+ $status->OnClick("return create_var('".$frmUser->GetName()."','disable_media',".$id.", true);");
+ }
+ else
+ {
+ $status = new CLink(S_DISABLED,'#','disabled');
+ $status->OnClick("return create_var('".$frmUser->GetName()."','enable_media',".$id.", true);");
+ }
+
+ $media_table->AddRow(array(
+ new CCheckBox('user_medias_to_del[]',null,null,$id),
+ new CSpan($media_types[$one_media['mediatypeid']], 'nowrap'),
+ new CSpan($one_media['sendto'], 'nowrap'),
+ new CSpan($one_media['period'], 'nowrap'),
+ media_severity2str($one_media['severity']),
+ $status)
+ );
+ }
+ $frmUser->AddRow(S_MEDIA, array($media_table,
+ new CButton('add_media',S_ADD,
+ 'return PopUp("popup_media.php?dstfrm='.$frmUser->GetName().'","new_media",'.
+ '"width=550,height=400,resizable=1,scrollbars=1");'),
+ SPACE,
+ (count($user_medias) > 0) ? new CButton('del_user_media',S_DELETE_SELECTED) : null
+ ));
}
- $cmbLang = new CcomboBox('lang',$lang);
+ $cmbLang = new CComboBox('lang',$lang);
$cmbLang->AddItem("en_gb",S_ENGLISH_GB);
$cmbLang->AddItem("cn_zh",S_CHINESE_CN);
$cmbLang->AddItem("fr_fr",S_FRENCH_FR);
@@ -138,9 +272,60 @@
$frmUser->AddRow(S_AUTO_LOGOUT_IN_SEC, new CTextBox("autologout",$autologout,5));
$frmUser->AddRow(S_URL_AFTER_LOGIN, new CTextBox("url",$url,50));
$frmUser->AddRow(S_SCREEN_REFRESH, new CTextBox("refresh",$refresh,5));
+
+
+ if($profile==0)
+ {
+ $frmUser->AddVar('perm_details', $perm_details);
+
+ $link = new CLink($perm_details ? S_HIDE : S_SHOW ,'#','action');
+ $link->OnClick("return create_var('".$frmUser->GetName()."','perm_details',".($perm_details ? 0 : 1).", true);");
+ $resources_list = array(
+ S_RIGHTS_OF_RESOURCES,
+ SPACE.'(',$link,')'
+ );
+ $frmUser->AddSpanRow($resources_list,'right_header');
+
+ if($perm_details)
+ {
+ $group_ids = array_keys($user_groups);
+ if(count($group_ids) == 0) $group_ids = array(-1);
+ $db_rights = DBselect('select * from rights r where r.groupid in ('.implode(',',$group_ids).')');
+
+ $tmp_perm = array();
+ while($db_right = DBfetch($db_rights))
+ {
+ if(isset($tmp_perm[$db_right['type']][$db_right['id']]))
+ {
+ $tmp_perm[$db_right['type']][$db_right['id']] =
+ min($tmp_perm[$db_right['type']][$db_right['id']],
+ $db_right['permission']);
+ }
+ else
+ {
+ $tmp_perm[$db_right['type']][$db_right['id']] = $db_right['permission'];
+ }
+ }
+
+ $user_rights = array();
+ foreach($tmp_perm as $type => $res)
+ {
+ foreach($res as $id => $perm)
+ {
+ array_push($user_rights, array(
+ 'type' => $type,
+ 'id' => $id,
+ 'permission' => $perm
+ ));
+ }
+ }
+
+ $frmUser->AddSpanRow(get_rights_of_elements_table($user_rights, $user_type));
+ }
+ }
$frmUser->AddItemToBottomRow(new CButton('save',S_SAVE));
- if(isset($userid))
+ if(isset($userid) && $profile == 0)
{
$frmUser->AddItemToBottomRow(SPACE);
$frmUser->AddItemToBottomRow(new CButtonDelete("Delete selected user?",
@@ -151,102 +336,149 @@
$frmUser->Show();
}
- # Insert form for User permissions
- function insert_permissions_form()
- {
- global $_REQUEST;
-
- $frmPerm = new CFormTable("New permission","users.php");
- $frmPerm->SetHelp("web.users.php");
-
- $frmPerm->AddVar("userid",$_REQUEST["userid"]);
- $frmPerm->AddVar("config",get_request("config",0));
-
- $cmbRes = new CComboBox("right");
- $cmbRes->AddItem("Configuration of Zabbix","Configuration of Zabbix");
- $cmbRes->AddItem("Default permission","Default permission");
- $cmbRes->AddItem("Graph","Graph");
- $cmbRes->AddItem("Host","Host");
- $cmbRes->AddItem("Screen","Screen");
- $cmbRes->AddItem("Service","IT Service");
- $cmbRes->AddItem("Item","Item");
- $cmbRes->AddItem("Network map","Network map");
- $cmbRes->AddItem("Trigger comment","Trigger comment");
- $cmbRes->AddItem("User","User");
- $cmbRes->AddItem("Application","Application");
- $frmPerm->AddRow(S_RESOURCE,$cmbRes);
-
- $cmbPerm = new CComboBox("permission");
- $cmbPerm->AddItem("R","Read-only");
- $cmbPerm->AddItem("U","Read-write");
- $cmbPerm->AddItem("H","Hide");
- $cmbPerm->AddItem("A","Add");
- $frmPerm->AddRow(S_PERMISSION,$cmbPerm);
-
- $frmPerm->AddRow("Resource ID (0 for all)",new CTextBox("id",0));
- $frmPerm->AddItemToBottomRow(new CButton("register","add permission"));
- $frmPerm->Show();
- }
-
# Insert form for User Groups
- function insert_usergroups_form($usrgrpid)
+ function insert_usergroups_form()
{
global $_REQUEST;
global $ZBX_CURNODEID;
$frm_title = S_USER_GROUP;
- if(isset($usrgrpid))
+ if(isset($_REQUEST["usrgrpid"]))
{
- $usrgrp=get_usergroup_by_groupid($usrgrpid);
- $frm_title = S_USER_GROUP." \"".$usrgrp["name"]."\"";
+ $usrgrp = get_group_by_usrgrpid($_REQUEST["usrgrpid"]);
+ $frm_title = S_USER_GROUP." \"".$usrgrp["name"]."\"";
}
- $users = get_request("users",array());
- if(isset($usrgrpid) && !isset($_REQUEST["form_refresh"]))
+ if(isset($_REQUEST["usrgrpid"]) && !isset($_REQUEST["form_refresh"]))
{
$name = $usrgrp["name"];
+
+ $group_users = array();
$db_users=DBselect("select distinct u.userid,u.alias from users u,users_groups ug ".
- "where u.userid=ug.userid and ug.usrgrpid=".$usrgrpid.
+ "where u.userid=ug.userid and ug.usrgrpid=".$_REQUEST["usrgrpid"].
" order by alias");
while($db_user=DBfetch($db_users))
+ $group_users[$db_user["userid"]] = $db_user['alias'];
+
+ $group_rights = array();
+ $sqls = array(
+ 'select r.*i,n.name as name from rights r, nodes n where r.groupid='.$_REQUEST["usrgrpid"].
+ ' and r.type='.RESOURCE_TYPE_NODE.' and r.id=n.nodeid',
+ 'select r.*i, CONCAT(n.name,":",g.name) as name from rights r, groups g, nodes n'.
+ ' where r.groupid='.$_REQUEST["usrgrpid"].' and n.nodeid='.DBid2nodeid('g.groupid').
+ ' and r.type='.RESOURCE_TYPE_GROUP.' and r.id=g.groupid',
+
+ );
+ foreach($sqls as $sql)
{
- if(in_array($db_user["userid"], $users)) continue;
- array_push($users,$db_user["userid"]);
+ $db_rights = DBselect($sql);
+ while($db_right = DBfetch($db_rights))
+ {
+ $group_rights[$db_right['name']] = array(
+ 'type' => $db_right['type'],
+ 'permission' => $db_right['permission'],
+ 'id' => $db_right['id']
+ );
+ }
}
}
else
{
- $name = get_request("gname","");
+ $name = get_request("gname","");
+ $group_users = get_request("group_users",array());
+ $group_rights = get_request("group_rights",array());
}
+ $perm_details = get_request('perm_details', 0);
+
+ ksort($group_rights);
$frmUserG = new CFormTable($frm_title,"users.php");
$frmUserG->SetHelp("web.users.groups.php");
- $frmUserG->AddVar("config",get_request("config",2));
- if(isset($usrgrpid))
+ $frmUserG->AddVar("config",get_request("config",1));
+
+ if(isset($_REQUEST["usrgrpid"]))
{
- $frmUserG->AddVar("usrgrpid",$usrgrpid);
+ $frmUserG->AddVar("usrgrpid",$_REQUEST["usrgrpid"]);
}
- $frmUserG->AddRow(S_GROUP_NAME,new CTextBox("gname",$name,30));
+ $grName = new CTextBox("gname",$name,49);
+ $grName->options['style'] = 'width: 250px';
+ $frmUserG->AddRow(S_GROUP_NAME,$grName);
- $form_row = array();
- $db_users=DBselect("select distinct userid,alias from users".
- " where mod(userid,100)=".$ZBX_CURNODEID.
- " order by alias");
- while($db_user=DBfetch($db_users))
+ $frmUserG->AddVar('group_rights', $group_rights);
+
+ $frmUserG->AddVar('group_users', $group_users);
+
+ $lstUsers = new CListBox('group_users_to_del[]');
+ $lstUsers->options['style'] = 'width: 250px';
+
+ foreach($group_users as $userid => $alias)
{
- array_push($form_row,
- array(
- new CCheckBox("users[]",
- in_array($db_user["userid"],$users) ? 'yes' : 'no',
- NULL, /* action */
- $db_user["userid"]), /* value */
- $db_user["alias"]
- ),
- BR);
+ $lstUsers->AddItem($userid, $alias);
}
- $frmUserG->AddRow(S_USERS,$form_row);
-
+
+ $frmUserG->AddRow(S_USERS,
+ array(
+ $lstUsers,
+ BR,
+ new CButton('add_user',S_ADD,
+ "return PopUp('popup_users.php?dstfrm=".$frmUserG->GetName().
+ "&list_name=group_users_to_del[]&var_name=group_users','new_user',".
+ "'width=450,height=450,resizable=1,scrollbars=1');"),
+ (count($group_users) > 0) ? new CButton('del_group_user',S_DELETE_SELECTED) : null
+ ));
+
+ $table_Rights = new CTable(S_NO_RIGHTS_DEFINED,'right_table');
+
+ $lstWrite = new CListBox('right_to_del[read_write][]' ,null ,20);
+ $lstRead = new CListBox('right_to_del[read_only][]' ,null ,20);
+ $lstDeny = new CListBox('right_to_del[deny][]' ,null ,20);
+
+ foreach($group_rights as $name => $element_data)
+ {
+ if($element_data['permission'] == PERM_DENY) $lstDeny->AddItem($name, $name);
+ elseif ($element_data['permission'] == PERM_READ_ONLY) $lstRead->AddItem($name, $name);
+ elseif ($element_data['permission'] == PERM_READ_WRITE) $lstWrite->AddItem($name, $name);
+
+ }
+
+ $table_Rights->SetHeader(array(S_READ_WRITE, S_READ_ONLY, S_DENY),'header');
+ $table_Rights->AddRow(array(new CCol($lstWrite,'read_write'), new CCol($lstRead,'read_only'), new CCol($lstDeny,'deny')));
+ $table_Rights->AddRow(array(
+ array(new CButton('add_read_write',S_ADD,
+ "return PopUp('popup_right.php?dstfrm=".$frmUserG->GetName().
+ "&permission=".PERM_READ_WRITE."','new_right',".
+ "'width=450,height=450,resizable=1,scrollbars=1');"),
+ new CButton('del_read_write',S_DELETE_SELECTED)),
+ array( new CButton('add_read_only',S_ADD,
+ "return PopUp('popup_right.php?dstfrm=".$frmUserG->GetName().
+ "&permission=".PERM_READ_ONLY."','new_right',".
+ "'width=450,height=450,resizable=1,scrollbars=1');"),
+ new CButton('del_read_only',S_DELETE_SELECTED)),
+ array(new CButton('add_deny',S_ADD,
+ "return PopUp('popup_right.php?dstfrm=".$frmUserG->GetName().
+ "&permission=".PERM_DENY."','new_right',".
+ "'width=450,height=450,resizable=1,scrollbars=1');"),
+ new CButton('del_deny',S_DELETE_SELECTED))
+ ));
+
+ $frmUserG->AddRow(S_RIGHTS,$table_Rights);
+
+ $frmUserG->AddVar('perm_details', $perm_details);
+
+ $link = new CLink($perm_details ? S_HIDE : S_SHOW ,'#','action');
+ $link->OnClick("return create_var('".$frmUserG->GetName()."','perm_details',".($perm_details ? 0 : 1).", true);");
+ $resources_list = array(
+ S_RIGHTS_OF_RESOURCES,
+ SPACE.'(',$link,')'
+ );
+ $frmUserG->AddSpanRow($resources_list,'right_header');
+
+ if($perm_details)
+ {
+ $frmUserG->AddSpanRow(get_rights_of_elements_table($group_rights));
+ }
+
$frmUserG->AddItemToBottomRow(new CButton("save",S_SAVE));
if(isset($_REQUEST["usrgrpid"]))
{
@@ -259,11 +491,84 @@
$frmUserG->Show();
}
+ function get_rights_of_elements_table($rights=array(),$user_type=USER_TYPE_ZABBIX_USER)
+ {
+ $table = new CTable('S_NO_ACCESSIBLE_RESOURCES', 'right_table');
+ $table->SetHeader(array(SPACE, S_READ_WRITE, S_READ_ONLY, S_DENY),'header');
+
+ $lst['node']['label'] = S_NODES;
+ $lst['node']['read_write'] = new CListBox('nodes_write' ,null ,6);
+ $lst['node']['read_only'] = new CListBox('nodes_read' ,null ,6);
+ $lst['node']['deny'] = new CListBox('nodes_deny' ,null ,6);
+
+ $nodes = get_accessible_nodes_by_rights($rights, $user_type, PERM_DENY, PERM_MODE_GE, PERM_RES_DATA_ARRAY);
+
+ foreach($nodes as $node)
+ {
+ switch($node['permission'])
+ {
+ case PERM_READ_ONLY: $list_name='read_only'; break;
+ case PERM_READ_WRITE: $list_name='read_write'; break;
+ default: $list_name='deny'; break;
+ }
+ $lst['node'][$list_name]->AddItem($node['nodeid'],$node['name']);
+ }
+
+ $lst['group']['label'] = S_HOST_GROUPS;
+ $lst['group']['read_write'] = new CListBox('groups_write' ,null ,10);
+ $lst['group']['read_only'] = new CListBox('groups_read' ,null ,10);
+ $lst['group']['deny'] = new CListBox('groups_deny' ,null ,10);
+
+ $groups = get_accessible_groups_by_rights($rights, $user_type, PERM_DENY, PERM_MODE_GE, PERM_RES_DATA_ARRAY);
+
+ foreach($groups as $group)
+ {
+ switch($group['permission'])
+ {
+ case PERM_READ_ONLY: $list_name='read_only'; break;
+ case PERM_READ_WRITE: $list_name='read_write'; break;
+ default: $list_name='deny'; break;
+ }
+ $lst['group'][$list_name]->AddItem($group['groupid'],$group['node_name'].':'.$group['name']);
+ }
+
+ $lst['host']['label'] = S_HOSTS;
+ $lst['host']['read_write'] = new CListBox('hosts_write' ,null ,15);
+ $lst['host']['read_only'] = new CListBox('hosts_read' ,null ,15);
+ $lst['host']['deny'] = new CListBox('hosts_deny' ,null ,15);
+
+ $hosts = get_accessible_hosts_by_rights($rights, $user_type, PERM_DENY, PERM_MODE_GE, PERM_RES_DATA_ARRAY);
+ foreach($hosts as $host)
+ {
+ switch($host['permission'])
+ {
+ case PERM_READ_ONLY: $list_name='read_only'; break;
+ case PERM_READ_WRITE: $list_name='read_write'; break;
+ default: $list_name='deny'; break;
+ }
+ $lst['host'][$list_name]->AddItem($host['hostid'],$host['node_name'].':'.$host['host']);
+ }
+
+ foreach($lst as $name => $lists)
+ {
+ $row = new CRow();
+ foreach($lists as $class => $list_obj)
+ {
+ $row->AddItem(new CCol($list_obj, $class));
+ }
+ $table->AddRow($row);
+ }
+
+ return $table;
+ }
+
# Insert form for Item information
function insert_item_form()
{
global $_REQUEST;
+ global $USER_DETAILS;
+ global $ZBX_CURNODEID;
$frmItem = new CFormTable(S_ITEM,"items.php");
$frmItem->SetHelp("web.items.item.php");
@@ -276,7 +581,7 @@
$description = get_request("description" ,"");
$key = get_request("key" ,"");
- $host = get_request("host", NULL);
+ $host = get_request("host", null);
$delay = get_request("delay" ,30);
$history = get_request("history" ,90);
$status = get_request("status" ,0);
@@ -378,7 +683,7 @@
array_push($delay_flex_el,
array(
- new CCheckBox("rem_delay_flex[]", 'no', NULL,$i),
+ new CCheckBox("rem_delay_flex[]", 'no', null,$i),
$val["delay"],
" sec at ",
$val["period"]
@@ -476,11 +781,11 @@
$frmItem->AddRow(S_KEY, array(new CTextBox("key",$key,40), $btnSelect));
$cmbValType = new CComboBox("value_type",$value_type,"submit()");
- $cmbValType->AddItem(ITEM_VALUE_TYPE_UINT64, S_NUMERIC_UINT64);
- $cmbValType->AddItem(ITEM_VALUE_TYPE_FLOAT, S_NUMERIC_FLOAT);
- $cmbValType->AddItem(ITEM_VALUE_TYPE_STR, S_CHARACTER);
- $cmbValType->AddItem(ITEM_VALUE_TYPE_LOG, S_LOG);
- $cmbValType->AddItem(ITEM_VALUE_TYPE_TEXT, S_TEXT);
+ $cmbValType->AddItem(ITEM_VALUE_TYPE_UINT64, S_NUMERIC_UINT64);
+ $cmbValType->AddItem(ITEM_VALUE_TYPE_FLOAT, S_NUMERIC_FLOAT);
+ $cmbValType->AddItem(ITEM_VALUE_TYPE_STR, S_CHARACTER);
+ $cmbValType->AddItem(ITEM_VALUE_TYPE_LOG, S_LOG);
+ $cmbValType->AddItem(ITEM_VALUE_TYPE_TEXT, S_TEXT);
$frmItem->AddRow(S_TYPE_OF_INFORMATION,$cmbValType);
if( ($value_type==ITEM_VALUE_TYPE_FLOAT) || ($value_type==ITEM_VALUE_TYPE_UINT64))
@@ -527,7 +832,7 @@
$frmItem->AddRow(S_KEEP_HISTORY_IN_DAYS, array(
new CTextBox("history",$history,8),
- (!isset($_REQUEST["itemid"])) ? NULL :
+ (!isset($_REQUEST["itemid"])) ? null :
new CButton("del_history",
"Clean history",
"return Confirm('History cleaning can take a long time. Continue?');")
@@ -567,7 +872,7 @@
{
$cmbMap = new CComboBox("valuemapid",$valuemapid);
$cmbMap->AddItem(0,S_AS_IS);
- $db_valuemaps = DBselect("select * from valuemaps");
+ $db_valuemaps = DBselect("select * from valuemaps where ".DBid2nodeid("valuemapid")."=".$ZBX_CURNODEID);
while($db_valuemap = DBfetch($db_valuemaps))
$cmbMap->AddItem($db_valuemap["valuemapid"],$db_valuemap["name"]);
@@ -618,20 +923,12 @@
$cmbGroups = new CComboBox("add_groupid",$add_groupid);
- $groups=DBselect("select groupid,name from groups order by name");
+ $groups=DBselect("select distinct groupid,name from groups ".
+ "where groupid in (".get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY,null,null,$ZBX_CURNODEID).") ".
+ " order by name");
while($group=DBfetch($groups))
{
-// Check if at least one host with read permission exists for this group
- $hosts=DBselect("select h.hostid,h.host from hosts h,hosts_groups hg".
- " where hg.groupid=".$group["groupid"]." and hg.hostid=h.hostid".
- " and h.status<>".HOST_STATUS_DELETED." group by h.hostid,h.host".
- " order by h.host");
- while($host=DBfetch($hosts))
- {
- if(!check_right("Host","U",$host["hostid"])) continue;
- $cmbGroups->AddItem($group["groupid"],$group["name"]);
- break;
- }
+ $cmbGroups->AddItem($group["groupid"],$group["name"]);
}
$frmItem->AddRow(S_GROUP,$cmbGroups);
@@ -664,7 +961,7 @@
return;
}
- $frmCopy = new CFormTable(count($group_itemid).' '.S_X_ELEMENTS_COPY_TO_DOT_DOT_DOT,NULL,'post',NULL,'form_copy_to');
+ $frmCopy = new CFormTable(count($group_itemid).' '.S_X_ELEMENTS_COPY_TO_DOT_DOT_DOT,null,'post',null,'form_copy_to');
$frmCopy->SetHelp('web.items.copyto.php');
$frmCopy->AddVar($elements_array_name, $group_itemid);
@@ -702,7 +999,7 @@
array_push($target_list,array(
new CCheckBox('copy_targetid[]',
in_array($target['target_id'], $copy_targetid),
- NULL,
+ null,
$target['target_id']),
SPACE,
$target['target_name'],
@@ -733,9 +1030,11 @@
$frmLogin->AddRow('Login name', new CTextBox('name'));
$frmLogin->AddRow('Password', new CPassBox('password'));
$frmLogin->AddItemToBottomRow(new CButton('enter','Enter'));
- $frmLogin->Show();
+ $frmLogin->Show(false);
SetFocus($frmLogin->GetName(),"name");
+
+ $frmLogin->Destroy();
}
# Insert form for Trigger
@@ -794,7 +1093,7 @@
foreach($dependences as $val){
array_push($dep_el,
array(
- new CCheckBox("rem_dependence[]", 'no', NULL, strval($val)),
+ new CCheckBox("rem_dependence[]", 'no', null, strval($val)),
expand_trigger_description($val)
),
BR);
@@ -808,32 +1107,31 @@
$frmTrig->AddRow("The trigger depends on",$dep_el);
/* end dependences */
+ global $USER_DETAILS;
/* new dependence */
- $cmbDepID = new CComboBox("new_dependence");
- if(isset($_REQUEST["triggerid"]))
- $sql="select t.triggerid,t.description from triggers t".
- " where t.triggerid!=".$_REQUEST["triggerid"]." order by t.description";
- else
- $sql="select t.triggerid,t.description from triggers t order by t.description";
+ $frmTrig->AddVar('new_dependence','0');
- $db_trigs=DBselect($sql);
- while($db_trig=DBfetch($db_trigs))
- {
- $cmbDepID->AddItem($db_trig["triggerid"],
- expand_trigger_description($db_trig["triggerid"]));
- }
- $frmTrig->AddRow("New dependency",array(
- $cmbDepID,SPACE,
- new CButton("add_dependence","add")));
+ $txtCondVal = new CTextBox('trigger','',50);
+ $txtCondVal->SetReadonly('yes');
+
+ $btnSelect = new CButton('btn1',S_SELECT,
+ "return PopUp('popup.php?dstfrm=".$frmTrig->GetName().
+ "&dstfld1=new_dependence&dstfld2=trigger&srctbl=triggers&srcfld1=triggerid&srcfld2=description','new_win',".
+ "'width=600,height=450,resizable=1,scrollbars=1');");
+
+ $btnSelect->SetAccessKey('T');
+ $frmTrig->AddRow("New dependency",array($txtCondVal,
+ $btnSelect, BR,
+ new CButton("add_dependence","add")
+ ));
+
/* end new dwpendence */
$cmbPrior = new CComboBox("priority",$priority);
- $cmbPrior->AddItem(0,"Not classified");
- $cmbPrior->AddItem(1,"Information");
- $cmbPrior->AddItem(2,"Warning");
- $cmbPrior->AddItem(3,"Average");
- $cmbPrior->AddItem(4,"High");
- $cmbPrior->AddItem(5,"Disaster");
+ for($i = 0; $i <= 5; $i++)
+ {
+ $cmbPrior->AddItem($i,get_severity_description($i));
+ }
$frmTrig->AddRow(S_SEVERITY,$cmbPrior);
$frmTrig->AddRow(S_COMMENTS,new CTextArea("comments",$comments,70,7));
@@ -855,14 +1153,16 @@
function insert_trigger_comment_form($triggerid)
{
- $trigger=get_trigger_by_triggerid($triggerid);
- $comments=stripslashes($trigger["comments"]);
+ $trigger = DBfetch(DBselect('select t.*, h.* from triggers t, functions f, items i, hosts h '.
+ ' where t.triggerid='.$triggerid.' and f.triggerid=t.triggerid and f.itemid=i.itemid '.
+ ' and i.hostid=h.hostid '));
- $frmComent = new CFormTable(S_COMMENTS." for \"".expand_trigger_description_simple($triggerid)."\"");
+ $frmComent = new CFormTable(S_COMMENTS." for ".$trigger['host']." : \"".expand_trigger_description_by_data($trigger)."\"");
$frmComent->SetHelp("web.tr_comments.comments.php");
$frmComent->AddVar("triggerid",$triggerid);
- $frmComent->AddRow(S_COMMENTS,new CTextArea("comments",$comments,100,25));
- $frmComent->AddItemToBottomRow(new CButton("register","update"));
+ $frmComent->AddRow(S_COMMENTS,new CTextArea("comments",stripslashes($trigger["comments"]),100,25));
+ $frmComent->AddItemToBottomRow(new CButton("save",S_SAVE));
+ $frmComent->AddItemToBottomRow(new CButton("cancel",S_CANCEL));
$frmComent->Show();
}
@@ -915,8 +1215,8 @@
$cmbGType->AddItem(GRAPH_TYPE_STACKED,S_STACKED);
$frmGraph->AddRow(S_GRAPH_TYPE,$cmbGType);
- $frmGraph->AddRow(S_SHOW_WORKING_TIME,new CCheckBox("showworkperiod",$showworkperiod,NULL,1));
- $frmGraph->AddRow(S_SHOW_TRIGGERS,new CCheckBox("showtriggers",$showtriggers,NULL,1));
+ $frmGraph->AddRow(S_SHOW_WORKING_TIME,new CCheckBox("showworkperiod",$showworkperiod,null,1));
+ $frmGraph->AddRow(S_SHOW_TRIGGERS,new CCheckBox("showtriggers",$showtriggers,null,1));
$cmbYType = new CComboBox("yaxistype",$yaxistype,"submit()");
$cmbYType->AddItem(GRAPH_YAXIS_TYPE_CALCULATED,S_CALCULATED);
@@ -955,22 +1255,19 @@
$db_graph = get_graph_by_graphid($_REQUEST["graphid"]);
- $db_hosts = get_hosts_by_graphid($_REQUEST["graphid"]);
- $db_host = DBfetch($db_hosts);
- if(!$db_host)
- {
- // empty graph, can contain any item
- $host_condition = " and h.status in(".HOST_STATUS_MONITORED.",".HOST_STATUS_TEMPLATE.")";
- }
- else
+
+ $db_host = DBfetch(get_hosts_by_graphid($_REQUEST["graphid"]));
+
+ $host_condition = "";
+ if($db_host)
{
if($db_host["status"]==HOST_STATUS_TEMPLATE)
{// graph for template must use only one host
- $host_condition = " and h.hostid=".$db_host["hostid"];
+ $host_condition = "&only_hostid=".$db_host["hostid"];
}
else
{
- $host_condition = " and h.status in(".HOST_STATUS_MONITORED.")";
+ $host_condition = "&monitored_hosts=1";
}
}
@@ -1012,17 +1309,26 @@
$frmGItem->AddVar("gitemid",$_REQUEST["gitemid"]);
}
- $cmbItems = new CComboBox("itemid", $itemid);
- $result=DBselect("select h.host,i.description,i.itemid,i.key_ from hosts h,items i".
- " where h.hostid=i.hostid".
- $host_condition.
- " and i.status=".ITEM_STATUS_ACTIVE." order by h.host,i.description");
- while($row=DBfetch($result))
+ $description = '';
+ if($itemid > 0)
{
- $cmbItems->AddItem($row["itemid"],
- $row["host"].":".SPACE.item_description($row["description"],$row["key_"]));
+ $description = DBfetch(DBselect("select * from items where itemid=".$itemid));
+ $description = $description['description'];
}
- $frmGItem->AddRow(S_PARAMETER, $cmbItems);
+
+ $frmGItem->AddVar('itemid',$itemid);
+
+ $txtCondVal = new CTextBox('description',$description,50);
+ $txtCondVal->SetReadonly('yes');
+
+ $btnSelect = new CButton('btn1',S_SELECT,
+ "return PopUp('popup.php?dstfrm=".$frmGItem->GetName().
+ "&dstfld1=itemid&dstfld2=description&".
+ "srctbl=items&srcfld1=itemid&srcfld2=description".$host_condition."','new_win',".
+ "'width=600,height=450,resizable=1,scrollbars=1');");
+
+ $btnSelect->SetAccessKey('T');
+ $frmGItem->AddRow(S_PARAMETER ,array($txtCondVal,$btnSelect));
if($db_graph["graphtype"] == GRAPH_TYPE_NORMAL)
{
@@ -1214,7 +1520,7 @@
{
array_push($valuemap_el,
array(
- new CCheckBox("rem_value[]", 'no', NULL, $i),
+ new CCheckBox("rem_value[]", 'no', null, $i),
$value["value"].SPACE.RARR.SPACE.$value["newvalue"]
),
BR);
@@ -1254,8 +1560,9 @@
function insert_action_form()
{
global $_REQUEST;
+ global $ZBX_CURNODEID;
- $uid=NULL;
+ $uid=null;
$frmAction = new CFormTable(S_ACTION,'actionconf.php');
$frmAction->SetHelp('web.actions.action.php');
@@ -1343,7 +1650,7 @@
{
array_push($cond_el,
array(
- new CCheckBox("rem_condition[]", 'no', NULL,$i),
+ new CCheckBox("rem_condition[]", 'no', null,$i),
get_condition_desc(
$val["type"],
$val["operator"],
@@ -1416,13 +1723,18 @@
// add condition value
if($new_condition_type == CONDITION_TYPE_GROUP)
{
- $cmbCondVal = new CComboBox('new_condition_value');
- $groups = DBselect("select groupid,name from groups order by name");
- while($group = DBfetch($groups))
- {
- $cmbCondVal->AddItem($group["groupid"],$group["name"]);
- }
- array_push($rowCondition,$cmbCondVal);
+ $frmAction->AddVar('new_condition_value','0');
+
+ $txtCondVal = new CTextBox('group','',20);
+ $txtCondVal->SetReadonly('yes');
+
+ $btnSelect = new CButton('btn1',S_SELECT,
+ "return PopUp('popup.php?dstfrm=".$frmAction->GetName().
+ "&dstfld1=new_condition_value&dstfld2=group&srctbl=host_group&srcfld1=groupid&srcfld2=name','new_win',".
+ "'width=450,height=450,resizable=1,scrollbars=1');");
+ $btnSelect->SetAccessKey('T');
+
+ array_push($rowCondition, $txtCondVal, $btnSelect);
}
else if($new_condition_type == CONDITION_TYPE_HOST)
{
@@ -1471,12 +1783,9 @@
else if($new_condition_type == CONDITION_TYPE_TRIGGER_SEVERITY)
{
$cmbCondVal = new CComboBox('new_condition_value');
- $cmbCondVal->AddItem(0,S_NOT_CLASSIFIED);
- $cmbCondVal->AddItem(1,S_INFORMATION);
- $cmbCondVal->AddItem(2,S_WARNING);
- $cmbCondVal->AddItem(3,S_AVERAGE);
- $cmbCondVal->AddItem(4,S_HIGH);
- $cmbCondVal->AddItem(5,S_DISASTER);
+ foreach(array(0,1,2,3,4,5) as $id)
+ $cmbCondVal->AddItem($id,get_severity_description($id));
+
array_push($rowCondition,$cmbCondVal);
}
// add condition button
@@ -1501,8 +1810,9 @@
$cmbGroups = new CComboBox('userid', $uid);
- $sql="select usrgrpid,name from usrgrp order by name";
- $groups=DBselect($sql);
+ $groups = DBselect("select usrgrpid,name from usrgrp ".
+ " where ".Dbid2nodeid("usrgrpid")."=".$ZBX_CURNODEID.
+ " order by name");
while($group=DBfetch($groups))
{
$cmbGroups->AddItem($group['usrgrpid'],$group['name']);
@@ -1514,8 +1824,9 @@
{
$cmbUser = new CComboBox('userid', $uid);
- $sql="select userid,alias from users order by alias";
- $users=DBselect($sql);
+ $users=DBselect("select userid,alias from users ".
+ " where ".Dbid2nodeid("userid")."=".$ZBX_CURNODEID.
+ " order by alias");
while($user=DBfetch($users))
{
$cmbUser->AddItem($user['userid'],$user['alias']);
@@ -1583,26 +1894,27 @@
if(isset($_REQUEST["mediatypeid"]) && !isset($_REQUEST["form_refresh"]))
{
- $result=DBselect("select mediatypeid,type,description,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem from media_type where mediatypeid=".$_REQUEST["mediatypeid"]);
- $row=DBfetch($result);
- $mediatypeid=$row["mediatypeid"];
- $type=@iif(isset($_REQUEST["type"]),$_REQUEST["type"],$row["type"]);
- $description=$row["description"];
- $smtp_server=$row["smtp_server"];
- $smtp_helo=$row["smtp_helo"];
- $smtp_email=$row["smtp_email"];
- $exec_path=$row["exec_path"];
- $gsm_modem=$row["gsm_modem"];
+ $result = DBselect("select mediatypeid,type,description,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem ".
+ "from media_type where mediatypeid=".$_REQUEST["mediatypeid"]);
+
+ $row = DBfetch($result);
+ $mediatypeid = $row["mediatypeid"];
+ $type = get_request("type",$row["type"]);
+ $description = $row["description"];
+ $smtp_server = $row["smtp_server"];
+ $smtp_helo = $row["smtp_helo"];
+ $smtp_email = $row["smtp_email"];
+ $exec_path = $row["exec_path"];
+ $gsm_modem = $row["gsm_modem"];
}
- $frmMeadia = new CFormTable(S_MEDIA,"config.php");
+ $frmMeadia = new CFormTable(S_MEDIA);
$frmMeadia->SetHelp("web.config.medias.php");
if(isset($_REQUEST["mediatypeid"]))
{
$frmMeadia->AddVar("mediatypeid",$_REQUEST["mediatypeid"]);
}
- $frmMeadia->AddVar("config",1);
$frmMeadia->AddRow(S_DESCRIPTION,new CTextBox("description",$description,30));
$cmbType = new CComboBox("type",$type,"submit()");
@@ -1640,10 +1952,10 @@
{
$frmMeadia->AddItemToBottomRow(SPACE);
$frmMeadia->AddItemToBottomRow(new CButtonDelete(S_DELETE_SELECTED_MEDIA,
- url_param("form").url_param("config").url_param("mediatypeid")));
+ url_param("form").url_param("mediatypeid")));
}
$frmMeadia->AddItemToBottomRow(SPACE);
- $frmMeadia->AddItemToBottomRow(new CButtonCancel(url_param("config")));
+ $frmMeadia->AddItemToBottomRow(new CButtonCancel());
$frmMeadia->Show();
}
@@ -1688,7 +2000,7 @@
if($imageid > 0)
{
$frmImages->AddRow(S_IMAGE,new CLink(
- new CImg("image.php?width=640&height=480&imageid=".$imageid,"no image",NULL),
+ new CImg("image.php?width=640&height=480&imageid=".$imageid,"no image",null),
"image.php?imageid=".$row["imageid"]));
}
@@ -1754,6 +2066,7 @@
function& get_screen_item_form()
{
global $_REQUEST;
+ global $USER_DETAILS;
$form = new CFormTable(S_SCREEN_CELL_CONFIGURATION,"screenedit.php#form");
$form->SetHelp("web.screenedit.cell.php");
@@ -1822,16 +2135,20 @@
if($resourcetype == SCREEN_RESOURCE_GRAPH)
{
// User-defined graph
- $result=DBselect("select graphid,name from graphs order by name");
+ $result = DBselect("select distinct g.graphid,g.name,n.name as node_name ".
+ " from graphs g, nodes n, graphs_items gi, items i, hosts h ".
+ " where n.nodeid=".DBid2nodeid("g.graphid")." and g.graphid=gi.graphid ".
+ " and gi.itemid=i.itemid and h.hostid=i.hostid".
+ " and i.hostid not in (".get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_MODE_LT).")".
+ " order by node_name,host,name,graphid");
$cmbGraphs = new CComboBox("resourceid",$resourceid);
while($row=DBfetch($result))
{
- $db_hosts = get_hosts_by_graphid($row["graphid"]);
- $db_host = DBfetch($db_hosts);
+ $db_host = DBfetch(get_hosts_by_graphid($row["graphid"]));
if($db_host)
{
- $name = $db_host["host"].":".$row["name"];
+ $name = "(".$row["node_name"].") ".$db_host["host"].":".$row["name"];
}
else
{
@@ -1845,17 +2162,18 @@
elseif($resourcetype == SCREEN_RESOURCE_SIMPLE_GRAPH)
{
// Simple graph
- $result=DBselect("select h.host,i.description,i.itemid,i.key_".
- " from hosts h,items i where h.hostid=i.hostid".
+ $result=DBselect("select n.name as node_name,h.host,i.description,i.itemid,i.key_".
+ " from hosts h,items i,nodes n where h.hostid=i.hostid and n.nodeid=".DBid2nodeid("i.itemid").
" and h.status=".HOST_STATUS_MONITORED." and i.status=".ITEM_STATUS_ACTIVE.
- " order by h.host,i.description");
+ " and i.hostid not in (".get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_MODE_LT).")".
+ " order by node_name,h.host,i.description");
$cmbItems = new CCombobox("resourceid",$resourceid);
while($row=DBfetch($result))
{
$description_=item_description($row["description"],$row["key_"]);
- $cmbItems->AddItem($row["itemid"],$row["host"].": ".$description_);
+ $cmbItems->AddItem($row["itemid"],"(".$row["node_name"].") ".$row["host"].": ".$description_);
}
$form->AddRow(S_PARAMETER,$cmbItems);
@@ -1863,12 +2181,15 @@
elseif($resourcetype == SCREEN_RESOURCE_MAP)
{
// Map
- $result=DBselect("select sysmapid,name from sysmaps order by name");
+ $result=DBselect("select n.name as node_name, s.sysmapid,s.name from sysmaps s, nodes n".
+ " where n.nodeid=".DBid2nodeid("s.sysmapid").
+ " order by name ");
$cmbMaps = new CComboBox("resourceid",$resourceid);
while($row=DBfetch($result))
{
- $cmbMaps->AddItem($row["sysmapid"],$row["name"]);
+ if(!sysmap_accessiable($row["sysmapid"],PERM_READ_ONLY)) continue;
+ $cmbMaps->AddItem($row["sysmapid"],"(".$row["node_name"].") ".$row["name"]);
}
$form->AddRow(S_MAP,$cmbMaps);
@@ -1876,16 +2197,17 @@
elseif($resourcetype == SCREEN_RESOURCE_PLAIN_TEXT)
{
// Plain text
- $result=DBselect("select h.host,i.description,i.itemid,i.key_".
- " from hosts h,items i where h.hostid=i.hostid".
+ $result=DBselect("select n.name as node_name,h.host,i.description,i.itemid,i.key_".
+ " from hosts h,items i,nodes n where h.hostid=i.hostid and n.nodeid=".DBid2nodeid("i.itemid").
" and h.status=".HOST_STATUS_MONITORED." and i.status=".ITEM_STATUS_ACTIVE.
- " order by h.host,i.description");
+ " and i.hostid not in (".get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_MODE_LT).")".
+ " order by node_name,h.host,i.description");
$cmbHosts = new CComboBox("resourceid",$resourceid);
while($row=DBfetch($result))
{
$description_=item_description($row["description"],$row["key_"]);
- $cmbHosts->AddItem($row["itemid"],$row["host"].": ".$description_);
+ $cmbHosts->AddItem($row["itemid"],"(".$row["node_name"].") ".$row["host"].": ".$description_);
}
@@ -1910,25 +2232,14 @@
$cmbGroup = new CComboBox("resourceid",$resourceid);
$cmbGroup->AddItem(0,S_ALL_SMALL);
- $result=DBselect("select groupid,name from groups order by name");
+ $result=DBselect("select distinct n.name as node_name,g.groupid,g.name from groups g,nodes n,hosts_groups hg,hosts h ".
+ " where g.groupid in (".get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY).")".
+ " and n.nodeid=".DBid2nodeid("g.groupid")." and g.groupid=hg.groupid and hg.hostid=h.hostid ".
+ " and h.status=".HOST_STATUS_MONITORED.
+ " order by node_name,g.name");
while($row=DBfetch($result))
{
- $cmbGroup = new CComboBox("resourceid",$resourceid);
-
- $cmbGroup->AddItem(0,S_ALL_SMALL);
- $result=DBselect("select groupid,name from groups order by name");
- while($row=DBfetch($result))
- {
- $result2=DBselect("select h.hostid,h.host from hosts h,items i,hosts_groups hg where".
- " h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid and hg.groupid=".$row["groupid"].
- " and hg.hostid=h.hostid group by h.hostid,h.host order by h.host");
- while($row2=DBfetch($result2))
- {
- if(!check_right("Host","R",$row2["hostid"])) continue;
- $cmbGroup->AddItem($row["groupid"],$row["name"]);
- break;
- }
- }
+ $cmbGroup->AddItem($row["groupid"],"(".$row["node_name"].") ".$row["name"]);
}
$form->AddRow(S_GROUP,$cmbGroup);
@@ -1936,12 +2247,15 @@
elseif($resourcetype == SCREEN_RESOURCE_SCREEN)
{
$cmbScreens = new CComboBox("resourceid",$resourceid);
- $result=DBselect("select screenid,name from screens");
+ $result=DBselect("select distinct n.name as node_name,s.screenid,s.name from screens s,nodes n ".
+ " where n.nodeid=".DBid2nodeid("s.screenid").
+ " order by node_name,s.name");
while($row=DBfetch($result))
{
+ if(!screen_accessiable($row["screenid"], PERM_READ_ONLY)) continue;
if(check_screen_recursion($_REQUEST["screenid"],$row["screenid"]))
continue;
- $cmbScreens->AddItem($row["screenid"],$row["name"]);
+ $cmbScreens->AddItem($row["screenid"],"(".$row["node_name"].") ".$row["name"]);
}
@@ -2018,7 +2332,7 @@
if(isset($_REQUEST["screenitemid"]))
{
$form->AddItemToBottomRow(SPACE);
- $form->AddItemToBottomRow(new CButtonDelete(NULL,
+ $form->AddItemToBottomRow(new CButtonDelete(null,
url_param("form").url_param("screenid").url_param("screenitemid")));
}
$form->AddItemToBottomRow(SPACE);
@@ -2027,46 +2341,25 @@
}
function insert_media_form()
- {
- global $_REQUEST;
+ { /* NOTE: only NEW media is acessed */
- $severity = get_request("severity",array());
+ global $_REQUEST;
+ global $ZBX_CURNODEID;
- if(isset($_REQUEST["mediaid"]) && !isset($_REQUEST["form_refresh"]))
- {
- $media=get_media_by_mediaid($_REQUEST["mediaid"]);
+ $severity = get_request("severity",array(0,1,2,3,4,5));
+ $sendto = get_request("sendto","");
+ $mediatypeid = get_request("mediatypeid",0);
+ $active = get_request("active",0);
+ $period = get_request("period","1-7,00:00-23:59");
- $sendto = $media["sendto"];
- $mediatypeid = $media["mediatypeid"];
- $active = $media["active"];
- $period = $media["period"];
+ $frmMedia = new CFormTable(S_NEW_MEDIA);
+ $frmMedia->SetHelp("web.media.php");
- if($media["severity"] & 1) array_push($severity,0);
- if($media["severity"] & 2) array_push($severity,1);
- if($media["severity"] & 4) array_push($severity,2);
- if($media["severity"] & 8) array_push($severity,3);
- if($media["severity"] & 16) array_push($severity,4);
- if($media["severity"] & 32) array_push($severity,5);
- }
- else
- {
- $sendto = get_request("sendto","");
- $mediatypeid = get_request("mediatypeid",0);
- $active = get_request("active",0);
- $period = get_request("period","1-7,00:00-23:59");
- }
-
- $frmMedia = new CFormTable(S_NEW_MEDIA,"media.php");
- $frmMedia->SetHelp("web.media.media.php");
-
- $frmMedia->AddVar("userid",$_REQUEST["userid"]);
- if(isset($_REQUEST["mediaid"]))
- {
- $frmMedia->AddVar("mediaid",$_REQUEST["mediaid"]);
- }
+ $frmMedia->AddVar("dstfrm",$_REQUEST["dstfrm"]);
$cmbType = new CComboBox("mediatypeid",$mediatypeid);
- $types=DBselect("select mediatypeid,description from media_type order by type");
+ $types=DBselect("select mediatypeid,description from media_type".
+ " where ".DBid2nodeid("mediatypeid")."=".$ZBX_CURNODEID." order by type");
while($type=DBfetch($types))
{
$cmbType->AddItem($type["mediatypeid"],$type["description"]);
@@ -2076,14 +2369,6 @@
$frmMedia->AddRow(S_SEND_TO,new CTextBox("sendto",$sendto,20));
$frmMedia->AddRow(S_WHEN_ACTIVE,new CTextBox("period",$period,48));
-
- $label[0] = S_NOT_CLASSIFIED;
- $label[1] = S_INFORMATION;
- $label[2] = S_WARNING;
- $label[3] = S_AVERAGE;
- $label[4] = S_HIGH;
- $label[5] = S_DISASTER;
-
$frm_row = array();
for($i=0; $i<=5; $i++){
array_push($frm_row,
@@ -2091,9 +2376,9 @@
new CCheckBox(
"severity[]",
in_array($i,$severity)?'yes':'no',
- NULL, /* action */
+ null, /* action */
$i), /* value */
- $label[$i]
+ get_severity_description($i)
),
BR);
}
@@ -2104,15 +2389,9 @@
$cmbStat->AddItem(1,S_DISABLED);
$frmMedia->AddRow("Status",$cmbStat);
- $frmMedia->AddItemToBottomRow(new CButton("save", S_SAVE));
- if(isset($_REQUEST["mediaid"]))
- {
- $frmMedia->AddItemToBottomRow(SPACE);
- $frmMedia->AddItemToBottomRow(new CButtonDelete(S_DELETE_SELECTED_MEDIA_Q,
- url_param("form").url_param("userid").url_param("mediaid")));
- }
+ $frmMedia->AddItemToBottomRow(new CButton("add", S_ADD));
$frmMedia->AddItemToBottomRow(SPACE);
- $frmMedia->AddItemToBottomRow(new CButtonCancel(url_param("userid")));
+ $frmMedia->AddItemToBottomRow(new CButton('cancel',S_CANCEL,'window.close();'));
$frmMedia->Show();
}
@@ -2128,7 +2407,7 @@
$frmHouseKeep->AddRow(S_DO_NOT_KEEP_ACTIONS_OLDER_THAN,
new CTextBox("alert_history",$config["alert_history"],8));
$frmHouseKeep->AddRow(S_DO_NOT_KEEP_EVENTS_OLDER_THAN,
- new CTextBox("alarm_history",$config["alarm_history"],8));
+ new CTextBox("event_history",$config["event_history"],8));
$frmHouseKeep->AddItemToBottomRow(new CButton("save",S_SAVE));
$frmHouseKeep->Show();
}
@@ -2141,7 +2420,7 @@
$frmHouseKeep->SetHelp("web.config.workperiod.php");
$frmHouseKeep->AddVar("config",get_request("config",7));
$frmHouseKeep->AddVar("alert_history",$config["alert_history"]);
- $frmHouseKeep->AddVar("alarm_history",$config["alarm_history"]);
+ $frmHouseKeep->AddVar("event_history",$config["event_history"]);
$frmHouseKeep->AddVar("refresh_unsupported",$config["refresh_unsupported"]);
$frmHouseKeep->AddRow(S_WORKING_TIME,
new CTextBox("work_period",$config["work_period"],35));
@@ -2157,7 +2436,7 @@
$frmHouseKeep->SetHelp("web.config.other.php");
$frmHouseKeep->AddVar("config",get_request("config",5));
$frmHouseKeep->AddVar("alert_history",$config["alert_history"]);
- $frmHouseKeep->AddVar("alarm_history",$config["alarm_history"]);
+ $frmHouseKeep->AddVar("event_history",$config["event_history"]);
$frmHouseKeep->AddVar("work_period",$config["work_period"]);
$frmHouseKeep->AddRow(S_REFRESH_UNSUPPORTED_ITEMS,
new CTextBox("refresh_unsupported",$config["refresh_unsupported"],8));
@@ -2167,7 +2446,8 @@
function insert_host_form($show_only_tmp=0)
{
-
+ global $ZBX_CURNODEID;
+ global $USER_DETAILS;
global $_REQUEST;
$groups= get_request("groups",array());
@@ -2215,7 +2495,10 @@
$templateid = $db_host["templateid"];
// add groups
- $db_groups=DBselect("select groupid from hosts_groups where hostid=".$_REQUEST["hostid"]);
+ $db_groups=DBselect("select distinct groupid from hosts_groups where hostid=".$_REQUEST["hostid"].
+ " and groupid in (".
+ get_accessible_groups_by_user($USER_DETAILS,PERM_READ_LIST,null,null,$ZBX_CURNODEID).
+ ") ");
while($db_group=DBfetch($db_groups)){
if(in_array($db_group["groupid"],$groups)) continue;
array_push($groups, $db_group["groupid"]);
@@ -2263,14 +2546,18 @@
$frmHost->AddRow(S_NAME,new CTextBox("host",$host,20));
$frm_row = array();
- $db_groups=DBselect("select distinct groupid,name from groups order by name");
+
+ $db_groups=DBselect("select distinct groupid,name from groups ".
+ " where groupid in (".
+ get_accessible_groups_by_user($USER_DETAILS,PERM_READ_LIST,null,null,$ZBX_CURNODEID).
+ ") order by name");
while($db_group=DBfetch($db_groups))
{
array_push($frm_row,
array(
new CCheckBox("groups[]",
in_array($db_group["groupid"],$groups) ? 'yes' : 'no',
- NULL,
+ null,
$db_group["groupid"]
),
$db_group["name"]
@@ -2333,6 +2620,7 @@
$cmbHosts->AddItem(0,"...");
$hosts=DBselect("select host,hostid from hosts where status in (".HOST_STATUS_TEMPLATE.")".
+ " and hostid in (".get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_LIST,null,null,$ZBX_CURNODEID).") ".
" order by host");
while($host=DBfetch($hosts))
{
@@ -2476,7 +2764,7 @@
# Insert host profile ReadOnly form
function insert_host_profile_form()
{
- $frmHostP = new CFormTable(S_HOST_PROFILE,"hosts.php");
+ $frmHostP = new CFormTable(S_HOST_PROFILE);
$frmHostP->SetHelp("web.host_profile.php");
$result=DBselect("select * from hosts_profiles where hostid=".$_REQUEST["hostid"]);
@@ -2513,6 +2801,7 @@
{
$frmHostP->AddSpanRow("Profile for this host is missing","form_row_c");
}
+ $frmHostP->AddItemToBottomRow(new CButtonCancel(url_param("groupid")));
$frmHostP->Show();
}
@@ -2590,6 +2879,7 @@
function insert_map_form()
{
global $_REQUEST;
+ global $ZBX_CURNODEID;
$frm_title = "New system map";
@@ -2604,7 +2894,7 @@
$name = $row["name"];
$width = $row["width"];
$height = $row["height"];
- $background = $row["background"];
+ $backgroundid = $row["backgroundid"];
$label_type = $row["label_type"];
$label_location = $row["label_location"];
}
@@ -2613,7 +2903,7 @@
$name = get_request("name","");
$width = get_request("width",800);
$height = get_request("height",600);
- $background = get_request("background","");
+ $backgroundid = get_request("backgroundid",0);
$label_type = get_request("label_type",0);
$label_location = get_request("label_location",0);
}
@@ -2629,11 +2919,13 @@
$frmMap->AddRow(S_WIDTH,new CTextBox("width",$width,5));
$frmMap->AddRow(S_HEIGHT,new CTextBox("height",$height,5));
- $cmbImg = new CComboBox("background",$background);
- $cmbImg->AddItem('',"No image...");
- $result=DBselect("select name from images where imagetype=2 order by name");
+ $cmbImg = new CComboBox("backgroundid",$backgroundid);
+ $cmbImg->AddItem(0,"No image...");
+ $result=DBselect("select * from images where imagetype=2 and ".DBid2nodeid("imageid")."=".$ZBX_CURNODEID." order by name");
while($row=DBfetch($result))
- $cmbImg->AddItem($row["name"],$row["name"]);
+ {
+ $cmbImg->AddItem($row["imageid"],$row["name"]);
+ }
$frmMap->AddRow(S_BACKGROUND_IMAGE,$cmbImg);
$cmbLabel = new CComboBox("label_type",$label_type);
@@ -2668,6 +2960,9 @@
function insert_map_element_form()
{
+ global $ZBX_CURNODEID;
+ global $USER_DETAILS;
+
$frmEl = new CFormTable("New map element","sysmap.php");
$frmEl->SetHelp("web.sysmap.host.php");
$frmEl->AddVar("sysmapid",$_REQUEST["sysmapid"]);
@@ -2687,9 +2982,9 @@
$label = $element["label"];
$x = $element["x"];
$y = $element["y"];
- $icon = $element["icon"];
$url = $element["url"];
- $icon_on = $element["icon_on"];
+ $iconid_off = $element["iconid_off"];
+ $iconid_on = $element["iconid_on"];
$label_location = $element["label_location"];
if(is_null($label_location)) $label_location = -1;
}
@@ -2700,16 +2995,21 @@
$label = get_request("label", "");
$x = get_request("x", 0);
$y = get_request("y", 0);
- $icon = get_request("icon", "");
$url = get_request("url", "");
- $icon_on = get_request("icon_on", "");
+ $iconid_off = get_request("iconid_off", 0);
+ $iconid_on = get_request("iconid_on", 0);
$label_location = get_request("label_location", "-1");
}
$cmbType = new CComboBox("elementtype",$elementtype,"submit()");
- $db_hosts = DBselect("select hostid from hosts");
- if(DBfetch($db_hosts))
+ $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_MODE_LT);
+
+ $db_hosts = DBselect("select distinct n.name as node_name,h.hostid,h.host from hosts h,nodes n ".
+ " where h.hostid not in(".$denyed_hosts.")".
+ " and n.nodeid=".DBid2nodeid("h.hostid").
+ " order by node_name,h.host");
+ if($db_hosts)
$cmbType->AddItem(SYSMAP_ELEMENT_TYPE_HOST, S_HOST);
$db_maps = DBselect("select sysmapid from sysmaps where sysmapid!=".$_REQUEST["sysmapid"]);
@@ -2733,10 +3033,11 @@
if($elementtype==SYSMAP_ELEMENT_TYPE_HOST)
{
$host = "";
- $host_info = 0;
- $db_hosts = DBselect("select host from hosts where hostid=$elementid");
- $host_info = DBfetch($db_hosts);
+ $host_info = DBfetch(DBselect("select distinct n.name as node_name,h.hostid,h.host from hosts h,nodes n ".
+ " where h.hostid not in(".$denyed_hosts.") and hostid=".$elementid.
+ " and n.nodeid=".DBid2nodeid("h.hostid").
+ " order by node_name,h.host"));
if($host_info)
$host = $host_info["host"];
else
@@ -2744,10 +3045,8 @@
if($elementid==0)
{
- $db_hosts = DBselect("select hostid,host from hosts",1);
- $db_host = DBfetch($db_hosts);
- $host = $db_host["host"];
- $elementid = $db_host["hostid"];
+ $host = "";
+ $elementid = 0;
}
$frmEl->AddVar("elementid",$elementid);
@@ -2761,10 +3060,13 @@
elseif($elementtype==SYSMAP_ELEMENT_TYPE_MAP)
{
$cmbMaps = new CComboBox("elementid",$elementid);
- $db_maps = DBselect("select sysmapid,name from sysmaps");
+ $db_maps = DBselect("select distinct n.name as node_name,s.sysmapid,s.name from sysmaps s,nodes n ".
+ " where ".DBid2nodeid("s.sysmapid")."=n.nodeid".
+ " order by node_name,s.name");
while($db_map = DBfetch($db_maps))
{
- $cmbMaps->AddItem($db_map["sysmapid"],$db_map["name"]);
+ if(!sysmap_accessiable($db_map["sysmapid"],PERM_READ_ONLY)) continue;
+ $cmbMaps->AddItem($db_map["sysmapid"],"(".$db_map['node_name'].") ".$db_map["name"]);
}
$frmEl->AddRow(S_MAP, $cmbMaps);
}
@@ -2772,27 +3074,32 @@
{
$cmbTriggers= new CComboBox("elementid",$elementid);
$cmbTriggers->AddItem(0,"-");
- $db_triggers = DBselect("select triggerid from triggers");
+ $db_triggers = DBselect("select distinct n.name as node_name,h.hostid,h.host,t.*".
+ " from triggers t,hosts h,items i,functions f,nodes n ".
+ " where f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid".
+ " and h.hostid not in (".$denyed_hosts.")".
+ " and ".DBid2nodeid("h.hostid")."=n.nodeid".
+ " order by node_name,h.host,t.description");
+
while($db_trigger = DBfetch($db_triggers))
{
$cmbTriggers->AddItem(
$db_trigger["triggerid"],
- expand_trigger_description($db_trigger["triggerid"]));
+ "(".$db_trigger['node_name'].") ".expand_trigger_description($db_trigger["triggerid"]));
}
$frmEl->AddRow(S_TRIGGER, $cmbTriggers);
}
- $cmbIcon = new CComboBox("icon",$icon);
- $result=DBselect("select name from images where imagetype=1 order by name");
+ $cmbIconOff = new CComboBox("iconid_off",$iconid_off);
+ $cmbIconOn = new CComboBox("iconid_on",$iconid_on);
+ $result = DBselect("select * from images where imagetype=1 and ".DBid2nodeid("imageid")."=".$ZBX_CURNODEID." order by name");
while($row=DBfetch($result))
- $cmbIcon->AddItem($row["name"],$row["name"]);
- $frmEl->AddRow("Icon (OFF)",$cmbIcon);
-
- $cmbIcon = new CComboBox("icon_on",$icon_on);
- $result=DBselect("select name from images where imagetype=1 order by name");
- while($row=DBfetch($result))
- $cmbIcon->AddItem($row["name"],$row["name"]);
- $frmEl->AddRow("Icon (ON)",$cmbIcon);
+ {
+ $cmbIconOff->AddItem($row["imageid"],$row["name"]);
+ $cmbIconOn->AddItem($row["imageid"],$row["name"]);
+ }
+ $frmEl->AddRow("Icon (OFF)",$cmbIconOff);
+ $frmEl->AddRow("Icon (ON)",$cmbIconOn);
$frmEl->AddRow("Coordinate X", new CTextBox("x", $x, 5));
$frmEl->AddRow("Coordinate Y", new CTextBox("y", $y, 5));
diff --git a/frontends/php/include/graphs.inc.php b/frontends/php/include/graphs.inc.php
index 32803367..20219ee9 100644
--- a/frontends/php/include/graphs.inc.php
+++ b/frontends/php/include/graphs.inc.php
@@ -99,18 +99,12 @@
function add_graph($name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$showtriggers,$graphtype=GRAPH_TYPE_NORMAL,$templateid=0)
{
- if(!check_right("Graph","A",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
- $graphid=get_dbid("graphs","graphid");
+ $graphid = get_dbid("graphs","graphid");
$result=DBexecute("insert into graphs".
- " (graphid,name,width,height,yaxistype,yaxismin,yaxismax,templateid,show_work_period,show_triggers,graphtype,templateid)".
+ " (graphid,name,width,height,yaxistype,yaxismin,yaxismax,templateid,show_work_period,show_triggers,graphtype)".
" values ($graphid,".zbx_dbstr($name).",$width,$height,$yaxistype,$yaxismin,".
- " $yaxismax,$templateid,$showworkperiod,$showtriggers,$graphtype,$templateid)");
+ " $yaxismax,$templateid,$showworkperiod,$showtriggers,$graphtype)");
if($result)
{
info("Graph '$name' added");
@@ -122,12 +116,6 @@
function update_graph($graphid,$name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$showtriggers,$graphtype=GRAPH_TYPE_NORMAL,$templateid=0)
{
- if(!check_right("Graph","U",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
$g_graph = get_graph_by_graphid($graphid);
$graphs = get_graphs_by_templateid($graphid);
@@ -159,12 +147,6 @@
function delete_graph($graphid)
{
- if(!check_right("Graph","U",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
$graph = get_graph_by_graphid($graphid);
$chd_graphs = get_graphs_by_templateid($graphid);
@@ -184,10 +166,6 @@
if($result)
{
info("Graph '".$graph["name"]."' deleted");
-
- // delete graph permisions
- DBexecute('delete from rights where name=\'Graph\' and id='.$graphid);
-
}
return $result;
}
@@ -652,7 +630,7 @@
if(isset($_REQUEST[$item]))
$form->AddVar($item,$_REQUEST[$item]);
- show_header2(
+ show_table_header(
S_NAVIGATE,
$form);
diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php
index de8de4e4..25a05dc3 100644
--- a/frontends/php/include/hosts.inc.php
+++ b/frontends/php/include/hosts.inc.php
@@ -19,6 +19,10 @@
**/
?>
<?php
+require_once "include/graphs.inc.php";
+require_once "include/profiles.inc.php";
+require_once "include/triggers.inc.php";
+require_once "include/items.inc.php";
/* HOST GROUP functions */
function add_host_to_group($hostid, $groupid)
@@ -55,7 +59,7 @@
if($groupid==NULL)
{
$groupid=get_dbid("groups","groupid");
- if(!DBexecute("insert into groups (name) values (".zbx_dbstr($name).")"))
+ if(!DBexecute("insert into groups (groupid,name) values (".$groupid.",".zbx_dbstr($name).")"))
return FALSE;
return $groupid;
@@ -69,12 +73,10 @@
if($newgroup == "" || $newgroup == NULL)
return TRUE;
- $result = db_save_group($newgroup);
- if(!$result)
- return $result;
+ $groupid = db_save_group($newgroup);
+ if(!$groupid)
+ return $groupid;
- $groupid = DBinsert_id($result,"groups","groupid");
-
return add_host_to_group($hostid, $groupid);
}
@@ -100,18 +102,10 @@
function add_host_group($name,$hosts=array())
{
-// if(!check_right("Host","A",0))
-// {
-// error("Insufficient permissions");
-// return FLASE;
-// }
-
- $result = db_save_group($name);
- if(!$result)
- return $result;
+ $groupid = db_save_group($name);
+ if(!$groupid)
+ return $groupid;
- $groupid = DBinsert_id($result,"groups","groupid");
-
update_host_groups_by_groupid($groupid,$hosts);
return $groupid;
@@ -119,13 +113,6 @@
function update_host_group($groupid,$name,$hosts)
{
-// if(!check_right("Host","U",0))
-// {
-// error("Insufficient permissions");
-// return 0;
-// }
-
-
$result = db_save_group($name,$groupid);
if(!$result)
return $result;
@@ -170,6 +157,7 @@
if($useip=="on" || $useip=="yes" || $useip==1) $useip=1;
else $useip=0;
+
if($hostid==NULL)
{
$hostid = get_dbid("hosts","hostid");
@@ -198,17 +186,9 @@
function add_host($host,$port,$status,$useip,$ip,$templateid,$newgroup,$groups)
{
- if(!check_right("Host","A",0))
- {
- error("Insufficient permissions");
- return FALSE;
- }
-
- $result = db_save_host($host,$port,$status,$useip,$ip,$templateid);
- if(!$result)
- return $result;
-
- $hostid = DBinsert_id($result,"hosts","hostid");
+ $hostid = db_save_host($host,$port,$status,$useip,$ip,$templateid);
+ if(!$hostid)
+ return $hostid;
update_host_groups($hostid,$groups);
@@ -223,12 +203,6 @@
function update_host($hostid,$host,$port,$status,$useip,$ip,$templateid,$newgroup,$groups)
{
- if(!check_right("Host","U",$hostid))
- {
- error("Insufficient permissions");
- return FALSE;
- }
-
$old_host = get_host_by_hostid($hostid);
$result = db_save_host($host,$port,$status,$useip,$ip,$templateid,$hostid);
@@ -324,19 +298,16 @@
// delete host profile
delete_host_profile($hostid);
- // delete host permisions
- DBexecute('delete from rights where name=\'Host\' and id='.$hostid);
-
// delete host
return DBexecute("delete from hosts where hostid=$hostid");
}
function delete_host_group($groupid)
{
- $sql="delete from hosts_groups where groupid=$groupid";
- DBexecute($sql);
- $sql="delete from groups where groupid=$groupid";
- return DBexecute($sql);
+ if(!DBexecute("delete from hosts_groups where groupid=$groupid"))
+ return FALSE;
+
+ return DBexecute("delete from groups where groupid=$groupid");
}
function get_hostgroup_by_groupid($groupid)
@@ -387,12 +358,6 @@
function update_host_status($hostid,$status)
{
- if(!check_right("Host","U",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
$sql="select status,host from hosts where hostid=$hostid";
$result=DBselect($sql);
$row=DBfetch($result);
@@ -421,19 +386,21 @@
return get_template_path($tmp_host["hostid"]).$tmp_host["host"]."/";
}
- function get_correct_group_and_host($a_groupid=NULL, $a_hostid=NULL, $right="U", $options = array())
+ function get_correct_group_and_host($a_groupid=NULL, $a_hostid=NULL, $perm=PERM_READ_WRITE, $options = array())
{
if(!is_array($options))
{
- error("Incorrest options for get_correct_group_and_host");
- show_page_footer();
- exit;
+ fatal_error("Incorrest options for get_correct_group_and_host");
}
+
+ global $USER_DETAILS;
+ global $ZBX_CURNODEID;
- $first_hostig_in_group = 0;
+ $first_hostid_in_group = 0;
$allow_all_hosts = (in_array("allow_all_hosts",$options)) ? 1 : 0;
$always_select_first_host = in_array("always_select_first_host",$options) ? 1 : 0;
+ $only_current_node = in_array("only_current_node",$options) ? 1 : 0;
if(in_array("monitored_hosts",$options))
$with_host_status = " and h.status=".HOST_STATUS_MONITORED;
@@ -448,6 +415,10 @@
$item_table = ""; $with_items = "";
}
+ $with_node = "";
+
+ $accessed_hosts = get_accessible_hosts_by_user($USER_DETAILS,$perm);
+
if(is_null($a_groupid))
{
$groupid = 0;
@@ -456,27 +427,16 @@
{
$groupid = $a_groupid;
- if($groupid > 0)
- if(!DBfetch(DBselect("select hg.groupid from hosts_groups hg".
- " where hg.groupid=".$groupid." group by hg.groupid")))
- $groupid = 0;
-
if($groupid > 0)
{
- // Check if at least one host with read permission exists for this group
- $sql = "select distinct h.hostid,h.host from hosts h,hosts_groups hg".$item_table.
- " where hg.groupid=".$groupid." and hg.hostid=h.hostid and".
- " h.status<>".HOST_STATUS_DELETED.$with_host_status.$with_items.
- " order by h.host";
-
- $db_hosts = DBselect($sql);
- while($db_host = DBfetch($db_hosts))
+ if($only_current_node) $with_node = " and ".DBid2nodeid('g.groupid')."=".$ZBX_CURNODEID." ";
+
+ if(!DBfetch(DBselect("select distinct g.groupid from groups g, hosts_groups hg, hosts h".$item_table.
+ " where hg.groupid=g.groupid and h.hostid=hg.hostid and h.hostid in (".$accessed_hosts.") ".
+ " and g.groupid=".$groupid.$with_host_status.$with_items.$with_node)))
{
- if(!check_right("Host",$right,$db_host["hostid"])) continue;
- $first_hostig_in_group = $db_host["hostid"];
- break;
+ $groupid = 0;
}
- if($first_hostig_in_group == 0) $groupid = 0;
}
}
@@ -489,85 +449,105 @@
$hostid = $a_hostid;
if(!($hostid == 0 && $allow_all_hosts == 1)) /* is not 'All' selected */
{
- if($groupid == 0)
- {
- $sql = "select distinct h.hostid,h.host from hosts h".$item_table.
- " where h.status<>".HOST_STATUS_DELETED.$with_host_status.$with_items.
- " order by h.host";
+ $group_table = "";
+ $witth_group = "";
- $db_hosts = DBselect($sql);
- while($db_host = DBfetch($db_hosts))
+ if($groupid != 0)
+ {
+ if($only_current_node) $with_node = " and ".DBid2nodeid('hg.hostid')."=".$ZBX_CURNODEID." ";
+
+ if(!DBfetch(DBselect("select hg.hostid from hosts_groups hg".
+ " where hg.groupid=".$groupid." and hg.hostid=".$hostid.$with_node)))
{
- if(!check_right("Host",$right,$db_host["hostid"])) continue;
- $first_hostig_in_group = $db_host["hostid"];
- break;
+ $hostid = 0;
}
- if($first_hostig_in_group == 0) $hostid = 0;
+ $group_table = " ,hosts_groups hg ";
+ $witth_group = " and hg.hostid=h.hostid and hg.groupid=".$groupid;
}
- if($groupid > 0)
- {
- if(!DBfetch(DBselect("select hg.hostid from hosts_groups hg".
- " where hg.groupid=".$groupid." and hg.hostid=".$hostid)))
- $hostid = 0;
+ if($only_current_node) $with_node = " and ".DBid2nodeid('h.hostid')."=".$ZBX_CURNODEID." ";
+
+ if($db_host = DBfetch(DBselect("select distinct h.hostid,h.host from hosts h ".$item_table.$group_table.
+ " where h.hostid in (".$accessed_hosts.") "
+ .$with_host_status.$with_items.$witth_group.$with_node.
+ " order by h.host")))
+ {
+ $first_hostid_in_group = $db_host["hostid"];
}
- if(!check_right("Host",$right,$hostid)) $hostid = 0;
+ if($first_hostid_in_group == 0) $hostid = 0; /* no hosts in selected grpore */
if($hostid > 0)
{
+ if($only_current_node) $with_node = " and ".DBid2nodeid('h.hostid')."=".$ZBX_CURNODEID." ";
+
if(!DBfetch(DBselect("select distinct h.hostid from hosts h".$item_table.
- " where h.status<>".HOST_STATUS_DELETED.$with_host_status.$with_items.
- " and h.hostid=".$hostid)))
+ " where h.hostid=".$hostid.$with_host_status.$with_items.$with_node.
+ " and h.hostid in (".$accessed_hosts.") ")))
+ {
$hostid = 0;
+ }
}
+
if(($hostid < 0) || ($hostid == 0 && $always_select_first_host == 1)) /* incorrect host */
{
- $hostid = $first_hostig_in_group;
+ $hostid = $first_hostid_in_group;
}
}
}
- $host_correct = ($hostid == $a_hostid) ? 1 : 0;
- $group_correct = ($groupid == $a_groupid) ? 1 : 0;
- $correct = ($group_correct && $host_correct) ? 1 : 0;
-
- $result = array(
+ $group_correct = ($groupid == $a_groupid) ? 1 : 0;
+ $host_correct = ($hostid == $a_hostid) ? 1 : 0;
+ return array(
"groupid" => $groupid,
"group_correct" => $group_correct,
"hostid" => $hostid,
"host_correct" => $host_correct,
- "correct" => $correct
+ "correct" => ($group_correct && $host_correct) ? 1 : 0
);
-
- return $result;
}
- function validate_group_with_host($right, $options = array(),$group_var=NULL,$host_var=NULL)
+ function validate_group_with_host($perm, $options = array(),$group_var=NULL,$host_var=NULL)
{
if(is_null($group_var)) $group_var = "web.latest.groupid";
if(is_null($host_var)) $host_var = "web.latest.hostid";
- $_REQUEST["groupid"] = get_request("groupid",get_profile($group_var,0));
- $_REQUEST["hostid"] = get_request("hostid",get_profile($host_var,
- (in_array("always_select_first_host",$options)) ? -1 : 0));
+ $_REQUEST["groupid"] = get_request("groupid", -1 );
+ $_REQUEST["hostid"] = get_request("hostid", get_profile($host_var,0));
+
+ if($_REQUEST["groupid"] == -1)
+ {
+ if($_REQUEST["hostid"] > 0)
+ $_REQUEST["groupid"] = 0;
+ else
+ $_REQUEST["groupid"] = get_profile($group_var,0);
+ }
+
+// SDI("ig:".$_REQUEST["groupid"]);
+// SDI("ih:".$_REQUEST["hostid"]);
- $result = get_correct_group_and_host($_REQUEST["groupid"],$_REQUEST["hostid"], $right, $options);
+ if(in_array("always_select_first_host",$options) && $_REQUEST["hostid"] == 0 && $_REQUEST["groupid"] != 0)
+ $_REQUEST["hostid"] = -1;
+
+ $result = get_correct_group_and_host($_REQUEST["groupid"],$_REQUEST["hostid"], $perm, $options);
$_REQUEST["groupid"] = $result["groupid"];
$_REQUEST["hostid"] = $result["hostid"];
+// SDI("og:".$_REQUEST["groupid"]);
+// SDI("oh:".$_REQUEST["hostid"]);
+
update_profile($host_var,$_REQUEST["hostid"]);
update_profile($group_var,$_REQUEST["groupid"]);
}
- function validate_group($right, $options = array(),$group_var=NULL)
+ function validate_group($perm, $options = array(),$group_var=NULL)
{
if(is_null($group_var)) $group_var = "web.latest.groupid";
$_REQUEST["groupid"] = get_request("groupid",get_profile($group_var,0));
- $result = get_correct_group_and_host($_REQUEST["groupid"],NULL,$right,$options);
+ $result = get_correct_group_and_host($_REQUEST["groupid"],NULL,$perm,$options);
$_REQUEST["groupid"] = $result["groupid"];
@@ -681,9 +661,6 @@
$result = DBexecute("delete from applications where applicationid=$applicationid");
if($result)
{
- // delete application permisions
- DBexecute('delete from rights where name=\'Application\' and id='.$applicationid);
-
info("Application '".$host["host"].":".$app["name"]."' deleted");
}
return $result;
diff --git a/frontends/php/include/html.inc.php b/frontends/php/include/html.inc.php
index 9a4f593a..385675f1 100644
--- a/frontends/php/include/html.inc.php
+++ b/frontends/php/include/html.inc.php
@@ -85,22 +85,45 @@
}
}
- function url_param($parameter)
+ function prepare_url(&$var, $varname)
+ {
+ $result = "";
+
+ if(is_array($var))
+ {
+ foreach($var as $id => $par)
+ $result .= prepare_url($par,$varname."[".$id."]");
+ }
+ else
+ {
+ $result = "&".$varname."=".$var;
+ }
+ return $result;
+ }
+
+ function url_param($parameter,$request=true,$name=null)
{
- global $_REQUEST;
$result = "";
- if(isset($_REQUEST[$parameter]))
+
+ if(!isset($name)) $name = $parameter;
+
+ if($request)
{
- if(is_array($_REQUEST[$parameter]))
- {
- foreach($_REQUEST[$parameter] as $par)
- $result .= "&".$parameter."[]=".$par;
- }
- else
- {
- $result = "&".$parameter."=".$_REQUEST[$parameter];
- }
+ global $_REQUEST;
+
+ $var =& $_REQUEST[$parameter];
+ }
+ else
+ {
+ global $$parameter;
+
+ $var =& $$parameter;
+ }
+
+ if(isset($var))
+ {
+ $result = prepare_url($var,$name);
}
return $result;
}
@@ -160,7 +183,6 @@
function table_nodata($text="...")
{
- cr();
echo "<TABLE BORDER=0 align=center WIDTH=\"100%\" BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>";
echo "<TR BGCOLOR=\"#DDDDDD\">";
echo "<TD ALIGN=CENTER>";
@@ -168,6 +190,5 @@
echo "</TD>";
echo "</TR>";
echo "</TABLE>";
- cr();
}
?>
diff --git a/frontends/php/include/images.inc.php b/frontends/php/include/images.inc.php
new file mode 100644
index 00000000..f83ede93
--- /dev/null
+++ b/frontends/php/include/images.inc.php
@@ -0,0 +1,209 @@
+<?php
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+?>
+<?php
+ function get_image_by_imageid($imageid)
+ {
+ $result = DBselect('select * from images where imageid='.$imageid);
+ $row = DBfetch($result);
+ if($row)
+ {
+ global $DB_TYPE;
+
+ if($DB_TYPE == "ORACLE")
+ {
+ if(!isset($row['image']))
+ return 0;
+
+ $row['image'] = $row['image']->load();
+ }
+ else if($DB_TYPE == "POSTGRESQL")
+ {
+ $row['image'] = pg_unescape_bytea($row['image']);
+ }
+ return $row;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+ function add_image($name,$imagetype,$file)
+ {
+ if(!is_null($file))
+ {
+ if($file["error"] != 0 || $file["size"]==0)
+ {
+ error("Incorrect Image");
+ }
+ elseif($file["size"]<1024*1024)
+ {
+ global $DB_TYPE;
+ global $DB;
+
+ $imageid = get_dbid("images","imageid");
+
+ $image = fread(fopen($file["tmp_name"],"r"),filesize($file["tmp_name"]));
+ if($DB_TYPE == "ORACLE")
+ {
+ $lobimage = OCINewDescriptor($DB, OCI_D_LOB);
+
+ $stid = OCIParse($DB, "insert into images (imageid,name,imagetype,image)".
+ " values ($imageid,".zbx_dbstr($name).",".$imagetype.",EMPTY_BLOB())".
+ " return image into :image");
+ if(!$stid)
+ {
+ $e = ocierror($stid);
+ error("Parse SQL error [".$e["message"]."] in [".$e["sqltext"]."]");
+ return false;
+ }
+
+ OCIBindByName($stid, ':image', $lobimage, -1, OCI_B_BLOB);
+
+ if(!OCIExecute($stid, OCI_DEFAULT))
+ {
+ $e = ocierror($stid);
+ error("Execute SQL error [".$e["message"]."] in [".$e["sqltext"]."]");
+ return false;
+ }
+
+ if ($lobimage->save($image)) {
+ OCICommit($DB);
+ }
+ else {
+ OCIRollback($DB);
+ error("Couldn't save image!\n");
+ return false;
+ }
+
+ $lobimage->free();
+ OCIFreeStatement($stid);
+
+ return $stid;
+ }
+ else if($DB_TYPE == "POSTGRESQL")
+ {
+ $image = pg_escape_bytea($image);
+ }
+ else if($DB_TYPE == "MYSQL")
+ {
+ //$image = zbx_dbstr($image);
+ }
+ else
+ {
+ $image = '';
+ }
+
+ return DBexecute("insert into images (imageid,name,imagetype,image)".
+ " values ($imageid,".zbx_dbstr($name).",".$imagetype.",".zbx_dbstr($image).")");
+ }
+ else
+ {
+ error("Image size must be less than 1Mb");
+ }
+ }
+ else
+ {
+ error("Select image to download");
+ }
+ return false;
+ }
+
+ function update_image($imageid,$name,$imagetype,$file)
+ {
+ if(is_null($file))
+ { /* only update parameters */
+ return DBexecute("update images set name=".zbx_dbstr($name).",imagetype=".zbx_dbstr($imagetype).
+ " where imageid=$imageid");
+ }
+ else
+ {
+ global $DB_TYPE;
+ global $DB;
+
+ if($file["error"] != 0 || $file["size"]==0)
+ {
+ error("Incorrect Image");
+ return FALSE;
+ }
+ if($file["size"]<1024*1024)
+ {
+ $image=fread(fopen($file["tmp_name"],"r"),filesize($file["tmp_name"]));
+
+ if($DB_TYPE == "ORACLE")
+ {
+
+ $result = DBexecute("update images set name=".zbx_dbstr($name).
+ ",imagetype=".zbx_dbstr($imagetype).
+ " where imageid=$imageid");
+
+ if(!$result) return $result;
+
+ $stid = OCIParse($DB, "select image from images where imageid=".$imageid." for update");
+
+ $result = OCIExecute($stid, OCI_DEFAULT);
+ if(!$result){
+ $e = ocierror($stid);
+ error("Execute SQL error [".$e["message"]."] in [".$e["sqltext"]."]");
+ OCIRollback($DB);
+ return false;
+ }
+
+ $row = DBfetch($stid);
+
+ $lobimage = $row['image'];
+
+ if (!$lobimage->save($image)) {
+ OCIRollback($DB);
+ } else {
+ OCICommit($DB);
+ }
+
+ $lobimage->free();
+
+ return $stid;
+ }
+ else if($DB_TYPE == "POSTGRESQL")
+ {
+ $image = pg_escape_bytea($image);
+ $sql="update images set name=".zbx_dbstr($name).",imagetype=".zbx_dbstr($imagetype).
+ ",image='".$image."' where imageid=$imageid";
+ return DBexecute($sql);
+ }
+
+ $sql="update images set name=".zbx_dbstr($name).",imagetype=".zbx_dbstr($imagetype).
+ ",image=".zbx_dbstr($image)." where imageid=$imageid";
+ return DBexecute($sql);
+ }
+ else
+ {
+ error("Image size must be less than 1Mb");
+ return FALSE;
+ }
+ }
+ }
+
+ function delete_image($imageid)
+ {
+ return DBexecute("delete from images where imageid=$imageid");
+ }
+
+?>
diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php
index ec0e48c5..6875c831 100644
--- a/frontends/php/include/items.inc.php
+++ b/frontends/php/include/items.inc.php
@@ -19,6 +19,63 @@
**/
?>
<?php
+ function item_type2str($type)
+ {
+ switch($type)
+ {
+ case 0: $type = S_ZABBIX_AGENT; break;
+ case 1: $type = S_SNMPV1_AGENT; break;
+ case 2: $type = S_ZABBIX_TRAPPER; break;
+ case 3: $type = S_SIMPLE_CHECK; break;
+ case 4: $type = S_SNMPV2_AGENT; break;
+ case 5: $type = S_ZABBIX_INTERNAL; break;
+ case 6: $type = S_SNMPV3_AGENT; break;
+ case 7: $type = S_ZABBIX_AGENT_ACTIVE; break;
+ case 8: $type = S_ZABBIX_AGGREGATE; break;
+ default:$type = S_UNKNOWN; break;
+ }
+ return $type;
+ }
+
+ function item_value_type2str($value_type)
+ {
+ switch($value_type)
+ {
+ case ITEM_VALUE_TYPE_UINT64: $value_type = S_NUMERIC_UINT64; break;
+ case ITEM_VALUE_TYPE_FLOAT: $value_type = S_NUMERIC_FLOAT; break;
+ case ITEM_VALUE_TYPE_STR: $value_type = S_CHARACTER; break;
+ case ITEM_VALUE_TYPE_LOG: $value_type = S_LOG; break;
+ case ITEM_VALUE_TYPE_TEXT: $value_type = S_TEXT; break;
+ default:$value_type = S_UNKNOWN; break;
+ }
+ return $value_type;
+ }
+
+ function item_status2str($status)
+ {
+ switch($status)
+ {
+ case 0: $status = S_ACTIVE; break;
+ case 1: $status = S_DISABLED; break;
+ case 3:
+ default:
+ $status = S_UNKNOWN; break;
+ }
+ return $status;
+ }
+
+ function item_status2style($status)
+ {
+ switch($status)
+ {
+ case 0: $status = 'off'; break;
+ case 1: $status = 'on'; break;
+ case 3:
+ default:
+ $status = 'uncnown'; break;
+ }
+ return $status;
+ }
# Update Item definition for selected group
function update_item_in_group($groupid,$itemid,$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,$valuemapid,$delay_flex,$applications)
@@ -79,13 +136,8 @@
$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,
$valuemapid,$delay_flex,$applications,$templateid=0)
{
- $host=get_host_by_hostid($hostid);
- if(!check_right("Item","A",0))
- {
- error("Insufficient permissions to item '".$host["host"].":$key'");
- return FALSE;
- }
+ $host=get_host_by_hostid($hostid);
if(($i = array_search(0,$applications)) !== FALSE)
unset($applications[$i]);
@@ -182,7 +234,6 @@
zbx_dbstr($formula).",$trends,".zbx_dbstr($logtimefmt).",$valuemapid,".
zbx_dbstr($delay_flex).",$templateid)");
-
if(!$result)
return $result;
@@ -225,12 +276,6 @@
function update_item_status($itemid,$status)
{
- if(!check_right("Item","U",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
if($status==ITEM_STATUS_ACTIVE)
$sql="update items set status=$status,error='' where itemid=$itemid";
else
@@ -249,12 +294,6 @@
{
$host = get_host_by_hostid($hostid);
- if(!check_right("Item","U",$itemid))
- {
- error("Insufficient permissions to item '".$host["host"].":$key'");
- return FALSE;
- }
-
if(($i = array_search(0,$applications)) !== FALSE)
unset($applications[$i]);
@@ -498,8 +537,7 @@
function get_item_by_itemid($itemid)
{
- $result=DBselect("select * from items where itemid=$itemid");
- $row=DBfetch($result);
+ $row = DBfetch(DBselect("select * from items where itemid=$itemid"));
if($row)
{
return $row;
@@ -543,9 +581,6 @@
$result = DBexecute("delete from items where itemid=$itemid");
if($result)
{
- // delete item permisions
- DBexecute('delete from rights where name=\'Item\' and id='.$itemid);
-
info("Item '".$host["host"].":".$item["key_"]."' deleted");
}
return $result;
@@ -555,14 +590,11 @@
{
$param="";
-// echo $key." ".$num."<br>";
-
-// $params=split('[\[\]\,]', $description);
- $params=preg_split('/[\]\[,]/', $key);
+ $params = preg_split('/[\]\[,]/', $key);
if(isset($params[$num]))
{
- $param=$params[$num];
+ $param = $params[$num];
}
return $param;
@@ -589,8 +621,10 @@
return get_host_by_itemid($itemid);
}
- function get_items_data_overview($groupid)
+ function get_items_data_overview($groupid, $nodeid)
{
+ global $USER_DETAILS;
+
$table = new CTableInfo(S_NO_ITEMS_DEFINED);
if($groupid > 0)
@@ -601,48 +635,38 @@
}
COpt::profiling_start('prepare data');
- $result = DBselect('select distinct h.hostid, h.host,i.itemid, i.key_, i.value_type, i.lastvalue, i.units, i.description'.
- ' from hosts h,items i '.$group_where.
- ' h.status='.HOST_STATUS_MONITORED.' and h.hostid=i.hostid and i.status='.ITEM_STATUS_ACTIVE.
- ' order by i.description');
+ $result = DBselect('select distinct h.hostid, h.host,i.itemid, i.key_, i.value_type, i.lastvalue, i.units, '.
+ ' i.description, t.priority, t.value as tr_value'.
+ ' from hosts h,items i left join functions f on f.itemid=i.itemid left join triggers t on t.triggerid=f.triggerid '.
+ $group_where.
+ ' h.hostid in ('.get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, null, null, $nodeid).') '.
+ ' and h.status='.HOST_STATUS_MONITORED.' and h.hostid=i.hostid and i.status='.ITEM_STATUS_ACTIVE.
+ ' order by i.description,i.itemid');
unset($items);
unset($hosts);
while($row = DBfetch($result))
{
- if(!check_right("Item","R",$row["itemid"])) continue;
- if(!check_right('Host','R',$row['hostid'])) continue;
-
- $access = 1;
- $db_applications = get_applications_by_itemid($row["itemid"]);
-
- while($db_app = DBfetch($db_applications))
- {
- if(check_right("Application","R",$db_app["applicationid"]))
- {
- $access = 1;
- break;
- }
- $access = 0;
- }
- if($access == 0) continue;
-
$hosts[$row['host']] = $row['host'];
$items[item_description($row["description"],$row["key_"])][$row['host']] = array(
'itemid' => $row['itemid'],
'value_type' => $row['value_type'],
'lastvalue' => $row['lastvalue'],
'units' => $row['units'],
- 'description' => $row['description']);
+ 'description' => $row['description'],
+ 'severity' => $row['priority'],
+ 'tr_value' => $row['tr_value']
+ );
}
if(!isset($hosts))
{
return $table;
}
+
sort($hosts);
COpt::profiling_stop('prepare data');
COpt::profiling_start('prepare table');
- $header=array(new CCol(S_TRIGGERS,'center'));
+ $header=array(new CCol(S_ITEMS,'center'));
foreach($hosts as $hostname)
{
$header=array_merge($header,array(new CImg('vtext.php?text='.$hostname)));
@@ -658,11 +682,9 @@ COpt::profiling_start('prepare table');
$value = '-';
if(isset($ithosts[$hostname]))
{
- $db_item_triggers = DBselect('select t.triggerid from triggers t, items i, functions f where'.
- ' i.itemid='.$ithosts[$hostname]['itemid'].' and i.itemid=f.itemid'.
- ' and t.priority>1 and t.triggerid=f.triggerid and t.value='.TRIGGER_VALUE_TRUE);
- if(DBfetch($db_item_triggers)) $style = "high";
-
+ if($ithosts[$hostname]['tr_value'] == TRIGGER_VALUE_TRUE)
+ $style = get_severity_style($ithosts[$hostname]['severity']);
+
if($ithosts[$hostname]["value_type"] == 0)
$value = convert_units($ithosts[$hostname]["lastvalue"],$ithosts[$hostname]["units"]);
else
@@ -697,4 +719,53 @@ COpt::profiling_stop('prepare table');
return DBselect("select distinct app.* from applications app, items_applications ia".
" where app.applicationid=ia.applicationid and ia.itemid=".$itemid);
}
+
+ # Delete from History
+
+ function delete_history_by_itemid($itemid, $use_housekeeper=0)
+ {
+ SDI('TODO: Correct housekeeper scheduling!'); /* TODO */ /* think about housekeeper scheduling, must be housekeeperid - unneeded */
+
+ $result = delete_trends_by_itemid($itemid,$use_housekeeper);
+ if(!$result) return $result;
+
+ if($use_housekeeper)
+ {
+ $housekeeperid = get_dbid('housekeeper','housekeeperid');
+ DBexecute("insert into housekeeper (housekeeperid,tablename,field,value)".
+ " values ($housekeeperid,'history_log','itemid',$itemid)");
+ $housekeeperid = get_dbid('housekeeper','housekeeperid');
+ DBexecute("insert into housekeeper (housekeeperid,tablename,field,value)".
+ " values ($housekeeperid,'history_uint','itemid',$itemid)");
+ $housekeeperid = get_dbid('housekeeper','housekeeperid');
+ DBexecute("insert into housekeeper (housekeeperid,tablename,field,value)".
+ " values ($housekeeperid,'history_str','itemid',$itemid)");
+ $housekeeperid = get_dbid('housekeeper','housekeeperid');
+ DBexecute("insert into housekeeper (housekeeperid,tablename,field,value)".
+ " values ($housekeeperid,'history','itemid',$itemid)");
+ return TRUE;
+ }
+
+ DBexecute("delete from history_log where itemid=$itemid");
+ DBexecute("delete from history_uint where itemid=$itemid");
+ DBexecute("delete from history_str where itemid=$itemid");
+ DBexecute("delete from history where itemid=$itemid");
+ return TRUE;
+ }
+
+ # Delete from Trends
+
+ function delete_trends_by_itemid($itemid, $use_housekeeper=0)
+ {
+ SDI('TODO: Correct housekeeper scheduling!'); /* TODO */ /* think about housekeeper scheduling, must be housekeeperid - unneeded */
+
+ if($use_housekeeper)
+ {
+ $housekeeperid = get_dbid('housekeeper','housekeeperid');
+ DBexecute("insert into housekeeper (housekeeperid,tablename,field,value)".
+ " values ($housekeeperid, 'trends','itemid',$itemid)");
+ return TRUE;
+ }
+ return DBexecute("delete from trends where itemid=$itemid");
+ }
?>
diff --git a/frontends/php/include/locales.inc.php b/frontends/php/include/locales.inc.php
index ab08431e..89290819 100644
--- a/frontends/php/include/locales.inc.php
+++ b/frontends/php/include/locales.inc.php
@@ -23,11 +23,15 @@
function process_locales()
{
global $TRANSLATION;
-
- foreach($TRANSLATION as $const=>$label)
+ global $GLOBALS;
+
+ if(isset($TRANSLATION) && is_array($TRANSLATION))
{
- if(!defined($const)) define($const,$label);
-// echo $const," ",$label,"<br>";
+ foreach($TRANSLATION as $const=>$label)
+ {
+ if(!defined($const)) define($const,$label);
+ }
}
+ unset($GLOBALS['TRANSLATION']);
}
?>
diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php
index a19ba777..a8b803ab 100644
--- a/frontends/php/include/locales/en_gb.inc.php
+++ b/frontends/php/include/locales/en_gb.inc.php
@@ -35,6 +35,7 @@
"S_COMMENT_ADDED"=> "Comment added",
"S_CANNOT_ADD_COMMENT"=> "Cannot add coment",
"S_ALARM_ACKNOWLEDGES_BIG"=> "ALARM ACKNOWLEDGES",
+ "S_ACKNOWLEDGE_ADDED"=> "Acknowledge added",
// actionconf.php
"S_CONFIGURATION_OF_ACTIONS"=> "Configuration of actions",
@@ -196,9 +197,9 @@
"S_MEDIA_TYPE_DELETED"=> "Media type deleted",
"S_MEDIA_TYPE_WAS_NOT_DELETED"=> "Media type was not deleted",
"S_CONFIGURATION"=> "Configuration",
+ "S_ADMINISTRATION"=> "Administration",
"S_DO_NOT_KEEP_ACTIONS_OLDER_THAN"=> "Do not keep actions older than (in days)",
"S_DO_NOT_KEEP_EVENTS_OLDER_THAN"=> "Do not keep events older than (in days)",
- "S_MEDIA_TYPES_BIG"=> "MEDIA TYPES",
"S_NO_MEDIA_TYPES_DEFINED"=> "No media types defined",
"S_SMTP_SERVER"=> "SMTP server",
"S_SMTP_HELO"=> "SMTP helo",
@@ -264,6 +265,13 @@
"S_CREATE_IMAGE"=> "Create Image",
"S_CREATE_RULE"=> "Create Rule",
"S_WORKING_TIME"=> "Working time",
+
+// nodes.php
+ "S_NODE"=> "Node",
+ "S_NODES"=> "Nodes",
+ "S_NODES_BIG"=> "NODES",
+ "S_NEW_NODE"=> "New node",
+ "S_NO_NODES_DEFINED"=> "No nodes defined",
// Latest values
"S_LATEST_VALUES"=> "Latest values",
@@ -409,6 +417,7 @@
"S_DELETED"=> "Deleted",
"S_UNKNOWN"=> "Unknown",
"S_GROUPS"=> "Groups",
+ "S_NO_GROUPS_DEFINED"=> "No groups defined",
"S_NEW_GROUP"=> "New group",
"S_USE_IP_ADDRESS"=> "Use IP address",
"S_IP_ADDRESS"=> "IP address",
@@ -461,6 +470,8 @@
"S_HOSTS"=> "Hosts",
"S_UNLINK"=> "Unlink",
"S_UNLINK_AND_CLEAR"=> "Unlink and clear",
+ "S_UNLINKED_SMALL"=> "unlinked",
+ "S_CLEANED_SMALL"=> "cleaned",
// items.php
"S_NO_ITEMS_DEFINED"=> "No items defined",
@@ -546,6 +557,7 @@
"S_SKIP_EXISTING_ITEMS"=> "Skip existing items",
"S_UPDATE_EXISTING_NON_LINKED_ITEMS"=> "update existing non linked items",
"S_COPY"=> "Copy",
+ "S_SHOW_ITEMS_WITH_DESCRIPTION_LIKE"=> "Show items with description like",
// events.php
"S_LATEST_EVENTS"=> "Latest events",
@@ -598,6 +610,7 @@
"S_NOTHING"=> "Nothing",
// media.php
+ "S_CONFIGURATION_OF_MEDIA_TYPES_BIG"=> "CONFIGURATION OF MEDIA TYPES",
"S_MEDIA"=> "Media",
"S_MEDIA_BIG"=> "MEDIA",
"S_MEDIA_ACTIVATED"=> "Media activated",
@@ -639,6 +652,7 @@
"S_MENU_HOSTS"=> "HOSTS",
"S_MENU_ITEMS"=> "ITEMS",
"S_MENU_AUDIT"=> "AUDIT",
+ "S_SWITCH"=> "Switch",
// overview.php
"S_SELECT_GROUP_DOT_DOT_DOT"=> "Select group ...",
@@ -696,6 +710,7 @@
"S_IT_SERVICES_AVAILABILITY_REPORT"=> "IT services availability report",
"S_IT_SERVICES_AVAILABILITY_REPORT_BIG"=> "IT SERVICES AVAILABILITY REPORT",
"S_FROM"=> "From",
+ "S_FROM_SMALL"=> "from",
"S_TILL"=> "Till",
"S_OK"=> "Ok",
"S_PROBLEMS"=> "Problems",
@@ -739,6 +754,10 @@
"S_CONFIGURATION_OF_SCREEN_BIG"=> "CONFIGURATION OF SCREEN",
"S_SCREEN_CELL_CONFIGURATION"=> "Screen cell configuration",
"S_RESOURCE"=> "Resource",
+ "S_RESOURCES"=> "Resources",
+ "S_RESOURCE_TYPE"=> "Resource type",
+ "S_RIGHTS_OF_RESOURCES"=> "Rights of resources",
+ "S_NO_RESOURCES_DEFINED"=> "No resources defined",
"S_SIMPLE_GRAPH"=> "Simple graph",
"S_GRAPH_NAME"=> "Graph name",
"S_WIDTH"=> "Width",
@@ -789,6 +808,8 @@
"S_SELECT_SCREEN_DOT_DOT_DOT"=> "Select screen ...",
// services.php
+ "S_ROOT_SMALL"=> "root",
+ "S_IT_SERVICE"=> "IT service",
"S_IT_SERVICES"=> "IT services",
"S_SERVICE_UPDATED"=> "Service updated",
"S_CANNOT_UPDATE_SERVICE"=> "Cannot update service",
@@ -824,6 +845,7 @@
"S_TRIGGER"=> "Trigger",
"S_SERVER"=> "Server",
"S_DELETE"=> "Delete",
+ "S_DELETE_SELECTED"=> "Delete selected",
"S_DELETE_SELECTED_SERVICES"=> "Delete selected services?",
"S_DELETE_SELECTED_LINKS"=> "Delete selected links?",
"S_SERVICES_DELETED"=> "Services deleted",
@@ -873,6 +895,8 @@
"S_EXPRESSION"=> "Expression",
"S_DISABLED"=> "Disabled",
"S_ENABLED"=> "Enabled",
+ "S_DISABLE_SELECTED"=> "Disable selected",
+ "S_ENABLE_SELECTED"=> "Enable selected",
"S_ENABLE_SELECTED_TRIGGERS_Q"=> "Enable selected triggers?",
"S_DISABLE_SELECTED_TRIGGERS_Q"=> "Disable selected triggers?",
"S_DELETE_SELECTED_TRIGGERS_Q"=> "Delete selected triggers?",
@@ -881,6 +905,7 @@
"S_CANNOT_UPDATE_TRIGGER"=> "Cannot update trigger",
"S_DEPENDS_ON"=> "Depends on",
"S_URL"=> "URL",
+ "S_INVALID_URL"=> "Invalid URL",
"S_CREATE_TRIGGER"=> "Create Trigger",
// tr_comments.php
@@ -911,6 +936,10 @@
"S_ACK"=> "Ack",
// users.php
+ "S_ZABBIX_USER"=> "ZABBIX User",
+ "S_ZABBIX_ADMIN"=> "ZABBIX Admin",
+ "S_SUPPER_ADMIN"=> "ZABBIX Supper Admin",
+ "S_USER_TYPE"=> "User type",
"S_USERS"=> "Users",
"S_USER_ADDED"=> "User added",
"S_CANNOT_ADD_USER"=> "Cannot add user",
@@ -922,6 +951,7 @@
"S_PERMISSION_ADDED"=> "Permission added",
"S_CANNOT_ADD_PERMISSION"=> "Cannot add permission",
"S_USER_UPDATED"=> "User updated",
+ "S_ONLY_FOR_GUEST_ALLOWED_EMPTY_PASSWORD"=> "Only for guest allowed empty passwod.",
"S_CANNOT_UPDATE_USER"=> "Cannot update user",
"S_CANNOT_UPDATE_USER_BOTH_PASSWORDS"=> "Cannot update user. Both passwords must be equal.",
"S_GROUP_ADDED"=> "Group added",
@@ -947,17 +977,23 @@
"S_NO_USERS_DEFINED"=> "No users defined",
"S_PERMISSION"=> "Permission",
"S_RIGHT"=> "Right",
+ "S_RIGHTS"=> "Rights",
+ "S_NO_RIGHTS_DEFINED"=> "No rights defined",
"S_RESOURCE_NAME"=> "Resource name",
"S_READ_ONLY"=> "Read only",
"S_READ_WRITE"=> "Read-write",
+ "S_DENY"=> "Deny",
"S_HIDE"=> "Hide",
"S_PASSWORD"=> "Password",
+ "S_CHANGE_PASSWORD"=> "Change password",
"S_PASSWORD_ONCE_AGAIN"=> "Password (once again)",
"S_URL_AFTER_LOGIN"=> "URL (after login)",
"S_AUTO_LOGOUT_IN_SEC"=> "Auto-logout (in sec=>0 - disable)",
"S_SCREEN_REFRESH"=> "Refresh (in seconds)",
"S_CREATE_USER"=> "Create User",
"S_CREATE_GROUP"=> "Create Group",
+ "S_DELETE_SELECTED_USERS_Q"=> "Delete selected users?",
+ "S_NO_ACCESSIBLE_RESOURCES"=> "No accessibles resources",
// audit.php
"S_AUDIT_LOG"=> "Audit log",
diff --git a/frontends/php/include/locales/lv_lv.inc.php b/frontends/php/include/locales/lv_lv.inc.php
index b596ee1f..5a360050 100644
--- a/frontends/php/include/locales/lv_lv.inc.php
+++ b/frontends/php/include/locales/lv_lv.inc.php
@@ -21,7 +21,7 @@
<?php
global $TRANSLATION;
- $lv_lv=array(
+ $TRANSLATION = array(
"S_DATE_FORMAT_YMDHMS"=> "d M H:i:s",
"S_DATE_FORMAT_YMD"=> "d M Y",
@@ -727,6 +727,4 @@
"S_HELP"=> "Help",
"S_PROFILE"=> "Profile",
);
-
- $TRANSLATION=array_merge($TRANSLATION,$lv_lv);
?>
diff --git a/frontends/php/include/locales/ru_ru.inc.php b/frontends/php/include/locales/ru_ru.inc.php
index 63c6a60e..82b45ccd 100644
--- a/frontends/php/include/locales/ru_ru.inc.php
+++ b/frontends/php/include/locales/ru_ru.inc.php
@@ -21,7 +21,7 @@
<?php
global $TRANSLATION;
- $ru_ru=array(
+ $TRANSLATION = array(
"S_DATE_FORMAT_YMDHMS"=> "d M H:i:s",
"S_DATE_FORMAT_YMD"=> "d M Y",
@@ -191,7 +191,7 @@
// Latest values
"S_LATEST_VALUES"=> "Latest values",
"S_NO_PERMISSIONS"=> "No permissions !",
- "S_LATEST_DATA"=> "LATEST DATA",
+ "S_LATEST_DATA"=> "Poslednie dannie",
"S_ALL_SMALL"=> "all",
"S_DESCRIPTION_LARGE"=> "DESCRIPTION",
"S_DESCRIPTION_SMALL"=> "Description",
@@ -727,6 +727,4 @@
"S_HELP"=> "Help",
"S_PROFILE"=> "Profile",
);
-
- $TRANSLATION=array_merge($TRANSLATION,$ru_ru);
?>
diff --git a/frontends/php/include/maps.inc.php b/frontends/php/include/maps.inc.php
index 42ffdd24..7a87d0e0 100644
--- a/frontends/php/include/maps.inc.php
+++ b/frontends/php/include/maps.inc.php
@@ -19,16 +19,59 @@
**/
?>
<?php
+ require_once "include/images.inc.php";
+ require_once "include/hosts.inc.php";
+ require_once "include/triggers.inc.php";
+
+ function sysmap_accessiable($sysmapid,$perm)
+ {
+ global $USER_DETAILS;
+
+ $result = false;
+
+ if($db_result = DBselect("select * from sysmaps_elements where sysmapid=".$sysmapid.
+ " and ".DBid2nodeid('sysmapid')." in (".get_accessible_nodes_by_user($USER_DETAILS,$perm).")"))
+ {
+ $result = true;
+
+ $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, PERM_MODE_LT);
+
+ while(($se_data = DBfetch($db_result)) && $result)
+ {
+ switch($se_data['elementtype'])
+ {
+ case SYSMAP_ELEMENT_TYPE_HOST:
+ if(in_array($se_data['elementid'],explode(',',$denyed_hosts)))
+ {
+ $result = false;
+ }
+ break;
+ case SYSMAP_ELEMENT_TYPE_MAP:
+ $result &= sysmap_accessiable($se_data['elementid'], PERM_READ_ONLY);
+ break;
+ case SYSMAP_ELEMENT_TYPE_IMAGE:
+ if(!DBfetch(DBselect("select distinct t.*".
+ " from triggers t,items i,functions f".
+ " where f.itemid=i.itemid and t.triggerid=f.triggerid".
+ " and i.hostid not in (".$denyed_hosts.") and t.triggerid=".$se_data['elementid'])))
+ {
+ $result = false;
+ }
+ break;
+ }
+ }
+ }
+ return $result;
+ }
+
function get_sysmap_by_sysmapid($sysmapid)
{
- $sql="select * from sysmaps where sysmapid=$sysmapid";
- $result=DBselect($sql);
- $row=DBfetch($result);
+ $row = DBfetch(DBselect("select * from sysmaps where sysmapid=".$sysmapid));
if($row)
{
return $row;
}
- error("No system map with sysmapid=[$sysmapid]");
+ error("No system map with sysmapid=[".$sysmapid."]");
return false;
}
@@ -61,41 +104,26 @@
$result = DBexecute("delete from sysmaps_elements where sysmapid=$sysmapid");
if(!$result) return $result;
- // delete map permisions
- DBexecute('delete from rights where name=\'Network map\' and id='.$sysmapid);
-
return DBexecute("delete from sysmaps where sysmapid=$sysmapid");
}
# Update System Map
- function update_sysmap($sysmapid,$name,$width,$height,$background,$label_type,$label_location)
+ function update_sysmap($sysmapid,$name,$width,$height,$backgroundid,$label_type,$label_location)
{
- if(!check_right("Network map","U",$sysmapid))
- {
- error("Insufficient permissions");
- return 0;
- }
-
return DBexecute("update sysmaps set name=".zbx_dbstr($name).",width=$width,height=$height,".
- "background=".zbx_dbstr($background).",label_type=$label_type,".
+ "backgroundid=".$backgroundid.",label_type=$label_type,".
"label_location=$label_location where sysmapid=$sysmapid");
}
# Add System Map
- function add_sysmap($name,$width,$height,$background,$label_type,$label_location)
+ function add_sysmap($name,$width,$height,$backgroundid,$label_type,$label_location)
{
- if(!check_right("Network map","A",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
$sysmapid=get_dbid("sysmaps","sysmapid");
- $result=DBexecute("insert into sysmaps (sysmapid,name,width,height,background,label_type,label_location)".
- " values ($sysmapid,".zbx_dbstr($name).",$width,$height,".zbx_dbstr($background).",$label_type,
+ $result=DBexecute("insert into sysmaps (sysmapid,name,width,height,backgroundid,label_type,label_location)".
+ " values ($sysmapid,".zbx_dbstr($name).",$width,$height,".$backgroundid.",$label_type,
$label_location)");
if(!$result)
@@ -158,7 +186,7 @@
# Add Element to system map
function add_element_to_sysmap($sysmapid,$elementid,$elementtype,
- $label,$x,$y,$icon,$url,$icon_on,$label_location)
+ $label,$x,$y,$iconid_off,$url,$iconid_on,$label_location)
{
if($label_location<0) $label_location='null';
if(check_circle_elements_link($sysmapid,$elementid,$elementtype))
@@ -170,9 +198,9 @@
$selementid = get_dbid("sysmaps_elements","selementid");
$result=DBexecute("insert into sysmaps_elements".
- " (sysmapid,elementid,elementtype,label,x,y,icon,url,icon_on,label_location)".
- " values ($sysmapid,$elementid,$elementtype,".zbx_dbstr($label).",
- $x,$y,".zbx_dbstr($icon).",".zbx_dbstr($url).",".zbx_dbstr($icon_on).",".
+ " (selementid,sysmapid,elementid,elementtype,label,x,y,iconid_off,url,iconid_on,label_location)".
+ " values ($selementid,$sysmapid,$elementid,$elementtype,".zbx_dbstr($label).",
+ $x,$y,$iconid_off,".zbx_dbstr($url).",$iconid_on,".
"$label_location)");
if(!$result)
@@ -184,7 +212,7 @@
# Update Element from system map
function update_sysmap_element($selementid,$sysmapid,$elementid,$elementtype,
- $label,$x,$y,$icon,$url,$icon_on,$label_location)
+ $label,$x,$y,$iconid_off,$url,$iconid_on,$label_location)
{
if($label_location<0) $label_location='null';
if(check_circle_elements_link($sysmapid,$elementid,$elementtype))
@@ -194,8 +222,8 @@
}
return DBexecute("update sysmaps_elements set elementid=$elementid,elementtype=$elementtype,".
- "label=".zbx_dbstr($label).",x=$x,y=$y,icon=".zbx_dbstr($icon).",url=".zbx_dbstr($url).
- ",icon_on=".zbx_dbstr($icon_on).",label_location=$label_location".
+ "label=".zbx_dbstr($label).",x=$x,y=$y,iconid_off=$iconid_off,url=".zbx_dbstr($url).
+ ",iconid_on=$iconid_on,label_location=$label_location".
" where selementid=$selementid");
}
@@ -251,12 +279,13 @@
if(!$element) return FALSE;
if(get_info_by_selementid($element["selementid"],$info,$color) != 0)
- $icon = $element["icon_on"];
+ $iconid = $element["iconid_on"];
else
- $icon = $element["icon"];
+ $iconid = $element["iconid_off"];
- $image = get_image_by_name($icon);
+ $image = get_image_by_imageid($iconid);
if(!$image) return FALSE;
+
return imagecreatefromstring($image['image']);
}
@@ -375,7 +404,7 @@
elseif($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_IMAGE)
{
if($url=="" && $db_element["elementid"]!=0)
- $url="alarms.php?triggerid=".$db_element["elementid"];
+ $url="events.php?triggerid=".$db_element["elementid"];
}
if($url=="") continue;
diff --git a/frontends/php/include/media.inc.php b/frontends/php/include/media.inc.php
index 90066f7d..b90f4b79 100644
--- a/frontends/php/include/media.inc.php
+++ b/frontends/php/include/media.inc.php
@@ -19,6 +19,41 @@
**/
?>
<?php
+
+ function media_type2str($type)
+ {
+ $str_type[ALERT_TYPE_EMAIL] = S_EMAIL;
+ $str_type[ALERT_TYPE_EXEC] = S_SCRIPT;
+ $str_type[ALERT_TYPE_SMS] = S_SMS;
+
+ if(isset($str_type[$type]))
+ return $str_type[$type];
+
+ return S_UNKNOWN;
+ }
+
+ function media_severity2str($severity)
+ {
+
+ insert_showhint_javascript();
+ $mapping = array(
+ 0 => array('letter' => 'N', 'style' => (($severity & 1) ? 'enabled' : NULL)),
+ 1 => array('letter' => 'I', 'style' => (($severity & 2) ? 'enabled' : NULL)),
+ 2 => array('letter' => 'W', 'style' => (($severity & 4) ? 'enabled' : NULL)),
+ 3 => array('letter' => 'A', 'style' => (($severity & 8) ? 'enabled' : NULL)),
+ 4 => array('letter' => 'H', 'style' => (($severity & 16) ? 'enabled' : NULL)),
+ 5 => array('letter' => 'D', 'style' => (($severity & 32) ? 'enabled' : NULL))
+ );
+
+ foreach($mapping as $id => $map)
+ {
+ $result[$id] = new CSpan($map['letter'], $map['style']);
+ $result[$id]->SetHint(get_severity_description($id)." (".(isset($map['style']) ? "on" : "off").")");
+ }
+
+ return unpack_object($result);
+ }
+
function get_media_by_mediaid($mediaid)
{
$sql="select * from media where mediaid=$mediaid";
@@ -34,4 +69,159 @@
}
return $result;
}
+
+ # Delete Media definition by mediatypeid
+
+ function delete_media_by_mediatypeid($mediatypeid)
+ {
+ $sql="delete from media where mediatypeid=$mediatypeid";
+ return DBexecute($sql);
+ }
+
+ # Delete alrtes by mediatypeid
+
+ function delete_alerts_by_mediatypeid($mediatypeid)
+ {
+ $sql="delete from alerts where mediatypeid=$mediatypeid";
+ return DBexecute($sql);
+ }
+
+ function get_mediatype_by_mediatypeid($mediatypeid)
+ {
+ $sql="select * from media_type where mediatypeid=$mediatypeid";
+ $result=DBselect($sql);
+ $row=DBfetch($result);
+ if($row)
+ {
+ return $row;
+ }
+ else
+ {
+ error("No media type with with mediatypeid=[$mediatypeid]");
+ }
+ return $item;
+ }
+
+ # Delete media type
+
+ function delete_mediatype($mediatypeid)
+ {
+
+ delete_media_by_mediatypeid($mediatypeid);
+ delete_alerts_by_mediatypeid($mediatypeid);
+ $sql="delete from media_type where mediatypeid=$mediatypeid";
+ return DBexecute($sql);
+ }
+
+ # Update media type
+
+ function update_mediatype($mediatypeid,$type,$description,$smtp_server,$smtp_helo,$smtp_email,$exec_path,$gsm_modem)
+ {
+ $ret = 0;
+
+ $sql="select * from media_type where description=".zbx_dbstr($description)." and mediatypeid!=$mediatypeid";
+ $result=DBexecute($sql);
+ if(DBfetch($result))
+ {
+ error("An action type with description '$description' already exists.");
+ }
+ else
+ {
+ $sql="update media_type set type=$type,description=".zbx_dbstr($description).",smtp_server=".zbx_dbstr($smtp_server).",smtp_helo=".zbx_dbstr($smtp_helo).",smtp_email=".zbx_dbstr($smtp_email).",exec_path=".zbx_dbstr($exec_path).",gsm_modem=".zbx_dbstr($gsm_modem)." where mediatypeid=$mediatypeid";
+ $ret = DBexecute($sql);
+ }
+ return $ret;
+ }
+
+ # Add Media type
+
+ function add_mediatype($type,$description,$smtp_server,$smtp_helo,$smtp_email,$exec_path,$gsm_modem)
+ {
+ $ret = 0;
+
+ if($description==""){
+ error(S_INCORRECT_DESCRIPTION);
+ return 0;
+ }
+
+ $sql="select * from media_type where description=".zbx_dbstr($description);
+ $result=DBexecute($sql);
+ if(DBfetch($result))
+ {
+ error("An action type with description '$description' already exists.");
+ }
+ else
+ {
+ $mediatypeid=get_dbid("media_type","mediatypeid");
+ $sql="insert into media_type (mediatypeid,type,description,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem) values ($mediatypeid,$type,".zbx_dbstr($description).",".zbx_dbstr($smtp_server).",".zbx_dbstr($smtp_helo).",".zbx_dbstr($smtp_email).",".zbx_dbstr($exec_path).",".zbx_dbstr($gsm_modem).")";
+ $ret = DBexecute($sql);
+ if($ret) $ret = $mediatypeid;
+ }
+ return $ret;
+ }
+
+ # Add Media definition
+
+ function add_media( $userid, $mediatypeid, $sendto, $severity, $active, $period)
+ {
+ if(validate_period($period) != 0)
+ {
+ error("Icorrect time period");
+ return NULL;
+ }
+
+ $c=count($severity);
+ $s=0;
+ for($i=0;$i<$c;$i++)
+ {
+ $s=$s|pow(2,(int)$severity[$i]);
+ }
+ $mediaid=get_dbid("media","mediaid");
+ $sql="insert into media (mediaid,userid,mediatypeid,sendto,active,severity,period) values ($mediaid,$userid,".zbx_dbstr($mediatypeid).",".zbx_dbstr($sendto).",$active,$s,".zbx_dbstr($period).")";
+ $ret = DBexecute($sql);
+ if($ret) $ret = $mediaid;
+ return $ret;
+ }
+
+ # Update Media definition
+
+ function update_media($mediaid, $userid, $mediatypeid, $sendto, $severity, $active, $period)
+ {
+ if(validate_period($period) != 0)
+ {
+ error("Icorrect time period");
+ return NULL;
+ }
+
+ $c=count($severity);
+ $s=0;
+ for($i=0;$i<$c;$i++)
+ {
+ $s=$s|pow(2,(int)$severity[$i]);
+ }
+ $sql="update media set userid=$userid, mediatypeid=$mediatypeid, sendto=".zbx_dbstr($sendto).", active=$active,severity=$s,period=".zbx_dbstr($period)." where mediaid=$mediaid";
+ return DBexecute($sql);
+ }
+
+ # Delete Media definition
+
+ function delete_media($mediaid)
+ {
+ return DBexecute("delete from media where mediaid=$mediaid");
+ }
+
+ # Activate Media
+
+ function activate_media($mediaid)
+ {
+ return DBexecute("update media set active=0 where mediaid=$mediaid");
+ }
+
+ # Disactivate Media
+
+ function disactivate_media($mediaid)
+ {
+ return DBexecute("update media set active=1 where mediaid=$mediaid");
+ }
+
?>
diff --git a/frontends/php/include/page_footer.php b/frontends/php/include/page_footer.php
new file mode 100644
index 00000000..81f083df
--- /dev/null
+++ b/frontends/php/include/page_footer.php
@@ -0,0 +1,55 @@
+<?php
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+ global $USER_DETAILS;
+ global $page;
+
+ show_messages();
+
+ if($page['type'] == PAGE_TYPE_HTML)
+ {
+
+ if(!defined('ZBX_PAGE_NO_MENU') && !defined('ZBX_PAGE_NO_FOOTER'))
+ {
+ $table = new CTable(NULL,"page_footer");
+ $table->SetCellSpacing(0);
+ $table->SetCellPadding(1);
+ $table->AddRow(array(
+ new CCol(new CLink(
+ S_ZABBIX_VER.SPACE.S_COPYRIGHT_BY.SPACE.S_SIA_ZABBIX,
+ "http://www.zabbix.com", "highlight"),
+ "page_footer_l"),
+ new CCol(array(
+ new CSpan(SPACE.SPACE."|".SPACE.SPACE,"divider"),
+ S_CONNECTED_AS.SPACE."'".$USER_DETAILS["alias"]."'".SPACE.
+ S_FROM_SMALL.SPACE."'".$USER_DETAILS["node"]['name']."'"
+ ),
+ "page_footer_r")
+ ));
+ $table->Show();
+ }
+
+COpt::profiling_stop("page");
+COpt::profiling_stop("script");
+
+ echo "</body>\n";
+ echo "</html>\n";
+ }
+ exit;
+?>
diff --git a/frontends/php/include/page_header.php b/frontends/php/include/page_header.php
new file mode 100644
index 00000000..011254a7
--- /dev/null
+++ b/frontends/php/include/page_header.php
@@ -0,0 +1,380 @@
+<?php
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+?>
+<?php
+ require_once("include/config.inc.php");
+
+ global $USER_DETAILS;
+ global $ZBX_CURNODEID;
+ global $ZBX_LOCALNODEID;
+ global $page;
+
+COpt::profiling_start("page");
+
+ unset($denyed_page_requested);
+
+ /* Header for HTML pages */
+
+ if(!isset($page["type"])) $page["type"] = PAGE_TYPE_HTML;
+ if(!isset($page["file"])) $page["file"] = basename($_SERVER['PHP_SELF']);
+
+ if(!defined('ZBX_PAGE_NO_AUTHERIZATION'))
+ {
+ check_authorisation();
+
+ include_once "include/locales/".$USER_DETAILS["lang"].".inc.php";
+ process_locales();
+ }
+ include_once "include/locales/en_gb.inc.php";
+ process_locales();
+
+ $ZBX_CURNODEID = get_cookie('current_nodeid', $ZBX_LOCALNODEID); // Selected node
+ if(isset($_REQUEST['switch_node']))
+ {
+ if(DBfetch(DBselect("select nodeid from nodes where nodeid=".$_REQUEST['switch_node'])))
+ $ZBX_CURNODEID = $_REQUEST['switch_node'];
+ }
+
+ if(count(get_accessible_nodes_by_user($USER_DETAILS,PERM_READ_LIST,null,PERM_RES_IDS_ARRAY,$ZBX_CURNODEID)) <= 0)
+ {
+ $denyed_page_requested = true;
+ $ZBX_CURNODEID = $ZBX_LOCALNODEID;
+ }
+
+ setcookie("current_nodeid",$ZBX_CURNODEID);
+
+ switch($page["type"])
+ {
+ case PAGE_TYPE_IMAGE:
+ set_image_header();
+ define('ZBX_PAGE_NO_MENU', 1);
+ break;
+
+ case PAGE_TYPE_HTML:
+ default:
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=<?php echo S_HTML_CHARSET; ?>">
+<meta name="Author" content="ZABBIX SIA (Alexei Vladishev, Eugene Grigorjev)">
+<link rel="stylesheet" href="css.css">
+<?php
+ if(isset($page['title']) && defined($page['title'])) $page['title'] = constant($page['title']);
+
+ if(defined('ZBX_PAGE_DO_REFRESH') && $USER_DETAILS["refresh"])
+ {
+ echo " <meta http-equiv=\"refresh\" content=\"".$USER_DETAILS["refresh"]."\">\n";
+
+ if(isset($page['title']))
+ $page['title'] .= ' [refreshed every '.$USER_DETAILS['refresh'].' sec]';
+ }
+
+ if(isset($page['title']))
+ {
+ if($curr_node_data = DBfetch(DBselect('select * from nodes where nodeid='.$ZBX_CURNODEID)))
+ $page['title'] = '('.$curr_node_data['name'].') '.$page['title'];
+
+ echo " <title>".$page['title']."</title>\n";
+ }
+?>
+</head>
+<body>
+<?php
+ break; /* case PAGE_TYPE_HTML */
+ } /* switch($page["type"]) */
+
+ /* NOTE - menu array format:
+ first level:
+ 'label' = main menu title.
+ 'default_page_id = default page url from 'pages' then opened menu.
+ 'pages' = collection of pages whitch displayed from this menu
+ this pages are saved a last visited submenu of main menu.
+
+ second level (pages):
+ 'url' = real url for this page
+ 'label' = submenu title, if missed menu skipped, but remmembed as last visited page.
+ 'sub_pages' = collection of pages for displaying but dont remember as last visited.
+
+ */
+ $ZBX_MENU = array(
+ "view"=>array(
+ "label" => S_MONITORING,
+ "default_page_id" => 0,
+ "pages"=>array(
+ array("url"=>"overview.php" ,"label"=>S_OVERVIEW ),
+ array("url"=>"latest.php" ,"label"=>S_LATEST_DATA ,
+ "sub_pages"=>array("history.php","chart.php")
+ ),
+ array("url"=>"tr_status.php" ,"label"=>S_TRIGGERS ,
+ "sub_pages"=>array("tr_events.php","acknow.php","tr_comments.php",
+ "chart4.php")
+ ),
+ array("url"=>"queue.php" ,"label"=>S_QUEUE ),
+ array("url"=>"events.php" ,"label"=>S_EVENTS ),
+ array("url"=>"actions.php" ,"label"=>S_ACTIONS ),
+ array("url"=>"maps.php" ,"label"=>S_MAPS ,
+ "sub_pages"=>array("map.php")
+ ),
+ array("url"=>"charts.php" ,"label"=>S_GRAPHS ,
+ "sub_pages"=>array("chart2.php")
+ ),
+ array("url"=>"screens.php" ,"label"=>S_SCREENS ),
+ array("url"=>"srv_status.php" ,"label"=>S_IT_SERVICES ,
+ "sub_pages"=>array("report3.php","chart_sla.php","chart5.php")
+ ),
+ array("url"=>"vtext.php"),
+ )
+ ),
+ "cm"=>array(
+ "label" => S_INVENTORY,
+ "default_page_id" => 0,
+ "pages"=>array(
+ array("url"=>"hostprofiles.php" ,"label"=>S_HOSTS )
+ )
+ ),
+ "reports"=>array(
+ "label" => S_REPORTS,
+ "default_page_id" => 0,
+ "pages"=>array(
+ array("url"=>"report1.php", "label"=>S_STATUS_OF_ZABBIX ),
+ array("url"=>"report2.php", "label"=>S_AVAILABILITY_REPORT ),
+ array("url"=>"report5.php", "label"=>S_TRIGGERS_TOP_100 )
+ )
+ ),
+ "config"=>array(
+ "label" => S_CONFIGURATION,
+ "default_page_id" => 0,
+ "pages"=>array(
+ array("url"=>"config.php" ,"label"=>S_GENERAL ,
+ "sub_pages"=>array("image.php")
+ ),
+ array("url"=>"hosts.php" ,"label"=>S_HOSTS ),
+ array("url"=>"items.php" ,"label"=>S_ITEMS ),
+ array("url"=>"triggers.php" ,"label"=>S_TRIGGERS ),
+ array("url"=>"actionconf.php" ,"label"=>S_ACTIONS ),
+ array("url"=>"sysmaps.php" ,"label"=>S_MAPS ,
+ "sub_pages"=>array("sysmap.php")
+ ),
+ array("url"=>"graphs.php" ,"label"=>S_GRAPHS ,
+ "sub_pages"=>array("graph.php")
+ ),
+ array("url"=>"screenconf.php" ,"label"=>S_SCREENS ,
+ "sub_pages"=>array("screenedit.php")
+ ),
+ array("url"=>"services.php" ,"label"=>S_IT_SERVICES ),
+ array("url"=>"bulkloader.php" ,"label"=>S_MENU_BULKLOADER ),
+ array("url"=>"popup.php")
+ )
+ ),
+ "admin"=>array(
+ "label" => S_ADMINISTRATION,
+ "default_page_id" => 0,
+ "pages"=>array(
+ array("url"=>"admin.php" ,"label"=>S_ADMINISTRATION ),
+ array("url"=>"nodes.php" ,"label"=>S_NODES ),
+ array("url"=>"users.php" ,"label"=>S_USERS ,
+ "sub_pages"=>array("popup_media.php",
+ "popup_usrgrp.php","popup_right.php","popup_users.php")
+ ),
+ array("url"=>"media_types.php" ,"label"=>S_MEDIA_TYPES ),
+ array("url"=>"audit.php" ,"label"=>S_AUDIT ),
+ array("url"=>"report4.php" ,"label"=>S_NOTIFICATIONS )
+ )
+ ),
+ "login"=>array(
+ "label" => S_LOGIN,
+ "default_page_id" => 0,
+ "pages"=>array(
+ array("url"=>"index.php",
+ "sub_pages"=>array("profile.php")
+ )
+ )
+ )
+ );
+
+
+ $help = new CLink(S_HELP, "http://www.zabbix.com/manual/v1.1/index.php", "small_font");
+ $help->SetTarget('_blank');
+ $page_header_r_col = array($help,
+ ($USER_DETAILS["alias"] != "guest") ?
+ array("|", new CLink(S_PROFILE, "profile.php", "small_font")) :
+ null
+ );
+ $logo = new CLink(new CImg("images/general/zabbix.png","ZABBIX"),"http://www.zabbix.com");
+ $logo->SetTarget('_blank');
+
+ $top_page_row = array(new CCol($logo, "page_header_l"), new CCol($page_header_r_col, "page_header_r"));
+ unset($logo, $page_header_r_col, $help);
+
+ $main_menu_row = array();
+ $sub_menu_row = array();
+
+ foreach($ZBX_MENU as $label=>$sub)
+ {
+// Check permissions
+ unset($deny);
+ if($label!='login' && !isset($USER_DETAILS['type']))
+ {
+ $deny = true;
+ }
+ elseif($label=='admin' && (!in_array($USER_DETAILS['type'], array(USER_TYPE_SUPPER_ADMIN)) ||
+ !in_array($ZBX_CURNODEID, get_accessible_nodes_by_user(
+ $USER_DETAILS,PERM_READ_WRITE,null,
+ PERM_RES_IDS_ARRAY,$ZBX_CURNODEID))))
+ {
+ $deny = true;
+ }
+ elseif($label=='config' && (
+ !in_array($USER_DETAILS['type'], array(USER_TYPE_SUPPER_ADMIN, USER_TYPE_ZABBIX_ADMIN)) ||
+ !in_array($ZBX_CURNODEID, get_accessible_nodes_by_user(
+ $USER_DETAILS,PERM_READ_LIST,null,
+ PERM_RES_IDS_ARRAY,$ZBX_CURNODEID))))
+ {
+ $deny = true;
+ }
+ elseif(!in_array($ZBX_CURNODEID, get_accessible_nodes_by_user(
+ $USER_DETAILS,PERM_READ_LIST,null,
+ PERM_RES_IDS_ARRAY,$ZBX_CURNODEID)))
+ {
+ $deny = true;
+ }
+
+// End of check permissions
+
+ unset($menu_url);
+ foreach($sub['pages'] as $sub_pages)
+ {
+ if($page['file'] == $sub_pages['url'] && isset($sub_pages['label']))
+ {
+ $menu_url = $sub_pages['url'];
+ break;
+ }
+ else if(isset($sub_pages['sub_pages']))
+ {
+ if(in_array($page['file'], $sub_pages['sub_pages']))
+ {
+ $menu_url = $sub_pages['url'];
+ break;
+ }
+ }
+ }
+
+ if(isset($menu_url)) /* active menu */
+ {
+ $class = "active";
+
+ update_profile('web.menu.'.$label.'.last', $menu_url);
+
+ if(isset($deny))
+ {
+ $denyed_page_requested = true;
+ continue;
+ }
+
+ foreach($sub['pages'] as $sub_pages)
+ {
+ if(!isset($sub_pages['label'])) continue;
+
+ array_push($sub_menu_row,
+ new CLink($sub_pages['label'], $sub_pages['url'],'highlight'),
+ new CSpan(SPACE.SPACE.'|'.SPACE.SPACE, 'divider')
+ );
+ }
+ }
+ else
+ {
+ if(isset($deny)) continue;
+
+ $class = "horizontal_menu_n";
+
+ $menu_url = get_profile('web.menu.'.$label.'.last',false);
+
+ if(!$menu_url)
+ $menu_url = $sub['pages'][$sub['default_page_id']]["url"];
+ }
+
+ array_push($main_menu_row, new CCol(new CLink($sub['label'], $menu_url, "highlight"),$class));
+ unset($menu_url, $class);
+ }
+
+ if(!defined('ZBX_PAGE_NO_MENU'))
+ {
+
+COpt::compare_files_with_menu($ZBX_MENU);
+
+ $table = new CTable(NULL,"page_header");
+ $table->SetCellSpacing(0);
+ $table->SetCellPadding(5);
+ $table->AddRow($top_page_row);
+ $table->Show();
+
+ $menu_table = new CTable(NULL,'menu');
+ $menu_table->SetCellSpacing(0);
+ $menu_table->SetCellPadding(5);
+ $menu_table->AddRow($main_menu_row);
+
+ $lst_nodes = new CComboBox('switch_node', $ZBX_CURNODEID);
+ $db_nodes = DBselect('select * from nodes where nodeid in ('.
+ get_accessible_nodes_by_user($USER_DETAILS,PERM_READ_LIST).') '.
+ ' order by name ');
+ while($node_data = DBfetch($db_nodes))
+ {
+ $lst_nodes->AddItem($node_data['nodeid'],$node_data['name']);
+ }
+
+ $node_form = new CForm();
+ $node_form->AddItem('Current node ['.$ZBX_CURNODEID.'] ');
+ $node_form->AddItem($lst_nodes);
+ unset($lst_nodes);
+ $node_form->AddItem(new CButton('submit',S_SWITCH));
+
+ $table = new CTable();
+ $table->SetCellSpacing(0);
+ $table->SetCellPadding(0);
+ $table->options['style'] = "width: 100%;";
+
+ $r_col = new CCol($node_form);
+ $r_col->options['style'] = "text-align: right;";
+
+ $table->AddRow(array($menu_table,$r_col));
+ $table->Show();
+
+ $sub_menu_table = new CTable(NULL,'sub_menu');
+ $sub_menu_table->SetCellSpacing(0);
+ $sub_menu_table->SetCellPadding(5);
+ $sub_menu_table->AddRow(new CCol($sub_menu_row));
+
+ $sub_menu_table->Show();
+ }
+ unset($ZBX_MENU);
+
+ destroy_objects();
+
+ unset($table, $top_page_row, $menu_table, $node_form);
+ unset($main_menu_row);
+ unset($db_nodes, $node_data);
+ unset($sub_menu_table, $sub_menu_row);
+
+ if(isset($denyed_page_requested))
+ {
+ access_deny();
+ }
+?>
diff --git a/frontends/php/include/perm.inc.php b/frontends/php/include/perm.inc.php
index 0d09f82a..7763e327 100644
--- a/frontends/php/include/perm.inc.php
+++ b/frontends/php/include/perm.inc.php
@@ -19,178 +19,542 @@
**/
?>
<?php
+ require_once "db.inc.php";
+ function permission2str($group_permission)
+ {
+ $str_perm[PERM_READ_WRITE] = S_READ_WRITE;
+ $str_perm[PERM_READ_ONLY] = S_READ_ONLY;
+ $str_perm[PERM_DENY] = S_DENY;
+
+ if(isset($str_perm[$group_permission]))
+ return $str_perm[$group_permission];
+
+ return S_UNCNOWN;
+ }
-define("ANY_ELEMENT_RIGHT", -1);
-define("GROUP_RIGHT", 0);
+/*****************************************
+ CHECK USER AUTHORISATION
+*****************************************/
function check_authorisation()
{
global $page;
global $PHP_AUTH_USER,$PHP_AUTH_PW;
global $USER_DETAILS;
- global $USER_RIGHTS;
global $_COOKIE;
global $_REQUEST;
- global $ZBX_CURNODEID;
+ global $ZBX_LOCALNODEID;
$USER_DETAILS = NULL;
- $USER_RIGHTS = array();
-
+
if(isset($_COOKIE["sessionid"]))
{
$sessionid = $_COOKIE["sessionid"];
- $USER_DETAILS = DBfetch(DBselect("select u.*,s.* from sessions s,users u".
+ if(!($USER_DETAILS = DBfetch(DBselect("select u.*,s.* from sessions s,users u".
" where s.sessionid=".zbx_dbstr($sessionid)." and s.userid=u.userid".
" and ((s.lastaccess+u.autologout>".time().") or (u.autologout=0))".
- " and mod(u.userid,100) = ".$ZBX_CURNODEID));
-
- if(!$USER_DETAILS)
+ " and ".DBid2nodeid('u.userid')." = ".$ZBX_LOCALNODEID))))
{
- $USER_DETAILS = array("alias"=>"- unknown -","userid"=>0);
-
setcookie("sessionid",$sessionid,time()-3600);
+ DBexecute("delete from sessions where sessionid=".zbx_dbstr($sessionid));
unset($_COOKIE["sessionid"]);
unset($sessionid);
- show_header("Login",0,0,1);
- show_error_message("Session was ended, please relogin!");
- show_page_footer();
- exit;
+ $incorrect_session = true;
}
- } else {
- $USER_DETAILS = DBfetch(DBselect("select u.* from users u where u.alias='guest' and mod(u.userid,100)=$ZBX_CURNODEID"));
- }
-
- if($USER_DETAILS)
- {
- if(isset($sessionid))
+ else
{
setcookie("sessionid",$sessionid);
DBexecute("update sessions set lastaccess=".time()." where sessionid=".zbx_dbstr($sessionid));
}
-
- $USER_RIGHTS = array();
-
- $db_rights = DBselect("select * from rights where userid=".$USER_DETAILS["userid"]);
- while($db_right = DBfetch($db_rights))
+ }
+
+ if(!$USER_DETAILS)
+ {
+ if(!($USER_DETAILS = DBfetch(DBselect("select u.* from users u where u.alias='guest'".
+ " and ".DBid2nodeid('u.userid')."=$ZBX_LOCALNODEID"))))
{
- $usr_right = array(
- "name"=> $db_right["name"],
- "id"=> $db_right["id"],
- "permission"=> $db_right["permission"]
- );
+ $missed_user_guest = true;
+ }
+ }
- array_push($USER_RIGHTS,$usr_right);
+ if($USER_DETAILS)
+ {
+ $USER_DETAILS['node'] = DBfetch(DBselect('select * from nodes where nodeid='.id2nodeid($USER_DETAILS['userid'])));
+ if(empty($USER_DETAILS['node']))
+ {
+ $USER_DETAILS['node']['name'] = '- uncnown -';
+ $USER_DETAILS['node']['nodeid'] = $ZBX_LOCALNODEID;
}
- return;
}
else
{
- $USER_DETAILS = array("alias"=>"- unknown -","userid"=>0);
+ $USER_DETAILS = array(
+ "alias" =>"- unknown -",
+ "userid"=>0,
+ "lang" =>"en_gb",
+ "type" =>"0",
+ "node" =>array(
+ "name" =>'- uncnown -',
+ "nodeid"=>0));
}
-
-// Incorrect login
-
- if(isset($sessionid))
+
+ if(isset($incorrect_session) || isset($missed_user_guest))
{
- setcookie("sessionid",$sessionid,time()-3600);
- unset($_COOKIE["sessionid"]);
+ if(isset($incorrect_session)) $message = "Session was ended, please relogin!";
+ else if(isset($missed_user_guest)) $message = "Database corrupted, missed default user 'guest'";
+
+ if($page["file"]!="index.php")
+ {
+ Redirect("index.php?message=".addslashes($message));
+ exit;
+ }
+ if(!isset($_REQUEST['message'])) $_REQUEST['message'] = $message;
}
+ }
- if($page["file"]!="index.php")
+/***********************************************
+ GET ACCESSIBLE RESOURCES BY USERID
+************************************************/
+ function perm_mode2comparator($perm_mode)
+ {
+ switch($perm_mode)
{
- echo "<meta http-equiv=\"refresh\" content=\"0; url=index.php\">";
- exit;
+ case PERM_MODE_NE: $perm_mode = '!='; break;
+ case PERM_MODE_EQ: $perm_mode = '=='; break;
+ case PERM_MODE_GT: $perm_mode = '>'; break;
+ case PERM_MODE_LT: $perm_mode = '<'; break;
+ case PERM_MODE_LE: $perm_mode = '<='; break;
+ case PERM_MODE_GE:
+ default: $perm_mode = '>='; break;
}
- show_header("Login",0,0,1);
- show_error_message("Login name or password is incorrect");
- insert_login_form();
- show_page_footer();
-
- //END TODO
- exit;
+ return $perm_mode;
}
- function permission2int($permission)
+ function get_accessible_hosts_by_user(&$user_data,$perm,$perm_mode=null,$perm_res=null,$nodeid=null,$hostid=null)
{
- $int_rights = array(
- "A" => 3,
- "U" => 2,
- "R" => 1,
- "H" => 0
- );
+ if(is_null($perm_res)) $perm_res = PERM_RES_STRING_LINE;
+ if($perm == PERM_READ_LIST) $perm = PERM_READ_ONLY;
+
+ $result = array();
+
+ $userid =& $user_data['userid'];
+
+ if(!isset($userid)) fatal_error('Incorrect user data in "get_accessible_hosts_by_user"');
- if(isset($int_rights[$permission]))
- return ($int_rights[$permission]);
+ switch($perm_res)
+ {
+ case PERM_RES_DATA_ARRAY: $resdata = '$host_data'; break;
+ default: $resdata = '$host_data["hostid"]'; break;
+ }
+
+COpt::counter_up('perm_host['.$userid.','.$perm.','.$perm_mode.','.$perm_res.','.$nodeid.']');
+COpt::counter_up('perm');
+
+ if(is_null($nodeid)) $where_nodeid = '';
+ else if(is_array($nodeid)) $where_nodeid = ' and n.nodeid in ('.implode(',', $nodeid).') ';
+ else $where_nodeid = ' and n.nodeid in ('.$nodeid.') ';
+
+ if(is_null($hostid)) $where_hostid = '';
+ else if(is_array($hostid)) $where_hostid = ' and h.hostid in ('.implode(',', $hostid).') ';
+ else $where_hostid = ' and h.hostid in ('.$hostid.') ';
+
+ $db_hosts = DBselect('select distinct n.nodeid,n.name as node_name,h.hostid,h.host, min(r.permission) as permission '.
+ ' from nodes n, users_groups ug '.
+ ' left join rights r on r.groupid=ug.usrgrpid and r.type='.RESOURCE_TYPE_GROUP.' and ug.userid='.$userid.
+ ' right join groups g on r.id=g.groupid '.
+ ' left join hosts_groups hg on g.groupid=hg.groupid '.
+ ' right join hosts h on hg.hostid=h.hostid '.
+ ' where '.DBid2nodeid('h.hostid').'=n.nodeid '.$where_nodeid.$where_hostid.' group by h.hostid'.
+ ' order by n.name, g.name, h.host');
+
+
+ while($host_data = DBfetch($db_hosts))
+ {
+ /* if no rights defined used node rights */
+ if(is_null($host_data['permission']))
+ {
+ if(!isset($nodes))
+ {
+ $nodes = get_accessible_nodes_by_user($user_data,
+ PERM_DENY,PERM_MODE_GE,PERM_RES_DATA_ARRAY);
+ }
+ $host_data['permission'] = $nodes[$host_data['nodeid']]['permission'];
+ }
- return ($int_rights["R"]);
+ if(eval('return ('.$host_data["permission"].' '.perm_mode2comparator($perm_mode).' '.$perm.')? 0 : 1;'))
+ continue;
+
+ $result[$host_data['hostid']] = eval('return '.$resdata.';');
+ }
+
+ if($perm_res == PERM_RES_STRING_LINE)
+ {
+ if(count($result) == 0)
+ $result = '-1';
+ else
+ $result = implode(',',$result);
+ }
+
+ return $result;
}
- function permission_min($permission1, $permission2) // NOTE: only for integer permissions !!! see: permission2int
+ function get_accessible_groups_by_user($user_data,$perm,$perm_mode=null,$perm_res=null,$nodeid=null)
{
- if(is_null($permission1) && is_null($permission2)) return NULL;
- if(is_null($permission1)) return $permission2;
- if(is_null($permission2)) return $permission1;
- return min($permission1,$permission2);
+ global $ZBX_LOCALNODEID;
+
+ if(is_null($perm_mode)) $perm_mode = PERM_MODE_GE;
+ if(is_null($perm_res)) $perm_res = PERM_RES_STRING_LINE;
+
+ $result = array();
+
+ $userid =& $user_data['userid'];
+ if(!isset($userid)) fatal_error('Incorrect user data in "get_accessible_groups_by_user"');
+
+ switch($perm_res)
+ {
+ case PERM_RES_DATA_ARRAY: $resdata = '$group_data'; break;
+ default: $resdata = '$group_data["groupid"]'; break;
+ }
+
+COpt::counter_up('perm_group['.$userid.','.$perm.','.$perm_mode.','.$perm_res.','.$nodeid.']');
+COpt::counter_up('perm');
+
+ if(is_null($nodeid)) $where_nodeid = '';
+ else if(is_array($nodeid)) $where_nodeid = ' and n.nodeid in ('.implode(',', $nodeid).') ';
+ else $where_nodeid = ' and n.nodeid in ('.$nodeid.') ';
+
+ /* if no rights defined used node rights */
+ $db_groups = DBselect('select n.nodeid,n.name as node_name,hg.groupid,hg.name, min(r.permission) as permission '.
+ ' from nodes n, users_groups g '.
+ ' left join rights r on r.groupid=g.usrgrpid and r.type='.RESOURCE_TYPE_GROUP.' and g.userid='.$userid.
+ ' right join groups hg on r.id=hg.groupid '.
+ ' where '.DBid2nodeid('hg.groupid').'=n.nodeid '.$where_nodeid.
+ ' group by hg.groupid, hg.name, g.userid order by n.name, hg.name');
+
+ while($group_data = DBfetch($db_groups))
+ {
+ /* deny if no rights defined */
+ if(is_null($group_data['permission']))
+ {
+ if(!isset($nodes))
+ {
+ $nodes = get_accessible_nodes_by_user($user_data,
+ PERM_DENY,PERM_MODE_GE,PERM_RES_DATA_ARRAY);
+ }
+ $group_data['permission'] = $nodes[$group_data['nodeid']]['permission'];
+ }
+
+ if(eval('return ('.$group_data["permission"].' '.perm_mode2comparator($perm_mode).' '.$perm.')? 0 : 1;'))
+ continue;
+
+ $result[$group_data['groupid']] = eval('return '.$resdata.';');
+ }
+
+ if($perm_res == PERM_RES_STRING_LINE)
+ {
+ if(count($result) == 0)
+ $result = '-1';
+ else
+ $result = implode(',',$result);
+ }
+
+ return $result;
}
- function permission_max($permission1, $permission2) // NOTE: only for integer permissions !!! see: permission2int
+
+ function get_accessible_nodes_by_user(&$user_data,$perm,$perm_mode=null,$perm_res=null,$nodeid=null)
{
- if(is_null($permission1) && is_null($permission2)) return NULL;
- if(is_null($permission1)) return $permission2;
- if(is_null($permission2)) return $permission1;
- return max($permission1,$permission2);
+ global $ZBX_LOCALNODEID;
+
+ if(is_null($perm_mode)) $perm_mode=PERM_MODE_GE;
+ if(is_null($perm_res)) $perm_res=PERM_RES_STRING_LINE;
+
+ $userid =& $user_data['userid'];
+ $user_type =& $user_data['type'];
+ if(!isset($userid)) fatal_error('Incorrect user data in "get_accessible_nodes_by_user"');
+
+ $result= array();
+
+ switch($perm_res)
+ {
+ case PERM_RES_DATA_ARRAY: $resdata = '$node_data'; break;
+ default: $resdata = '$node_data["nodeid"]'; break;
+ }
+
+COpt::counter_up('perm_nodes['.$userid.','.$perm.','.$perm_mode.','.$perm_res.','.$nodeid.']');
+COpt::counter_up('perm');
+
+ if(is_null($nodeid)) $where_nodeid = '';
+ else if(is_array($nodeid)) $where_nodeid = ' where n.nodeid in ('.implode(',', $nodeid).') ';
+ else $where_nodeid = ' where n.nodeid in ('.$nodeid.') ';
+
+ $db_nodes = DBselect('select n.nodeid,n.name,min(r.permission) as permission'.
+ ' from users_groups g left join rights r on r.groupid=g.usrgrpid and'.
+ ' r.type='.RESOURCE_TYPE_NODE.' and g.userid='.$userid.
+ ' right join nodes n on r.id=n.nodeid'.$where_nodeid.
+ ' group by n.nodeid');
+
+ while($node_data = DBfetch($db_nodes))
+ {
+
+ /* deny if no rights defined (for local node read/write)*/
+ if(is_null($node_data['permission']))
+ {
+ if($user_type == USER_TYPE_SUPPER_ADMIN)
+ $node_data['permission'] = PERM_READ_WRITE;
+ else
+ $node_data['permission'] =
+ ($node_data['nodeid'] == $ZBX_LOCALNODEID) ? PERM_READ_WRITE : PERM_DENY;
+ }
+
+ /* special processing for PERM_READ_LIST*/
+ if(PERM_DENY == $node_data['permission'] && PERM_READ_LIST == $perm)
+ {
+ $groups = get_accessible_groups_by_user($user_data,
+ $perm, PERM_MODE_GE,PERM_RES_DATA_ARRAY,$node_data['nodeid']);
+ if(count($groups) == 0) continue;
+ }
+ else
+ {
+ if(eval('return ('.$node_data["permission"].' '.perm_mode2comparator($perm_mode).' '.$perm.')? 0 : 1;'))
+ continue;
+ }
+
+ $result[$node_data["nodeid"]] = eval('return '.$resdata.';');
+ }
+
+ if($perm_res == PERM_RES_STRING_LINE)
+ {
+ if(count($result) == 0)
+ $result = '-1';
+ else
+ $result = implode(',',$result);
+ }
+
+ return $result;
}
- function check_right($right,$permission,$id = GROUP_RIGHT)
+/***********************************************
+ GET ACCESSIBLE RESOURCES BY RIGHTS
+************************************************/
+ /* NOTE: right structure is
+
+ $rights[i]['type'] = type of resource
+ $rights[i]['permission']= permission for resource
+ $rights[i]['id'] = resource id
+
+ */
+
+ function get_accessible_hosts_by_rights(&$rights,$user_type,$perm,$perm_mode=null,$perm_res=null,$nodeid=null)
{
- global $USER_RIGHTS;
+ if(is_null($perm_res)) $perm_res = PERM_RES_STRING_LINE;
+ if($perm == PERM_READ_LIST) $perm = PERM_READ_ONLY;
- $default_permission = permission2int("H");
- $group_permission = NULL;
- $id_permission = NULL;
- $any_permission = NULL;
+ $result = array();
- $permission = permission2int($permission);
+ switch($perm_res)
+ {
+ case PERM_RES_DATA_ARRAY: $resdata = '$host_data'; break;
+ default: $resdata = '$host_data["hostid"]'; break;
+ }
+
+ if(is_null($nodeid)) $where_nodeid = '';
+ else if(is_array($nodeid)) $where_nodeid = ' and n.nodeid in ('.implode(',', $nodeid).') ';
+ else $where_nodeid = ' and n.nodeid in ('.$nodeid.') ';
- if(count($USER_RIGHTS) > 0)
+ $db_hosts = DBselect('select n.nodeid,n.name as node_name,hg.groupid,h.hostid,h.host '.
+ ' from nodes n, hosts h left join hosts_groups hg on hg.hostid=h.hostid '.
+ ' where n.nodeid='.DBid2nodeid('h.hostid').$where_nodeid.' order by n.name,h.host');
+
+ $res_perm = array();
+ foreach($rights as $right)
{
- foreach($USER_RIGHTS as $usr_right)
+ $res_perm[$right['type']][$right['id']] = $right['permission'];
+ }
+
+ $host_perm = array();
+
+ while($host_data = DBfetch($db_hosts))
+ {
+ if(isset($host_data['groupid']) && isset($res_perm[RESOURCE_TYPE_GROUP][$host_data['groupid']]))
{
- $int_permision = permission2int($usr_right["permission"]);
- if($usr_right["name"] == $right) {
+ $host_perm[$host_data['hostid']][RESOURCE_TYPE_GROUP][$host_data['groupid']] =
+ $res_perm[RESOURCE_TYPE_GROUP][$host_data['groupid']];
+ }
- if($usr_right["id"] == $id)
- $id_permission = permission_max($id_permission, $int_permision);
- if($usr_right["id"] == GROUP_RIGHT)
- $group_permission = permission_max($group_permission, $int_permision);
- else
- $any_permission = permission_max($any_permission, $int_permision);
- }
- if($usr_right["name"] == 'Default permission')
+ if(isset($res_perm[RESOURCE_TYPE_NODE][$host_data['nodeid']]))
+ {
+ $host_perm[$host_data['hostid']][RESOURCE_TYPE_NODE] = $res_perm[RESOURCE_TYPE_NODE][$host_data['nodeid']];
+ }
+ $host_perm[$host_data['hostid']]['data'] = $host_data;
+
+ }
+
+ foreach($host_perm as $hostid => $host_data)
+ {
+ $host_data = $host_data['data'];
+
+ if(isset($host_perm[$hostid][RESOURCE_TYPE_GROUP]))
+ {
+ $host_data['permission'] = min($host_perm[$hostid][RESOURCE_TYPE_GROUP]);
+ }
+ else if(isset($host_perm[$hostid][RESOURCE_TYPE_NODE]))
+ {
+ $host_data['permission'] = $host_perm[$hostid][RESOURCE_TYPE_NODE];
+ }
+ else
+ {
+ if(!isset($node_data[$host_data['nodeid']]))
{
- $default_permission = permission_max($default_permission, $int_permision);
+ $node_data = get_accessible_nodes_by_rights($rights,$user_type,
+ PERM_DENY, PERM_MODE_GE, PERM_RES_DATA_ARRAY, $host_data['nodeid']);
}
+ $host_data['permission'] = $node_data[$host_data['nodeid']]['permission'];
}
+
+ if(eval('return ('.$host_data["permission"].' '.perm_mode2comparator($perm_mode).' '.$perm.')? 0 : 1;'))
+ continue;
+
+ $result[$host_data['hostid']] = eval('return '.$resdata.';');
+
}
- if($id == ANY_ELEMENT_RIGHT)
- $access = $any_permission;
- else
- $access = $id_permission;
-
- if(is_null($access)) $access = $group_permission;
- if(is_null($access)) $access = $default_permission;
+ if($perm_res == PERM_RES_STRING_LINE)
+ {
+ if(count($result) == 0)
+ $result = '-1';
+ else
+ $result = implode(',',$result);
+ }
+
+ return $result;
+ }
+ function get_accessible_groups_by_rights(&$rights,$user_type,$perm,$perm_mode=null,$perm_res=null,$nodeid=null)
+ {
+ if(is_null($perm_mode)) $perm_mode=PERM_MODE_GE;
+ if(is_null($perm_res)) $perm_res=PERM_RES_STRING_LINE;
+
+ $result= array();
+
+ switch($perm_res)
+ {
+ case PERM_RES_DATA_ARRAY: $resdata = '$group_data'; break;
+ default: $resdata = '$group_data["groupid"]'; break;
+ }
+
+ if(is_null($nodeid)) $where_nodeid = '';
+ else if(is_array($nodeid)) $where_nodeid = ' and n.nodeid in ('.implode(',', $nodeid).') ';
+ else $where_nodeid = ' and n.nodeid in ('.$nodeid.') ';
+
+ $group_perm = array();
+ foreach($rights as $right)
+ {
+ if($right['type'] != RESOURCE_TYPE_GROUP) continue;
+ $group_perm[$right['id']] = $right['permission'];
+ }
+ $db_groups = DBselect('select n.nodeid,n.name as node_name, g.groupid,g.name, '.PERM_DENY.' as permission from groups g, nodes n '.
+ ' where '.DBid2nodeid('g.groupid').'=n.nodeid '.$where_nodeid.
+ ' order by n.name, g.name');
-//SDI($right.": ".$access." >= ".$permission);
- return (($access >= $permission) ? 1 : 0);
+ while($group_data = DBfetch($db_groups))
+ {
+ if(isset($group_perm[$group_data['groupid']]))
+ {
+ $group_data['permission'] = $group_perm[$group_data['groupid']];
+ }
+ else
+ {
+ if(!isset($node_data[$group_data['nodeid']]))
+ {
+ $node_data = get_accessible_nodes_by_rights($rights,$user_type,
+ PERM_DENY, PERM_MODE_GE, PERM_RES_DATA_ARRAY, $group_data['nodeid']);
+ }
+ $group_data['permission'] = $node_data[$group_data['nodeid']]['permission'];
+ }
+
+ if(eval('return ('.$group_data["permission"].' '.perm_mode2comparator($perm_mode).' '.$perm.')? 0 : 1;'))
+ continue;
+
+ $result[$group_data["groupid"]] = eval('return '.$resdata.';');
+ }
+
+ if($perm_res == PERM_RES_STRING_LINE)
+ {
+ if(count($result) == 0)
+ $result = '-1';
+ else
+ $result = implode(',',$result);
+ }
+
+ return $result;
}
- function check_anyright($right,$permission)
+ function get_accessible_nodes_by_rights(&$rights,$user_type,$perm,$perm_mode=null,$perm_res=null,$nodeid=null)
{
- return check_right($right,$permission, ANY_ELEMENT_RIGHT);
- }
+ global $ZBX_LOCALNODEID;
+
+ if(is_null($perm_mode)) $perm_mode=PERM_MODE_GE;
+ if(is_null($perm_res)) $perm_res=PERM_RES_STRING_LINE;
+
+ $result= array();
+
+ if(is_null($user_type)) $user_type = USER_TYPE_ZABBIX_USER;
+ switch($perm_res)
+ {
+ case PERM_RES_DATA_ARRAY: $resdata = '$node_data'; break;
+ default: $resdata = '$node_data["nodeid"]'; break;
+ }
+
+ if(is_null($nodeid)) $where_nodeid = '';
+ else if(is_array($nodeid)) $where_nodeid = ' where n.nodeid in ('.implode(',', $nodeid).') ';
+ else $where_nodeid = ' where n.nodeid in ('.$nodeid.') ';
+
+ $node_perm = array();
+ foreach($rights as $right)
+ {
+ if($right['type'] != RESOURCE_TYPE_NODE) continue;
+ $node_perm[$right['id']] = $right['permission'];
+ }
+
+ $db_nodes = DBselect('select n.nodeid,n.name, '.PERM_DENY.' as permission from nodes n '.$where_nodeid.' order by n.name');
+
+ while($node_data = DBfetch($db_nodes))
+ {
+ if(isset($node_perm[$node_data['nodeid']]))
+ $node_data['permission'] = $node_perm[$node_data['nodeid']];
+ elseif($node_data['nodeid'] == $ZBX_LOCALNODEID || $user_type == USER_TYPE_SUPPER_ADMIN)
+ /* for local node or superuser default permission is READ_WRITE */
+ $node_data['permission'] = PERM_READ_WRITE;
+
+
+ /* special processing for PERM_READ_LIST*/
+ if(PERM_DENY == $node_data['permission'] && PERM_READ_LIST == $perm)
+ {
+ $groups = get_accessible_groups_by_rights($rights,$user_type,
+ $perm, PERM_MODE_GE, PERM_RES_DATA_ARRAY, $node_data['nodeid']);
+ if(count($groups) == 0) continue;
+ }
+ else
+ {
+ if(eval('return ('.$node_data["permission"].' '.perm_mode2comparator($perm_mode).' '.$perm.')? 0 : 1;'))
+ continue;
+ }
+
+ $result[$node_data["nodeid"]] = eval('return '.$resdata.';');
+ }
+
+ if($perm_res == PERM_RES_STRING_LINE)
+ {
+ if(count($result) == 0)
+ $result = '-1';
+ else
+ $result = implode(',',$result);
+ }
+
+ return $result;
+ }
?>
diff --git a/frontends/php/include/profiles.inc.php b/frontends/php/include/profiles.inc.php
index 87ee793a..8e1e341b 100644
--- a/frontends/php/include/profiles.inc.php
+++ b/frontends/php/include/profiles.inc.php
@@ -25,13 +25,6 @@
$hostid,$devicetype,$name,$os,$serialno,$tag,$macaddress,
$hardware,$software,$contact,$location,$notes)
{
- // If user has update permission then ok
- if(!check_right("Host","U",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
$result=DBexecute("select * from hosts_profiles where hostid=$hostid");
if(DBfetch($result))
{
@@ -53,11 +46,6 @@
function delete_host_profile($hostid)
{
- if(!check_right("Host","U",0))
- {
- error("Insufficient permissions");
- return 0;
- }
$result=DBexecute("delete from hosts_profiles where hostid=$hostid");
return $result;
diff --git a/frontends/php/include/screens.inc.php b/frontends/php/include/screens.inc.php
index d3f62644..ce5c0af8 100644
--- a/frontends/php/include/screens.inc.php
+++ b/frontends/php/include/screens.inc.php
@@ -17,16 +17,79 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
+
+ require_once "include/events.inc.php";
+ require_once "include/actions.inc.php";
?>
<?php
+ function screen_accessiable($screenid,$perm)
+ {
+ global $USER_DETAILS;
+
+ $result = false;
+
+ if(DBselect("select screenid from screens where screenid=".$screenid.
+ " and ".DBid2nodeid('screenid')." in (".get_accessible_nodes_by_user($USER_DETAILS,$perm).")"))
+ {
+ $result = true;
+
+ $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, PERM_MODE_LT);
+ $denyed_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY, PERM_MODE_LT);
+
+ $db_result = DBselect("select * from screens_items where screenid=".$screenid);
+ while(($ac_data = DBfetch($db_result)) && $result)
+ {
+ switch($ac_data['resourcetype'])
+ {
+ case SCREEN_RESOURCE_GRAPH:
+ $itemid = array();
+
+ $db_gitems = DBselect("select distinct itemid from graphs_items ".
+ " where graphid=".$ac_data['resourceid']);
+
+ while($gitem_data = DBfetch($db_gitems)) array_push($itemid, $gitem_data['itemid']);
+
+ if(count($itemid) == 0) $itemid = array(-1);
+ // break; /* use same processing as items */
+ case SCREEN_RESOURCE_SIMPLE_GRAPH:
+ // break; /* use same processing as items */
+ case SCREEN_RESOURCE_PLAIN_TEXT:
+ if(!isset($itemid))
+ $itemid = array($ac_data['resourceid']);
+
+ if(DBfetch(DBselect("select itemid from items where itemid in (".implode(',',$itemid).") ".
+ " and hostid in (".$denyed_hosts.")")))
+ {
+ $result = false;
+ }
+
+ unset($itemid);
+ break;
+ case SCREEN_RESOURCE_MAP:
+ $result &= sysmap_accessiable($ac_data['resourceid'], PERM_READ_ONLY);
+ break;
+ case SCREEN_RESOURCE_SCREEN:
+ $result &= screen_accessiable($ac_data['resourceid'],PERM_READ_ONLY);
+ break;
+ case SCREEN_RESOURCE_SERVER_INFO:
+ case SCREEN_RESOURCE_HOSTS_INFO:
+ case SCREEN_RESOURCE_TRIGGERS_INFO:
+ case SCREEN_RESOURCE_TRIGGERS_OVERVIEW:
+ case SCREEN_RESOURCE_DATA_OVERVIEW:
+ case SCREEN_RESOURCE_CLOCK:
+ case SCREEN_RESOURCE_URL:
+ case SCREEN_RESOURCE_ACTIONS:
+ case SCREEN_RESOURCE_EVENTS:
+ /* skip */
+ break;
+ }
+ }
+ }
+ return $result;
+ }
+
function add_screen($name,$hsize,$vsize)
{
- if(!check_right("Screen","A",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
$screenid=get_dbid("screens","screenid");
$sql="insert into screens (screenid,name,hsize,vsize) values ($screenid,".zbx_dbstr($name).",$hsize,$vsize)";
$result=DBexecute($sql);
@@ -39,12 +102,6 @@
function update_screen($screenid,$name,$hsize,$vsize)
{
- if(!check_right("Screen","U",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
$sql="update screens set name=".zbx_dbstr($name).",hsize=$hsize,vsize=$vsize where screenid=$screenid";
return DBexecute($sql);
}
@@ -57,9 +114,6 @@
$result=DBexecute("delete from screens_items where resourceid=$screenid and resourcetype=".SCREEN_RESOURCE_SCREEN);
if(!$result) return $result;
- // delete screen permisions
- DBexecute('delete from rights where name=\'Screen\' and id='.$screenid);
-
return DBexecute("delete from screens where screenid=$screenid");
}
@@ -68,10 +122,11 @@
$sql="delete from screens_items where screenid=$screenid and x=$x and y=$y";
DBexecute($sql);
$screenitemid=get_dbid("screens_items","screenitemid");
- $sql="insert into screens_items (resourcetype,screenid,x,y,resourceid,width,height,colspan,rowspan,elements,valign,halign,style,url)".
- " values ($resourcetype,$screenid,$x,$y,$resourceid,$width,$height,$colspan,$rowspan,$elements,$valign,$halign,$style,".
- zbx_dbstr($url).")";
- $result=DBexecute($sql);
+ $result=DBexecute("insert into screens_items (screenitemid,resourcetype,screenid,x,y,resourceid,width,height,".
+ " colspan,rowspan,elements,valign,halign,style,url) ".
+ " values ($screenitemid,$resourcetype,$screenid,$x,$y,$resourceid,".
+ " $width,$height,$colspan,$rowspan,$elements,$valign,$halign,$style,".
+ zbx_dbstr($url).")");
if(!$result)
return $result;
@@ -81,8 +136,9 @@
function update_screen_item($screenitemid,$resourcetype,$resourceid,$width,$height,$colspan,$rowspan,$elements,$valign,$halign,$style,$url)
{
- $sql="update screens_items set resourcetype=$resourcetype,resourceid=$resourceid,width=$width,height=$height,colspan=$colspan,rowspan=$rowspan,elements=$elements,valign=$valign,halign=$halign,style=$style,url=".zbx_dbstr($url)." where screenitemid=$screenitemid";
- return DBexecute($sql);
+ return DBexecute("update screens_items set resourcetype=$resourcetype,resourceid=$resourceid,".
+ "width=$width,height=$height,colspan=$colspan,rowspan=$rowspan,elements=$elements,valign=$valign,".
+ "halign=$halign,style=$style,url=".zbx_dbstr($url)." where screenitemid=$screenitemid");
}
function delete_screen_item($screenitemid)
@@ -93,8 +149,7 @@
function get_screen_by_screenid($screenid)
{
- $sql="select * from screens where screenid=$screenid";
- $result=DBselect($sql);
+ $result = DBselect("select * from screens where screenid=$screenid");
$row=DBfetch($result);
if($row)
{
@@ -123,12 +178,15 @@
// editmode: 0 - view with actions, 1 - edit mode, 2 - view without any actions
function get_screen($screenid, $editmode, $effectiveperiod=NULL)
{
+ if(!screen_accessiable($screenid, $editmode ? PERM_READ_WRITE : PERM_READ_ONLY))
+ access_deny();
+
if(is_null($effectiveperiod))
$effectiveperiod = 3600;
$result=DBselect("select name,hsize,vsize from screens where screenid=$screenid");
$row=DBfetch($result);
- if(!$row) return new CSpan("Screen missing".BR);
+ if(!$row) return new CTableInfo(S_NO_SCREENS_DEFINED);
for($r=0;$r<$row["vsize"];$r++)
{
@@ -290,12 +348,14 @@
}
elseif( ($screenitemid!=0) && ($resourcetype==SCREEN_RESOURCE_TRIGGERS_OVERVIEW) )
{
- $item = array(get_triggers_overview($resourceid));
+ global $ZBX_CURNODEID;
+ $item = array(get_triggers_overview($resourceid, $ZBX_CURNODEID));
if($editmode == 1) array_push($item,new CLink(S_CHANGE,$action));
}
elseif( ($screenitemid!=0) && ($resourcetype==SCREEN_RESOURCE_DATA_OVERVIEW) )
{
- $item = array(get_items_data_overview($resourceid));
+ global $ZBX_CURNODEID;
+ $item = array(get_items_data_overview($resourceid, $ZBX_CURNODEID));
if($editmode == 1) array_push($item,new CLink(S_CHANGE,$action));
}
elseif( ($screenitemid!=0) && ($resourcetype==SCREEN_RESOURCE_URL) )
diff --git a/frontends/php/include/services.inc.php b/frontends/php/include/services.inc.php
index 9be53611..11dbd31b 100644
--- a/frontends/php/include/services.inc.php
+++ b/frontends/php/include/services.inc.php
@@ -21,10 +21,7 @@
<?php
function add_service($name,$triggerid,$algorithm,$showsla,$goodsla,$sortorder,$service_times=array())
{
-
-var_dump($service_times);
-
- if(is_null($triggerid)) $triggerid = 'NULL';
+ if(is_null($triggerid) || $triggerid==0) $triggerid = 'NULL';
$serviceid=get_dbid("services","serviceid");
@@ -51,7 +48,7 @@ var_dump($service_times);
function update_service($serviceid,$name,$triggerid,$algorithm,$showsla,$goodsla,$sortorder,$service_times=array())
{
- if(is_null($triggerid)) $triggerid = 'NULL';
+ if(is_null($triggerid) || $triggerid==0) $triggerid = 'NULL';
$result = DBexecute("update services set name=".zbx_dbstr($name).",triggerid=$triggerid,status=0,algorithm=$algorithm,showsla=$showsla,goodsla=$goodsla,sortorder=$sortorder where serviceid=$serviceid");
@@ -65,13 +62,17 @@ var_dump($service_times);
return $result;
}
- function add_host_to_services($hostid,$serviceid)
+ function add_host_to_services($hostid, $serviceid)
{
- $sql="select distinct t.triggerid,t.description from triggers t,hosts h,items i,functions f where h.hostid=$hostid and h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid";
- $result=DBselect($sql);
+ global $ZBX_CURNODEID;
+
+ $result = DBselect('select distinct h.host,t.triggerid,t.description '.
+ ' from triggers t,hosts h,items i,functions f where h.hostid='.$hostid.' and h.hostid=i.hostid '.
+ ' and i.itemid=f.itemid and f.triggerid=t.triggerid '.
+ ' and '.DBid2nodeid('t.triggerid').'='.$ZBX_CURNODEID);
while($row=DBfetch($result))
{
- $serviceid2=add_service($row["description"],$row["triggerid"],"on",0,"off",99,0);
+ $serviceid2 = add_service(expand_trigger_description_by_data($row),$row["triggerid"],"on",0,"off",99);
add_service_link($serviceid2,$serviceid,0);
}
return 1;
@@ -79,9 +80,7 @@ var_dump($service_times);
function is_service_hardlinked($serviceid)
{
- $sql="select count(*) as cnt from services_links where servicedownid=$serviceid and soft=0";
- $result=DBselect($sql);
- $row=DBfetch($result);
+ $row = DBfetch(DBselect("select count(*) as cnt from services_links where servicedownid=".$serviceid." and soft=0"));
if($row["cnt"]>0)
{
return TRUE;
@@ -103,8 +102,6 @@ var_dump($service_times);
{
return $result;
}
- // delete service permisions
- DBexecute('delete from rights where name=\'Service\' and id='.$serviceid);
$sql="delete from services where serviceid=$serviceid";
return DBexecute($sql);
@@ -114,9 +111,7 @@ var_dump($service_times);
# Warning: recursive function
function does_service_depend_on_the_service($serviceid,$serviceid2)
{
-# echo "Serviceid:$serviceid Triggerid:$serviceid2<br>";
$service=get_service_by_serviceid($serviceid);
-# echo "Service status:".$service["status"]."<br>";
if($service["status"]==0)
{
return FALSE;
@@ -130,9 +125,7 @@ var_dump($service_times);
}
- $sql="select serviceupid from services_links where servicedownid=$serviceid2 and soft=0";
-# echo $sql."<br>";
- $result=DBselect($sql);
+ $result=DBselect("select serviceupid from services_links where servicedownid=$serviceid2 and soft=0");
while($row=DBfetch($result))
{
if(does_service_depend_on_the_service($serviceid,$row["serviceupid"]) == TRUE)
@@ -145,9 +138,7 @@ var_dump($service_times);
function service_has_parent($serviceid)
{
- $sql="select count(*) as cnt from services_links where servicedownid=$serviceid";
- $result=DBselect($sql);
- $row=DBfetch($result);
+ $row = DBfetch(DBselect("select count(*) as cnt from services_links where servicedownid=$serviceid"));
if($row["cnt"]>0)
{
return TRUE;
@@ -157,9 +148,7 @@ var_dump($service_times);
function service_has_no_this_parent($parentid,$serviceid)
{
- $sql="select count(*) as cnt from services_links where serviceupid=$parentid and servicedownid=$serviceid";
- $result=DBselect($sql);
- $row=DBfetch($result);
+ $row = DBfetch(DBselect("select count(*) as cnt from services_links where serviceupid=$parentid and servicedownid=$serviceid"));
if($row["cnt"]>0)
{
return FALSE;
@@ -171,6 +160,7 @@ var_dump($service_times);
{
if( ($softlink==0) && (is_service_hardlinked($servicedownid)==true) )
{
+ error("cannot link hardlinked service.");
return false;
}
@@ -485,20 +475,17 @@ SDI(
function get_num_of_service_childs($serviceid)
{
- $sql="select count(*) as cnt from services_links where serviceupid=$serviceid";
- $result=DBselect($sql);
- $row=DBfetch($result);
+ $row = DBfetch(DBselect("select count(distinct servicedownid) as cnt from services_links ".
+ " where serviceupid=".$serviceid));
return $row["cnt"];
}
function get_service_by_serviceid($serviceid)
{
- $sql="select * from services where serviceid=$serviceid";
- $result=DBselect($sql);
- $res = DBfetch($result);
+ $res = DBfetch(DBselect("select * from services where serviceid=".$serviceid));
if(!$res)
{
- error("No service with serviceid=[$serviceid]");
+ error("No service with serviceid=[".$serviceid."]");
return FALSE;
}
return $res;
diff --git a/frontends/php/include/triggers.inc.php b/frontends/php/include/triggers.inc.php
index 7526b851..7f079310 100644
--- a/frontends/php/include/triggers.inc.php
+++ b/frontends/php/include/triggers.inc.php
@@ -19,6 +19,19 @@
**/
?>
<?php
+ require_once "maps.inc.php";
+
+ function get_severity_style($severity)
+ {
+ if($severity == 1) return "information";
+ elseif($severity == 2) return "warning";
+ elseif($severity == 3) return "average";
+ elseif($severity == 4) return "high";
+ elseif($severity == 5) return "disaster";
+
+ return "";
+ }
+
function get_severity_description($severity)
{
if($severity == 0) return S_NOT_CLASSIFIED;
@@ -288,11 +301,6 @@
$expression, $description, $priority, $status,
$comments, $url, $deps=array(), $templateid=0)
{
-// if(!check_right("Trigger","A",0))
-// {
-// error("Insufficient permissions");
-// return 0;
-// }
if(!is_null($expression)) if(validate_expression($expression)) return FALSE;
$triggerid=get_dbid("triggers","triggerid");
@@ -306,7 +314,7 @@
return $result;
}
- add_alarm($triggerid,TRIGGER_VALUE_UNKNOWN);
+ add_event($triggerid,TRIGGER_VALUE_UNKNOWN);
$expression = implode_exp($expression,$triggerid);
@@ -378,7 +386,7 @@
$copy_mode ? 0 : $triggerid);
}
- $newtriggerid=dn_getid("triggers","triggerid");
+ $newtriggerid=get_dbid("triggers","triggerid");
$result = DBexecute("insert into triggers".
" (triggerid,description,priority,status,comments,url,value,expression,templateid)".
@@ -467,29 +475,29 @@
if($expression[$i] == '}')
{
$state='';
- $sql='select h.host,i.key_,f.function,f.parameter,i.itemid'.
+ if($function_data = DBfetch(DBselect('select h.host,i.key_,f.function,f.parameter,i.itemid,i.value_type'.
' from items i,functions f,hosts h'.
- ' where functionid='.$functionid.' and i.itemid=f.itemid and h.hostid=i.hostid';
-
- $res1=DBselect($sql);
- $row1=DBfetch($res1);
- if($html == 0)
- {
- $exp=$exp."{".$row1["host"].":".$row1["key_"].".".$row1["function"]."(".$row1["parameter"].")}";
- }
- else
+ ' where functionid='.$functionid.' and i.itemid=f.itemid and h.hostid=i.hostid')))
{
- $Link = new CLink($row1["host"].":".$row1["key_"]);
- $item=get_item_by_itemid($row1["itemid"]);
- if($item["value_type"] ==0)
+ if($html == 0)
{
- $Link->SetUrl('history.php?action=showgraph&itemid='.$row1['itemid']);
+ $exp .= "{".$function_data["host"].":".$function_data["key_"].".".
+ $function_data["function"]."(".$function_data["parameter"].")}";
}
else
{
- $Link->SetUrl('history.php?action=showvalues&period=3600&itemid='.$row1['itemid']);
+ $link = new CLink($function_data["host"].":".$function_data["key_"],
+ 'history.php?action='.( $function_data["value_type"] ==0 ? 'showvalues' : 'showgraph').
+ '&itemid='.$function_data['itemid']);
+
+ $exp .= $link->ToString().'.'.bold($function_data["function"].'(').$function_data["parameter"].bold(')');
}
- $exp .= $Link->ToString().'.'.bold($row1["function"].'(').$row1["parameter"].bold(')');
+ }
+ else
+ {
+ if($html == 1) $exp .= "<FONT COLOR=\"#AA0000\">";
+ $exp .= "*ERROR*";
+ if($html == 1) $exp .= "</FONT>";
}
continue;
}
@@ -540,14 +548,14 @@
$itemid=$row["itemid"];
- $res=DBexecute("insert into functions (itemid,triggerid,function,parameter)".
- " values ($itemid,$triggerid,".zbx_dbstr($function).",".
+ $functionid = get_dbid("functions","functionid");
+ $res=DBexecute("insert into functions (functionid,itemid,triggerid,function,parameter)".
+ " values ($functionid,$itemid,$triggerid,".zbx_dbstr($function).",".
zbx_dbstr($parameter).")");
if(!$res)
{
return $res;
}
- $functionid=DBinsert_id($res,"functions","functionid");
$exp=$exp.'{'.$functionid.'}';
@@ -617,12 +625,6 @@
function update_trigger_comments($triggerid,$comments)
{
- if(!check_right("Trigger comment","U",$triggerid))
- {
- error("Insufficient permissions");
- return 0;
- }
-
return DBexecute("update triggers set comments=".zbx_dbstr($comments).
" where triggerid=$triggerid");
}
@@ -638,40 +640,38 @@
update_trigger_status($db_chd_trigger["triggerid"],$status);
}
- if(!check_right_on_trigger("U",$triggerid))
- {
- error("Insufficient permissions");
- return 0;
- }
- add_alarm($triggerid,TRIGGER_VALUE_UNKNOWN);
+ add_event($triggerid,TRIGGER_VALUE_UNKNOWN);
return DBexecute("update triggers set status=$status where triggerid=$triggerid");
}
# "Processor load on {HOSTNAME} is 5" to "Processor load on www.sf.net is 5"
- function expand_trigger_description_simple($triggerid)
+ function expand_trigger_description_by_data($row)
{
- $result=DBselect("select distinct t.description,h.host".
- " from triggers t,functions f,items i,hosts h".
- " where t.triggerid=$triggerid and f.triggerid=t.triggerid".
- " and f.itemid=i.itemid and i.hostid=h.hostid");
-
-
- $row = DBfetch($result);
if($row)
{
+ if(is_null($row["host"])) $row["host"] = "{HOSTNAME}";
$description = str_replace("{HOSTNAME}", $row["host"],$row["description"]);
}
else
{
- $result = DBselect("select description from triggers where triggerid=$triggerid");
- $row = DBfetch($result);
- $description = $row["description"];
+ $description = "*ERROR*";
}
-
return $description;
}
+
+ function expand_trigger_description_simple($triggerid)
+ {
+ return expand_trigger_description_by_data(
+ DBfetch(
+ DBselect("select distinct t.description,h.host".
+ " from triggers t left join functions f on t.triggerid=f.triggerid ".
+ " left join items i on f.itemid=i.itemid ".
+ " left join hosts h on i.hostid=h.hostid ".
+ " where t.triggerid=$triggerid")
+ )
+ );
+ }
- # "Processor load on %s is 5" to "Processor load on www.sf.net is 5"
function expand_trigger_description($triggerid)
{
$description=expand_trigger_description_simple($triggerid);
@@ -689,27 +689,27 @@
$now = time();
while($row=DBfetch($result))
{
- if(!add_alarm($row["triggerid"],TRIGGER_VALUE_UNKNOWN,$now)) continue;
+ if(!add_event($row["triggerid"],TRIGGER_VALUE_UNKNOWN,$now)) continue;
DBexecute('update triggers set value='.TRIGGER_VALUE_UNKNOWN.' where triggerid='.$row["triggerid"]);
}
}
- function add_alarm($triggerid, $value, $time=NULL)
+ function add_event($triggerid, $value, $time=NULL)
{
if(is_null($time)) $time = time();
- $result = DBselect('select value from alarms where triggerid='.$triggerid.' order by clock desc',1);
+ $result = DBselect('select value from events where triggerid='.$triggerid.' order by clock desc',1);
$last_value = DBfetch($result);
if($last_value)
{
if($value == $last_value['value'])
return false;
}
- $result = DBexecute('insert into alarms(triggerid,clock,value) values('.$triggerid.','.$time.','.$value.')');
+ $eventid = get_dbid("events","eventid");
+ $result = DBexecute('insert into events(eventid,triggerid,clock,value) values('.$eventid.','.$triggerid.','.$time.','.$value.')');
if($value == TRIGGER_VALUE_FALSE || $value == TRIGGER_VALUE_TRUE)
{
- $alarm_id = DBinsert_id($result,'alarms','alarmid');
DBexesute('update alerts set retries=3,error=\'Trigger changed its status. WIll not send repeats.\''.
' where triggerid='.$triggerid.' and repeats>0 and status='.ALERT_STATUS_NOT_SENT);
}
@@ -750,7 +750,7 @@
$result=delete_function_by_triggerid($triggerid);
if(!$result) return $result;
- $result=delete_alarms_by_triggerid($triggerid);
+ $result=delete_events_by_triggerid($triggerid);
if(!$result) return $result;
$result=delete_services_by_triggerid($triggerid);
@@ -778,9 +778,6 @@
if($result)
{
- // delete trigger permisions
- DBexecute('delete from rights where name=\'Trigger comment\' and id='.$triggerid);
-
$msg = "Trigger '".$trigger["description"]."' deleted";
$trig_host = DBfetch($trig_hosts);
if($trig_host)
@@ -797,12 +794,6 @@
function update_trigger($triggerid,$expression=NULL,$description=NULL,$priority=NULL,$status=NULL,
$comments=NULL,$url=NULL,$deps=array(),$templateid=0)
{
- if(!check_right_on_trigger("U",$triggerid))
- {
- error("Insufficient permissions");
- return 0;
- }
-
$trigger = get_trigger_by_triggerid($triggerid);
$trig_hosts = get_hosts_by_triggerid($triggerid);
$trig_host = DBfetch($trig_hosts);
@@ -854,7 +845,7 @@
}
$expression = implode_exp($expression,$triggerid);
- add_alarm($triggerid,TRIGGER_VALUE_UNKNOWN);
+ add_event($triggerid,TRIGGER_VALUE_UNKNOWN);
reset_items_nextcheck($triggerid);
$sql="update triggers set";
@@ -889,14 +880,15 @@
return $result;
}
- function check_right_on_trigger($permission,$triggerid)
+ function check_right_on_trigger($permission,$triggerid) /* TODO */
{
+ /*
$result=DBselect("select distinct h.hostid from functions f,items i,hosts h".
" where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=$triggerid");
while($row=DBfetch($result))
if(check_right("Host",$permission,$row["hostid"]))
return 1;
-
+ */
return 0;
}
@@ -929,8 +921,9 @@
function insert_dependency($triggerid_down,$triggerid_up)
{
- $result=DBexecute("insert into trigger_depends (triggerid_down,triggerid_up)".
- " values ($triggerid_down,$triggerid_up)");
+ $triggerdepid = get_dbid("trigger_depends","triggerdepid");
+ $result=DBexecute("insert into trigger_depends (triggerdepid,triggerid_down,triggerid_up)".
+ " values ($triggerdepid,$triggerid_down,$triggerid_up)");
if(!$result)
{
return $result;
@@ -961,9 +954,9 @@
return DBexecute("delete from functions where triggerid=$triggerid");
}
- function delete_alarms_by_triggerid($triggerid)
+ function delete_events_by_triggerid($triggerid)
{
- return DBexecute("delete from alarms where triggerid=$triggerid");
+ return DBexecute("delete from events where triggerid=$triggerid");
}
function delete_triggers_by_itemid($itemid)
@@ -1067,8 +1060,10 @@
}
}
- function get_triggers_overview($groupid)
+ function get_triggers_overview($groupid, $nodeid)
{
+ global $USER_DETAILS;
+
$table = new CTableInfo(S_NO_TRIGGERS_DEFINED);
if($groupid > 0)
{
@@ -1077,18 +1072,21 @@
$group_where = ' where';
}
- $result=DBselect('select distinct t.description,t.value,t.lastchange,h.hostid,h.host'.
+ $result=DBselect('select distinct t.description,t.value,t.priority,t.lastchange,h.hostid,h.host'.
' from hosts h,items i,triggers t, functions f '.$group_where.
' h.status='.HOST_STATUS_MONITORED.' and h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid'.
- ' and t.status='.TRIGGER_STATUS_ENABLED.
+ ' and h.hostid in ('.get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, null, null, $nodeid).') '.
+ ' and t.status='.TRIGGER_STATUS_ENABLED.' and i.status='.ITEM_STATUS_ACTIVE.
' order by t.description');
unset($triggers);
unset($hosts);
while($row = DBfetch($result))
{
- if(!check_right('Host','R',$row['hostid'])) continue;
$hosts[$row['host']] = $row['host'];
- $triggers[$row['description']][$row['host']] = array('value' => $row['value'], 'lastchange' => $row['lastchange']);
+ $triggers[$row['description']][$row['host']] = array(
+ 'value' => $row['value'],
+ 'lastchange' => $row['lastchange'],
+ 'priority' => $row['priority']);
}
if(!isset($hosts))
{
@@ -1110,9 +1108,16 @@
$style = NULL;
if(isset($trhosts[$hostname]))
{
- if($trhosts[$hostname]['value'] == TRIGGER_VALUE_FALSE) $style = 'normal';
- elseif($trhosts[$hostname]['value'] == TRIGGER_VALUE_UNKNOWN) $style = 'unknown_trigger';
- else $style = 'high';
+ switch($trhosts[$hostname]['value'])
+ {
+ case TRIGGER_VALUE_TRUE:
+ $style = get_severity_style($trhosts[$hostname]['priority']);
+ break;
+ case TRIGGER_VALUE_FALSE:
+ $style = 'normal';
+ default:
+ $style = 'unknown_trigger';
+ }
if((time(NULL)-$trhosts[$hostname]['lastchange'])<300) $style .= '_blink1';
elseif((time(NULL)-$trhosts[$hostname]['lastchange'])<900) $style .= '_blink2';
@@ -1123,4 +1128,154 @@
}
return $table;
}
+
+ function get_function_by_functionid($functionid)
+ {
+ $result=DBselect("select * from functions where functionid=$functionid");
+ $row=DBfetch($result);
+ if($row)
+ {
+ return $row;
+ }
+ else
+ {
+ error("No function with functionid=[$functionid]");
+ }
+ return $item;
+ }
+
+ function calculate_availability($triggerid,$period_start,$period_end)
+ {
+ if(($period_start==0)&&($period_end==0))
+ {
+ $sql="select count(*) as cnt,min(clock) as minn,max(clock) as maxx from events where triggerid=$triggerid";
+ }
+ else
+ {
+ $sql="select count(*) as cnt,min(clock) as minn,max(clock) as maxx from events where triggerid=$triggerid and clock>=$period_start and clock<=$period_end";
+ }
+
+ $row=DBfetch(DBselect($sql));
+ if($row["cnt"]>0)
+ {
+ $min=$row["minn"];
+ $max=$row["maxx"];
+ }
+ else
+ {
+ if(($period_start==0)&&($period_end==0))
+ {
+ $max=time();
+ $min=$max-24*3600;
+ }
+ else
+ {
+ $ret["true_time"] = 0;
+ $ret["false_time"] = 0;
+ $ret["unknown_time"] = 0;
+ $ret["true"] = 0;
+ $ret["false"] = 0;
+ $ret["unknown"] = 100;
+ return $ret;
+ }
+ }
+
+ $result=DBselect("select clock,value from events where triggerid=$triggerid and clock>=$min and clock<=$max");
+
+ $state = -1;
+ $true_time = 0;
+ $false_time = 0;
+ $unknown_time = 0;
+ $time = $min;
+
+ if(($period_start==0)&&($period_end==0))
+ {
+ $max=time();
+ }
+ $rows=0;
+ while($row=DBfetch($result))
+ {
+ $clock=$row["clock"];
+ $value=$row["value"];
+
+ $diff=$clock-$time;
+
+ $time=$clock;
+
+ if($state==-1)
+ {
+ $state=$value;
+ if($state == 0)
+ {
+ $false_time+=$diff;
+ }
+ if($state == 1)
+ {
+ $true_time+=$diff;
+ }
+ if($state == 2)
+ {
+ $unknown_time+=$diff;
+ }
+ }
+ else if($state==0)
+ {
+ $false_time+=$diff;
+ $state=$value;
+ }
+ else if($state==1)
+ {
+ $true_time+=$diff;
+ $state=$value;
+ }
+ else if($state==2)
+ {
+ $unknown_time+=$diff;
+ $state=$value;
+ }
+ $rows++;
+ }
+
+ if($rows==0)
+ {
+ $trigger = get_trigger_by_triggerid($triggerid);
+ $state = $trigger['value'];
+ }
+
+ if($state==0)
+ {
+ $false_time=$false_time+$max-$time;
+ }
+ elseif($state==1)
+ {
+ $true_time=$true_time+$max-$time;
+ }
+ elseif($state==3)
+ {
+ $unknown_time=$unknown_time+$max-$time;
+ }
+
+ $total_time=$true_time+$false_time+$unknown_time;
+
+ if($total_time==0)
+ {
+ $ret["true_time"] = 0;
+ $ret["false_time"] = 0;
+ $ret["unknown_time"] = 0;
+ $ret["true"] = 0;
+ $ret["false"] = 0;
+ $ret["unknown"] = 100;
+ }
+ else
+ {
+ $ret["true_time"] = $true_time;
+ $ret["false_time"] = $false_time;
+ $ret["unknown_time"] = $unknown_time;
+ $ret["true"] = (100*$true_time)/$total_time;
+ $ret["false"] = (100*$false_time)/$total_time;
+ $ret["unknown"] = (100*$unknown_time)/$total_time;
+ }
+ return $ret;
+ }
+
?>
diff --git a/frontends/php/include/users.inc.php b/frontends/php/include/users.inc.php
index 0bdb19a6..5c57c1d5 100644
--- a/frontends/php/include/users.inc.php
+++ b/frontends/php/include/users.inc.php
@@ -19,69 +19,121 @@
**/
?>
<?php
+ function user_type2str($user_type_int)
+ {
+ $str_user_type[USER_TYPE_ZABBIX_USER] = S_ZABBIX_USER;
+ $str_user_type[USER_TYPE_ZABBIX_ADMIN] = S_ZABBIX_ADMIN;
+ $str_user_type[USER_TYPE_SUPPER_ADMIN] = S_SUPPER_ADMIN;
+
+ if(isset($str_user_type[$user_type_int]))
+ return $str_user_type[$user_type_int];
+
+ return S_UNCNOWN;
+ }
+
# Add User definition
- function add_user($name,$surname,$alias,$passwd,$url,$autologout,$lang,$refresh)
+ function add_user($name,$surname,$alias,$passwd,$url,$autologout,$lang,$refresh,$user_type,$user_groups,$user_medias)
{
- if(!check_right("User","A",0))
+ global $USER_DETAILS;
+ global $ZBX_CURNODEID;
+
+ if($USER_DETAILS['type'] != USER_TYPE_SUPPER_ADMIN)
{
error("Insufficient permissions");
return 0;
}
+SDI('pass: '.$passwd);
+SDI('groups: '.$user_groups);
- if($alias==""){
- error("Incorrect Alias name");
+ if(DBfetch(DBexecute("select * from users where alias=".zbx_dbstr($alias)." and ".DBid2nodeid('userid')."=".$ZBX_CURNODEID)))
+ {
+ error('User "'.$alias.'" already exists');
return 0;
}
- $sql="select * from users where alias=".zbx_dbstr($alias);
- $result=DBexecute($sql);
- if(DBfetch($result))
+ $userid = get_dbid("users","userid");
+
+ $result = DBexecute('insert into users (userid,name,surname,alias,passwd,url,autologout,lang,refresh,type)'.
+ ' values ('.$userid.','.zbx_dbstr($name).','.zbx_dbstr($surname).','.zbx_dbstr($alias).','.
+ zbx_dbstr(md5($passwd)).','.zbx_dbstr($url).','.$autologout.','.zbx_dbstr($lang).','.$refresh.','.$user_type.')');
+
+ if($result)
{
- error("User '$alias' already exists");
- return 0;
+ DBexecute('delete from users_groups where userid='.$userid);
+ foreach($user_groups as $groupid => $grou_pname)
+ {
+ $users_groups_id = get_dbid("users_groups","id");
+ $result = DBexecute('insert into users_groups (id,usrgrpid,userid)'.
+ 'values('.$users_groups_id.','.$groupid.','.$userid.')');
+
+ if($result == false) break;
+ }
+ if($result)
+ {
+ DBexecute('delete from media where userid='.$userid);
+ foreach($user_medias as $mediaid => $media_data)
+ {
+ $mediaid = get_dbid("media","mediaid");
+ $result = DBexecute('insert into media (mediaid,userid,mediatypeid,sendto,active,severity,period)'.
+ ' values ('.$mediaid.','.$userid.','.$media_data['mediatypeid'].','.
+ zbx_dbstr($media_data['sendto']).','.$media_data['active'].','.$media_data['severity'].','.
+ zbx_dbstr($media_data['period']).')');
+
+ if($result == false) break;
+ }
+ }
}
-
- $passwd=md5($passwd);
- $userid = get_dbid("users","userid");
- $sql="insert into users (userid,name,surname,alias,passwd,url,autologout,lang,refresh) values ($userid,".zbx_dbstr($name).",".zbx_dbstr($surname).",".zbx_dbstr($alias).",".zbx_dbstr($passwd).",".zbx_dbstr($url).",$autologout,".zbx_dbstr($lang).",$refresh)";
- DBexecute($sql);
- return $userid;
+
+ return $result;
}
# Update User definition
- function update_user($userid,$name,$surname,$alias,$passwd, $url,$autologout,$lang,$refresh)
+ function update_user($userid,$name,$surname,$alias,$passwd, $url,$autologout,$lang,$refresh,$user_type,$user_groups,$user_medias)
{
- if(!check_right("User","U",$userid))
- {
- error("Insufficient permissions");
- return 0;
- }
-
- if($alias==""){
- error("incorrect alias name");
- return 0;
- }
+ global $ZBX_CURNODEID;
- $sql="select * from users where alias=".zbx_dbstr($alias)." and userid<>$userid";
- $result=DBexecute($sql);
- if(DBfetch($result))
+ if(DBfetch(DBexecute("select * from users where alias=".zbx_dbstr($alias).
+ " and userid<>$userid and ".DBid2nodeid('userid')."=".$ZBX_CURNODEID)))
{
error("User '$alias' already exists");
return 0;
}
-
- if($passwd=="")
- {
- $sql="update users set name=".zbx_dbstr($name).",surname=".zbx_dbstr($surname).",alias=".zbx_dbstr($alias).",url=".zbx_dbstr($url).",autologout=$autologout,lang=".zbx_dbstr($lang).",refresh=$refresh where userid=$userid";
- }
- else
+
+ $result = DBexecute("update users set name=".zbx_dbstr($name).",surname=".zbx_dbstr($surname).","."alias=".zbx_dbstr($alias).
+ (isset($passwd) ? (',passwd='.zbx_dbstr(md5($passwd))) : '').
+ ",url=".zbx_dbstr($url).","."autologout=$autologout,lang=".zbx_dbstr($lang).",refresh=$refresh,".
+ "type=$user_type where userid=$userid");
+
+ if($result)
{
- $passwd=md5($passwd);
- $sql="update users set name=".zbx_dbstr($name).",surname=".zbx_dbstr($surname).",alias=".zbx_dbstr($alias).",passwd=".zbx_dbstr($passwd).",url=".zbx_dbstr($url).",autologout=$autologout,lang=".zbx_dbstr($lang).",refresh=$refresh where userid=$userid";
+ DBexecute('delete from users_groups where userid='.$userid);
+ foreach($user_groups as $groupid => $grou_pname)
+ {
+ $users_groups_id = get_dbid("users_groups","id");
+ $result = DBexecute('insert into users_groups (id,usrgrpid,userid)'.
+ 'values('.$users_groups_id.','.$groupid.','.$userid.')');
+
+ if($result == false) break;
+ }
+ if($result)
+ {
+ DBexecute('delete from media where userid='.$userid);
+ foreach($user_medias as $mediaid => $media_data)
+ {
+ $mediaid = get_dbid("media","mediaid");
+ $result = DBexecute('insert into media (mediaid,userid,mediatypeid,sendto,active,severity,period)'.
+ ' values ('.$mediaid.','.$userid.','.$media_data['mediatypeid'].','.
+ zbx_dbstr($media_data['sendto']).','.$media_data['active'].','.$media_data['severity'].','.
+ zbx_dbstr($media_data['period']).')');
+
+ if($result == false) break;
+ }
+ }
}
- return DBexecute($sql);
+
+ return $result;
}
# Update User Profile
@@ -92,71 +144,65 @@
if($userid!=$USER_DETAILS["userid"])
{
- error("Insufficient permissions");
- return 0;
+ access_deny();
}
- if($passwd=="")
- {
- $sql="update users set url=".zbx_dbstr($url).",autologout=$autologout,lang=".zbx_dbstr($lang).",refresh=$refresh where userid=$userid";
- }
- else
- {
- $passwd=md5($passwd);
- $sql="update users set passwd=".zbx_dbstr($passwd).",url=".zbx_dbstr($url).",autologout=$autologout,lang=".zbx_dbstr($lang).",refresh=$refresh where userid=$userid";
- }
- return DBexecute($sql);
+ return DBexecute("update users set url=".zbx_dbstr($url).",autologout=$autologout,lang=".zbx_dbstr($lang).
+ (isset($passwd) ? (',passwd='.zbx_dbstr(md5($passwd))) : '').
+ ",refresh=$refresh where userid=$userid");
}
- # Add permission
+ # Delete User definition
- function add_permission($userid,$right,$permission,$id)
+ function delete_user($userid)
{
- $sql="insert into rights (userid,name,permission,id) values ($userid,".zbx_dbstr($right).",".zbx_dbstr($permission).",$id)";
- return DBexecute($sql);
- }
- function get_usergroup_by_groupid($groupid)
- {
- $result=DBselect("select * from usrgrp where usrgrpid=".$groupid);
- $row=DBfetch($result);
- if($row)
+ if(DBfetch(DBselect('select * from users where userid='.$userid.' and alias=\'guest\'')))
{
- return $row;
+ error("Cannot delete user 'guest'");
+ return false;
}
- error("No user groups with usrgrpid=[$groupid]");
- return FALSE;
+
+ while($row=DBfetch(DBexecute('select actionid from actions where userid='.$userid)))
+ {
+ $result = delete_action($row["actionid"]);
+ if(!$result) return $result;
+ }
+
+ $result = DBexecute('delete from media where userid='.$userid);
+ if(!$result) return $result;
+
+ $result = DBexecute('delete from profiles where userid='.$userid);
+ if(!$result) return $result;
+
+ $result = DBexecute('delete from users_groups where userid='.$userid);
+ if(!$result) return $result;
+
+ $result = DBexecute('delete from users where userid='.$userid);
+
+ return $result;
}
+
function get_user_by_userid($userid)
{
- $sql="select * from users where userid=$userid";
- $result=DBselect($sql);
- $row=DBfetch($result);
- if($row)
+ if($row = DBfetch(DBselect("select * from users where userid=$userid")))
{
return $row;
}
- error("No user with itemid=[$userid]");
+ error("No user with id [$userid]");
return false;
}
- function add_user_group($name,$users=array())
+/**************************
+ USER GROUPS
+**************************/
+
+ function add_user_group($name,$users=array(),$rights=array())
{
- if(!check_right("Host","A",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
- if($name==""){
- error("Incorrect group name");
- return 0;
- }
+ global $ZBX_CURNODEID;
- $sql="select * from usrgrp where name=".zbx_dbstr($name);
- $result=DBexecute($sql);
- if(DBfetch($result))
+ if(DBfetch(DBexecute("select * from usrgrp where name=".zbx_dbstr($name)." and ".DBid2nodeid('usrgrpid')."=".$ZBX_CURNODEID)))
{
error("Group '$name' already exists");
return 0;
@@ -164,70 +210,85 @@
$usrgrpid=get_dbid("usrgrp","usrgrpid");
- $sql="insert into usrgrp (usrgrpid,name) values ($usrgrpid,".zbx_dbstr($name).")";
- $result=DBexecute($sql);
- if(!$result)
+ $result=DBexecute("insert into usrgrp (usrgrpid,name) values ($usrgrpid,".zbx_dbstr($name).")");
+ if(!$result) return $result;
+
+ $result=DBexecute("delete from users_groups where usrgrpid=".$usrgrpid);
+ foreach($users as $userid => $name)
{
- return $result;
+ $id = get_dbid('users_groups','id');
+ $result=DBexecute('insert into users_groups (id,usrgrpid,userid) values ('.$id.','.$usrgrpid.','.$userid.')');
+ if(!$result) return $result;
+ }
+
+ $result=DBexecute("delete from rights where groupid=".$usrgrpid);
+ foreach($rights as $right)
+ {
+ $id = get_dbid('rights','rightid');
+ $result=DBexecute('insert into rights (rightid,groupid,type,permission,id)'.
+ ' values ('.$id.','.$usrgrpid.','.$right['type'].','.$right['permission'].','.$right['id'].')');
+ if(!$result) return $result;
}
-
- update_user_groups($usrgrpid,$users);
return $result;
}
- function update_user_group($usrgrpid,$name,$users=array())
+ function update_user_group($usrgrpid,$name,$users=array(),$rights=array())
{
- if(!check_right("Host","U",0))
- {
- error("Insufficient permissions");
- return 0;
- }
-
- if($name==""){
- error("Incorrect group name");
- return 0;
- }
+ global $ZBX_CURNODEID;
- $sql="select * from usrgrp where name=".zbx_dbstr($name)." and usrgrpid<>$usrgrpid";
- $result=DBexecute($sql);
- if(DBfetch($result))
+ if(DBfetch(DBexecute("select * from usrgrp where name=".zbx_dbstr($name).
+ " and usrgrpid<>".$usrgrpid." and ".DBid2nodeid('usrgrpid')."=".$ZBX_CURNODEID)))
{
error("Group '$name' already exists");
return 0;
}
- $sql="update usrgrp set name=".zbx_dbstr($name)." where usrgrpid=$usrgrpid";
- $result=DBexecute($sql);
+ $result=DBexecute("update usrgrp set name=".zbx_dbstr($name)." where usrgrpid=$usrgrpid");
if(!$result)
{
return $result;
}
- update_user_groups($usrgrpid,$users);
+ $result=DBexecute("delete from users_groups where usrgrpid=".$usrgrpid);
+ foreach($users as $userid => $name)
+ {
+ $id = get_dbid('users_groups','id');
+ $result=DBexecute('insert into users_groups (id,usrgrpid,userid) values ('.$id.','.$usrgrpid.','.$userid.')');
+ if(!$result) return $result;
+ }
+
+ $result=DBexecute("delete from rights where groupid=".$usrgrpid);
+ foreach($rights as $right)
+ {
+ $id = get_dbid('rights','rightid');
+ $result=DBexecute('insert into rights (rightid,groupid,type,permission,id)'.
+ ' values ('.$id.','.$usrgrpid.','.$right['type'].','.$right['permission'].','.$right['id'].')');
+ if(!$result) return $result;
+ }
return $result;
}
function delete_user_group($usrgrpid)
{
- $sql="delete from users_groups where usrgrpid=$usrgrpid";
- DBexecute($sql);
- $sql="delete from usrgrp where usrgrpid=$usrgrpid";
- return DBexecute($sql);
- }
+ $result = DBexecute("delete from rights where groupid=$usrgrpid");
+ if(!$result) return $result;
- function update_user_groups($usrgrpid,$users=array())
- {
- $count=count($users);
+ $result = DBexecute("delete from users_groups where usrgrpid=$usrgrpid");
+ if(!$result) return $result;
- $sql="delete from users_groups where usrgrpid=$usrgrpid";
- DBexecute($sql);
+ $result = DBexecute("delete from usrgrp where usrgrpid=$usrgrpid");
+ return $result;
+ }
- for($i=0;$i<$count;$i++)
+ function get_group_by_usrgrpid($usrgrpid)
+ {
+ if($row = DBfetch(DBselect("select * from usrgrp where usrgrpid=".$usrgrpid)))
{
- $sql="insert into users_groups (usrgrpid,userid) values ($usrgrpid,".$users[$i].")";
- DBexecute($sql);
+ return $row;
}
+ error("No user groups with id [$usrgrpid]");
+ return FALSE;
}
?>
diff --git a/frontends/php/include/validate.inc.php b/frontends/php/include/validate.inc.php
index 39581101..dba4ffae 100644
--- a/frontends/php/include/validate.inc.php
+++ b/frontends/php/include/validate.inc.php
@@ -19,9 +19,9 @@
**/
?>
<?php
- function unset_request($key)
+ function unset_request($key,$requester='unknown')
{
-// SDI("unset: $key");
+// SDI("unset [".$requester."]: $key");
unset($_REQUEST[$key]);
}
@@ -49,7 +49,7 @@
}
define("NOT_EMPTY","({}!='')&&");
- define("DB_ID","({}>=0&&{}<=4294967295)&&");
+ define("DB_ID","({}>=0&&{}<=10000000000000000000)&&");
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
@@ -108,7 +108,7 @@
{
if(!isset($fields[$key]))
{
- unset_request($key);
+ unset_request($key,'unset_not_in_list');
}
}
}
@@ -119,9 +119,9 @@
{
list($type,$opt,$flags,$validation,$exception)=$checks;
- if(($flags&P_NZERO)&&(isset($_REQUEST[$field]))&&($_REQUEST[$field]==0))
+ if(($flags&P_NZERO)&&(isset($_REQUEST[$field]))&&(is_numeric($_REQUEST[$field]))&&($_REQUEST[$field]==0))
{
- unset_request($field);
+ unset_request($field,'unset_if_zero');
}
}
}
@@ -135,7 +135,7 @@
if(($flags&P_ACT)&&(isset($_REQUEST[$field])))
{
- unset_request($field);
+ unset_request($field,'unset_action_vars');
}
}
}
@@ -144,7 +144,7 @@
{
foreach($_REQUEST as $key => $val)
{
- unset_request($key);
+ unset_request($key,'unset_all');
}
}
@@ -250,7 +250,7 @@
if(!isset($_REQUEST[$field]))
return ZBX_VALID_OK;
- unset_request($field);
+ unset_request($field,'O_NO');
if($flags&P_SYS)
{
@@ -300,9 +300,17 @@
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
$system_fields=array(
"sessionid"=> array(T_ZBX_STR, O_OPT, P_SYS, HEX(),NULL),
+ "switch_node"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID,NULL),
"triggers_hash"=> array(T_ZBX_STR, O_OPT, P_SYS, NOT_EMPTY,NULL)
);
+ function invalid_url()
+ {
+ unset_all();
+ show_error_message(S_INVALID_URL);
+ include_once "include/page_footer.php";
+ }
+
function check_fields(&$fields)
{
@@ -320,18 +328,20 @@
unset_not_in_list($fields);
unset_if_zero($fields);
- if($err&ZBX_VALID_ERROR)
- {
- unset_all();
- show_messages(FALSE, "", "Invalid URL");
- show_page_footer();
- exit;
- }
if($err!=ZBX_VALID_OK)
{
unset_action_vars($fields);
}
- show_infomsg();
+
+ $fields = null;
+
+ if($err&ZBX_VALID_ERROR)
+ {
+ invalid_url();
+ }
+
+ show_messages();
+
return ($err==ZBX_VALID_OK ? 1 : 0);
}
?>