Pass COMPUTER_NAME to templates
This commit is contained in:
@@ -5,6 +5,7 @@ services:
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- PORT=3000
|
||||
- COMPUTER_NAME=MyComputer
|
||||
- MAC_ADDRESS=12:34:56:78:90:AB
|
||||
- OIDC_WELL_KNOWN_URL=
|
||||
- CLIENT_ID=
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
NODE_ENV=production
|
||||
PORT=3000
|
||||
COMPUTER_NAME=MyComputer
|
||||
MAC_ADDRESS=12:34:56:78:90:AB
|
||||
OIDC_WELL_KNOWN_URL=
|
||||
CLIENT_ID=
|
||||
|
||||
20
index.js
20
index.js
@@ -7,6 +7,7 @@ const { createTemplateRenderer } = require("./utils/templates.jsm");
|
||||
require("dotenv").config();
|
||||
|
||||
const PORT = process.env.PORT || 3000;
|
||||
const COMPUTER_NAME = process.env.COMPUTER_NAME || "MyComputer";
|
||||
const REDIRECT_URI =
|
||||
process.env.REDIRECT_URI || "http://127.0.0.1:3000/callback";
|
||||
|
||||
@@ -37,9 +38,14 @@ let client;
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
if (req.session.user) {
|
||||
res.send(renderHtml("index.html", { USERNAME: req.session.user.sub }));
|
||||
res.send(
|
||||
renderHtml("index.html", {
|
||||
COMPUTER_NAME,
|
||||
USERNAME: req.session.user.sub,
|
||||
})
|
||||
);
|
||||
} else {
|
||||
res.send(renderHtml("login.html"));
|
||||
res.send(renderHtml("login.html", { COMPUTER_NAME }));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -60,18 +66,20 @@ let client;
|
||||
req.session.user = userinfo;
|
||||
res.redirect("/");
|
||||
} catch (error) {
|
||||
res.send(renderHtml("login-fail.html", { error }));
|
||||
res.send(renderHtml("login-fail.html", { COMPUTER_NAME, ERROR: error }));
|
||||
}
|
||||
});
|
||||
|
||||
app.get("/wakeup3770", (req, res) => {
|
||||
app.get("/wakeup", (req, res) => {
|
||||
if (!req.session.user) return res.redirect("/");
|
||||
|
||||
wol.wake(process.env.MAC_ADDRESS, (error) => {
|
||||
if (error) {
|
||||
res.send(renderHtml("wakeup-fail.html", { error }));
|
||||
res.send(
|
||||
renderHtml("wakeup-fail.html", { COMPUTER_NAME, ERROR: error })
|
||||
);
|
||||
} else {
|
||||
res.send(renderHtml("wakeup-success.html"));
|
||||
res.send(renderHtml("wakeup-success.html", { COMPUTER_NAME }));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>喚醒 PinLin3770</title>
|
||||
<title>喚醒 {{COMPUTER_NAME}}</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: sans-serif; padding: 1.5rem; font-size: 1.2rem;
|
||||
@@ -14,12 +14,12 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>喚醒 PinLin3770</h1>
|
||||
<h1>喚醒 {{COMPUTER_NAME}}</h1>
|
||||
<p>已登入為身分 {{USERNAME}}</p>
|
||||
<form method="POST" action="/logout">
|
||||
<button type="submit">登出</button>
|
||||
</form>
|
||||
<br>
|
||||
<a href="/wakeup3770">喚醒 PinLin3770</a>
|
||||
<a href="/wakeup">喚醒 {{COMPUTER_NAME}}</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>登入失敗 | 喚醒 PinLin3770</title>
|
||||
<title>登入失敗 | 喚醒 {{COMPUTER_NAME}}</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: sans-serif; padding: 1.5rem; font-size: 1.2rem;
|
||||
@@ -14,9 +14,9 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>喚醒 PinLin3770</h1>
|
||||
<h1>喚醒 {{COMPUTER_NAME}}</h1>
|
||||
<p>⚠️ 登入失敗</p>
|
||||
<p>{{error}}</p>
|
||||
<p>{{ERROR}}</p>
|
||||
<a href="/">回首頁</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>登入 | 喚醒 PinLin3770</title>
|
||||
<title>登入 | 喚醒 {{COMPUTER_NAME}}</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: sans-serif; padding: 1.5rem; font-size: 1.2rem;
|
||||
@@ -14,7 +14,7 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>喚醒 PinLin3770</h1>
|
||||
<h1>喚醒 {{COMPUTER_NAME}}</h1>
|
||||
<a href="/login">點此登入</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>喚醒失敗 | 喚醒 PinLin3770</title>
|
||||
<title>喚醒失敗 | 喚醒 {{COMPUTER_NAME}}</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: sans-serif; padding: 1.5rem; font-size: 1.2rem;
|
||||
@@ -14,9 +14,9 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>喚醒 PinLin3770</h1>
|
||||
<h1>喚醒 {{COMPUTER_NAME}}</h1>
|
||||
<p>⚠️ 發送魔法封包失敗</p>
|
||||
<p>{{error}}</p>
|
||||
<p>{{ERROR}}</p>
|
||||
<a href="/">回首頁</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>喚醒成功 | 喚醒 PinLin3770</title>
|
||||
<title>喚醒成功 | 喚醒 {{COMPUTER_NAME}}</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: sans-serif; padding: 1.5rem; font-size: 1.2rem;
|
||||
@@ -14,7 +14,7 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>喚醒 PinLin3770</h1>
|
||||
<h1>喚醒 {{COMPUTER_NAME}}</h1>
|
||||
<p>✅ 已經發送魔法封包</p>
|
||||
<a href="/">回首頁</a>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user