Completed
Push — master ( 8edb92...ad3576 )
by Ralf
15:11
created
api/src/Session.php 2 patches
Spacing   +174 added lines, -178 removed lines patch added patch discarded remove patch
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	const CD_SECOND_FACTOR_REQUIRED = 96;
171 171
 	const CD_FORCE_PASSWORD_CHANGE = 97;
172 172
 	const CD_ACCOUNT_EXPIRED = 98;
173
-	const CD_BLOCKED = 99;	// to many failed attempts to loing
173
+	const CD_BLOCKED = 99; // to many failed attempts to loing
174 174
 
175 175
 	/**
176 176
 	 * Verbose reason why session creation failed
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 	 *
192 192
 	 * @param array $domain_names =null domain-names used in this install
193 193
 	 */
194
-	function __construct(array $domain_names=null)
194
+	function __construct(array $domain_names = null)
195 195
 	{
196 196
 		$this->required_files = $_SESSION[self::EGW_REQUIRED_FILES];
197 197
 
@@ -207,27 +207,27 @@  discard block
 block discarded – undo
207 207
 			$save_rep = false;
208 208
 			if (!isset($GLOBALS['egw_info']['server']['max_access_log_age']))
209 209
 			{
210
-				$GLOBALS['egw_info']['server']['max_access_log_age'] = 90;	// default 90 days
210
+				$GLOBALS['egw_info']['server']['max_access_log_age'] = 90; // default 90 days
211 211
 				$save_rep = true;
212 212
 			}
213 213
 			if (!isset($GLOBALS['egw_info']['server']['block_time']))
214 214
 			{
215
-				$GLOBALS['egw_info']['server']['block_time'] = 1;	// default 1min, its enough to slow down brute force attacks
215
+				$GLOBALS['egw_info']['server']['block_time'] = 1; // default 1min, its enough to slow down brute force attacks
216 216
 				$save_rep = true;
217 217
 			}
218 218
 			if (!isset($GLOBALS['egw_info']['server']['num_unsuccessful_id']))
219 219
 			{
220
-				$GLOBALS['egw_info']['server']['num_unsuccessful_id']  = 3;	// default 3 trys per id
220
+				$GLOBALS['egw_info']['server']['num_unsuccessful_id'] = 3; // default 3 trys per id
221 221
 				$save_rep = true;
222 222
 			}
223 223
 			if (!isset($GLOBALS['egw_info']['server']['num_unsuccessful_ip']))
224 224
 			{
225
-				$GLOBALS['egw_info']['server']['num_unsuccessful_ip']  = $GLOBALS['egw_info']['server']['num_unsuccessful_id'] * 5;	// default is 5 times as high as the id default; since accessing via proxy is quite common
225
+				$GLOBALS['egw_info']['server']['num_unsuccessful_ip'] = $GLOBALS['egw_info']['server']['num_unsuccessful_id'] * 5; // default is 5 times as high as the id default; since accessing via proxy is quite common
226 226
 				$save_rep = true;
227 227
 			}
228 228
 			if (!isset($GLOBALS['egw_info']['server']['install_id']))
229 229
 			{
230
-				$GLOBALS['egw_info']['server']['install_id']  = md5(Auth::randomstring(15));
230
+				$GLOBALS['egw_info']['server']['install_id'] = md5(Auth::randomstring(15));
231 231
 			}
232 232
 			if (!isset($GLOBALS['egw_info']['server']['max_history']))
233 233
 			{
@@ -239,12 +239,12 @@  discard block
 block discarded – undo
239 239
 			{
240 240
 				$config = new Config('phpgwapi');
241 241
 				$config->read_repository();
242
-				$config->value('max_access_log_age',$GLOBALS['egw_info']['server']['max_access_log_age']);
243
-				$config->value('block_time',$GLOBALS['egw_info']['server']['block_time']);
244
-				$config->value('num_unsuccessful_id',$GLOBALS['egw_info']['server']['num_unsuccessful_id']);
245
-				$config->value('num_unsuccessful_ip',$GLOBALS['egw_info']['server']['num_unsuccessful_ip']);
246
-				$config->value('install_id',$GLOBALS['egw_info']['server']['install_id']);
247
-				$config->value('max_history',$GLOBALS['egw_info']['server']['max_history']);
242
+				$config->value('max_access_log_age', $GLOBALS['egw_info']['server']['max_access_log_age']);
243
+				$config->value('block_time', $GLOBALS['egw_info']['server']['block_time']);
244
+				$config->value('num_unsuccessful_id', $GLOBALS['egw_info']['server']['num_unsuccessful_id']);
245
+				$config->value('num_unsuccessful_ip', $GLOBALS['egw_info']['server']['num_unsuccessful_ip']);
246
+				$config->value('install_id', $GLOBALS['egw_info']['server']['install_id']);
247
+				$config->value('max_history', $GLOBALS['egw_info']['server']['max_history']);
248 248
 				$config->save_repository();
249 249
 			}
250 250
 		}
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 		// set session_timeout from global php.ini and default to 14400=4h, if not set
254 254
 		if (!($GLOBALS['egw_info']['server']['sessions_timeout'] = ini_get('session.gc_maxlifetime')))
255 255
       	{
256
-      		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400);
256
+      		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout'] = 14400);
257 257
       	}
258 258
 	}
259 259
 
@@ -328,15 +328,15 @@  discard block
 block discarded – undo
328 328
 
329 329
 		if (!isset($_SESSION[self::EGW_SESSION_ENCRYPTED]) && self::init_crypt($kp3))
330 330
 		{
331
-			foreach(self::$egw_session_vars as $name)
331
+			foreach (self::$egw_session_vars as $name)
332 332
 			{
333 333
 				if (isset($_SESSION[$name]))
334 334
 				{
335
-					$_SESSION[$name] = mcrypt_generic(self::$mcrypt,serialize($_SESSION[$name]));
335
+					$_SESSION[$name] = mcrypt_generic(self::$mcrypt, serialize($_SESSION[$name]));
336 336
 					//error_log(__METHOD__."() 'encrypting' session var: $name, len=".strlen($_SESSION[$name]));
337 337
 				}
338 338
 			}
339
-			$_SESSION[self::EGW_SESSION_ENCRYPTED] = true;	// flag session as encrypted
339
+			$_SESSION[self::EGW_SESSION_ENCRYPTED] = true; // flag session as encrypted
340 340
 
341 341
 			mcrypt_generic_deinit(self::$mcrypt);
342 342
 			self::$mcrypt = null;
@@ -351,24 +351,24 @@  discard block
 block discarded – undo
351 351
 	 * @param boolean $recursion =true if true call itself for every item > $limit
352 352
 	 * @param int $limit =1000 log only differences > $limit
353 353
 	 */
354
-	static function log_session_usage(&$arr,$label,$recursion=true,$limit=1000)
354
+	static function log_session_usage(&$arr, $label, $recursion = true, $limit = 1000)
355 355
 	{
356 356
 		if (!is_array($arr)) return;
357 357
 
358 358
 		$sizes = array();
359
-		foreach($arr as $key => &$data)
359
+		foreach ($arr as $key => &$data)
360 360
 		{
361 361
 			$sizes[$key] = strlen(serialize($data));
362 362
 		}
363
-		arsort($sizes,SORT_NUMERIC);
364
-		foreach($sizes as $key => $size)
363
+		arsort($sizes, SORT_NUMERIC);
364
+		foreach ($sizes as $key => $size)
365 365
 		{
366 366
 			$diff = $size - (int)$_SESSION[$label.'-sizes'][$key];
367 367
 			$_SESSION[$label.'-sizes'][$key] = $size;
368 368
 			if ($diff > $limit)
369 369
 			{
370 370
 				error_log("strlen({$label}[$key])=".Vfs::hsize($size).", diff=".Vfs::hsize($diff));
371
-				if ($recursion) self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit);
371
+				if ($recursion) self::log_session_usage($arr[$key], $label.'['.$key.']', $recursion, $limit);
372 372
 			}
373 373
 		}
374 374
 	}
@@ -383,15 +383,15 @@  discard block
 block discarded – undo
383 383
 	{
384 384
 		if ($_SESSION[self::EGW_SESSION_ENCRYPTED] && self::init_crypt(self::get_request('kp3')))
385 385
 		{
386
-			foreach(self::$egw_session_vars as $name)
386
+			foreach (self::$egw_session_vars as $name)
387 387
 			{
388 388
 				if (isset($_SESSION[$name]))
389 389
 				{
390
-					$_SESSION[$name] = unserialize(trim(mdecrypt_generic(self::$mcrypt,$_SESSION[$name])));
390
+					$_SESSION[$name] = unserialize(trim(mdecrypt_generic(self::$mcrypt, $_SESSION[$name])));
391 391
 					//error_log(__METHOD__."() 'decrypting' session var $name: gettype($name) = ".gettype($_SESSION[$name]));
392 392
 				}
393 393
 			}
394
-			unset($_SESSION[self::EGW_SESSION_ENCRYPTED]);	// delete encryption flag
394
+			unset($_SESSION[self::EGW_SESSION_ENCRYPTED]); // delete encryption flag
395 395
 		}
396 396
 	}
397 397
 
@@ -406,13 +406,13 @@  discard block
 block discarded – undo
406 406
 	 */
407 407
 	static private function init_crypt($kp3)
408 408
 	{
409
-		if(!$GLOBALS['egw_info']['server']['mcrypt_enabled'])
409
+		if (!$GLOBALS['egw_info']['server']['mcrypt_enabled'])
410 410
 		{
411
-			return false;	// session encryption is switched off
411
+			return false; // session encryption is switched off
412 412
 		}
413 413
 		if ($GLOBALS['egw_info']['currentapp'] == 'syncml' || !$kp3)
414 414
 		{
415
-			$kp3 = 'staticsyncmlkp3';	// syncml has no kp3!
415
+			$kp3 = 'staticsyncmlkp3'; // syncml has no kp3!
416 416
 		}
417 417
 		if (is_null(self::$mcrypt))
418 418
 		{
@@ -428,9 +428,9 @@  discard block
 block discarded – undo
428 428
 			}
429 429
 			$iv_size = mcrypt_enc_get_iv_size(self::$mcrypt);
430 430
 			$iv = !isset($GLOBALS['egw_info']['server']['mcrypt_iv']) || strlen($GLOBALS['egw_info']['server']['mcrypt_iv']) < $iv_size ?
431
-				mcrypt_create_iv ($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'],0,$iv_size);
431
+				mcrypt_create_iv ($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'], 0, $iv_size);
432 432
 
433
-			if (mcrypt_generic_init(self::$mcrypt,$kp3, $iv) < 0)
433
+			if (mcrypt_generic_init(self::$mcrypt, $kp3, $iv) < 0)
434 434
 			{
435 435
 				error_log(__METHOD__."() could not initialise mcrypt, sessions get NOT encrypted!");
436 436
 				return self::$mcrypt = false;
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
 	 * @param string|boolean $check_2fa =false string: 2fa-code to check (only if exists) and fail if wrong, false: do NOT check 2fa
452 452
 	 * @return string|boolean session id or false if session was not created, $this->(cd_)reason contains cause
453 453
 	 */
454
-	function create($login,$passwd = '',$passwd_type = '',$no_session=false,$auth_check=true,$fail_on_forced_password_change=false,$check_2fa=false)
454
+	function create($login, $passwd = '', $passwd_type = '', $no_session = false, $auth_check = true, $fail_on_forced_password_change = false, $check_2fa = false)
455 455
 	{
456 456
 		try {
457 457
 			if (is_array($login))
@@ -469,9 +469,9 @@  discard block
 block discarded – undo
469 469
 			}
470 470
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ...");
471 471
 
472
-			self::split_login_domain($login,$this->account_lid,$this->account_domain);
472
+			self::split_login_domain($login, $this->account_lid, $this->account_domain);
473 473
 			// add domain to the login, if not already there
474
-			if (substr($this->login,-strlen($this->account_domain)-1) != '@'.$this->account_domain)
474
+			if (substr($this->login, -strlen($this->account_domain) - 1) != '@'.$this->account_domain)
475 475
 			{
476 476
 				$this->login .= '@'.$this->account_domain;
477 477
 			}
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 			{
489 489
 				$this->account_domain = $GLOBALS['egw_info']['user']['domain'];
490 490
 			}
491
-			elseif($this->account_domain != $GLOBALS['egw_info']['user']['domain'])
491
+			elseif ($this->account_domain != $GLOBALS['egw_info']['user']['domain'])
492 492
 			{
493 493
 				throw new Exception("Wrong domain! '$this->account_domain' != '{$GLOBALS['egw_info']['user']['domain']}'");
494 494
 			}
@@ -496,9 +496,9 @@  discard block
 block discarded – undo
496 496
 
497 497
 			$user_ip = self::getuser_ip();
498 498
 
499
-			$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u');
499
+			$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid, 'account_lid', 'u');
500 500
 
501
-			if (($blocked = $this->login_blocked($login,$user_ip)) ||	// too many unsuccessful attempts
501
+			if (($blocked = $this->login_blocked($login, $user_ip)) || // too many unsuccessful attempts
502 502
 				$GLOBALS['egw_info']['server']['global_denied_users'][$this->account_lid] ||
503 503
 				$auth_check && !$GLOBALS['egw']->auth->authenticate($this->account_lid, $this->passwd, $this->passwd_type) ||
504 504
 				$this->account_id && $GLOBALS['egw']->accounts->get_type($this->account_id) == 'g')
@@ -507,9 +507,9 @@  discard block
 block discarded – undo
507 507
 				$this->cd_reason = $blocked ? self::CD_BLOCKED : self::CD_BAD_LOGIN_OR_PASSWORD;
508 508
 
509 509
 				// we dont log anon users as it would block the website
510
-				if (!$GLOBALS['egw']->acl->get_specific_rights_for_account($this->account_id,'anonymous','phpgwapi'))
510
+				if (!$GLOBALS['egw']->acl->get_specific_rights_for_account($this->account_id, 'anonymous', 'phpgwapi'))
511 511
 				{
512
-					$this->log_access($this->reason,$login,$user_ip,0);	// log unsuccessfull login
512
+					$this->log_access($this->reason, $login, $user_ip, 0); // log unsuccessfull login
513 513
 				}
514 514
 				if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
515 515
 				return false;
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
 			if ($this->account_lid != ($lid = $GLOBALS['egw']->accounts->id2name($this->account_id)))
528 528
 			{
529 529
 				$this->account_lid = $lid;
530
-				$this->login = $lid.substr($this->login,strlen($lid));
530
+				$this->login = $lid.substr($this->login, strlen($lid));
531 531
 			}
532 532
 
533 533
 			$GLOBALS['egw_info']['user']['account_id'] = $this->account_id;
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 				}
550 550
 				$this->sessionid = session_id();
551 551
 			}
552
-			$this->kp3       = Auth::randomstring(24);
552
+			$this->kp3 = Auth::randomstring(24);
553 553
 
554 554
 			$GLOBALS['egw_info']['user'] = $this->read_repositories();
555 555
 			if ($GLOBALS['egw']->accounts->is_expired($GLOBALS['egw_info']['user']))
@@ -582,10 +582,10 @@  discard block
 block discarded – undo
582 582
 						throw new \Exception('Invalid 2-Factor Authentication code', self::CD_BAD_LOGIN_OR_PASSWORD);
583 583
 					}
584 584
 				}
585
-				catch(\Exception $e) {
585
+				catch (\Exception $e) {
586 586
 					$this->cd_reason = $e->getCode();
587 587
 					$this->reason = $e->getMessage();
588
-					$this->log_access($this->reason, $login, $user_ip, 0);	// log unsuccessfull login
588
+					$this->log_access($this->reason, $login, $user_ip, 0); // log unsuccessfull login
589 589
 					if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check,$fail_on_forced_password_change,'$check_2fa') UNSUCCESSFULL ($this->reason)");
590 590
 					return false;
591 591
 				}
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
 				return false;
598 598
 			}
