/usr/share/zabbix/api/classes/class.czbxapi.php is in zabbix-frontend-php 1:1.8.11-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | <?php
/*
** ZABBIX
** Copyright (C) 2000-2009 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
class CZBXAPI{
public static $error = array();
private static $transaction = array('counter' => 0);
// TRANSACTION METHODS{
protected static function BeginTransaction($caller = 'CZBXAPI'){
global $DB;
if(!isset(self::$transaction[$caller])) self::$transaction[$caller] = 0;
self::$transaction[$caller]++;
//SDII(self::$transaction);
if(self::$transaction['counter'] > 0){
self::$transaction['counter']++;
}
else{
if($DB['TRANSACTIONS'] == 0){
DBstart();
self::$transaction['counter'] = 1;
self::$transaction['owner'] = $caller;
}
else{
self::$transaction['counter'] = 2;
self::$transaction['owner'] = 'DB_CLASS';
}
}
//SDII(self::$transaction);
return true;
}
protected static function EndTransaction($result = true, $caller = 'CZBXAPI'){
$result = $result;
if(!isset(self::$transaction[$caller])){
self::$error[] = array('error' => ZBX_API_ERROR_INTERNAL,
'data' => 'Trying to end not started transaction from: '.$caller
);
}
else if((self::$transaction['owner'] == $caller) && (self::$transaction[$caller] == 1)){
if(self::$transaction['counter'] > 1){
self::$error[] = array('error' => ZBX_API_ERROR_INTERNAL,
'data' => 'Ending transaction regardless to opened logical subtransactions: '.$caller
);
}
unset(self::$transaction['owner']);
self::$transaction[$caller] = 0;
self::$transaction['counter'] = 0;
$result = DBend($result);
}
else{
if(self::$transaction[$caller] > 0) self::$transaction[$caller]--;
else self::$error[] = array('error' => ZBX_API_ERROR_INTERNAL,
'data' => 'Attempt to close not started transaction from: '.$caller
);
if(self::$transaction['counter'] > 0) self::$transaction['counter']--;
else self::$error[] = array('error' => ZBX_API_ERROR_INTERNAL,
'data' => 'Count of opened transaction is not equal to attempts to close them. Attemp from: '.$caller
);
}
return $result;
}
protected static function endAPITransactions($result){
if((self::$transaction['counter'] > 0) && (self::$transaction['owner'] != 'DB_CLASS')){
unset(self::$transaction['owner']);
self::$transaction['counter'] = 0;
$result = DBend($result);
}
}
// TRANSACTION METHODS}
// ERROR METHODS{
protected static function setError($method, $errno = ZBX_API_ERROR_INTERNAL, $error = 'Unknown Zabbix internal error') {
if ($error) {
CZBXAPI::$error[] = array('error' => $errno, 'data' => '[ '.$method.' ] '.$error);
}
}
protected static function setMethodErrors($method, $errors){
global $ZBX_MESSAGES;
if(empty($errors)){
$php_error = is_array($ZBX_MESSAGES) ? end($ZBX_MESSAGES) : false;
while($php_error && ($php_error['type'] != 'error')){
$php_error = prev($ZBX_MESSAGES);
}
$php_error = $php_error ? $php_error['message'] : null;
if(is_null($php_error)){
self::setError($method);
}
else{
self::setError($method, ZBX_API_ERROR_INTERNAL, $php_error);
}
}
else{
foreach($errors as $enum => $error){
self::setError($method, $error['errno'], $error['error']);
}
}
}
public static function clearErrors(){
self::$error = array();
}
public static function getErrorMessages(){
$return = array();
foreach(self::$error as $error){
$return[] = $error['data'];
}
return $return;
}
public static function resetErrors(){
$errors = self::getErrorMessages();
self::clearErrors();
return $errors;
}
// ERROR METHODS}
protected static function exception($code=ZBX_API_ERROR_INTERNAL, $errors=array()){
throw new APIException($code, $errors);
}
}
|