diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..a7b4525 --- /dev/null +++ b/.env.sample @@ -0,0 +1,25 @@ +# General variables +TZ="UTC" +COLOR="blue-grey" +HS_SERVER=http://localhost:8080 +KEY="GenerateYourOwnRandomKey" +SCRIPT_NAME=/admin +DOMAIN_NAME=http://localhost:8080 +AUTH_TYPE="Basic" +LOG_LEVEL="Debug" + +# BasicAuth variables +BASIC_AUTH_USER="admin" +BASIC_AUTH_PASS="admin" + +# Flask OIDC Variables +OIDC_AUTH_URL=https://localhost:8080 +OIDC_CLIENT_ID=Headscale-WebUI +OIDC_CLIENT_SECRET=secret + +# About section on the Settings page +GIT_COMMIT="" +GIT_BRANCH="" +APP_VERSION="" +BUILD_DATE="" +HS_VERSION="" diff --git a/.gitignore b/.gitignore index 53bc162..29e1466 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__ .venv -poetry.lock \ No newline at end of file +.env +poetry.lock diff --git a/SETUP.md b/SETUP.md index 72a0558..24bc876 100644 --- a/SETUP.md +++ b/SETUP.md @@ -5,11 +5,32 @@ * Containers are published to [GHCR](https://github.com/users/iFargle/packages/container/package/headscale-webui) and [Docker Hub](https://hub.docker.com/r/ifargle/headscale-webui) # Contents + * [Bare Metal](#bare-metal) * [Docker Compose](#docker-compose) * [Reverse Proxies](#reverse-proxies) * [Authentication](#authentication) --- +# Bare Metal + +1. Install dependencies: + +```bash +# Debian/Ubuntu +apt install gcc python3-poetry --yes +poetry install --only main +``` + +2. Configurations: rename `.env.sample` -> `.env` and edit `.env` as per your requirements. + +3. Run server + +```bash +poetry run gunicorn -b 0.0.0.0:5000 server:app +``` + +That's it. Cheers. + # Docker Compose ## Environment Settings * `TZ` - Set this to your current timezone. Example: `Asia/Tokyo` @@ -81,7 +102,7 @@ https://[DOMAIN] { reverse_proxy * [HS_SERVER] } ``` -* Example: +* Example: ``` https://example.com { reverse_proxy /admin* http://headscale-webui:5000 @@ -90,7 +111,7 @@ https://example.com { } ``` ---- +--- # Authentication *If your OIDC provider isn't listed or doesn't work, please open up a [new issue](https://github.com/iFargle/headscale-webui/issues/new) and it will be worked on.* diff --git a/headscale.py b/headscale.py index 14f01b9..d2dcc37 100644 --- a/headscale.py +++ b/headscale.py @@ -5,7 +5,9 @@ from cryptography.fernet import Fernet from datetime import timedelta, date from dateutil import parser from flask import Flask +from dotenv import load_dotenv +load_dotenv() LOG_LEVEL = os.environ["LOG_LEVEL"].replace('"', '').upper() # Initiate the Flask application and logging: app = Flask(__name__, static_url_path="/static") diff --git a/pyproject.toml b/pyproject.toml index 33a9da2..3835a91 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,6 +18,7 @@ pyuwsgi = "^2.0.21" gunicorn = "^20.1.0" flask-basicauth = "^0.2.0" flask-providers-oidc = "^1.2.1" +python-dotenv = "^1.0.0" [tool.poetry.dev-dependencies] diff --git a/server.py b/server.py index 85c0b79..fc49a08 100644 --- a/server.py +++ b/server.py @@ -7,7 +7,9 @@ from flask import Flask, escape, Markup, redirect, rende from dateutil import parser from flask_executor import Executor from werkzeug.middleware.proxy_fix import ProxyFix +from dotenv import load_dotenv +load_dotenv() # Global vars # Colors: https://materializecss.com/color.html COLOR = os.environ["COLOR"].replace('"', '').lower() diff --git a/templates/settings.html b/templates/settings.html index 3198fb9..f1a7e2b 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -17,7 +17,7 @@ vpn_key - +
Save @@ -57,6 +57,7 @@
  • To generate your API key, run the command headscale apikeys create on your control server. Once you generate your first key, this UI will automatically renew the key near expiration.
  • The Headscale server is configured via the HS_SERVER environment variable in Docker. Current server: {{url}}
  • You must configure an encryption key via the KEY environment variable in Docker. One can be generated with the command openssl rand -base64 32
  • +
  • Enter the API key generated by headscale, press "Save" then "Test". Saving before using the "Test" button is important.
  • -{% endblock %} \ No newline at end of file +{% endblock %}