599 599
 
600
-			if ($GLOBALS['egw']->acl->check('anonymous',1,'phpgwapi'))
600
+			if ($GLOBALS['egw']->acl->check('anonymous', 1, 'phpgwapi'))
601 601
 			{
602 602
 				$this->session_flags = 'A';
603 603
 			}
@@ -615,39 +615,39 @@  discard block
 block discarded – undo
615 615
 				'passwd'         => $this->passwd,
616 616
 				'account_domain' => $this->account_domain,
617 617
 				'user_ip'        => $user_ip,
618
-			),'',true)))	// true = run hooks from all apps, not just the ones the current user has perms to run
618
+			), '', true)))	// true = run hooks from all apps, not just the ones the current user has perms to run
619 619
 			{
620
-				foreach($hook_result as $reason)
620
+				foreach ($hook_result as $reason)
621 621
 				{
622 622
 					if ($reason)	// called hook requests to deny the session
623 623
 					{
624 624
 						$this->reason = $this->cd_reason = $reason;
625
-						$this->log_access($this->reason,$login,$user_ip,0);		// log unsuccessfull login
625
+						$this->log_access($this->reason, $login, $user_ip, 0); // log unsuccessfull login
626 626
 						if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
627 627
 						return false;
628 628
 					}
629 629
 				}
630 630
 			}
631 631
 			$GLOBALS['egw']->db->transaction_begin();
632
-			$this->register_session($this->login,$user_ip,$now,$this->session_flags);
632
+			$this->register_session($this->login, $user_ip, $now, $this->session_flags);
633 633
 			if ($this->session_flags != 'A')		// dont log anonymous sessions
634 634
 			{
635
-				$this->sessionid_access_log = $this->log_access($this->sessionid,$login,$user_ip,$this->account_id);
635
+				$this->sessionid_access_log = $this->log_access($this->sessionid, $login, $user_ip, $this->account_id);
636 636
 			}
637 637
 			Cache::setSession('phpgwapi', 'account_previous_login', $GLOBALS['egw']->auth->previous_login);
638
-			$GLOBALS['egw']->accounts->update_lastlogin($this->account_id,$user_ip);
638
+			$GLOBALS['egw']->accounts->update_lastlogin($this->account_id, $user_ip);
639 639
 			$GLOBALS['egw']->db->transaction_commit();
640 640
 
641 641
 			if ($GLOBALS['egw_info']['server']['usecookies'] && !$no_session)
642 642
 			{
643
-				self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid);
644
-				self::egw_setcookie('kp3',$this->kp3);
645
-				self::egw_setcookie('domain',$this->account_domain);
643
+				self::egw_setcookie(self::EGW_SESSION_NAME, $this->sessionid);
644
+				self::egw_setcookie('kp3', $this->kp3);
645
+				self::egw_setcookie('domain', $this->account_domain);
646 646
 			}
647 647
 			if ($GLOBALS['egw_info']['server']['usecookies'] && !$no_session || isset($_COOKIE['last_loginid']))
648 648
 			{
649
-				self::egw_setcookie('last_loginid', $this->account_lid ,$now+1209600); /* For 2 weeks */
650
-				self::egw_setcookie('last_domain',$this->account_domain,$now+1209600);
649
+				self::egw_setcookie('last_loginid', $this->account_lid, $now + 1209600); /* For 2 weeks */
650
+				self::egw_setcookie('last_domain', $this->account_domain, $now + 1209600);
651 651
 			}
652 652
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid");
653 653
 
@@ -663,13 +663,13 @@  discard block
 block discarded – undo
663 663
 				'user_ip'        => $user_ip,
664 664
 				'session_type'   => Session\Type::get($_SERVER['REQUEST_URI'],
665 665
 					$GLOBALS['egw_info']['flags']['current_app'],
666
-					true),	// true return WebGUI instead of login, as we are logged in now
667
-			),'',true);
666
+					true), // true return WebGUI instead of login, as we are logged in now
667
+			), '', true);
668 668
 
669 669
 			return $this->sessionid;
670 670
 		}
671 671
 		// catch all exceptions, as their (allways logged) trace (eg. on a database error) would contain the user password
