示例#1
0
def send_cookie(login):
    session_ttl = sql.get_setting('session_ttl')
    session_ttl = int(session_ttl)
    expires = datetime.datetime.utcnow() + datetime.timedelta(days=session_ttl)
    user_uuid = str(uuid.uuid4())
    user_token = str(uuid.uuid4())
    sql.write_user_uuid(login, user_uuid)
    sql.write_user_token(login, user_token)

    id = sql.get_user_id_by_uuid(user_uuid)
    try:
        cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
        user_group_id = cookie.get('group')
        user_group_id = user_group_id.value
        if sql.check_user_group(id, user_group_id):
            user_groups = user_group_id
        else:
            user_groups = sql.select_user_groups(id, limit=1)
    except:
        user_groups = sql.select_user_groups(id, limit=1)

    c = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
    c["uuid"] = user_uuid
    c["uuid"]["path"] = "/app"
    # c["uuid"]["samesite"] = "Strict"
    c["uuid"]["Secure"] = "True"
    c["uuid"]["expires"] = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
    c["group"] = user_groups
    c["group"]["path"] = "/app"
    # c["group"]["samesite"] = "Strict"
    c["group"]["Secure"] = "True"
    c["group"]["expires"] = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
    print(c.output())

    try:
        groups = sql.select_groups(id=user_groups)
        for g in groups:
            if g[0] == int(user_groups):
                user_group = g[1]
    except:
        user_group = ''

    try:
        user_name = sql.get_user_name_by_uuid(user_uuid)
        funct.logging('localhost',
                      ' user: '******', group: ' + user_group +
                      ' log in',
                      haproxywi=1)
    except:
        pass
    print("Content-type: text/html\n")
    print('ok')
    sys.exit()
示例#2
0
def send_cookie(login):
    session_ttl = int()
    session_ttl = sql.get_setting('session_ttl')
    session_ttl = int(session_ttl)
    expires = datetime.datetime.utcnow() + datetime.timedelta(days=session_ttl)
    user_uuid = str(uuid.uuid4())
    user_token = str(uuid.uuid4())
    sql.write_user_uuid(login, user_uuid)
    sql.write_user_token(login, user_token)

    id = sql.get_user_id_by_uuid(user_uuid)
    user_groups = sql.select_user_groups(id, limit=1)

    c = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
    c["uuid"] = user_uuid
    c["uuid"]["path"] = "/"
    # c["uuid"]["sameSite"] = "Strict"
    c["uuid"]["Secure"] = "True"
    c["uuid"]["expires"] = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
    c["group"] = user_groups
    c["group"]["path"] = "/"
    # c["group"]["sameSite"] = "Strict"
    c["group"]["Secure"] = "True"
    c["group"]["expires"] = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
    print(c)

    try:
        funct.logging('locahost',
                      ' ' + sql.get_user_name_by_uuid(user_uuid) + ' log in',
                      haproxywi=1)
    except:
        pass
    print("Content-type: text/html\n")
    print('ok')
    sys.exit()
示例#3
0
文件: funct.py 项目: vqiu/haproxy-wi
def check_group(group, role_id):
	import http.cookies
	import sql
	cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
	user_id = cookie.get('uuid')
	id = sql.get_user_id_by_uuid(user_id.value)
	if sql.select_user_groups(id, check_id=group) or role_id == 1:
		return True
	else:
		logging('localhost', ' has tried to actions in not own group ', haproxywi=1, login=1)
		return False