Merge pull request #3235 from thelounge/xpaw/root-warning

Print a warning when running as root
This commit is contained in:
Pavel Djundik 2019-05-26 18:02:00 +03:00 committed by GitHub
commit e910ab5194
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@
const log = require("../log"); const log = require("../log");
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
const colors = require("chalk");
const program = require("commander"); const program = require("commander");
const Helper = require("../helper"); const Helper = require("../helper");
const Utils = require("./utils"); const Utils = require("./utils");
@ -22,8 +23,14 @@ Helper.setHome(process.env.THELOUNGE_HOME || Utils.defaultHome());
// Check config file owner and warn if we're running under a different user // Check config file owner and warn if we're running under a different user
if (process.getuid) { if (process.getuid) {
const uid = process.getuid();
if (uid === 0) {
log.warn(`You are currently running The Lounge as root. ${colors.bold.red("We highly discourage running as root!")}`);
}
fs.stat(path.join(Helper.getHomePath(), "config.js"), (err, stat) => { fs.stat(path.join(Helper.getHomePath(), "config.js"), (err, stat) => {
if (!err && stat.uid !== process.getuid()) { if (!err && stat.uid !== uid) {
log.warn("Config file owner does not match the user you are currently running The Lounge as."); log.warn("Config file owner does not match the user you are currently running The Lounge as.");
log.warn("To avoid issues, you should execute The Lounge commands under the same user."); log.warn("To avoid issues, you should execute The Lounge commands under the same user.");
} }