672
-		catch(Exception $e) {
672
+		catch (Exception $e) {
673 673
 			$this->reason = $this->cd_reason = $e->getMessage();
674 674
 			error_log(__METHOD__."('$login', ".array2string(str_repeat('*', strlen($passwd))).
675 675
 				", '$passwd_type', no_session=".array2string($no_session).
@@ -688,13 +688,12 @@  discard block
 block discarded – undo
688 688
 	 * @param int $now
689 689
 	 * @param string $session_flags
690 690
 	 */
691
-	private function register_session($login,$user_ip,$now,$session_flags)
691
+	private function register_session($login, $user_ip, $now, $session_flags)
692 692
 	{
693 693
 		// restore session vars set before session was started
694 694
 		if (is_array($this->required_files))
695 695
 		{
696
-			$_SESSION[self::EGW_REQUIRED_FILES] = !is_array($_SESSION[self::EGW_REQUIRED_FILES]) ? $this->required_files :
697
-				array_unique(array_merge($_SESSION[self::EGW_REQUIRED_FILES],$this->required_files));
696
+			$_SESSION[self::EGW_REQUIRED_FILES] = !is_array($_SESSION[self::EGW_REQUIRED_FILES]) ? $this->required_files : array_unique(array_merge($_SESSION[self::EGW_REQUIRED_FILES], $this->required_files));
698 697
 			unset($this->required_files);
699 698
 		}
700 699
 		$_SESSION[self::EGW_SESSION_VAR] = array(
@@ -730,7 +729,7 @@  discard block
 block discarded – undo
730 729
 	* @param int $account_id =0 numerical account_id
731 730
 	* @return int $sessionid primary key of egw_access_log for login, null otherwise
732 731
 	*/
733
-	private function log_access($sessionid,$login='',$user_ip='',$account_id=0)
732
+	private function log_access($sessionid, $login = '', $user_ip = '', $account_id = 0)
734 733
 	{
735 734
 		$now = time();
736 735
 
@@ -743,7 +742,7 @@  discard block
 block discarded – undo
743 742
 
744 743
 		if ($login)
745 744
 		{
746
-			$GLOBALS['egw']->db->insert(self::ACCESS_LOG_TABLE,array(
745
+			$GLOBALS['egw']->db->insert(self::ACCESS_LOG_TABLE, array(
747 746
 				'session_php' => $sessionid,
748 747
 				'loginid'   => $login,
749 748
 				'ip'        => $user_ip,
@@ -751,20 +750,20 @@  discard block
 block discarded – undo
751 750
 				'account_id'=> $account_id,
752 751
 				'user_agent'=> $_SERVER['HTTP_USER_AGENT'],
753 752
 				'session_dla'    => $now,
754
-				'session_action' => $this->update_dla(false),	// dont update egw_access_log
755
-			),false,__LINE__,__FILE__);
753
+				'session_action' => $this->update_dla(false), // dont update egw_access_log
754
+			), false, __LINE__, __FILE__);
756 755
 
757
-			$ret = $GLOBALS['egw']->db->get_last_insert_id(self::ACCESS_LOG_TABLE,'sessionid');
756
+			$ret = $GLOBALS['egw']->db->get_last_insert_id(self::ACCESS_LOG_TABLE, 'sessionid');
758 757
 
759 758
 			// if we can not store failed login attempts in database, store it in cache
760 759
 			if (!$ret && !$account_id)
761 760
 			{
762 761
 				Cache::setInstance(__CLASS__, self::FALSE_IP_CACHE_PREFIX.$user_ip,
763
-					1+Cache::getInstance(__CLASS__, self::FALSE_IP_CACHE_PREFIX.$user_ip),
762
+					1 + Cache::getInstance(__CLASS__, self::FALSE_IP_CACHE_PREFIX.$user_ip),
764 763
 					$GLOBALS['egw_info']['server']['block_time'] * 60);
765 764
 
766 765
 				Cache::setInstance(__CLASS__, self::FALSE_ID_CACHE_PREFIX.$login,
767
-					1+Cache::getInstance(__CLASS__, self::FALSE_ID_CACHE_PREFIX.$login),
766
+					1 + Cache::getInstance(__CLASS__, self::FALSE_ID_CACHE_PREFIX.$login),
768 767
 					$GLOBALS['egw_info']['server']['block_time'] * 60);
769 768
 			}
770 769
 		}
@@ -774,20 +773,20 @@  discard block
 block discarded – undo
774 773
 			{
775 774
 				$sessionid = $this->sessionid_access_log;
776 775
 			}
777
-			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array(
776
+			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array(
778 777
 				'lo' => $now
779
-			),is_numeric($sessionid) ? array(
778
+			), is_numeric($sessionid) ? array(
780 779
 				'sessionid' => $sessionid,
781 780
 			) : array(
782 781
 				'session_php' => $sessionid,
783
-			),__LINE__,__FILE__);
782
+			), __LINE__, __FILE__);
784 783
 
785 784
 			// run maintenance only on logout, to not delay login
786 785
 			if ($GLOBALS['egw_info']['server']['max_access_log_age'])
787 786
 			{
788 787
 				$max_age = $now - $GLOBALS['egw_info']['server']['max_access_log_age'] * 24 * 60 * 60;
789 788
 
790
-				$GLOBALS['egw']->db->delete(self::ACCESS_LOG_TABLE,"li < $max_age",__LINE__,__FILE__);
789
+				$GLOBALS['egw']->db->delete(self::ACCESS_LOG_TABLE, "li < $max_age", __LINE__, __FILE__);
791 790
 			}
792 791
 		}
793 792
 		//error_log(__METHOD__."('$sessionid', '$login', '$user_ip', $account_id) returning ".array2string($ret));
@@ -801,12 +800,12 @@  discard block
 block discarded – undo
801 800
 	 * @param string $ip ip of the user
802 801
 	 * @returns bool login blocked?
803 802
 	 */
804
-	private function login_blocked($login,$ip)
803
+	private function login_blocked($login, $ip)
805 804
 	{
806 805
 		$block_time = time() - $GLOBALS['egw_info']['server']['block_time'] * 60;
807 806
 
808 807
 		$false_id = $false_ip = 0;
809
-		foreach($GLOBALS['egw']->db->union(array(
808
+		foreach ($GLOBALS['egw']->db->union(array(
810 809
 			array(
811 810
 				'table' => self::ACCESS_LOG_TABLE,
812 811
 				'cols'  => "'false_ip' AS name,COUNT(*) AS num",
@@ -849,7 +848,7 @@  discard block
 block discarded – undo
849 848
 		if (!empty($GLOBALS['egw_info']['server']['unsuccessful_ip_whitelist']) &&
850 849
 			preg_match_all('/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(:\d+)?/',
851 850
 				$GLOBALS['egw_info']['server']['unsuccessful_ip_whitelist'], $matches) &&
852
-			($key=array_search($ip, $matches[1])) !== false)
851
+			($key = array_search($ip, $matches[1])) !== false)
853 852
 		{
854 853
 			$blocked = !empty($matches[3][$key]) && $false_ip > $matches[3][$key];
855 854
 		}
@@ -864,28 +863,28 @@  discard block
 block discarded – undo
864 863
 		//error_log(__METHOD__."('$login', '$ip') false_ip=$false_ip, false_id=$false_id --> blocked=".array2string($blocked));
865 864
 
866 865
 		if ($blocked && $GLOBALS['egw_info']['server']['admin_mails'] &&
867
-			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60)	// max. one mail every 5mins
866
+			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time() - 5 * 60)	// max. one mail every 5mins
868 867
 		{
869 868
 			try {
870 869
 				$mailer = new Mailer();
871 870
 				// notify admin(s) via email
872 871
 				$mailer->setFrom('eGroupWare@'.$GLOBALS['egw_info']['server']['mail_suffix']);
873
-				$mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2",$login,$ip));
874
-				$mailer->setBody(lang("Too many unsucessful attempts to login: %1 for the user '%2', %3 for the IP %4",$false_id,$login,$false_ip,$ip));
875
-				foreach(preg_split('/,\s*/',$GLOBALS['egw_info']['server']['admin_mails']) as $mail)
872
+				$mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2", $login, $ip));
873
+				$mailer->setBody(lang("Too many unsucessful attempts to login: %1 for the user '%2', %3 for the IP %4", $false_id, $login, $false_ip, $ip));
874
+				foreach (preg_split('/,\s*/', $GLOBALS['egw_info']['server']['admin_mails']) as $mail)
876 875
 				{
877 876
 					$mailer->addAddress($mail);
878 877
 				}
879 878
 				$mailer->send();
880 879
 			}
881
-			catch(\Exception $e) {
880
+			catch (\Exception $e) {
882 881
 				// ignore exception, but log it, to block the account and give a correct error-message to user
883 882
 				error_log(__METHOD__."('$login', '$ip') ".$e->getMessage());
884 883
 			}
885 884
 			// save time of mail, to not send to many mails
886 885
 			$config = new Config('phpgwapi');
887 886
 			$config->read_repository();
888
-			$config->value('login_blocked_mail_time',time());
887
+			$config->value('login_blocked_mail_time', time());
889 888
 			$config->save_repository();
890 889
 		}
891 890
 		return $blocked;
@@ -906,7 +905,7 @@  discard block
 block discarded – undo
906 905
 	 * @param boolean $only_basic_auth =false return only a basic auth pseudo sessionid, default no
907 906
 	 * @return string
908 907
 	 */
909
-	static function get_sessionid($only_basic_auth=false)
908
+	static function get_sessionid($only_basic_auth = false)
910 909
 	{
911 910
 		// for WebDAV and GroupDAV we use a pseudo sessionid created from md5(user:passwd)
912 911
 		// --> allows this stateless protocolls which use basic auth to use sessions!
@@ -933,11 +932,11 @@  discard block
 block discarded – undo
933 932
 				EGW_SERVER_ROOT.':'.self::getuser_ip().':'.filemtime(EGW_SERVER_ROOT.'/api/setup/setup.inc.php').
934 933
 				':'.$_SERVER['HTTP_USER_AGENT']);
935 934
 		}
936
-		elseif(!$only_basic_auth && isset($_REQUEST[self::EGW_SESSION_NAME]))
935
+		elseif (!$only_basic_auth && isset($_REQUEST[self::EGW_SESSION_NAME]))
937 936
 		{
938 937
 			$sessionid = $_REQUEST[self::EGW_SESSION_NAME];
939 938
 		}
940
-		elseif(!$only_basic_auth && isset($_COOKIE[self::EGW_SESSION_NAME]))
939
+		elseif (!$only_basic_auth && isset($_COOKIE[self::EGW_SESSION_NAME]))
941 940
 		{
942 941
 			$sessionid = $_COOKIE[self::EGW_SESSION_NAME];
943 942
 		}
@@ -945,7 +944,7 @@  discard block
 block discarded – undo
945 944
 		{
946 945
 			$sessionid = false;
947 946
 		}
948
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true));
947
+		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid, true));
949 948
 		return $sessionid;
950 949
 	}
951 950
 
@@ -961,9 +960,7 @@  discard block
 block discarded – undo
961 960
 	 */
962 961
 	static function get_request($name)
963 962
 	{
964
-		return isset($_REQUEST[$name]) ? $_REQUEST[$name] :
965
-			(isset($_COOKIE[$name]) ? $_COOKIE[$name] :
966
-			(isset($_COOKIE[$name=ucfirst($name)]) ? $_COOKIE[$name] : null));
963
+		return isset($_REQUEST[$name]) ? $_REQUEST[$name] : (isset($_COOKIE[$name]) ? $_COOKIE[$name] : (isset($_COOKIE[$name = ucfirst($name)]) ? $_COOKIE[$name] : null));
967 964
 	}
968 965
 
969 966
 	/**
@@ -973,13 +970,13 @@  discard block
 block discarded – undo
973 970
 	 * @param string $kp3 ?? to be verified
974 971
 	 * @return bool is the session valid?
975 972
 	 */
976
-	function verify($sessionid=null,$kp3=null)
973
+	function verify($sessionid = null, $kp3 = null)
977 974
 	{
978 975
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace());
979 976
 
980 977
 		$fill_egw_info_and_repositories = !$GLOBALS['egw_info']['flags']['restored_from_session'];
981 978
 
982
-		if(!$sessionid)
979
+		if (!$sessionid)
983 980
 		{
984 981
 			$sessionid = self::get_sessionid();
985 982
 			$kp3       = self::get_request('kp3');
@@ -1015,23 +1012,23 @@  discard block
 block discarded – undo
1015 1012
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session does NOT exist!");
1016 1013
 			return false;
1017 1014
 		}
1018
-		$session =& $_SESSION[self::EGW_SESSION_VAR];
1015
+		$session = & $_SESSION[self::EGW_SESSION_VAR];
1019 1016
 
1020 1017
 		if ($session['session_dla'] <= time() - $GLOBALS['egw_info']['server']['sessions_timeout'])
1021 1018
 		{
1022 1019
 			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session timed out!");
1023
-			$this->destroy($sessionid,$kp3);
1020
+			$this->destroy($sessionid, $kp3);
1024 1021
 			return false;
1025 1022
 		}
1026 1023
 
1027 1024
 		$this->session_flags = $session['session_flags'];
1028 1025
 
1029
-		$this->split_login_domain($session['session_lid'],$this->account_lid,$this->account_domain);
1026
+		$this->split_login_domain($session['session_lid'], $this->account_lid, $this->account_domain);
1030 1027
 
1031 1028
 		// This is to ensure that we authenticate to the correct domain (might not be default)
1032
-		if($GLOBALS['egw_info']['user']['domain'] && $this->account_domain != $GLOBALS['egw_info']['user']['domain'])
1029
+		if ($GLOBALS['egw_info']['user']['domain'] && $this->account_domain != $GLOBALS['egw_info']['user']['domain'])
1033 1030
 		{
1034
-			return false;	// session not verified, domain changed
1031
+			return false; // session not verified, domain changed
1035 1032
 		}
1036 1033
 		$GLOBALS['egw_info']['user']['kp3'] = $this->kp3;
1037 1034
 
@@ -1044,7 +1041,7 @@  discard block
 block discarded – undo
1044 1041
 		{
1045 1042
 			$this->update_notification_heartbeat();
1046 1043
 		}
1047
-		$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u');
1044
+		$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid, 'account_lid', 'u');
1048 1045
 		if (!$this->account_id)
1049 1046
 		{
1050 1047
 			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')");
@@ -1091,7 +1088,7 @@  discard block
 block discarded – undo
1091 1088
 
1092 1089
 		if ($GLOBALS['egw_info']['server']['sessions_checkip'])
1093 1090
 		{
1094
-			if (strtoupper(substr(PHP_OS,0,3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] ||
1091
+			if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] ||
1095 1092
 				$GLOBALS['egw_info']['user']['session_ip'] != $this->getuser_ip()))
1096 1093
 			{
1097 1094
 				if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong IP");
@@ -1114,9 +1111,9 @@  discard block
 block discarded – undo
1114 1111
 		// query accesslog-id, if not set in session (session is made persistent after login!)
1115 1112
 		if (!$this->sessionid_access_log && $this->session_flags != 'A')
1116 1113
 		{
1117
-			$this->sessionid_access_log = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'sessionid',array(
1114
+			$this->sessionid_access_log = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, 'sessionid', array(
1118 1115
 				'session_php' => $this->sessionid,
1119
-			),__LINE__,__FILE__)->fetchColumn();
1116
+			), __LINE__, __FILE__)->fetchColumn();
1120 1117
 			//error_log(__METHOD__."() sessionid=$this->sessionid --> sessionid_access_log=$this->sessionid_access_log");
1121 1118
 		}
1122 1119
 
@@ -1127,9 +1124,9 @@  discard block
 block discarded – undo
1127 1124
 			(!isset($_COOKIE[self::EGW_SESSION_NAME]) || $_COOKIE[self::EGW_SESSION_NAME] !== $_REQUEST[self::EGW_SESSION_NAME]))
1128 1125
 		{
1129 1126
 			if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now");
1130
-			self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid);
1131
-			self::egw_setcookie('kp3',$this->kp3);
1132
-			self::egw_setcookie('domain',$this->account_domain);
1127
+			self::egw_setcookie(self::EGW_SESSION_NAME, $this->sessionid);
1128
+			self::egw_setcookie('kp3', $this->kp3);
1129
+			self::egw_setcookie('domain', $this->account_domain);
1133 1130
 		}
1134 1131
 
1135 1132
 		if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS");
@@ -1144,27 +1141,27 @@  discard block
 block discarded – undo
1144 1141
 	 * @param string $kp3
1145 1142
 	 * @return boolean true on success, false on error
1146 1143
 	 */
1147
-	function destroy($sessionid, $kp3='')
1144
+	function destroy($sessionid, $kp3 = '')
1148 1145
 	{
1149 1146
 		if (!$sessionid && $kp3)
1150 1147
 		{
1151 1148
 			return false;
1152 1149
 		}
1153
-		$this->log_access($sessionid);	// log logout-time
1150
+		$this->log_access($sessionid); // log logout-time
1154 1151
 
1155 1152
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($sessionid,$kp3)");
1156 1153
 
1157 1154
 		if (is_numeric($sessionid))	// do we have a access-log-id --> get PHP session id
1158 1155
 		{
1159
-			$sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'session_php',array(
1156
+			$sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, 'session_php', array(
1160 1157
 					'sessionid' => $sessionid,
1161
-				),__LINE__,__FILE__)->fetchColumn();
1158
+				), __LINE__, __FILE__)->fetchColumn();
1162 1159
 		}
1163 1160
 
1164 1161
 		Hooks::process(array(
1165 1162
 			'location'  => 'session_destroyed',
1166 1163
 			'sessionid' => $sessionid,
1167
-		),'',true);	// true = run hooks from all apps, not just the ones the current user has perms to run
1164
+		), '', true); // true = run hooks from all apps, not just the ones the current user has perms to run
1168 1165
 
1169 1166
 		// Only do the following, if where working with the current user
1170 1167
 		if (!$GLOBALS['egw_info']['user']['sessionid'] || $sessionid == $GLOBALS['egw_info']['user']['sessionid'])
@@ -1185,7 +1182,7 @@  discard block
 block discarded – undo
1185 1182
 		}
1186 1183
 		else
1187 1184
 		{
1188
-			$this->commit_session();	// close our own session
1185
+			$this->commit_session(); // close our own session
1189 1186
 
1190 1187
 			session_id($sessionid);
1191 1188
 			if (session_start())
@@ -1225,25 +1222,25 @@  discard block
 block discarded – undo
1225 1222
 		// as $webserver_url may be part of $url (as /egw is part of phpgwapi/js/egw_instant_load.html)
1226 1223
 		if (($url[0] != '/' || $webserver_url != '/') && (!$webserver_url || strpos($url, $webserver_url.'/') === false))
1227 1224
 		{
1228
-			if($url[0] != '/' && substr($webserver_url,-1) != '/')
1225
+			if ($url[0] != '/' && substr($webserver_url, -1) != '/')
1229 1226
 			{
1230
-				$url = $webserver_url .'/'. $url;
1227
+				$url = $webserver_url.'/'.$url;
1231 1228
 			}
1232 1229
 			else
1233 1230
 			{
1234
-				$url = $webserver_url . $url;
1231
+				$url = $webserver_url.$url;
1235 1232
 			}
1236 1233
 		}
1237 1234
 
1238
-		if(isset($GLOBALS['egw_info']['server']['enforce_ssl']) && $GLOBALS['egw_info']['server']['enforce_ssl'])
1235
+		if (isset($GLOBALS['egw_info']['server']['enforce_ssl']) && $GLOBALS['egw_info']['server']['enforce_ssl'])
1239 1236
 		{
1240
-			if(substr($url ,0,4) != 'http')
1237
+			if (substr($url, 0, 4) != 'http')
1241 1238
 			{
1242 1239
 				$url = 'https://'.$_SERVER['HTTP_HOST'].$url;
1243 1240
 			}
1244 1241
 			else
1245 1242
 			{
1246
-				$url = str_replace ( 'http:', 'https:', $url);
1243
+				$url = str_replace('http:', 'https:', $url);
1247 1244
 			}
1248 1245
 		}
1249 1246
 		$vars = array();
@@ -1256,7 +1253,7 @@  discard block
 block discarded – undo
1256 1253
 		}
