This commit is contained in:
Jay
2017-05-25 13:37:16 +08:00
parent c934490047
commit 432ff46ecd
8 changed files with 452 additions and 75 deletions
+159 -1
View File
@@ -132,10 +132,168 @@ router
if (!arr.data.id) return n('ERR0028');
try {
let query = "delete from ??.?? where `devuid` = ?";
let param = [config.db.db11, 'dev', arr.data.id];
await tool.promiseQuery(res, query, param);
} catch (err) {
return rt.err(res, err, n, 'ERR8003');
}
res.api_res = {
record: []
}
return n();
})
.post('/addipmi', 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.devuid) return n('ERR0028');
if (!arr.data.account) return n('ERR0016');
if (!arr.data.password) return n('ERR0017');
if (!arr.data.ip) return n('ERR0010');
try {
let query = "select count(*) as c from ??.?? where `ip` = ?";
let param = [config.db.db11, 'ipmi', arr.data.ip];
let c = await tool.promiseQuery(res, query, param);
if (c.data.length > 0 && c.data.c > 0) return n('ERR0027');
} catch (err) {
return rt.err(res, err, n, 'ERR8000');
}
let u = '';
let obj = so.get(req.headers['x-auth-token'] || '');
if (obj != null && 'user' in obj && 'account' in obj.user) u = obj.user.account;
try {
let query = "insert into ??.?? (`devuid`, `ip`, `account`, `password`, `cuser`, `ctime`, `muser`, `mtime`) values \
(?, ?, ?, ?, ?, unix_timestamp(), ?, unix_timestamp())";
let param = [config.db.db11, 'ipmi', arr.data.devuid, arr.data.ip, arr.data.account, arr.data.password, u, u];
await tool.promiseQuery(res, query, param);
} catch (err) {
return rt.err(res, err, n, 'ERR8001');
}
res.api_res = {
record: []
};
return n();
})
.post('/editipmi', 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.id) return n('ERR0028');
if (!arr.data.account) return n('ERR0016');
if (!arr.data.password) return n('ERR0017');
if (!arr.data.ip) return n('ERR0010');
try {
let query = "select count(*) as c from ??.?? where `ipmuid` != ? and `ip` = ?";
let param = [config.db.db11, 'ipmi', arr.data.id, arr.data.ip];
let c = await tool.promiseQuery(res, query, param);
if (c.data.length > 0 && c.data.c > 0) return n('ERR0027');
} catch (err) {
return rt.err(res, err, n, 'ERR8000');
}
let u = '';
let obj = so.get(req.headers['x-auth-token'] || '');
if (obj != null && 'user' in obj && 'account' in obj.user) u = obj.user.account;
try {
let query = "update ??.?? set \
`account` = ?, \
`password` = ?, \
`ip` = ?, \
`muser` = ?, \
`mtime` = unix_timestamp() \
where \
`ipmuid` = ?";
let param = [config.db.db11, 'ipmi', arr.data.account, arr.data.password, arr.data.ip, u, arr.data.id];
await tool.promiseQuery(res, query, param);
} catch (err) {
return rt.err(res, err, n, 'ERR8002');
}
res.api_res = {
record: []
};
return n();
})
.post('/delipmi', 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.id) return n('ERR0028');
try {
let query = "delete from ??.?? where `ipmuid` = ?";
let param = [config.db.db11, 'ipmi', arr.data.id];
await tool.promiseQuery(res, query, param);
} catch (err) {
return rt.err(res, err, n, 'ERR8003');
}
res.api_res = {
record: []
};
return n();
})
.post('/getipmiinfo', async(req, res, n) => {
if (!config.permission.server) return n('ERR9000');
let arr = req.body;
if (!arr.data) return n('ERR0000');
if (!arr.data.id) return n('ERR0028');
res.api_res = {
record: [],
rt: {
log: [],
sensor: [],
bmcgroup: [],
bmcdata: []
}
};
try {
let query = "select * from ??.?? where `ipmuid` = ?";
let param = [config.db.db11, 'ipmi', arr.data.id];
let ipmi = await tool.promiseQuery(res, query, param);
if (ipmi.data.length == 0) return n('ERR8000');
delete ipmi.data[0].password;
res.api_res.record = tool.checkArray(ipmi.data);
query = "select * from ??.?? order by `guid`";
param = [config.db.db11, 'bmg'];
let bmg = await tool.promiseQuery(res, query, param);
res.api_res.rt.bmcgroup = tool.checkArray(bmg.data);
query = "select * from ??.?? where `ipmuid` = ?";
param = [config.db.db11, 'bmrt', arr.data.id];
let bmrt = await tool.promiseQuery(res, query, param);
res.api_res.rt.bmcdata = tool.checkArray(bmrt.data);
query = "select * from ??.?? where `ipmuid` = ?";
param = [config.db.db11, 'ipmilogrt', arr.data.id];
let log = await tool.promiseQuery(res, query, param);
res.api_res.rt.log = tool.checkArray(log.data);
query = "select * from ??.?? where `ipmuid` = ?";
param = [config.db.db11, 'ipmisenrt', arr.data.id];
let sensor = await tool.promiseQuery(res, query, param);
res.api_res.rt.sensor = tool.checkArray(sensor.data);
} catch (err) {
return rt.err(res, err, n, 'ERR8000');
}
return n();
})
.all('*', rt.send);