/**
  * Checks authorisation for a template
  *
  */
 protected function checkAuth()
 {
     global $cfg;
     $auth = Auth::getInstance();
     if (!$auth->isLoggedIn()) {
         BasicLogger::logMessage("Logging in user as default", self::module, 'debug');
         $auth->attemptLogin($cfg['Auth']['anonuser']);
     } else {
         $auth->attemptLogin();
     }
     BasicLogger::logMessage("logged in as '{$auth->getUser()}'", self::module, 'debug');
     return AuthUtil::templateAccessAllowed(end($this->templateIDStack), $auth->getUser());
 }
 protected function processValid()
 {
     global $cfg;
     $auth = Auth::getInstance();
     //If the fwtid (forward template id) variable is set, then set the
     //templateID to that requested as long as the user has permission
     BasicLogger::logMessage("Checking access to requested template", 'debug');
     if (isset($this->fieldData['fwdtid']) && $this->fieldData['fwdtid'] != '' && AuthUtil::templateAccessAllowed($this->fieldData['fwdtid'], $auth->getUserID())) {
         BasicLogger::logMessage("Access granted, forwarding user to {$this->fieldData['fwdtid']}", 'debug');
         MVCUtils::redirect($this->fieldData['fwdtid']);
         //If the fwtid (forward template id) variable is not set, then set the
         //templateID to that default as long as the user has permission
     } elseif (!(isset($this->fieldData['fwdtid']) && $this->fieldData['fwdtid'] == '') && AuthUtil::templateAccessAllowed(MVCUtils::getTemplateID($cfg['smarty']['defaultTemplate']), $auth->getUserID())) {
         BasicLogger::logMessage("Access granted, forwarding user to {$cfg['smarty']['defaultTemplate']}", 'debug');
         MVCUtils::redirect(MVCUtils::getTemplateID($cfg['smarty']['defaultTemplate']));
         //If all the above fails, show the user permission denied
     } else {
         BasicLogger::logMessage("Access denied", 'debug');
         MVCUtils::redirect(MVCUtils::getTemplateID($cfg['Auth']['permissionErrorTemplate']));
     }
     /*//If the fwtid (forward template id) variable is set, then set the 
     		//templateID to that requested as long as the user is allowed access.
     		if(isset($this->fieldData['fwdtid']) && 
     		 $this->fieldData['fwdtid'] != '' && 
     		 AuthUtil::templateAccessAllowed($this->fieldData['fwdtid'], $auth->getUserID())){
     		 	
     			$this->templateID = $this->fieldData['fwdtid'];
     			
     		//If now fwtid has not been set, then forward to the default template
     		//as long as the user is allowed access
     		}elseif((!isset($this->fieldData['fwdtid']) || 
     		 $this->fieldData['fwdtid'] == '') &&
     		 AuthUtil::templateAccessAllowed(MVCUtils::getTemplateID($cfg['smarty']['defaultTemplate']), $auth->getUserID())){
     		 	
     			$this->templateID = MVCUtils::getTemplateID($cfg['smarty']['defaultTemplate']);
     		}*/
 }