1257 1254
 
1258 1255
 		// check if the url already contains a query and ensure that vars is an array and all strings are in extravars
1259
-		list($ret_url,$othervars) = explode('?', $url, 2);
1256
+		list($ret_url, $othervars) = explode('?', $url, 2);
1260 1257
 		if ($extravars && is_array($extravars))
1261 1258
 		{
1262 1259
 			$vars += $extravars;
@@ -1264,19 +1261,19 @@  discard block
 block discarded – undo
1264 1261
 		}
1265 1262
 		else
1266 1263
 		{
1267
-			if ($othervars) $extravars .= ($extravars?'&':'').$othervars;
1264
+			if ($othervars) $extravars .= ($extravars ? '&' : '').$othervars;
1268 1265
 		}
1269 1266
 
1270 1267
 		// parse extravars string into the vars array
1271 1268
 		if ($extravars)
1272 1269
 		{
1273
-			foreach(explode('&',$extravars) as $expr)
1270
+			foreach (explode('&', $extravars) as $expr)
1274 1271
 			{
1275
-				list($var,$val) = explode('=', $expr,2);
1276
-				if (strpos($val,'%26') != false) $val = str_replace('%26','&',$val);	// make sure to not double encode &
1277
-				if (substr($var,-2) == '[]')
1272
+				list($var, $val) = explode('=', $expr, 2);
1273
+				if (strpos($val, '%26') != false) $val = str_replace('%26', '&', $val); // make sure to not double encode &
1274
+				if (substr($var, -2) == '[]')
1278 1275
 				{
1279
-					$vars[substr($var,0,-2)][] = $val;
1276
+					$vars[substr($var, 0, -2)][] = $val;
1280 1277
 				}
1281 1278
 				else
1282 1279
 				{
@@ -1289,11 +1286,11 @@  discard block
 block discarded – undo
1289 1286
 		if (count($vars))
1290 1287
 		{
1291 1288
 			$query = array();
1292
-			foreach($vars as $key => $value)
1289
+			foreach ($vars as $key => $value)
1293 1290
 			{
1294 1291
 				if (is_array($value))
1295 1292
 				{
1296
-					foreach($value as $val)
1293
+					foreach ($value as $val)
1297 1294
 					{
1298 1295
 						$query[] = $key.'[]='.urlencode($val);
1299 1296
 					}
@@ -1303,7 +1300,7 @@  discard block
 block discarded – undo
1303 1300
 					$query[] = $key.'='.urlencode($value);
1304 1301
 				}
1305 1302
 			}
1306
-			$ret_url .= '?' . implode('&',$query);
1303
+			$ret_url .= '?'.implode('&', $query);
1307 1304
 		}
1308 1305
 		return $ret_url;
1309 1306
 	}
@@ -1319,8 +1316,7 @@  discard block
 block discarded – undo
1319 1316
 	public static function getuser_ip()
1320 1317
 	{
1321 1318
 		return isset($_SERVER['HTTP_X_FORWARDED_FOR']) ?
1322
-			preg_replace('/, *10\..*$/', '', $_SERVER['HTTP_X_FORWARDED_FOR']) :
1323
-			$_SERVER['REMOTE_ADDR'];
1319
+			preg_replace('/, *10\..*$/', '', $_SERVER['HTTP_X_FORWARDED_FOR']) : $_SERVER['REMOTE_ADDR'];
1324 1320
 	}
1325 1321
 
1326 1322
 	/**
@@ -1353,7 +1349,7 @@  discard block
 block discarded – undo
1353 1349
 	 * @param int $cookietime =0 when cookie should expire, 0 for session only (optional)
1354 1350
 	 * @param string $cookiepath =null optional path (eg. '/') if the eGW install-dir should not be used
1355 1351
 	 */
1356
-	public static function egw_setcookie($cookiename,$cookievalue='',$cookietime=0,$cookiepath=null)
1352
+	public static function egw_setcookie($cookiename, $cookievalue = '', $cookietime = 0, $cookiepath = null)
1357 1353
 	{
1358 1354
 		if (empty(self::$cookie_domain) || empty(self::$cookie_path))
1359 1355
 		{
@@ -1366,11 +1362,11 @@  discard block
 block discarded – undo
1366 1362
 		static $is_iOS = null;
1367 1363
 		if (!$cookietime && !isset($is_iOS)) $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile());
1368 1364
 
1369
-		if(!headers_sent())	// gives only a warning, but can not send the cookie anyway
1365
+		if (!headers_sent())	// gives only a warning, but can not send the cookie anyway
1370 1366
 		{
1371 1367
 			setcookie($cookiename, $cookievalue,
1372
-				!$cookietime && $is_iOS ? time()+self::IOS_SESSION_COOKIE_LIFETIME : $cookietime,
1373
-				is_null($cookiepath) ? self::$cookie_path : $cookiepath,self::$cookie_domain,
1368
+				!$cookietime && $is_iOS ? time() + self::IOS_SESSION_COOKIE_LIFETIME : $cookietime,
1369
+				is_null($cookiepath) ? self::$cookie_path : $cookiepath, self::$cookie_domain,
1374 1370
 				// if called via HTTPS, only send cookie for https and only allow cookie access via HTTP (true)
1375 1371
 				empty($GLOBALS['egw_info']['server']['insecure_cookies']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off', true);
1376 1372
 		}
@@ -1389,21 +1385,21 @@  discard block
 block discarded – undo
1389 1385
 		else
1390 1386
 		{
1391 1387
 			// Use HTTP_X_FORWARDED_HOST if set, which is the case behind a none-transparent proxy
1392
-			self::$cookie_domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ?  $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'];
1388
+			self::$cookie_domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'];
1393 1389
 		}
1394 1390
 		// remove port from HTTP_HOST
1395 1391
 		$arr = null;
1396
-		if (preg_match("/^(.*):(.*)$/",self::$cookie_domain,$arr))
1392
+		if (preg_match("/^(.*):(.*)$/", self::$cookie_domain, $arr))
1397 1393
 		{
1398 1394
 			self::$cookie_domain = $arr[1];
1399 1395
 		}
1400
-		if (count(explode('.',self::$cookie_domain)) <= 1)
1396
+		if (count(explode('.', self::$cookie_domain)) <= 1)
1401 1397
 		{
1402 1398
 			// setcookie dont likes domains without dots, leaving it empty, gets setcookie to fill the domain in
1403 1399
 			self::$cookie_domain = '';
1404 1400
 		}
1405 1401
 		if (!$GLOBALS['egw_info']['server']['cookiepath'] ||
1406
-			!(self::$cookie_path = parse_url($GLOBALS['egw_info']['server']['webserver_url'],PHP_URL_PATH)))
1402
+			!(self::$cookie_path = parse_url($GLOBALS['egw_info']['server']['webserver_url'], PHP_URL_PATH)))
1407 1403
 		{
1408 1404
 			self::$cookie_path = '/';
1409 1405
 		}
@@ -1423,7 +1419,7 @@  discard block
 block discarded – undo
1423 1419
 	 * @param array $domains =null defaults to $GLOBALS['egw_domain'] from the header
1424 1420
 	 * @return string $GLOBALS['egw_info']['user']['domain'] set with the domain/instance to use
1425 1421
 	 */
1426
-	public static function search_instance($login,$domain_requested,&$default_domain,$server_names,array $domains=null)
1422
+	public static function search_instance($login, $domain_requested, &$default_domain, $server_names, array $domains = null)
1427 1423
 	{
1428 1424
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")");
1429 1425
 
@@ -1431,10 +1427,10 @@  discard block
 block discarded – undo
1431 1427
 
1432 1428
 		if (!isset($default_domain) || !isset($domains[$default_domain]))	// allow to overwrite the default domain
1433 1429
 		{
1434
-			foreach((array)$server_names as $server_name)
1430
+			foreach ((array)$server_names as $server_name)
1435 1431
 			{
1436
-				list($server_name) = explode(':', $server_name);	// remove port from HTTP_HOST
1437
-				if(isset($domains[$server_name]))
1432
+				list($server_name) = explode(':', $server_name); // remove port from HTTP_HOST
1433
+				if (isset($domains[$server_name]))
1438 1434
 				{
1439 1435
 					$default_domain = $server_name;
1440 1436
 					break;
@@ -1444,7 +1440,7 @@  discard block
 block discarded – undo
1444 1440
 					$parts = explode('.', $server_name);
1445 1441
 					array_shift($parts);
1446 1442
 					$domain_part = implode('.', $parts);
1447
-					if(isset($domains[$domain_part]))
1443
+					if (isset($domains[$domain_part]))
1448 1444
 					{
1449 1445
 						$default_domain = $domain_part;
1450 1446
 						break;
@@ -1460,11 +1456,11 @@  discard block
 block discarded – undo
1460 1456
 		}
1461 1457
 		if (isset($login))	// on login
1462 1458
 		{
1463
-			if (strpos($login,'@') === false || count($domains) == 1)
1459
+			if (strpos($login, '@') === false || count($domains) == 1)
1464 1460
 			{
1465
-				$login .= '@' . (isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain);
1461
+				$login .= '@'.(isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain);
1466 1462
 			}
1467
-			$parts = explode('@',$login);
1463
+			$parts = explode('@', $login);
1468 1464
 			$domain = array_pop($parts);
1469 1465
 			$GLOBALS['login'] = $login;
1470 1466
 		}
@@ -1503,7 +1499,7 @@  discard block
 block discarded – undo
1503 1499
 	 * @param boolean $update_access_log =false false: dont update egw_access_log table, but set $this->action
1504 1500
 	 * @return string action as written to egw_access_log.session_action
1505 1501
 	 */
1506
-	private function update_dla($update_access_log=false)
1502
+	private function update_dla($update_access_log = false)
1507 1503
 	{
1508 1504
 		// This way XML-RPC users aren't always listed as xmlrpc.php
1509 1505
 		if (!$update_access_log)
@@ -1521,14 +1517,14 @@  discard block
 block discarded – undo
1521 1517
 				$action = $_SERVER['PHP_SELF'];
1522 1518
 				// remove EGroupware path, if not installed in webroot
1523 1519
 				$egw_path = $GLOBALS['egw_info']['server']['webserver_url'];
1524
-				if ($egw_path[0] != '/') $egw_path = parse_url($egw_path,PHP_URL_PATH);
1520
+				if ($egw_path[0] != '/') $egw_path = parse_url($egw_path, PHP_URL_PATH);
1525 1521
 				if ($action == '/Microsoft-Server-ActiveSync')
1526 1522
 				{
1527 1523
 					$action .= '?Cmd='.$_GET['Cmd'].'&DeviceId='.$_GET['DeviceId'];
1528 1524
 				}
1529 1525
 				elseif ($egw_path)
1530 1526
 				{
1531
-					list(,$action) = explode($egw_path,$action,2);
1527
+					list(,$action) = explode($egw_path, $action, 2);
1532 1528
 				}
1533 1529
 			}
1534 1530
 			$this->set_action($action);
@@ -1536,14 +1532,14 @@  discard block
 block discarded – undo
1536 1532
 		// update dla in access-log table, if we have an access-log row (non-anonymous session)
1537 1533
 		if ($this->sessionid_access_log && $update_access_log && is_object($GLOBALS['egw']->db))
1538 1534
 		{
1539
-			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array(
1535
+			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array(
1540 1536
 				'session_dla' => time(),
1541 1537
 				'session_action' => $this->action,
1542 1538
 			) + ($this->action === '/logout.php' ? array() : array(
1543
-				'lo' => null,	// just in case it was (automatic) timed out before
1544
-			)),array(
1539
+				'lo' => null, // just in case it was (automatic) timed out before
1540
+			)), array(
1545 1541
 				'sessionid' => $this->sessionid_access_log,
1546
-			),__LINE__,__FILE__);
1542
+			), __LINE__, __FILE__);
1547 1543
 		}
1548 1544
 
1549 1545
 		$_SESSION[self::EGW_SESSION_VAR]['session_dla'] = time();
@@ -1561,12 +1557,12 @@  discard block
 block discarded – undo
1561 1557
 		// update dla in access-log table, if we have an access-log row (non-anonymous session)
1562 1558
 		if ($this->sessionid_access_log)
1563 1559
 		{
1564
-			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array(
1560
+			$GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array(
1565 1561
 				'notification_heartbeat' => time(),
1566
-			),array(
1562
+			), array(
1567 1563
 				'sessionid' => $this->sessionid_access_log,
1568 1564
 				'lo IS NULL',
1569
-			),__LINE__,__FILE__);
1565
+			), __LINE__, __FILE__);
1570 1566
 		}
1571 1567
 	}
1572 1568
 
@@ -1587,7 +1583,7 @@  discard block
 block discarded – undo
1587 1583
 		{
1588 1584
 			// authentication happens in login.php, which does NOT yet create egw-object in session
1589 1585
 			// --> need to store homedirectory in session
1590
-			if(isset($GLOBALS['auto_create_acct']['homedirectory']))
1586
+			if (isset($GLOBALS['auto_create_acct']['homedirectory']))
1591 1587
 			{
1592 1588
 				Cache::setSession(__CLASS__, 'homedirectory',
1593 1589
 					$user['homedirectory'] = $GLOBALS['auto_create_acct']['homedirectory']);
@@ -1600,7 +1596,7 @@  discard block
 block discarded – undo
1600 1596
 		$user['preferences'] = $GLOBALS['egw']->preferences->read_repository();
1601 1597
 		if (is_object($GLOBALS['egw']->datetime))
1602 1598
 		{
1603
-			$GLOBALS['egw']->datetime->__construct();		// to set tz_offset from the now read prefs
1599
+			$GLOBALS['egw']->datetime->__construct(); // to set tz_offset from the now read prefs
1604 1600
 		}
1605 1601
 		$user['apps']        = $GLOBALS['egw']->applications->read_repository();
1606 1602
 		$user['domain']      = $this->account_domain;
@@ -1623,9 +1619,9 @@  discard block
 block discarded – undo
1623 1619
 	 * @param string &$account_lid returned account_lid (ie. user)
1624 1620
 	 * @param string &$domain returned domain (ie. domain)
1625 1621
 	 */
1626
-	private function split_login_domain($login,&$account_lid,&$domain)
1622
+	private function split_login_domain($login, &$account_lid, &$domain)
1627 1623
 	{
1628
-		$parts = explode('@',$login);
1624
+		$parts = explode('@', $login);
1629 1625
 
1630 1626
 		//conference - for strings like [email protected]@default ,
1631 1627
 		//allows that user have a login that is his e-mail. (viniciuscb)
@@ -1633,11 +1629,11 @@  discard block
 block discarded – undo
1633 1629
 		{
1634 1630
 			$probable_domain = array_pop($parts);
1635 1631
 			//Last part of login string, when separated by @, is a domain name
1636
-			if (in_array($probable_domain,$this->egw_domains))
1632
+			if (in_array($probable_domain, $this->egw_domains))
1637 1633
 			{
1638 1634
 				$got_login = true;
1639 1635
 				$domain = $probable_domain;
1640
-				$account_lid = implode('@',$parts);
1636
+				$account_lid = implode('@', $parts);
1641 1637
 			}
1642 1638
 		}
1643 1639
 
@@ -1660,9 +1656,9 @@  discard block
 block discarded – undo
1660 1656
 	 * @param boolean $allow_password_md5 =false can password alread be an md5 hash
1661 1657
 	 * @return string
1662 1658
 	 */
1663
-	static function user_pw_hash($user,$password,$allow_password_md5=false)
1659
+	static function user_pw_hash($user, $password, $allow_password_md5 = false)
1664 1660
 	{
1665
-		$password_md5 = $allow_password_md5 && preg_match('/^[a-f0-9]{32}$/',$password) ? $password : md5($password);
1661
+		$password_md5 = $allow_password_md5 && preg_match('/^[a-f0-9]{32}$/', $password) ? $password : md5($password);
1666 1662
 
1667 1663
 		$hash = sha1(strtolower($user).$password_md5);
1668 1664
 
@@ -1677,12 +1673,12 @@  discard block
 block discarded – undo
1677 1673
 	 */
1678 1674
 	public static function init_handler()
1679 1675
 	{
1680
-		switch(session_status())
1676
+		switch (session_status())
1681 1677
 		{
1682 1678
 			case PHP_SESSION_DISABLED:
1683 1679
 				throw new \ErrorException('EGroupware requires PHP session extension!');
1684 1680
 			case PHP_SESSION_NONE:
1685
-				ini_set('session.use_cookies',0);	// disable the automatic use of cookies, as it uses the path / by default
1681
+				ini_set('session.use_cookies', 0); // disable the automatic use of cookies, as it uses the path / by default
1686 1682
 				session_name(self::EGW_SESSION_NAME);
1687 1683
 				if (($sessionid = self::get_sessionid()))
1688 1684
 				{
@@ -1695,7 +1691,7 @@  discard block
 block discarded – undo
1695 1691
 				}
1696 1692
 				break;
1697 1693
 			case PHP_SESSION_ACTIVE:
1698
-				return true;	// session created by MServer
1694
+				return true; // session created by MServer
1699 1695
 		}
1700 1696
 		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() no active session!");
1701 1697
 
@@ -1713,7 +1709,7 @@  discard block
 block discarded – undo
1713 1709
 	 * @param int $expire =null expiration time in seconds, default $GLOBALS['egw_info']['flags']['nocachecontrol'] or php.ini session.cache_expire
1714 1710
 	 * @param int $private =null allows to set private caching with given expiration time, by setting it to true
1715 1711
 	 */
1716
-	public static function cache_control($expire=null, $private=null)
1712
+	public static function cache_control($expire = null, $private = null)
1717 1713
 	{
1718 1714
 		if (is_null($expire) && isset($GLOBALS['egw_info']['flags']['nocachecontrol']) && is_int($GLOBALS['egw_info']['flags']['nocachecontrol']))
1719 1715
 		{
@@ -1723,7 +1719,7 @@  discard block
 block discarded – undo
1723 1719
 		if (!isset($_SESSION))
1724 1720
 		{
1725 1721
 			// controling caching and expires header
1726
-			if(!isset($expire) && (!isset($GLOBALS['egw_info']['flags']['nocachecontrol']) ||
1722
+			if (!isset($expire) && (!isset($GLOBALS['egw_info']['flags']['nocachecontrol']) ||
1727 1723
 				!$GLOBALS['egw_info']['flags']['nocachecontrol']))
1728 1724
 			{
1729 1725
 				session_cache_limiter('nocache');
@@ -1733,7 +1729,7 @@  discard block
 block discarded – undo
1733 1729
 				// allow public caching: proxys, cdns, ...
1734 1730
 				if (isset($expire))
1735 1731
 				{
1736
-					session_cache_expire((int)ceil($expire/60));	// in minutes
1732
+					session_cache_expire((int)ceil($expire / 60)); // in minutes
1737 1733
 				}
1738 1734
 				session_cache_limiter($private ? 'private' : 'public');
1739 1735
 			}
@@ -1746,8 +1742,8 @@  discard block
 block discarded – undo
1746 1742
 		// session already started
1747 1743
 		if (isset($_SESSION))
1748 1744
 		{
1749
-			if ($expire && (session_cache_limiter() !== ($expire===true?'private_no_expire':'public') ||
1750
-				is_int($expire) && $expire/60 !== session_cache_expire()))
1745
+			if ($expire && (session_cache_limiter() !== ($expire === true ? 'private_no_expire' : 'public') ||
1746
+				is_int($expire) && $expire / 60 !== session_cache_expire()))
1751 1747
 			{
1752 1748
 				$file = $line = null;
1753 1749
 				if (headers_sent($file, $line))
@@ -1755,20 +1751,20 @@  discard block
 block discarded – undo
1755 1751
 					error_log(__METHOD__."($expire) called, but header already sent in $file: $line");
1756 1752
 					return;
1757 1753
 				}
1758
-				if($expire === true)	// same behavior as session_cache_limiter('private_no_expire')
1754
+				if ($expire === true)	// same behavior as session_cache_limiter('private_no_expire')
1759 1755
 				{
1760
-					header('Cache-Control: private, max-age='.(60*session_cache_expire()));
1756
+					header('Cache-Control: private, max-age='.(60 * session_cache_expire()));
1761 1757
 					header_remove('Expires');
1762 1758
 				}
1763 1759
 				elseif ($private)
1764 1760
 				{
1765 1761
 					header('Cache-Control: private, max-age='.$expire);
1766
-					header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT');
1762
+					header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expire).' GMT');
1767 1763
 				}
1768 1764
 				else
1769 1765
 				{
1770 1766
 					header('Cache-Control: public, max-age='.$expire);
1771
-					header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT');
1767
+					header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expire).' GMT');
1772 1768
 				}
1773 1769
 				// remove Pragma header, might be set by old header
1774 1770
 				if (function_exists('header_remove'))	// PHP 5.3+
@@ -1793,10 +1789,10 @@  discard block
 block discarded – undo
1793 1789
 	 * @param array $filter =array() extra filter for sessions
1794 1790
 	 * @return array with sessions (values for keys as in $sort)
1795 1791
 	 */
1796
-	public static function session_list($start,$sort='DESC',$order='session_dla',$all_no_sort=False,array $filter=array())
1792
+	public static function session_list($start, $sort = 'DESC', $order = 'session_dla', $all_no_sort = False, array $filter = array())
1797 1793
 	{
1798 1794
 		$sessions = array();
1799
-		if (!preg_match('/^[a-z0-9_ ,]+$/i',$order_by=$order.' '.$sort) || $order_by == ' ')
1795
+		if (!preg_match('/^[a-z0-9_ ,]+$/i', $order_by = $order.' '.$sort) || $order_by == ' ')
1800 1796
 		{
1801 1797
 			$order_by = 'session_dla DESC';
1802 1798
 		}
@@ -1804,7 +1800,7 @@  discard block
 block discarded – undo
1804 1800
 		$filter[] = 'account_id>0';
1805 1801
 		$filter[] = 'session_dla > '.(int)(time() - $GLOBALS['egw_info']['server']['sessions_timeout']);
1806 1802
 		$filter[] = '(notification_heartbeat IS NULL OR notification_heartbeat > '.self::heartbeat_limit().')';
1807
-		foreach($GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, '*', $filter, __LINE__, __FILE__,
1803
+		foreach ($GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, '*', $filter, __LINE__, __FILE__,
1808 1804
 			$all_no_sort ? false : $start, 'ORDER BY '.$order_by) as $row)
1809 1805
 		{
1810 1806
 			$sessions[$row['sessionid']] = $row;
@@ -1818,7 +1814,7 @@  discard block
 block discarded – undo
1818 1814
 	 * @param array $filter =array() extra filter for sessions
1819 1815
 	 * @return int number of active sessions
1820 1816
 	 */
1821
-	public static function session_count(array $filter=array())
1817
+	public static function session_count(array $filter = array())
1822 1818
 	{
1823 1819
 		$filter['lo'] = null;
1824 1820
 		$filter[] = 'account_id>0';
@@ -1834,16 +1830,16 @@  discard block
 block discarded – undo
1834 1830
 	 */
1835 1831
 	public static function heartbeat_limit()
1836 1832
 	{
1837
-		static $limit=null;
1833
+		static $limit = null;
1838 1834
 
1839 1835
 		if (is_null($limit))
1840 1836
 		{
1841 1837
 			$config = Config::read('notifications');
1842
-			if (!($popup_poll_interval  = $config['popup_poll_interval']))
1838
+			if (!($popup_poll_interval = $config['popup_poll_interval']))
1843 1839
 			{
1844 1840
 				$popup_poll_interval = 60;
1845 1841
 			}
1846
-			$limit = (int)(time() - $popup_poll_interval-10);	// 10s grace periode
1842
+			$limit = (int)(time() - $popup_poll_interval - 10); // 10s grace periode
1847 1843
 		}
1848 1844
 		return $limit;
1849 1845
 	}
Please login to merge, or discard this patch.
Braces   +176 added lines, -45 removed lines patch added patch discarded remove patch
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 
253 253
 		// set session_timeout from global php.ini and default to 14400=4h, if not set
254 254
 		if (!($GLOBALS['egw_info']['server']['sessions_timeout'] = ini_get('session.gc_maxlifetime')))
255
-      	{
255
+		{
256 256
       		ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400);
257 257
       	}
258 258
 	}
@@ -291,7 +291,10 @@  discard block
 block discarded – undo
291 291
 	 */
292 292
 	function commit_session()
293 293
 	{
294
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() sessionid=$this->sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]).' '.function_backtrace());
294
+		if (self::ERROR_LOG_DEBUG)
295
+		{
296
+			error_log(__METHOD__."() sessionid=$this->sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]).' '.function_backtrace());
297
+		}
295 298
 		self::encrypt($this->kp3);
296 299
 
297 300
 		session_write_close();
@@ -353,7 +356,10 @@  discard block
 block discarded – undo
353 356
 	 */
354 357
 	static function log_session_usage(&$arr,$label,$recursion=true,$limit=1000)
355 358
 	{
356
-		if (!is_array($arr)) return;
359
+		if (!is_array($arr))
360
+		{
361
+			return;
362
+		}
357 363
 
358 364
 		$sizes = array();
359 365
 		foreach($arr as $key => &$data)
@@ -368,7 +374,10 @@  discard block
 block discarded – undo
368 374
 			if ($diff > $limit)
369 375
 			{
370 376
 				error_log("strlen({$label}[$key])=".Vfs::hsize($size).", diff=".Vfs::hsize($diff));
371
-				if ($recursion) self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit);
377
+				if ($recursion)
378
+				{
379
+					self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit);
380
+				}
372 381
 			}
373 382
 		}
374 383
 	}
@@ -467,7 +476,10 @@  discard block
 block discarded – undo
467 476
 				$this->passwd      = $passwd;
468 477
 				$this->passwd_type = $passwd_type;
469 478
 			}
470
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ...");
479
+			if (self::ERROR_LOG_DEBUG)
480
+			{
481
+				error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ...");
482
+			}
471 483
 
472 484
 			self::split_login_domain($login,$this->account_lid,$this->account_domain);
473 485
 			// add domain to the login, if not already there
@@ -511,7 +523,10 @@  discard block
 block discarded – undo
511 523
 				{
512 524
 					$this->log_access($this->reason,$login,$user_ip,0);	// log unsuccessfull login
513 525
 				}
514
-				if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
526
+				if (self::ERROR_LOG_DEBUG)
527
+				{
528
+					error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
529
+				}
515 530
 				return false;
516 531
 			}
517 532
 
@@ -557,7 +572,10 @@  discard block
 block discarded – undo
557 572
 				$this->reason = 'account is expired';
558 573
 				$this->cd_reason = self::CD_ACCOUNT_EXPIRED;
559 574
 
560
-				if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
575
+				if (self::ERROR_LOG_DEBUG)
576
+				{
577
+					error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
578
+				}
561 579
 				return false;
562 580
 			}
563 581
 
@@ -586,7 +604,10 @@  discard block
 block discarded – undo
586 604
 					$this->cd_reason = $e->getCode();
587 605
 					$this->reason = $e->getMessage();
588 606
 					$this->log_access($this->reason, $login, $user_ip, 0);	// log unsuccessfull login
589
-					if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check,$fail_on_forced_password_change,'$check_2fa') UNSUCCESSFULL ($this->reason)");
607
+					if (self::ERROR_LOG_DEBUG)
608
+					{
609
+						error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check,$fail_on_forced_password_change,'$check_2fa') UNSUCCESSFULL ($this->reason)");
610
+					}
590 611
 					return false;
591 612
 				}
