diff --git a/src/controllers/logman.js b/src/controllers/logman.js index 3d2d651..6dff85e 100644 --- a/src/controllers/logman.js +++ b/src/controllers/logman.js @@ -11,21 +11,12 @@ import { logmanExec } from '../executor/logman.js'; export default function () { var router = express.Router(); - router.get('/get', checkGet(['domain', 'type']), async function (req, res, next) { + router.get('/get', checkGet(['user', 'type']), async function (req, res, next) { try { - let domain = await virtualminExec.getDomainInfo(req.query.domain.toString()); let type = req.query.type.toString() + let user = req.query.user.toString() let n = parseInt((req.query.n || 100).toString()) || 100; - let output = await logmanExec.getLog(domain, type, n); - return res.json(output); - } catch (err) { - next(err); - } - }); - router.post('/restart', checkGet(['domain']), async function (req, res, next) { - try { - let domain = await virtualminExec.getDomainInfo(req.query.domain.toString()); - let output = await logmanExec.restartPassenger(domain); + let output = await logmanExec.getLog(user, type, n); return res.json(output); } catch (err) { next(err); diff --git a/src/executor/logman.js b/src/executor/logman.js index 7bc38d2..758f93f 100644 --- a/src/executor/logman.js +++ b/src/executor/logman.js @@ -15,34 +15,28 @@ class LogmanExecutor { } } /** - * @param {any} domain + * @param {string} user * @param {string} type * @param {number} n */ - async getLog(domain, type, n) { + async getLog(user, type, n) { switch (type) { case 'access': - if (!domain['Access log']) { - return { - code: 255, - stderr: 'No access log found', - stdout: '', - } - } return await spawnSudoUtil("SHELL_SUDO", ["root", - "tail", "-n", n, domain['Access log']]); + "tail", "-n", n + '', `/home/${user}/logs/access_log`]); case 'error': - if (!domain['Error log']) { - return { - code: 255, - stderr: 'No error log found', - stdout: '', - } - } return await spawnSudoUtil("SHELL_SUDO", ["root", - "tail", "-n", n, domain['Error log']]); + "tail", "-n", n + '', `/home/${user}/logs/error_log`]); + case 'php': + return await spawnSudoUtil("SHELL_SUDO", ["root", + "tail", "-n", n + '', `/home/${user}/logs/php_log`]); + case 'unit-stdout': + return await spawnSudoUtil("SHELL_SUDO", ["root", + "tail", "-n", n + '', `/home/${user}/logs/unit_stdout_log`]); + case 'unit-stderr': + return await spawnSudoUtil("SHELL_SUDO", ["root", + "tail", "-n", n + '', `/home/${user}/logs/unit_stderr_log`]); case 'passenger': - const user = domain['Username']; const procs = await this.getPassengerPids(user); if (procs.code !== 0) { return procs;