initial work on wtv-admin features

This commit is contained in:
zefie
2022-10-07 19:31:05 -04:00
parent dae6637e8e
commit 86d8a09688
15 changed files with 891 additions and 60 deletions

View File

@@ -0,0 +1,94 @@
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)) {
headers = "200 OK\r\nContent-Type: text/html";
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>
<font size="-1">
<br>
<br>
<h1>${minisrv_config.config.service_name} Admin Tricks</h1>
<br>
<table>
<tr>
<td colspan=3 height=6>
<tr>
<td width=170><a href="wtv-tricks:/tricks">Standard Tricks</a>
<td width=10>
<td><a href="wtv-admin:/findaccount">Account Lookup</a>
<tr>
<td colspan=3 height=6>
<tr>
<td><a href="wtv-admin:/ban">Ban an SSID</a>
<td width = 10>
<td><a href="wtv-admin:/deleteaccount">Delete an Account</a>
<tr>
<td colspan=3 height=6>
<tr>
<td><a href="wtv-admin:/unban">Unban an SSID</a>
<td width = 10>
<td><a href="wtv-admin:/deleteuser">Delete User from Account</a>
<tr>
<td colspan=3 height=6>
<tr>
<td><strike><a href="wtv-admin:/whitelist">Whitelist an SSID</a></strike>
<td width = 10>
<td><strike><a href="wtv-admin:/removeuserpasswd">Remove Pass from User </a></strike>
<tr>
<td colspan=3 height=6>
<tr>
<td><strike><a href="wtv-admin:/addadmin">Grant Admin to SSID</a></strike>
<td width = 10>
<td><strike><a href="wtv-admin:/deladmin">Revoke Admin from SSID</a></strike>
<tr>
<td colspan=3 height=6>
<tr>
<td><!-- TODO -->
<td width = 10>
<td><!-- TODO -->
<tr>
<td colspan=3 height=6>
<tr>
<td><!-- TODO -->
<td width = 10>
<td><!-- TODO -->
<tr>
<td colspan=3 height=6>
<tr>
<td><!-- TODO -->
<td width = 10>
<td>
<!-- TODO -->
<td width = 10>
</table>
</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

@@ -0,0 +1,94 @@
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)) {
if (request_headers.query.ssid) {
var ssid = request_headers.query.ssid.toLowerCase();
if (ssid == socket.ssid) {
var nobanself = true;
} else {
var fake_config = wtvshared.getUserConfig();
if (!fake_config.config) fake_config.config = {};
if (!fake_config.config.ssid_block_list) fake_config.config.ssid_block_list = [];
var entry_exists = false;
Object.keys(fake_config.config.ssid_block_list).forEach(function (k) {
if (fake_config.config.ssid_block_list[k] == ssid) {
entry_exists = true;
}
});
if (!entry_exists) {
fake_config.config.ssid_block_list.push(ssid);
wtvshared.writeToUserConfig(fake_config);
reloadConfig();
}
}
}
headers = `200 OK
Content-Type: text/html
wtv-expire-all: wtv-admin:/ban`;
if (ssid) {
headers += "\nwtv-noback-all: wtv-admin:/ban";
}
data = `<html>
<body>
<display nosave nosend>
<title>${minisrv_config.config.service_name} Admin Tricks</title>
<sidebar width=20%>
<img src="wtv-admin:/images/nuke.gif">
</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>Ban an SSID</h3>
<form action="wtv-admin:/ban" method="POST">
<input type="text" name="ssid" value="${(ssid) ? ssid : ""}">
<input type="submit" value="Ban SSID">
</form><br><br>`
if (request_headers.query.ssid) {
if (nobanself) {
data += "<strong>Cannot ban yourself.</strong>"
} else {
if (entry_exists) {
data += "<strong>SSID " + request_headers.query.ssid + " is already in the ban list.</strong><br><br>";
} else {
data += "<strong>SSID " + request_headers.query.ssid + " added to the ban list.</strong><br><br>";
}
}
}
data += `
<br>
<br>
<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

@@ -0,0 +1,112 @@
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)) {
if (request_headers.query.ssid) {
var ssid_match = false;
var ssid = request_headers.query.ssid.toLowerCase();
var user_info = wtva.getAccountInfoBySSID(ssid);
if (request_headers.query.confirm_delete) {
user_info = null;
if (ssid == socket.ssid) {
ssid_match = true;
} else {
// delete
var userAccount = wtva.getAccountBySSID(ssid);
userAccount.unregisterBox();
}
}
}
headers = `200 OK
Content-Type: text/html
wtv-expire-all: wtv-admin:/deleteaccount
wtv-noback-all: wtv-admin:/deleteaccount`;
data = `<html>
<body>
<display nosave nosend>
<title>${minisrv_config.config.service_name} Admin Tricks</title>
<sidebar width=20%>
<img src="wtv-admin:/images/nuke.gif">
</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>Delete an Account</h3>
<form action="wtv-admin:/deleteaccount" method="POST">
<input type="text" name="ssid" value="${(ssid) ? ssid : ""}"> &nbsp; <input type="submit" value="Look Up SSID">
</form><br><br>`
if (ssid) {
if (user_info) {
data += `
<strong>User Information:</strong>
<table border=1 cellpadding=3 width=400>
<tr><td>Username:</td><td>${user_info.username} (User ID: ${user_info.user_id})</td></tr>
<tr><td>SSID:</td><td>${user_info.ssid}</td></tr>`;
if (user_info.account_users) {
data += `<tr><td>Primary User:</td><td>${user_info.account_users['subscriber'].subscriber_username}</td></tr>`;
if (Object.keys(user_info.account_users).length > 1) {
data += `<tr><td>Additional Users:</td><td>`;
Object.keys(user_info.account_users).forEach(function (k) {
if (k == "subscriber") return;
data += user_info.account_users[k].subscriber_username + "<br>";
})
data += `</td></tr>`
}
}
data += `
<tr>
<td border=0 colspan=2 align=right>
<form action="wtv-admin:/deleteaccount" method="POST">
<input type="hidden" name="ssid" value="${user_info.ssid}">
<input type="hidden" name="confirm_delete" value="true">
<input type="submit" value="Confirm Delete">
</form>
</td>
</tr>
`
data += `</table>`;
} else if (request_headers.query.confirm_delete && ssid_match) {
data += `<strong>Cannot delete yourself in this manner.<br>Try ${minisrv_config.config.service_name} Tricks Unregister.</strong><br><br>`;
} else if (request_headers.query.confirm_delete) {
data += "<strong>Account for SSID \"" + ssid + "\" has been deleted.</strong><br><br>";
} else {
data += "<strong>Could not find an account for SSID \"" + ssid + "\"</strong><br><br>";
}
}
data += `
<br>
<br>
<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

@@ -0,0 +1,118 @@
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)) {
if (request_headers.query.username) {
var show_cannot_modify_self = false;
var show_cannot_remove_primary = false;
var show_box_was_unregistered = false;
var user_info = wtva.getAccountInfo(request_headers.query.username.toLowerCase()); // username search
if (user_info) {
if (user_info.ssid == socket.ssid) {
show_cannot_modify_self = true;
}
if (request_headers.query.confirm_delete) {
if (!show_cannot_modify_self) {
// delete
var userAccount = wtva.getAccountBySSID(user_info.ssid);
userAccount.switchUserID(0, false, false);
var userCount = Object.keys(user_info.account_users).length;
if (user_info.user_id === 0) {
show_cannot_remove_primary = true;
} else {
var result = userAccount.removeUser(user_info.user_id);
}
}
}
}
}
headers = `200 OK
Content-Type: text/html
wtv-expire-all: wtv-admin:/deleteuser
wtv-noback-all: wtv-admin:/deleteuser`;
data = `<html>
<body>
<display nosave nosend>
<title>${minisrv_config.config.service_name} Admin Tricks</title>
<sidebar width=20%>
<img src="wtv-admin:/images/nuke.gif">
</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>Delete a user from an account</h3>
<form action="wtv-admin:/deleteuser" method="POST">
<input type="text" name="username" value="${(request_headers.query.username) ? request_headers.query.username : ""}"> &nbsp; <input type="submit" value="Look Up User">
</form><br><br>`
if (request_headers.query.username) {
if (user_info && !request_headers.query.confirm_delete) {
data += `
<strong>User Information:</strong>
<table border=1 cellpadding=3 width=400>
<tr><td>Username:</td><td>${user_info.username} (User ID: ${user_info.user_id})</td></tr>
<tr><td>SSID:</td><td>${user_info.ssid}</td></tr>`;
if (user_info.account_users) {
data += `<tr><td>Primary User:</td><td>${user_info.account_users['subscriber'].subscriber_username}</td></tr>`;
}
data += `
<tr>
<td border=0 colspan=2 align=right>
<form action="wtv-admin:/deleteuser" method="POST">
<input type="hidden" name="username" value="${user_info.username}">
<input type="hidden" name="confirm_delete" value="true">
<input type="submit" value="Confirm Delete">
</form>
</td>
</tr>
`
data += `</table>`;
} else if (request_headers.query.confirm_delete && show_cannot_modify_self) {
data += `<strong>Cannot modify your account in this manner.<br>Try <a href="wtv-setup:/remove-users">wtv-setup</a>.</strong><br><br>`;
} else if (request_headers.query.confirm_delete && show_cannot_remove_primary) {
data += `<strong>Cannot delete a primary user in this manner.<br>Try <a href="wtv-admin:/deleteaccount?ssid=${user_info.ssid}">deleting the account</a>.<br><br>`;
} else if (request_headers.query.confirm_delete && show_box_was_unregistered) {
data += `<strong>Account for "${user_info.username}" was deleted, and SSID ${user_info.ssid} unregistered, as it was the only user.<br><br>`;
} else if (request_headers.query.confirm_delete) {
if (result) data += `<strong>User "${user_info.username}" has been deleted from account belonging to SSID ${user_info.ssid}.</strong><br><br>`;
else data += `<strong>Could not delete "${user_info.username}" from SSID ${user_info.ssid}.</strong><br><br>`;
} else {
data += "<strong>Could not find an account for user \"" + request_headers.query.username + "\"</strong><br><br>";
}
}
data += `
<br>
<br>
<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

@@ -0,0 +1,97 @@
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)) {
if (request_headers.query.username) {
var user_info = wtva.getAccountInfo(request_headers.query.username.toLowerCase()); // username search
if (!user_info) user_info = wtva.getAccountInfoBySSID(request_headers.query.username.toLowerCase()); // ssid search
}
headers = `200 OK
Content-Type: text/html
wtv-expire-all: wtv-admin:/findaccount
wtv-noback-all: wtv-admin:/findaccount`;
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>Account Lookup</h3>
<form action="wtv-admin:/findaccount" method="POST">
<input type="text" name="username" value="${(request_headers.query.username) ? request_headers.query.username : ""}"> &nbsp; <input type="submit" value="Look Up User / SSID">
</form><br><br>`
if (request_headers.query.username) {
if (user_info) {
data += `
<strong>User Information:</strong>
<table border=1 cellpadding=3>
<tr><td>Username:</td><td>${user_info.username} (User ID: ${user_info.user_id})</td></tr>
<tr><td>SSID:</td><td>${user_info.ssid}</td></tr>`;
if (user_info.account_users) {
data += `<tr><td>Primary User:</td><td>${user_info.account_users['subscriber'].subscriber_username}</td></tr>`;
if (Object.keys(user_info.account_users).length > 1) {
data += `<tr><td>Additional Users:</td><td>`;
Object.keys(user_info.account_users).forEach(function (k) {
if (k == "subscriber") return;
data += user_info.account_users[k].subscriber_username + "<br>";
})
data += `</td></tr>`
}
}
data += `
<tr>
<td border=0 colspan=2>
<a href="wtv-admin:/ban?ssid=${user_info.ssid}">Ban SSID</a>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
<a href="wtv-admin:/unban?unban_ssid=${user_info.ssid}">Unban SSID</a>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
<a href="wtv-admin:/deleteaccount?ssid=${user_info.ssid}">Delete Account</span>
</td>
</tr>
`
data += `</table>`;
} else {
data += "<strong>Could not find user \"" + request_headers.query.username + "\"</strong><br><br>";
}
}
data += `
<br>
<br>
<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];
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -0,0 +1,104 @@
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();
var ssids_removed = [];
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)) {
if (request_headers.query.unban_ssid) {
var config_changed = false;
var fake_config = wtvshared.getUserConfig();
if (!fake_config.config) fake_config.config = {};
if (!fake_config.config.ssid_block_list) fake_config.config.ssid_block_list = [];
if (typeof request_headers.query.unban_ssid === 'string') {
Object.keys(fake_config.config.ssid_block_list).forEach(function (k) {
if (fake_config.config.ssid_block_list[k] == request_headers.query.unban_ssid) {
fake_config.config.ssid_block_list.splice(k, 1);
ssids_removed.push(request_headers.query.unban_ssid)
config_changed = true;
}
});
} else {
Object.keys(fake_config.config.ssid_block_list).forEach(function (k) {
Object.keys(request_headers.query.unban_ssid).forEach(function (j) {
if (fake_config.config.ssid_block_list[k] == request_headers.query.unban_ssid[j]) {
fake_config.config.ssid_block_list.splice(k,1);
ssids_removed.push(request_headers.query.unban_ssid[j])
config_changed = true;
}
});
});
}
if (config_changed) {
wtvshared.writeToUserConfig(fake_config);
minisrv_config = reloadConfig();
}
}
headers = `200 OK
Content-Type: text/html
wtv-expire-all: wtv-admin:/unban`;
if (request_headers.query.unban_ssid) {
headers += "\nwtv-noback-all: wtv-admin:/unban";
}
data = `<html>
<body>
<display nosave nosend>
<title>${minisrv_config.config.service_name} Admin Tricks</title>
<sidebar width=20%>
<img src="wtv-admin:/images/nuke_inverted.gif">
</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>Unban an SSID</h3>`;
if (minisrv_config.config.ssid_block_list.length > 0) {
data += '<form action="wtv-admin:/unban" method="POST">';
data += '<select name="unban_ssid" multiple size="8">';
Object.keys(minisrv_config.config.ssid_block_list).forEach(function (k) {
var ssid = minisrv_config.config.ssid_block_list[k];
data += "<option value=\"" + ssid + "\">" + ssid + "</option>\n";
});
data += '</select><br><input type="submit" value="Unban SSID(s)"></form>';
} else {
data += "No SSIDs are in the ban list.<br><br>";
}
if (ssids_removed.length > 0) {
if (config_changed) {
data += "<strong>SSID(s) " + ssids_removed + " removed from the ban list.</strong><br><br>";
}
}
data += `
<br>
<br>
<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

@@ -0,0 +1,153 @@
class WTVAdmin {
fs = require('fs');
path = require('path');
minisrv_config = [];
wtvr = null;
wtvshared = null;
wtvclient = null;
WTVClientSessionData = require('./WTVClientSessionData.js');
service_name = "wtv-admin";
constructor(minisrv_config, wtvclient, service_name) {
this.minisrv_config = minisrv_config;
var { WTVShared } = require('./WTVShared.js');
var WTVRegister = require('./WTVRegister.js');
this.wtvclient = wtvclient;
this.wtvshared = new WTVShared(minisrv_config);
this.wtvr = new WTVRegister(minisrv_config);
this.clientAddress = wtvclient.getClientAddress();
this.service_name = service_name;
}
ip2long(ip) {
var components;
if (components = ip.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)) {
var iplong = 0;
var power = 1;
for (var i = 4; i >= 1; i -= 1) {
iplong += power * parseInt(components[i]);
power *= 256;
}
return iplong;
}
else return -1;
}
isInSubnet(ip, subnet) {
var mask, base_ip, long_ip = this.ip2long(ip);
if ((mask = subnet.match(/^(.*?)\/(\d{1,2})$/)) && ((base_ip = this.ip2long(mask[1])) >= 0)) {
var freedom = Math.pow(2, 32 - parseInt(mask[2]));
return (long_ip > base_ip) && (long_ip < base_ip + freedom - 1);
}
else return false;
}
rejectConnection(reason_is_ssid) {
var rejectReason;
if (reason_is_ssid) {
rejectReason = this.wtvclient.ssid + " is not in the whitelist.";
console.log(" * Request from SSID", this.wtvshared.filterSSID(this.wtvclient.ssid), "(" + this.clientAddress + ") for wtv-admin, but that SSID is not in the admin whitelist.");
} else {
rejectReason = this.clientAddress + " is not in the whitelist for SSID " + this.wtvclient.ssid + ".";
console.log(" * Request from SSID", this.wtvshared.filterSSID(this.wtvclient.ssid), "(" + this.clientAddress + ") for wtv-admin, but that IP is not authorized for that SSID.");
}
return rejectReason;
}
checkPassword(password) {
if (this.minisrv_config.services[this.service_name].password) {
return (password == this.minisrv_config.services[this.service_name].password);
} else {
// no password set
return true;
}
}
isAuthorized() {
var allowed_ssid = false;
var allowed_ip = false;
if (this.minisrv_config.services[this.service_name].authorized_ssids) {
var self = this;
Object.keys(self.minisrv_config.services[this.service_name].authorized_ssids).forEach(function (k) {
if (typeof self.minisrv_config.services[self.service_name].authorized_ssids[k] == "string") {
var ssid = self.minisrv_config.services[self.service_name].authorized_ssids[k]
if (ssid == self.wtvclient.ssid) allowed_ssid = true;
allowed_ip = true; // no ip block defined
} else {
var ssid = k;
if (ssid == self.wtvclient.ssid) {
allowed_ssid = true;
Object.keys(self.minisrv_config.services[self.service_name].authorized_ssids[k]).forEach(function (j) {
if (self.isInSubnet(self.clientAddress, self.minisrv_config.services[self.service_name].authorized_ssids[k][j])) {
allowed_ip = true;
}
});
}
}
});
}
return (allowed_ssid && allowed_ip) ? true : this.rejectConnection(!allowed_ssid);
}
getAccountInfo(username, directory = null) {
var search_dir = this.minisrv_config.config.SessionStore;
var account_data = null;
var self = this;
if (directory) search_dir = directory;
this.fs.readdirSync(search_dir).forEach(file => {
if (self.fs.lstatSync(search_dir + self.path.sep + file).isDirectory() && account_data === null) {
account_data = self.getAccountInfo(username, search_dir + self.path.sep + file);
}
if (account_data !== null) return;
if (!file.match(/.*\.json/ig)) return;
try {
var temp_session_data_file = self.fs.readFileSync(search_dir + self.path.sep + file, 'Utf8');
var temp_session_data = JSON.parse(temp_session_data_file);
if (temp_session_data.subscriber_username.toLowerCase() == username.toLowerCase()) {
account_data = [temp_session_data, (search_dir + self.path.sep + file).replace(this.minisrv_config.config.SessionStore + this.path.sep, "").split(this.path.sep)[0]];
}
} catch (e) {
console.error(" # Error parsing Session Data JSON", search_dir + self.path.sep + file, e);
}
});
if (account_data !== null) {
if (account_data.ssid) return account_data;
var account_info = {};
account_info.ssid = account_data[1];
account_info.username = account_data[0].subscriber_username;
account_info.user_id = account_data[0].subscriber_userid;
var userSession = new this.WTVClientSessionData(this.minisrv_config, account_info.ssid);
userSession.user_id = 0;
account_info.account_users = userSession.listPrimaryAccountUsers();
return account_info;
}
return null;
}
getAccountInfoBySSID(ssid) {
var account_info = {};
var userSession = new this.WTVClientSessionData(this.minisrv_config, ssid);
userSession.user_id = 0;
if (userSession.isRegistered(false)) {
account_info.ssid = ssid;
account_info.account_users = userSession.listPrimaryAccountUsers();
account_info.username = account_info.account_users['subscriber'].subscriber_username;
account_info.user_id = 0;
return account_info;
}
else return false;
}
getAccountBySSID(ssid) {
var userSession = new this.WTVClientSessionData(this.minisrv_config, ssid);
userSession.user_id = 0;
return userSession;
}
}
module.exports = WTVAdmin;

