This commit is contained in:
Jay
2017-05-26 11:06:15 +08:00
parent 58057bcfa0
commit d702c63eb6
5 changed files with 110 additions and 7 deletions
+62
View File
@@ -295,6 +295,68 @@ router
return n();
})
.post('/getbmctl', async(req, res, n) => {
if (!config.permission.server) return n('ERR9000');
try {
let query = "select `uid`,`name` from ??.??";
let param = [config.db.db11, 'bmctl'];
let ctls = await tool.promiseQuery(res, query, param);
res.api_res = {
record: tool.checkArray(ctls.data)
}
} catch (err) {
return rt.err(res, err, n, 'ERR8000');
}
return n();
})
.post('/runbmctl', async(req, res, n) => {
if (!config.permission.server) return n('ERR9000');
if (!tool.checkPermission(req)) return n('ERR9000');
let arr = req.body;
if (!arr.data) return n('ERR0000');
if (!arr.data.ctlid || !arr.data.ipmuid) return n('ERR0028');
res.api_res = {
record: []
};
try {
let query = "select * from ??.?? where `uid` = ?";
let param = [config.db.db11, 'bmctl', arr.data.ctlid];
let ctl = await tool.promiseQuery(res, query, param);
if (ctl.data.length == 0) return n('ERR8000');
query = "select * from ??.?? where `ipmuid` = ?";
param = [config.db.db11, 'ipmi', arr.data.ipmuid];
let ipmi = await tool.promiseQuery(res, query, param);
if (ipmi.data.length == 0) return n('ERR8000');
let cmd = ctl.data[0].cmd;
cmd = cmd.trim();
if (!cmd) return n('ERR7000');
cmd = cmd.replace(/\@ipmuid/i, ipmi.data[0].ipmuid);
let result = await new Promise((resolve, reject) => {
exec(cmd, (err, stderr, stdout) => {
if (err) return reject(err);
return resolve(stdout || stderr);
});
})
result = result.split(/\n/).filter(e => e).join('');
if (result == 0) return n('ERR7000');
} catch (err) {
return rt.err(res, err, n, 'ERR8000');
}
return n();
})
.all('*', rt.send);
module.exports = router;