40 Commits

Author SHA1 Message Date
9949179997 style(login.html): format 2025-08-25 22:18:36 +02:00
6a072724f2 style(index.html): format 2025-08-25 22:18:23 +02:00
b79f3f3387 style(details.html): format with prettier 2025-08-25 22:18:06 +02:00
a494b606a5 feat(web_server.py): add WEB_SERVER and BACKEND app.configs 2025-08-25 21:43:15 +02:00
90094e9c43 chore(web_server.py): remove LoginManager from self.app.config 2025-08-25 21:42:38 +02:00
4285da4fa8 feat(web_server.py): add BackendServer reference to webserver 2025-08-25 21:42:00 +02:00
14450ba70d feat(__main__.py): init BackendServer in __main__ 2025-08-25 21:40:44 +02:00
5a4b5ddd82 chore(backend/__init__.py): add BackendServer to __all__ 2025-08-25 21:40:17 +02:00
2964ac7644 feat(backend/server.py): add placeholder backend 2025-08-25 21:39:32 +02:00
1d00d5f4f5 chore(routes/auth.py): make login fail message more ambigiuous 2025-08-25 20:24:57 +02:00
38da1f476e feat(templates/login.html): autofocus password field 2025-08-25 20:22:32 +02:00
c840788907 Merge pull request 'refactor: use OOP' (#6) from refactor/use-oop into develop
Reviewed-on: #6
2025-08-25 17:56:22 +00:00
a3e9aed6f4 chore(web_server.py): add web server to initial loggin to avoid confusion 2025-08-25 19:48:17 +02:00
8ad55eed10 fix(__main__.py): fix wrong import path 2025-08-25 19:40:39 +02:00
77b6bd0732 refactor(web_server.py): rewrite to use OOP 2025-08-25 19:40:11 +02:00
a32df2fd67 chore(templates/stream.html): remove stream.html template 2025-08-25 19:39:32 +02:00
8b418a7d52 refactor(templates/panel.html): adapt urls for blueprints 2025-08-25 19:38:35 +02:00
3e1fe9fa1e refactor(templates/login.html): adapt urls for blueprints 2025-08-25 19:38:22 +02:00
bd9d95b741 refactor(templates/index.html): adapt urls for blueprints 2025-08-25 19:38:12 +02:00
4baf29eb4a refactor(templates/details.html): adapt urls for blueprints 2025-08-25 19:37:58 +02:00
d91f135d53 feat(user.py): add user management 2025-08-25 19:35:16 +02:00
c1e20e5524 feat(routes/__init__.py): add __init__.py 2025-08-25 19:32:24 +02:00
d56256f681 feat(routes/panel.py): add panel.py route blueprint 2025-08-25 19:32:05 +02:00
bbaffb344f feat(routes/auth.py): add auth.py route blueprint 2025-08-25 19:31:55 +02:00
50be48dba4 feat(routes/index.py): add index.py route blueprint 2025-08-25 19:31:42 +02:00
fc5dc23c0e refactor(style.css): use new palette 2025-08-25 19:26:41 +02:00
44df495096 feat(palette.css): add catppuccin color palette 2025-08-25 19:26:13 +02:00
8dbbea3f56 feat(__main__.py): add __main__.py 2025-08-24 22:02:59 +02:00
e575e8a15d refactor(.vscode/launch.json): use __main__.py for running web server 2025-08-24 22:02:39 +02:00
1901441948 chore(py.typed): add py.typed 2025-08-15 20:38:14 +02:00
6bed7da165 build(pyproject.toml): use basic type checking to kinda supress flask_login's nonexistent typing 2025-08-15 20:36:20 +02:00
f8f74ccd4b chore(routes/__init__.py): add __init__.py 2025-08-09 22:47:47 +02:00
5fb6920436 style(.vscode/settings.json): fix indentation 2025-08-09 22:46:45 +02:00
23a53f79a0 fix(web_server.py): fix server error when using /stream 2025-08-09 22:46:06 +02:00
89dd67b489 chore(backend/__init__.py): add __init__.py 2025-08-09 22:44:06 +02:00
c2e1984959 style(web_server.py): fix typing errors 2025-08-09 22:42:19 +02:00
dbc61ac6b7 chore(web/__init__.py): add web/__init__.py 2025-08-09 22:41:43 +02:00
github-actions[bot]
ed91c8d8cb chore(release): 0.1.1 2025-08-09 15:20:50 +00:00
451bdeb618 Merge pull request 'chore(.vscode/launch.json): use shell instead of debugpy for running flask' (#5) from release/0.1.1 into main
Reviewed-on: #5
2025-08-09 15:20:11 +00:00
8b6bf1e913 chore(.vscode/launch.json): use shell instead of debugpy for running flask 2025-08-09 17:19:27 +02:00
22 changed files with 479 additions and 336 deletions

14
.vscode/launch.json vendored
View File

@@ -2,18 +2,12 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "Launch Flask", "name": "Debug Flask",
"type": "debugpy", "type": "debugpy",
"request": "launch", "request": "launch",
"module": "flask", "program": "${workspaceFolder}/src/judas_server/__main__.py",
"env": { "console": "integratedTerminal",
"FLASK_APP": "judas_server/web/web_server.py" "justMyCode": true
},
"args": [
"run",
"--host",
"0.0.0.0"
]
} }
] ]
} }