View File

@@ -3,7 +3,6 @@ class WTVRegister {
fs = require('fs'); fs = require('fs');
path = require('path'); path = require('path');
minisrv_config = []; minisrv_config = [];
service_owner = "a minisrv user"; service_owner = "a minisrv user";
session_store_dir = null; session_store_dir = null;

View File

@@ -48,7 +48,6 @@ class WTVShared {
return query return query
} }
htmlEntitize(string, process_newline = false) { htmlEntitize(string, process_newline = false) {
string = this.html_entities.encode(string).replace(/&apos;/g, "'"); string = this.html_entities.encode(string).replace(/&apos;/g, "'");
@@ -144,6 +143,27 @@ class WTVShared {
return (this.isMiniBrowser(ssid_session) || parseInt(ssid_session.get("wtv-system-version")) < 3500) ? true : false; return (this.isMiniBrowser(ssid_session) || parseInt(ssid_session.get("wtv-system-version")) < 3500) ? true : false;
} }
getUserConfig() {
try {
if (this.fs.lstatSync(__dirname + "/user_config.json")) {
try {
var minisrv_user_config = JSON.parse(this.fs.readFileSync(__dirname + this.path.sep + "user_config.json"));
} catch (e) {
console.error("ERROR: Could not read user_config.json", e);
var throw_me = true;
}
} else {
var minisrv_user_config = {}
}
return minisrv_user_config;
} catch (e) {
if (minisrv_config.config.debug_flags) {
if (minisrv_config.config.debug_flags.debug) console.error(" * Notice: Could not find user configuration (user_config.json). Using default configuration.");
}
}
}
readMiniSrvConfig(user_config = true, notices = true) { readMiniSrvConfig(user_config = true, notices = true) {
if (notices) console.log(" *** Reading global configuration..."); if (notices) console.log(" *** Reading global configuration...");
try { try {
@@ -169,21 +189,12 @@ class WTVShared {
if (user_config) { if (user_config) {
try { try {
if (this.fs.lstatSync(__dirname + "/user_config.json")) { if (notices) console.log(" *** Reading user configuration...");
if (notices) console.log(" *** Reading user configuration..."); var minisrv_user_config = this.getUserConfig()
try { try {
var minisrv_user_config = JSON.parse(this.fs.readFileSync(__dirname + this.path.sep + "user_config.json")); minisrv_config = integrateConfig(minisrv_config, minisrv_user_config)
} catch (e) { } catch (e) {
console.error("ERROR: Could not read user_config.json", e); console.error("ERROR: Could not read user_config.json", e);
var throw_me = true;
}
// file exists and we read and parsed it, but the variable is undefined
// Likely a syntax parser error that did not trip the exception check above
try {
minisrv_config = integrateConfig(minisrv_config, minisrv_user_config)
} catch (e) {
console.error("ERROR: Could not read user_config.json", e);
}
} }
} catch (e) { } catch (e) {
if (minisrv_config.config.debug_flags) { if (minisrv_config.config.debug_flags) {
@@ -192,7 +203,76 @@ class WTVShared {
} }
} }
return minisrv_config; // defaults
minisrv_config.config.debug_flags = [];
minisrv_config.config.debug_flags.debug = false;
minisrv_config.config.debug_flags.quiet = true; // will squash minisrv_config.config.debug_flags.debug even if its true
minisrv_config.config.debug_flags.show_headers = false;
if (minisrv_config.config.verbosity) {
switch (minisrv_config.config.verbosity) {
case 0:
minisrv_config.config.debug_flags.debug = false;
minisrv_config.config.debug_flags.quiet = true;
minisrv_config.config.debug_flags.show_headers = false;
if (notices) console.log(" * Console Verbosity level 0 (quietest)")
break;
case 1:
minisrv_config.config.debug_flags.debug = false;
minisrv_config.config.debug_flags.quiet = true;
minisrv_config.config.debug_flags.show_headers = true;
if (notices) console.log(" * Console Verbosity level 1 (headers shown)")
break;
case 2:
minisrv_config.config.debug_flags.debug = true;
minisrv_config.config.debug_flags.quiet = true;
minisrv_config.config.debug_flags.show_headers = false;
if (notices) console.log(" * Console Verbosity level 2 (verbose without headers)")
break;
case 3:
minisrv_config.config.debug_flags.debug = true;
minisrv_config.config.debug_flags.quiet = true;
minisrv_config.config.debug_flags.show_headers = true;
if (notices) console.log(" * Console Verbosity level 3 (verbose with headers)")
break;
default:
minisrv_config.config.debug_flags.debug = true;
minisrv_config.config.debug_flags.quiet = false;
minisrv_config.config.debug_flags.show_headers = true;
if (notices) console.log(" * Console Verbosity level 4 (debug verbosity)")
break;
}
}
if (notices) console.log(" *** Configuration successfully read.");
this.minisrv_config = minisrv_config;
return this.minisrv_config;
}
writeToUserConfig(config) {
if (config) {
try {
var minisrv_user_config = this.getUserConfig();
// write back
try {
var new_user_config = {};
Object.assign(new_user_config, minisrv_user_config, config);
if (this.minisrv_config.config.debug_flags.debug) console.log(" * Writing new user configuration...");
this.fs.writeFileSync(__dirname + this.path.sep + "user_config.json", JSON.stringify(new_user_config, null, "\t"));
}
catch (e) {
if (this.minisrv_config.config.debug_flags) {
if (this.minisrv_config.config.debug_flags.debug) console.error(" * WARNING: Could not update user config. Data may have been lost.", e);
}
}
} catch (e) {
if (this.minisrv_config.config.debug_flags) {
if (this.minisrv_config.config.debug_flags.debug) console.error(" * Notice: Could not find user configuration (user_config.json). Using default configuration.");
}
}
}
} }
getMiniSrvConfig() { getMiniSrvConfig() {

View File

@@ -165,6 +165,7 @@ async function processPath(socket, service_vault_file_path, request_headers = ne
request_is_async: request_is_async, request_is_async: request_is_async,
minisrv_version_string: z_title, minisrv_version_string: z_title,
parseBool: parseBool, parseBool: parseBool,
reloadConfig: reloadConfig,
cwd: __dirname // current working directory, updated below in function cwd: __dirname // current working directory, updated below in function
} }
@@ -1728,6 +1729,12 @@ function getGitRevision() {
return null; return null;
} }
} }
var minisrv_config = null;
function reloadConfig() {
minisrv_config = wtvshared.readMiniSrvConfig(true, false); // snatches minisrv_config
return minisrv_config;
}
// SERVER START // SERVER START
var git_commit = getGitRevision() var git_commit = getGitRevision()
@@ -1736,7 +1743,7 @@ if (git_commit) console.log("**** Welcome to " + z_title + " (git " + git_commit
else console.log("**** Welcome to " + z_title + " ****"); else console.log("**** Welcome to " + z_title + " ****");
const wtvshared = new WTVShared(); // creates minisrv_config const wtvshared = new WTVShared(); // creates minisrv_config
var minisrv_config = wtvshared.getMiniSrvConfig(); // snatches minisrv_config minisrv_config = wtvshared.getMiniSrvConfig(); // snatches minisrv_config
const wtvmime = new WTVMime(minisrv_config); const wtvmime = new WTVMime(minisrv_config);
if (git_commit) { if (git_commit) {
@@ -1832,46 +1839,6 @@ process.on('uncaughtException', function (err) {
console.error((err && err.stack) ? err.stack : err); console.error((err && err.stack) ? err.stack : err);
}); });
// defaults
minisrv_config.config.debug_flags = [];
minisrv_config.config.debug_flags.debug = false;
minisrv_config.config.debug_flags.quiet = true; // will squash minisrv_config.config.debug_flags.debug even if its true
minisrv_config.config.debug_flags.show_headers = false;
if (minisrv_config.config.verbosity) {
switch (minisrv_config.config.verbosity) {
case 0:
minisrv_config.config.debug_flags.debug = false;
minisrv_config.config.debug_flags.quiet = true;
minisrv_config.config.debug_flags.show_headers = false;
console.log(" * Console Verbosity level 0 (quietest)")
break;
case 1:
minisrv_config.config.debug_flags.debug = false;
minisrv_config.config.debug_flags.quiet = true;
minisrv_config.config.debug_flags.show_headers = true;
console.log(" * Console Verbosity level 1 (headers shown)")
break;
case 2:
minisrv_config.config.debug_flags.debug = true;
minisrv_config.config.debug_flags.quiet = true;
minisrv_config.config.debug_flags.show_headers = false;
console.log(" * Console Verbosity level 2 (verbose without headers)")
break;
case 3:
minisrv_config.config.debug_flags.debug = true;
minisrv_config.config.debug_flags.quiet = true;
minisrv_config.config.debug_flags.show_headers = true;
console.log(" * Console Verbosity level 3 (verbose with headers)")
break;
default:
minisrv_config.config.debug_flags.debug = true;
minisrv_config.config.debug_flags.quiet = false;
minisrv_config.config.debug_flags.show_headers = true;
console.log(" * Console Verbosity level 4 (debug verbosity)")
break;
}
}
var initstring = ''; var initstring = '';
ports.sort(); ports.sort();

View File

@@ -111,6 +111,10 @@
"port": 1608, "port": 1608,
"connections": 3 "connections": 3
}, },
"wtv-admin": {
"port": 1698,
"password": "viRak-7"
},
"http": { "http": {
"port": 1650, "port": 1650,
"connections": 3, "connections": 3,

View File

@@ -1,6 +1,6 @@
{ {
"name": "zefie_wtvp_minisrv", "name": "zefie_wtvp_minisrv",
"version": "0.9.30", "version": "0.9.31",
"description": "WebTV Service (WTVP) Emulation Server", "description": "WebTV Service (WTVP) Emulation Server",
"main": "app.js", "main": "app.js",
"homepage": "https://github.com/zefie/zefie_wtvp_minisrv", "homepage": "https://github.com/zefie/zefie_wtvp_minisrv",

View File

@@ -35,6 +35,15 @@
"8100000000000000" "8100000000000000"
] ]
}, },
"wtv-admin": {
"authorized_ssids": {
"8100000000000000": [
"192.168.1.0/24",
"127.0.0.1"
]
},
"password": "my-secure-password"
},
"wtv-log": { "wtv-log": {
"write_logs_to_disk": true "write_logs_to_disk": true
}, },