592 613
 			}
@@ -615,25 +636,34 @@  discard block
 block discarded – undo
615 636
 				'passwd'         => $this->passwd,
616 637
 				'account_domain' => $this->account_domain,
617 638
 				'user_ip'        => $user_ip,
618
-			),'',true)))	// true = run hooks from all apps, not just the ones the current user has perms to run
639
+			),'',true)))
640
+			{
641
+				// true = run hooks from all apps, not just the ones the current user has perms to run
619 642
 			{
620 643
 				foreach($hook_result as $reason)
621 644
 				{
622 645
 					if ($reason)	// called hook requests to deny the session
623 646
 					{
624 647
 						$this->reason = $this->cd_reason = $reason;
648
+			}
625 649
 						$this->log_access($this->reason,$login,$user_ip,0);		// log unsuccessfull login
626
-						if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
650
+						if (self::ERROR_LOG_DEBUG)
651
+						{
652
+							error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)");
653
+						}
627 654
 						return false;
628 655
 					}
629 656
 				}
630 657
 			}
631 658
 			$GLOBALS['egw']->db->transaction_begin();
632 659
 			$this->register_session($this->login,$user_ip,$now,$this->session_flags);
633
-			if ($this->session_flags != 'A')		// dont log anonymous sessions
660
+			if ($this->session_flags != 'A')
661
+			{
662
+				// dont log anonymous sessions
634 663
 			{
635 664
 				$this->sessionid_access_log = $this->log_access($this->sessionid,$login,$user_ip,$this->account_id);
636 665
 			}
666
+			}
637 667
 			Cache::setSession('phpgwapi', 'account_previous_login', $GLOBALS['egw']->auth->previous_login);
