BREAKING CHANGES: (for SeCuRiTy):

By default:
- `ssid_sessions[socket.ssid]` is now `session_data`
- `require` is no longer allowed in user scripts

To access global `socket_sessions` and `ssid_sessions`, as well as `require` additional modules, you must set `privileged: true` for the specific service. See `config.json`.
This commit is contained in:
zefie
2022-10-09 13:26:14 -04:00
parent 2491f62b89
commit 37f1ab67ad
118 changed files with 577 additions and 530 deletions

View File

@@ -56,7 +56,7 @@ Welcome to Mail 
In Mail, you can exchange typed messages—called
<i>m-mail</i>&#151;with anyone who is on ${minisrv_config.config.service_name}, as well as anyone using other compatible MiniSrvs around the world. This is your m-mail address:
<blockquote>
<b>${ssid_sessions[socket.ssid].getSessionData("subscriber_username")}@${minisrv_config.config.service_name}</b>
<b>${session_data.getSessionData("subscriber_username")}@${minisrv_config.config.service_name}</b>
</blockquote>
Choose <b>Begin</b> to start using Mail. <!-- Or to learn more,
choose this link:

View File

@@ -11,12 +11,12 @@ if (request_headers.query.action == "editfromheader") {
}
var addresstoadd = parseAddress()
if (ssid_sessions[socket.ssid].getSessionData("address_book")) {
ssid_sessions[socket.ssid].setSessionData("address_book", ssid_sessions[socket.ssid].getSessionData("address_book") + addresstoadd);
ssid_sessions[socket.ssid].saveSessionData();
if (session_data.getSessionData("address_book")) {
session_data.setSessionData("address_book", session_data.getSessionData("address_book") + addresstoadd);
session_data.saveSessionData();
} else {
ssid_sessions[socket.ssid].setSessionData("address_book", addresstoadd);
ssid_sessions[socket.ssid].saveSessionData();
session_data.setSessionData("address_book", addresstoadd);
session_data.saveSessionData();
}
@@ -117,10 +117,10 @@ label="View saved messages">
<TABLE CELLSPACING=0 CELLPADDING=0>
<TR><TD COLSPAN=3 HEIGHT=12VALIGN=TOP ALIGN=LEFT>
<TR><TD COLSPAN=3 HEIGHT=35 VALIGN=TOP><FONT SIZE=+3 COLOR="E7CE4A"><B><SHADOW><BLACKFACE>Buddies for ${ssid_sessions[socket.ssid].getSessionData("subscriber_username") || "You"}</BLACKFACE></SHADOW></B></FONT>
<TR><TD COLSPAN=3 HEIGHT=35 VALIGN=TOP><FONT SIZE=+3 COLOR="E7CE4A"><B><SHADOW><BLACKFACE>Buddies for ${session_data.getSessionData("subscriber_username") || "You"}</BLACKFACE></SHADOW></B></FONT>
<TR><TD COLSPAN=3 HEIGHT=25 VALIGN=TOP>
<TABLE CELLSPACING=0 CELLPADDING=0>
<TD WIDTH=400>Your address is ${ssid_sessions[socket.ssid].getSessionData("messenger_email") || "unlinked"}@${ssid_sessions[socket.ssid].getSessionData("messenger_domain") || "escargot.chat"}
<TD WIDTH=400>Your address is ${session_data.getSessionData("messenger_email") || "unlinked"}@${session_data.getSessionData("messenger_domain") || "escargot.chat"}
<TD ALIGN=RIGHT>
</TABLE>
</TABLE>

View File

@@ -6,7 +6,7 @@ var messageid = request_headers.query.message_id;
var attachment_id = request_headers.query.attachment_id;
if (!attachment_id && attachment_id != 0) errpage = wtvshared.doErrorPage(400, "Attachment ID required.");
else {
var message = ssid_sessions[socket.ssid].mailstore.getMessageByID(messageid);
var message = session_data.mailstore.getMessageByID(messageid);
if (!message) errpage = wtvshared.doErrorPage(400, "Invalid Message ID");
else {
if (!message.attachments) message.attachments = []; // backwards compat

View File

@@ -5,10 +5,10 @@ var errpage = null;
var messageid = request_headers.query.message_id || null;
if (!messageid) {
// get user signature
data = ssid_sessions[socket.ssid].getSessionData("subscriber_signature");
data = session_data.getSessionData("subscriber_signature");
} else {
// get message signature
var message = ssid_sessions[socket.ssid].mailstore.getMessageByID(messageid);
var message = session_data.mailstore.getMessageByID(messageid);
if (!message) errpage = wtvshared.doErrorPage(400, "Invalid Message ID");
data = message.signature
}

View File

@@ -8,20 +8,20 @@ function mail_end_error(msg) {
data = errpage[1];
}
var intro_seen = ssid_sessions[socket.ssid].mailstore.checkMailIntroSeen();
var intro_seen = session_data.mailstore.checkMailIntroSeen();
if (!intro_seen && !request_headers.query.intro_seen) {
// user is trying to bypass the intro screen
headers = "300 OK\nLocation: wtv-mail:/DiplomaMail";
} else {
if (!intro_seen && request_headers.query.intro_seen) {
// User has come from intro
ssid_sessions[socket.ssid].mailstore.setMailIntroSeen(true);
session_data.mailstore.setMailIntroSeen(true);
}
// check if mailstore exists (returns null if guest)
mailstore_exists = ssid_sessions[socket.ssid].mailstore.mailstoreExists();
mailstore_exists = session_data.mailstore.mailstoreExists();
// create mailstore if it doesnt exist (also returns null if guest)
if (!mailstore_exists) mailstore_exists = ssid_sessions[socket.ssid].mailstore.createMailstore();
if (!mailstore_exists) mailstore_exists = session_data.mailstore.createMailstore();
if (mailstore_exists) {
// mailstore exists and user is not guest
@@ -33,29 +33,29 @@ if (!intro_seen && !request_headers.query.intro_seen) {
var page = (request_headers.query.page) ? parseInt(request_headers.query.page) : 0;
// get mailbox name
var mailbox_name = ssid_sessions[socket.ssid].mailstore.getMailboxById(parseInt(mailbox));
var mailbox_name = session_data.mailstore.getMailboxById(parseInt(mailbox));
// if false or null, then mailbox is invalid
if (!mailbox_name) {
mail_end_error("Invalid Mailbox ID");
} else {
// mailboxid is ok
if (!ssid_sessions[socket.ssid].mailstore.mailboxExists(mailbox)) {
if (!session_data.mailstore.mailboxExists(mailbox)) {
// mailbox does not yet exist, create it
var mailbox_exists = ssid_sessions[socket.ssid].mailstore.createMailbox(mailbox);
var mailbox_exists = session_data.mailstore.createMailbox(mailbox);
if (!mailbox_exists) {
// failed to create mailbox for some reason
mail_end_error();
} else {
if (mailbox === 0) {
// Just created Inbox for the first time, so create the welcome message
ssid_sessions[socket.ssid].mailstore.createWelcomeMessage();
session_data.mailstore.createWelcomeMessage();
}
}
}
var message_list = ssid_sessions[socket.ssid].mailstore.listMessages(mailbox, limit, reverse_sort, (page * limit))
var total_message_count = ssid_sessions[socket.ssid].mailstore.countMessages(mailbox);
var total_unread_message_count = ssid_sessions[socket.ssid].mailstore.countUnreadMessages(mailbox);
var message_list = session_data.mailstore.listMessages(mailbox, limit, reverse_sort, (page * limit))
var total_message_count = session_data.mailstore.countMessages(mailbox);
var total_unread_message_count = session_data.mailstore.countUnreadMessages(mailbox);
var message_list_string = null;
if (total_message_count == 0) {
@@ -69,7 +69,7 @@ if (!intro_seen && !request_headers.query.intro_seen) {
}
}
var username = ssid_sessions[socket.ssid].getSessionData("subscriber_username");
var username = session_data.getSessionData("subscriber_username");
var notImplementedAlert = new clientShowAlert({
'image': minisrv_config.config.service_logo,
'message': "This feature is not available.",
@@ -204,7 +204,7 @@ label="View saved e-mail messages">
var icon_image = null;
switch (mailbox_name) {
case "Inbox":
icon_image = ssid_sessions[socket.ssid].mailstore.getMailboxIcon();
icon_image = session_data.mailstore.getMailboxIcon();
break;
case "Sent":
icon_image = "MailboxSent.gif";

View File

@@ -8,7 +8,7 @@ function mail_end_error(msg) {
data = errpage[1];
}
var intro_seen = ssid_sessions[socket.ssid].mailstore.checkMailIntroSeen();
var intro_seen = session_data.mailstore.checkMailIntroSeen();
if (!intro_seen && !request_headers.query.intro_seen) {
// user is trying to bypass the intro screen
headers = "300 OK\nLocation: wtv-mail:/DiplomaMail";
@@ -17,11 +17,11 @@ if (!intro_seen && !request_headers.query.intro_seen) {
mail_end_error("Message ID Required");
} else {
var messageid = request_headers.query.message_id;
var message = ssid_sessions[socket.ssid].mailstore.getMessageByID(messageid);
var message = session_data.mailstore.getMessageByID(messageid);
if (!message) {
mail_end_error("Invalid Message ID");
} else {
ssid_sessions[socket.ssid].mailstore.setMessageReadStatus(messageid);
session_data.mailstore.setMessageReadStatus(messageid);
var notImplementedAlert = new clientShowAlert({
'image': minisrv_config.config.service_logo,
'message': "This feature is not available.",
@@ -31,7 +31,7 @@ if (!intro_seen && !request_headers.query.intro_seen) {
}).getURL();
if (request_headers.query.message_delete) {
ssid_sessions[socket.ssid].mailstore.deleteMessage(messageid);
session_data.mailstore.deleteMessage(messageid);
headers = `300 OK
wtv-expire: wtv-mail:/listmail
Location: wtv-mail:/listmail`;
@@ -39,7 +39,7 @@ Location: wtv-mail:/listmail`;
headers = `200 OK
Content-type: text/html`;
var message_colors = ssid_sessions[socket.ssid].mailstore.getSignatureColors(message.signature);
var message_colors = session_data.mailstore.getSignatureColors(message.signature);
if (typeof message.subject == "object" && message.subject) message.subject = wtvshared.decodeBufferText(message.subject);
data = `<wtvnoscript>

View File

@@ -2,7 +2,7 @@ var minisrv_service_file = true;
var message_snapshot_data = null;
var message_voicemail_data = null;
var intro_seen = ssid_sessions[socket.ssid].mailstore.checkMailIntroSeen();
var intro_seen = session_data.mailstore.checkMailIntroSeen();
if (!intro_seen && !request_headers.query.intro_seen) {
// user is trying to bypass the intro screen
headers = "300 OK\nLocation: wtv-mail:/DiplomaMail";
@@ -20,8 +20,8 @@ if (!intro_seen && !request_headers.query.intro_seen) {
}
if (request_headers.query.clear == "true") {
ssid_sessions[socket.ssid].deleteSessionData("mail_draft");
ssid_sessions[socket.ssid].deleteSessionData("mail_draft_attachments");
session_data.deleteSessionData("mail_draft");
session_data.deleteSessionData("mail_draft_attachments");
headers = `300 OK
wtv-expire: wtv-mail:/listmail
wtv-expire: wtv-mail:/sendmail
@@ -29,7 +29,7 @@ Location: wtv-mail:/sendmail`;
}
var newsgroup = null;
if (parseBool(request_headers.query.discuss)) {
if (wtvshared.parseBool(request_headers.query.discuss)) {
newsgroup = request_headers.query.group || request_headers.query.message_to || null;
}
@@ -48,10 +48,10 @@ Location: wtv-mail:/sendmail`;
var msg_url_title = request_headers.query.message_title || null;
var no_signature = false;
var mail_draft_data = ssid_sessions[socket.ssid].getSessionData("mail_draft");
var mail_draft_attachments = ssid_sessions[socket.ssid].getSessionData("mail_draft_attachments") || {};
var mail_draft_data = session_data.getSessionData("mail_draft");
var mail_draft_attachments = session_data.getSessionData("mail_draft_attachments") || {};
if (mail_draft_data) {
ssid_sessions[socket.ssid].deleteSessionData("mail_draft");
session_data.deleteSessionData("mail_draft");
if (mail_draft_data.to_addr) to_addr = mail_draft_data.to_addr;
if (mail_draft_data.msg_subject) msg_subject = mail_draft_data.msg_subject;
if (mail_draft_data.msg_body) msg_body = mail_draft_data.msg_body;
@@ -81,8 +81,8 @@ Content-Type: audio/wav`;
data = message_voicemail_data;
} else {
var username = ssid_sessions[socket.ssid].getSessionData("subscriber_username");
var userdisplayname = wtvshared.htmlEntitize(ssid_sessions[socket.ssid].getSessionData("subscriber_name"));
var username = session_data.getSessionData("subscriber_username");
var userdisplayname = wtvshared.htmlEntitize(session_data.getSessionData("subscriber_name"));
var address = username + "@" + minisrv_config.config.domain_name
var notImplementedAlert = new clientShowAlert({
'image': minisrv_config.config.service_logo,
@@ -94,7 +94,7 @@ Content-Type: audio/wav`;
if ((typeof request_headers.query.sendoff !== 'undefined' && request_headers.query.sendoff != false) || request_headers.query.saveoff || request_headers.query.get_snap || request_headers.query.get_gab) {
var from_addr = address;
var signature = ssid_sessions[socket.ssid].getSessionData("subscriber_signature") || null;
var signature = session_data.getSessionData("subscriber_signature") || null;
if (typeof request_headers.query.sendoff !== 'undefined' && request_headers.query.sendoff != false) {
var attachments = [];
@@ -140,7 +140,7 @@ Content-Type: audio/wav`;
'From': from_addr,
'Newsgroups': newsgroup,
'Subject': msg_subject || "(No subject)",
'Message-ID': "<"+ssid_sessions[socket.ssid].generatePassword(16) + "@" + minisrv_config.config.domain_name+">",
'Message-ID': "<"+session_data.generatePassword(16) + "@" + minisrv_config.config.domain_name+">",
'Date': strftime('%A, %d-%b-%y %k:%M:%S %z', new Date())
}
if (msg_body) {
@@ -175,14 +175,14 @@ Location: wtv-news:/news?group=${newsgroup}`;
});
}
} else {
var messagereturn = ssid_sessions[socket.ssid].mailstore.sendMessageToAddr(from_addr, to_addr, msg_body, msg_subject, userdisplayname, to_name, signature, attachments, msg_url, msg_url_title);
var messagereturn = session_data.mailstore.sendMessageToAddr(from_addr, to_addr, msg_body, msg_subject, userdisplayname, to_name, signature, attachments, msg_url, msg_url_title);
if (messagereturn !== true) {
var errpage = wtvshared.doErrorPage(400, messagereturn);
headers = errpage[0];
data = errpage[1];
} else {
ssid_sessions[socket.ssid].deleteSessionData("mail_draft");
ssid_sessions[socket.ssid].deleteSessionData("mail_draft_attachments");
session_data.deleteSessionData("mail_draft");
session_data.deleteSessionData("mail_draft_attachments");
headers = `300 OK
wtv-expire: wtv-mail:/listmail
wtv-expire: wtv-mail:/sendmail
@@ -200,7 +200,7 @@ Location: wtv-mail:/listmail`;
msg_url_title: msg_url_title,
newsgroup: newsgroup
}
ssid_sessions[socket.ssid].setSessionData("mail_draft", mail_draft_data);
session_data.setSessionData("mail_draft", mail_draft_data);
headers = `200 OK
Content-type: text/html
wtv-expire: wtv-mail:/sendmail`;
@@ -209,31 +209,31 @@ wtv-expire: wtv-mail:/sendmail`;
headers = `200 OK
Content-type: text/html`;
var mail_draft_data = ssid_sessions[socket.ssid].getSessionData("mail_draft_attachments") || {};
var mail_draft_data = session_data.getSessionData("mail_draft_attachments") || {};
if (request_headers.query.snapping == "false") {
headers += "\nwtv-expire: cache:snapshot.jpg";
if (mail_draft_data.message_snapshot_data) mail_draft_data.message_snapshot_data = null;
ssid_sessions[socket.ssid].setSessionData("mail_draft_attachments", mail_draft_data);
session_data.setSessionData("mail_draft_attachments", mail_draft_data);
}
if (request_headers.query.gabbing == "false") {
headers += "\nwtv-expire: cache:voicemail.wav";
if (mail_draft_data.message_voicemail_data) mail_draft_data.message_voicemail_data = null;
ssid_sessions[socket.ssid].setSessionData("mail_draft_attachments", mail_draft_data);
session_data.setSessionData("mail_draft_attachments", mail_draft_data);
}
if (request_headers.query.message_snapshot_data) {
mail_draft_data.message_snapshot_data = request_headers.query.message_snapshot_data
ssid_sessions[socket.ssid].setSessionData("mail_draft_attachments", mail_draft_data);
session_data.setSessionData("mail_draft_attachments", mail_draft_data);
}
if (request_headers.query.message_voicemail_data) {
mail_draft_data.message_voicemail_data = request_headers.query.message_voicemail_data
ssid_sessions[socket.ssid].setSessionData("mail_draft_attachments", mail_draft_data);
session_data.setSessionData("mail_draft_attachments", mail_draft_data);
}
var message_colors = null;
if (no_signature) message_colors = ssid_sessions[socket.ssid].mailstore.getSignatureColors(null, true);
else message_colors = ssid_sessions[socket.ssid].mailstore.getSignatureColors(ssid_sessions[socket.ssid].getSessionData("subscriber_signature"), true);
if (no_signature) message_colors = session_data.mailstore.getSignatureColors(null, true);
else message_colors = session_data.mailstore.getSignatureColors(session_data.getSessionData("subscriber_signature"), true);
data = `<HTML>
<head>
@@ -379,7 +379,7 @@ data += `
<spacer type=horizontal size=13>
<td height=80>
<img src="wtv-mail:/content/images/Mail.gif" width=87 height=45>
<img src="wtv-mail:/content/images/${ssid_sessions[socket.ssid].mailstore.getMailboxIcon()}" width=74 height=45 transparency=60>
<img src="wtv-mail:/content/images/${session_data.mailstore.getMailboxIcon()}" width=74 height=45 transparency=60>
<td width=250 align=left><font sizerange=small>
</table>
<tr>
@@ -513,8 +513,8 @@ link=${message_colors.link}
vlink=${message_colors.vlink}
vspace=0
hspace=0>`;
if (ssid_sessions[socket.ssid].getSessionData("subscriber_signature") && ssid_sessions[socket.ssid].getSessionData("subscriber_signature") != "" && !no_signature) {
data += wtvshared.sanitizeSignature(ssid_sessions[socket.ssid].getSessionData("subscriber_signature"));
if (session_data.getSessionData("subscriber_signature") && session_data.getSessionData("subscriber_signature") != "" && !no_signature) {
data += wtvshared.sanitizeSignature(session_data.getSessionData("subscriber_signature"));
}
if (msg_url) {
data += `<input type="hidden" name="message_url" value="${msg_url}">
@@ -538,7 +538,7 @@ Included Page: <a href="${msg_url}">${wtvshared.htmlEntitize(msg_url_title).repl
<table cellspacing=0 cellpadding=0 border=0>
<tr>
<td width=305 valign=top>`;
if (!ssid_sessions[socket.ssid].getSessionData("subscriber_signature") || ssid_sessions[socket.ssid].getSessionData("subscriber_signature") == "") {
if (!session_data.getSessionData("subscriber_signature") || session_data.getSessionData("subscriber_signature") == "") {
data += `<input type = hidden name = "togglesign" value = "false"> <td abswidth=13 > `;
} else if (no_signature) {
data += `<a href="javascript:Signing('true')">