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({
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() {
function ping() {
if (time() - last_send > keepalive) {
write(': ping\n\n');
last_send = time();
}
}
}
function emit(obj) {
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')) {
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), '');
......@@ -43,10 +41,10 @@
}
});
}
}
}
ping();
while (client.socket.is_connected) {
ping();
while (client.socket.is_connected) {
Object.keys(callbacks).forEach(function (e) {
try {
callbacks[e].cycle();
......@@ -57,6 +55,4 @@
});
yield();
ping();
}
//})();
\ No newline at end of file
}
\ No newline at end of file
(function () {
const settings = load('modopts.js', 'web');
const settings = load('modopts.js', 'web');
load(settings.web_directory + '/lib/init.js');
load(settings.web_lib + 'auth.js');
require('filebase.js', 'FileBase');
load(settings.web_directory + '/lib/init.js');
load(settings.web_lib + 'auth.js');
require('filebase.js', 'FileBase');
var CHUNK_SIZE = 1024;
var CHUNK_SIZE = 1024;
var reply = {};
if ((http_request.method === 'GET' || http_request.method === 'POST') &&
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':
......@@ -50,13 +48,11 @@
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
/* 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');
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');
load(settings.web_directory + '/lib/init.js');
load(settings.web_lib + 'auth.js');
load(settings.web_lib + 'forum.js');
var reply = {};
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') &&
// 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;
......@@ -249,10 +248,9 @@
}
}
}
reply = JSON.stringify(reply);
http_reply.header['Content-Type'] = 'application/json';
http_reply.header['Content-Length'] = reply.length;
write(reply);
})();
\ 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 () {
/* Posts a notification message to a list of sub-boards when commits are made
/* Posts a notification message to a list of sub-boards when commits are made
to a GitHub repository.
- In your repository, go to Settings -> Webhooks -> Add webhook
......@@ -17,25 +16,25 @@
- Where 'secret' is the secret passphrase as configured above
- Where 'SUB' is the internal code of a sub-board to post to
- Multiple subs can be specified, separated by commas
*/
*/
load('sbbsdefs.js');
load('hmac.js');
const options = load({}, 'modopts.js', 'github_notify');
load(system.exec_dir + '../web/lib/init.js');
load('sbbsdefs.js');
load('hmac.js');
const options = load({}, 'modopts.js', 'github_notify');
load(system.exec_dir + '../web/lib/init.js');
function b2h(str) {
function b2h(str) {
return str.split('').map(function (e) {
var n = ascii(e).toString(16);
return n.length < 2 ? ('0' + n) : n;
}).join('');
}
}
function verify_signature(key, payload, hash) {
function verify_signature(key, payload, hash) {
return (b2h(hmac_sha1(key, payload)) === hash);
}
}
try {
try {
const hash = http_request.header['x-hub-signature'].split('=')[1];
const payload = JSON.parse(http_request.post_data);
if (typeof options[payload.repository.name] === 'undefined') {
......@@ -46,27 +45,27 @@
if (!verify_signature(secret, http_request.post_data, hash)) {
throw 'GitHub signature mismatch';
}
} catch (err) {
} catch (err) {
log(LOG_ERR, err);
exit();
}
}
const header = {
const header = {
from: payload.head_commit.author.username,
to: 'All',
subject: 'Changes to ' + payload.repository.full_name
};
};
const body = payload.commits.map(function (e) {
const body = payload.commits.map(function (e) {
const ret = [ 'Commit ID: ' + e.id, 'Author: ' + e.author.username ];
if (e.added.length) ret.push('Added: ' + e.added.join(', '));
if (e.removed.length) ret.push('Removed: ' + e.removed.join(', '));
if (e.modified.length) ret.push('Modified: ' + e.modified.join(', '));
ret.push('', 'Message:', e.message, '', 'Commit URL:', e.url, '');
return ret.join('\r\n');
}).concat('Repository URL: ' + payload.repository.url).join('\r\n\r\n');
}).concat('Repository URL: ' + payload.repository.url).join('\r\n\r\n');
subs.forEach(function (sub) {
subs.forEach(function (sub) {
try {
const mb = new MsgBase(sub);
if (!mb.open()) throw 'Failed to open message base ' + sub;
......@@ -75,11 +74,10 @@
} catch (err) {
log(LOG_ERR, err);
}
});
});
const _tf = new File(system.data_dir + '/github_notify');
if (_tf.open('w')) {
const _tf = new File(system.data_dir + '/github_notify');
if (_tf.open('w')) {
_tf.write(body);
_tf.close();
}
})();
\ No newline at end of file
}
(function () {
load('sbbsdefs.js');
load(system.exec_dir + '../web/lib/init.js');
load(settings.web_lib + '/auth.js');
load('sbbsdefs.js');
load(system.exec_dir + '../web/lib/init.js');
load(settings.web_lib + '/auth.js');
if (user.alias !== settings.guest) exit();
if (!settings.user_registration) exit();
if (user.alias !== settings.guest) exit();
if (!settings.user_registration) exit();
var MIN_ALIAS = 1,
var MIN_ALIAS = 1,
MIN_REALNAME = 3,
MIN_NETMAIL = 6,
MIN_LOCATION = 4,
MIN_ADDRESS = 6,
MIN_PHONE = 3;
var reply = {
var reply = {
errors : [],
userNumber : 0
};
};
var prepUser = {
var prepUser = {
alias : '',
handle : '',
name : '',
......@@ -30,29 +29,29 @@
birthdate : '',
gender : '',
password : ''
};
};
function required(mask) {
function required(mask) {
return (system.new_user_questions&mask);
}
}
function cleanParam(param) {
function cleanParam(param) {
if (paramExists(param)) {
return http_request.query[param][0].replace(/[\x00-\x19\x7F]/g, '');
}
return "";
}
}
function paramExists(param) {
function paramExists(param) {
if (typeof http_request.query[param] !== 'undefined' &&
http_request.query[param][0] !== ''
) {
return true;
}
return false;
}
}
function paramLength(param) {
function paramLength(param) {
if (typeof http_request.query[param] === 'undefined') {
return 0;
} else if (http_request.query[param][0].replace(' ', '').length < 1) {
......@@ -62,9 +61,9 @@
} else {
return http_request.query[param][0].length;
}
}
}
function newUser() {
function newUser() {
var usr = system.new_user(prepUser.alias);
if (typeof usr === 'number') {
reply.errors.push(locale.strings.api_register.error_failed);
......@@ -77,96 +76,96 @@
usr[property] = prepUser[property];
}
reply.userNumber = usr.number;
}
}
// See if the hidden form fields were filled
if (( paramExists('send-me-free-stuff') &&
// See if the hidden form fields were filled
if (( paramExists('send-me-free-stuff') &&
http_request.query['send-me-free-stuff'][0] !== ''
) ||
( paramExists('subscribe-to-newsletter') &&
http_request.query['subscribe-to-newsletter'][0] !== ''
)
) {
) {
log(LOG_WARNING, locale.strings.api_register.log_bot_attempt);
exit();
}
}
if (system.newuser_password !== '' &&
if (system.newuser_password !== '' &&
( typeof http_request.query['newuser-password'] === 'undefined' ||
http_request.query['newuser-password'][0] != system.newuser_password
)
) {
) {
reply.errors.push(locale.strings.api_register.error_bad_syspass);
}
}
// More could be done to respect certain newuser question toggles
// (UQ_DUPREAL, UQ_NOUPPRLWR, UQ_NOCOMMAS), but I don't care right now.
// More could be done to respect certain newuser question toggles
// (UQ_DUPREAL, UQ_NOUPPRLWR, UQ_NOCOMMAS), but I don't care right now.
if (!paramExists('alias') ||
if (!paramExists('alias') ||
paramLength('alias') < MIN_ALIAS ||
paramLength('alias') > LEN_ALIAS
) {
) {
reply.errors.push(locale.strings.api_register.error_invalid_alias);
} else if (system.matchuser(http_request.query.alias[0]) > 0) {
} else if (system.matchuser(http_request.query.alias[0]) > 0) {
reply.errors.push(locale.strings.api_register.error_alias_taken);
} else {
} else {
prepUser.alias = cleanParam('alias');
prepUser.handle = cleanParam('alias');
}
}
if ((!paramExists('password1') || !paramExists('password2')) ||
if ((!paramExists('password1') || !paramExists('password2')) ||
http_request.query.password1[0] !== http_request.query.password2[0]
) {
) {
reply.errors.push(locale.strings.api_register.error_password_mismatch);
} else if (
} else if (
paramLength('password1') < settings.minimum_password_length ||
paramLength('password1') > LEN_PASS
) {
) {
reply.errors.push(
format(
locale.strings.api_register.error_password_length,
settings.minimum_password_length, LEN_PASS
)
);
} else {
} else {
prepUser.password = cleanParam('password1');
}
}
if (!paramExists('netmail') && !required(UQ_NONETMAIL)) {
if (!paramExists('netmail') && !required(UQ_NONETMAIL)) {
reply.errors.push(locale.strings.api_register.error_email_required);
} else if (
} else if (
( paramLength('netmail') < MIN_NETMAIL ||
paramLength('netmail') > LEN_NETMAIL
) && !required(UQ_NONETMAIL)
) {
) {
reply.errors.push(locale.strings.api_register.error_invalid_email);
} else {
} else {
prepUser.netmail = cleanParam('netmail');
}
}
if (required(UQ_REALNAME) &&
if (required(UQ_REALNAME) &&
( !paramExists('realname') ||
paramLength('realname') < MIN_REALNAME ||
paramLength('realname') > LEN_NAME
)
) {
) {
reply.errors.push(locale.strings.api_register.error_invalid_name);
} else {
} else {
prepUser.name = cleanParam('realname');
}
}
if (required(UQ_LOCATION) &&
if (required(UQ_LOCATION) &&
( !paramExists('location') ||
paramLength('location') < MIN_LOCATION ||
paramLength('location') > LEN_LOCATION
)
) {
) {
reply.errors.push(locale.strings.api_register.error_invalid_location);
} else {
} else {
prepUser.location = cleanParam('location');
}
}
if (required(UQ_ADDRESS) &&
if (required(UQ_ADDRESS) &&
( !paramExists('address') ||
paramLength('address') < MIN_ADDRESS ||
paramLength('address') > LEN_ADDRESS ||
......@@ -174,48 +173,47 @@
paramLength('zipcode') < 3 ||
paramLength('zipcode') > LEN_ADDRESS
)
) {
) {
reply.errors.push(locale.strings.api_register.error_invalid_street_address);
} else {
} else {
prepUser.address = cleanParam('address');
prepUser.zipcode = cleanParam('zipcode');
}
}
if (required(UQ_PHONE) &&
if (required(UQ_PHONE) &&
( !paramExists('phone') ||
paramLength('phone') < MIN_PHONE ||
paramLength('phone') > LEN_PHONE
)
) {
) {
reply.errors.push(locale.strings.api_register.error_invalid_phone);
} else {
} else {
prepUser.phone = cleanParam('phone');
}
}
if (required(UQ_SEX) &&
if (required(UQ_SEX) &&
( !paramExists('gender') ||
paramLength('gender') != 1 ||
['X','M','F','O'].indexOf(http_request.query.gender[0]) < 0
)
) {
) {
reply.errors.push(locale.strings.api_register.error_invalid_gender);
} else {
} else {
prepUser.gender = http_request.query.gender[0];
}
}
if (paramExists('birth') &&
if (paramExists('birth') &&
http_request.query.birth[0].match(/^\d\d\/\d\d\/\d\d$/) !== null
) {
) {
// Should really test for valid date (and date format per system config)
prepUser.birthdate = cleanParam('birth');
} else if (required(UQ_BIRTH)) {
} else if (required(UQ_BIRTH)) {
reply.errors.push(locale.strings.api_register.error_invalid_birthdate);
}
}
if (reply.errors.length < 1) newUser();
if (reply.errors.length < 1) newUser();
reply = JSON.stringify(reply);
http_reply.header['Content-Type'] = 'application/json';
http_reply.header['Content-Length'] = reply.length;
write(reply);
})();
\ 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 () {
load("sbbsdefs.js");
load("nodedefs.js");
const settings = load('modopts.js', 'web');
load(settings.web_directory + '/lib/init.js');
load(settings.web_lib + 'auth.js');
const sbbsimsg = load({}, "sbbsimsg_lib.js");
var reply = {};
load("sbbsdefs.js");
load("nodedefs.js");
const settings = load('modopts.js', 'web');
load(settings.web_directory + '/lib/init.js');
load(settings.web_lib + 'auth.js');
const sbbsimsg = load({}, "sbbsimsg_lib.js");
if (user.number > 0 && user.alias != settings.guest
var reply = {};
if (user.number > 0 && user.alias != settings.guest
&& typeof http_request.query.call != 'undefined'
&& http_request.query.call[0] == 'send_telegram'
&& typeof http_request.query.host != 'undefined'
&& typeof http_request.query.username != 'undefined'
&& typeof http_request.query.message != 'undefined'
) {
) {
sbbsimsg.send_msg(
http_request.query.username[0] + '@' + http_request.query.host[0],
http_request.query.message[0],
user.alias
);