638 668
 			$GLOBALS['egw']->accounts->update_lastlogin($this->account_id,$user_ip);
639 669
 			$GLOBALS['egw']->db->transaction_commit();
@@ -649,7 +679,10 @@  discard block
 block discarded – undo
649 679
 				self::egw_setcookie('last_loginid', $this->account_lid ,$now+1209600); /* For 2 weeks */
650 680
 				self::egw_setcookie('last_domain',$this->account_domain,$now+1209600);
651 681
 			}
652
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid");
682
+			if (self::ERROR_LOG_DEBUG)
683
+			{
684
+				error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid");
685
+			}
653 686
 
654 687
 			// hook called once session is created
655 688
 			Hooks::process(array(
@@ -864,10 +897,13 @@  discard block
 block discarded – undo
864 897
 		//error_log(__METHOD__."('$login', '$ip') false_ip=$false_ip, false_id=$false_id --> blocked=".array2string($blocked));
865 898
 
866 899
 		if ($blocked && $GLOBALS['egw_info']['server']['admin_mails'] &&
867
-			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60)	// max. one mail every 5mins
900
+			$GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60)
901
+		{
902
+			// max. one mail every 5mins
868 903
 		{
869 904
 			try {
870 905
 				$mailer = new Mailer();
906
+		}
871 907
 				// notify admin(s) via email
872 908
 				$mailer->setFrom('eGroupWare@'.$GLOBALS['egw_info']['server']['mail_suffix']);
873 909
 				$mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2",$login,$ip));
@@ -945,7 +981,10 @@  discard block
 block discarded – undo
945 981
 		{
946 982
 			$sessionid = false;
947 983
 		}
948
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true));
984
+		if (self::ERROR_LOG_DEBUG)
985
+		{
986
+			error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true));
987
+		}
949 988
 		return $sessionid;
950 989
 	}
951 990
 
@@ -975,7 +1014,10 @@  discard block
 block discarded – undo
975 1014
 	 */
976 1015
 	function verify($sessionid=null,$kp3=null)
977 1016
 	{
978
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace());
1017
+		if (self::ERROR_LOG_DEBUG)
1018
+		{
1019
+			error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace());
1020
+		}
979 1021
 
980 1022
 		$fill_egw_info_and_repositories = !$GLOBALS['egw_info']['flags']['restored_from_session'];
981 1023
 
@@ -991,7 +1033,10 @@  discard block
 block discarded – undo
991 1033
 
992 1034
 		if (!$this->sessionid)
993 1035
 		{
994
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') get_sessionid()='".self::get_sessionid()."' No session ID");
1036
+			if (self::ERROR_LOG_DEBUG)
1037
+			{
1038
+				error_log(__METHOD__."('$sessionid') get_sessionid()='".self::get_sessionid()."' No session ID");
1039
+			}
995 1040
 			return false;
996 1041
 		}
997 1042
 
@@ -1012,14 +1057,20 @@  discard block
 block discarded – undo
1012 1057
 		// check if we have a eGroupware session --> return false if not (but dont destroy it!)
1013 1058
 		if (is_null($_SESSION) || !isset($_SESSION[self::EGW_SESSION_VAR]))
1014 1059
 		{
1015
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session does NOT exist!");
1060
+			if (self::ERROR_LOG_DEBUG)
1061
+			{
1062
+				error_log(__METHOD__."('$sessionid') session does NOT exist!");
1063
+			}
1016 1064
 			return false;
1017 1065
 		}
1018 1066
 		$session =& $_SESSION[self::EGW_SESSION_VAR];
1019 1067
 
1020 1068
 		if ($session['session_dla'] <= time() - $GLOBALS['egw_info']['server']['sessions_timeout'])
1021 1069
 		{
1022
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session timed out!");
1070
+			if (self::ERROR_LOG_DEBUG)
1071
+			{
1072
+				error_log(__METHOD__."('$sessionid') session timed out!");
1073
+			}
1023 1074
 			$this->destroy($sessionid,$kp3);
1024 1075
 			return false;
1025 1076
 		}
@@ -1047,7 +1098,10 @@  discard block
 block discarded – undo
1047 1098
 		$this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u');
1048 1099
 		if (!$this->account_id)
1049 1100
 		{
1050
-			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')");
1101
+			if (self::ERROR_LOG_DEBUG)
1102
+			{
1103
+				error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')");
1104
+			}
1051 1105
 			return false;
1052 1106
 		}
1053 1107
 
@@ -1074,7 +1128,10 @@  discard block
 block discarded – undo
1074 1128
 
1075 1129
 		if ($GLOBALS['egw']->accounts->is_expired($GLOBALS['egw_info']['user']))
1076 1130
 		{
1077
-			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) accounts is expired");
1131
+			if (self::ERROR_LOG_DEBUG)
1132
+			{
1133
+				error_log("*** Session::verify($sessionid) accounts is expired");
1134
+			}
1078 1135
 			return false;
1079 1136
 		}
1080 1137
 		$this->passwd = base64_decode(Cache::getSession('phpgwapi', 'password'));
@@ -1085,7 +1142,10 @@  discard block
 block discarded – undo
1085 1142
 		}
1086 1143
 		if ($this->account_domain != $GLOBALS['egw_info']['user']['domain'])
1087 1144
 		{
1088
-			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong domain");
1145
+			if (self::ERROR_LOG_DEBUG)
1146
+			{
1147
+				error_log("*** Session::verify($sessionid) wrong domain");
1148
+			}
1089 1149
 			return false;
1090 1150
 		}
1091 1151
 
@@ -1094,7 +1154,10 @@  discard block
 block discarded – undo
1094 1154
 			if (strtoupper(substr(PHP_OS,0,3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] ||
1095 1155
 				$GLOBALS['egw_info']['user']['session_ip'] != $this->getuser_ip()))
1096 1156
 			{
1097
-				if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong IP");
1157
+				if (self::ERROR_LOG_DEBUG)
1158
+				{
1159
+					error_log("*** Session::verify($sessionid) wrong IP");
1160
+				}
1098 1161
 				return false;
1099 1162
 			}
1100 1163
 		}
@@ -1107,7 +1170,10 @@  discard block
 block discarded – undo
1107 1170
 		}
1108 1171
 		if (!$this->account_lid)
1109 1172
 		{
1110
-			if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !account_lid");
1173
+			if (self::ERROR_LOG_DEBUG)
1174
+			{
1175
+				error_log("*** Session::verify($sessionid) !account_lid");
1176
+			}
1111 1177
 			return false;
1112 1178
 		}
1113 1179
 
@@ -1126,13 +1192,19 @@  discard block
 block discarded – undo
1126 1192
 			$_REQUEST[self::EGW_SESSION_NAME] === $this->sessionid &&
1127 1193
 			(!isset($_COOKIE[self::EGW_SESSION_NAME]) || $_COOKIE[self::EGW_SESSION_NAME] !== $_REQUEST[self::EGW_SESSION_NAME]))
1128 1194
 		{
1129
-			if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now");
1195
+			if (self::ERROR_LOG_DEBUG)
1196
+			{
1197
+				error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now");
1198
+			}
1130 1199
 			self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid);
1131 1200
 			self::egw_setcookie('kp3',$this->kp3);
1132 1201
 			self::egw_setcookie('domain',$this->account_domain);
1133 1202
 		}
1134 1203
 
1135
-		if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS");
1204
+		if (self::ERROR_LOG_DEBUG)
1205
+		{
1206
+			error_log("--> Session::verify($sessionid) SUCCESS");
1207
+		}
1136 1208
 
1137 1209
 		return true;
1138 1210
 	}
@@ -1152,14 +1224,20 @@  discard block
 block discarded – undo
1152 1224
 		}
1153 1225
 		$this->log_access($sessionid);	// log logout-time
1154 1226
 
1155
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($sessionid,$kp3)");
1227
+		if (self::ERROR_LOG_DEBUG)
1228
+		{
1229
+			error_log(__METHOD__."($sessionid,$kp3)");
1230
+		}
1156 1231
 
1157
-		if (is_numeric($sessionid))	// do we have a access-log-id --> get PHP session id
1232
+		if (is_numeric($sessionid))
1233
+		{
1234
+			// do we have a access-log-id --> get PHP session id
1158 1235
 		{
1159 1236
 			$sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'session_php',array(
1160 1237
 					'sessionid' => $sessionid,
1161 1238
 				),__LINE__,__FILE__)->fetchColumn();
1162 1239
 		}
1240
+		}
1163 1241
 
