mirror of
https://github.com/iFargle/headscale-webui.git
synced 2026-01-04 03:33:28 +01:00
test
This commit is contained in:
54
server.py
54
server.py
@@ -91,21 +91,21 @@ elif AUTH_TYPE == "basic":
|
||||
# Set Authentication type - Dynamically load function decorators
|
||||
# https://wiki.python.org/moin/PythonDecoratorLibrary#Enable.2FDisable_Decorators
|
||||
########################################################################################
|
||||
def auth_type(flag):
|
||||
def decorator_auth_type(func):
|
||||
def enable_oidc():
|
||||
def decorator_enable_oidc(func):
|
||||
@wraps(func)
|
||||
def wrapper_decorator_auth_type(*args, **kwargs):
|
||||
if flag is not "oidc":
|
||||
def wrapper_decorator_enable_oidc(*args, **kwargs):
|
||||
if AUTH_TYPE != "oidc":
|
||||
func(*args, **kwargs)
|
||||
oidc.require_login(func)
|
||||
return wrapper_decorator_auth_type
|
||||
return decorator_auth_type
|
||||
return wrapper_decorator_enable_oidc
|
||||
return decorator_enable_oidc
|
||||
########################################################################################
|
||||
# / pages - User-facing pages
|
||||
########################################################################################
|
||||
@app.route('/')
|
||||
@app.route('/overview')
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def overview_page():
|
||||
# Some basic sanity checks:
|
||||
pass_checks = str(helper.load_checks())
|
||||
@@ -118,7 +118,7 @@ def overview_page():
|
||||
)
|
||||
|
||||
@app.route('/machines', methods=('GET', 'POST'))
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def machines_page():
|
||||
# Some basic sanity checks:
|
||||
pass_checks = str(helper.load_checks())
|
||||
@@ -133,7 +133,7 @@ def machines_page():
|
||||
)
|
||||
|
||||
@app.route('/users', methods=('GET', 'POST'))
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def users_page():
|
||||
# Some basic sanity checks:
|
||||
pass_checks = str(helper.load_checks())
|
||||
@@ -148,7 +148,7 @@ def users_page():
|
||||
)
|
||||
|
||||
@app.route('/settings', methods=('GET', 'POST'))
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def settings_page():
|
||||
# Some basic sanity checks:
|
||||
pass_checks = str(helper.load_checks())
|
||||
@@ -166,7 +166,7 @@ def settings_page():
|
||||
)
|
||||
|
||||
@app.route('/error')
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def error_page():
|
||||
if helper.access_checks() == "Pass":
|
||||
return redirect(url_for('overview_page'))
|
||||
@@ -184,7 +184,7 @@ def error_page():
|
||||
########################################################################################
|
||||
|
||||
@app.route('/api/test_key', methods=('GET', 'POST'))
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def test_key_page():
|
||||
api_key = headscale.get_api_key()
|
||||
url = headscale.get_url()
|
||||
@@ -221,7 +221,7 @@ def test_key_page():
|
||||
return message
|
||||
|
||||
@app.route('/api/save_key', methods=['POST'])
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def save_key_page():
|
||||
json_response = request.get_json()
|
||||
api_key = json_response['api_key']
|
||||
@@ -246,7 +246,7 @@ def save_key_page():
|
||||
# Machine API Endpoints
|
||||
########################################################################################
|
||||
@app.route('/api/update_route', methods=['POST'])
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def update_route_page():
|
||||
json_response = request.get_json()
|
||||
route_id = json_response['route_id']
|
||||
@@ -257,7 +257,7 @@ def update_route_page():
|
||||
return headscale.update_route(url, api_key, route_id, current_state)
|
||||
|
||||
@app.route('/api/machine_information', methods=['POST'])
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def machine_information_page():
|
||||
json_response = request.get_json()
|
||||
machine_id = json_response['id']
|
||||
@@ -267,7 +267,7 @@ def machine_information_page():
|
||||
return headscale.get_machine_info(url, api_key, machine_id)
|
||||
|
||||
@app.route('/api/delete_machine', methods=['POST'])
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def delete_machine_page():
|
||||
json_response = request.get_json()
|
||||
machine_id = json_response['id']
|
||||
@@ -277,7 +277,7 @@ def delete_machine_page():
|
||||
return headscale.delete_machine(url, api_key, machine_id)
|
||||
|
||||
@app.route('/api/rename_machine', methods=['POST'])
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def rename_machine_page():
|
||||
json_response = request.get_json()
|
||||
machine_id = json_response['id']
|
||||
@@ -288,7 +288,7 @@ def rename_machine_page():
|
||||
return headscale.rename_machine(url, api_key, machine_id, new_name)
|
||||
|
||||
@app.route('/api/move_user', methods=['POST'])
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def move_user_page():
|
||||
json_response = request.get_json()
|
||||
machine_id = json_response['id']
|
||||
@@ -299,7 +299,7 @@ def move_user_page():
|
||||
return headscale.move_user(url, api_key, machine_id, new_user)
|
||||
|
||||
@app.route('/api/set_machine_tags', methods=['POST'])
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def set_machine_tags():
|
||||
json_response = request.get_json()
|
||||
machine_id = json_response['id']
|
||||
@@ -310,7 +310,7 @@ def set_machine_tags():
|
||||
return headscale.set_machine_tags(url, api_key, machine_id, machine_tags)
|
||||
|
||||
@app.route('/api/register_machine', methods=['POST'])
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def register_machine():
|
||||
json_response = request.get_json()
|
||||
machine_key = json_response['key']
|
||||
@@ -324,7 +324,7 @@ def register_machine():
|
||||
# User API Endpoints
|
||||
########################################################################################
|
||||
@app.route('/api/rename_user', methods=['POST'])
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def rename_user_page():
|
||||
json_response = request.get_json()
|
||||
old_name = json_response['old_name']
|
||||
@@ -335,7 +335,7 @@ def rename_user_page():
|
||||
return headscale.rename_user(url, api_key, old_name, new_name)
|
||||
|
||||
@app.route('/api/add_user', methods=['POST'])
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def add_user():
|
||||
json_response = json.dumps(request.get_json())
|
||||
url = headscale.get_url()
|
||||
@@ -344,7 +344,7 @@ def add_user():
|
||||
return headscale.add_user(url, api_key, json_response)
|
||||
|
||||
@app.route('/api/delete_user', methods=['POST'])
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def delete_user():
|
||||
json_response = request.get_json()
|
||||
user_name = json_response['name']
|
||||
@@ -354,7 +354,7 @@ def delete_user():
|
||||
return headscale.delete_user(url, api_key, user_name)
|
||||
|
||||
@app.route('/api/get_users', methods=['POST'])
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def get_users_page():
|
||||
url = headscale.get_url()
|
||||
api_key = headscale.get_api_key()
|
||||
@@ -365,7 +365,7 @@ def get_users_page():
|
||||
# Pre-Auth Key API Endpoints
|
||||
########################################################################################
|
||||
@app.route('/api/add_preauth_key', methods=['POST'])
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def add_preauth_key():
|
||||
json_response = json.dumps(request.get_json())
|
||||
url = headscale.get_url()
|
||||
@@ -374,7 +374,7 @@ def add_preauth_key():
|
||||
return headscale.add_preauth_key(url, api_key, json_response)
|
||||
|
||||
@app.route('/api/expire_preauth_key', methods=['POST'])
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def expire_preauth_key():
|
||||
json_response = json.dumps(request.get_json())
|
||||
url = headscale.get_url()
|
||||
@@ -383,7 +383,7 @@ def expire_preauth_key():
|
||||
return headscale.expire_preauth_key(url, api_key, json_response)
|
||||
|
||||
@app.route('/api/build_preauthkey_table', methods=['POST'])
|
||||
@auth_type(AUTH_TYPE)
|
||||
@enable_oidc
|
||||
def build_preauth_key_table():
|
||||
json_response = request.get_json()
|
||||
user_name = json_response['name']
|
||||
|
||||
Reference in New Issue
Block a user