View File

@@ -1,4 +1,4 @@
{ {
"python.analysis.autoImportCompletions": true, "python.analysis.autoImportCompletions": true,
"python.analysis.typeCheckingMode": "standard", "python.analysis.typeCheckingMode": "standard"
} }

View File

@@ -2,6 +2,12 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## [0.1.1] - 2025-08-09
### Miscellaneous Tasks
- [`8b6bf1e`](https://github.com/pufereq/template-repo/commit/8b6bf1e91366d76ee3203b508b895e4b75d7f845) **.vscode/launch.json**: use shell instead of debugpy for running flask
## [0.1.0] - 2025-08-09 ## [0.1.0] - 2025-08-09
### Bug Fixes ### Bug Fixes

View File

@@ -4,7 +4,7 @@ build-backend = "uv_build"
[project] [project]
name = "judas_server" name = "judas_server"
version = "0.1.0" version = "0.1.1"
description = "The backbone of the remote PC fleet management system." description = "The backbone of the remote PC fleet management system."
readme = "README.md" readme = "README.md"
authors = [] authors = []
@@ -21,6 +21,9 @@ test = [
"pytest-mock>=3.14.1", "pytest-mock>=3.14.1",
] ]
[tool.basedpyright]
typeCheckingMode = "basic"
[tool.ruff] [tool.ruff]
line-length = 79 line-length = 79
exclude = ["tests/*"] exclude = ["tests/*"]

View File

@@ -0,0 +1,20 @@
# -*- 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 - %(name)s - %(levelname)s - %(message)s",
)
backend_server = BackendServer()
web_server = JudasWebServer(backend=backend_server, secret_key="dildo")
web_server.run(
host="0.0.0.0",
port=5000,
)

View File

@@ -0,0 +1,3 @@
from .server import BackendServer
__all__ = ["BackendServer"]

View File

@@ -0,0 +1,48 @@
# -*- 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, "mem_usage": 0},
"ondemand": {},
}
}
self.running: bool = False
def start_polling(self) -> None:
self.running = True
def _poll_loop(self) -> None:
while self.running:
for client in self.clients.values():
client["polled"]["cpu"] = round(rn.uniform(0, 100), 1)
client["polled"]["ram"] = round(rn.uniform(0, 100), 1)
time.sleep(1)
def get_client_data(
self, client_id: str
) -> dict[str, dict[str, Any]] | None:
return self.clients.get(client_id, None)

View File

View File

View 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"]

View 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"))

View 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
)

View File

@@ -0,0 +1,27 @@
# -*- 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
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", username=flask_login.current_user.id, pcs={}
)

View 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%;
}

View File

