-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
200 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import express from 'express'; | ||
import { | ||
iptablesExec as executor | ||
} from '../executor/iptables.js'; | ||
import { | ||
checkGet, | ||
checkPost | ||
} from '../util.js'; | ||
import { virtualminExec } from '../executor/virtualmin.js'; | ||
import { logmanExec } from '../executor/logman.js'; | ||
|
||
export default function () { | ||
var router = express.Router(); | ||
router.get('/get', checkGet(['domain', 'type']), async function (req, res, next) { | ||
try { | ||
let domain = await virtualminExec.getDomainInfo(req.query.domain.toString()); | ||
let type = req.query.type.toString() | ||
let n = parseInt(req.query.n.toString()) || 100; | ||
let output = await logmanExec.getLog(domain, type, n); | ||
return res.json(output); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}); | ||
return router; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { | ||
cat, | ||
executeLock, | ||
spawnSudoUtil, | ||
writeTo | ||
} from '../util.js'; | ||
import { XMLParser } from "fast-xml-parser"; | ||
|
||
class LogmanExecutor { | ||
constructor() { | ||
if (process.env.PASSENGERLOG) { | ||
this.PASSENGERLOG = '/var/log/nginx/passenger.log'; | ||
} | ||
} | ||
/** | ||
* @param {any} domain | ||
* @param {string} type | ||
* @param {number} n | ||
*/ | ||
async getLog(domain, type, n) { | ||
switch (type) { | ||
case 'access': | ||
if (!domain['Access log']) { | ||
return { | ||
code: 255, | ||
stdout: 'No access log found', | ||
} | ||
} | ||
return await spawnSudoUtil("SHELL_SUDO", ["root", | ||
"tail", "-n", n, domain['Access log']]); | ||
case 'error': | ||
if (!domain['Error log']) { | ||
return { | ||
code: 255, | ||
stdout: 'No error log found', | ||
} | ||
} | ||
return await spawnSudoUtil("SHELL_SUDO", ["root", | ||
"tail", "-n", n, domain['Error log']]); | ||
case 'passenger': | ||
const user = domain['Username']; | ||
const pe = await spawnSudoUtil("SHELL_SUDO", [user, | ||
"passenger-status", "--show=xml"]); | ||
const peo = pe.stdout.trim(); | ||
if (!peo) { | ||
return { | ||
code: 255, | ||
stdout: 'Passenger instance is not set here', | ||
} | ||
} | ||
const parser = new XMLParser(); | ||
let peom = parser.parse(peo); | ||
let peoma = peom?.info?.supergroups?.supergroup; | ||
if (!peoma) { | ||
return { | ||
code: 255, | ||
stderr: 'incomplete response from passenger-status', | ||
stdout: '' | ||
} | ||
} | ||
let peomaa = Array.isArray(peoma) ? peoma : [peoma]; | ||
let peomaps = peomaa.map(x => x.group.processes).filter(x => x); | ||
if (!peomaps.length) { | ||
return { | ||
code: 255, | ||
stderr: 'No processes from passenger-status is running', | ||
stdout: '' | ||
} | ||
} | ||
let procs = peomaps.reduce((a, b) => { | ||
let x = (Array.isArray(b.process) ? b.process : [b.process]); | ||
a[b.group.name] = x.map(y => y.pid).filter(y => typeof y === "number"); | ||
}, {}); | ||
let head = `List of passenger processes running:\n`; | ||
head += JSON.stringify(procs, null, 2); | ||
head += `\n------------------------\n`; | ||
let pids = Object.values(procs).flatMap(x => x).join('\\|'); | ||
const pes = await spawnSudoUtil("SHELL_SUDO", ["root", | ||
"bash", "-c", `grep -w "\\^App \\(${pids}\\)" "${this.PASSENGERLOG}" | tail -n ${n}` | ||
]); | ||
if (pes.code == 0) { | ||
pes.stdout = head + pes.stdout; | ||
} | ||
return pes; | ||
default: | ||
return { | ||
code: 255, | ||
stdout: 'Unknown log type ' + type | ||
} | ||
} | ||
} | ||
} | ||
|
||
export const logmanExec = new LogmanExecutor(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters