Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 11c07c02 authored by echicken's avatar echicken 🐔

Remove closures. They shouldn't be necessary, and anyway while

they solve the unexpected redeclaration errors, other unexpected
scope problems persist.
parent 4cf07e5d
(function () {
const settings = load('modopts.js', 'web');
var settings = load('modopts.js', 'web');
load(settings.web_directory + '/lib/init.js');
load(settings.web_lib + 'auth.js');
load(settings.web_directory + '/lib/init.js');
load(settings.web_lib + 'auth.js');
var response = JSON.stringify({
authenticated: (user.alias !== settings.guest)
});
var response = JSON.stringify({
authenticated: (user.alias !== settings.guest)
});
http_reply.header['Content-Type'] = 'application/json';
http_reply.header['Content-Length'] = response.length;
http_reply.header['Content-Type'] = 'application/json';
http_reply.header['Content-Length'] = response.length;
write(response);
})();
\ No newline at end of file
write(response);
//(function () {
load('sbbsdefs.js');
const settings = load('modopts.js', 'web');
load(settings.web_directory + '/lib/init.js');
load(settings.web_lib + 'auth.js');
load(settings.web_lib + 'request.js');
load('sbbsdefs.js');
const settings = load('modopts.js', 'web');
load(settings.web_directory + '/lib/init.js');
load(settings.web_lib + 'auth.js');
load(settings.web_lib + 'request.js');
js.time_limit = 0;
js.time_limit = 0;
http_reply.header['Cache-Control'] = 'no-cache';
http_reply.header['Content-type'] = 'text/event-stream';
http_reply.header['X-Accel-Buffering'] = 'no'; // probably not needed by everyone (nginx)
http_reply.header['Cache-Control'] = 'no-cache';
http_reply.header['Content-type'] = 'text/event-stream';
http_reply.header['X-Accel-Buffering'] = 'no'; // probably not needed by everyone (nginx)
const keepalive = 15;
var last_send = 0;
const keepalive = 15;
var last_send = 0;
function ping() {
if (time() - last_send > keepalive) {
write(': ping\n\n');
last_send = time();
}
}
function emit(obj) {
Object.keys(obj).forEach(function (e) {
write(e + ': ' + (typeof obj[e] == 'object' ? JSON.stringify(obj[e]) : obj[e]) + '\n');
});
write('\n');
function ping() {
if (time() - last_send > keepalive) {
write(': ping\n\n');
last_send = time();
}
const callbacks = {};
if (file_isdir(settings.web_lib + 'events')) {
if (Array.isArray(http_request.query.subscribe)) {
http_request.query.subscribe.forEach(function (e) {
const base = file_getname(e).replace(file_getext(e), '');
const script = settings.web_lib + 'events/' + base + '.js';
try {
if (file_exists(script)) callbacks[e] = load({}, script);
} catch (err) {
log(LOG_ERR, 'Failed to load event module ' + e + ': ' + err);
}
});
}
}
ping();
while (client.socket.is_connected) {
Object.keys(callbacks).forEach(function (e) {
}
function emit(obj) {
Object.keys(obj).forEach(function (e) {
write(e + ': ' + (typeof obj[e] == 'object' ? JSON.stringify(obj[e]) : obj[e]) + '\n');
});
write('\n');
last_send = time();
}
const callbacks = {};
if (file_isdir(settings.web_lib + 'events')) {
if (Array.isArray(http_request.query.subscribe)) {
http_request.query.subscribe.forEach(function (e) {
const base = file_getname(e).replace(file_getext(e), '');
const script = settings.web_lib + 'events/' + base + '.js';
try {
callbacks[e].cycle();
if (file_exists(script)) callbacks[e] = load({}, script);
} catch (err) {
log(LOG_ERR, 'Callback ' + e + ' failed: ' + err);
delete callbacks[e];
log(LOG_ERR, 'Failed to load event module ' + e + ': ' + err);
}
});
yield();
ping();
}
//})();
\ No newline at end of file
}
ping();
while (client.socket.is_connected) {
Object.keys(callbacks).forEach(function (e) {
try {
callbacks[e].cycle();
} catch (err) {
log(LOG_ERR, 'Callback ' + e + ' failed: ' + err);
delete callbacks[e];
}
});
yield();
ping();
}
\ No newline at end of file
(function () {
const settings = load('modopts.js', 'web');
load(settings.web_directory + '/lib/init.js');
load(settings.web_lib + 'auth.js');
require('filebase.js', 'FileBase');
var CHUNK_SIZE = 1024;
var reply = {};
if ((http_request.method === 'GET' || http_request.method === 'POST') &&
typeof http_request.query.call !== 'undefined' && user.number > 0
) {
switch (http_request.query.call[0].toLowerCase()) {
case 'download-file':
if (typeof http_request.query.dir !== 'undefined' &&
typeof file_area.dir[http_request.query.dir[0]] !== 'undefined' &&
file_area.dir[http_request.query.dir[0]].can_download &&
typeof http_request.query.file !== 'undefined'
) {
var fileBase = new FileBase(file_area.dir[http_request.query.dir[0]].code);
var file = null;
fileBase.some(function (e) {
if (e.base.toLowerCase() + '.' + e.ext.toLowerCase() !== http_request.query.file[0].toLowerCase()) {
return false;
} else if (typeof e.path !== 'undefined') {
file = e;
return true;
}
});
if (file === null) break;
http_reply.header['Content-Type'] = 'application/octet-stream';
http_reply.header['Content-Disposition'] = 'attachment; filename="' + file.base + '.' + file.ext + '"';
http_reply.header['Content-Encoding'] = 'binary';
http_reply.header['Content-Length'] = file_size(file.path);
var f = new File(file.path);
f.open('rb');
for (var n = 0; n < f.length; n += CHUNK_SIZE) {
var r = f.length - f.position;
write(f.read(r > CHUNK_SIZE ? CHUNK_SIZE : r));
yield(false);
const settings = load('modopts.js', 'web');
load(settings.web_directory + '/lib/init.js');
load(settings.web_lib + 'auth.js');
require('filebase.js', 'FileBase');
var CHUNK_SIZE = 1024;
var reply = {};
if ((http_request.method === 'GET' || http_request.method === 'POST') &&
typeof http_request.query.call !== 'undefined' && user.number > 0
) {
switch (http_request.query.call[0].toLowerCase()) {
case 'download-file':
if (typeof http_request.query.dir !== 'undefined' &&
typeof file_area.dir[http_request.query.dir[0]] !== 'undefined' &&
file_area.dir[http_request.query.dir[0]].can_download &&
typeof http_request.query.file !== 'undefined'
) {
var fileBase = new FileBase(file_area.dir[http_request.query.dir[0]].code);
var file = null;
fileBase.some(function (e) {
if (e.base.toLowerCase() + '.' + e.ext.toLowerCase() !== http_request.query.file[0].toLowerCase()) {
return false;
} else if (typeof e.path !== 'undefined') {
file = e;
return true;
}
f.close();
reply = false;
});
if (file === null) break;
http_reply.header['Content-Type'] = 'application/octet-stream';
http_reply.header['Content-Disposition'] = 'attachment; filename="' + file.base + '.' + file.ext + '"';
http_reply.header['Content-Encoding'] = 'binary';
http_reply.header['Content-Length'] = file_size(file.path);
var f = new File(file.path);
f.open('rb');
for (var n = 0; n < f.length; n += CHUNK_SIZE) {
var r = f.length - f.position;
write(f.read(r > CHUNK_SIZE ? CHUNK_SIZE : r));
yield(false);
}
break;
default:
break;
}
f.close();
reply = false;
}
break;
default:
break;
}
if (!reply) exit();
}
reply = JSON.stringify(reply);
http_reply.header['Content-Type'] = 'application/json';
http_reply.header['Content-Length'] = reply.length;
write(reply);
if (!reply) exit();
})();
\ No newline at end of file
reply = JSON.stringify(reply);
http_reply.header['Content-Type'] = 'application/json';
http_reply.header['Content-Length'] = reply.length;
write(reply);
(function () {
/* This script is an interface between HTTP clients and the functions defined
in web/lib/forum.js. A basic check for an authenticated, non-guest user
is done here; otherwise all permission checking is done at the function
level. */
/* This script is an interface between HTTP clients and the functions defined
in web/lib/forum.js. A basic check for an authenticated, non-guest user
is done here; otherwise all permission checking is done at the function
level. */
const settings = load('modopts.js', 'web');
load(settings.web_directory + '/lib/init.js');
load(settings.web_lib + 'auth.js');
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'
) {
var handled = false;
// Authenticated calls
if (user.number > 0 && user.alias !== settings.guest) {
handled = true;
switch(http_request.query.call[0].toLowerCase()) {
case 'get-mail-unread-count':
reply.count = user.stats.mail_waiting;
break;
case 'get-mail-body':
if (typeof http_request.query.number !== 'undefined') {
reply = getMailBody(http_request.query.number[0]);
}
break;
case 'get-signature':
reply.signature = getSignature();
break;
case 'post-reply':
if (typeof http_request.query.sub !== 'undefined' &&
typeof http_request.query.body !== 'undefined' &&
typeof http_request.query.pid !== 'undefined'
) {
reply.success = postReply(
http_request.query.sub[0],
http_request.query.body[0],
Number(http_request.query.pid[0])
);
} else {
reply.success = false;
}
break;
case 'post':
if (typeof http_request.query.sub !== 'undefined' &&
typeof http_request.query.to !== 'undefined' &&
typeof http_request.query.subject !== 'undefined' &&
typeof http_request.query.body !== 'undefined'
) {
reply.success = postNew(
http_request.query.sub[0],
http_request.query.to[0],
http_request.query.subject[0],
http_request.query.body[0]
);
} else {
reply.success = false;
}
break;
case 'delete-message':
if (typeof http_request.query.sub !== 'undefined' &&
typeof http_request.query.number !== 'undefined'
) {
reply.success = deleteMessage(
http_request.query.sub[0],
http_request.query.number[0]
);
} else {
reply.success = false;
}
break;
case 'delete-mail':
if (typeof http_request.query.number !== 'undefined') {
reply.success = deleteMail(http_request.query.number);
} else {
reply.success = false;
}
break;
case 'set-scan-cfg':
if (typeof http_request.query.sub !== 'undefined' &&
typeof http_request.query.cfg !== 'undefined'
) {
reply.success = setScanCfg(
http_request.query.sub[0],
http_request.query.cfg[0]
);
} else {
reply.success = false;
}
break;
case 'vote':
if (typeof http_request.query.sub !== 'undefined' &&
typeof http_request.query.id !== 'undefined' &&
typeof http_request.query.up !== 'undefined' &&
!(user.security.restrictions&UFLAG_V)
) {
reply.success = voteMessage(
http_request.query.sub[0],
http_request.query.id[0],
http_request.query.up[0]
);
} else {
reply.success = false;
}
break;
case 'submit-poll-answers':
if (typeof http_request.query.sub !== 'undefined' &&
typeof http_request.query.id !== 'undefined' &&
typeof http_request.query.answer !== 'undefined'
) {
reply.success = submitPollAnswers(
http_request.query.sub[0],
http_request.query.id[0],
http_request.query.answer
);
}
break;
case 'submit-poll':
if (typeof http_request.query.subject !== 'undefined' &&
typeof http_request.query.sub !== 'undefined' &&
typeof http_request.query.votes !== 'undefined' &&
typeof http_request.query.results !== 'undefined' &&
typeof http_request.query.answer !== 'undefined'
) {
reply.success = postPoll(
http_request.query.sub[0],
http_request.query.subject[0],
http_request.query.votes[0],
http_request.query.results[0],
http_request.query.answer,
http_request.query.comment || []
);
}
break;
default:
handled = false;
break;
const settings = load('modopts.js', 'web');
load(settings.web_directory + '/lib/init.js');
load(settings.web_lib + 'auth.js');
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'
) {
var handled = false;
// Authenticated calls
if (user.number > 0 && user.alias !== settings.guest) {
handled = true;
switch(http_request.query.call[0].toLowerCase()) {
case 'get-mail-unread-count':
reply.count = user.stats.mail_waiting;
break;
}
case 'get-mail-body':
if (typeof http_request.query.number !== 'undefined') {
reply = getMailBody(http_request.query.number[0]);
}
break;
case 'get-signature':
reply.signature = getSignature();
break;
case 'post-reply':
if (typeof http_request.query.sub !== 'undefined' &&
typeof http_request.query.body !== 'undefined' &&
typeof http_request.query.pid !== 'undefined'
) {
reply.success = postReply(
http_request.query.sub[0],
http_request.query.body[0],
Number(http_request.query.pid[0])
);
} else {
reply.success = false;
}
break;
case 'post':
if (typeof http_request.query.sub !== 'undefined' &&
typeof http_request.query.to !== 'undefined' &&
typeof http_request.query.subject !== 'undefined' &&
typeof http_request.query.body !== 'undefined'
) {
reply.success = postNew(
http_request.query.sub[0],
http_request.query.to[0],
http_request.query.subject[0],
http_request.query.body[0]
);
} else {
reply.success = false;
}
break;
}
case 'delete-message':
if (typeof http_request.query.sub !== 'undefined' &&
typeof http_request.query.number !== 'undefined'
) {
reply.success = deleteMessage(
http_request.query.sub[0],
http_request.query.number[0]
);
} else {
reply.success = false;
}
break;
// Unauthenticated calls
if (!handled) {
case 'delete-mail':
if (typeof http_request.query.number !== 'undefined') {
reply.success = deleteMail(http_request.query.number);
} else {
reply.success = false;
}
break;
switch(http_request.query.call[0].toLowerCase()) {
case 'set-scan-cfg':
if (typeof http_request.query.sub !== 'undefined' &&
typeof http_request.query.cfg !== 'undefined'
) {
reply.success = setScanCfg(
http_request.query.sub[0],
http_request.query.cfg[0]
);
} else {
reply.success = false;
}
break;
case 'vote':
if (typeof http_request.query.sub !== 'undefined' &&
typeof http_request.query.id !== 'undefined' &&
typeof http_request.query.up !== 'undefined' &&
!(user.security.restrictions&UFLAG_V)
) {
reply.success = voteMessage(
http_request.query.sub[0],
http_request.query.id[0],
http_request.query.up[0]
);
} else {
reply.success = false;
}
break;
case 'submit-poll-answers':
if (typeof http_request.query.sub !== 'undefined' &&
typeof http_request.query.id !== 'undefined' &&
typeof http_request.query.answer !== 'undefined'
) {
reply.success = submitPollAnswers(
case 'get-thread-votes':
if (typeof http_request.query.sub !== 'undefined' &&
typeof http_request.query.id !== 'undefined'
) {
var id = parseInt(http_request.query.id[0]);
if (!isNaN(id)) {
reply = getVotesInThread(
http_request.query.sub[0],
http_request.query.id[0],
http_request.query.answer
id
);
}
break;
case 'submit-poll':
if (typeof http_request.query.subject !== 'undefined' &&
typeof http_request.query.sub !== 'undefined' &&
typeof http_request.query.votes !== 'undefined' &&
typeof http_request.query.results !== 'undefined' &&
typeof http_request.query.answer !== 'undefined'
) {
reply.success = postPoll(
http_request.query.sub[0],
http_request.query.subject[0],
http_request.query.votes[0],
http_request.query.results[0],
http_request.query.answer,
http_request.query.comment || []
);
}
break;
case 'get-sub-votes':
if (typeof http_request.query.sub !== 'undefined') {
reply = getVotesInThreads(http_request.query.sub[0]);
}
break;
case 'get-poll-results':
if (typeof http_request.query.sub !== 'undefined' &&
typeof http_request.query.id !== 'undefined'
) {
reply = getUserPollData(
http_request.query.sub[0],
http_request.query.id[0]
);
}
break;