27 define(
"TITLE_CORE_AUTH", _(
"Login"));
31 public static $origReferer;
39 private $authExternal;
41 function __construct()
44 $this->Title = TITLE_CORE_AUTH;
45 $this->PluginLevel = 1000;
47 parent::__construct();
50 $this->
dbManager = $container->get(
"db.manager");
51 $this->userDao = $container->get(
'dao.user');
52 $this->session = $container->get(
'session');
61 return self::$origReferer;
73 return $this->userDao->updateUserTable();
89 if (!$this->session->isStarted()) {
90 $this->session->setName(
'Login');
91 $this->session->start();
95 if ($this->authExternal !==
false && $this->authExternal[
'useAuthExternal']) {
96 $this->
checkUsernameAndPassword($this->authExternal[
'loginAuthExternal'], $this->authExternal[
'passwordAuthExternal']);
99 if (array_key_exists(
'selectMemberGroup', $_POST)) {
100 $selectedGroupId = intval($_POST[
'selectMemberGroup']);
101 $this->userDao->setDefaultGroupMembership(intval($_SESSION[Auth::USER_ID]), $selectedGroupId);
102 $_SESSION[Auth::GROUP_ID] = $selectedGroupId;
103 $this->session->set(Auth::GROUP_ID, $selectedGroupId);
104 $SysConf[
'auth'][Auth::GROUP_ID] = $selectedGroupId;
107 if (array_key_exists(Auth::USER_ID, $_SESSION)) {
108 $SysConf[
'auth'][Auth::USER_ID] = $_SESSION[Auth::USER_ID];
110 if (array_key_exists(Auth::GROUP_ID, $_SESSION)) {
111 $SysConf[
'auth'][Auth::GROUP_ID] = $_SESSION[Auth::GROUP_ID];
116 if (!empty($_SESSION[
'time']) && @$_SESSION[
'time'] + (60 * 480) < $Now) {
120 $_SESSION[
'time'] = $Now;
121 if (empty($_SESSION[
'ip'])) {
122 $_SESSION[
'ip'] = $this->
getIP();
123 }
else if ((@$_SESSION[
'checkip'] == 1) && (@$_SESSION[
'ip'] != $this->
getIP())) {
126 $_SESSION[
'ip'] = $this->
getIP();
129 if (@$_SESSION[Auth::USER_NAME]) {
131 if (empty($_SESSION[
'time_check'])) {
132 $_SESSION[
'time_check'] = time() + (480 * 60);
134 if (time() >= @$_SESSION[
'time_check']) {
135 $row = $this->userDao->getUserAndDefaultGroupByUserName(@$_SESSION[Auth::USER_NAME]);
137 if (empty($row[
'user_pass'])) {
147 plugin_disable($_SESSION[Auth::USER_LEVEL]);
148 $this->
State = PLUGIN_STATE_READY;
160 if (empty($userRow)) {
161 $userRow = $this->userDao->getUserAndDefaultGroupByUserName(
'Default User');
164 $_SESSION[Auth::USER_ID] = $userRow[
'user_pk'];
165 $SysConf[
'auth'][Auth::USER_ID] = $userRow[
'user_pk'];
166 $this->session->set(Auth::USER_ID, $userRow[
'user_pk']);
167 $_SESSION[Auth::USER_NAME] = $userRow[
'user_name'];
168 $this->session->set(Auth::USER_NAME, $userRow[
'user_name']);
169 $_SESSION[
'Folder'] = $userRow[
'root_folder_fk'];
170 $_SESSION[Auth::USER_LEVEL] = $userRow[
'user_perm'];
171 $this->session->set(Auth::USER_LEVEL, $userRow[
'user_perm']);
172 $_SESSION[
'UserEmail'] = $userRow[
'user_email'];
173 $_SESSION[
'UserEnote'] = $userRow[
'email_notify'];
174 $_SESSION[Auth::GROUP_ID] = $userRow[
'group_fk'];
175 $SysConf[
'auth'][Auth::GROUP_ID] = $userRow[
'group_fk'];
176 $this->session->set(Auth::GROUP_ID, $userRow[
'group_fk']);
177 $_SESSION[
'GroupName'] = $userRow[
'group_name'];
189 $Vars = array(
'HTTP_CLIENT_IP',
'HTTP_X_COMING_FROM',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED');
190 foreach ($Vars as $V) {
191 if (!empty($_SERVER[$V])) {
192 return ($_SERVER[$V]);
195 return (@$_SERVER[
'REMOTE_ADDR']);
206 if (empty($timezone) || strpos($timezone,
"Unknown") ==
true) {
207 $timezone = date_default_timezone_get();
209 $_SESSION[
'timezone'] = $timezone;
211 if (empty($referrer)) {
214 $referrerQuery = parse_url($referrer,PHP_URL_QUERY);
215 if ($referrerQuery) {
217 parse_str($referrerQuery,$params);
218 if (array_key_exists(
'mod', $params) && $params[
'mod'] == $this->Name) {
225 return new RedirectResponse($referrer);
228 $initPluginId = plugin_find_id(
"init");
229 if ($initPluginId >= 0) {
231 $this->vars[
'info'] = $Plugins[$initPluginId]->infoFirstTimeUsage();
234 if (isset($_SERVER[
'HTTPS']) && $_SERVER[
'HTTPS'] !=
"off") {
235 $this->vars[
'protocol'] =
"HTTPS";
237 $this->vars[
'protocol'] = preg_replace(
"@/.*@",
"", @$_SERVER[
'SERVER_PROTOCOL']);
240 $this->vars[
'referrer'] = $referrer;
241 $this->vars[
'loginFailure'] = !empty($userName) || !empty($password);
242 if (!empty($userName) && $userName!=
'Default User') {
243 $this->vars[
'userName'] = $userName;
245 return $this->
render(
'login.html.twig',$this->vars);
253 if (array_key_exists(
'User', $_SESSION) && $_SESSION[
'User'] !=
"Default User") {
256 header(
"Location: $Uri");
259 parent::OutputOpen();
271 if ($this->authExternal !==
false && $this->authExternal[
'useAuthExternal']) {
272 $username = $this->authExternal[
'loginAuthExternal'];
275 $this->userDao->getUserAndDefaultGroupByUserName($username);
276 }
catch (Exception $e) {
279 if (! $user_exists && $GLOBALS[
'SysConf'][
'EXT_AUTH'][
'CONF_EXT_AUTH_NEW_USER_AUTO_CREATE']) {
281 $User =
trim(str_replace(
"'",
"''", $this->authExternal[
'loginAuthExternal']));
282 $Pass = $this->authExternal[
'passwordAuthExternal'] ;
283 $Seed = rand() . rand();
284 $Hash = sha1($Seed . $Pass);
285 $Desc = $this->authExternal[
'descriptionAuthExternal'];
289 $Email = $this->authExternal[
'emailAuthExternal'];
291 $agentList = $GLOBALS[
'SysConf'][
'EXT_AUTH'][
'CONF_EXT_AUTH_NEW_USER_AGENT_LIST'];
292 add_user($User, $Desc, $Seed, $Hash, $Perm, $Email, $Email_notify, $agentList, $Folder);
296 if (empty($userName) || $userName ==
'Default User') {
300 $row = $this->userDao->getUserAndDefaultGroupByUserName($userName);
301 }
catch (Exception $e) {
305 if (empty($row[
'user_name'])) {
310 if (! empty($row[
'user_seed']) && ! empty($row[
'user_pass'])) {
311 $passwordHash = sha1($row[
'user_seed'] . $password);
312 if (strcmp($passwordHash, $row[
'user_pass']) != 0) {
315 }
else if (! empty($row[
'user_seed'])) {
318 }
else if (!empty($password)) {
326 $_SESSION[
'time_check'] = time() + (480 * 60);
328 if (
"X" . $row[
'user_perm'] ==
"X") {
331 $_SESSION[Auth::USER_LEVEL] = $row[
'user_perm'];
336 $_SESSION[
'NoPopup'] = 1;
338 $_SESSION[
'NoPopup'] = 0;
PostInitialize()
This is where the magic for Authentication happens.
Traceback_uri()
Get the URI without query to this location.
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
updateSession($userRow)
Set $_SESSION and $SysConf user variables.
add_user($User, $Desc, $Seed, $Hash, $Perm, $Email, $Email_notify, $agentList, $Folder, $default_bucketpool_fk='')
Add a user.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Output()
This is only called when the user logs out.
siteminder_check()
Check if SiteMinder is enabled.
getIP()
Retrieve the user's IP address. Some proxy systems pass forwarded IP address info. This ensures that someone who steals the cookie won't gain access unless they come from the same IP.
fo_dbManager * dbManager
fo_dbManager object
This is the Plugin class. All plugins should:
OutputOpen()
perform logout
Install()
Only used during installation. This may be called multiple times. Used to ensure the DB has the right...
auth_external_check()
Check if the external HTTP authentication is enabled. The mapping variables should be configured in f...
GetArrayVal($Key, $Arr)
Get the value from a array(map)
checkUsernameAndPassword($userName, $password)
See if a username/password is valid.
char * trim(char *ptext)
Trimming whitespace.
staticValue()
getter to retreive value of static var
render($templateName, $vars=null)