diff --git a/README.md b/README.md
index 67f5ecbe..913de648 100644
--- a/README.md
+++ b/README.md
@@ -122,6 +122,7 @@ These options can be configured by setting environment variables using `-e KEY="
| `UI_TRAFFIC_STATS` | `false` | `true` | Enable detailed RX / TX client stats in Web UI |
| `UI_CHART_TYPE` | `0` | `1` | UI_CHART_TYPE=0 # Charts disabled, UI_CHART_TYPE=1 # Line chart, UI_CHART_TYPE=2 # Area chart, UI_CHART_TYPE=3 # Bar chart |
| `UI_SHOW_LINKS` | `false` | `true` | Enable display of a short download link in Web UI |
+| `MAX_AGE` | `0` | `1440` | The maximum age of Web UI sessions in minutes. `0` means that the session will exist until the browser is closed. |
> If you change `WG_PORT`, make sure to also change the exposed port.
diff --git a/src/config.js b/src/config.js
index 9335bfbc..7941845c 100644
--- a/src/config.js
+++ b/src/config.js
@@ -6,6 +6,7 @@ module.exports.RELEASE = version;
module.exports.PORT = process.env.PORT || '51821';
module.exports.WEBUI_HOST = process.env.WEBUI_HOST || '0.0.0.0';
module.exports.PASSWORD_HASH = process.env.PASSWORD_HASH;
+module.exports.MAX_AGE = parseInt(process.env.MAX_AGE, 10) * 1000 * 60 || 0;
module.exports.WG_PATH = process.env.WG_PATH || '/etc/wireguard/';
module.exports.WG_DEVICE = process.env.WG_DEVICE || 'eth0';
module.exports.WG_HOST = process.env.WG_HOST;
diff --git a/src/lib/Server.js b/src/lib/Server.js
index d46d29eb..3bee3499 100644
--- a/src/lib/Server.js
+++ b/src/lib/Server.js
@@ -29,6 +29,7 @@ const {
WEBUI_HOST,
RELEASE,
PASSWORD_HASH,
+ MAX_AGE,
LANG,
UI_TRAFFIC_STATS,
UI_CHART_TYPE,
@@ -83,6 +84,11 @@ module.exports = class Server {
return `"${LANG}"`;
}))
+ .get('/api/remember-me', defineEventHandler((event) => {
+ setHeader(event, 'Content-Type', 'application/json');
+ return MAX_AGE > 0;
+ }))
+
.get('/api/ui-traffic-stats', defineEventHandler((event) => {
setHeader(event, 'Content-Type', 'application/json');
return `"${UI_TRAFFIC_STATS}"`;
@@ -121,7 +127,7 @@ module.exports = class Server {
return config;
}))
.post('/api/session', defineEventHandler(async (event) => {
- const { password } = await readBody(event);
+ const { password, remember } = await readBody(event);
if (!requiresPassword) {
// if no password is required, the API should never be called.
@@ -139,6 +145,9 @@ module.exports = class Server {
});
}
+ if (MAX_AGE && remember) {
+ event.node.req.session.cookie.maxAge = MAX_AGE;
+ }
event.node.req.session.authenticated = true;
event.node.req.session.save();
diff --git a/src/www/index.html b/src/www/index.html
index ff755847..2867a594 100644
--- a/src/www/index.html
+++ b/src/www/index.html
@@ -565,7 +565,25 @@
+
+
+
+