1164 1242
 		Hooks::process(array(
1165 1243
 			'location'  => 'session_destroyed',
@@ -1169,7 +1247,10 @@  discard block
 block discarded – undo
1169 1247
 		// Only do the following, if where working with the current user
1170 1248
 		if (!$GLOBALS['egw_info']['user']['sessionid'] || $sessionid == $GLOBALS['egw_info']['user']['sessionid'])
1171 1249
 		{
1172
-			if (self::ERROR_LOG_DEBUG) error_log(__METHOD__." ********* about to call session_destroy!");
1250
+			if (self::ERROR_LOG_DEBUG)
1251
+			{
1252
+				error_log(__METHOD__." ********* about to call session_destroy!");
1253
+			}
1173 1254
 			session_unset();
1174 1255
 			@session_destroy();
1175 1256
 			// we need to (re-)load the eGW session-handler, as session_destroy unloads custom session-handlers
@@ -1264,7 +1345,10 @@  discard block
 block discarded – undo
1264 1345
 		}
1265 1346
 		else
1266 1347
 		{
1267
-			if ($othervars) $extravars .= ($extravars?'&':'').$othervars;
1348
+			if ($othervars)
1349
+			{
1350
+				$extravars .= ($extravars?'&':'').$othervars;
1351
+			}
1268 1352
 		}
1269 1353
 
1270 1354
 		// parse extravars string into the vars array
@@ -1273,7 +1357,11 @@  discard block
 block discarded – undo
1273 1357
 			foreach(explode('&',$extravars) as $expr)
1274 1358
 			{
1275 1359
 				list($var,$val) = explode('=', $expr,2);
1276
-				if (strpos($val,'%26') != false) $val = str_replace('%26','&',$val);	// make sure to not double encode &
1360
+				if (strpos($val,'%26') != false)
1361
+				{
1362
+					$val = str_replace('%26','&',$val);
1363
+				}
1364
+				// make sure to not double encode &
1277 1365
 				if (substr($var,-2) == '[]')
1278 1366
 				{
1279 1367
 					$vars[substr($var,0,-2)][] = $val;
@@ -1359,14 +1447,22 @@  discard block
 block discarded – undo
1359 1447
 		{
1360 1448
 			self::set_cookiedomain();
1361 1449
 		}
1362
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($cookiename,$cookievalue,$cookietime,$cookiepath,".self::$cookie_domain.")");
1450
+		if (self::ERROR_LOG_DEBUG)
1451
+		{
1452
+			error_log(__METHOD__."($cookiename,$cookievalue,$cookietime,$cookiepath,".self::$cookie_domain.")");
1453
+		}
1363 1454
 
1364 1455
 		// if we are installed in iOS as web-app, we must not set a cookietime==0 (session-cookie),
1365 1456
 		// as every change between apps will cause the cookie to get lost
1366 1457
 		static $is_iOS = null;
1367
-		if (!$cookietime && !isset($is_iOS)) $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile());
1458
+		if (!$cookietime && !isset($is_iOS))
1459
+		{
1460
+			$is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile());
1461
+		}
1368 1462
 
1369
-		if(!headers_sent())	// gives only a warning, but can not send the cookie anyway
1463
+		if(!headers_sent())
1464
+		{
1465
+			// gives only a warning, but can not send the cookie anyway
1370 1466
 		{
1371 1467
 			setcookie($cookiename, $cookievalue,
1372 1468
 				!$cookietime && $is_iOS ? time()+self::IOS_SESSION_COOKIE_LIFETIME : $cookietime,
@@ -1374,6 +1470,7 @@  discard block
 block discarded – undo
1374 1470
 				// if called via HTTPS, only send cookie for https and only allow cookie access via HTTP (true)
1375 1471
 				empty($GLOBALS['egw_info']['server']['insecure_cookies']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off', true);
1376 1472
 		}
1473
+		}
1377 1474
 	}
1378 1475
 
1379 1476
 	/**
@@ -1425,15 +1522,25 @@  discard block
 block discarded – undo
1425 1522
 	 */
1426 1523
 	public static function search_instance($login,$domain_requested,&$default_domain,$server_names,array $domains=null)
1427 1524
 	{
1428
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")");
1525
+		if (self::ERROR_LOG_DEBUG)
1526
+		{
1527
+			error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")");
1528
+		}
1429 1529
 
1430
-		if (is_null($domains)) $domains = $GLOBALS['egw_domain'];
1530
+		if (is_null($domains))
1531
+		{
1532
+			$domains = $GLOBALS['egw_domain'];
1533
+		}
1431 1534
 
1432
-		if (!isset($default_domain) || !isset($domains[$default_domain]))	// allow to overwrite the default domain
1535
+		if (!isset($default_domain) || !isset($domains[$default_domain]))
1536
+		{
1537
+			// allow to overwrite the default domain
1433 1538
 		{
1434 1539
 			foreach((array)$server_names as $server_name)
1435 1540
 			{
1436
-				list($server_name) = explode(':', $server_name);	// remove port from HTTP_HOST
1541
+				list($server_name) = explode(':', $server_name);
1542
+		}
1543
+		// remove port from HTTP_HOST
1437 1544
 				if(isset($domains[$server_name]))
1438 1545
 				{
1439 1546
 					$default_domain = $server_name;
@@ -1458,11 +1565,14 @@  discard block
 block discarded – undo
1458 1565
 				}
1459 1566
 			}
1460 1567
 		}
1461
-		if (isset($login))	// on login
1568
+		if (isset($login))
1569
+		{
1570
+			// on login
1462 1571
 		{
1463 1572
 			if (strpos($login,'@') === false || count($domains) == 1)
1464 1573
 			{
1465 1574
 				$login .= '@' . (isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain);
1575
+		}
1466 1576
 			}
1467 1577
 			$parts = explode('@',$login);
1468 1578
 			$domain = array_pop($parts);
@@ -1476,7 +1586,10 @@  discard block
 block discarded – undo
1476 1586
 		{
1477 1587
 			$domain = $default_domain;
1478 1588
 		}
1479
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() default_domain=".array2string($default_domain).', login='.array2string($login)." returning ".array2string($domain));
1589
+		if (self::ERROR_LOG_DEBUG)
1590
+		{
1591
+			error_log(__METHOD__."() default_domain=".array2string($default_domain).', login='.array2string($login)." returning ".array2string($domain));
1592
+		}
1480 1593
 
1481 1594
 		return $domain;
1482 1595
 	}
@@ -1521,7 +1634,10 @@  discard block
 block discarded – undo
1521 1634
 				$action = $_SERVER['PHP_SELF'];
1522 1635
 				// remove EGroupware path, if not installed in webroot
1523 1636
 				$egw_path = $GLOBALS['egw_info']['server']['webserver_url'];
1524
-				if ($egw_path[0] != '/') $egw_path = parse_url($egw_path,PHP_URL_PATH);
1637
+				if ($egw_path[0] != '/')
1638
+				{
1639
+					$egw_path = parse_url($egw_path,PHP_URL_PATH);
1640
+				}
1525 1641
 				if ($action == '/Microsoft-Server-ActiveSync')
1526 1642
 				{
1527 1643
 					$action .= '?Cmd='.$_GET['Cmd'].'&DeviceId='.$_GET['DeviceId'];
@@ -1548,7 +1664,10 @@  discard block
 block discarded – undo
1548 1664
 
1549 1665
 		$_SESSION[self::EGW_SESSION_VAR]['session_dla'] = time();
1550 1666
 		$_SESSION[self::EGW_SESSION_VAR]['session_action'] = $this->action;
1551
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
1667
+		if (self::ERROR_LOG_DEBUG)
1668
+		{
1669
+			error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
1670
+		}
1552 1671
 
1553 1672
 		return $this->action;
1554 1673
 	}
@@ -1690,14 +1809,20 @@  discard block
 block discarded – undo
1690 1809
 					self::cache_control();
1691 1810
 					$ok = session_start();
1692 1811
 					self::decrypt();
1693
-					if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() sessionid=$sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
1812
+					if (self::ERROR_LOG_DEBUG)
1813
+					{
1814
+						error_log(__METHOD__."() sessionid=$sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]));
1815
+					}
1694 1816
 					return $ok;
1695 1817
 				}
1696 1818
 				break;
1697 1819
 			case PHP_SESSION_ACTIVE:
1698 1820
 				return true;	// session created by MServer
1699 1821
 		}
1700
-		if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() no active session!");
1822
+		if (self::ERROR_LOG_DEBUG)
1823
+		{
1824
+			error_log(__METHOD__."() no active session!");
1825
+		}
1701 1826
 
1702 1827
 		return false;
1703 1828
 	}
@@ -1755,9 +1880,12 @@  discard block
 block discarded – undo
1755 1880
 					error_log(__METHOD__."($expire) called, but header already sent in $file: $line");
1756 1881
 					return;
1757 1882
 				}
1758
-				if($expire === true)	// same behavior as session_cache_limiter('private_no_expire')
1883
+				if($expire === true)
1884
+				{
1885
+					// same behavior as session_cache_limiter('private_no_expire')
1759 1886
 				{
1760 1887
 					header('Cache-Control: private, max-age='.(60*session_cache_expire()));
1888
+				}
1761 1889
 					header_remove('Expires');
1762 1890
 				}
1763 1891
 				elseif ($private)
@@ -1771,10 +1899,13 @@  discard block
 block discarded – undo
1771 1899
 					header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT');
1772 1900
 				}
1773 1901
 				// remove Pragma header, might be set by old header
1774
-				if (function_exists('header_remove'))	// PHP 5.3+
1902
+				if (function_exists('header_remove'))
1903
+				{
1904
+					// PHP 5.3+
1775 1905
 				{
1776 1906
 					header_remove('Pragma');
1777 1907
 				}
1908
+				}
1778 1909
 				else
