implement remove-user functionality
This commit is contained in:
@@ -8,6 +8,7 @@ if (ssid_sessions[socket.ssid].user_id != 0) {
|
||||
} else {
|
||||
headers = `200 OK
|
||||
Connection: Keep-Alive
|
||||
wtv-expire-all: wtv-setup:/accounts
|
||||
Content-Type: text/html`
|
||||
|
||||
data = `<HTML>
|
||||
@@ -112,14 +113,14 @@ Subscriber:
|
||||
<TD COLSPAN=3 VALIGN=top ALIGN=right>
|
||||
<FONT COLOR="#E7CE4A" SIZE=-1><SHADOW>
|
||||
<INPUT action="/remove-users?user-count=x"
|
||||
name="RemoveUser" value="Remove User" WIDTH=140 ${(num_accounts >= 1) ? 'USESTYLE' : 'disabled="disabled" text=gray' }
|
||||
name="RemoveUser" value="Remove User" WIDTH=140 ${(num_accounts > 1) ? 'USESTYLE' : 'disabled="disabled" text=gray' }
|
||||
TYPE=SUBMIT BORDERIMAGE="file://ROM/Borders/ButtonBorder2.bif" NAME="Button1" WIDTH=103>
|
||||
<IMG SRC="ROMCache/Spacer.gif" WIDTH=4 HEIGHT=1>
|
||||
<INPUT action="/add-user?user_count=${num_accounts}"
|
||||
name="AddUser" value="Add User" WIDTH=120 ${(num_accounts >= minisrv_config.config.user_accounts.max_users_per_account) ? 'disabled="disabled" text=gray' : 'USESTYLE'}
|
||||
TYPE=SUBMIT BORDERIMAGE="file://ROM/Borders/ButtonBorder2.bif" NAME="Button2" WIDTH=103>
|
||||
<IMG SRC="ROMCache/Spacer.gif" WIDTH=4 HEIGHT=1>
|
||||
<INPUT action="client:goback"
|
||||
<INPUT action="wtv-setup:/serve-billing-overview?"
|
||||
name="Done"
|
||||
value="Done"
|
||||
WIDTH=120
|
||||
|
||||
164
zefie_wtvp_minisrv/ServiceVault/wtv-setup/remove-users.js
Normal file
164
zefie_wtvp_minisrv/ServiceVault/wtv-setup/remove-users.js
Normal file
@@ -0,0 +1,164 @@
|
||||
var minisrv_service_file = true;
|
||||
|
||||
if (Object.keys(ssid_sessions[socket.ssid].listPrimaryAccountUsers()).length == 1) {
|
||||
errpage = wtvshared.doErrorPage(400, "There are no more users to remove.");
|
||||
}
|
||||
else if (ssid_sessions[socket.ssid].user_id != 0) errpage = wtvshared.doErrorPage(400, "You are not authorized to add users to this account.");
|
||||
if (errpage) {
|
||||
headers = errpage[0];
|
||||
data = errpage[1];
|
||||
} else {
|
||||
headers = `200 OK
|
||||
Connection: Keep-Alive
|
||||
wtv-expire-all: wtv-setup:/remove-users
|
||||
wtv-expire-all: wtv-setup:/validate-remove-users
|
||||
Content-Type: text/html`
|
||||
|
||||
data = `<HTML>
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>
|
||||
Remove users
|
||||
</TITLE>
|
||||
<DISPLAY nosave
|
||||
noscroll>
|
||||
</HEAD>
|
||||
<sidebar width=110> <table cellspacing=0 cellpadding=0 BGCOLOR=30364D>
|
||||
<tr>
|
||||
<td colspan=3 abswidth=104 absheight=4>
|
||||
<td rowspan=99 width=6 absheight=420 valign=top align=left>
|
||||
<img src="wtv-home:/ROMCache/Shadow.gif" width=6 height=420>
|
||||
<tr>
|
||||
<td abswidth=6>
|
||||
<td abswidth=92 absheight=76>
|
||||
<table href="wtv-home:/home" absheight=76 cellspacing=0 cellpadding=0>
|
||||
<tr>
|
||||
<td align=right>
|
||||
<img src="${minisrv_config.config.service_logo}" width=87 height=67>
|
||||
</table>
|
||||
<td abswidth=6>
|
||||
<tr><td absheight=5 colspan=3>
|
||||
<table cellspacing=0 cellpadding=0>
|
||||
<tr><td abswidth=104 absheight=2 valign=middle align=center bgcolor=1C1E28>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
<tr><td abswidth=104 absheight=1 valign=top align=left>
|
||||
<tr><td abswidth=104 absheight=2 valign=top align=left bgcolor=4D5573>
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=1 height=1>
|
||||
</table>
|
||||
<tr><td absheight=37>
|
||||
<tr><td absheight=263 align=right colspan=3>
|
||||
<img src="ROMCache/AccountBanner.gif" width=53 height=263>
|
||||
<tr><td absheight=41>
|
||||
</table>
|
||||
</sidebar>
|
||||
<BODY NOHTILEBG BGCOLOR="#191919" TEXT="#42CC55" LINK="36d5ff" VLINK="36d5ff" HSPACE=0 VSPACE=0 FONTSIZE="large"
|
||||
>
|
||||
<TABLE cellspacing=0 cellpadding=0>
|
||||
<TR><TD width=20><img src="wtv-home:/ROMCache/Spacer.gif" width=20 height=1>
|
||||
<TD colspan=3 height=16 valign=top align=left>
|
||||
<TR>
|
||||
<TD width=20>
|
||||
<TD colspan=3 height=39 valign=top>
|
||||
<FONT size=+2 color="42CC55"> <blackface><shadow>
|
||||
Remove users </shadow></blackface>
|
||||
</FONT>
|
||||
<TR><TD width=10>
|
||||
<TD colspan=5 height=56 valign=top>
|
||||
<TABLE cellspacing=0 cellpadding=0>
|
||||
<TD width=400>
|
||||
<FONT color="42CC55">
|
||||
Mark users to remove permanently from your account,
|
||||
then choose <b>Remove</b>.
|
||||
</FONT>
|
||||
<TD align=right>
|
||||
</TABLE>
|
||||
<td abswidth=20>
|
||||
<TR>
|
||||
<td>
|
||||
<td WIDTH=198 HEIGHT=214 VALIGN=top ALIGN=left>
|
||||
<FONT COLOR="44cc55"><B>
|
||||
<TABLE CELLSPACING=0 CELLPADDING=0>
|
||||
<TR><TD COLSPAN=3 HEIGHT=2 VALIGN=MIDDLE ALIGN=CENTER BGCOLOR="2B2B2B"><IMG SRC="ROMCache/spacer.gif" WIDTH=10 HEIGHT=1>
|
||||
<TR><TD COLSPAN=3 HEIGHT=1 VALIGN=TOP ALIGN=LEFT>
|
||||
<TR><TD COLSPAN=3 HEIGHT=2 VALIGN=TOP ALIGN=LEFT BGCOLOR="0D0D0D"><IMG SRC="ROMCache/spacer.gif" WIDTH=10 HEIGHT=1>
|
||||
<TR><TD abswidth=54 absheight=25 valign=middle align=left>
|
||||
<TD abswidth=230 valign=left align=left>
|
||||
<font><blackface>Name</blackface></font>
|
||||
<TD abswidth=150 valign=left align=right>
|
||||
<font size="-1"><blackface>New Messages</blackface></font>
|
||||
<TR><TD COLSPAN=3 HEIGHT=2 VALIGN=MIDDLE ALIGN=CENTER BGCOLOR="2B2B2B"><IMG SRC="ROMCache/spacer.gif" WIDTH=1 HEIGHT=1>
|
||||
<TR><TD COLSPAN=3 HEIGHT=1 VALIGN=TOP ALIGN=LEFT>
|
||||
<TR><TD COLSPAN=3 HEIGHT=2 VALIGN=TOP ALIGN=LEFT BGCOLOR="0D0D0D"><IMG SRC="ROMCache/spacer.gif" WIDTH=1 HEIGHT=1>
|
||||
<TR><TD COLSPAN=3 HEIGHT=0>
|
||||
|
||||
<P><FORM ACTION="wtv-setup:/validate-remove-users" METHOD="POST">
|
||||
`;
|
||||
|
||||
var accounts = ssid_sessions[socket.ssid].listPrimaryAccountUsers();
|
||||
|
||||
var num_accounts = ssid_sessions[socket.ssid].getNumberOfUserAccounts();
|
||||
if (num_accounts > 1) {
|
||||
delete accounts.subscriber;
|
||||
for (const [key, value] of Object.entries(accounts)) {
|
||||
var userSession = new WTVClientSessionData(minisrv_config, socket.ssid);
|
||||
userSession.user_id = parseInt(key.replace("user", ''));
|
||||
|
||||
var mailcount = 0;
|
||||
if (userSession.mailstore.mailstoreExists()) {
|
||||
if (userSession.mailstore.mailboxExists(0)) {
|
||||
mailcount = userSession.mailstore.countUnreadMessages(0);
|
||||
}
|
||||
}
|
||||
|
||||
data += `<FONT COLOR="42CC55"><B>
|
||||
|
||||
<TR><TD COLSPAN=3 HEIGHT=5>
|
||||
<tr>
|
||||
<td colspan=2><input type=checkbox name="${key}"><font size=+1> <b>${value.subscriber_username}</b>
|
||||
<td align=right>${mailcount}
|
||||
</tr>
|
||||
</B></FONT>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
data += `
|
||||
</table>
|
||||
<TR>
|
||||
<TD>
|
||||
<TD COLSPAN=4 HEIGHT=4 VALIGN=top ALIGN=left>
|
||||
<tr>
|
||||
<TD>
|
||||
<td colspan=4 height=2 valign=middle align=center bgcolor="2B2B2B">
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=436 height=1>
|
||||
<tr>
|
||||
<TD>
|
||||
<td colspan=4 height=1 valign=top align=left>
|
||||
<tr>
|
||||
<TD>
|
||||
<td colspan=4 height=2 valign=top align=left bgcolor="0D0D0D">
|
||||
<img src="wtv-home:/ROMCache/Spacer.gif" width=436 height=1>
|
||||
<TR>
|
||||
<TD>
|
||||
<TD COLSPAN=4 HEIGHT=4 VALIGN=top ALIGN=left>
|
||||
<TR>
|
||||
<TD>
|
||||
<TD COLSPAN=3 VALIGN=top ALIGN=right>
|
||||
<FONT COLOR="#E7CE4A" SIZE=-1><SHADOW>
|
||||
<INPUT type="submit"
|
||||
name="Remove" value="Remove" WIDTH=103 USESTYLE
|
||||
TYPE=SUBMIT BORDERIMAGE="file://ROM/Borders/ButtonBorder2.bif" NAME="Button1" WIDTH=103>
|
||||
<IMG SRC="wtv-home:/ROMCache/Spacer.gif" WIDTH=4 HEIGHT=1>
|
||||
<INPUT action="wtv-setup:/accounts?"
|
||||
name="Done"
|
||||
value="Done"
|
||||
WIDTH=103
|
||||
selected
|
||||
TYPE=SUBMIT BORDERIMAGE="file://ROM/Borders/ButtonBorder2.bif" NAME="Button3" USESTYLE WIDTH=103>
|
||||
</SHADOW></FONT></FORM>
|
||||
<TD>
|
||||
</TABLE>
|
||||
</BODY>
|
||||
</HTML>
|
||||
`;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
var minisrv_service_file = true;
|
||||
|
||||
if (Object.keys(ssid_sessions[socket.ssid].listPrimaryAccountUsers()).length == 1) {
|
||||
errpage = wtvshared.doErrorPage(400, "There are no more users to remove.");
|
||||
}
|
||||
else if (ssid_sessions[socket.ssid].user_id != 0) errpage = wtvshared.doErrorPage(400, "You are not authorized to remove users from this account.");
|
||||
|
||||
var usersToRemove = [];
|
||||
Object.keys(request_headers.query).forEach(function (k) {
|
||||
if (k.substr(0, 4) === "user" && request_headers.query[k] === "on") {
|
||||
usersToRemove.push(parseInt(k.replace("user", "")));
|
||||
}
|
||||
});
|
||||
|
||||
if (usersToRemove.length === 0) errpage = wtvshared.doErrorPage(400, "No users were specified for removal.");
|
||||
|
||||
if (errpage) {
|
||||
headers = errpage[0];
|
||||
data = errpage[1];
|
||||
} else {
|
||||
if (!request_headers.query.confirm_remove) {
|
||||
var message = '';
|
||||
if (usersToRemove.length == 1) {
|
||||
var userSession = new WTVClientSessionData(minisrv_config, socket.ssid);
|
||||
userSession.switchUserID(usersToRemove[0]);
|
||||
var userName = userSession.getSessionData("subscriber_username");
|
||||
message = `Removing <b>${userName}</b> will permanently remove all of <b>${userName}</b>'s e-mail and favorites as well. You will not be able to restore <b>${userName}</b>.`;
|
||||
} else {
|
||||
message = "Removing the selected users will permanently remove their e-mail and favorites as well. You will not be able to restore the users.";
|
||||
}
|
||||
var removeurl = request_headers.request_url;
|
||||
if (removeurl.indexOf('?') >= 0) {
|
||||
removeurl = removeurl.substring(0, removeurl.indexOf('?'));
|
||||
}
|
||||
removeurl += "?";
|
||||
|
||||
Object.keys(usersToRemove).forEach(function (k) {
|
||||
removeurl += "user" + usersToRemove[k] + "=on&";
|
||||
});
|
||||
removeurl += "confirm_remove=true";
|
||||
|
||||
var confirmAlert = new clientShowAlert({
|
||||
'image': minisrv_config.config.service_logo,
|
||||
'message': message,
|
||||
'buttonlabel1': "Don't Remove",
|
||||
'buttonaction1': "client:donothing",
|
||||
'buttonlabel2': "Remove",
|
||||
'buttonaction2': removeurl,
|
||||
'noback': true,
|
||||
}).getURL();
|
||||
headers = `300 OK
|
||||
Connection: Keep-Alive
|
||||
Content-Type: text/html
|
||||
wtv-expire-all: wtv-setup:/remove-users
|
||||
wtv-expire-all: wtv-setup:/accounts
|
||||
wtv-visit: ${confirmAlert}
|
||||
Location: ${confirmAlert}`
|
||||
} else {
|
||||
Object.keys(usersToRemove).forEach(function (k) {
|
||||
ssid_sessions[socket.ssid].removeUser(usersToRemove[k]);
|
||||
})
|
||||
var num_accounts = ssid_sessions[socket.ssid].getNumberOfUserAccounts();
|
||||
var gourl = "wtv-setup:/remove-users?";
|
||||
if (num_accounts == 1) gourl = "wtv-setup:/accounts?";
|
||||
|
||||
headers = `300 OK
|
||||
Connection: Keep-Alive
|
||||
Content-Type: text/html
|
||||
wtv-expire-all: wtv-setup:/remove-users
|
||||
wtv-expire-all: wtv-setup:/accounts
|
||||
wtv-visit: ${gourl}
|
||||
Location: ${gourl}`
|
||||
}
|
||||
}
|
||||
@@ -173,13 +173,26 @@ class WTVClientSessionData {
|
||||
* @param subscriber {boolean} Returns the parent subscriber directory instead of the user's directory
|
||||
* @returns {string|boolean} Absolute path to the user's file store, or false if unregistered
|
||||
*/
|
||||
getUserStoreDirectory(subscriber = false) {
|
||||
//if (!this.isRegistered()) return false;
|
||||
getUserStoreDirectory(subscriber = false, user_id = null) {
|
||||
if (user_id == null) user_id = this.user_id;
|
||||
var userstore = this.minisrv_config.config.SessionStore + this.path.sep + this.ssid + this.path.sep;
|
||||
if (!subscriber) userstore += "user" + this.user_id + this.path.sep;
|
||||
if (!subscriber) userstore += "user" + user_id + this.path.sep;
|
||||
return userstore;
|
||||
}
|
||||
|
||||
removeUser(user_id) {
|
||||
if (!this.isRegistered()) return false; // not registered
|
||||
if (parseInt(this.user_id) !== 0) return false; // not primary account
|
||||
if (user_id === 0) return false; // cannot delete primary account in this fashion
|
||||
|
||||
var userstore = this.getUserStoreDirectory(false, user_id);
|
||||
if (this.fs.existsSync(userstore)) {
|
||||
this.fs.rmSync(userstore, { recursive: true });
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a file in the user's file store
|
||||
* @param {string} path Relative path to User's file store
|
||||
@@ -496,7 +509,7 @@ class WTVClientSessionData {
|
||||
this.session_store = {};
|
||||
}
|
||||
if (this.fs.existsSync(user_store_base)) {
|
||||
this.fs.rmdirSync(user_store_base, { recursive: true });
|
||||
this.fs.rmSync(user_store_base, { recursive: true });
|
||||
}
|
||||
return true;
|
||||
} catch (e) {
|
||||
|
||||
@@ -282,6 +282,8 @@
|
||||
<Content Include="ServiceVault\wtv-setup\phone-call-waiting.js" />
|
||||
<Content Include="ServiceVault\wtv-setup\phone-reset.js" />
|
||||
<Content Include="ServiceVault\wtv-setup\phone.js" />
|
||||
<Content Include="ServiceVault\wtv-setup\validate-remove-users.js" />
|
||||
<Content Include="ServiceVault\wtv-setup\remove-users.js" />
|
||||
<Content Include="ServiceVault\wtv-setup\reset-musicobj.js">
|
||||
<SubType>Code</SubType>
|
||||
</Content>
|
||||
|
||||
Reference in New Issue
Block a user