It works, with TODOs
This commit is contained in:
parent
fe5979aa5b
commit
47984787fc
|
@ -0,0 +1,2 @@
|
|||
- improve configuration
|
||||
- improve APP_PREFIX
|
|
@ -33,8 +33,11 @@ def create_app(environment='development'):
|
|||
from config import config
|
||||
from .views import main_blueprint
|
||||
|
||||
# BRUTTO BRUTTO
|
||||
app_prefix = os.getenv('APP_PREFIX', '')
|
||||
# Instantiate app.
|
||||
app = Flask(__name__)
|
||||
app = Flask(__name__,
|
||||
static_url_path=f"{app_prefix}/static")
|
||||
|
||||
# Set app config.
|
||||
env = os.environ.get('FLASK_ENV', environment)
|
||||
|
@ -43,11 +46,14 @@ def create_app(environment='development'):
|
|||
config[env].configure(app)
|
||||
app.config['APP_TZ'] = os.environ.get('TZ', 'UTC')
|
||||
|
||||
# app.static_url_path = f"{app.config['APP_PREFIX']}/static"
|
||||
|
||||
app.logger.info("middleware init: mobility")
|
||||
mobility.init_app(app)
|
||||
|
||||
# Register blueprints.
|
||||
app.logger.info("registering main blueprint")
|
||||
app.logger.info(f"registering main blueprint with prefix '{
|
||||
main_blueprint.url_prefix}'")
|
||||
app.register_blueprint(main_blueprint)
|
||||
|
||||
app.logger.info("jinja2 custom filters loaded")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
function renameNode(nodeId) {
|
||||
var newName = $("#newName").val();
|
||||
var url = `/node/${nodeId}/rename/${newName}`;
|
||||
var url = `${nodeId}/rename/${newName}`;
|
||||
$.ajax({
|
||||
url: url,
|
||||
xhrFields: {
|
||||
|
@ -15,8 +15,7 @@ function renameNode(nodeId) {
|
|||
|
||||
function createPKA(username) {
|
||||
console.log(username);
|
||||
var url = `/user/${username}/pakcreate`;
|
||||
console.log(url);
|
||||
var url = `${username}/pakcreate`;
|
||||
var ephemereal = $("#ephemereal").is(":checked");
|
||||
var reusable = $("#reusable").is(":checked");
|
||||
var expiration = $("#expiration").val();
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
{% block meta %}{% endblock %}
|
||||
<!-- styles -->
|
||||
<!-- <link rel="stylesheet" href="{{ url_for('static', filename='bootstrap.min.css') }}" -->
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css"
|
||||
integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@forevolve/bootstrap-dark@1.0.0/dist/css/toggle-bootstrap.min.css" />
|
||||
|
@ -51,13 +50,13 @@
|
|||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/nodes">nodes</a>
|
||||
<a class="nav-link" href="{{ url_for('main.nodes') }}">nodes</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/users">users</a>
|
||||
<a class="nav-link" href="{{ url_for('main.users') }}">users</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/routes">routes</a>
|
||||
<a class="nav-link" href="{{ url_for('main.routes') }}">routes</a>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="navbar-nav">
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
{{ node.expiry | htime_dt }}
|
||||
</span>
|
||||
{% if node.expireDate and not node.expired %}
|
||||
<a href="/node/{{ node.id }}/expire">
|
||||
<a href="{{ url_for('main.expireNode', nodeId=node.id) }}">
|
||||
<span data-toggle="tooltip" data-placement="right" title="expire/disconnect node">
|
||||
<i class="fas fa-plug"></i>
|
||||
</span>
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
<td class="no-sort">
|
||||
{% if node.expireDate and not node.expired %}
|
||||
<span data-toggle="tooltip" data-placement="right" title="expire/disconnect">
|
||||
<a class="nodeco" href="/node/{{node.id}}/list-expire" disabled>
|
||||
<a class="nodeco" href="{{ url_for('main.expireNodeList', nodeId=node.id) }}">
|
||||
<i class="fas fa-plug"></i>
|
||||
</a>
|
||||
</span>
|
||||
|
@ -58,7 +58,7 @@
|
|||
<i class="fas fa-plug disabled"></i>
|
||||
{% endif %}
|
||||
<span data-toggle="tooltip" data-placement="right" title="delete">
|
||||
<a class="nodeco" href="/node/{{node.id}}/delete">
|
||||
<a class="nodeco" href="{{ url_for('main.deleteNode', nodeId=node.id) }}">
|
||||
<i class="fas fa-trash"></i>
|
||||
</a>
|
||||
</span>
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
</a>
|
||||
</div>
|
||||
<div class="col col-2 float-left">
|
||||
<a class="routeToggle" href="/routeToggle/{{rts[0].id}}">
|
||||
<a class="routeToggle" href="{{ url_for('main.routeToggle', routeId=rts[0].id) }}">
|
||||
{{ rts[0].enabled | fancyBool | safe}}
|
||||
</a>
|
||||
</div>
|
||||
|
@ -78,7 +78,7 @@
|
|||
</a>
|
||||
</div>
|
||||
<div class="col col-2 float-left">
|
||||
<a class="routeToggle" href="/routeToggle/{{rt.id}}">
|
||||
<a class="routeToggle" href="{{ url_for('main.routeToggle', routeId=rt.id) }}">
|
||||
{{ rt.enabled | fancyBool | safe}}
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
@ -135,7 +135,7 @@
|
|||
{% endif %}
|
||||
|
||||
<!-- new key modal -->
|
||||
<div class="modal fade" id="createPKA" tabindex="-1" role="dialog" aria-labelledby="cretePKA" aria-hidden="true">
|
||||
<div class="modal fade" id="createPKA" tabindex="-1" role="dialog" aria-labelledby="createPKA" aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
|
@ -161,7 +161,7 @@
|
|||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||
<button type="button" class="btn btn-primary" onClick="createPKA(user='{{user.name}}')">Save changes</button>
|
||||
<button type="button" class="btn btn-primary" onClick="createPKA(user='{{ user.name }}')">Save changes</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import logging
|
||||
import datetime
|
||||
import os
|
||||
from flask import current_app
|
||||
from flask import render_template, Blueprint, request
|
||||
from flask import redirect, session, url_for
|
||||
|
@ -18,7 +19,8 @@ from hsapi_client.preauthkeys import (v1ListPreAuthKeyRequest,
|
|||
|
||||
log = logging.getLogger()
|
||||
|
||||
main_blueprint = Blueprint('main', __name__)
|
||||
main_blueprint = Blueprint(
|
||||
'main', __name__, url_prefix=os.getenv('APP_PREFIX', '/'))
|
||||
|
||||
|
||||
@main_blueprint.route('/health', methods=['GET'])
|
||||
|
@ -180,7 +182,7 @@ def deleteNode(nodeId: int):
|
|||
|
||||
@main_blueprint.route('/node/<int:nodeId>/rename/<newName>', methods=['GET'])
|
||||
@auth.authorize_admins('default')
|
||||
def renameNode(nodeId: int, newName: str):
|
||||
def renameNode(nodeId: str, newName: str):
|
||||
Node().rename(nodeId, newName)
|
||||
return jsonify(dict(newName=newName))
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ class BaseConfig(object):
|
|||
APP_NAME = "HSMAN"
|
||||
APP_VERSION = os.getenv('APP_VERSION', "0.0alpha1")
|
||||
APP_SHA = os.getenv('APP_SHA', "000000")
|
||||
APP_PREFIX = os.getenv('APP_PREFIX', '')
|
||||
DEBUG_TB_ENABLED = False
|
||||
WTF_CSRF_ENABLED = False
|
||||
|
||||
|
|
|
@ -9,8 +9,6 @@ threads = 4
|
|||
preload_app = True
|
||||
# worker_class = "uvicorn.workers.UvicornWorker"
|
||||
|
||||
chdir = "/hsman"
|
||||
|
||||
# logconfig = "app/logging/production.ini"
|
||||
logconfig = "app/logging/production.ini"
|
||||
# access_log_format = "%(h)s %(l)s %(t)s %(r)s %(s)s %(b)s %(f)s %(a)s"
|
||||
|
|
|
@ -457,13 +457,13 @@ files = [
|
|||
|
||||
[[package]]
|
||||
name = "hsapi-client"
|
||||
version = "0.9.2"
|
||||
version = "0.9.3"
|
||||
description = "Headscale API client"
|
||||
optional = false
|
||||
python-versions = "<4.0,>=3.11"
|
||||
files = [
|
||||
{file = "hsapi_client-0.9.2-py3-none-any.whl", hash = "sha256:bbda176e10b7ba0c1376eac6e8fcbd9027a41fab21585edad275cfbd21cce66d"},
|
||||
{file = "hsapi_client-0.9.2.tar.gz", hash = "sha256:902256e6240e47b3eecacde930f9d67e12a0d46d34d7dbcc86e95b2976013099"},
|
||||
{file = "hsapi_client-0.9.3-py3-none-any.whl", hash = "sha256:75bf3e5f35a857c36f49560ba8d70243b3dc66138f50dbf2b862ae240a68b9ab"},
|
||||
{file = "hsapi_client-0.9.3.tar.gz", hash = "sha256:58e1494608e17b224d27ca7fa004219cc1a1f7926c677e16fc21774e9502ed25"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[tool.poetry]
|
||||
name = "hsman"
|
||||
version = "0.9.0"
|
||||
version = "0.9.1"
|
||||
description = "Flask Admin webui for Headscale"
|
||||
authors = ["Andrea Mistrali <andrea@mistrali.pw>"]
|
||||
license = "BSD"
|
||||
|
|
Loading…
Reference in New Issue