updates to wtv-admin

This commit is contained in:
zefie
2022-10-16 17:41:08 -04:00
parent 84e875fa3e
commit f285751467
14 changed files with 343 additions and 15 deletions

View File

@@ -21,7 +21,7 @@ if (auth === true) {
<sidebar width=20%>
<img src="wtv-tricks:/images/Favorites_bg.jpg">
</sidebar>
<body bgcolor="#0a0a0a" text="#CC1111" link="#ff55ff" vlink="#ff55ff" vspace=0>
<body bgcolor="#101010" text="#FF3455" link="#ff55ff" vlink="#ff55ff" vspace=0>
<font size="-1">
<br>
<br>
@@ -57,19 +57,19 @@ if (auth === true) {
<tr>
<td><strike><a href="wtv-admin:/addadmin">Grant Admin to SSID</a></strike>
<td width = 10>
<td><strike><a href="wtv-admin:/modadmin">Modify Admin for SSID</a></strike>
<td><a href="wtv-admin:/polyzoot">Polyzoot a User</a>
<tr>
<td colspan=3 height=6>
<tr>
<td><a href="wtv-admin:/polyzoot">Polyzoot a User</a>
<td><strike><a href="wtv-admin:/modadmin">Modify Admin for SSID</a></strike>
<td width = 10>
<td><a href="wtv-admin:/reloadconfig">Reload Config</a>
<td><a href="wtv-admin:/operatortweaks">Edit Config</a>
<tr>
<td colspan=3 height=6>
<tr>
<td><a href="wtv-admin:/regenfavs">Restore Favs for User</a>
<td width = 10>
<td><!-- TODO -->
<td><a href="wtv-admin:/reloadconfig">Reload Config</a>
<tr>
<td colspan=3 height=6>
<tr>

View File

@@ -47,7 +47,7 @@ wtv-expire-all: wtv-admin:/ban`;
<sidebar width=20%>
<img src="wtv-admin:/images/nuke.gif">
</sidebar>
<body bgcolor="#0a0a0a" text="#CC1111" link="#ff55ff" vlink="#ff55ff" vspace=0>
<body bgcolor="#101010" text="#FF3455" link="#ff55ff" vlink="#ff55ff" vspace=0>
<br>
<br>
<h1>${minisrv_config.config.service_name} Admin Tricks</h1>

View File

@@ -39,7 +39,7 @@ wtv-noback-all: wtv-admin:/deleteaccount`;
<sidebar width=20%>
<img src="wtv-admin:/images/nuke.gif">
</sidebar>
<body bgcolor="#0a0a0a" text="#CC1111" link="#ff55ff" vlink="#ff55ff" vspace=0>
<body bgcolor="#101010" text="#FF3455" link="#ff55ff" vlink="#ff55ff" vspace=0>
<br>
<br>
<h1>${minisrv_config.config.service_name} Admin Tricks</h1>

View File

@@ -48,7 +48,7 @@ wtv-noback-all: wtv-admin:/deleteuser`;
<sidebar width=20%>
<img src="wtv-admin:/images/nuke.gif">
</sidebar>
<body bgcolor="#0a0a0a" text="#CC1111" link="#ff55ff" vlink="#ff55ff" vspace=0>
<body bgcolor="#101010" text="#FF3455" link="#ff55ff" vlink="#ff55ff" vspace=0>
<br>
<br>
<h1>${minisrv_config.config.service_name} Admin Tricks</h1>

View File

@@ -28,7 +28,7 @@ wtv-noback-all: wtv-admin:/findaccount`;
<sidebar width=20%>
<img src="wtv-tricks:/images/Favorites_bg.jpg">
</sidebar>
<body bgcolor="#0a0a0a" text="#CC1111" link="#ff55ff" vlink="#ff55ff" vspace=0>
<body bgcolor="#101010" text="#FF3455" link="#ff55ff" vlink="#ff55ff" vspace=0>
<br>
<br>
<h1>${minisrv_config.config.service_name} Admin Tricks</h1>

View File

@@ -0,0 +1,272 @@
var minisrv_service_file = true;
var WTVAdmin = require(classPath + "/WTVAdmin.js");
var wtva = new WTVAdmin(minisrv_config, session_data, service_name);
var auth = wtva.isAuthorized();
function generateFormField(type, confvar, options = null) {
if (confvar.indexOf('.') > 0) {
var confvar_split = confvar.split('.');
console.log(confvar_split)
// not operater error resistant, be mindful if you modify this page
if (user_config.config[confvar_split[0]])
var confvar_value = user_config.config[confvar_split[0]][confvar_split[1]] || minisrv_config.config[confvar_split[0]][confvar_split[1]]
else
var confvar_value = minisrv_config.config[confvar_split[0]][confvar_split[1]];
confvar = confvar.replace(".", "-");
} else
var confvar_value = user_config.config[confvar] || minisrv_config.config[confvar];
if (type == "input")
return `<input bgcolor="101010" text="ee44bb" type="text" name="${confvar}" value="${confvar_value}"${(options) ? ' '+options : ''}>`
if (type == "checkbox")
return `<input type="hidden" name="${confvar}" value="false">\n<input type=checkbox name="${confvar}" ${wtvshared.parseBool(confvar_value) ? "checked=checked" : ''}${(options) ? ' ' + options : ''}>`
if (type == "select") {
var out = `<select name="${confvar}">\n`
if (options) {
Object.keys(options).forEach((k) => {
out += `<option value="${options[k].value}"${(confvar_value == options[k].value) ? ' selected' : ''}>${options[k].name}</option>\n`
});
}
return out + "</select>";
}
}
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)) {
var user_config = wtvshared.getUserConfig();
headers = "200 OK\r\nContent-Type: text/html";
data = `<html>
<body>
<display nosave nosend>
<title>${minisrv_config.config.service_name} Operator Tweaks</title>
<script type="text/javascript">
function forceNumeric(e) {
switch (e.keyCode) {
case 8:
case 9:
case 13:
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
case 57:
return true;
break;
default:
return false;
}
}
function passwordFieldToggle(check) {
document.forms[0]['passwords-min_length'].disabled = !check.checked;
document.forms[0]['passwords-min_length'].readonly = !check.checked;
document.forms[0]['passwords-max_length'].disabled = !check.checked;
document.forms[0]['passwords-max_length'].readonly = !check.checked;
document.forms[0]['passwords-form_size'].disabled = !check.checked;
document.forms[0]['passwords-form_size'].readonly = !check.checked;
}
function validateNumber(field, min, max, def) {
var num = parseInt(field.value);
if (num === NaN) num = def;
if (num < min) num = min;
if (num > max) num = max;
if (field.value != num) field.value = num;
}
</script>
<sidebar width=20%>
<img src="wtv-tricks:/images/Favorites_bg.jpg">
</sidebar>
<body bgcolor="#101010" text="#EE44bb" link="#ff55ff" vlink="#ff55ff" vspace=0>
<font size="-1">
<br>
<br>
<h1><font color=#FF3455>${minisrv_config.config.service_name} Operator Tweaks</font></h1>
<font size=-1><i>These settings can be updated without restarting minisrv</i></font>
<hr>
<table>
<tr>
<TD>
<TR>
<td>
<tr>
<td WIDTH=198 VALIGN=top ALIGN=left>
<table cellspacing=0 cellpadding=5>
<tr><td absheight=60 valign=top>
<font size=-1><b>service_owner</b><br>The name of the server
operator
<tr><td absheight=60 valign=top>
<font size=-1><b>service_owner_account</b><br>The minisrv account name of the server
operator
<tr><td absheight=90 valign=top>
<font size=-1><b>service_owner_contact</b><br>The email address or username of the
server operator where users can contact them
<tr><td absheight=100 valign=top>
<font size=-1><b>service_owner_<br>contact_method</b><br>The method by which the user can
contact the server operator (eg. email, Discord, Twitter, etc...)
<tr><td absheight=60 valign=top>
<font size=-1><b>service_name</b><br>The name of the service (eg. WebTV)
<tr><td absheight=90 valign=top>
<font size=-1><b>service_logo</b><br>The logo for the service. Filename only. Must exist in the SharedROMCache service vault.
<tr><td absheight=70 valign=top>
<font size=-1><b>service_splash_logo</b><br>The splash page logo for the service. Absolute path. Can be file:// or wtv url.
<tr><td absheight=60 valign=top>
<font size=-1><b>show_detailed_splash</b><br>Show service information and client connection speed on the splash page.
<tr><td absheight=60 valign=top>
<font size=-1><b>hide_ssid_in_logs</b><br>Filter SSIDs in console logs and log files.
<tr><td absheight=90 valign=top>
<font size=-1><b>filter_<br>passwords_in_logs</b><br>Filter passwords (if the form field contains 'pass') in console logs and log files.
<tr><td absheight=45 valign=top>
<font size=-1><b>verbosity</b><br>Console log debug level.
<tr><td absheight=60 valign=top>
<font size=-1><b>show_diskmap</b><br>Useful for debugging wtv-disk downloads.
<tr><td absheight=140 valign=top>
<font size=-1><b>allow_guests</b><br>Allows users to use the service without having to register.
Guest session data is destroyed upon logout, and some features are not available to guests.
<tr><td absheight=90 valign=top>
<font size=-1><b>enable_<br>lzpf_compression</b><br>Toggles whether LZPF compression will be considered or not
<tr><td absheight=90 valign=top>
<font size=-1><b>enable_<br>gzip_compression</b><br>Toggles whether GZIP compression will be considered or not
<tr><td absheight=45 valign=top>
<font size=-1><b>Max Users Per Account</b>
<tr><td absheight=45 valign=top>
<font size=-1><b>Min Username Length</b>
<tr><td absheight=45 valign=top>
<font size=-1><b>Max Username Length</b>
<tr><td absheight=120 valign=top>
<font size=-1><b>Enable Passwords</b><br>
When disabled, accounts will not be able to use passwords, if they had a password set prior, the account will be accessible without it.
<tr><td absheight=45 valign=top>
<font size=-1><b>Min Password Length</b>
<tr><td absheight=45 valign=top>
<font size=-1><b>Max Password Length</b>
<tr><td absheight=60 valign=top>
<font size=-1><b>Password Field Size</b>
The size of the field on the login password page
</table>
<TD WIDTH=15>
<TD WIDTH=198 absheight=2000 VALIGN=top ALIGN=left colspan=2>
<form action="wtv-admin:/validate-operator-tweaks">
<input type=hidden name=autosubmit value=true autosubmit=onleave>
<table cellspacing=0 cellpadding=5>
<tr><td valign=top>
<table>
<tr>
<td absheight=60 valign=top>
${generateFormField('input', 'service_owner')}
<tr>
<td absheight=60 valign=top>
${generateFormField('input', 'service_owner_account')}
<tr>
<td absheight=90 valign=top>
${generateFormField('input', 'service_owner_contact')}
<tr>
<td absheight=90 valign=top>
${generateFormField('input', 'service_owner_contact_method')}
<tr>
<td absheight=60 valign=top>
${generateFormField('input', 'service_name')}
<tr>
<td absheight=90 valign=top>
${generateFormField('input', 'service_logo')}
<tr>
<td absheight=70 valign=top>
${generateFormField('input', 'service_splash_logo')}
<tr>
<td absheight=60 valign=top>
${generateFormField('checkbox', 'show_detailed_splash')}
<tr>
<td absheight=60 valign=top>
${generateFormField('checkbox', 'hide_ssid_in_logs')}
<tr>
<td absheight=70 valign=top>
${generateFormField('checkbox', 'filter_passwords_in_logs')}
<tr>
<td absheight=50 valign=top>
${generateFormField('select', 'verbosity', [
{ "name": "Quiet (0)", value: 0 },
{ "name": "Show Headers (1)", value: 1 },
{ "name": "Verbose, without Headers (2)", value: 2 },
{ "name": "Verbose, with headers (3)", value: 3 },
{ "name": "Debug (4)", value: 4 },
])}
<tr>
<td absheight=60 valign=top>
${generateFormField('checkbox', 'show_diskmap')}
<tr>
<td absheight=140 valign=top>
${generateFormField('checkbox', 'allow_guests')}
<tr>
<td absheight=85 valign=top>
${generateFormField('checkbox', 'enable_lzpf_compression')}
<tr>
<td absheight=80 valign=top>
${generateFormField('checkbox', 'enable_gzip_compression')}
<tr>
<td absheight=42 valign=top>
${generateFormField('input', 'user_accounts.max_users_per_account', "size=2 onkeypress='return forceNumeric(event)' onchange='validateNumber(this,1,50,6)' maxlength=2")}
<tr>
<td absheight=42 valign=top>
${generateFormField('input', 'user_accounts.min_username_length', "size=2 onkeypress='return forceNumeric(event)' onchange='validateNumber(this,3,50,5)' maxlength=2")}
<tr>
<td absheight=50 valign=top>
${generateFormField('input', 'user_accounts.max_username_length', "size=2 onkeypress='return forceNumeric(event)' onchange='validateNumber(this,3,50,18)' maxlength=2")}
<tr>
<td absheight=113 valign=top>
${generateFormField('checkbox', 'passwords.enabled', "onchange='passwordFieldToggle(this)'")}
<tr>
<td absheight=40 valign=top>
${generateFormField('input', 'passwords.min_length', "size=2 onkeypress='return forceNumeric(event)' onchange='validateNumber(this,3,32,5)' maxlength=2")}
<tr>
<td absheight=46 valign=top>
${generateFormField('input', 'passwords.max_length', "size=2 onkeypress='return forceNumeric(event)' onchange='validateNumber(this,3,256,32)' maxlength=2")}
<tr>
<td absheight=60 valign=top>
${generateFormField('input', 'passwords.form_size', "size=2 onkeypress='return forceNumeric(event)' onchange='validateNumber(this,5,99,16)' maxlength=2")}
</table>
</table>
</form>
<tr>
<td colspan=4><hr>
<TR>
<TD>
<TD COLSPAN=2 VALIGN=top ALIGN=left>
<TD VALIGN=top ALIGN=right>
<FORM action="client:goback">
<FONT COLOR="#E7CE4A" SIZE=-1><SHADOW>
<INPUT TYPE=SUBMIT BORDERIMAGE="file://ROM/Borders/ButtonBorder2.bif" Value=Done NAME="Done" USESTYLE WIDTH=103>
</SHADOW></FONT></FORM>
<TD>
</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

@@ -58,7 +58,7 @@ wtv-noback-all: wtv-admin:/polyzoot`;
<sidebar width=20%>
<img src="wtv-admin:/images/polyzoot.jpg">
</sidebar>
<body bgcolor="#0a0a0a" text="#CC1111" link="#ff55ff" vlink="#ff55ff" vspace=0>
<body bgcolor="#101010" text="#FF3455" link="#ff55ff" vlink="#ff55ff" vspace=0>
<br>
<br>
<h1>${minisrv_config.config.service_name} Admin Tricks</h1>

View File

@@ -39,7 +39,7 @@ wtv-noback-all: wtv-admin:/regenfavs`;
<sidebar width=20%>
<img src="wtv-tricks:/images/Favorites_bg.jpg">
</sidebar>
<body bgcolor="#0a0a0a" text="#CC1111" link="#ff55ff" vlink="#ff55ff" vspace=0>
<body bgcolor="#101010" text="#FF3455" link="#ff55ff" vlink="#ff55ff" vspace=0>
<br>
<br>
<h1>${minisrv_config.config.service_name} Admin Tricks</h1>

View File

@@ -25,7 +25,7 @@ wtv-noback-all: wtv-admin:/reloadconfig`;
<sidebar width=20%>
<img src="wtv-tricks:/images/Favorites_bg.jpg">
</sidebar>
<body bgcolor="#0a0a0a" text="#CC1111" link="#ff55ff" vlink="#ff55ff" vspace=0>
<body bgcolor="#101010" text="#FF3455" link="#ff55ff" vlink="#ff55ff" vspace=0>
<br>
<br>
<h1>${minisrv_config.config.service_name} Admin Tricks</h1>

View File

@@ -44,7 +44,7 @@ wtv-noback-all: wtv-admin:/removeuserpasswd`;
<sidebar width=20%>
<img src="wtv-admin:/images/nuke.gif">
</sidebar>
<body bgcolor="#0a0a0a" text="#CC1111" link="#ff55ff" vlink="#ff55ff" vspace=0>
<body bgcolor="#101010" text="#FF3455" link="#ff55ff" vlink="#ff55ff" vspace=0>
<br>
<br>
<h1>${minisrv_config.config.service_name} Admin Tricks</h1>

View File

@@ -56,7 +56,7 @@ wtv-expire-all: wtv-admin:/unban`;
<sidebar width=20%>
<img src="wtv-admin:/images/nuke_inverted.gif">
</sidebar>
<body bgcolor="#0a0a0a" text="#CC1111" link="#ff55ff" vlink="#ff55ff" vspace=0>
<body bgcolor="#101010" text="#FF3455" link="#ff55ff" vlink="#ff55ff" vspace=0>
<br>
<br>
<h1>${minisrv_config.config.service_name} Admin Tricks</h1>

View File

@@ -0,0 +1,48 @@
var minisrv_service_file = true;
var WTVAdmin = require(classPath + "/WTVAdmin.js");
var wtva = new WTVAdmin(minisrv_config, session_data, 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)) {
var user_config = wtvshared.getUserConfig();
Object.keys(request_headers.query).forEach((k) => {
if (k === "autosubmit") return;
var v = request_headers.query[k];
if (!isNaN(parseInt(v))) v = parseInt(v);
if (v === "on" || v === "true" || v === "false") v = wtvshared.parseBool(v);
if (k.indexOf("-") > 0) {
var s = k.split("-");
if (!user_config.config[s[0]]) user_config.config[s[0]] = {}
user_config.config[s[0]][s[1]] = v;
} else {
user_config.config[k] = v;
}
});
var res = wtvshared.writeToUserConfig(user_config);
if (res) {
console.log(" * Configuration updated from wtv-admin, reloading")
reloadConfig();
headers = "200 OK\r\nContent-Type: text/html";
} else {
err = wtvshared.doErrorPage(400, "Error writing userconfig");
headers = err[0];
data = err[1];
}
}
}
if (!headers) {
err = wtvshared.doErrorPage();
headers = err[0];
data = err[1];
}