@@ -1,22 +1,4 @@
:root { @import "palette.css";
--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;
}
* { * {
margin: 0; margin: 0;
@@ -25,22 +7,22 @@
} }
body { body {
background-color: var(--nord-aur4); background-color: var(--ctp-base);
font-family: monospace, sans-serif !important; font-family: monospace, sans-serif !important;
color: var(--nord-fg0); color: var(--ctp-text);
} }
input { input {
font-family: inherit; font-family: inherit;
color: #eceff4; color: #eceff4;
background-color: var(--nord-bg2); background-color: var(--ctp-crust);
border: none; border: none;
border-radius: 0.25rem; border-radius: 0.25rem;
padding: 0.25rem; padding: 0.25rem;
} }
a { a {
color: var(--nord-acc0); color: var(--ctp-blue);
text-decoration: none; text-decoration: none;
} }
@@ -54,8 +36,8 @@ header {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
background-color: var(--nord-bg0); background-color: var(--ctp-mantle);
color: var(--nord-fg0); /* color: var(--ctp-text); */
padding: 1rem; padding: 1rem;
} }
@@ -64,34 +46,34 @@ main {
flex-direction: column; flex-direction: column;
gap: 1rem; gap: 1rem;
padding: 1rem; padding: 1rem;
background-color: var(--nord-bg1); /* background-color: var(--ctp-base); */
flex-grow: 1; flex-grow: 1;
text-align: center; text-align: center;
} }
header a { header a {
text-decoration: none; text-decoration: none;
color: var(--nord-fg0); /* color: var(--nord-fg0); */
} }
.button { .button {
display: inline-block; display: inline-block;
padding: 0.5rem 1rem; padding: 0.5rem 1rem;
background-color: var(--nord-acc0); background-color: var(--ctp-lavender);
color: var(--nord-bg0); color: var(--ctp-base);
border: none; border: none;
border-radius: 0.25rem; border-radius: 0.25rem;
text-decoration: none; text-decoration: none;
transition: 0.3s ease-in-out; transition: 0.3s ease-in-out;
} }
.button a:hover { /* .button a:hover { */
color: var(--nord-bg0); /* color: var(--nord-bg0); */
text-decoration: none; /* text-decoration: none; */
} /* } */
.button:hover { .button:hover {
background-color: var(--nord-acc2); background-color: var(--ctp-mauve);
cursor: pointer; cursor: pointer;
} }
@@ -106,9 +88,9 @@ header a {
justify-content: center; justify-content: center;
margin: 1rem; margin: 1rem;
padding: 1rem; padding: 1rem;
background-color: var(--nord-aur0); background-color: var(--ctp-surface0);
color: var(--nord-fg0); color: var(--ctp-red);
border: 6px solid var(--nord-aur1); border: 6px solid var(--ctp-red);
border-radius: 24px; border-radius: 24px;
} }
@@ -117,9 +99,9 @@ header a {
width: 100%; width: 100%;
} }
.select-table{ .select-table {
border-collapse: collapse; border-collapse: collapse;
border: 2px solid var(--nord-fg0); border: 2px solid var(--ctp-surface0);
} }
.select-table thead { .select-table thead {
@@ -131,18 +113,18 @@ header a {
.select-table th, .select-table td { .select-table th, .select-table td {
padding: 0.5rem; padding: 0.5rem;
text-align: center; text-align: center;
border: 1px solid var(--nord-fg1); border: 1px solid var(--ctp-surface0);
border-collapse: collapse; border-collapse: collapse;
} }
.select-table th { .select-table th {
background-color: var(--nord-bg2); background-color: var(--ctp-surface1);
color: var(--nord-fg0); color: var(--nord-fg0);
} }
.select-table a { .select-table a {
display: block; display: block;
color: var(--nord-acc0); /* color: var(--nord-acc0); */
text-decoration: none; text-decoration: none;
transition: 0.1s ease-in-out; transition: 0.1s ease-in-out;
} }
@@ -152,23 +134,23 @@ header a {
} }
.select-table tr:hover { .select-table tr:hover {
background-color: var(--nord-acc1); background-color: var(--ctp-surface0);
} }
.select-table tr:hover a { .select-table tr:hover a {
color: var(--nord-bg0); color: var(--ctp-base);
} }
.red-bg { .red-bg {
background-color: var(--nord-aur0); background-color: var(--ctp-red);
} }
.yellow-bg { .yellow-bg {
background-color: var(--nord-aur2); background-color: var(--ctp-yellow);
} }
.green-bg { .green-bg {
background-color: var(--nord-aur3); background-color: var(--ctp-green);
} }
.button-container { .button-container {
@@ -183,24 +165,24 @@ header a {
} }
.link:hover { .link:hover {
color: var(--nord-acc2); color: var(--ctp-blue);
} }
.details-table tr td:first-child { .details-table tr td:first-child {
font-weight: 900; font-weight: 900;
background-color: var(--nord-bg3); background-color: var(--ctp-surface0);
white-space: nowrap; white-space: nowrap;
width: 1%; width: 1%;
} }
.details-table { .details-table {
border-collapse: collapse; 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; padding: 0.5rem;
text-align: left; text-align: left;
border: 1px solid var(--nord-fg1); border: 1px solid var(--ctp-text);
border-collapse: collapse; border-collapse: collapse;
} }

View File

@@ -1,36 +1,44 @@
<!DOCTYPE html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>judas panel - details</title> <title>judas panel - details</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}"> <link
</head> rel="stylesheet"
<body> href="{{ url_for('static', filename='css/style.css') }}"
/>
</head>
<body>
<div id="wrapper"> <div id="wrapper">
<header> <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> <p><a class="button" href="{{ url_for('logout') }}">Logout</a></p>
</header> </header>
<main> <main>
<div class="button-container"> <div class="button-container">
<p><a href="{{ url_for('panel') }}" class="link">Back to Panel</a></p> <p><a href="{{ url_for('panel') }}" class="link">Back to Panel</a></p>
<h2>{{ pc.id }}</h2> <h2>{{ pc.id }}</h2>
<p><a href="{{ url_for('stream', pc_id=pc.id) }}" class="link">View Stream</a></p> <p>
</div> <a href="{{ url_for('stream', pc_id=pc.id) }}" class="link"
<table class="center-table details-table"> >View Stream</a
<tbody> >
<tr> </p>
<td>Status</td> </div>
<td>{{ pc.status }}</td> <table class="center-table details-table">
</tr> <tbody>
<tr> <tr>
<td>Last Seen</td> <td>Status</td>
<td>{{ pc.last_seen }}</td> <td>{{ pc.status }}</td>
</tr> </tr>
</tbody> <tr>
</table> <td>Last Seen</td>
</main> <td>{{ pc.last_seen }}</td>
</tr>
</tbody>
</table>
</main>
</div> </div>
</body> </body>
</html> </html>

View File

@@ -1,54 +1,54 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>judas</title> <title>judas</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head> </head>
<body> <body>
<div id="wrapper"> <div id="wrapper">
<header> <header>
<h1><a href="{{ url_for('index') }}">judas</a></h1> <h1><a href="{{ url_for('index.index') }}">judas</a></h1>
{% if logged %} {% 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 %} {% 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 %} {% endif %}
</header> </header>
<main class="center"> <main class="center">
<div> <div>
<p>Welcome to</p> <p>Welcome to</p>
<h2 id="typing-text" style="font-size: 3rem;">judas</h2> <h2 id="typing-text" style="font-size: 3rem;">judas</h2>
<p>a remote PC fleet management system</p> <p>a remote PC fleet management system</p>
</div> </div>
<p style="color: #bf616a;"><strong>Notice:</strong> Please use this system responsibly and in accordance with all applicable laws and organizational policies.</p> <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 %} {% 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 %} {% 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 %} {% endif %}
</main> </main>
</div> </div>
<script> <script>
var i = 0; var i = 0;
var txt = document.getElementById("typing-text").innerHTML; var txt = document.getElementById("typing-text").innerHTML;
var minSpeed = 50; var minSpeed = 50;
var maxSpeed = 200; var maxSpeed = 200;
document.getElementById("typing-text").innerHTML = ""; document.getElementById("typing-text").innerHTML = "";
function typeWriter() { function typeWriter() {
if (i < txt.length) { if (i < txt.length) {
document.getElementById("typing-text").innerHTML += txt.charAt(i); document.getElementById("typing-text").innerHTML += txt.charAt(i);
i++; i++;
var randomDelay = Math.floor(Math.random() * (maxSpeed - minSpeed + 1)) + minSpeed; var randomDelay = Math.floor(Math.random() * (maxSpeed - minSpeed + 1)) + minSpeed;
setTimeout(typeWriter, randomDelay); setTimeout(typeWriter, randomDelay);
} }
} }
typeWriter(); typeWriter();
</script> </script>
</body> </body>
</html> </html>

View File

@@ -1,32 +1,32 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>judas - login page</title> <title>judas - login page</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head> </head>
<body> <body>
<div id="wrapper"> <div id="wrapper">
<header> <header>
<h1><a href="{{ url_for('index') }}">judas</a></h1> <h1><a href="{{ url_for('index.index') }}">judas</a></h1>
</header> </header>
<main> <main>
<h1>Login</h1> <h1>Login</h1>
<form method="post" class="center"> <form method="post" class="center">
<label for="password">Password:</label> <label for="password">Password:</label>
<input type="password" id="password" name="password" required> <input type="password" id="password" name="password" required autofocus>
<br> <br>
<br> <br>
<input type="submit" value="Login" class="button"> <input type="submit" value="Login" class="button">
{% if error %} {% if error %}
<div class="error-container"> <div class="error-container">
<h1>Login failure</h1> <h1>Login failure</h1>
<p>{{ error }}</p> <p>{{ error }}</p>
</div> </div>
{% endif %} {% endif %}
</form> </form>
</main> </main>
</div> </div>
</body> </body>
</html> </html>

View File

@@ -9,8 +9,8 @@
<body> <body>
<div id="wrapper"> <div id="wrapper">
<header> <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> <p><a class="button" href="{{ url_for('auth.logout') }}">Logout</a></p>
</header> </header>
<main> <main>
<h2 class="center">Select a PC to Control</h2> <h2 class="center">Select a PC to Control</h2>
@@ -39,4 +39,4 @@
</main> </main>
</div> </div>
</body> </body>
</html> </html>

View File

@@ -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>

View 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

View File

@@ -1,170 +1,62 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from typing import Final from __future__ import annotations
import flask import logging as lg
import flask_login from typing import TYPE_CHECKING
PASSWORD: Final[str] = "123" from flask import Flask
from flask_login import LoginManager
app = flask.Flask(__name__) from judas_server.web.user import load_user
app.secret_key = "dildo"
login_manager = flask_login.LoginManager() if TYPE_CHECKING:
login_manager.init_app(app) from judas_server.backend import BackendServer
PC_DETAILS = { class JudasWebServer:
"PC1": { def __init__(self, backend: BackendServer, secret_key: str) -> None:
"id": "PC1", self.logger: lg.Logger = lg.getLogger(
"status": "online", f"{__name__}.{self.__class__.__name__}"
"last_seen": "2023-10-01 12:00:00", )
}, self.logger.debug("Initializing JudasWebServer...")
"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",
},
}
self.backend: BackendServer = backend
class User(flask_login.UserMixin): self.app: Flask = Flask(
"""Represents a user for authentication purposes.""" __name__, static_folder="static", template_folder="templates"
)
self.app.secret_key = secret_key
def __init__(self, id: str): self.app.config["WEB_SERVER"] = self
super().__init__() self.app.config["BACKEND"] = self.backend
self.id = id
# hard-code password
self.app.config["PASSWORD"] = "123"
@login_manager.user_loader # extensions
def load_user(user_id: str) -> User | None: self.login_manager: LoginManager = LoginManager()
"""Loads a user by user_id.
Args: self.configure_extensions()
user_id: The ID of the user. self.init_routes()
Returns: def configure_extensions(self) -> None:
The User object if found, else None. self.logger.debug("Configuring extensions...")
""" self.login_manager.init_app(self.app)
if user_id == "admin": self.login_manager.user_loader(load_user)
return User("admin") self.login_manager.login_view = "auth.login"
return None
# TODO: add login page
@app.route("/") def init_routes(self) -> None:
def index() -> flask.Response | str: self.logger.debug("Initializing routes...")
"""Renders the index page with a link to the login page.""" from judas_server.web.routes import auth_bp, index_bp, panel_bp
return flask.render_template(
"index.html", logged=flask_login.current_user.is_authenticated
)
self.app.register_blueprint(index_bp)
self.app.register_blueprint(auth_bp)
self.app.register_blueprint(panel_bp)
@app.route("/login", methods=["GET", "POST"]) def run(self, host: str = "0.0.0.0", port: int = 5000) -> None:
def login() -> str: self.logger.info(f"Starting web server on {host}:{port}...")
"""Handles user login via password form.""" self.app.run(host=host, port=port)
if flask.request.method == "POST": self.logger.info("Server stopped.")
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)