diff options
Diffstat (limited to 'frontends/php/include')
| -rw-r--r-- | frontends/php/include/db.inc.php | 301 | ||||
| -rw-r--r-- | frontends/php/include/defines.inc.php | 3 | ||||
| -rw-r--r-- | frontends/php/include/discovery.inc.php | 21 | ||||
| -rw-r--r-- | frontends/php/include/events.inc.php | 235 | ||||
| -rw-r--r-- | frontends/php/include/import.inc.php | 2 | ||||
| -rw-r--r-- | frontends/php/include/locales/en_gb.inc.php | 2 | ||||
| -rw-r--r-- | frontends/php/include/page_header.php | 13 | ||||
| -rw-r--r-- | frontends/php/include/perm.inc.php | 85 | ||||
| -rw-r--r-- | frontends/php/include/profiles.inc.php | 13 |
9 files changed, 433 insertions, 242 deletions
diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php index a0bbaf4d..fda0e808 100644 --- a/frontends/php/include/db.inc.php +++ b/frontends/php/include/db.inc.php @@ -19,13 +19,13 @@ **/ ?> <?php - global $DB, $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD; + global $DB, $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD, $DB_TRANSACTIONS; function DBconnect(&$error) { $result = true; - global $DB, $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD; + global $DB, $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD, $DB_TRANSACTIONS; $DB = null; @@ -82,49 +82,39 @@ } break; case "SQLITE3": - if(!function_exists('init_db_access')) - { - function init_db_access() - { + $DB_TRANSACTIONS = 0; + if(!function_exists('init_db_access')){ + function init_db_access(){ global $DB_DATABASE, $ZBX_SEM_ID; $ZBX_SEM_ID = false; - if(function_exists('ftok') && function_exists('sem_get') && - file_exists($DB_DATABASE)) - { + if(function_exists('ftok') && function_exists('sem_get') && file_exists($DB_DATABASE)){ $ZBX_SEM_ID = sem_get(ftok($DB_DATABASE, 'z'), 1); } } } - if(!function_exists('lock_db_access')) - { - function lock_db_access() - { + if(!function_exists('lock_db_access')){ + function lock_db_access(){ global $ZBX_SEM_ID; - if($ZBX_SEM_ID && function_exists('sem_acquire')) - { + if($ZBX_SEM_ID && function_exists('sem_acquire')){ sem_acquire($ZBX_SEM_ID); } } } - if(!function_exists('unlock_db_access')) - { - function unlock_db_access() - { + if(!function_exists('unlock_db_access')){ + function unlock_db_access(){ global $ZBX_SEM_ID; - if($ZBX_SEM_ID && function_exists('sem_release')) + if($ZBX_SEM_ID && function_exists('sem_release')) sem_release($ZBX_SEM_ID); } } - if(!function_exists('free_db_access')) - { - function free_db_access() - { + if(!function_exists('free_db_access')){ + function free_db_access(){ global $ZBX_SEM_ID; if($ZBX_SEM_ID && function_exists('sem_remove')) @@ -135,17 +125,14 @@ } - if(file_exists($DB_DATABASE)) - { + if(file_exists($DB_DATABASE)){ $DB = sqlite3_open($DB_DATABASE); - if(!$DB) - { + if(!$DB){ $error = "Error connecting to database"; $result = false; } } - else - { + else{ $error = "Missed database"; $result = false; } @@ -163,19 +150,22 @@ return $result; } - function DBclose() - { - global $DB, $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD; + function DBclose(){ + global $DB, $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD, $DB_TRANSACTIONS; $result = false; - if( isset($DB) && !empty($DB) ) - { - switch($DB_TYPE) - { - case "MYSQL": $result = mysql_close($DB); break; - case "POSTGRESQL": $result = pg_close($DB); break; - case "ORACLE": $result = ocilogoff($DB); break; + if( isset($DB) && !empty($DB) ){ + switch($DB_TYPE){ + case "MYSQL": + $result = mysql_close($DB); + break; + case "POSTGRESQL": + $result = pg_close($DB); + break; + case "ORACLE": + $result = ocilogoff($DB); + break; case "SQLITE3": $result = true; sqlite3_close($DB); @@ -192,7 +182,8 @@ $GLOBALS['DB_PORT'], $GLOBALS['DB_DATABASE'], $GLOBALS['DB_USER'], - $GLOBALS['DB_PASSWORD'] + $GLOBALS['DB_PASSWORD'], + $GLOBALS['SQLITE_TRANSACTION'] ); return $result; @@ -227,28 +218,119 @@ } return true; } - - function DBstart() - { - /* TODO *//* start transaction */ - // lock_db_access(); /* check DBselect & DBexecute */ + + function DBStart(){ + global $DB,$DB_TYPE,$DB_TRANSACTIONS; +//SDI('TRANSACTION STARTED'); + $result = false; + if( isset($DB) && !empty($DB) ) + switch($DB_TYPE){ + case "MYSQL": + $result = DBexecute('begin;'); + break; + case "POSTGRESQL": + $result = DBexecute('begin;'); + break; + case "ORACLE": + $DB_TRANSACTIONS++; + + if($DB_TRANSACTIONS>1){ + info("POSSIBLE ERROR: Used incorect logic in database processing started subtransaction!"); + } + $result = true; +// TODO OCI_DEFAULT + break; + case "SQLITE3": + $DB_TRANSACTIONS++; + + if(1 == $DB_TRANSACTIONS){ + lock_db_access(); + $result = DBexecute('begin;'); + } + else{ + error("POSSIBLE ERROR: Used incorect logic in database processing started subtransaction!"); + } + break; + } + return $result; } - function DBend($result) - { - /* end transaction *//* TODO */ - - if($result) - { // OK - /* commit TODO */ + + function DBend($result=true){ + if($result){ // OK + $result = DBcommit(); } - else - { // FAIL - /* rollback TODO */ + + if(!$result){ // FAIL + DBrollback(); + } +//SDI('TRANSACTION ENDED: '.$result); + return $result; + } + + function DBcommit(){ + global $DB,$DB_TYPE,$DB_TRANSACTIONS; +//SDI('COMMITED!'); + $result = false; + if( isset($DB) && !empty($DB) ) + switch($DB_TYPE){ + case "MYSQL": + $result = DBexecute('commit;'); + break; + case "POSTGRESQL": + $result = DBexecute('commit;'); + break; + case "ORACLE": + $result = ocicommit(); + $DB_TRANSACTIONS = 0; + break; + case "SQLITE3": + if($DB_TRANSACTIONS>1) + $DB_TRANSACTIONS--; + + if(1 == $DB_TRANSACTIONS){ + $result = DBexecute('commit;'); + $DB_TRANSACTIONS = 0; + + unlock_db_access(); + } + break; + } + return $result; + } + + function DBrollback(){ + global $DB,$DB_TYPE,$DB_TRANSACTIONS; +//SDI('ROLLED BACK!'); + $result = false; + if( isset($DB) && !empty($DB) ) + switch($DB_TYPE){ + case "MYSQL": + $result = DBexecute('rollback;'); + break; + case "POSTGRESQL": + $result = DBexecute('rollback;'); + break; + case "ORACLE": + $result = ocirollback(); + $DB_TRANSACTIONS = 0; + break; + case "SQLITE3": + if($DB_TRANSACTIONS>1) + $DB_TRANSACTIONS--; + + if(1 == $DB_TRANSACTIONS){ + $result = DBexecute('rollback;'); + $DB_TRANSACTIONS = 0; + + unlock_db_access(); + } + break; } - // unlock_db_access(); /* check DBselect & DBexecute */ + return $result; } + /* NOTE: LIMIT and OFFSET records @@ -266,72 +348,64 @@ function &DBselect($query, $limit='NO') { - global $DB, $DB_TYPE; + global $DB, $DB_TYPE, $DB_TRANSACTIONS; //COpt::savesqlrequest($query); $result = false; if( isset($DB) && !empty($DB) ) - switch($DB_TYPE) - { + switch($DB_TYPE){ case "MYSQL": - if(is_numeric($limit)) - { + if(is_numeric($limit)){ $query .= ' limit '.intval($limit); } $result=mysql_query($query,$DB); - if(!$result) - { + if(!$result){ error("Error in query [$query] [".mysql_error()."]"); } break; case "POSTGRESQL": - if(is_numeric($limit)) - { + if(is_numeric($limit)){ $query .= ' limit '.intval($limit); } - if(!($result = pg_query($DB,$query))) - { + $result = pg_query($DB,$query); + if(!$result){ error("Error in query [$query] [".pg_last_error()."]"); } break; case "ORACLE": - if(is_numeric($limit)) - { + if(is_numeric($limit)){ $query = 'select * from ('.$query.') where rownum<'.intval($limit); } $stid=OCIParse($DB,$query); - if(!$stid) - { + if(!$stid){ $e=@ocierror(); error("SQL error [".$e["message"]."] in [".$e["sqltext"]."]"); } - $result=@OCIExecute($stid); - if(!$result) - { + + $result=@OCIExecute($stid,($DB_TRANSACTIONS?OCI_DEFAULT:OCI_COMMIT_ON_SUCCESS)); + if(!$result){ $e=ocierror($stid); error("SQL error [".$e["message"]."] in [".$e["sqltext"]."]"); } - else - { + else{ $result = $stid; } break; case "SQLITE3": - lock_db_access(); - if(!($result = sqlite3_query($DB,$query))) - { - error("Error in query [$query] [".sqlite3_error($DB)."]"); - } - else - { + if(!$DB_TRANSACTIONS){ + lock_db_access(); + } + + if(!($result = sqlite3_query($DB,$query))){ + error("Error in query [$query] [".sqlite3_error($DB)."]"); + } + else{ $data = array(); - while($row = sqlite3_fetch_array($result)) - { - foreach($row as $id => $name) - { + while($row = sqlite3_fetch_array($result)){ + foreach($row as $id => $name){ if(!zbx_strstr($id,'.')) continue; $ids = explode('.',$id); $row[array_pop($ids)] = $row[$id]; @@ -344,69 +418,69 @@ $result = &$data; } - unlock_db_access(); + if(!$DB_TRANSACTIONS){ + unlock_db_access(); + } break; } return $result; } - function DBexecute($query, $skip_error_messages=0) - { - global $DB,$DB_TYPE; + function DBexecute($query, $skip_error_messages=0){ + global $DB,$DB_TYPE,$DB_TRANSACTIONS; //COpt::savesqlrequest($query); $result = false; if( isset($DB) && !empty($DB) ) - switch($DB_TYPE) - { + switch($DB_TYPE){ case "MYSQL": $result=mysql_query($query,$DB); - if(!$result) - { + if(!$result){ error("Error in query [$query] [".mysql_error()."]"); } break; case "POSTGRESQL": - if(!($result = pg_query($DB,$query))) - { + if(!($result = pg_query($DB,$query))){ error("Error in query [$query] [".pg_last_error()."]"); } break; case "ORACLE": $result = DBselect($query); - if(!$result) - { + if(!$result){ $e = ocierror($stid); error("SQL error [".$e["message"]."] in [".$e["sqltext"]."]"); } break; case "SQLITE3": - lock_db_access(); + if(!$DB_TRANSACTIONS){ + lock_db_access(); + } + $result = sqlite3_exec($DB, $query); - if(!$result) - { + if(!$result){ error("Error in query [$query] [".sqlite3_error($DB)."]"); } - unlock_db_access(); + + if(!$DB_TRANSACTIONS){ + unlock_db_access(); + } break; } - return $result; + return $result; } - function DBfetch(&$cursor) - { + function DBfetch(&$cursor){ global $DB, $DB_TYPE; $result = false; - if( isset($DB) && !empty($DB) ) - switch($DB_TYPE) - { + if(isset($DB) && !empty($DB)) + switch($DB_TYPE){ case "MYSQL": $result = mysql_fetch_assoc($cursor); break; @@ -422,17 +496,14 @@ } break; case "SQLITE3": - if($cursor) - { + if($cursor){ $result = array_shift($cursor); - if(is_null($result)) $result = false; - } break; } - return $result; + return $result; } diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php index ad34beff..eb8b0a16 100644 --- a/frontends/php/include/defines.inc.php +++ b/frontends/php/include/defines.inc.php @@ -440,6 +440,9 @@ define('DHOST_STATUS_ACTIVE', 0); define('DHOST_STATUS_DISABLED', 1); + define('AVAILABLE_NOCACHE', 0); // take available objects not from cache + + // define('BR', "<br/>\n"); define('SBR', "<br/>\n"); define('SPACE', ' '); diff --git a/frontends/php/include/discovery.inc.php b/frontends/php/include/discovery.inc.php index 10cd2565..673c9d40 100644 --- a/frontends/php/include/discovery.inc.php +++ b/frontends/php/include/discovery.inc.php @@ -21,27 +21,20 @@ ?> <?php - function check_right_on_discovery($permission) - { + function check_right_on_discovery($permission){ global $USER_DETAILS; - if( $USER_DETAILS['type'] >= USER_TYPE_ZABBIX_ADMIN ) - { - if ( 0 == count( - get_accessible_nodes_by_user($USER_DETAILS, $permission, null, PERM_RES_IDS_ARRAY, get_current_nodeid()) - )) + if( $USER_DETAILS['type'] >= USER_TYPE_ZABBIX_ADMIN ){ + if (0 < count(get_accessible_nodes_by_user($USER_DETAILS, $permission, null, PERM_RES_IDS_ARRAY, get_current_nodeid()))) return true; } - - return false; + return false; } - function svc_default_port($type_int) - { + function svc_default_port($type_int){ $port = 0; - switch($type_int) - { + switch($type_int){ case SVC_SSH: $port = 22; break; case SVC_LDAP: $port = 389; break; case SVC_SMTP: $port = 25; break; @@ -56,7 +49,7 @@ case SVC_SNMPv2:$port = 161; break; } - return $port; + return $port; } function discovery_check_type2str($type_int) diff --git a/frontends/php/include/events.inc.php b/frontends/php/include/events.inc.php index bbfc2bc1..211c44d8 100644 --- a/frontends/php/include/events.inc.php +++ b/frontends/php/include/events.inc.php @@ -27,68 +27,6 @@ } } - function get_history_of_discovery_events($start,$num){ - $db_events = DBselect('select distinct e.source,e.object,e.objectid,e.clock,e.value from events e'. - ' where e.source='.EVENT_SOURCE_DISCOVERY.' order by e.clock desc', - 10*($start+$num) - ); - - $table = new CTableInfo(S_NO_EVENTS_FOUND); - $table->SetHeader(array(S_TIME, S_IP, S_DESCRIPTION, S_STATUS)); - $col=0; - - $skip = $start; - while(($event_data = DBfetch($db_events))&&($col<$num)) - { - if($skip > 0) - { - $skip--; - continue; - } - - if($event_data["value"] == 0) - { - $value=new CCol(S_UP,"off"); - } - elseif($event_data["value"] == 1) - { - $value=new CCol(S_DOWN,"on"); - } - else - { - $value=new CCol(S_UNKNOWN_BIG,"unknown"); - } - - - switch($event_data['object']) - { - case EVENT_OBJECT_DHOST: - $object_data = DBfetch(DBselect('select ip from dhosts where dhostid='.$event_data['objectid'])); - $description = SPACE; - break; - case EVENT_OBJECT_DSERVICE: - $object_data = DBfetch(DBselect('select h.ip,s.type,s.port from dhosts h,dservices s '. - ' where h.dhostid=s.dhostid and s.dserviceid='.$event_data['objectid'])); - $description = S_SERVICE.': '.discovery_check_type2str($object_data['type']).'; '. - S_PORT.': '.$object_data['port']; - break; - default: - continue; - } - - if(!$object_data) continue; - - - $table->AddRow(array( - date("Y.M.d H:i:s",$event_data["clock"]), - $object_data['ip'], - $description, - $value)); - - $col++; - } - return $table; - } /* function: * event_initial_time @@ -176,6 +114,14 @@ function first_initial_eventid($row,$show_unknown=0){ return false; } +/* function: + * get_latest_events + * + * description: + * return latest events by VALUE + * + * author: Aly + */ function get_latest_events($row,$show_unknown=0){ $eventz = array(); @@ -226,6 +172,14 @@ function get_latest_events($row,$show_unknown=0){ return $events; } +/* function: + * get_next_event + * + * description: + * return next event by value + * + * author: Aly + */ function get_next_event($row,$show_unknown=0){ $sql_cond=($show_unknown == 0)?' AND e.value<>'.TRIGGER_VALUE_UNKNOWN:''; @@ -251,4 +205,161 @@ function get_next_event($row,$show_unknown=0){ $rez = DBfetch(DBselect($sql,1)); return $rez; } + + +function get_history_of_discovery_events($start,$num){ + $db_events = DBselect('select distinct e.source,e.object,e.objectid,e.clock,e.value from events e'. + ' where e.source='.EVENT_SOURCE_DISCOVERY.' order by e.clock desc', + 10*($start+$num) + ); + + $table = new CTableInfo(S_NO_EVENTS_FOUND); + $table->SetHeader(array(S_TIME, S_IP, S_DESCRIPTION, S_STATUS)); + $col=0; + + $skip = $start; + while(($event_data = DBfetch($db_events))&&($col<$num)){ + if($skip > 0){ + $skip--; + continue; + } + + if($event_data["value"] == 0){ + $value=new CCol(S_UP,"off"); + } + elseif($event_data["value"] == 1){ + $value=new CCol(S_DOWN,"on"); + } + else{ + $value=new CCol(S_UNKNOWN_BIG,"unknown"); + } + + + switch($event_data['object']){ + case EVENT_OBJECT_DHOST: + $object_data = DBfetch(DBselect('select ip from dhosts where dhostid='.$event_data['objectid'])); + $description = SPACE; + break; + case EVENT_OBJECT_DSERVICE: + $object_data = DBfetch(DBselect('select h.ip,s.type,s.port from dhosts h,dservices s '. + ' where h.dhostid=s.dhostid and s.dserviceid='.$event_data['objectid'])); + $description = S_SERVICE.': '.discovery_check_type2str($object_data['type']).'; '. + S_PORT.': '.$object_data['port']; + break; + default: + continue; + } + + if(!$object_data) continue; + + + $table->AddRow(array( + date("Y.M.d H:i:s",$event_data["clock"]), + $object_data['ip'], + $description, + $value)); + + $col++; + } +return $table; +} + +function make_event_details($triggerid,&$trigger_data){ + $table = new CTableInfo(); + + if(is_show_subnodes()){ + $table->AddRow(array(S_NODE, get_node_name_by_elid($triggerid))); + } + + $table->AddRow(array(S_HOST, $trigger_data['host'])); + $table->AddRow(array(S_TRIGGER, $trigger_data['exp_desc'])); + $table->AddRow(array(S_SEVERITY, new CSpan(get_severity_description($trigger_data["priority"]), get_severity_style($trigger_data["priority"])))); + $table->AddRow(array(S_EXPRESSION, $trigger_data['exp_expr'])); + +return $table; +} + +function make_small_eventlist($triggerid,&$trigger_data,$show_unknown=0){ + $sql_cond = ''; + if(0 == $show_unknown){ + $sql_cond = ' AND value<>2 '; + } + + $table = new CTableInfo(); + $table->SetHeader(array(S_TIME,S_STATUS,S_ACK,S_DURATION)); + + $sql = 'SELECT * '. + ' FROM events '. + ' WHERE objectid='.$triggerid. + ' AND object='.EVENT_OBJECT_TRIGGER. + $sql_cond. + ' ORDER BY clock DESC'; + + $result = DBselect($sql,10*($_REQUEST['start']+PAGE_SIZE)); + + $rows = array(); + $count = 0; + + $col=0; + $skip = $_REQUEST['start']; + while(($col<PAGE_SIZE) && ($row=DBfetch($result))){ + if($skip > 0){ + if((0 == $show_unknown) && ($row['value'] == TRIGGER_VALUE_UNKNOWN)) continue; + $skip--; + continue; + } + + if(!empty($rows) && ($rows[$count]['value'] != $row['value'])){ + $count++; + } + else if(!empty($rows) && + ($rows[$count]['value'] == $row['value']) && + ($trigger_data['type'] == TRIGGER_MULT_EVENT_ENABLED) && + ($row['value'] == TRIGGER_VALUE_TRUE) + ){ + $count++; + } + $rows[$count] = $row; + $col++; + } + + $clock=time(); + + foreach($rows as $id => $row){ + $lclock=$clock; + $clock=$row["clock"]; + + $duration = zbx_date2age($lclock,$clock); + + if($row["value"] == TRIGGER_VALUE_FALSE){ + $value=new CCol(S_FALSE_BIG,"off"); + } + elseif($row["value"] == TRIGGER_VALUE_TRUE){ + $value=new CCol(S_TRUE_BIG,"on"); + } + else{ + $value=new CCol(S_UNKNOWN_BIG,"unknown"); + } + + $ack = "-"; + if($row["value"] == 1 && $row["acknowledged"] == 1){ + $db_acks = get_acknowledges_by_eventid($row["eventid"]); + $rows=0; + while($a=DBfetch($db_acks)) $rows++; + + $ack=array( + new CLink(new CSpan(S_YES,'off'),'acknow.php?eventid='.$row['eventid'],'action'), + SPACE.'('.$rows.')' + ); + } + + $table->AddRow(array( + date('Y.M.d H:i:s',$row['clock']), + $value, + $ack, + $duration + )); + } +return $table; +} ?> diff --git a/frontends/php/include/import.inc.php b/frontends/php/include/import.inc.php index e3697ac9..2fa6a977 100644 --- a/frontends/php/include/import.inc.php +++ b/frontends/php/include/import.inc.php @@ -131,7 +131,7 @@ 0, /* useip */ "", /* dns */ "", /* ip */ - 0, + 0, /* proxy_hostid */ array(), null, array()); diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php index e0b57341..d1be5d65 100644 --- a/frontends/php/include/locales/en_gb.inc.php +++ b/frontends/php/include/locales/en_gb.inc.php @@ -839,6 +839,8 @@ 'S_PARAMS'=> 'Additional parameters', // events.php + 'S_EVENT_DETAILS'=> 'Event details', + 'S_LIST'=> 'List', 'S_LATEST_EVENTS'=> 'Latest events', 'S_HISTORY_OF_EVENTS_BIG'=> 'HISTORY OF EVENTS', 'S_NO_EVENTS_FOUND'=> 'No events found', diff --git a/frontends/php/include/page_header.php b/frontends/php/include/page_header.php index d61de1c0..1bde9468 100644 --- a/frontends/php/include/page_header.php +++ b/frontends/php/include/page_header.php @@ -113,15 +113,21 @@ COpt::profiling_start("page"); "label"=>S_WEB, "sub_pages"=>array("httpdetails.php") ), - array("url"=>"latest.php" ,"label"=>S_LATEST_DATA , - "sub_pages"=>array("history.php","chart.php") + 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("acknow.php","tr_comments.php","chart4.php","scripts_exec.php") ), - array("url"=>"events.php" ,"label"=>S_EVENTS ), + array( + "url"=>"events.php", + "label"=>S_EVENTS, + "sub_pages"=>array("tr_events.php") + ), array( "url"=>"actions.php", "label"=>S_ACTIONS), @@ -414,6 +420,7 @@ COpt::profiling_start("page"); <script type="text/javascript" src="js/common.js"></script> <script type="text/javascript" src="js/prototype.js"></script> + <script type="text/javascript" src="js/url.js"></script> <?php if(isset($page['scripts']) && is_array($page['scripts'])){ foreach($page['scripts'] as $id => $script){ diff --git a/frontends/php/include/perm.inc.php b/frontends/php/include/perm.inc.php index e5f96bb3..c319448d 100644 --- a/frontends/php/include/perm.inc.php +++ b/frontends/php/include/perm.inc.php @@ -184,9 +184,9 @@ return $perm_mode; } - function get_accessible_hosts_by_user(&$user_data,$perm,$perm_mode=null,$perm_res=null,$nodeid=null,$hostid=null){ + function get_accessible_hosts_by_user(&$user_data,$perm,$perm_mode=null,$perm_res=null,$nodeid=null,$cache=1){ static $available_hosts; - + if(is_null($perm_res)) $perm_res = PERM_RES_STRING_LINE; if($perm == PERM_READ_LIST) $perm = PERM_READ_ONLY; @@ -201,7 +201,7 @@ $nodeid_str =(is_array($nodeid))?implode('',$nodeid):strval($nodeid); - if(isset($available_hosts[$userid][$perm][$perm_mode][$perm_res][$nodeid_str])){ + if($cache && isset($available_hosts[$userid][$perm][$perm_mode][$perm_res][$nodeid_str])){ return $available_hosts[$userid][$perm][$perm_mode][$perm_res][$nodeid_str]; } @@ -221,39 +221,40 @@ COpt::counter_up('perm'); if ( !is_null($nodeid) ) array_push($where, DBin_node('h.hostid', $nodeid)); - if(is_array($hostid)) array_push($where, ' h.hostid in ('.implode(',', $hostid).') '); - elseif(isset($hostid)) array_push($where, ' h.hostid in ('.$hostid.') '); +// if(is_array($hostid)) array_push($where, ' h.hostid in ('.implode(',', $hostid).') '); +// else if(!empty($hostid)) array_push($where, ' h.hostid in ('.$hostid.') '); - if(count($where)) $where = ' where '.implode(' and ',$where); - else $where = ''; + if(count($where)) + $where = ' where '.implode(' and ',$where); + else + $where = ''; - $sql = 'select distinct n.nodeid,n.name as node_name,h.hostid,h.host, min(r.permission) as permission,ug.userid '. - ' from hosts h left join hosts_groups hg on hg.hostid=h.hostid '. - ' left join groups g on g.groupid=hg.groupid '. - ' left join rights r on r.id=g.groupid and r.type='.RESOURCE_TYPE_GROUP. - ' left join users_groups ug on ug.usrgrpid=r.groupid and ug.userid='.$userid. - ' left join nodes n on '.DBid2nodeid('h.hostid').'=n.nodeid '. - $where.' group by h.hostid,n.nodeid,n.name,h.host,ug.userid '. - ' order by n.name,n.nodeid, h.host, permission desc, userid desc'; + $sql = 'SELECT DISTINCT n.nodeid,n.name as node_name,h.hostid,h.host, min(r.permission) as permission,ug.userid '. + ' FROM hosts h '. + ' LEFT JOIN hosts_groups hg ON hg.hostid=h.hostid '. + ' LEFT JOIN groups g ON g.groupid=hg.groupid '. + ' LEFT JOIN rights r ON r.id=g.groupid and r.type='.RESOURCE_TYPE_GROUP. + ' LEFT JOIN users_groups ug ON ug.usrgrpid=r.groupid and ug.userid='.$userid. + ' LEFT JOIN nodes n ON '.DBid2nodeid('h.hostid').'=n.nodeid '. + $where. + ' GROUP BY h.hostid,n.nodeid,n.name,h.host,ug.userid '. + ' ORDER BY n.name,n.nodeid, h.host, permission desc, userid desc'; $db_hosts = DBselect($sql); $processed = array(); - while($host_data = DBfetch($db_hosts)) - { + while($host_data = DBfetch($db_hosts)){ // It seems that host details are not required by the logic // $host_data += DBfetch(DBselect('select * from hosts where hostid='.$host_data['hostid'])); if(is_null($host_data['nodeid'])) $host_data['nodeid'] = id2nodeid($host_data['hostid']); /* if no rights defined used node rights */ - if( (is_null($host_data['permission']) || is_null($host_data['userid'])) ) - { + if( (is_null($host_data['permission']) || is_null($host_data['userid'])) ){ if( isset($processed[$host_data['hostid']]) ) continue; - if(!isset($nodes)) - { + if(!isset($nodes)){ $nodes = get_accessible_nodes_by_user($user_data, PERM_DENY,PERM_MODE_GE,PERM_RES_DATA_ARRAY); } @@ -383,29 +384,32 @@ COpt::counter_up('perm'); 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.') '; + 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,min(r.permission) as permission, g.userid'. - ' from nodes n left join rights r on r.id=n.nodeid and r.type='.RESOURCE_TYPE_NODE. - ' left join users_groups g on r.groupid=g.usrgrpid and g.userid='.$userid. - $where_nodeid.' group by n.nodeid, g.userid order by nodeid desc, userid desc, permission desc'); + $db_nodes = DBselect('SELECT n.nodeid,min(r.permission) as permission, g.userid'. + ' FROM nodes n '. + ' left join rights r on r.id=n.nodeid and r.type='.RESOURCE_TYPE_NODE. + ' left join users_groups g on r.groupid=g.usrgrpid and g.userid='.$userid. + $where_nodeid. + ' GROUP BY n.nodeid, g.userid '. + ' ORDER BY nodeid desc, userid desc, permission desc'); - while(($node_data = DBfetch($db_nodes)) || (!isset($do_break) && !ZBX_DISTRIBUTED)) - { - if($node_data && $perm_res == PERM_RES_DATA_ARRAY) - { + while(($node_data = DBfetch($db_nodes)) || (!isset($do_break) && !ZBX_DISTRIBUTED)){ + + if($node_data && ($perm_res == PERM_RES_DATA_ARRAY)){ $node_data += DBfetch(DBselect('select * from nodes where nodeid='.$node_data['nodeid'])); } if($node_data && isset($processed_nodeids[$node_data["nodeid"]])) continue; - if(!ZBX_DISTRIBUTED) - { - if(!$node_data) - { + if(!ZBX_DISTRIBUTED){ + if(!$node_data){ $node_data = array( 'nodeid' => $ZBX_LOCALNODEID, 'name' => 'local', @@ -420,8 +424,7 @@ COpt::counter_up('perm'); } else if(isset($nodeid) && (bccomp($node_data['nodeid'] ,$nodeid) != 0)) continue; } - else - { + else{ $node_data['permission'] = PERM_DENY; } } @@ -429,8 +432,7 @@ COpt::counter_up('perm'); $processed_nodeids[$node_data["nodeid"]] = $node_data["nodeid"]; /* deny if no rights defined (for local node read/write)*/ - if(is_null($node_data['permission']) || is_null($node_data['userid'])) - { + if(is_null($node_data['permission']) || is_null($node_data['userid'])){ if($user_type == USER_TYPE_SUPER_ADMIN) $node_data['permission'] = PERM_READ_WRITE; else @@ -451,8 +453,7 @@ COpt::counter_up('perm'); $result[$node_data["nodeid"]]= ($perm_res == PERM_RES_DATA_ARRAY)?$node_data:$node_data["nodeid"]; } - if($perm_res == PERM_RES_STRING_LINE) - { + if($perm_res == PERM_RES_STRING_LINE) { if(count($result) == 0) $result = '-1'; else diff --git a/frontends/php/include/profiles.inc.php b/frontends/php/include/profiles.inc.php index dfd913a1..46685bf9 100644 --- a/frontends/php/include/profiles.inc.php +++ b/frontends/php/include/profiles.inc.php @@ -68,10 +68,12 @@ function update_profile($idx,$value,$type=PROFILE_TYPE_UNKNOWN){ if($type==PROFILE_TYPE_ARRAY && !is_array($value)) $value = array($value); if(PROFILE_TYPE_ARRAY == $type){ + DBstart(); $sql='DELETE FROM profiles WHERE userid='.$USER_DETAILS["userid"].' and idx='.zbx_dbstr($idx); DBExecute($sql); - - insert_profile($idx,$value,$type); + + $result = insert_profile($idx,$value,$type); + DBend($result); } else{ $row = DBfetch(DBselect('SELECT value FROM profiles WHERE userid='.$USER_DETAILS["userid"].' AND idx='.zbx_dbstr($idx))); @@ -94,18 +96,19 @@ return true; function insert_profile($idx,$value,$type=PROFILE_TYPE_UNKNOWN){ global $USER_DETAILS; + $result = true; if(is_array($value)){ foreach($value as $key => $val){ - insert_profile($idx,$val,$type); // recursion!!! + $result&=insert_profile($idx,$val,$type); // recursion!!! } } else{ $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); + $result = DBexecute($sql); } - +return $result; } /***********************************/ |
