/usr/share/z-push/lib/log/log.php is in z-push-common 2.3.8-2ubuntu1.
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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | <?php
/***********************************************
* File : log.php
* Project : Z-Push
* Descr : Logging functionalities
*
* Created : 13.11.2015
*
* Copyright 2007 - 2016 Zarafa Deutschland GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Consult LICENSE file for details
************************************************/
abstract class Log {
/**
* @var string
*/
protected $user = '';
/**
* @var string
*/
protected $authUser = '';
/**
* @var string
*/
protected $devid = '';
/**
* @var string
*/
protected $pidstr = '';
/**
* @var array
*/
protected $specialLogUsers = array();
/**
* Only used as a cache value for IsUserInSpecialLogUsers.
* @var array
*/
private $isUserInSpecialLogUsers = array();
/**
* Only used as a cache value for IsAuthUserInSpecialLogUsers function
* @var bool
*/
private $isAuthUserInSpecialLogUsers = false;
/**
* @var array
*/
private $unauthMessageCache = array();
/**
* Constructor
*/
public function __construct() {
}
/**
* Returns the current user.
*
* @access public
* @return string
*/
public function GetUser() {
return $this->user;
}
/**
* Sets the current user.
*
* @param string $value
*
* @access public
* @return void
*/
public function SetUser($value) {
$this->user = $value;
}
/**
* Returns the current authenticated user.
*
* @access public
* @return string
*/
public function GetAuthUser() {
return $this->authUser;
}
/**
* Sets the current authenticated user.
*
* @param string $value
*
* @access public
* @return void
*/
public function SetAuthUser($value) {
$this->isAuthUserInSpecialLogUsers = false;
$this->authUser = $value;
}
/**
* Check that the current authUser ($this->GetAuthUser) is in the special log user array.
* This call is equivalent to `$this->IsUserInSpecialLogUsers($this->GetAuthUser())` at the exception that this
* call uses cache so there won't be more than one check to the specialLogUser for the AuthUser.
*
* @access public
* @return bool
*/
public function IsAuthUserInSpecialLogUsers() {
if ($this->isAuthUserInSpecialLogUsers) {
return true;
}
if($this->IsUserInSpecialLogUsers($this->GetAuthUser())){
$this->isAuthUserInSpecialLogUsers = true;
return true;
}
return false;
}
/**
* Returns the current device id.
*
* @access public
* @return string
*/
public function GetDevid() {
return $this->devid;
}
/**
* Sets the current device id.
*
* @param string $value
*
* @access public
* @return void
*/
public function SetDevid($value) {
$this->devid = $value;
}
/**
* Returns the current PID (as string).
*
* @access public
* @return string
*/
public function GetPidstr() {
return $this->pidstr;
}
/**
* Sets the current PID.
*
* @param string $value
*
* @access public
* @return void
*/
public function SetPidstr($value) {
$this->pidstr = $value;
}
/**
* Indicates if special log users are known.
*
* @access public
* @return bool True if we do have to log some specific user. False otherwise.
*/
public function HasSpecialLogUsers() {
return !empty($this->specialLogUsers);
}
/**
* Indicates if the user is in the special log users.
*
* @param string $user
*
* @access public
* @return bool
*/
public function IsUserInSpecialLogUsers($user) {
if (isset($this->isUserInSpecialLogUsers[$user])) {
return true;
}
if ($this->HasSpecialLogUsers() && in_array($user, $this->GetSpecialLogUsers())) {
$this->isUserInSpecialLogUsers[$user] = true;
return true;
}
return false;
}
/**
* Returns the current special log users array.
*
* @access public
* @return array
*/
public function GetSpecialLogUsers() {
return $this->specialLogUsers;
}
/**
* Sets the current special log users array.
*
* @param array $value
*
* @access public
* @return void
*/
public function SetSpecialLogUsers(array $value) {
$this->isUserInSpecialLogUsers = array(); // reset cache
$this->specialLogUsers = $value;
}
/**
* If called, the current user should get an extra log-file.
*
* If called until the user is authenticated (e.g. at the end of IBackend->Logon()) all
* messages logged until then will also be logged in the user file.
*
* @access public
* @return void
*/
public function SpecialLogUser() {
$this->isAuthUserInSpecialLogUsers = true;
}
/**
* Logs a message with a given log level.
*
*
* @param int $loglevel
* @param string $message
*
* @access public
* @return void
*/
public function Log($loglevel, $message) {
if ($loglevel <= LOGLEVEL) {
$this->Write($loglevel, $message);
}
if ($loglevel <= LOGUSERLEVEL) {
// cache log messages for unauthenticated users
if (!RequestProcessor::isUserAuthenticated()) {
$this->unauthMessageCache[] = array($loglevel, $message);
}
// user is authenticated now
elseif ($this->IsAuthUserInSpecialLogUsers()) {
// something was logged before the user was authenticated and cached write it to the log
if (!empty($this->unauthMessageCache)) {
foreach ($this->unauthMessageCache as $authcache) {
$this->WriteForUser($authcache[0], $authcache[1]);
}
$this->unauthMessageCache = array();
}
$this->WriteForUser($loglevel, $message);
}
else {
$this->unauthMessageCache[] = array($loglevel, $message);
}
}
$this->afterLog($loglevel, $message);
}
/**
* This function is used as an event for log implementer.
* It happens when the ZLog static class is finished with the initialization of this instance.
*
* @access public
* @return void
*/
public function AfterInitialize() {
}
/**
* This function is used as an event for log implementer.
* It happens when the a call to the Log function is finished.
*
* @access protected
* @return void
*/
protected function afterLog($loglevel, $message) {
}
/**
* Returns the string representation of the given $loglevel.
* String can be padded
*
* @param int $loglevel one of the LOGLEVELs
* @param boolean $pad
*
* @access protected
* @return string
*/
protected function GetLogLevelString($loglevel, $pad = false) {
if ($pad)
$s = " ";
else
$s = "";
switch($loglevel) {
case LOGLEVEL_OFF: return ""; break;
case LOGLEVEL_FATAL: return "[FATAL]"; break;
case LOGLEVEL_ERROR: return "[ERROR]"; break;
case LOGLEVEL_WARN: return "[".$s."WARN]"; break;
case LOGLEVEL_INFO: return "[".$s."INFO]"; break;
case LOGLEVEL_DEBUG: return "[DEBUG]"; break;
case LOGLEVEL_WBXML: return "[WBXML]"; break;
case LOGLEVEL_DEVICEID: return "[DEVICEID]"; break;
case LOGLEVEL_WBXMLSTACK: return "[WBXMLSTACK]"; break;
}
}
/**
* Writes a log message to the general log.
*
* @param int $loglevel
* @param string $message
*
* @access protected
* @return void
*/
abstract protected function Write($loglevel, $message);
/**
* Writes a log message to the user specific log.
* @param int $loglevel
* @param string $message
*
* @access public
* @return void
*/
abstract public function WriteForUser($loglevel, $message);
}
|