diff options
-rw-r--r-- | modules/email/email.js | 12 | ||||
-rw-r--r-- | modules/proxy/proxy.js | 8 | ||||
-rw-r--r-- | modules/statusbot/statusbot.js | 10 | ||||
-rw-r--r-- | modules/zelfoverhoor/zelfoverhoor.js | 10 | ||||
-rwxr-xr-x | webserver.js | 8 |
5 files changed, 39 insertions, 9 deletions
diff --git a/modules/email/email.js b/modules/email/email.js index e4d342b..d7fe171 100644 --- a/modules/email/email.js +++ b/modules/email/email.js @@ -41,10 +41,16 @@ function sendEmail(recip, text) { } module.exports = function(app, io, moddir) { - var allowedRecipients = - fs.readFileSync(moddir + "/allowed_recipients.txt").toString().trim().split("\n"); + var allowedRecipients, password; - var password = fs.readFileSync(moddir + "/password.txt").toString().trim(); + try { + allowedRecipients = + fs.readFileSync(moddir + "/allowed_recipients.txt").toString().trim().split("\n"); + password = fs.readFileSync(moddir + "/password.txt").toString().trim(); + } catch (e) { + console.error(e); + return false; + } app.post("/email", bodyParser.json(), function(req, res) { var body = req.body; diff --git a/modules/proxy/proxy.js b/modules/proxy/proxy.js index 49caf54..ccec53a 100644 --- a/modules/proxy/proxy.js +++ b/modules/proxy/proxy.js @@ -29,9 +29,15 @@ function objectFromList(l){ } module.exports=function(app,io,moddir){ - var iddict=objectFromList( + var iddict; + try { + iddict=objectFromList( fs.readFileSync(moddir+"/idfile.txt").toString() .split("\n").map(function(r){return r.split(" ");})); + } catch (e) { + console.error(e); + return false; + } app.all("/proxy/:id/*",function(req,res){ var id=req.params.id; diff --git a/modules/statusbot/statusbot.js b/modules/statusbot/statusbot.js index 1af5804..a518b17 100644 --- a/modules/statusbot/statusbot.js +++ b/modules/statusbot/statusbot.js @@ -272,8 +272,14 @@ function matrixSendMsgLogin(text, cb) { module.exports = function(app, io, _moddir) { moddir = _moddir; - const config = require("./matrix.json"); - const accounts = require("./accounts.json"); + let config, accounts; + try { + config = require("./matrix.json"); + accounts = require("./accounts.json"); + } catch (e) { + console.error(e); + return false; + } const ratelimit = new PRatelimit(1000); diff --git a/modules/zelfoverhoor/zelfoverhoor.js b/modules/zelfoverhoor/zelfoverhoor.js index 03de63c..0acb322 100644 --- a/modules/zelfoverhoor/zelfoverhoor.js +++ b/modules/zelfoverhoor/zelfoverhoor.js @@ -6,7 +6,12 @@ var moddir; var dbdir=cmn.persistdir+"/zelfoverhoor"; mkdirp.sync(dbdir); -var accounts=require("./accounts.json"); +var accounts=null; +try { + accounts=require("./accounts.json"); +} catch (e) { + console.error(e); +} var SHUFFLE_QUESTIONS=false; @@ -97,6 +102,9 @@ function canAccessFile(fname){ module.exports=function(app,io,_moddir){ moddir=_moddir; + // Failed to load accounts.json + if(accounts==null)return false; + if(canAccessFile(dbdir+"/questiondb.json")&&canAccessFile(dbdir+"/questionsets.json")&&canAccessFile(dbdir+"/userlists.json")){ questiondb=JSON.parse(fs.readFileSync(dbdir+"/questiondb.json")); questionsets=JSON.parse(fs.readFileSync(dbdir+"/questionsets.json")); diff --git a/webserver.js b/webserver.js index 71f6bcd..39f2410 100755 --- a/webserver.js +++ b/webserver.js @@ -87,8 +87,12 @@ const module_list = fs.readdirSync("modules").filter(function (f) { }); for (let i = 0; i < module_list.length; i++) { const mod = require("./modules/" + module_list[i] + "/" + module_list[i] + ".js"); - mod(app, io, cmn.serverdir + "/modules/" + module_list[i]); - console.log("Loaded module " + module_list[i]); + const ret = mod(app, io, cmn.serverdir + "/modules/" + module_list[i]); + if (ret === false) { + console.log("FAILED LOADING module " + module_list[i]); + } else { + console.log("Loaded module " + module_list[i]); + } } |