Skip to content

Commit 16301ce

Browse files
committed
multiple changes
- If the session is no longer valid, the site autoredirects to the login page - The status interval and online timeout are now customisable - Fixed issue causing page to be slightly larger than viewport - FIxed issue where authentication was required even with no password
1 parent 4426937 commit 16301ce

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ services:
2525
- IP=192.168.1.123 # the target's IP address
2626
- PORT=8080 # port to run on
2727
- PASSWORD=pleasechangeme # password required to access yoink, leave blank if you do not need authentication
28-
# - TOKEN_KEY=7%ocK!w"GS1au4EKg;o9 # ONLY SET THIS IF YOU DO NOT WANT RESTARTING YOINK TO INVALIDATE SESSION TOKENS. I RECOMMEND YOU LEAVE IT BLANK
28+
- STATUS_INTERVAL=5000 # how often the frontend pings to request server status, in ms
29+
- ONLINE_TIMOUT=30000 # how long before it is decided the server did not respond to the WOL ping. Has no actual effect, only means the status returns to 'offline' sooner
30+
# - TOKEN_KEY=7%ocK!w"GS1au4EKg;o9 # ONLY SET THIS IF YOU DO NOT WANT RESTARTING YOINK TO INVALIDATE SESSION TOKENS. I RECOMMEND YOU DO NOT SET THIS VALUE. IF YOU DO SET IT, DO NOT SHARE IT WITH ANYONE AS IT CAN BE USED TO REVERSE ENGINEER THE PASSWORD
2931
```
3032

3133
### With Node.js

docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ services:
99
- MAC=00:11:22:33:44:55 # the target's MAC address
1010
- IP=192.168.1.123 # the target's IP address
1111
- PORT=8080 # port to run on
12-
- PASSWORD=pleasechangeme # password, leave blank for no authentication
12+
- PASSWORD=pleasechangeme # password, leave blank for no authentication
13+
- STATUS_INTERVAL=5000 # how often the frontend pings to request server status, in ms
14+
- ONLINE_TIMOUT=30000 # how long before it is decided the server did not respond to the WOL ping. Has no actual effect, only means the status returns to 'offline' sooner

src/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function generateToken(){ // hash password into a token
2828
}
2929

3030
function checkAuth(token){ // checks validity of token
31+
if (PASSWORD == "") return true;
3132
if (typeof token !== "string" || token === "") return false;
3233

3334
try {
@@ -47,6 +48,8 @@ const IP = process.env.IP;
4748
const NAME = process.env.NAME;
4849
const PASSWORD = process.env.PASSWORD || "";
4950
const TOKEN_KEY = process.env.TOKEN_KEY || crypto.randomBytes(64).toString('hex');
51+
const STATUS_INTERVAL = process.env.status_INTERVAL || 1000;
52+
const ONLINE_TIMEOUT = process.env.ONLINE_TIMEOUT || 20000
5053

5154
assert(MAC);
5255
assert(IP);
@@ -70,7 +73,9 @@ app.get("/", async (req, res) => {
7073
} else {
7174
res.render("index.njk", {
7275
name: NAME,
73-
message: message
76+
message: message,
77+
statusInterval: STATUS_INTERVAL,
78+
onlineTimeout: ONLINE_TIMEOUT
7479
})
7580
}
7681
} catch(e) {

src/public/main.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ body {
7171
footer {
7272
position: absolute;
7373
bottom: 0px;
74+
left: 0px;
7475
text-align: center;
7576
width: 100%;
7677
padding: 16px;

src/public/main.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ const indicator = document.getElementById("indicator");
44
const favicon = document.getElementById("favicon");
55
let serverStatus = "Waiting for response...";
66
let awaitingOnline = false;
7-
const onlineTimeout = 20000; // time in ms to wait before deciding wol ping didn't work
87

98
var wakeFailed;
109

10+
function redirectAuth(){
11+
window.location.href = "/auth";
12+
}
13+
1114
function yoink(){
1215
fetch(`${window.location.href}yoink`, {
1316
method: 'POST'
@@ -22,6 +25,8 @@ function yoink(){
2225
awaitingOnline = false;
2326
getStatus();
2427
}, onlineTimeout)
28+
} else if (res.status === 401){
29+
redirectAuth()
2530
}
2631
})
2732
}
@@ -30,7 +35,12 @@ function getStatus(){ // check if target machine is online
3035
fetch(`${window.location.href}status`, {
3136
method: 'GET'
3237
})
33-
.then(res => res.text())
38+
.then(res => {
39+
if (res.status == 401) {
40+
redirectAuth();
41+
}
42+
res.text()
43+
})
3444
.then(online => {
3545

3646
if (awaitingOnline && serverOnline){
@@ -49,8 +59,8 @@ function getStatus(){ // check if target machine is online
4959

5060

5161
button.disabled = (serverOnline || awaitingOnline);
62+
setTimeout(getStatus, statusInterval); // run function again after delay
5263
});
5364
}
5465

5566
getStatus();
56-
setInterval(getStatus, 1000);

src/views/index.njk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@
88
<button id="yoinkButton" onclick="yoink()">{{message}}</button>
99
</div>
1010

11+
<script>
12+
const statusInterval = {{statusInterval}};
13+
const onlineTimeout = {{onlineTimeout}};
14+
</script>
1115
<script src="/main.js"></script>
1216
{% endblock %}

0 commit comments

Comments
 (0)