diff --git a/web/root/api/attachments.ssjs b/web/root/api/attachments.ssjs index 4d8f4eb0ca3bfde1b45041094aa2e6ecbf143c81..51cf998ab89f9d7cdc254c4050df77189604c388 100644 --- a/web/root/api/attachments.ssjs +++ b/web/root/api/attachments.ssjs @@ -1,58 +1,59 @@ -load(system.exec_dir + "../web/lib/init.js"); -load(settings.web_lib + "auth.js"); -load(settings.web_lib + "mime-decode.js"); +load(system.exec_dir + '../web/lib/init.js'); +load(settings.web_lib + 'auth.js'); +load(settings.web_lib + 'mime-decode.js'); -var barfOut = function(err) { +function barfOut(err) { log(err); exit(); } -if( typeof http_request.query.sub == "undefined" - || - ( http_request.query.sub[0] != 'mail' - && - typeof msg_area.sub[http_request.query.sub[0]] == "undefined" +if (typeof http_request.query.sub === 'undefined' || + ( http_request.query.sub[0] !== 'mail' && + typeof msg_area.sub[http_request.query.sub[0]] === 'undefined' ) ) { - barfOut("Invalid sub."); + barfOut('Invalid sub.'); } var sub = http_request.query.sub[0]; -if(typeof http_request.query.msg == "undefined") - barfOut("No message number provided."); +if (typeof http_request.query.msg === 'undefined') { + barfOut('No message number provided.'); +} + var id = parseInt(http_request.query.msg[0]); -if(typeof http_request.query.cid != "undefined") +if (typeof http_request.query.cid !== 'undefined') { var cid = http_request.query.cid[0]; -else if(typeof http_request.query.filename != "undefined") +} else if (typeof http_request.query.filename !== 'undefined') { var filename = http_request.query.filename[0]; -else - barfOut("No attachment specified."); +} else { + barfOut('No attachment specified.'); +} var msgBase = new MsgBase(sub); -if(!msgBase.open()) - barfOut("Unable to open MsgBase " + sub); +if (!msgBase.open()) barfOut('Unable to open MsgBase ' + sub); var header = msgBase.get_msg_header(false, id); -if(header === null) - barfOut("No such message."); -if(typeof msgBase.cfg == "undefined" && header.to_ext != user.number) - barfOut("Not your message."); +if (header === null) barfOut('No such message.'); +if (typeof msgBase.cfg === 'undefined' && header.to_ext != user.number) { + barfOut('Not your message.'); +} var body = msgBase.get_msg_body(false, id, header); -if(body === null) - barfOut("Cannot read message body!"); +if (body === null) barfOut('Cannot read message body!'); msgBase.close(); -if(typeof cid != "undefined") +if (typeof cid !== 'undefined') { var att = mime_get_cid_attach(header, body, cid); -else if(typeof filename != "undefined") +} else if (typeof filename !== 'undefined') { var att = mime_get_attach(header, body, filename); +} -if(typeof att != "undefined") { - if(typeof att.content_type != "undefined") - http_reply.header["Content-Type"] = att.content_type; - http_reply.header["Content-Length"] = att.body.length; +if (typeof att != 'undefined') { + if (typeof att.content_type !== 'undefined') { + http_reply.header['Content-Type'] = att.content_type; + } + http_reply.header['Content-Length'] = att.body.length; write(att.body); } \ No newline at end of file diff --git a/web/root/api/auth.ssjs b/web/root/api/auth.ssjs index 7ca3eab841137da57ac2e535254eccbd441783af..7919e8ac921200eda922bb5a2aae7dd4a99ea112 100644 --- a/web/root/api/auth.ssjs +++ b/web/root/api/auth.ssjs @@ -2,10 +2,10 @@ load(system.exec_dir + '../web/lib/init.js'); load(settings.web_lib + 'auth.js'); var response = JSON.stringify( - { 'authenticated' : (user.alias !== settings.guest) } + { 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); diff --git a/web/root/api/files.ssjs b/web/root/api/files.ssjs index 7e3125a215fa2b089f32e9c5ec53282896714ce8..f2c37f14139184425db6fe4bce6de09e18134f0b 100644 --- a/web/root/api/files.ssjs +++ b/web/root/api/files.ssjs @@ -5,7 +5,7 @@ load('filedir.js'); var reply = {}; -if ((http_request.method === "GET" || http_request.method === "POST") && +if ((http_request.method === 'GET' || http_request.method === 'POST') && typeof http_request.query.call !== 'undefined' && user.number > 0 && user.alias !== settings.guest diff --git a/web/root/api/register.ssjs b/web/root/api/register.ssjs index 1d8073f6f4cbcd8d342034eeaf6cf0d05f34b3e1..992c4d587d195042c9a8e4c05e91af061e58ddec 100644 --- a/web/root/api/register.ssjs +++ b/web/root/api/register.ssjs @@ -1,12 +1,9 @@ load('sbbsdefs.js'); -load(system.exec_dir + "../web/lib/init.js"); -load(settings.web_lib + "/auth.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, MIN_REALNAME = 3, @@ -17,164 +14,199 @@ var MIN_ALIAS = 1, var reply = { - 'errors' : [], - 'userNumber' : 0 + errors : [], + userNumber : 0 }; var prepUser = { - 'alias' : "", - 'handle' : "", - 'realname' : "", - 'netmail' : "", - 'address' : "", - 'location' : "", - 'phone' : "", - 'birthdate' : "", - 'gender' : "", - 'password' : "" + alias : '', + handle : '', + realname : '', + netmail : '', + address : '', + location : '', + phone : '', + birthdate : '', + gender : '', + password : '' }; -var required = function(mask) { +function required(mask) { return (system.new_user_questions&mask); } -var cleanParam = function(param) { - if(paramExists(param)) - return http_request.query[param][0].replace(/[^\x20-\x7E]/g, ""); +function cleanParam(param) { + if (paramExists(param)) { + return http_request.query[param][0].replace(/[^\x20-\x7E]/g, ''); + } return ""; } -var paramExists = function(param) { - if( typeof http_request.query[param] != "undefined" - && - http_request.query[param][0] != "" +function paramExists(param) { + if (typeof http_request.query[param] !== 'undefined' && + http_request.query[param][0] !== '' ) { return true; } return false; } -var paramLength = function(param) { - if(typeof http_request.query[param] == "undefined") +function paramLength(param) { + if (typeof http_request.query[param] === 'undefined') { return 0; - else if(http_request.query[param][0].replace(" ", "").length < 1) + } else if (http_request.query[param][0].replace(' ', '').length < 1) { return 0; - else if(cleanParam(param).length < 1) + } else if (cleanParam(param).length < 1) { return 0; - else + } else { return http_request.query[param][0].length; + } } -var newUser = function() { +function newUser() { var usr = system.new_user(prepUser.alias); - if(typeof usr == "number") { - reply.errors.push("Failed to create user record."); + if (typeof usr === 'number') { + reply.errors.push('Failed to create user record.'); return; } - log("User #" + usr.number + " registered via HTTP."); + log('User #' + usr.number + ' registered via HTTP.'); usr.security.password = prepUser.password; - for(var property in prepUser) { - if(property == "alias" || property == "password") - continue; + for (var property in prepUser) { + if (property === 'alias' || property === 'password') continue; usr[property] = prepUser[property]; } reply.userNumber = usr.number; } // 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] != "" +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("Hidden registration form input element filled. Likely a bot. Cancelling user registration."); + log('Hidden registration form input element filled. ' + + 'Likely a bot. Cancelling user registration.' + ); exit(); } -if( system.newuser_password != "" - && - ( typeof http_request.query["newuser-password"] == "undefined" - || - http_request.query["newuser-password"][0] != 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("Incorrect registration password."); + reply.errors.push('Incorrect registration password.'); } // 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") || paramLength("alias") < MIN_ALIAS || paramLength("alias") > LEN_ALIAS) { - reply.errors.push("Valid username is required."); -} else if(system.matchuser(http_request.query.alias[0]) > 0) { - reply.errors.push("Username already taken."); +if (!paramExists('alias') || + paramLength('alias') < MIN_ALIAS || + paramLength('alias') > LEN_ALIAS +) { + reply.errors.push('Valid username is required.'); +} else if (system.matchuser(http_request.query.alias[0]) > 0) { + reply.errors.push('Username already taken.'); +} else { + prepUser.alias = cleanParam('alias'); + prepUser.handle = cleanParam('alias'); +} + +if ((!paramExists('password1') || !paramExists('password2')) || + http_request.query.password1[0] !== http_request.query.password2[0] +) { + reply.errors.push('Password & confirmation are required, and must match.'); +} else if ( + paramLength('password1') < settings.minimum_password_length || + paramLength('password1') > LEN_PASS +) { + reply.errors.push( + 'Password must be between ' + + settings.minimum_password_length + ' and ' + LEN_PASS + ' in length.' + ); +} else { + prepUser.password = cleanParam('password1'); +} + +if (!paramExists('netmail') && !required(UQ_NONETMAIL)) { + reply.errors.push('Email address is required.'); +} else if ( + ( paramLength('netmail') < MIN_NETMAIL || + paramLength('netmail') > LEN_NETMAIL + ) && !required(UQ_NONETMAIL) +) { + reply.errors.push('Invalid email address.'); +} else { + prepUser.netmail = cleanParam('netmail'); +} + +if (required(UQ_REALNAME) && + ( !paramExists('realname') || + paramLength('realname') < MIN_REALNAME || + paramLength('realname') > LEN_NAME + ) +) { + reply.errors.push('Valid real name is required.'); +} else { + prepUser.realname = cleanParam('realname'); +} + +if (required(UQ_LOCATION) && + ( !paramExists('location') || + paramLength('location') < MIN_LOCATION || + paramLength('location') > LEN_LOCATION + ) +) { + reply.errors.push('Valid location is required.'); } else { - prepUser.alias = cleanParam("alias"); - prepUser.handle = cleanParam("alias"); + prepUser.location = cleanParam('location'); } -if( (!paramExists("password1") || !paramExists("password2")) - || - http_request.query.password1[0] != http_request.query.password2[0] +if (required(UQ_ADDRESS) && + ( !paramExists('address') || + paramLength('address') < MIN_ADDRESS || + paramLength('address') > LEN_ADDRESS + ) ) { - reply.errors.push("Password & confirmation are required, and must match."); -} else if(paramLength("password1") < settings.minimum_password_length || paramLength("password1") > LEN_PASS) { - reply.errors.push("Password must be between " + settings.minimum_password_length + " and " + LEN_PASS + " in length."); + reply.errors.push('Valid street address is required.'); } else { - prepUser.password = cleanParam("password1"); -} - -if(!paramExists("netmail") && !required(UQ_NONETMAIL)) - reply.errors.push("Email address is required."); -else if((paramLength("netmail") < MIN_NETMAIL || paramLength("netmail") > LEN_NETMAIL) && !required(UQ_NONETMAIL)) - reply.errors.push("Invalid email address."); -else - prepUser.netmail = cleanParam("netmail"); - -if(required(UQ_REALNAME) && (!paramExists("realname") || paramLength("realname") < MIN_REALNAME || paramLength("realname") > LEN_NAME)) - reply.errors.push("Valid real name is required."); -else - prepUser.realname = cleanParam("realname"); - -if(required(UQ_LOCATION) && (!paramExists("location") || paramLength("location") < MIN_LOCATION || paramLength("location") > LEN_LOCATION)) - reply.errors.push("Valid location is required."); -else - prepUser.location = cleanParam("location"); - -if(required(UQ_ADDRESS) && (!paramExists("address") || paramLength("address") < MIN_ADDRESS || paramLength("address") > LEN_ADDRESS)) - reply.errors.push("Valid street address is required."); -else - prepUser.address = cleanParam("address"); - -if(required(UQ_PHONE) && (!paramExists("phone") || paramLength("phone") < MIN_PHONE || paramLength("phone") > LEN_PHONE)) - reply.errors.push("Valid phone number is required."); -else - prepUser.phone = cleanParam("phone"); - -if(required(UQ_SEX) && (!paramExists("gender") || paramLength("gender") != 1)) - reply.errors.push("Sex is required. Heh heh."); -else - prepUser.gender = cleanParam("gender"); - -if( paramExists("birth") - && + prepUser.address = cleanParam('address'); +} + +if (required(UQ_PHONE) && + ( !paramExists('phone') || + paramLength('phone') < MIN_PHONE || + paramLength('phone') > LEN_PHONE + ) +) { + reply.errors.push('Valid phone number is required.'); +} else { + prepUser.phone = cleanParam('phone'); +} + +if (required(UQ_SEX) && + (!paramExists('gender') || paramLength('gender') != 1) +) { + reply.errors.push('Sex is required. Heh heh.'); +} else { + prepUser.gender = cleanParam('gender'); +} + +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)) { - reply.errors.push("Birthdate is required."); + prepUser.birthdate = cleanParam('birth'); +} else if (required(UQ_BIRTH)) { + reply.errors.push('Birthdate is required.'); } -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; +http_reply.header['Content-Type'] = 'application/json'; +http_reply.header['Content-Length'] = reply.length; write(reply); \ No newline at end of file diff --git a/web/root/api/system.ssjs b/web/root/api/system.ssjs index e40d9f08495edafc6c481aba6fed249e421ec7df..c7cbdaab768a0cda7394cac3d463e1da463a8fbf 100644 --- a/web/root/api/system.ssjs +++ b/web/root/api/system.ssjs @@ -1,90 +1,81 @@ -load("sbbsdefs.js"); -load("nodedefs.js"); -load(system.exec_dir + "../web/lib/init.js"); -load(settings.web_lib + "auth.js"); +load('sbbsdefs.js'); +load('nodedefs.js'); +load(system.exec_dir + '../web/lib/init.js'); +load(settings.web_lib + 'auth.js'); var reply = {}; -if( (http_request.method == "GET" || http_request.method == "POST") - && - typeof http_request.query.call != "undefined" - && +if ((http_request.method === 'GET' || http_request.method === 'POST') && + typeof http_request.query.call !== 'undefined' && user.number > 0 ) { - switch(http_request.query.call[0]) { + switch (http_request.query.call[0]) { - case "node-list": + case 'node-list': reply = system.node_list.map( - function(node) { - if(node.status == 3) - var usr = new User(node.useron); + function (node) { + if (node.status === 3) var usr = new User(node.useron); return ({ - 'status' : NodeStatus[node.status], - 'action' : NodeAction[node.action], - 'user' : (typeof usr == "undefined" ? "" : usr.alias) + status : NodeStatus[node.status], + action : NodeAction[node.action], + user : (typeof usr === 'undefined' ? '' : usr.alias) }); } ); var usr = new User(1); - for(var un = 1; un < system.lastuser; un++) { + for (var un = 1; un < system.lastuser; un++) { usr.number = un; - if(usr.connection != "HTTP") - continue; - if(usr.alias == settings.guest) - continue; - if(usr.settings&USER_QUIET) - continue; - if(usr.logontime < time() - settings.inactivity) - continue; - var webAction = getSessionValue(usr.number, "action"); - if(webAction === null) - continue; + if (usr.connection !== 'HTTP') continue; + if (usr.alias === settings.guest) continue; + if (usr.settings&USER_QUIET) continue; + if (usr.logontime < time() - settings.inactivity) continue; + var webAction = getSessionValue(usr.number, 'action'); + if (webAction === null) continue; reply.push( - { 'status' : "", - 'action' : "viewing " + webAction, - 'user' : usr.alias + { status : '', + action : 'viewing ' + webAction, + user : usr.alias } ); } break; - case "send-telegram": - if(user.alias == settings.guest) + case 'send-telegram': + if (user.alias === settings.guest) break; + if (typeof http_request.query.user === 'undefined') break; + if (typeof http_request.query.telegram === 'undefined' || + http_request.query.telegram[0] === '' + ) { break; - if(typeof http_request.query.user == "undefined") - break; - if(typeof http_request.query.telegram == "undefined" || http_request.query.telegram[0] == "") - break; - if(http_request.query.telegram[0].length > settings.maximum_telegram_length) + } + if (http_request.query.telegram[0].length > + settings.maximum_telegram_length + ) { break; + } var un = system.matchuser(http_request.query.user[0]); - if(un < 1) - break; + if (un < 1) break; system.put_telegram( un, - "Telegram from " + - user.alias + " via WWW on " + system.timestr() + "\r\n" + - http_request.query.telegram[0] + - "\r\n" + 'Telegram from ' + + user.alias + ' via WWW on ' + system.timestr() + '\r\n' + + http_request.query.telegram[0] + '\r\n' ); break; - case "get-telegram": - if(user.alias == settings.guest) - break; + case 'get-telegram': + if (user.alias === settings.guest) break; reply.telegram = system.get_telegram(user.number); break; - case "set-xtrn-intent": - if(user.alias == settings.guest) - break; - if(typeof http_request.query.code == "undefined") - break; - if(http_request.query.code[0].length > 8) - break; - if(typeof xtrn_area.prog[http_request.query.code[0]] == "undefined") + case 'set-xtrn-intent': + if (user.alias === settings.guest) break; + if (typeof http_request.query.code === 'undefined') break; + if (http_request.query.code[0].length > 8) break; + if (typeof xtrn_area.prog[http_request.query.code[0]] === 'undefined') { break; + } setSessionValue(user.number, 'xtrn', http_request.query.code[0]); break; @@ -96,6 +87,6 @@ if( (http_request.method == "GET" || http_request.method == "POST") } reply = JSON.stringify(reply); -http_reply.header["Content-Type"] = "application/json"; -http_reply.header["Content-Length"] = reply.length; +http_reply.header['Content-Type'] = 'application/json'; +http_reply.header['Content-Length'] = reply.length; write(reply); \ No newline at end of file