Skip to content

Commit

Permalink
Add footer note to all HTML pages
Browse files Browse the repository at this point in the history
  • Loading branch information
vsivanandharao committed Sep 6, 2024
1 parent 74a5e99 commit e158c2b
Show file tree
Hide file tree
Showing 7 changed files with 277 additions and 173 deletions.
2 changes: 2 additions & 0 deletions pyninja/monitor/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from fastapi import Request, status
from fastapi.responses import HTMLResponse

import pyninja
from pyninja import exceptions, models, monitor, squire

LOGGER = logging.getLogger("uvicorn.default")
Expand Down Expand Up @@ -133,6 +134,7 @@ async def session_error(
"request": request,
"signin": monitor.config.static.login_endpoint,
"reason": error.detail,
"version": f"v{pyninja.version}",
},
)

Expand Down
4 changes: 4 additions & 0 deletions pyninja/monitor/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from fastapi.responses import HTMLResponse, JSONResponse
from fastapi.websockets import WebSocket, WebSocketDisconnect, WebSocketState

import pyninja
from pyninja import exceptions, models, monitor, squire

LOGGER = logging.getLogger("uvicorn.default")
Expand All @@ -28,6 +29,7 @@ async def error_endpoint(request: Request) -> HTMLResponse:
context={
"request": request,
"signin": monitor.config.static.login_endpoint,
"version": f"v{pyninja.version}",
},
)
)
Expand Down Expand Up @@ -57,6 +59,7 @@ async def logout_endpoint(request: Request) -> HTMLResponse:
"detail": "Session Expired",
"signin": monitor.config.static.login_endpoint,
"show_login": True,
"version": f"v{pyninja.version}",
},
)
return await monitor.config.clear_session(response)
Expand Down Expand Up @@ -120,6 +123,7 @@ async def monitor_endpoint(request: Request, session_token: str = Cookie(None)):
context={
"request": request,
"signin": monitor.config.static.login_endpoint,
"version": f"v{pyninja.version}",
},
)

Expand Down
24 changes: 22 additions & 2 deletions pyninja/monitor/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js"></script>
<link property="og:image" rel="icon" href="https://thevickypedia.github.io/open-source/images/logo/fastapi.ico">
<link property="og:image" rel="apple-touch-icon" href="https://thevickypedia.github.io/open-source/images/logo/fastapi.png">
<link property="og:image" rel="apple-touch-icon"
href="https://thevickypedia.github.io/open-source/images/logo/fastapi.png">
<!-- Font Awesome icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
Expand Down Expand Up @@ -79,6 +80,16 @@
background-color: #494949;
}

footer {
bottom: 10px;
position: fixed;
width: 100%;
color: #fff;
text-align: center;
font-family: 'Courier New', monospace;
font-size: small;
}

</style>
<noscript>
<style>
Expand Down Expand Up @@ -134,13 +145,15 @@ <h2 style="margin-top:5%">This page requires JavaScript
alert("ERROR: Username and password are required to authenticate your request!");
return false;
}

async function ConvertStringToHex(str) {
let arr = [];
for (let i = 0; i < str.length; i++) {
arr[i] = ("00" + str.charCodeAt(i).toString(16)).slice(-4);
}
return "\\u" + arr.join("\\u");
}

async function CalculateHash(username, password, timestamp) {
const message = username + password + timestamp;
const encoder = new TextEncoder();
Expand All @@ -157,6 +170,7 @@ <h2 style="margin-top:5%">This page requires JavaScript
return hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
}
}

let hex_user = await ConvertStringToHex(username);
let hex_pass = await ConvertStringToHex(password);
let timestamp = Math.round(new Date().getTime() / 1000);
Expand All @@ -183,7 +197,7 @@ <h2 style="margin-top:5%">This page requires JavaScript
console.log(data);
}
},
error: function(jqXHR, textStatus, errorThrown) {
error: function (jqXHR, textStatus, errorThrown) {
console.error(`Status: ${textStatus}, Error: ${errorThrown}`);
if (jqXHR.hasOwnProperty("responseJSON")) {
alert(jqXHR.responseJSON.detail);
Expand All @@ -195,4 +209,10 @@ <h2 style="margin-top:5%">This page requires JavaScript
}

</script>
<footer>
<div class="footer">
PyNinja - {{ version }}<br>
<a href="https://github.com/thevickypedia/PyNinja">https://github.com/thevickypedia/PyNinja</a>
</div>
</footer>
</html>
27 changes: 22 additions & 5 deletions pyninja/monitor/templates/logout.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<meta name="keywords" content="Python, Monitor, fastapi, JavaScript, HTML, CSS">
<meta name="author" content="Vignesh Rao">
<link property="og:image" rel="icon" href="https://thevickypedia.github.io/open-source/images/logo/fastapi.ico">
<link property="og:image" rel="apple-touch-icon" href="https://thevickypedia.github.io/open-source/images/logo/fastapi.png">
<link property="og:image" rel="apple-touch-icon"
href="https://thevickypedia.github.io/open-source/images/logo/fastapi.png">
<meta content="width=device-width, initial-scale=1" name="viewport">
<style>
img {
Expand All @@ -31,6 +32,16 @@
body {
background-color: #151515;
}

footer {
bottom: 10px;
position: fixed;
width: 100%;
color: #fff;
text-align: center;
font-family: 'Courier New', monospace;
font-size: small;
}
</style>
<noscript>
<style>
Expand All @@ -57,14 +68,20 @@ <h2 style="margin-top:5%">LOGOUT</h2>
<h3>{{ detail }}</h3>
<p>
<img src="https://thevickypedia.github.io/open-source/images/gif/blended_fusion.gif"
onerror="this.src='https://vigneshrao.com/open-source/images/gif/blended_fusion.gif'"
width="200" height="200" alt="Image" class="center">
onerror="this.src='https://vigneshrao.com/open-source/images/gif/blended_fusion.gif'"
width="200" height="200" alt="Image" class="center">
</p>
{% if show_login %}
<button style="text-align:center" onClick="window.location.href = '/monitor';">LOGIN</button>
<button style="text-align:center" onClick="window.location.href = '/monitor';">LOGIN</button>
{% else %}
<h3>Please close the session window</h3>
<h3>Please close the session window</h3>
{% endif %}
<h4>Click <a href="https://vigneshrao.com/contact">ME</a> to reach out.</h4>
</body>
<footer>
<div class="footer">
PyNinja - {{ version }}<br>
<a href="https://github.com/thevickypedia/PyNinja">https://github.com/thevickypedia/PyNinja</a>
</div>
</footer>
</html>
Loading

0 comments on commit e158c2b

Please sign in to comment.