add wtv-admin:/reloadconfig

This commit is contained in:
zefie
2022-10-07 21:28:44 -04:00
parent 744a580e55
commit 9edccab487
4 changed files with 62 additions and 6 deletions

View File

@@ -63,7 +63,7 @@ if (auth === true) {
<tr> <tr>
<td><a href="wtv-admin:/polyzoot">Polyzoot a User</a> <td><a href="wtv-admin:/polyzoot">Polyzoot a User</a>
<td width = 10> <td width = 10>
<td><!-- TODO --> <td><a href="wtv-admin:/reloadconfig">Reload Config</a>
<tr> <tr>
<td colspan=3 height=6> <td colspan=3 height=6>
<tr> <tr>

View File

@@ -0,0 +1,56 @@
var minisrv_service_file = true;
var WTVAdmin = require("./WTVAdmin.js");
var wtva = new WTVAdmin(minisrv_config, ssid_sessions[socket.ssid], service_name);
var auth = wtva.isAuthorized();
if (auth === true) {
var password = null;
if (request_headers.Authorization) {
var authheader = request_headers.Authorization.split(' ');
if (authheader[0] == "Basic") {
password = Buffer.from(authheader[1], 'base64').toString();
if (password) password = password.split(':')[1];
}
}
if (wtva.checkPassword(password)) {
reloadConfig();
headers = `200 OK
Content-Type: text/html
wtv-expire-all: wtv-admin:/reloadconfig
wtv-noback-all: wtv-admin:/reloadconfig`;
data = `<html>
<body>
<display nosave nosend>
<title>${minisrv_config.config.service_name} Admin Tricks</title>
<sidebar width=20%>
<img src="wtv-tricks:/images/Favorites_bg.jpg">
</sidebar>
<body bgcolor="#0a0a0a" text="#CC1111" link="#ff55ff" vlink="#ff55ff" vspace=0>
<br>
<br>
<h1>${minisrv_config.config.service_name} Admin Tricks</h1>
<br>
<table>
<tr>
<td colspan=3 height=6>
<h3>Reload Config</h3>
The config.json and user_config.json files has been reloaded.<br>
If you added a new service, it will not bind without a restart.
<tr>
</table>
<p align="right">
<a href="client:goback">Go Back</a>
</p>
</body>
</html>
`;
} else {
var errpage = wtvshared.doErrorPage(401, "Please enter the administration password, you can leave the username blank.");
headers = errpage[0];
data = errpage[1];
}
} else {
var errpage = wtvshared.doErrorPage(403, auth);
headers = errpage[0];
data = errpage[1];
}

View File

@@ -164,8 +164,8 @@ class WTVShared {
} }
readMiniSrvConfig(user_config = true, notices = true) { readMiniSrvConfig(user_config = true, notices = true, reload_notice = false) {
if (notices) console.log(" *** Reading global configuration..."); if (notices || reload_notice) console.log(" *** Reading global configuration...");
try { try {
var minisrv_config = JSON.parse(this.fs.readFileSync(__dirname + this.path.sep + "config.json")); var minisrv_config = JSON.parse(this.fs.readFileSync(__dirname + this.path.sep + "config.json"));
} catch (e) { } catch (e) {
@@ -189,7 +189,7 @@ class WTVShared {
if (user_config) { if (user_config) {
try { try {
if (notices) console.log(" *** Reading user configuration..."); if (notices || reload_notice) console.log(" *** Reading user configuration...");
var minisrv_user_config = this.getUserConfig() var minisrv_user_config = this.getUserConfig()
try { try {
minisrv_config = integrateConfig(minisrv_config, minisrv_user_config) minisrv_config = integrateConfig(minisrv_config, minisrv_user_config)
@@ -244,7 +244,7 @@ class WTVShared {
} }
} }
if (notices) console.log(" *** Configuration successfully read."); if (notices || reload_notice) console.log(" *** Configuration successfully read.");
this.minisrv_config = minisrv_config; this.minisrv_config = minisrv_config;
return this.minisrv_config; return this.minisrv_config;
} }

View File

@@ -1732,7 +1732,7 @@ function getGitRevision() {
var minisrv_config = null; var minisrv_config = null;
function reloadConfig() { function reloadConfig() {
minisrv_config = wtvshared.readMiniSrvConfig(true, false); // snatches minisrv_config minisrv_config = wtvshared.readMiniSrvConfig(true, false, true); // snatches minisrv_config
return minisrv_config; return minisrv_config;
} }