View File

@@ -374,7 +374,8 @@ class WTVShared {
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(this.getAbsolutePath("user_config.json", parentDirectory), JSON.stringify(new_user_config, null, "\t"));
this.fs.writeFileSync(this.getAbsolutePath("user_config.json", this.parentDirectory), JSON.stringify(new_user_config, null, "\t"));
return true;
}
catch (e) {
if (this.minisrv_config.config.debug_flags) {
@@ -388,6 +389,7 @@ class WTVShared {
}
}
}
return false;
}
generateString(len, extra_chars = null) {

View File

@@ -189,6 +189,12 @@
<Content Include="ServiceVault\wtv-admin\images\nuke.gif" />
<Content Include="ServiceVault\wtv-admin\images\nuke_inverted.gif" />
<Content Include="ServiceVault\wtv-admin\images\polyzoot.jpg" />
<Content Include="ServiceVault\wtv-admin\validate-operator-tweaks.js">
<SubType>Code</SubType>
</Content>
<Content Include="ServiceVault\wtv-admin\operatortweaks.js">
<SubType>Code</SubType>
</Content>
<Content Include="ServiceVault\wtv-admin\polyzoot.js" />
<Content Include="ServiceVault\wtv-admin\regenfavs.js" />
<Content Include="ServiceVault\wtv-admin\reloadconfig.js" />