diff options
author | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-04-03 14:24:48 +0000 |
---|---|---|
committer | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-04-03 14:24:48 +0000 |
commit | 4f6849b38d72481080471bb1842860f93fa86a88 (patch) | |
tree | 162e37b3aa9edaf69e24d83f81c84b8be137841e /frontends/php/include | |
parent | 33d9602f430db48458034a24ad72a5c6b25dfe22 (diff) | |
download | zabbix-4f6849b38d72481080471bb1842860f93fa86a88.tar.gz zabbix-4f6849b38d72481080471bb1842860f93fa86a88.tar.xz zabbix-4f6849b38d72481080471bb1842860f93fa86a88.zip |
- improvements in permission check for triggers (Artem)
git-svn-id: svn://svn.zabbix.com/trunk@5588 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
-rw-r--r-- | frontends/php/include/actions.inc.php | 19 | ||||
-rw-r--r-- | frontends/php/include/blocks.inc.php | 102 | ||||
-rw-r--r-- | frontends/php/include/classes/ctree.inc.php | 2 | ||||
-rw-r--r-- | frontends/php/include/graphs.inc.php | 18 | ||||
-rw-r--r-- | frontends/php/include/triggers.inc.php | 66 |
5 files changed, 125 insertions, 82 deletions
diff --git a/frontends/php/include/actions.inc.php b/frontends/php/include/actions.inc.php index fa7ed31b..80859009 100644 --- a/frontends/php/include/actions.inc.php +++ b/frontends/php/include/actions.inc.php @@ -819,20 +819,12 @@ include_once 'include/discovery.inc.php'; } $sendto=$row["sendto"]; - $pre = new CTag('pre','yes'); - $pre->AddItem(array(bold(S_SUBJECT.': '),$row["subject"])); - $subject = empty($row["subject"]) ? '' : $pre; - - $pre = new CTag('pre','yes'); - $pre->AddItem($row["message"]); - $message = array($subject, $pre); + $message = array(bold(S_SUBJECT.': '),br(),$row["subject"],br(),br(),bold(S_MESSAGE.': '),br(),$row['message']); - if($row["error"] == "") - { + if(empty($row["error"])){ $error=new CSpan(SPACE,"off"); } - else - { + else{ $error=new CSpan($row["error"],"on"); } $table->AddRow(array( @@ -843,7 +835,7 @@ include_once 'include/discovery.inc.php'; new CCol($retries, 'top'), new CCol($sendto, 'top'), new CCol($message, 'top'), - new CCol($error, 'top'))); + new CCol($error, 'wraptext top'))); $col++; } @@ -899,12 +891,13 @@ function get_actions_for_event($eventid){ $message = array(bold(S_SUBJECT.': '),br(),$row["subject"],br(),br(),bold(S_MESSAGE.': '),br(),$row['message']); - if($row["error"] == ""){ + if(empty($row["error"])){ $error=new CSpan(SPACE,"off"); } else{ $error=new CSpan($row["error"],"on"); } + $table->AddRow(array( get_node_name_by_elid($row['alertid']), new CCol($time, 'top'), diff --git a/frontends/php/include/blocks.inc.php b/frontends/php/include/blocks.inc.php index f6071658..bc676c20 100644 --- a/frontends/php/include/blocks.inc.php +++ b/frontends/php/include/blocks.inc.php @@ -25,15 +25,9 @@ require_once "include/maps.inc.php"; // Author: Aly -function make_favorite_graphs($available_hosts=false){ - global $USER_DETAILS; - - if(!$available_hosts){ - $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, null, null, get_current_nodeid()); - } - +function make_favorite_graphs(){ $table = new CTableInfo(); - + $fav_graphs = get4favorites('web.favorite.graphids'); foreach($fav_graphs['id'] as $key => $resourceid){ @@ -166,13 +160,12 @@ return $table; } // Author: Aly -function make_system_summary($available_hosts=false){ +function make_system_summary(){ global $USER_DETAILS; $config=select_config(); - if(!$available_hosts){ - $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, null, null, get_current_nodeid()); - } + $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, null, null, get_current_nodeid()); + $available_triggers = get_accessible_triggers(PERM_READ_LIST, null, get_current_nodeid()); $table = new CTableInfo(); $table->SetHeader(array( @@ -257,7 +250,7 @@ function make_system_summary($available_hosts=false){ ' AND hg.hostid=h.hostid '. ' AND t.triggerid=f.triggerid AND t.status='.TRIGGER_STATUS_ENABLED. ' AND i.status='.ITEM_STATUS_ACTIVE.' AND '.DBin_node('t.triggerid'). - ' AND h.hostid in ('.$available_hosts.') '. + ' AND t.triggerid IN ('.$available_triggers.') '. ' AND h.status='.HOST_STATUS_MONITORED. ' AND t.value='.TRIGGER_VALUE_TRUE. ' AND t.priority='.$key. @@ -296,12 +289,11 @@ function make_system_summary($available_hosts=false){ $actions= new CTable(' - '); $sql='SELECT COUNT(a.alertid) as cnt'. - ' FROM alerts a,functions f,items i,events e'. + ' FROM alerts a,events e'. ' WHERE a.eventid='.$row_inf_event['eventid']. ' AND e.eventid = a.eventid'. - ' AND f.triggerid=e.objectid '. - ' AND i.itemid=f.itemid '. - ' AND i.hostid IN ('.$available_hosts.') '; + ' AND e.object='.EVENT_OBJECT_TRIGGER. + ' AND e.objectid IN ('.$available_triggers.') '; $alerts=DBfetch(DBselect($sql)); @@ -309,38 +301,35 @@ function make_system_summary($available_hosts=false){ $mixed = 0; // Sent $sql='SELECT COUNT(a.alertid) as sent '. - ' FROM alerts a,functions f,items i,events e'. + ' FROM alerts a,events e'. ' WHERE a.eventid='.$row_inf_event['eventid']. ' AND a.status='.ALERT_STATUS_SENT. ' AND e.eventid = a.eventid'. - ' AND f.triggerid=e.objectid '. - ' AND i.itemid=f.itemid '. - ' AND i.hostid IN ('.$available_hosts.') '; + ' AND e.object='.EVENT_OBJECT_TRIGGER. + ' AND e.objectid IN ('.$available_triggers.') '; $tmp=DBfetch(DBselect($sql)); $alerts['sent'] = $tmp['sent']; $mixed+=($alerts['sent'])?ALERT_STATUS_SENT:0; // In progress $sql='SELECT COUNT(a.alertid) as inprogress '. - ' FROM alerts a,functions f,items i,events e'. + ' FROM alerts a,events e'. ' WHERE a.eventid='.$row_inf_event['eventid']. ' AND a.status='.ALERT_STATUS_NOT_SENT. ' AND e.eventid = a.eventid'. - ' AND f.triggerid=e.objectid '. - ' AND i.itemid=f.itemid '. - ' AND i.hostid IN ('.$available_hosts.') '; + ' AND e.object='.EVENT_OBJECT_TRIGGER. + ' AND e.objectid IN ('.$available_triggers.') '; $tmp=DBfetch(DBselect($sql)); $alerts['inprogress'] = $tmp['inprogress']; // Failed $sql='SELECT COUNT(a.alertid) as failed '. - ' FROM alerts a,functions f,items i,events e'. + ' FROM alerts a,events e'. ' WHERE a.eventid='.$row_inf_event['eventid']. ' AND a.status='.ALERT_STATUS_FAILED. ' AND e.eventid = a.eventid'. - ' AND f.triggerid=e.objectid '. - ' AND i.itemid=f.itemid '. - ' AND i.hostid IN ('.$available_hosts.') '; + ' AND e.object='.EVENT_OBJECT_TRIGGER. + ' AND e.objectid IN ('.$available_triggers.') '; $tmp=DBfetch(DBselect($sql)); $alerts['failed'] = $tmp['failed']; @@ -506,12 +495,12 @@ return $table; } // author Aly -function make_latest_issues($available_hosts=false){ +function make_latest_issues(){ global $USER_DETAILS; - if(!$available_hosts){ - $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, null, null, get_current_nodeid()); - } + $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, null, null, get_current_nodeid()); + $available_triggers = get_accessible_triggers(PERM_READ_LIST, null, get_current_nodeid()); + $scripts_by_hosts = get_accessible_scripts_by_hosts(explode(',',$available_hosts)); $config=select_config(); @@ -533,7 +522,7 @@ function make_latest_issues($available_hosts=false){ ' AND hg.hostid=h.hostid '. ' AND t.triggerid=f.triggerid AND t.status='.TRIGGER_STATUS_ENABLED. ' AND i.status='.ITEM_STATUS_ACTIVE.' AND '.DBin_node('t.triggerid'). - ' AND h.hostid in ('.$available_hosts.') '. + ' AND t.triggerid IN ('.$available_triggers.') '. ' AND h.status='.HOST_STATUS_MONITORED. ' AND t.value='.TRIGGER_VALUE_TRUE. ' ORDER BY t.lastchange DESC'; @@ -589,24 +578,24 @@ function make_latest_issues($available_hosts=false){ $actions= new CTable(' - '); $sql='SELECT COUNT(a.alertid) as cnt '. - ' FROM alerts a,functions f,items i,events e'. + ' FROM alerts a,events e'. ' WHERE a.eventid='.$row_event['eventid']. ' AND e.eventid = a.eventid'. - ' AND f.triggerid=e.objectid '. - ' AND i.itemid=f.itemid '. - ' AND i.hostid IN ('.$available_hosts.') '; + ' AND e.object='.EVENT_OBJECT_TRIGGER. + ' AND e.objectid IN ('.$available_triggers.') '; + $alerts=DBfetch(DBselect($sql)); if(isset($alerts['cnt']) && ($alerts['cnt'] > 0)){ $sql='SELECT COUNT(a.alertid) as sent '. - ' FROM alerts a,functions f,items i,events e'. + ' FROM alerts a,events e'. ' WHERE a.eventid='.$row_event['eventid']. ' AND a.status='.ALERT_STATUS_SENT. ' AND e.eventid = a.eventid'. - ' AND f.triggerid=e.objectid '. - ' AND i.itemid=f.itemid '. - ' AND i.hostid IN ('.$available_hosts.') '; + ' AND e.object='.EVENT_OBJECT_TRIGGER. + ' AND e.objectid IN ('.$available_triggers.') '; + $alerts=DBfetch(DBselect($sql)); $alert_cnt = new CSpan($alerts['sent'],'green'); @@ -618,13 +607,13 @@ function make_latest_issues($available_hosts=false){ $tdl->AddOption('width','10'); $sql='SELECT COUNT(a.alertid) as inprogress '. - ' FROM alerts a,functions f,items i,events e'. + ' FROM alerts a,events e'. ' WHERE a.eventid='.$row_event['eventid']. ' AND a.status='.ALERT_STATUS_NOT_SENT. ' AND e.eventid = a.eventid'. - ' AND f.triggerid=e.objectid '. - ' AND i.itemid=f.itemid '. - ' AND i.hostid IN ('.$available_hosts.') '; + ' AND e.object='.EVENT_OBJECT_TRIGGER. + ' AND e.objectid IN ('.$available_triggers.') '; + $alerts=DBfetch(DBselect($sql)); $alert_cnt = new CSpan($alerts['inprogress'],'orange'); @@ -636,13 +625,13 @@ function make_latest_issues($available_hosts=false){ $tdc->AddOption('width','10'); $sql='SELECT COUNT(a.alertid) as failed '. - ' FROM alerts a,functions f,items i,events e'. + ' FROM alerts a,events e'. ' WHERE a.eventid='.$row_event['eventid']. ' AND a.status='.ALERT_STATUS_FAILED. ' AND e.eventid = a.eventid'. - ' AND f.triggerid=e.objectid '. - ' AND i.itemid=f.itemid '. - ' AND i.hostid IN ('.$available_hosts.') '; + ' AND e.object='.EVENT_OBJECT_TRIGGER. + ' AND e.objectid IN ('.$available_triggers.') '; + $alerts=DBfetch(DBselect($sql)); $alert_cnt = new CSpan($alerts['failed'],'red'); @@ -677,13 +666,10 @@ return $table; } // author Aly -function make_webmon_overview($available_hosts=false){ +function make_webmon_overview(){ global $USER_DETAILS; - if(!$available_hosts){ - $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, null, null, get_current_nodeid()); - } - + $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, null, null, get_current_nodeid()); $table = new CTableInfo(); $table->SetHeader(array( @@ -753,12 +739,10 @@ function make_webmon_overview($available_hosts=false){ return $table; } -function make_latest_data($available_hosts=false){ +function make_latest_data(){ global $USER_DETAILS; - if(!$available_hosts){ - $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, null, null, get_current_nodeid()); - } + $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, null, null, get_current_nodeid()); while($db_app = DBfetch($db_applications)){ $db_items = DBselect('SELECT DISTINCT i.* '. diff --git a/frontends/php/include/classes/ctree.inc.php b/frontends/php/include/classes/ctree.inc.php index 3d07609a..369f5cde 100644 --- a/frontends/php/include/classes/ctree.inc.php +++ b/frontends/php/include/classes/ctree.inc.php @@ -104,7 +104,7 @@ var $maxlevel=0; $tr = $this->MakeSImgStr($id); $td = new CCol($this->tree[$id]['caption']); - $td->AddOption('style','height: 20px; padding-right: 10px; padding-left: 2px;'); + $td->AddOption('style',' white-space: normal; height: 20px; padding-right: 10px; padding-left: 2px;'); $tr->AddItem($td); $table->AddRow($tr); diff --git a/frontends/php/include/graphs.inc.php b/frontends/php/include/graphs.inc.php index 265d3614..d42a687d 100644 --- a/frontends/php/include/graphs.inc.php +++ b/frontends/php/include/graphs.inc.php @@ -200,7 +200,7 @@ $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, $perm, null, null, $nodeid); $denied_graphs = array(); - $available_graphs = array(); + $result = array(); $sql = 'SELECT DISTINCT g.graphid '. ' FROM graphs as g, graphs_items as gi, items as i '. @@ -209,8 +209,8 @@ ' AND i.itemid=gi.itemid '. ' AND i.hostid NOT IN ('.$available_hosts.')'; - $result = DBselect($sql); - while($graph = DBfetch($result)){ + $db_graphs = DBselect($sql); + while($graph = DBfetch($db_graphs)){ $denied_graphs[] = $graph['graphid']; } @@ -222,19 +222,19 @@ ' AND i.status='.ITEM_STATUS_ACTIVE. (!empty($denied_graphs)?' AND g.graphid NOT IN ('.implode(',',$denied_graphs).')':''); - $result = DBselect($sql); - while($graph = DBfetch($result)){ - $available_graphs[$graph['graphid']] = $graph['graphid']; + $db_graphs = DBselect($sql); + while($graph = DBfetch($db_graphs)){ + $result[$graph['graphid']] = $graph['graphid']; } if(PERM_RES_STRING_LINE == $perm_res){ if(count($result) == 0) - $available_graphs = '-1'; + $result = '-1'; else - $available_graphs = implode(',',$available_graphs); + $result = implode(',',$result); } - return $available_graphs; + return $result; } /* diff --git a/frontends/php/include/triggers.inc.php b/frontends/php/include/triggers.inc.php index dc976c86..1db8ad74 100644 --- a/frontends/php/include/triggers.inc.php +++ b/frontends/php/include/triggers.inc.php @@ -172,6 +172,72 @@ } INIT_TRIGGER_EXPRESSION_STRUCTURES(); + +/* + * Function: get_accessible_triggers + * + * Description: + * returns string of accessible triggers + * + * Author: + * Aly + * + */ + function get_accessible_triggers($perm,$perm_res=null,$nodeid=null,$hostid=null,$cache=1){ + global $USER_DETAILS; + static $available_triggers; + + $result = array(); + + if(is_null($perm_res)) $perm_res = PERM_RES_STRING_LINE; + $nodeid_str =(is_array($nodeid))?implode('',$nodeid):strval($nodeid); + $hostid_str =(is_array($hostid))?implode('',$hostid):strval($hostid); + + if($cache && isset($available_triggers[$perm][$perm_res][$nodeid_str][$hostid_str])){ + return $available_triggers[$perm][$perm_res][$nodeid_str][$hostid_str]; + } + + $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, $perm, null, null, $nodeid); + + $denied_graphs = array(); + $available_graphs = array(); + + $sql = 'SELECT DISTINCT t.triggerid '. + ' FROM triggers t, functions f, items as i '. + ' WHERE t.triggerid=f.triggerid '. + ' AND f.itemid=i.itemid'. + (!empty($hostid)?' AND i.hostid='.$hostid:''). + ' AND i.hostid NOT IN ('.$available_hosts.')'; + + $db_triggers = DBselect($sql); + while($trigger = DBfetch($db_triggers)){ + $denied_triggers[] = $trigger['triggerid']; + } + + $sql = 'SELECT DISTINCT t.triggerid '. + ' FROM triggers t, functions f, items as i '. + ' WHERE t.triggerid=f.triggerid '. + ' AND f.itemid=i.itemid'. + ' AND i.status='.ITEM_STATUS_ACTIVE. + (!empty($hostid)?' AND i.hostid='.$hostid:''). + (!empty($denied_triggers)?' AND t.triggerid NOT IN ('.implode(',',$denied_triggers).')':''); + + $db_triggers = DBselect($sql); + while($trigger = DBfetch($db_triggers)){ + $result[$trigger['triggerid']] = $trigger['triggerid']; + } + + if(PERM_RES_STRING_LINE == $perm_res){ + if(count($result) == 0) + $result = '-1'; + else + $result = implode(',',$result); + } + + $available_triggers[$perm][$perm_res][$nodeid_str][$hostid_str] = $result; + + return $result; + } /* |