コード例 #1
0
ファイル: class.cwebuser.php プロジェクト: itnihao/zatree-2.2
 public static function login($login, $password)
 {
     try {
         self::setDefault();
         self::$data = API::User()->login(array('user' => $login, 'password' => $password, 'userData' => true));
         if (!self::$data) {
             throw new Exception();
         }
         if (self::$data['gui_access'] == GROUP_GUI_ACCESS_DISABLED) {
             error(_('GUI access disabled.'));
             throw new Exception();
         }
         if (empty(self::$data['url'])) {
             self::$data['url'] = CProfile::get('web.menu.view.last', 'index.php');
         }
         if (isset(self::$data['attempt_failed']) && self::$data['attempt_failed']) {
             CProfile::init();
             CProfile::update('web.login.attempt.failed', self::$data['attempt_failed'], PROFILE_TYPE_INT);
             CProfile::update('web.login.attempt.ip', self::$data['attempt_ip'], PROFILE_TYPE_STR);
             CProfile::update('web.login.attempt.clock', self::$data['attempt_clock'], PROFILE_TYPE_INT);
             CProfile::flush();
         }
         // remove guest session after successful login
         DBexecute('DELETE FROM sessions WHERE sessionid=' . zbx_dbstr(get_cookie('zbx_sessionid')));
         zbx_setcookie('zbx_sessionid', self::$data['sessionid'], self::$data['autologin'] ? time() + SEC_PER_DAY * 31 : 0);
         return true;
     } catch (Exception $e) {
         self::setDefault();
         return false;
     }
 }
コード例 #2
0
ファイル: CWebUser.php プロジェクト: TonywalkerCN/Zabbix
 /**
  * Tries to login a user and populates self::$data on success.
  *
  * @param string $login			user login
  * @param string $password		user password
  *
  * @throws Exception if user cannot be logged in
  *
  * @return bool
  */
 public static function login($login, $password)
 {
     try {
         self::setDefault();
         self::$data = API::User()->login(array('user' => $login, 'password' => $password, 'userData' => true));
         if (!self::$data) {
             throw new Exception();
         }
         if (self::$data['gui_access'] == GROUP_GUI_ACCESS_DISABLED) {
             error(_('GUI access disabled.'));
             throw new Exception();
         }
         if (empty(self::$data['url'])) {
             self::$data['url'] = CProfile::get('web.menu.view.last', 'index.php');
         }
         $result = (bool) self::$data;
         if (isset(self::$data['attempt_failed']) && self::$data['attempt_failed']) {
             CProfile::init();
             CProfile::update('web.login.attempt.failed', self::$data['attempt_failed'], PROFILE_TYPE_INT);
             CProfile::update('web.login.attempt.ip', self::$data['attempt_ip'], PROFILE_TYPE_STR);
             CProfile::update('web.login.attempt.clock', self::$data['attempt_clock'], PROFILE_TYPE_INT);
             $result &= CProfile::flush();
         }
         // remove guest session after successful login
         $result &= DBexecute('DELETE FROM sessions WHERE sessionid=' . zbx_dbstr(get_cookie('zbx_sessionid')));
         if ($result) {
             self::setSessionCookie(self::$data['sessionid']);
             add_audit_ext(AUDIT_ACTION_LOGIN, AUDIT_RESOURCE_USER, self::$data['userid'], '', null, null, null);
         }
         return $result;
     } catch (Exception $e) {
         self::setDefault();
         return false;
     }
 }
コード例 #3
0
function init_nodes()
{
    // init current node id
    if (defined('ZBX_NODES_INITIALIZED')) {
        return null;
    }
    global $ZBX_LOCALNODEID, $ZBX_LOCMASTERID, $ZBX_CURRENT_NODEID, $ZBX_CURMASTERID, $ZBX_NODES, $ZBX_NODES_IDS, $ZBX_AVAILABLE_NODES, $ZBX_VIEWED_NODES, $ZBX_WITH_ALL_NODES;
    $ZBX_AVAILABLE_NODES = array();
    $ZBX_NODES_IDS = array();
    $ZBX_NODES = array();
    $ZBX_CURRENT_NODEID = $ZBX_LOCALNODEID;
    $ZBX_WITH_ALL_NODES = !defined('ZBX_NOT_ALLOW_ALL_NODES');
    if (!defined('ZBX_PAGE_NO_AUTHORIZATION') && ZBX_DISTRIBUTED) {
        if (CWebUser::$data['type'] == USER_TYPE_SUPER_ADMIN) {
            $sql = 'SELECT DISTINCT n.nodeid,n.name,n.masterid FROM nodes n';
        } else {
            $sql = 'SELECT DISTINCT n.nodeid,n.name,n.masterid' . ' FROM nodes n,groups hg,rights r,users_groups g' . ' WHERE r.id=hg.groupid' . ' AND r.groupid=g.usrgrpid' . ' AND g.userid=' . CWebUser::$data['userid'] . ' AND n.nodeid=' . DBid2nodeid('hg.groupid');
        }
        $db_nodes = DBselect($sql);
        while ($node = DBfetch($db_nodes)) {
            $ZBX_NODES[$node['nodeid']] = $node;
            $ZBX_NODES_IDS[$node['nodeid']] = $node['nodeid'];
        }
        $ZBX_AVAILABLE_NODES = get_accessible_nodes_by_user(CWebUser::$data, PERM_READ_LIST, PERM_RES_IDS_ARRAY, $ZBX_NODES_IDS);
        $ZBX_VIEWED_NODES = get_viewed_nodes();
        $ZBX_CURRENT_NODEID = $ZBX_VIEWED_NODES['selected'];
        if ($node_data = DBfetch(DBselect('SELECT n.masterid FROM nodes n WHERE n.nodeid=' . $ZBX_CURRENT_NODEID))) {
            $ZBX_CURMASTERID = $node_data['masterid'];
        }
        if (!isset($ZBX_NODES[$ZBX_CURRENT_NODEID])) {
            $ZBX_CURRENT_NODEID = $ZBX_LOCALNODEID;
            $ZBX_CURMASTERID = $ZBX_LOCMASTERID;
        }
        if (isset($_REQUEST['select_nodes'])) {
            update_node_profile($ZBX_VIEWED_NODES['nodeids']);
        }
        if (isset($_REQUEST['switch_node'])) {
            CProfile::update('web.nodes.switch_node', $ZBX_VIEWED_NODES['selected'], PROFILE_TYPE_ID);
        }
    } else {
        $ZBX_CURRENT_NODEID = $ZBX_LOCALNODEID;
        $ZBX_CURMASTERID = $ZBX_LOCMASTERID;
    }
    define('ZBX_NODES_INITIALIZED', 1);
    // reset profiles if node is different than local
    if ($ZBX_CURRENT_NODEID != $ZBX_LOCALNODEID) {
        CProfile::init();
    }
}