From 7ba77356d59c134315d175e9fa7e9160335fb585 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 18 Jun 2018 09:05:37 +0200 Subject: [PATCH] new "session_created" hook --- api/src/Session.php | 16 ++++++- api/src/Session/Type.php | 101 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 api/src/Session/Type.php diff --git a/api/src/Session.php b/api/src/Session.php index 0b261be8bb..663448a5a3 100644 --- a/api/src/Session.php +++ b/api/src/Session.php @@ -17,7 +17,6 @@ * @package api * @subpackage session * @author Ralf Becker since 2003 on - * @version $Id$ */ namespace EGroupware\Api; @@ -617,6 +616,21 @@ class Session } if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid"); + // hook called once session is created + Hooks::process(array( + 'location' => 'session_created', + 'sessionid' => $this->sessionid, + 'session_flags' => $this->session_flags, + 'account_id' => $this->account_id, + 'account_lid' => $this->account_lid, + 'passwd' => $this->passwd, + 'account_domain' => $this->account_domain, + 'user_ip' => $user_ip, + 'session_type' => Session\Type::get($_SERVER['REQUEST_URI'], + $GLOBALS['egw_info']['flags']['current_app'], + true), // true return WebGUI instead of login, as we are logged in now + ),'',true); + return $this->sessionid; } // catch all exceptions, as their (allways logged) trace (eg. on a database error) would contain the user password diff --git a/api/src/Session/Type.php b/api/src/Session/Type.php new file mode 100644 index 0000000000..830e34518e --- /dev/null +++ b/api/src/Session/Type.php @@ -0,0 +1,101 @@ + + */ + +namespace EGroupware\Api\Session; + +/** + * Determine type of session based on request-uri and currentapp + * + * + */ +class Type +{ + const LOGIN = 'login'; + const SYNCML = 'syncml'; + const GROUPDAV = 'groupdav'; + const ESYNC = 'esync'; + const WEBDAV = 'webdav'; + const WEBGUI = 'webgui'; + const SETUP = 'setup'; + const SITEMGR = 'sitemgr'; + const SHARING = 'sharing'; + const WOPI = 'wopi'; + + /** + * Return the type of session, based on the $request_uri + * + * @param string $request_uri + * @param string $currentapp + * @param bolean $nologin =false true: return self::WEBGUI instead of self::LOGIN + * @return string see above constants + */ + public static function get($request_uri, $currentapp, $nologin=false) + { + // sometimes the query makes an url unparseble, eg. /index.php?url=http://something.com/other.html + if (!($script = @parse_url($request_uri,PHP_URL_PATH))) + { + list($script) = explode('?',$request_uri); + if ($script[0] != '/') $script = parse_url($script,PHP_URL_PATH); + } + if (($e = strpos($script,'.php/')) !== false) + { + $script = substr($script,0,$e+4); // cut off WebDAV path + } + elseif (substr($script,-1) == '/') + { + $script .= 'index.php'; + } + $script_name = basename($script); + + if (!$nologin && ($script_name == 'login.php' || $script_name == 'logout.php')) + { + $type = self::LOGIN; + } + elseif($script_name == 'rpc.php') + { + $type = self::SYNCML; + } + elseif($script_name == 'groupdav.php') + { + $type = self::GROUPDAV; + } + elseif($script_name == 'webdav.php') + { + $type = self::WEBDAV; + } + elseif($script_name == 'share.php') + { + $type = self::SHARING; + } + elseif(basename(dirname($script)) == 'collabora' || $currentapp == 'collabora') + { + $type = self::WOPI; + } + elseif(basename(dirname($script)) == 'activesync' || $currentapp == 'activesync') + { + $type = self::ESYNC; + } + elseif(basename(dirname($script)) == 'setup' || $currentapp == 'setup') + { + $type = self::SETUP; + } + elseif ($currentapp == 'sitemgr-link') + { + $type = self::SITEMGR; + } + else + { + $type = self::WEBGUI; + } + //error_log(__METHOD__."('$request_uri', '$currentapp', $nologin) --> '$type'"); + return $type; + } +} \ No newline at end of file