Added placeholder for utils/check

This commit is contained in:
James Ketrenos 2018-10-08 10:56:14 -07:00
parent 77332428e6
commit d0ffda22b6
3 changed files with 100 additions and 15 deletions

View File

@ -22,10 +22,6 @@ require("./console-line.js"); /* Monkey-patch console.log with line numbers */
const picturesPath = config.get("picturesPath").replace(/\/$/, ""), const picturesPath = config.get("picturesPath").replace(/\/$/, ""),
serverConfig = config.get("server"); serverConfig = config.get("server");
config.get("admin.mail");
config.get("smtp.host");
config.get("smtp.sender");
let basePath = config.get("basePath"); let basePath = config.get("basePath");
let photoDB = null, userDB = null; let photoDB = null, userDB = null;
@ -102,11 +98,17 @@ app.use(session({
const index = require("./routes/index"); const index = require("./routes/index");
const transporter = require("nodemailer").createTransport({ if (config.has("admin.mail") &&
host: config.get("smtp.host"), config.has("smtp.host") &&
pool: true, config.has("smtp.sender")) {
port: config.has("smtp.port") ? config.get("smtp.port") : 25 app.set("transporter", require("nodemailer").createTransport({
}); host: config.get("smtp.host"),
pool: true,
port: config.has("smtp.port") ? config.get("smtp.port") : 25
}));
} else {
console.log("SMTP disabled. To enable SMTP, configure admin.mail, smtp.host, and smtp.sender");
}
const templates = { const templates = {
"html": [ "html": [
@ -176,6 +178,11 @@ app.use(basePath, function(req, res, next) {
throw "DB mis-match between authentications and users table"; throw "DB mis-match between authentications and users table";
} }
if (!app.get("transporter")) {
console.log("Not sending VERIFIED email; SMTP not configured.");
return;
}
let user = results[0], let user = results[0],
envelope = { envelope = {
to: config.get("admin.mail"), to: config.get("admin.mail"),

View File

@ -11,12 +11,6 @@ const router = express.Router();
let userDB; let userDB;
let transporter = createTransport({
host: config.get("smtp.host"),
pool: true,
port: config.has("smtp.port") ? config.get("smtp.port") : 25
});
let ldap; let ldap;
if (config.has("ldap.url")) { if (config.has("ldap.url")) {
ldap = new LdapAuth(config.get("ldap")); ldap = new LdapAuth(config.get("ldap"));
@ -145,6 +139,12 @@ router.post("/create", function(req, res) {
throw error; throw error;
}); });
}).then(function() { }).then(function() {
const transporter = app.get("transporter");
if (!transporter) {
console.log("Not sending VERIFY email; SMTP not configured.");
return;
}
let data = { let data = {
username: name, username: name,
mail: mail, mail: mail,

78
util/check.js Normal file
View File

@ -0,0 +1,78 @@
"use strict";
const fs = require("fs"),
Promise = require("bluebird"),
config = require("config");
if (process.argv.length <= 2) {
console.log("usage: node check file|id [file|id] ... ");
process.exit(-1);
}
const items = process.argv.splice(2);
const picturesPath = config.get("picturesPath").replace(/\/$/, "");
for (let i = 0; i < items.length; i++) {
if (parseInt(items[i]) == items[i]) {
items[i] = {
type: "id",
value: items[i]
};
} else {
items[i] = {
type: "file",
value: items[i]
}
}
}
const exists = function(path) {
return stat(path).then(function() {
return true;
}).catch(function() {
return false;
});
}
const stat = function (_path) {
if (_path.indexOf(picturesPath.replace(/\/$/, "")) == 0) {
_path = _path.substring(picturesPath.length);
}
let path = picturesPath + _path;
return new Promise(function (resolve, reject) {
fs.stat(path, function (error, stats) {
if (error) {
return reject(error);
}
return resolve(stats);
});
});
}
require("../server/db/photos").then(function(db) {
const photoDB = db;
return Promise.mapSeries(items, function(item) {
switch (item.type) {
case "file":
return exists(item.value).then(function(exists) {
console.log("File '" + item.value + "' " + (exists ? "exists" : "does not exist."));
});
case "id":
return photoDB.sequelize.query("SELECT * FROM photos WHERE id=:id", {
replacements: {
id: item.value
},
type: photoDB.Sequelize.QueryTypes.SELECT,
raw: true
}).then(function(photos) {
if (photos.length == 0) {
console.log("Item " + item.value + " does not exist.");
} else {
console.log("Item " + item.value + " exists:", photos[0]);
}
});
}
});
});