示例#1
0
def check_auth(username, password, remote_addr=None):
    if remote_addr:
        cache_key = 'ip_' + remote_addr
        count = cache_db.list_length(cache_key)
        if count and count > 10:
            raise flask.abort(403)

        key_exists = cache_db.exists(cache_key)
        cache_db.list_rpush(cache_key, '')
        if not key_exists:
            cache_db.expire(cache_key, 20)

    db_username = persist_db.dict_get('auth', 'username') or DEFAULT_USERNAME
    if username != db_username:
        return False

    db_password = persist_db.dict_get('auth', 'password')
    if not db_password:
        if password == DEFAULT_PASSWORD:
            return True
        return False

    pass_ver, pass_salt, db_pass_hash = db_password.split('$')
    if pass_ver == '0':
        pass_hash = _hash_password_v0(pass_salt, password)
    elif pass_ver == '1':
        pass_hash = _hash_password_v1(pass_salt, password)
    else:
        return False
    return pass_hash == db_pass_hash
示例#2
0
文件: server.py 项目: bitland/pritunl
 def push_output(self, output):
     if not app_server.server_log_lines:
         return
     cache_db.list_rpush(self.get_cache_key('output'), output.rstrip('\n'))
     clear_lines = cache_db.list_length(self.get_cache_key('output')) - \
         app_server.server_log_lines
     for _ in xrange(clear_lines):
         cache_db.list_lpop(self.get_cache_key('output'))
     self._event_delay(type=SERVER_OUTPUT_UPDATED, resource_id=self.id)
示例#3
0
文件: utils.py 项目: bitland/pritunl
def check_auth(username, password, remote_addr=None):
    from administrator import Administrator

    if remote_addr:
        # TODO
        cache_key = 'ip_' + remote_addr
        count = cache_db.list_length(cache_key)
        if count and count > 10:
            raise flask.abort(403)

        # TODO
        key_exists = cache_db.exists(cache_key)
        cache_db.list_rpush(cache_key, '')
        if not key_exists:
            cache_db.expire(cache_key, 20)

    administrator = Administrator.find_user(username=username)
    if not administrator:
        return
    if not administrator.test_password(password):
        return
    return administrator
示例#4
0
def check_auth(username, password, remote_addr=None):
    if remote_addr:
        cache_key = "ip_" + remote_addr
        count = cache_db.list_length(cache_key)
        if count and count > 10:
            raise flask.abort(403)

        key_exists = cache_db.exists(cache_key)
        cache_db.list_rpush(cache_key, "")
        if not key_exists:
            cache_db.expire(cache_key, 20)

    db_username = persist_db.dict_get("auth", "username") or DEFAULT_USERNAME
    if username != db_username:
        return False

    db_password = persist_db.dict_get("auth", "password")
    if not db_password:
        if password == DEFAULT_PASSWORD:
            return True
        return False
    return _test_password_hash(db_password, password)