1779 1910
 				{
1780 1911
 					header('Pragma:');
Please login to merge, or discard this patch.
api/src/Framework/Login.php 1 patch
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -44,32 +44,32 @@  discard block
 block discarded – undo
44 44
 	 * @param string $extra_vars for login url
45 45
 	 * @param string $change_passwd =null string with message to render input fields for password change
46 46
 	*/
47
-	function screen($extra_vars, $change_passwd=null)
47
+	function screen($extra_vars, $change_passwd = null)
48 48
 	{
49
-		Api\Header\ContentSecurityPolicy::add('frame-src', array());	// array() no external frame-sources
49
+		Api\Header\ContentSecurityPolicy::add('frame-src', array()); // array() no external frame-sources
50 50
 
51 51
 		//error_log(__METHOD__."() this->template=$this->framework->template, this->template_dir=$this->framework->template_dir, get_class(this)=".get_class($this));
52 52
 		try {
53 53
 			$tmpl = new Template(EGW_SERVER_ROOT.$this->framework->template_dir);
54
-			$tmpl->set_file(array('login_form' => Api\Header\UserAgent::mobile()?'login_mobile.tpl':'login.tpl'));
54
+			$tmpl->set_file(array('login_form' => Api\Header\UserAgent::mobile() ? 'login_mobile.tpl' : 'login.tpl'));
55 55
 		}
56
-		catch(Api\Exception\WrongParameter $e) {
56
+		catch (Api\Exception\WrongParameter $e) {
57 57
 			unset($e);
58 58
 			$tmpl = new Template(EGW_SERVER_ROOT.'/api/templates/default');
59
-			$tmpl->set_file(array('login_form' => Api\Header\UserAgent::mobile()?'login_mobile.tpl':'login.tpl'));
59
+			$tmpl->set_file(array('login_form' => Api\Header\UserAgent::mobile() ? 'login_mobile.tpl' : 'login.tpl'));
60 60
 		}
61 61
 
62
-		$tmpl->set_var('lang_message',$GLOBALS['loginscreenmessage']);
62
+		$tmpl->set_var('lang_message', $GLOBALS['loginscreenmessage']);
63 63
 
64 64
 		// did admin disable 2FA
65 65
 		if ($GLOBALS['egw_info']['server']['2fa_required'] === 'disabled')
66 66
 		{
67
-			$tmpl->set_block('login_form','2fa_section');
67
+			$tmpl->set_block('login_form', '2fa_section');
68 68
 			$tmpl->set_var('2fa_section', '');
69 69
 		}
70 70
 		else
71 71
 		{
72
-			$tmpl->set_var('lang_2fa',lang('2-Factor-Authentication'));
72
+			$tmpl->set_var('lang_2fa', lang('2-Factor-Authentication'));
73 73
 			$tmpl->set_var('lang_2fa_help', htmlspecialchars(
74 74
 				lang('If you use "2-Factor-Authentication", please enter the code here.')));
75 75
 
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
 		// hide change-password fields, if not requested
83 83
 		if (!$change_passwd)
84 84
 		{
85
-			$tmpl->set_block('login_form','change_password');
85
+			$tmpl->set_block('login_form', 'change_password');
86 86
 			$tmpl->set_var('change_password', '');
87
-			$tmpl->set_var('lang_password',lang('password'));
87
+			$tmpl->set_var('lang_password', lang('password'));
88 88
 
89 89
 			// display login-message depending on $_GET[cd] and what's in database/header for "login_message"
90 90
 			$cd_msg = self::check_logoutcode($_GET['cd']);
@@ -105,9 +105,9 @@  discard block
 block discarded – undo
105 105
 		}
106 106
 		else
107 107
 		{
108
-			$tmpl->set_var('lang_password',lang('Old password'));
109
-			$tmpl->set_var('lang_new_password',lang('New password'));
110
-			$tmpl->set_var('lang_repeat_password',lang('Repeat password'));
108
+			$tmpl->set_var('lang_password', lang('Old password'));
109
+			$tmpl->set_var('lang_new_password', lang('New password'));
110
+			$tmpl->set_var('lang_repeat_password', lang('Repeat password'));
111 111
 			$tmpl->set_var('cd', $change_passwd);
112 112
 			$tmpl->set_var('cd_class', 'error');
113 113
 			$last_loginid = $_POST['login'];
@@ -116,56 +116,56 @@  discard block
 block discarded – undo
116 116
 			$tmpl->set_var('autofocus_login', '');
117 117
 			$tmpl->set_var('autofocus_new_passwd', 'autofocus');
118 118
 		}
119
-		if($GLOBALS['egw_info']['server']['show_domain_selectbox'])
119
+		if ($GLOBALS['egw_info']['server']['show_domain_selectbox'])
120 120
 		{
121
-			foreach(array_keys($GLOBALS['egw_domain']) as $domain)
121
+			foreach (array_keys($GLOBALS['egw_domain']) as $domain)
122 122
 			{
123 123
 				$domains[$domain] = $domain;
124 124
 			}
125 125
 			$tmpl->set_var(array(
126 126
 				'lang_domain'   => lang('domain'),
127
-				'select_domain' => Api\Html::select('logindomain',$last_domain,$domains,true,'tabindex="2"',0,false),
127
+				'select_domain' => Api\Html::select('logindomain', $last_domain, $domains, true, 'tabindex="2"', 0, false),
128 128
 			));
129 129
 		}
130 130
 		else
131 131
 		{
132 132
 			/* trick to make domain section disapear */
133
-			$tmpl->set_block('login_form','domain_selection');
134
-			$tmpl->set_var('domain_selection',$GLOBALS['egw_info']['user']['domain'] ?
135
-			Api\Html::input_hidden('logindomain',$GLOBALS['egw_info']['user']['domain']) : '');
133
+			$tmpl->set_block('login_form', 'domain_selection');
134
+			$tmpl->set_var('domain_selection', $GLOBALS['egw_info']['user']['domain'] ?
135
+			Api\Html::input_hidden('logindomain', $GLOBALS['egw_info']['user']['domain']) : '');
136 136
 
137
-			if($last_loginid !== '')
137
+			if ($last_loginid !== '')
138 138
 			{
139 139
 				reset($GLOBALS['egw_domain']);
140 140
 				$default_domain = key($GLOBALS['egw_domain']);
141 141
 
142
-				if(!empty ($last_domain) && $last_domain != $default_domain)
142
+				if (!empty ($last_domain) && $last_domain != $default_domain)
143 143
 				{
144
-					$last_loginid .= '@' . $last_domain;
144
+					$last_loginid .= '@'.$last_domain;
145 145
 				}
146 146
 			}
147 147
 		}
148 148
 
149 149
 		$config_reg = Api\Config::read('registration');
150 150
 
151
-		if($config_reg['enable_registration'])
151
+		if ($config_reg['enable_registration'])
152 152
 		{
153 153
 			$lang = $_GET['lang'] ? $_GET['lang'] : $GLOBALS['egw_info']['user']['preferences']['common']['lang'];
154 154
 			if ($config_reg['register_link'])
155 155
 			{
156
-				$reg_link='&nbsp;<a href="'. $this->framework->link('/registration/index.php','lang_code='.$lang). '&cd=no">'.lang('Sign up').'</a>';
156
+				$reg_link = '&nbsp;<a href="'.$this->framework->link('/registration/index.php', 'lang_code='.$lang).'&cd=no">'.lang('Sign up').'</a>';
157 157
 			}
158 158
 			if ($config_reg['lostpassword_link'])
159 159
 			{
160
-				$lostpw_link='&nbsp;<a href="'. $this->framework->link('/registration/index.php','menuaction=registration.registration_ui.lost_password&lang_code='.$lang). '&cd=no">'.lang('Lost password').'</a>';
160
+				$lostpw_link = '&nbsp;<a href="'.$this->framework->link('/registration/index.php', 'menuaction=registration.registration_ui.lost_password&lang_code='.$lang).'&cd=no">'.lang('Lost password').'</a>';
161 161
 			}
162 162
 			if ($config_reg['lostid_link'])
163 163
 			{
164
-				$lostid_link='&nbsp;<a href="'. $this->framework->link('/registration/index.php','menuaction=registration.registration_ui.lost_username&lang_code='.$lang). '&cd=no">'.lang('Lost Login Id').'</a>';
164
+				$lostid_link = '&nbsp;<a href="'.$this->framework->link('/registration/index.php', 'menuaction=registration.registration_ui.lost_username&lang_code='.$lang).'&cd=no">'.lang('Lost Login Id').'</a>';
165 165
 			}
166 166
 
167 167
 			/* if at least one option of "registration" is activated display the registration section */
168
-			if($config_reg['register_link'] || $config_reg['lostpassword_link'] || $config_reg['lostid_link'] )
168
+			if ($config_reg['register_link'] || $config_reg['lostpassword_link'] || $config_reg['lostid_link'])
169 169
 			{
170 170
 				$tmpl->set_var(array(
171 171
 				'register_link'     => $reg_link,
@@ -176,31 +176,31 @@  discard block
 block discarded – undo
176 176
 			else
177 177
 			{
178 178
 				/* trick to make registration section disapear */
179
-				$tmpl->set_block('login_form','registration');
180
-				$tmpl->set_var('registration','');
179
+				$tmpl->set_block('login_form', 'registration');
180
+				$tmpl->set_var('registration', '');
181 181
 			}
182 182
 		}
183 183
 
184
-		$tmpl->set_var('login_url', $GLOBALS['egw_info']['server']['webserver_url'] . '/login.php' . $extra_vars);
184
+		$tmpl->set_var('login_url', $GLOBALS['egw_info']['server']['webserver_url'].'/login.php'.$extra_vars);
185 185
 		$tmpl->set_var('version', $GLOBALS['egw_info']['server']['versions']['phpgwapi']);
186 186
 		$tmpl->set_var('login', htmlspecialchars($last_loginid));
187 187
 
188
-		$tmpl->set_var('lang_username',lang('username'));
189
-		$tmpl->set_var('lang_login',lang('login'));
188
+		$tmpl->set_var('lang_username', lang('username'));
189
+		$tmpl->set_var('lang_login', lang('login'));
190 190
 
191 191
 		$tmpl->set_var('website_title', $GLOBALS['egw_info']['server']['site_title']);
192
-		$tmpl->set_var('template_set',$this->framework->template);
192
+		$tmpl->set_var('template_set', $this->framework->template);
193 193
 
194 194
 		$var['background_file'] = self::pick_login_background($GLOBALS['egw_info']['server']['login_background_file']);
195 195
 
196 196
 		$var['logo_file'] = \EGroupware\Api\Framework::get_login_logo_or_bg_url('login_logo_file', 'login_logo');
197 197
 
198
-		$var['logo_url'] = $GLOBALS['egw_info']['server']['login_logo_url']?$GLOBALS['egw_info']['server']['login_logo_url']:'http://www.egroupware.org';
199
-		if (substr($var['logo_url'],0,4) != 'http')
198
+		$var['logo_url'] = $GLOBALS['egw_info']['server']['login_logo_url'] ? $GLOBALS['egw_info']['server']['login_logo_url'] : 'http://www.egroupware.org';
199
+		if (substr($var['logo_url'], 0, 4) != 'http')
200 200
 		{
201 201
 			$var['logo_url'] = 'http://'.$var['logo_url'];
202 202
 		}
203
-		$var['logo_title'] = $GLOBALS['egw_info']['server']['login_logo_title']?$GLOBALS['egw_info']['server']['login_logo_title']:'www.eGroupWare.org';
203
+		$var['logo_title'] = $GLOBALS['egw_info']['server']['login_logo_title'] ? $GLOBALS['egw_info']['server']['login_logo_title'] : 'www.eGroupWare.org';
204 204
 		$tmpl->set_var($var);
205 205
 
206 206
 		/* language section if activated in site Config */
@@ -208,14 +208,14 @@  discard block
 block discarded – undo
208 208
 		{
209 209
 			$tmpl->set_var(array(
210 210
 				'lang_language' => lang('Language'),
211
-				'select_language' => Api\Html::select('lang',$GLOBALS['egw_info']['user']['preferences']['common']['lang'],
212
-				Api\Translation::get_installed_langs(),true,'tabindex="1"',0,false),
211
+				'select_language' => Api\Html::select('lang', $GLOBALS['egw_info']['user']['preferences']['common']['lang'],
212
+				Api\Translation::get_installed_langs(), true, 'tabindex="1"', 0, false),
213 213
 			));
214 214
 		}
215 215
 		else
216 216
 		{
217
-			$tmpl->set_block('login_form','language_select');
218
-			$tmpl->set_var('language_select','');
217
+			$tmpl->set_block('login_form', 'language_select');
218
+			$tmpl->set_var('language_select', '');
219 219
 		}
220 220
 
221 221
 		/********************************************************\
@@ -223,36 +223,36 @@  discard block
 block discarded – undo
223 223
 		* and place a time selectbox, how long cookie is valid   *
224 224
 		\********************************************************/
225 225
 
226
-		if($GLOBALS['egw_info']['server']['allow_cookie_auth'])
226
+		if ($GLOBALS['egw_info']['server']['allow_cookie_auth'])
227 227
 		{
228
-			$tmpl->set_block('login_form','remember_me_selection');
229
-			$tmpl->set_var('lang_remember_me',lang('Remember me'));
230
-			$tmpl->set_var('select_remember_me',Api\Html::select('remember_me', '', array(
228
+			$tmpl->set_block('login_form', 'remember_me_selection');
229
+			$tmpl->set_var('lang_remember_me', lang('Remember me'));
230
+			$tmpl->set_var('select_remember_me', Api\Html::select('remember_me', '', array(
231 231
 				'' => lang('not'),
232 232
 				'1hour' => lang('1 Hour'),
233 233
 				'1day' => lang('1 Day'),
234 234
 				'1week'=> lang('1 Week'),
235 235
 				'1month' => lang('1 Month'),
236 236
 				'forever' => lang('Forever'),
237
-			),true,'tabindex="3"',0,false));
237
+			), true, 'tabindex="3"', 0, false));
238 238
 		}
239 239
 		else
240 240
 		{
241 241
 			/* trick to make remember_me section disapear */
242
-			$tmpl->set_block('login_form','remember_me_selection');
243
-			$tmpl->set_var('remember_me_selection','');
242
+			$tmpl->set_block('login_form', 'remember_me_selection');
243
+			$tmpl->set_var('remember_me_selection', '');
244 244
 		}
245 245
 		$tmpl->set_var('autocomplete', ($GLOBALS['egw_info']['server']['autocomplete_login'] ? 'autocomplete="off"' : ''));
246 246
 
247 247
 		if (Api\Header\UserAgent::type() == 'msie' && Api\Header\UserAgent::version() < 12)
248 248
 		{
249
-			$tmpl->set_var('cd', lang('Browser %1 %2 is not recommended. You may experience issues and not working features. Please use the latest version of Chrome, Firefox or Edge. Thank You!',Api\Header\UserAgent::type(), Api\Header\UserAgent::version()));
249
+			$tmpl->set_var('cd', lang('Browser %1 %2 is not recommended. You may experience issues and not working features. Please use the latest version of Chrome, Firefox or Edge. Thank You!', Api\Header\UserAgent::type(), Api\Header\UserAgent::version()));
250 250
 			$tmpl->set_var('cd_class', 'error');
251 251
 		}
252 252
 		// load jquery for login screen too
253 253
 		Api\Framework::includeJS('jquery', 'jquery');
254 254
 
255
-		$this->framework->render($tmpl->fp('loginout','login_form'),false,false);
255
+		$this->framework->render($tmpl->fp('loginout', 'login_form'), false, false);
256 256
 	}
257 257
 
258 258
 	/**
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	{
268 268
 		if (is_array($backgrounds))
269 269
 		{
270
-			$chosen = $backgrounds[rand(0, count($backgrounds)-1)];
270
+			$chosen = $backgrounds[rand(0, count($backgrounds) - 1)];
271 271
 		}
272 272
 		else
273 273
 		{
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 		}
282 282
 		else
283 283
 		{
284
-			return Api\Image::find('api',$chosen ? $chosen : 'login_background', '', null);
284
+			return Api\Image::find('api', $chosen ? $chosen : 'login_background', '', null);
285 285
 		}
286 286
 	}
287 287
 
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 			$tmpl = new Template(EGW_SERVER_ROOT.$this->framework->template_dir);
295 295
 			$tmpl->set_file(array('login_form' => 'login_denylogin.tpl'));
296 296
 		}
297
-		catch(Api\Exception\WrongParameter $e) {
297
+		catch (Api\Exception\WrongParameter $e) {
298 298
 			unset($e);
299 299
 			$tmpl = new Template(EGW_SERVER_ROOT.'/api/templates/default');
300 300
 			$tmpl->set_file(array('login_form' => 'login_denylogin.tpl'));
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 		// load jquery for deny-login screen too
310 310
 		Api\Framework::includeJS('jquery', 'jquery');
311 311
 
312
-		$this->framework->render($tmpl->fp('loginout','login_form'),false,false);
312
+		$this->framework->render($tmpl->fp('loginout', 'login_form'), false, false);
313 313
 	}
314 314
 
315 315
 	/**
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 	 */
321 321
 	static function check_logoutcode($code)
322 322
 	{
323
-		switch($code)
323
+		switch ($code)
324 324
 		{
325 325
 			case 1:
326 326
 				return lang('You have been successfully logged out');
Please login to merge, or discard this patch.