...
 
Commits (8)
function xjs_compile(filename) {
if(cwd != '') {
if(typeof cwd == 'string' && cwd != '') {
if(filename.search(/^((\/)|([A-Za-z]:[\/\\]))/)==-1)
filename=cwd+filename;
}
......@@ -91,3 +91,29 @@ function xjs_compile(filename) {
}
return(ssjs_filename);
}
function xjs_eval(filename, str) {
const ssjs = xjs_compile(filename);
const f = new File(filename + '.html');
if (!f.open('w+', false)) {
log(LOG_ERR, "!ERROR " + f.error + " creating " + f.name);
return '';
}
function write(s) {
f.write(s);
}
function writeln(s) {
f.writeln(s);
}
load(ssjs);
if (str) {
f.rewind();
const ret = f.read();
f.close();
f.remove();
return ret;
} else {
f.close();
return filename + '.html';
}
}
\ No newline at end of file
<? var _bs = locale.get('button_block_sender', 'page_forum'); ?>
<button id="bsb-%s" class="btn btn-default icon" aria-label="<? write(_bs); ?>" title="<? write(_bs); ?>" onclick="blockSender('%s', '%s', '%s')">
<span class="glyphicon glyphicon-ban-circle"></span>
</button>
\ No newline at end of file
require('sbbsdefs.js', 'MSG_DELETE');
require('xjs.js', 'xjs_compile');
load(settings.web_lib + 'mime-decode.js');
function listGroups() {
......@@ -404,10 +405,25 @@ function getMailBody(number) {
ret.body = formatMessage(pt_body == body ? decoded.body : pt_body); // See above re: pt_body
ret.inlines = decoded.inlines;
ret.attachments = decoded.attachments;
if (user.is_sysop) {
ret.buttons = [
format(xjs_eval(settings.web_components + 'twit-button.xjs', true), number, number, header.from, header.from_net_addr),
];
}
return ret;
}
function addTwit(str) {
const f = new File(system.ctrl_dir + 'twitlist.cfg');
if (!f.open('a')) {
log(LOG_ERR, 'Failed to add ' + str + ' to twitlist');
return;
}
f.writeln(str);
f.close();
}
// Returns the user's signature, or an empty String
function getSignature() {
var fn = format('%s/user/%04d.sig', system.data_dir, user.number);
......
......@@ -90,6 +90,7 @@ button_thread_previous_page = Previous page
button_thread_next_page = Next page
button_thread_forward_pages = Jump %s page(s) forward
button_thread_last_page = Last page
button_block_sender = Block Sender
[sidebar_node_list]
label_title = Who's Online
......
......@@ -63,6 +63,10 @@ EN_US.prototype.group_numbers = function (n) {
).split('').reverse().join('') + (d > -1 ? n.substring(d) : '');
}
EN_US.prototype.get = function (str, sec) {
return this.strings[sec || this.section][str];
}
EN_US.prototype.write = function (str, sec) {
write(this.strings[sec || this.section][str]);
}
......
......@@ -11,33 +11,33 @@
}
?>
<?xjs function writeMessage(header) { ?>
<li id="li-<?xjs write(header.number); ?>" class="list-group-item mail striped <?xjs write(header.attr&MSG_READ ? 'read' : 'unread'); ?>">
<? function writeMessage(header) { ?>
<li id="li-<? write(header.number); ?>" class="list-group-item mail striped <? write(header.attr&MSG_READ ? 'read' : 'unread'); ?>">
<div class="row">
<div class="col-sm-1">
<div class="checkbox">
<label class="checkbox-inline">
<input id="check-<?xjs write(header.number); ?>" type="checkbox" class="mail-select">
<input id="check-<? write(header.number); ?>" type="checkbox" class="mail-select">
</label>
</div>
</div>
<div class="col-sm-11" style="cursor:pointer;" onclick="getMailBody(<?xjs write(header.number); ?>)">
<?xjs write(_mail_tab == 'sent' ? locale.strings.page_mail.label_message_to : locale.strings.page_mail.label_message_from); ?>:
<strong><?xjs write(_mail_tab == 'sent' ? header.to : header.from); ?></strong>
<?xjs if (header.from_net_type != NET_NONE) { ?>
&lt;<?xjs write(_mail_tab == 'sent' ? (header.to + '@' + header.to_net_addr) : (header.from + '@' + header.from_net_addr)); ?>&gt;
<?xjs } ?>
<?xjs write(locale.strings.page_mail.label_message_date); ?>
<?xjs write((new Date(header.when_written_time * 1000)).toLocaleString()); ?>
<div class="col-sm-11" style="cursor:pointer;" onclick="getMailBody(<? write(header.number); ?>)">
<? write(_mail_tab == 'sent' ? locale.strings.page_mail.label_message_to : locale.strings.page_mail.label_message_from); ?>:
<strong><? write(_mail_tab == 'sent' ? header.to : header.from); ?></strong>
<? if (header.from_net_type != NET_NONE) { ?>
&lt;<? write(_mail_tab == 'sent' ? (header.to + '@' + header.to_net_addr) : (header.from + '@' + header.from_net_addr)); ?>&gt;
<? } ?>
<? write(locale.strings.page_mail.label_message_date); ?>
<? write((new Date(header.when_written_time * 1000)).toLocaleString()); ?>
<p>
<?xjs write(locale.strings.page_mail.label_message_subject); ?>:
<strong><?xjs write(header.subject); ?></strong>
<? write(locale.strings.page_mail.label_message_subject); ?>:
<strong><? write(header.subject); ?></strong>
</p>
</div>
</div>
<div class="message" id="message-<?xjs write(header.number); ?>" hidden></div>
<div class="message" id="message-<? write(header.number); ?>" hidden></div>
</li>
<?xjs } ?>
<? } ?>
<?xjs
function _read_unread(tab) {
......@@ -47,8 +47,7 @@
} else {
write(_mail[tab].unread);
}
write('/' + _mail[tab].read);
write(')');
write('/' + _mail[tab].read + ')');
}
?>
......@@ -74,51 +73,51 @@
</script>
<?xjs if (typeof http_request.query.notice != "undefined") { ?>
<? if (typeof http_request.query.notice != "undefined") { ?>
<div id="noticebox" class="alert alert-warning">
<?xjs write(http_request.query.notice[0]); ?>
<? write(http_request.query.notice[0]); ?>
</div>
<script type="text/javascript">
$("#noticebox").fadeOut(3000, function () {
$("#noticebox").remove();
});
</script>
<?xjs } ?>
<? } ?>
<?xjs if (!(user.security.restrictions&UFLAG_E) && !(user.security.restrictions&UFLAG_M)) { ?>
<button class="btn btn-default icon" aria-label="<?xjs write(locale.strings.page_mail.button_post_new); ?>" title="<?xjs write(locale.strings.page_mail.button_post_new); ?>" onclick="addNew('mail')">
<? if (!(user.security.restrictions&UFLAG_E) && !(user.security.restrictions&UFLAG_M)) { ?>
<button class="btn btn-default icon" aria-label="<? write(locale.strings.page_mail.button_post_new); ?>" title="<? write(locale.strings.page_mail.button_post_new); ?>" onclick="addNew('mail')">
<span class="glyphicon glyphicon-pencil"></span>
</button>
<button class="btn btn-default icon" aria-label="<?xjs write(locale.strings.page_mail.button_select_all); ?>" title="<?xjs write(locale.strings.page_mail.button_select_all); ?>" onclick="selectAllMail()">
<button class="btn btn-default icon" aria-label="<? write(locale.strings.page_mail.button_select_all); ?>" title="<? write(locale.strings.page_mail.button_select_all); ?>" onclick="selectAllMail()">
<span class="glyphicon glyphicon-check"></span>
</button>
<button class="btn btn-default icon" aria-label="<?xjs write(locale.strings.page_mail.button_delete_selected); ?>" title="<?xjs write(locale.strings.page_mail.button_delete_selected); ?>" onclick="deleteSelectedMail()">
<button class="btn btn-default icon" aria-label="<? write(locale.strings.page_mail.button_delete_selected); ?>" title="<? write(locale.strings.page_mail.button_delete_selected); ?>" onclick="deleteSelectedMail()">
<span class="glyphicon glyphicon-trash"></span>
</button>
<?xjs } ?>
<? } ?>
<ul class="nav nav-tabs">
<li role="presentation" class="<?xjs write(_active_tab('inbox')); ?>">
<a href="./?page=<?xjs write(page); ?>&amp;tab=inbox">
<?xjs write(locale.strings.page_mail.label_tab_inbox); ?>
<?xjs _read_unread('inbox'); ?>
<li role="presentation" class="<? write(_active_tab('inbox')); ?>">
<a href="./?page=<? write(page); ?>&amp;tab=inbox">
<? write(locale.strings.page_mail.label_tab_inbox); ?>
<? _read_unread('inbox'); ?>
</a>
</li>
<li role="presentation" class="<?xjs write(_active_tab('spam')); ?>">
<a href="./?page=<?xjs write(page); ?>&amp;tab=spam">
<li role="presentation" class="<? write(_active_tab('spam')); ?>">
<a href="./?page=<? write(page); ?>&amp;tab=spam">
Spam
<?xjs _read_unread('spam'); ?>
<? _read_unread('spam'); ?>
</a>
</li>
<li role="presentation" class="<?xjs write(_active_tab('sent')); ?>">
<a href="./?page=<?xjs write(page); ?>&amp;tab=sent">
<?xjs write(locale.strings.page_mail.label_tab_sent); ?>
<?xjs _read_unread('sent'); ?>
<li role="presentation" class="<? write(_active_tab('sent')); ?>">
<a href="./?page=<? write(page); ?>&amp;tab=sent">
<? write(locale.strings.page_mail.label_tab_sent); ?>
<? _read_unread('sent'); ?>
</a>
</li>
</ul>
<br>
<ul id="forum-list-container" class="list-group">
<?xjs _mail.headers.forEach(writeMessage); ?>
<? _mail.headers.forEach(writeMessage); ?>
</ul>
......@@ -12,9 +12,7 @@ load(settings.web_lib + 'forum.js');
var reply = {};
// There must be an API call, and the user must not be a guest or unknown
if ((http_request.method === 'GET' || http_request.method === 'POST') &&
typeof http_request.query.call !== 'undefined'
) {
if (http_request.query.call !== undefined && (http_request.method === 'GET' || http_request.method === 'POST')) {
var handled = false;
......@@ -152,6 +150,14 @@ if ((http_request.method === 'GET' || http_request.method === 'POST') &&
}
break;
case 'block-sender':
if (user.is_sysop) {
if (http_request.query.from) addTwit(decodeURIComponent(http_request.query.from[0]));
if (http_request.query.from_net) addTwit(decodeURIComponent(http_request.query.from_net[0]));
reply.err = null;
}
break;
default:
handled = false;
break;
......
......@@ -352,18 +352,19 @@ function onThreadStats(data) {
/* Fetch a private mail message's body (with links to attachments) where 'id'
is the message number. Output it to an element with id 'message-<id>'. */
async function getMailBody(id) {
if (!$('#message-' + id).attr('hidden')) {
$('#message-' + id).attr('hidden', true);
} else if ($('#message-' + id).html() != '') {
$('#message-' + id).attr('hidden', false);
const tgt = `#message-${id}`;
if (!$(tgt).attr('hidden')) {
$(tgt).attr('hidden', true);
} else if ($(tgt).html() != '') {
$(tgt).attr('hidden', false);
} else {
const data = await v4_get('./api/forum.ssjs?call=get-mail-body&number=' + id);
const data = await v4_get(`./api/forum.ssjs?call=get-mail-body&number=${id}`);
var str = data.body;
if (data.inlines && data.inlines.length > 0) {
str += '<br>Inline attachments: ' + data.inlines.join('<br>') + '<br>';
str += `<br>Inline attachments: ${data.inlines.join('<br>')}<br>`;
}
if (data.attachments && data.attachments.length > 0) {
str += '<br>Attachments: ' + data.attachments.join('<br>') + '<br>';
str += `<br>Attachments: ${data.attachments.join('<br>')}<br>`;
}
str +=
'<button class="btn btn-default icon" ' +
......@@ -377,11 +378,17 @@ async function getMailBody(id) {
'title="Delete this message" onclick="deleteMessage(\'mail\',' + id + ')">' +
'<span class="glyphicon glyphicon-trash"></span>' +
'</button>';
$('#message-' + id).html(str);
$('#message-' + id).attr('hidden', false);
if (data.buttons) str += data.buttons.join('');
$(tgt).html(str);
$(tgt).attr('hidden', false);
}
}
async function blockSender(id, from, from_net) {
const data = await v4_get(`./api/forum.ssjs?call=block-sender&from=${from}&from_net=${from_net}`);
if (!data.err) $(`#bsb-${id}`).attr('disabled', true);
}
async function setScanCfg(sub, cfg) {
var opts = [ 'scan-cfg-off', 'scan-cfg-new', 'scan-cfg-youonly' ];
const data = await v4_get('./api/forum.ssjs?call=set-scan-cfg&sub=' + sub + '&cfg=' + cfg);
......