Skip to content

Commit

Permalink
Integrate night mode feature for monitoring page
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Sep 7, 2024
1 parent ad142cd commit cf9bbb0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pyninja/monitor/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ async def websocket_endpoint(websocket: WebSocket, session_token: str = Cookie(N
session_token: Session token set after verifying username and password.
"""
await websocket.accept()
if not monitor.authenticator.validate_session(websocket.client.host, session_token):
session_validity = await monitor.authenticator.validate_session(
websocket.client.host, session_token
)
if not session_validity:
await websocket.send_text("Unauthorized")
await websocket.close()
return
Expand Down
7 changes: 6 additions & 1 deletion pyninja/monitor/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
href="https://thevickypedia.github.io/open-source/images/logo/fastapi.png">
<meta content="width=device-width, initial-scale=1" name="viewport">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<!-- CSS and JS for night mode -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script type="text/javascript" src="https://thevickypedia.github.io/open-source/nightmode/night.js" defer></script>
<link rel="stylesheet" type="text/css" href="https://thevickypedia.github.io/open-source/nightmode/night.css">
<!--suppress CssUnusedSymbol -->
<style id="main-css">
body {
Expand Down Expand Up @@ -84,7 +88,8 @@
}
</style>
</head>
<body>
<body translate="no">
<div class="toggler fa fa-moon-o"></div>
<h1>System Monitor</h1>
<div class="container">
<div class="box">
Expand Down
4 changes: 4 additions & 0 deletions pyninja/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ def get_all_routes() -> List[APIRoute]:
dependencies=dependencies,
)
)
else:
logging.getLogger().warning("Remote execution disabled")
# Conditional endpoint based on monitor_username and monitor_password
if all((models.env.monitor_username, models.env.monitor_password)):
routes.extend(monitor.get_all_monitor_routes(dependencies))
else:
logging.warning("Monitoring feature disabled")
return routes
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ psutil==6.0.0
pydantic==2.8.2
pydantic-settings==2.4.0
PyYaml==6.0.2
uvicorn==0.30.5
requests
uvicorn[standard]==0.30.5

0 comments on commit cf9bbb0

Please sign in to comment.