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