Ejemplo n.º 3
0
 /**
  * Checks authorisation for a template
  *
  */
 protected function checkAuth()
 {
     global $cfg;
     $auth = Auth::getInstance();
     if (!$auth->isLoggedIn()) {
         $auth->attemptLogin($cfg['Auth']['anonuser']);
     } else {
         $auth->attemptLogin();
     }
     if (is_null($auth->getUserID())) {
         $Nuser = array();
         $Nuser['username'] = $auth->getUser();
         $Nuser['enabled'] = 't';
         $Nuser['id'] = "#id#";
         $db = Database::getInstance($cfg['Auth']['dsn']);
         $userID = $db->insert('users', $Nuser, true);
         if (isset($cfg['Auth']['defaultNewUserGroup'])) {
             $group = array();
             $group['groupid'] = $cfg['Auth']['defaultNewUserGroup'];
             $group['userid'] = $userID;
             $db->insert('usersgroups', $group, true);
         }
         $auth->attemptLogin();
     }
     return AuthUtil::templateAccessAllowed($this->templateID, $auth->getUser());
 }
 protected function processValid()
 {
     global $cfg;
     $db = Database::getInstance($cfg['Auth']['dsn']);
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $userName = $auth->getUser();
     $sql = "SELECT usersconfigs.val, usersconfigs.id \n\t\t\tFROM configs, usersconfigs \n\t\t\tWHERE configs.id = usersconfigs.configid \n\t\t\tAND configs.name = 'user_curlogin' \n\t\t\tAND usersconfigs.userid = " . $userID;
     $usercurlogin = $db->getRow($sql);
     $sql = "SELECT usersconfigs.val, usersconfigs.id\n\t\t\tFROM configs, usersconfigs \n\t\t\tWHERE configs.id = usersconfigs.configid\n\t\t\tAND configs.name = 'user_lastlogin'\n\t\t\tAND usersconfigs.userid = " . $userID;
     $userlastlogin = $db->getRow($sql);
     $sql = "SELECT id FROM dir \n\t\t\tWHERE parent = " . $cfg['DPS']['userDirectoryID'] . " \n\t\t\tAND name = '" . $userName . "'";
     $dirID = $db->getOne($sql);
     if ($dirID == '') {
         $newdir['name'] = $userName;
         $newdir['parent'] = $cfg['DPS']['userDirectoryID'];
         $newdir['id'] = '#id#';
         $newdir['notes'] = $userName . "'s home directory";
         $newdir['inherit'] = 'f';
         $dirID = $db->insert('dir', $newdir, true);
         $newperm['dirid'] = $dirID;
         $newperm['userid'] = $userID;
         $newperm['permissions'] = 'B' . $cfg['DPS']['fileRW'] . 'B';
         $db->insert('dirusers', $newperm, false);
         //false for binary insert
         $sql_gperm['dirid'] = $dirID;
         $sql_gperm['permissions'] = 'B' . $cfg['DPS']['fileRWO'] . 'B';
         $sql_gperm['groupid'] = $cfg['Auth']['AdminGroup'];
         $db->insert('dirgroups', $sql_gperm, false);
     }
     if (is_null($userlastlogin) && !is_null($usercurlogin)) {
         $awset = array();
         $sql = "SELECT id FROM configs WHERE configs.name = 'user_lastlogin'";
         $awset['configid'] = $db->getOne($sql);
         $awset['val'] = $usercurlogin['val'];
         $awset['userid'] = $userID;
         $db->insert('usersconfigs', $awset, true);
     } elseif (is_null($userlastlogin) && is_null($usercurlogin)) {
         $awset = array();
         $sql = "SELECT id FROM configs WHERE configs.name = 'user_lastlogin'";
         $awset['configid'] = $db->getOne($sql);
         $awset['val'] = time();
         $awset['userid'] = $userID;
         $db->insert('usersconfigs', $awset, true);
     } elseif (!is_null($userlastlogin) && is_null($usercurlogin)) {
         $logint = array();
         $logint['val'] = time();
         $atWhere = "id = " . $userlastlogin['id'];
         $db->update('usersconfigs', $logint, $atWhere, true);
     } else {
         $logint = array();
         $logint['val'] = $usercurlogin['val'];
         $atWhere = "id = " . $userlastlogin['id'];
         $db->update('usersconfigs', $logint, $atWhere, true);
     }
     if (is_null($usercurlogin)) {
         $awset = array();
         $sql = "SELECT id FROM configs WHERE configs.name = 'user_curlogin'";
         $awset['configid'] = $db->getOne($sql);
         $awset['val'] = time();
         $awset['userid'] = $userID;
         $db->insert('usersconfigs', $awset, true);
     } else {
         $logint = array();
         $logint['val'] = time();
         $atWhere = "id = " . $usercurlogin['id'];
         $db->update('usersconfigs', $logint, $atWhere, true);
     }
     BasicLogger::logMessage("Checking access to requested template", 'debug');
     if (isset($this->fieldData['fwdtid']) && $this->fieldData['fwdtid'] != '' && AuthUtil::templateAccessAllowed($this->fieldData['fwdtid'], $auth->getUserID())) {
         BasicLogger::logMessage("Access granted, forwarding user to {$this->fieldData['fwdtid']}", 'debug');
         MVCUtils::redirect($this->fieldData['fwdtid']);
         //If the fwtid (forward template id) variable is not set, then set the
         //templateID to that default as long as the user has permission
     } elseif (!(isset($this->fieldData['fwdtid']) && $this->fieldData['fwdtid'] == '') && AuthUtil::templateAccessAllowed(MVCUtils::getTemplateID($cfg['smarty']['defaultTemplate']), $auth->getUserID())) {
         BasicLogger::logMessage("Access granted, forwarding user to {$cfg['smarty']['defaultTemplate']}", 'debug');
         MVCUtils::redirect(MVCUtils::getTemplateID($cfg['smarty']['defaultTemplate']));
         //If all the above fails, show the user permission denied
     } else {
         BasicLogger::logMessage("Access denied", 'debug');
         MVCUtils::redirect(MVCUtils::getTemplateID($cfg['Auth']['permissionErrorTemplate']));
     }
 }