Compare commits
56 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
813407057e | ||
|
89b6c1ee83
|
|||
| bf5cc97c11 | |||
| 6f21e53677 | |||
|
9f74246157
|
|||
|
84ce50963b
|
|||
|
3bcffaafab
|
|||
|
e6cc1d901e
|
|||
|
9e71270e41
|
|||
|
1fa355089d
|
|||
|
860ce5c836
|
|||
|
055ab10ab7
|
|||
|
dbb464e41c
|
|||
|
11400520c9
|
|||
|
b8f5fdc794
|
|||
|
d8405fa363
|
|||
|
c628498637
|
|||
|
786c43ae06
|
|||
|
309efe074b
|
|||
|
9949179997
|
|||
|
6a072724f2
|
|||
|
b79f3f3387
|
|||
|
a494b606a5
|
|||
|
90094e9c43
|
|||
|
4285da4fa8
|
|||
|
14450ba70d
|
|||
|
5a4b5ddd82
|
|||
|
2964ac7644
|
|||
|
1d00d5f4f5
|
|||
|
38da1f476e
|
|||
| c840788907 | |||
|
a3e9aed6f4
|
|||
|
8ad55eed10
|
|||
|
77b6bd0732
|
|||
|
a32df2fd67
|
|||
|
8b418a7d52
|
|||
|
3e1fe9fa1e
|
|||
|
bd9d95b741
|
|||
|
4baf29eb4a
|
|||
|
d91f135d53
|
|||
|
c1e20e5524
|
|||
|
d56256f681
|
|||
|
bbaffb344f
|
|||
|
50be48dba4
|
|||
|
fc5dc23c0e
|
|||
|
44df495096
|
|||
|
8dbbea3f56
|
|||
|
e575e8a15d
|
|||
|
1901441948
|
|||
|
6bed7da165
|
|||
|
f8f74ccd4b
|
|||
|
5fb6920436
|
|||
|
23a53f79a0
|
|||
|
89dd67b489
|
|||
|
c2e1984959
|
|||
|
dbc61ac6b7
|
38
.github/workflows/release.yaml
vendored
38
.github/workflows/release.yaml
vendored
@@ -5,35 +5,35 @@ on:
|
||||
inputs:
|
||||
short_description:
|
||||
type: string
|
||||
description: 'Short description of the release'
|
||||
description: "Short description of the release"
|
||||
required: false
|
||||
auto_bump:
|
||||
type: boolean
|
||||
description: 'Auto bump version?'
|
||||
description: "Auto bump version?"
|
||||
required: true
|
||||
bump_type:
|
||||
type: choice
|
||||
description: 'Bump type'
|
||||
description: "Bump type"
|
||||
required: true
|
||||
options:
|
||||
- 'major'
|
||||
- 'minor'
|
||||
- 'patch'
|
||||
- 'prerelease'
|
||||
- "major"
|
||||
- "minor"
|
||||
- "patch"
|
||||
- "prerelease"
|
||||
as_pre_release:
|
||||
type: boolean
|
||||
description: 'As pre-release?'
|
||||
description: "As pre-release?"
|
||||
required: true
|
||||
prerelease_type:
|
||||
type: choice
|
||||
description: 'Pre-release label'
|
||||
description: "Pre-release label"
|
||||
required: true
|
||||
options:
|
||||
- 'dev'
|
||||
- 'alpha'
|
||||
- 'beta'
|
||||
- 'rc'
|
||||
- 'post'
|
||||
- "dev"
|
||||
- "alpha"
|
||||
- "beta"
|
||||
- "rc"
|
||||
- "post"
|
||||
jobs:
|
||||
bump_version:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -44,7 +44,7 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
submodules: 'recursive'
|
||||
submodules: "recursive"
|
||||
|
||||
- name: 📦 install uv
|
||||
uses: astral-sh/setup-uv@v5
|
||||
@@ -92,9 +92,12 @@ jobs:
|
||||
echo "Changes:" && cat release_body.md
|
||||
uv run git-cliff > CHANGELOG.md
|
||||
|
||||
- name: 📦 update lockfile (re-sync)
|
||||
run: uv sync
|
||||
|
||||
- name: 📤 push changes
|
||||
run: |
|
||||
git add CHANGELOG.md pyproject.toml src/*/__init__.py
|
||||
git add CHANGELOG.md pyproject.toml src/*/__init__.py uv.lock
|
||||
git commit -m "chore(release): ${{ steps.get_version.outputs.BUMPED_VERSION }}"
|
||||
git push origin main
|
||||
|
||||
@@ -105,13 +108,14 @@ jobs:
|
||||
tag_name: ${{ steps.get_version.outputs.BUMPED_VERSION }}
|
||||
body_path: release_body.md
|
||||
prerelease: ${{ github.event.inputs.as_pre_release }}
|
||||
discussion_category_name: 'Announcements'
|
||||
discussion_category_name: "Announcements"
|
||||
|
||||
- name: 🧹 cleanup
|
||||
run: |
|
||||
rm release_body.md
|
||||
|
||||
- name: 📤 merge into develop
|
||||
continue-on-error: true
|
||||
run: |
|
||||
git checkout develop
|
||||
git merge main
|
||||
|
||||
8
.vscode/launch.json
vendored
8
.vscode/launch.json
vendored
@@ -2,10 +2,12 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch Flask",
|
||||
"type": "node-terminal",
|
||||
"name": "Debug Flask",
|
||||
"type": "debugpy",
|
||||
"request": "launch",
|
||||
"command": "flask --app src/judas_server/web/web_server.py run --host=0.0.0.0"
|
||||
"program": "${workspaceFolder}/src/judas_server/__main__.py",
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"python.analysis.autoImportCompletions": true,
|
||||
"python.analysis.typeCheckingMode": "standard",
|
||||
"python.analysis.typeCheckingMode": "standard"
|
||||
}
|
||||
|
||||
72
CHANGELOG.md
72
CHANGELOG.md
@@ -2,6 +2,78 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [0.2.0] - 2025-08-26
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- [`1fa3550`](https://github.com/pufereq/template-repo/commit/1fa355089df36404fc5128620674f8a535e6d2c5) **panel.py**: fix panel route to be at `/panel` instead of `/panel/`
|
||||
- [`d8405fa`](https://github.com/pufereq/template-repo/commit/d8405fa36376a29b1f5ae99f571f2adc8a6cc978) **server.py**: fix placeholder naming to be consistent
|
||||
- [`8ad55ee`](https://github.com/pufereq/template-repo/commit/8ad55eed10dcc7d2fb849f3643dc805903f560a7) **__main__.py**: fix wrong import path
|
||||
- [`23a53f7`](https://github.com/pufereq/template-repo/commit/23a53f79a073d4c88756a347312340f59d31b0da) **web_server.py**: fix server error when using /stream
|
||||
|
||||
### Features
|
||||
|
||||
- [`9f74246`](https://github.com/pufereq/template-repo/commit/9f74246157717216b7687b0ca5cb453fba60405e) **web_server.py**: use socketio
|
||||
- [`84ce509`](https://github.com/pufereq/template-repo/commit/84ce50963b7811c45e0c7fe94a1e66d71da70060) **routes/api.py**: add API route
|
||||
- [`dbb464e`](https://github.com/pufereq/template-repo/commit/dbb464e41ccac68854a30084122aaa7659272081) **__main__.py**: call `BackendServer.run()`
|
||||
- [`b8f5fdc`](https://github.com/pufereq/template-repo/commit/b8f5fdc794fe831386fb74e5ecb872f9ea118ec2) **server.py**: create a thread for _poll_loop
|
||||
- [`a494b60`](https://github.com/pufereq/template-repo/commit/a494b606a5bf796685b1c0757c69d63d62e5e8a2) **web_server.py**: add `WEB_SERVER` and `BACKEND` app.configs
|
||||
- [`4285da4`](https://github.com/pufereq/template-repo/commit/4285da4fa8be01e29041ec31bdf451d90f3e9825) **web_server.py**: add BackendServer reference to webserver
|
||||
- [`14450ba`](https://github.com/pufereq/template-repo/commit/14450ba70df1b6d7effeb66407db2a4f03846404) **__main__.py**: init BackendServer in __main__
|
||||
- [`2964ac7`](https://github.com/pufereq/template-repo/commit/2964ac76442425ab0078366cbe0f4162bab87638) **backend/server.py**: add placeholder backend
|
||||
- [`38da1f4`](https://github.com/pufereq/template-repo/commit/38da1f476e3509d8c57b1c0a298e21bc1536c6d4) **templates/login.html**: autofocus password field
|
||||
- [`d91f135`](https://github.com/pufereq/template-repo/commit/d91f135d5361ab91c55c43303e4eb2ae8e688ea2) **user.py**: add user management
|
||||
- [`c1e20e5`](https://github.com/pufereq/template-repo/commit/c1e20e55245fa199d494453c9adf59addd232b86) **routes/__init__.py**: add __init__.py
|
||||
- [`d56256f`](https://github.com/pufereq/template-repo/commit/d56256f6816b6f0043791bcb288264554cd68cf0) **routes/panel.py**: add panel.py route blueprint
|
||||
- [`bbaffb3`](https://github.com/pufereq/template-repo/commit/bbaffb344fe0d519d2c535dc61902514acb3db9a) **routes/auth.py**: add auth.py route blueprint
|
||||
- [`50be48d`](https://github.com/pufereq/template-repo/commit/50be48dba4e895a73b09c9af32fa27268df7561a) **routes/index.py**: add index.py route blueprint
|
||||
- [`44df495`](https://github.com/pufereq/template-repo/commit/44df49509691505d9ec749395bc330a23e72fd38) **palette.css**: add catppuccin color palette
|
||||
- [`8dbbea3`](https://github.com/pufereq/template-repo/commit/8dbbea3f56894753edcf7acdd0961634fcac8732) **__main__.py**: add __main__.py
|
||||
|
||||
### Miscellaneous Tasks
|
||||
|
||||
- [`89b6c1e`](https://github.com/pufereq/template-repo/commit/89b6c1ee835f7bf7cc8511683a0637f893daec25) **release.yaml**: update with latest pufereq/python-template release.yaml
|
||||
- [`860ce5c`](https://github.com/pufereq/template-repo/commit/860ce5c836ec459b6ae70adf5583d9f5b6f8858f) **panel.py**: remove unnecesarry imports
|
||||
- [`c628498`](https://github.com/pufereq/template-repo/commit/c628498637ab2a3d3554ee1e80a9872ecfd0d5e0) **__main__.py**: change log format
|
||||
- [`90094e9`](https://github.com/pufereq/template-repo/commit/90094e9c4380c9f516e1134b75f13fac775d9cd0) **web_server.py**: remove LoginManager from `self.app.config`
|
||||
- [`5a4b5dd`](https://github.com/pufereq/template-repo/commit/5a4b5ddd82bce3de8198dd2955c71edf5625d131) **backend/__init__.py**: add BackendServer to __all__
|
||||
- [`1d00d5f`](https://github.com/pufereq/template-repo/commit/1d00d5f4f5cecb5c7e6b65347a29b3bfdfa48ddd) **routes/auth.py**: make login fail message more ambigiuous
|
||||
- [`a3e9aed`](https://github.com/pufereq/template-repo/commit/a3e9aed6f4caecf2b6c707ae5b87f395e788ccc3) **web_server.py**: add `web server` to initial loggin to avoid confusion
|
||||
- [`a32df2f`](https://github.com/pufereq/template-repo/commit/a32df2fd67a038b7bf147e83cbcca96498b89d58) **templates/stream.html**: remove stream.html template
|
||||
- [`1901441`](https://github.com/pufereq/template-repo/commit/190144194887865716977acc51971323ab0e0bdf) **py.typed**: add py.typed
|
||||
- [`f8f74cc`](https://github.com/pufereq/template-repo/commit/f8f74ccd4b27c9dc85c58b76d2328e9e7a288403) **routes/__init__.py**: add __init__.py
|
||||
- [`89dd67b`](https://github.com/pufereq/template-repo/commit/89dd67b4897cfda2af9387d0f3bd6cdaa531d85e) **backend/__init__.py**: add __init__.py
|
||||
- [`dbc61ac`](https://github.com/pufereq/template-repo/commit/dbc61ac6b73e821ba3ba6987bda68d8b84089aec) **web/__init__.py**: add web/__init__.py
|
||||
|
||||
### Refactor
|
||||
|
||||
- [`e6cc1d9`](https://github.com/pufereq/template-repo/commit/e6cc1d901e2eaaef2c65e9cf02ee4c6b1fd2d425) **panel.html**: rewrite panel.html template
|
||||
- [`9e71270`](https://github.com/pufereq/template-repo/commit/9e71270e41aaa4e241e82d1688a29d1a9823fed4) **panel.py**: remove unnecesarry args to `render_template`
|
||||
- [`1140052`](https://github.com/pufereq/template-repo/commit/11400520c984bb6efb85f3a6ed8acfd2a5cfe177) **server.py**: fix method naming and add logging
|
||||
- [`77b6bd0`](https://github.com/pufereq/template-repo/commit/77b6bd07327cfe9750b18bcc7fcdb980b127ab27) **web_server.py**: rewrite to use OOP
|
||||
- [`8b418a7`](https://github.com/pufereq/template-repo/commit/8b418a7d52c0a32d967da735bc6c519cf2808804) **templates/panel.html**: adapt urls for blueprints
|
||||
- [`3e1fe9f`](https://github.com/pufereq/template-repo/commit/3e1fe9fa1e53a0376b2073fd208470bfb57ea1b0) **templates/login.html**: adapt urls for blueprints
|
||||
- [`bd9d95b`](https://github.com/pufereq/template-repo/commit/bd9d95b741e1bc032d0fa7c816f802ce678b5645) **templates/index.html**: adapt urls for blueprints
|
||||
- [`4baf29e`](https://github.com/pufereq/template-repo/commit/4baf29eb4afba7cf2cfab4e0ab5853d0c94c6ed1) **templates/details.html**: adapt urls for blueprints
|
||||
- [`fc5dc23`](https://github.com/pufereq/template-repo/commit/fc5dc23c0e222db257f7fb55d0b878db5c3a255d) **style.css**: use new palette
|
||||
- [`e575e8a`](https://github.com/pufereq/template-repo/commit/e575e8a15dd36616ac0d722e13e90a2df59af8b1) **.vscode/launch.json**: use __main__.py for running web server
|
||||
|
||||
### Styling
|
||||
|
||||
- [`3bcffaa`](https://github.com/pufereq/template-repo/commit/3bcffaafab8ed9bd2f5cf0380d560ea1dc70616b) **style.css**: format w/ prettier
|
||||
- [`055ab10`](https://github.com/pufereq/template-repo/commit/055ab10ab702094c8a07f8e5317098e0f95eaffa) **__main__.py**: add typing
|
||||
- [`9949179`](https://github.com/pufereq/template-repo/commit/99491799970e28ec488dee0f9958ea885d5b7383) **login.html**: format
|
||||
- [`6a07272`](https://github.com/pufereq/template-repo/commit/6a072724f293e52d0d9eaef5ca70b92be05c115b) **index.html**: format
|
||||
- [`b79f3f3`](https://github.com/pufereq/template-repo/commit/b79f3f3387b15726a2b42fb17f2355fdb97a4a4a) **details.html**: format with prettier
|
||||
- [`5fb6920`](https://github.com/pufereq/template-repo/commit/5fb69204361379dab44c426c61a170baa1364280) **.vscode/settings.json**: fix indentation
|
||||
- [`c2e1984`](https://github.com/pufereq/template-repo/commit/c2e198495930f667eb8d777299dfcf2e83f88301) **web_server.py**: fix typing errors
|
||||
|
||||
### Build
|
||||
|
||||
- [`786c43a`](https://github.com/pufereq/template-repo/commit/786c43ae06f0550d589e74c94b14cd1a9b1136c6) **uv.lock**: add `flask-socketio` depedency
|
||||
- [`309efe0`](https://github.com/pufereq/template-repo/commit/309efe074b24d9964dd7d2b767e85d533d526006) **pyproject.toml**: add `flask-socketio` depedency
|
||||
- [`6bed7da`](https://github.com/pufereq/template-repo/commit/6bed7da165f3c361d938d52ba94b3e2e15894d76) **pyproject.toml**: use basic type checking to kinda supress flask_login's nonexistent typing
|
||||
|
||||
## [0.1.1] - 2025-08-09
|
||||
|
||||
### Miscellaneous Tasks
|
||||
|
||||
@@ -4,12 +4,16 @@ build-backend = "uv_build"
|
||||
|
||||
[project]
|
||||
name = "judas_server"
|
||||
version = "0.1.1"
|
||||
version = "0.2.0"
|
||||
description = "The backbone of the remote PC fleet management system."
|
||||
readme = "README.md"
|
||||
authors = []
|
||||
requires-python = ">=3.13"
|
||||
dependencies = ["flask>=3.1.1", "flask-login>=0.6.3"]
|
||||
dependencies = [
|
||||
"flask>=3.1.1",
|
||||
"flask-login>=0.6.3",
|
||||
"flask-socketio>=5.5.1",
|
||||
]
|
||||
license = { text = "GPL-3.0+" }
|
||||
|
||||
[dependency-groups]
|
||||
@@ -21,6 +25,9 @@ test = [
|
||||
"pytest-mock>=3.14.1",
|
||||
]
|
||||
|
||||
[tool.basedpyright]
|
||||
typeCheckingMode = "basic"
|
||||
|
||||
[tool.ruff]
|
||||
line-length = 79
|
||||
exclude = ["tests/*"]
|
||||
|
||||
23
src/judas_server/__main__.py
Normal file
23
src/judas_server/__main__.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging as lg
|
||||
|
||||
if __name__ == "__main__":
|
||||
from judas_server.web.web_server import JudasWebServer
|
||||
from judas_server.backend import BackendServer
|
||||
|
||||
lg.basicConfig(
|
||||
level=lg.DEBUG,
|
||||
format="%(asctime)s : [%(levelname)s] : %(threadName)s : %(name)s :: %(message)s",
|
||||
)
|
||||
|
||||
backend_server: BackendServer = BackendServer()
|
||||
backend_server.run()
|
||||
|
||||
web_server: JudasWebServer = JudasWebServer(
|
||||
backend=backend_server, secret_key="dildo"
|
||||
)
|
||||
web_server.run(
|
||||
host="0.0.0.0",
|
||||
port=5000,
|
||||
)
|
||||
3
src/judas_server/backend/__init__.py
Normal file
3
src/judas_server/backend/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .server import BackendServer
|
||||
|
||||
__all__ = ["BackendServer"]
|
||||
54
src/judas_server/backend/server.py
Normal file
54
src/judas_server/backend/server.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import logging as lg
|
||||
import random as rn
|
||||
import threading
|
||||
import time
|
||||
|
||||
|
||||
class BackendServer:
|
||||
def __init__(self) -> None:
|
||||
self.logger: lg.Logger = lg.getLogger(
|
||||
f"{__name__}.{self.__class__.__name__}"
|
||||
)
|
||||
self.logger.debug("Initializing Server...")
|
||||
|
||||
# TODO: add socket logic here
|
||||
|
||||
self.clients: dict[str, dict[str, dict[str, Any]]] = {
|
||||
"C_01": {
|
||||
"one_time": {
|
||||
"hostname": "mock-host",
|
||||
"platform": "windows 11",
|
||||
"cpu_info": "i7",
|
||||
},
|
||||
"polled": {"cpu_usage": 0, "ram_usage": 0},
|
||||
"ondemand": {},
|
||||
}
|
||||
}
|
||||
|
||||
self.running: bool = False
|
||||
|
||||
def run(self) -> None:
|
||||
self.running = True
|
||||
threading.Thread(
|
||||
name="BackendServer thread", target=self._loop, daemon=True
|
||||
).start()
|
||||
|
||||
def _loop(self) -> None:
|
||||
self.logger.info("Starting server loop...")
|
||||
while self.running:
|
||||
for client in self.clients.values():
|
||||
client["polled"]["cpu_usage"] = round(rn.uniform(0, 100), 1)
|
||||
client["polled"]["ram_usage"] = round(rn.uniform(0, 100), 1)
|
||||
time.sleep(1)
|
||||
|
||||
self.logger.info("Server loop stopped.")
|
||||
|
||||
def get_client_data(
|
||||
self, client_id: str
|
||||
) -> dict[str, dict[str, Any]] | None:
|
||||
return self.clients.get(client_id, None)
|
||||
0
src/judas_server/py.typed
Normal file
0
src/judas_server/py.typed
Normal file
0
src/judas_server/web/__init__.py
Normal file
0
src/judas_server/web/__init__.py
Normal file
5
src/judas_server/web/routes/__init__.py
Normal file
5
src/judas_server/web/routes/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from .auth import auth_bp
|
||||
from .index import index_bp
|
||||
from .panel import panel_bp
|
||||
|
||||
__all__ = ["auth_bp", "index_bp", "panel_bp"]
|
||||
60
src/judas_server/web/routes/api.py
Normal file
60
src/judas_server/web/routes/api.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import annotations
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import flask
|
||||
import flask_login
|
||||
import threading
|
||||
import logging as lg
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from werkzeug.wrappers import Response
|
||||
|
||||
bp: flask.Blueprint = flask.Blueprint("api", __name__, url_prefix="/api")
|
||||
|
||||
|
||||
@bp.route("/client/<client_id>", methods=["GET"])
|
||||
@flask_login.login_required
|
||||
def get_client_data(client_id: str) -> tuple[Response, int]:
|
||||
"""API endpoint to get client data by ID.
|
||||
|
||||
Args:
|
||||
client_id (str): The ID of the client.
|
||||
|
||||
Returns:
|
||||
Response: JSON response with client data or error message.
|
||||
"""
|
||||
backend = flask.current_app.config["BACKEND"]
|
||||
data = backend.get_client_data(client_id)
|
||||
if data is None:
|
||||
return flask.jsonify({"error": "Client not found"}), 404
|
||||
return flask.jsonify(data), 200
|
||||
|
||||
|
||||
@bp.route("/clients", methods=["GET"])
|
||||
@flask_login.login_required
|
||||
def list_clients() -> tuple[Response, int]:
|
||||
"""API endpoint to list all clients.
|
||||
|
||||
Returns:
|
||||
Response: JSON response with list of client IDs.
|
||||
"""
|
||||
backend = flask.current_app.config["BACKEND"]
|
||||
client_ids = list(backend.clients.keys())
|
||||
return flask.jsonify({"clients": client_ids}), 200
|
||||
|
||||
|
||||
def emit_polled_data(app, socketio):
|
||||
backend = app.config["BACKEND"]
|
||||
|
||||
def poll_loop():
|
||||
import time
|
||||
|
||||
while True:
|
||||
for client_id, data in backend.clients.items():
|
||||
socketio.emit("update_data", {client_id: data})
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
threading.Thread(name="Socketio", target=poll_loop, daemon=True).start()
|
||||
42
src/judas_server/web/routes/auth.py
Normal file
42
src/judas_server/web/routes/auth.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import annotations
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import flask
|
||||
import flask_login
|
||||
|
||||
from judas_server.web.user import User
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from werkzeug.wrappers import Response
|
||||
|
||||
auth_bp: flask.Blueprint = flask.Blueprint(
|
||||
"auth", __name__, url_prefix="/auth"
|
||||
)
|
||||
|
||||
|
||||
@auth_bp.route("/login", methods=["GET", "POST"])
|
||||
def login() -> Response | str:
|
||||
"""Handles user login via password form."""
|
||||
if flask.request.method == "POST":
|
||||
password = flask.request.form.get("password", "")
|
||||
if password == flask.current_app.config["PASSWORD"]:
|
||||
user = User("admin")
|
||||
flask_login.login_user(user)
|
||||
next_page = flask.request.args.get("next")
|
||||
return flask.redirect(next_page or flask.url_for("index.index"))
|
||||
# return flask.redirect(flask.url_for("panel.panel"))
|
||||
else:
|
||||
return flask.render_template(
|
||||
"login.html",
|
||||
error="Invalid credentials.",
|
||||
)
|
||||
return flask.render_template("login.html")
|
||||
|
||||
|
||||
@auth_bp.route("/logout")
|
||||
@flask_login.login_required
|
||||
def logout() -> Response:
|
||||
"""Logs out the current user."""
|
||||
flask_login.logout_user()
|
||||
return flask.redirect(flask.url_for("index.index"))
|
||||
20
src/judas_server/web/routes/index.py
Normal file
20
src/judas_server/web/routes/index.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import annotations
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import flask
|
||||
import flask_login
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from werkzeug.wrappers import Response
|
||||
|
||||
index_bp: flask.Blueprint = flask.Blueprint("index", __name__)
|
||||
|
||||
|
||||
@index_bp.route("/")
|
||||
def index() -> Response | str:
|
||||
"""Renders the index page."""
|
||||
return flask.render_template(
|
||||
"index.html", logged=flask_login.current_user.is_authenticated
|
||||
)
|
||||
21
src/judas_server/web/routes/panel.py
Normal file
21
src/judas_server/web/routes/panel.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import annotations
|
||||
|
||||
import flask
|
||||
import flask_login
|
||||
|
||||
|
||||
panel_bp: flask.Blueprint = flask.Blueprint(
|
||||
"panel", __name__, url_prefix="/panel"
|
||||
)
|
||||
|
||||
|
||||
@panel_bp.route("")
|
||||
@flask_login.login_required
|
||||
def panel() -> str:
|
||||
"""Renders the main panel page with PC details.
|
||||
|
||||
Returns:
|
||||
Rendered HTML template with PC details.
|
||||
"""
|
||||
return flask.render_template("panel.html")
|
||||
80
src/judas_server/web/static/css/palette.css
Normal file
80
src/judas_server/web/static/css/palette.css
Normal file
@@ -0,0 +1,80 @@
|
||||
:root {
|
||||
--ctp-rosewater: #f5e0dc;
|
||||
--ctp-rosewater-rgb: 245 224 220;
|
||||
--ctp-rosewater-hsl: 9.600 55.556% 91.176%;
|
||||
--ctp-flamingo: #f2cdcd;
|
||||
--ctp-flamingo-rgb: 242 205 205;
|
||||
--ctp-flamingo-hsl: 0.000 58.730% 87.647%;
|
||||
--ctp-pink: #f5c2e7;
|
||||
--ctp-pink-rgb: 245 194 231;
|
||||
--ctp-pink-hsl: 316.471 71.831% 86.078%;
|
||||
--ctp-mauve: #cba6f7;
|
||||
--ctp-mauve-rgb: 203 166 247;
|
||||
--ctp-mauve-hsl: 267.407 83.505% 80.980%;
|
||||
--ctp-red: #f38ba8;
|
||||
--ctp-red-rgb: 243 139 168;
|
||||
--ctp-red-hsl: 343.269 81.250% 74.902%;
|
||||
--ctp-maroon: #eba0ac;
|
||||
--ctp-maroon-rgb: 235 160 172;
|
||||
--ctp-maroon-hsl: 350.400 65.217% 77.451%;
|
||||
--ctp-peach: #fab387;
|
||||
--ctp-peach-rgb: 250 179 135;
|
||||
--ctp-peach-hsl: 22.957 92.000% 75.490%;
|
||||
--ctp-yellow: #f9e2af;
|
||||
--ctp-yellow-rgb: 249 226 175;
|
||||
--ctp-yellow-hsl: 41.351 86.047% 83.137%;
|
||||
--ctp-green: #a6e3a1;
|
||||
--ctp-green-rgb: 166 227 161;
|
||||
--ctp-green-hsl: 115.455 54.098% 76.078%;
|
||||
--ctp-teal: #94e2d5;
|
||||
--ctp-teal-rgb: 148 226 213;
|
||||
--ctp-teal-hsl: 170.000 57.353% 73.333%;
|
||||
--ctp-sky: #89dceb;
|
||||
--ctp-sky-rgb: 137 220 235;
|
||||
--ctp-sky-hsl: 189.184 71.014% 72.941%;
|
||||
--ctp-sapphire: #74c7ec;
|
||||
--ctp-sapphire-rgb: 116 199 236;
|
||||
--ctp-sapphire-hsl: 198.500 75.949% 69.020%;
|
||||
--ctp-blue: #89b4fa;
|
||||
--ctp-blue-rgb: 137 180 250;
|
||||
--ctp-blue-hsl: 217.168 91.870% 75.882%;
|
||||
--ctp-lavender: #b4befe;
|
||||
--ctp-lavender-rgb: 180 190 254;
|
||||
--ctp-lavender-hsl: 231.892 97.368% 85.098%;
|
||||
--ctp-text: #cdd6f4;
|
||||
--ctp-text-rgb: 205 214 244;
|
||||
--ctp-text-hsl: 226.154 63.934% 88.039%;
|
||||
--ctp-subtext1: #bac2de;
|
||||
--ctp-subtext1-rgb: 186 194 222;
|
||||
--ctp-subtext1-hsl: 226.667 35.294% 80.000%;
|
||||
--ctp-subtext0: #a6adc8;
|
||||
--ctp-subtext0-rgb: 166 173 200;
|
||||
--ctp-subtext0-hsl: 227.647 23.611% 71.765%;
|
||||
--ctp-overlay2: #9399b2;
|
||||
--ctp-overlay2-rgb: 147 153 178;
|
||||
--ctp-overlay2-hsl: 228.387 16.757% 63.725%;
|
||||
--ctp-overlay1: #7f849c;
|
||||
--ctp-overlay1-rgb: 127 132 156;
|
||||
--ctp-overlay1-hsl: 229.655 12.775% 55.490%;
|
||||
--ctp-overlay0: #6c7086;
|
||||
--ctp-overlay0-rgb: 108 112 134;
|
||||
--ctp-overlay0-hsl: 230.769 10.744% 47.451%;
|
||||
--ctp-surface2: #585b70;
|
||||
--ctp-surface2-rgb: 88 91 112;
|
||||
--ctp-surface2-hsl: 232.500 12.000% 39.216%;
|
||||
--ctp-surface1: #45475a;
|
||||
--ctp-surface1-rgb: 69 71 90;
|
||||
--ctp-surface1-hsl: 234.286 13.208% 31.176%;
|
||||
--ctp-surface0: #313244;
|
||||
--ctp-surface0-rgb: 49 50 68;
|
||||
--ctp-surface0-hsl: 236.842 16.239% 22.941%;
|
||||
--ctp-base: #1e1e2e;
|
||||
--ctp-base-rgb: 30 30 46;
|
||||
--ctp-base-hsl: 240.000 21.053% 14.902%;
|
||||
--ctp-mantle: #181825;
|
||||
--ctp-mantle-rgb: 24 24 37;
|
||||
--ctp-mantle-hsl: 240.000 21.311% 11.961%;
|
||||
--ctp-crust: #11111b;
|
||||
--ctp-crust-rgb: 17 17 27;
|
||||
--ctp-crust-hsl: 240.000 22.727% 8.627%;
|
||||
}
|
||||
@@ -1,22 +1,4 @@
|
||||
:root {
|
||||
--nord-bg0: #2e3440;
|
||||
--nord-bg1: #3b4252;
|
||||
--nord-bg2: #434c5e;
|
||||
--nord-bg3: #4c566a;
|
||||
--nord-fg0: #eceff4;
|
||||
--nord-fg1: #e5e9f0;
|
||||
--nord-fg2: #d8dee9;
|
||||
--nord-acc0: #8fbcbb;
|
||||
--nord-acc1: #88c0d0;
|
||||
--nord-acc2: #81a1c1;
|
||||
--nord-acc3: #5e81ac;
|
||||
--nord-aur0: #bf616a;
|
||||
--nord-aur1: #d08770;
|
||||
--nord-aur2: #ebcb8b;
|
||||
--nord-aur3: #a3be8c;
|
||||
--nord-aur4: #b48ead;
|
||||
|
||||
}
|
||||
@import "palette.css";
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
@@ -25,22 +7,22 @@
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: var(--nord-aur4);
|
||||
background-color: var(--ctp-base);
|
||||
font-family: monospace, sans-serif !important;
|
||||
color: var(--nord-fg0);
|
||||
color: var(--ctp-text);
|
||||
}
|
||||
|
||||
input {
|
||||
font-family: inherit;
|
||||
color: #eceff4;
|
||||
background-color: var(--nord-bg2);
|
||||
background-color: var(--ctp-crust);
|
||||
border: none;
|
||||
border-radius: 0.25rem;
|
||||
padding: 0.25rem;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--nord-acc0);
|
||||
color: var(--ctp-blue);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
@@ -54,8 +36,8 @@ header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background-color: var(--nord-bg0);
|
||||
color: var(--nord-fg0);
|
||||
background-color: var(--ctp-mantle);
|
||||
/* color: var(--ctp-text); */
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
@@ -64,34 +46,33 @@ main {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
padding: 1rem;
|
||||
background-color: var(--nord-bg1);
|
||||
/* background-color: var(--ctp-base); */
|
||||
flex-grow: 1;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
header a {
|
||||
text-decoration: none;
|
||||
color: var(--nord-fg0);
|
||||
/* color: var(--nord-fg0); */
|
||||
}
|
||||
|
||||
.button {
|
||||
display: inline-block;
|
||||
padding: 0.5rem 1rem;
|
||||
background-color: var(--nord-acc0);
|
||||
color: var(--nord-bg0);
|
||||
background-color: var(--ctp-lavender);
|
||||
color: var(--ctp-base);
|
||||
border: none;
|
||||
border-radius: 0.25rem;
|
||||
text-decoration: none;
|
||||
transition: 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
.button a:hover {
|
||||
color: var(--nord-bg0);
|
||||
text-decoration: none;
|
||||
}
|
||||
/* .button a:hover { */
|
||||
/* color: var(--nord-bg0); */
|
||||
/* text-decoration: none; */
|
||||
/* } */
|
||||
|
||||
.button:hover {
|
||||
background-color: var(--nord-acc2);
|
||||
background-color: var(--ctp-mauve);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
@@ -106,9 +87,9 @@ header a {
|
||||
justify-content: center;
|
||||
margin: 1rem;
|
||||
padding: 1rem;
|
||||
background-color: var(--nord-aur0);
|
||||
color: var(--nord-fg0);
|
||||
border: 6px solid var(--nord-aur1);
|
||||
background-color: var(--ctp-surface0);
|
||||
color: var(--ctp-red);
|
||||
border: 6px solid var(--ctp-red);
|
||||
border-radius: 24px;
|
||||
}
|
||||
|
||||
@@ -117,9 +98,9 @@ header a {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.select-table{
|
||||
.select-table {
|
||||
border-collapse: collapse;
|
||||
border: 2px solid var(--nord-fg0);
|
||||
border: 2px solid var(--ctp-surface0);
|
||||
}
|
||||
|
||||
.select-table thead {
|
||||
@@ -128,21 +109,22 @@ header a {
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.select-table th, .select-table td {
|
||||
.select-table th,
|
||||
.select-table td {
|
||||
padding: 0.5rem;
|
||||
text-align: center;
|
||||
border: 1px solid var(--nord-fg1);
|
||||
border: 1px solid var(--ctp-surface0);
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.select-table th {
|
||||
background-color: var(--nord-bg2);
|
||||
background-color: var(--ctp-surface1);
|
||||
color: var(--nord-fg0);
|
||||
}
|
||||
|
||||
.select-table a {
|
||||
display: block;
|
||||
color: var(--nord-acc0);
|
||||
/* color: var(--nord-acc0); */
|
||||
text-decoration: none;
|
||||
transition: 0.1s ease-in-out;
|
||||
}
|
||||
@@ -152,23 +134,23 @@ header a {
|
||||
}
|
||||
|
||||
.select-table tr:hover {
|
||||
background-color: var(--nord-acc1);
|
||||
background-color: var(--ctp-surface0);
|
||||
}
|
||||
|
||||
.select-table tr:hover a {
|
||||
color: var(--nord-bg0);
|
||||
color: var(--ctp-base);
|
||||
}
|
||||
|
||||
.red-bg {
|
||||
background-color: var(--nord-aur0);
|
||||
background-color: var(--ctp-red);
|
||||
}
|
||||
|
||||
.yellow-bg {
|
||||
background-color: var(--nord-aur2);
|
||||
background-color: var(--ctp-yellow);
|
||||
}
|
||||
|
||||
.green-bg {
|
||||
background-color: var(--nord-aur3);
|
||||
background-color: var(--ctp-green);
|
||||
}
|
||||
|
||||
.button-container {
|
||||
@@ -183,24 +165,38 @@ header a {
|
||||
}
|
||||
|
||||
.link:hover {
|
||||
color: var(--nord-acc2);
|
||||
color: var(--ctp-blue);
|
||||
}
|
||||
|
||||
.details-table tr td:first-child {
|
||||
font-weight: 900;
|
||||
background-color: var(--nord-bg3);
|
||||
background-color: var(--ctp-surface0);
|
||||
white-space: nowrap;
|
||||
width: 1%;
|
||||
}
|
||||
|
||||
.details-table {
|
||||
border-collapse: collapse;
|
||||
border: 2px solid var(--nord-fg0);
|
||||
border: 2px solid var(--ctp-surface1);
|
||||
}
|
||||
|
||||
.details-table th, .details-table td {
|
||||
.details-table th,
|
||||
.details-table td {
|
||||
padding: 0.5rem;
|
||||
text-align: left;
|
||||
border: 1px solid var(--nord-fg1);
|
||||
border: 1px solid var(--ctp-text);
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
#notify {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 3rem;
|
||||
right: 50%;
|
||||
transform: translateX(50%);
|
||||
background-color: var(--ctp-surface1);
|
||||
padding: 1rem 2rem;
|
||||
border: 4px solid var(--ctp-text);
|
||||
border-radius: 1rem;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>judas panel - details</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="{{ url_for('static', filename='css/style.css') }}"
|
||||
/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="wrapper">
|
||||
<header>
|
||||
<h1><a href="{{ url_for('index') }}">judas</a></h1>
|
||||
<h1><a href="{{ url_for('index.index') }}">judas</a></h1>
|
||||
<p><a class="button" href="{{ url_for('logout') }}">Logout</a></p>
|
||||
</header>
|
||||
<main>
|
||||
<div class="button-container">
|
||||
<p><a href="{{ url_for('panel') }}" class="link">Back to Panel</a></p>
|
||||
<h2>{{ pc.id }}</h2>
|
||||
<p><a href="{{ url_for('stream', pc_id=pc.id) }}" class="link">View Stream</a></p>
|
||||
<p>
|
||||
<a href="{{ url_for('stream', pc_id=pc.id) }}" class="link"
|
||||
>View Stream</a
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
<table class="center-table details-table">
|
||||
<tbody>
|
||||
@@ -32,5 +39,6 @@
|
||||
</table>
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
<body>
|
||||
<div id="wrapper">
|
||||
<header>
|
||||
<h1><a href="{{ url_for('index') }}">judas</a></h1>
|
||||
<h1><a href="{{ url_for('index.index') }}">judas</a></h1>
|
||||
{% if logged %}
|
||||
<p><a class="button" href="{{ url_for('logout') }}">Logout</a></p>
|
||||
<p><a class="button" href="{{ url_for('auth.logout') }}">Logout</a></p>
|
||||
{% else %}
|
||||
<p><a class="button" href="{{ url_for('login') }}">Login</a></p>
|
||||
<p><a class="button" href="{{ url_for('auth.login') }}">Login</a></p>
|
||||
{% endif %}
|
||||
</header>
|
||||
<main class="center">
|
||||
@@ -24,9 +24,9 @@
|
||||
</div>
|
||||
<p style="color: #bf616a;"><strong>Notice:</strong> Please use this system responsibly and in accordance with all applicable laws and organizational policies.</p>
|
||||
{% if logged %}
|
||||
<p><a class="button" href="{{ url_for('panel') }}">Go to panel</a></p>
|
||||
<p><a class="button" href="{{ url_for('panel.panel') }}">Go to panel</a></p>
|
||||
{% else %}
|
||||
<p>Please <a href="{{ url_for('login')}}" class="link">log in</a> to manage your remote PCs.</p>
|
||||
<p>Please <a href="{{ url_for('auth.login')}}" class="link">log in</a> to manage your remote PCs.</p>
|
||||
{% endif %}
|
||||
</main>
|
||||
</div>
|
||||
|
||||
@@ -9,13 +9,13 @@
|
||||
<body>
|
||||
<div id="wrapper">
|
||||
<header>
|
||||
<h1><a href="{{ url_for('index') }}">judas</a></h1>
|
||||
<h1><a href="{{ url_for('index.index') }}">judas</a></h1>
|
||||
</header>
|
||||
<main>
|
||||
<h1>Login</h1>
|
||||
<form method="post" class="center">
|
||||
<label for="password">Password:</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
<input type="password" id="password" name="password" required autofocus>
|
||||
<br>
|
||||
<br>
|
||||
<input type="submit" value="Login" class="button">
|
||||
|
||||
@@ -1,42 +1,61 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>judas panel</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="{{ url_for('static', filename='css/style.css') }}"
|
||||
/>
|
||||
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
|
||||
<script src="https://cdn.socket.io/4.8.1/socket.io.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
const socket = io();
|
||||
const dataElement = $("#data");
|
||||
|
||||
const showNotify = (message) => {
|
||||
$("#notify").stop().fadeIn();
|
||||
$("#notify").text(message);
|
||||
setTimeout(() => {
|
||||
$("#notify").fadeOut();
|
||||
}, 3000);
|
||||
};
|
||||
|
||||
$("#notify").hide();
|
||||
|
||||
socket.on("connect", () => {
|
||||
console.log("Connected to server");
|
||||
showNotify("Connected to server");
|
||||
});
|
||||
|
||||
socket.on("disconnect", () => {
|
||||
console.log("Disconnected from server");
|
||||
showNotify("Disconnected from server");
|
||||
});
|
||||
|
||||
socket.on("update_data", (data) => {
|
||||
console.log("Received data:", data);
|
||||
document.getElementById("data").innerHTML = JSON.stringify(
|
||||
data,
|
||||
null,
|
||||
2,
|
||||
);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="wrapper">
|
||||
<header>
|
||||
<h1><a href="{{ url_for('index') }}">judas</a></h1>
|
||||
<p><a class="button" href="{{ url_for('logout') }}">Logout</a></p>
|
||||
<h1><a href="{{ url_for('index.index') }}">judas</a></h1>
|
||||
<p><a class="button" href="{{ url_for('auth.logout') }}">Logout</a></p>
|
||||
</header>
|
||||
<div id="notify"></div>
|
||||
<main>
|
||||
<h2 class="center">Select a PC to Control</h2>
|
||||
<p class="center">Choose a PC from the list below to view details or send commands.</p>
|
||||
<table class="center-table select-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>PC ID</th>
|
||||
<th>Status</th>
|
||||
<th>Last Seen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for pc in pcs.values() %}
|
||||
<tr>
|
||||
<td><a href="{{ url_for('details', pc_id=pc.id) }}">{{ pc.id }}</a></td>
|
||||
<td class='{% if pc.status == "online" %}green-bg{% elif pc.status == "offline" %}red-bg{% else %}yellow-bg{% endif %}'>{{ pc.status if pc.status else 'Unknown' }}</td> <td>{{ pc.last_seen if pc.last_seen else 'Never' }}</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
<td colspan="3">No PCs found.</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<pre id="data"></pre>
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,16 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>judas panel - stream</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="wrapper">
|
||||
<header>
|
||||
<h1><a href="{{ url_for('index') }}">judas</a></h1>
|
||||
<p><a class="button" href="{{ url_for('logout') }}">Logout</a></p>
|
||||
</header>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
29
src/judas_server/web/user.py
Normal file
29
src/judas_server/web/user.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import flask_login
|
||||
|
||||
|
||||
class User(flask_login.UserMixin):
|
||||
"""Represents a user for authentication purposes."""
|
||||
|
||||
def __init__(self, id: str) -> None:
|
||||
super().__init__()
|
||||
self.id = id
|
||||
|
||||
def get_id(self) -> str:
|
||||
"""Return the unique identifier for the user."""
|
||||
return self.id
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"User(id={self.id})"
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"User(id={self.id})"
|
||||
|
||||
|
||||
def load_user(user_id):
|
||||
if user_id == "admin":
|
||||
return User("admin")
|
||||
return None
|
||||
@@ -1,170 +1,72 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from typing import Final
|
||||
from __future__ import annotations
|
||||
|
||||
import flask
|
||||
import flask_login
|
||||
import logging as lg
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
PASSWORD: Final[str] = "123"
|
||||
from flask import Flask
|
||||
from flask_login import LoginManager
|
||||
from flask_socketio import SocketIO
|
||||
|
||||
app = flask.Flask(__name__)
|
||||
app.secret_key = "dildo"
|
||||
from judas_server.web.user import load_user
|
||||
|
||||
login_manager = flask_login.LoginManager()
|
||||
login_manager.init_app(app)
|
||||
if TYPE_CHECKING:
|
||||
from judas_server.backend import BackendServer
|
||||
|
||||
|
||||
PC_DETAILS = {
|
||||
"PC1": {
|
||||
"id": "PC1",
|
||||
"status": "online",
|
||||
"last_seen": "2023-10-01 12:00:00",
|
||||
},
|
||||
"PC2": {
|
||||
"id": "PC2",
|
||||
"status": "offline",
|
||||
"last_seen": "2023-10-01 11:00:00",
|
||||
},
|
||||
"PC3": {
|
||||
"id": "PC3",
|
||||
"status": "offline",
|
||||
"last_seen": "2023-10-01 11:00:00",
|
||||
},
|
||||
"PC4": {
|
||||
"id": "PC4",
|
||||
"status": "offline",
|
||||
"last_seen": "2023-10-01 11:00:00",
|
||||
},
|
||||
"PC5": {
|
||||
"id": "PC5",
|
||||
"status": "offline",
|
||||
"last_seen": "2023-10-01 11:00:00",
|
||||
},
|
||||
"PC6": {
|
||||
"id": "PC6",
|
||||
"status": "offline",
|
||||
"last_seen": "2023-10-01 11:00:00",
|
||||
},
|
||||
"PC7": {
|
||||
"id": "PC7",
|
||||
"status": "offline",
|
||||
"last_seen": "2023-10-01 11:00:00",
|
||||
},
|
||||
}
|
||||
class JudasWebServer:
|
||||
def __init__(self, backend: BackendServer, secret_key: str) -> None:
|
||||
self.logger: lg.Logger = lg.getLogger(
|
||||
f"{__name__}.{self.__class__.__name__}"
|
||||
)
|
||||
self.logger.debug("Initializing JudasWebServer...")
|
||||
|
||||
self.backend: BackendServer = backend
|
||||
|
||||
class User(flask_login.UserMixin):
|
||||
"""Represents a user for authentication purposes."""
|
||||
self.app: Flask = Flask(
|
||||
__name__, static_folder="static", template_folder="templates"
|
||||
)
|
||||
self.app.secret_key = secret_key
|
||||
|
||||
def __init__(self, id: str):
|
||||
super().__init__()
|
||||
self.id = id
|
||||
self.app.config["WEB_SERVER"] = self
|
||||
self.app.config["BACKEND"] = self.backend
|
||||
|
||||
# hard-code password
|
||||
self.app.config["PASSWORD"] = "123"
|
||||
|
||||
@login_manager.user_loader
|
||||
def load_user(user_id: str) -> User | None:
|
||||
"""Loads a user by user_id.
|
||||
# extensions
|
||||
self.login_manager: LoginManager = LoginManager()
|
||||
|
||||
Args:
|
||||
user_id: The ID of the user.
|
||||
self.socketio: SocketIO = SocketIO(self.app, cors_allowed_origins="*")
|
||||
|
||||
Returns:
|
||||
The User object if found, else None.
|
||||
"""
|
||||
if user_id == "admin":
|
||||
return User("admin")
|
||||
return None
|
||||
self.configure_extensions()
|
||||
self.init_routes()
|
||||
|
||||
def configure_extensions(self) -> None:
|
||||
self.logger.debug("Configuring extensions...")
|
||||
self.login_manager.init_app(self.app)
|
||||
self.login_manager.user_loader(load_user)
|
||||
self.login_manager.login_view = "auth.login"
|
||||
|
||||
@app.route("/")
|
||||
def index() -> flask.Response | str:
|
||||
"""Renders the index page with a link to the login page."""
|
||||
return flask.render_template(
|
||||
"index.html", logged=flask_login.current_user.is_authenticated
|
||||
# TODO: add login page
|
||||
|
||||
def init_routes(self) -> None:
|
||||
self.logger.debug("Initializing routes...")
|
||||
from judas_server.web.routes import (
|
||||
auth_bp,
|
||||
index_bp,
|
||||
panel_bp,
|
||||
api,
|
||||
)
|
||||
|
||||
self.app.register_blueprint(index_bp)
|
||||
self.app.register_blueprint(auth_bp)
|
||||
self.app.register_blueprint(panel_bp)
|
||||
self.app.register_blueprint(api.bp)
|
||||
api.emit_polled_data(self.app, self.socketio)
|
||||
|
||||
@app.route("/login", methods=["GET", "POST"])
|
||||
def login() -> str:
|
||||
"""Handles user login via password form."""
|
||||
if flask.request.method == "POST":
|
||||
password = flask.request.form.get("password", "")
|
||||
if password == PASSWORD:
|
||||
user = User("admin")
|
||||
flask_login.login_user(user)
|
||||
return flask.redirect(flask.url_for("panel"))
|
||||
else:
|
||||
return flask.render_template(
|
||||
"login.html",
|
||||
error="Invalid password. Please try again.",
|
||||
)
|
||||
return flask.render_template("login.html")
|
||||
|
||||
|
||||
@app.route("/logout")
|
||||
@flask_login.login_required
|
||||
def logout() -> str:
|
||||
"""Logs out the current user."""
|
||||
flask_login.logout_user()
|
||||
return flask.redirect(flask.url_for("index"))
|
||||
|
||||
|
||||
@app.route("/panel")
|
||||
@flask_login.login_required
|
||||
def panel() -> str:
|
||||
"""Renders the main panel page with PC details.
|
||||
|
||||
Returns:
|
||||
Rendered HTML template with PC details.
|
||||
"""
|
||||
return flask.render_template(
|
||||
"panel.html",
|
||||
username=flask_login.current_user.id,
|
||||
pcs=PC_DETAILS,
|
||||
)
|
||||
|
||||
|
||||
@app.route("/details/<pc_id>")
|
||||
@flask_login.login_required
|
||||
def details(pc_id: str) -> str:
|
||||
"""Renders the details page for a specific PC.
|
||||
|
||||
Args:
|
||||
pc_id: The ID of the PC to display details for.
|
||||
|
||||
Returns:
|
||||
Rendered HTML template with PC details.
|
||||
"""
|
||||
return flask.render_template(
|
||||
"details.html",
|
||||
username=flask_login.current_user.id,
|
||||
pc=PC_DETAILS[pc_id],
|
||||
)
|
||||
|
||||
|
||||
@app.route("/stream/<pc_id>")
|
||||
@flask_login.login_required
|
||||
def stream(pc_id: str) -> str:
|
||||
"""Renders the stream page for a specific PC.
|
||||
|
||||
Args:
|
||||
pc_id: The ID of the PC to stream from.
|
||||
|
||||
Returns:
|
||||
Rendered HTML template for streaming.
|
||||
"""
|
||||
return flask.render_template(
|
||||
logged=True,
|
||||
username=flask_login.current_user.id,
|
||||
pc=PC_DETAILS[pc_id],
|
||||
)
|
||||
|
||||
|
||||
@app.route("/stream_feed/<pc_id>")
|
||||
@flask_login.login_required
|
||||
def stream_feed(pc_id: str) -> flask.Response:
|
||||
return flask.Response(mimetype="multipart/x-mixed-replace; boundary=frame")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True)
|
||||
def run(self, host: str = "0.0.0.0", port: int = 5000) -> None:
|
||||
self.logger.info(f"Starting web server on {host}:{port}...")
|
||||
self.socketio.run(app=self.app, host=host, port=port)
|
||||
self.logger.info("Server stopped.")
|
||||
|
||||
86
uv.lock
generated
86
uv.lock
generated
@@ -1,5 +1,5 @@
|
||||
version = 1
|
||||
revision = 2
|
||||
revision = 3
|
||||
requires-python = ">=3.13"
|
||||
|
||||
[[package]]
|
||||
@@ -11,6 +11,15 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/78/b6/6307fbef88d9b5ee7421e68d78a9f162e0da4900bc5f5793f6d3d0e34fb8/annotated_types-0.7.0-py3-none-any.whl", hash = "sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53", size = 13643, upload-time = "2024-05-20T21:33:24.1Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bidict"
|
||||
version = "0.23.1"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/9a/6e/026678aa5a830e07cd9498a05d3e7e650a4f56a42f267a53d22bcda1bdc9/bidict-0.23.1.tar.gz", hash = "sha256:03069d763bc387bbd20e7d49914e75fc4132a41937fa3405417e1a5a2d006d71", size = 29093, upload-time = "2024-02-18T19:09:05.748Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/99/37/e8730c3587a65eb5645d4aba2d27aae48e8003614d6aaf15dda67f702f1f/bidict-0.23.1-py3-none-any.whl", hash = "sha256:5dae8d4d79b552a71cbabc7deb25dfe8ce710b17ff41711e13010ead2abfc3e5", size = 32764, upload-time = "2024-02-18T19:09:04.156Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "blinker"
|
||||
version = "1.9.0"
|
||||
@@ -188,6 +197,19 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/59/f5/67e9cc5c2036f58115f9fe0f00d203cf6780c3ff8ae0e705e7a9d9e8ff9e/Flask_Login-0.6.3-py3-none-any.whl", hash = "sha256:849b25b82a436bf830a054e74214074af59097171562ab10bfa999e6b78aae5d", size = 17303, upload-time = "2023-10-30T14:53:19.636Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flask-socketio"
|
||||
version = "5.5.1"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "flask" },
|
||||
{ name = "python-socketio" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/d1/1f/54d3de4982df695682af99c65d4b89f8a46fe6739780c5a68690195835a0/flask_socketio-5.5.1.tar.gz", hash = "sha256:d946c944a1074ccad8e99485a6f5c79bc5789e3ea4df0bb9c864939586c51ec4", size = 37401, upload-time = "2025-01-06T19:49:59.056Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/47/38/1b75b3ba3452860211ec87710f9854112911a436ee4d155533e0b83b5cd9/Flask_SocketIO-5.5.1-py3-none-any.whl", hash = "sha256:35a50166db44d055f68021d6ec32cb96f1f925cd82de4504314be79139ea846f", size = 18259, upload-time = "2025-01-06T19:49:56.555Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "git-cliff"
|
||||
version = "2.10.0"
|
||||
@@ -229,6 +251,15 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/01/61/d4b89fec821f72385526e1b9d9a3a0385dda4a72b206d28049e2c7cd39b8/gitpython-3.1.45-py3-none-any.whl", hash = "sha256:8908cb2e02fb3b93b7eb0f2827125cb699869470432cc885f019b8fd0fccff77", size = 208168, upload-time = "2025-07-24T03:45:52.517Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "h11"
|
||||
version = "0.16.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/01/ee/02a2c011bdab74c6fb3c75474d40b3052059d95df7e73351460c8588d963/h11-0.16.0.tar.gz", hash = "sha256:4e35b956cf45792e4caa5885e69fba00bdbc6ffafbfa020300e549b208ee5ff1", size = 101250, upload-time = "2025-04-24T03:35:25.427Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/04/4b/29cac41a4d98d144bf5f6d33995617b185d14b22401f75ca86f384e87ff1/h11-0.16.0-py3-none-any.whl", hash = "sha256:63cf8bbe7522de3bf65932fda1d9c2772064ffb3dae62d55932da54b31cb6c86", size = 37515, upload-time = "2025-04-24T03:35:24.344Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "3.10"
|
||||
@@ -279,11 +310,12 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "judas-server"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "flask" },
|
||||
{ name = "flask-login" },
|
||||
{ name = "flask-socketio" },
|
||||
]
|
||||
|
||||
[package.dev-dependencies]
|
||||
@@ -302,6 +334,7 @@ test = [
|
||||
requires-dist = [
|
||||
{ name = "flask", specifier = ">=3.1.1" },
|
||||
{ name = "flask-login", specifier = ">=0.6.3" },
|
||||
{ name = "flask-socketio", specifier = ">=5.5.1" },
|
||||
]
|
||||
|
||||
[package.metadata.requires-dev]
|
||||
@@ -489,6 +522,18 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/b2/05/77b60e520511c53d1c1ca75f1930c7dd8e971d0c4379b7f4b3f9644685ba/pytest_mock-3.14.1-py3-none-any.whl", hash = "sha256:178aefcd11307d874b4cd3100344e7e2d888d9791a6a1d9bfe90fbc1b74fd1d0", size = 9923, upload-time = "2025-05-26T13:58:43.487Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "python-engineio"
|
||||
version = "4.12.2"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "simple-websocket" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/ba/0b/67295279b66835f9fa7a491650efcd78b20321c127036eef62c11a31e028/python_engineio-4.12.2.tar.gz", hash = "sha256:e7e712ffe1be1f6a05ee5f951e72d434854a32fcfc7f6e4d9d3cae24ec70defa", size = 91677, upload-time = "2025-06-04T19:22:18.789Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/0c/fa/df59acedf7bbb937f69174d00f921a7b93aa5a5f5c17d05296c814fff6fc/python_engineio-4.12.2-py3-none-any.whl", hash = "sha256:8218ab66950e179dfec4b4bbb30aecf3f5d86f5e58e6fc1aa7fde2c698b2804f", size = 59536, upload-time = "2025-06-04T19:22:16.916Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "python-gitlab"
|
||||
version = "6.2.0"
|
||||
@@ -526,6 +571,19 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/89/be/10966ab26f0f26a58b7f56b31c6cb71dea85c8cbaa856f4989c035a62901/python_semantic_release-10.2.0-py3-none-any.whl", hash = "sha256:88ebe464bd15edf9793715212257fc3d04baafea10a6362bc78d69892418ce88", size = 141226, upload-time = "2025-06-29T22:06:31.14Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "python-socketio"
|
||||
version = "5.13.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "bidict" },
|
||||
{ name = "python-engineio" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/21/1a/396d50ccf06ee539fa758ce5623b59a9cb27637fc4b2dc07ed08bf495e77/python_socketio-5.13.0.tar.gz", hash = "sha256:ac4e19a0302ae812e23b712ec8b6427ca0521f7c582d6abb096e36e24a263029", size = 121125, upload-time = "2025-04-12T15:46:59.933Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/3c/32/b4fb8585d1be0f68bde7e110dffbcf354915f77ad8c778563f0ad9655c02/python_socketio-5.13.0-py3-none-any.whl", hash = "sha256:51f68d6499f2df8524668c24bcec13ba1414117cfb3a90115c559b601ab10caf", size = 77800, upload-time = "2025-04-12T15:46:58.412Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "requests"
|
||||
version = "2.32.4"
|
||||
@@ -575,6 +633,18 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/e0/f9/0595336914c5619e5f28a1fb793285925a8cd4b432c9da0a987836c7f822/shellingham-1.5.4-py2.py3-none-any.whl", hash = "sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686", size = 9755, upload-time = "2023-10-24T04:13:38.866Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simple-websocket"
|
||||
version = "1.1.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "wsproto" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/b0/d4/bfa032f961103eba93de583b161f0e6a5b63cebb8f2c7d0c6e6efe1e3d2e/simple_websocket-1.1.0.tar.gz", hash = "sha256:7939234e7aa067c534abdab3a9ed933ec9ce4691b0713c78acb195560aa52ae4", size = 17300, upload-time = "2024-10-10T22:39:31.412Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/52/59/0782e51887ac6b07ffd1570e0364cf901ebc36345fea669969d2084baebb/simple_websocket-1.1.0-py3-none-any.whl", hash = "sha256:4af6069630a38ed6c561010f0e11a5bc0d4ca569b36306eb257cd9a192497c8c", size = 13842, upload-time = "2024-10-10T22:39:29.645Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smmap"
|
||||
version = "5.0.2"
|
||||
@@ -665,3 +735,15 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/09/5e/1655cf481e079c1f22d0cabdd4e51733679932718dc23bf2db175f329b76/wrapt-1.17.2-cp313-cp313t-win_amd64.whl", hash = "sha256:eaf675418ed6b3b31c7a989fd007fa7c3be66ce14e5c3b27336383604c9da85c", size = 40750, upload-time = "2025-01-14T10:35:03.378Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/2d/82/f56956041adef78f849db6b289b282e72b55ab8045a75abad81898c28d19/wrapt-1.17.2-py3-none-any.whl", hash = "sha256:b18f2d1533a71f069c7f82d524a52599053d4c7166e9dd374ae2136b7f40f7c8", size = 23594, upload-time = "2025-01-14T10:35:44.018Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wsproto"
|
||||
version = "1.2.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "h11" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/c9/4a/44d3c295350d776427904d73c189e10aeae66d7f555bb2feee16d1e4ba5a/wsproto-1.2.0.tar.gz", hash = "sha256:ad565f26ecb92588a3e43bc3d96164de84cd9902482b130d0ddbaa9664a85065", size = 53425, upload-time = "2022-08-23T19:58:21.447Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/78/58/e860788190eba3bcce367f74d29c4675466ce8dddfba85f7827588416f01/wsproto-1.2.0-py3-none-any.whl", hash = "sha256:b9acddd652b585d75b20477888c56642fdade28bdfd3579aa24a4d2c037dd736", size = 24226, upload-time = "2022-08-23T19:58:19.96Z" },
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user