From 432ff46ecd89e6a23bd0c019cfa03205193e85bc Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 25 May 2017 13:37:16 +0800 Subject: [PATCH] update --- route/api/server.js | 160 +++++++++++++++- src/components/AdminPage/Server/DevList.js | 4 +- .../AdminPage/Server/IPMIPage/SetListItem.js | 8 +- .../AdminPage/Server/IPMIPage/index.js | 78 ++++---- .../Server/{Models => Modals}/DevModal.js | 15 +- .../AdminPage/Server/Modals/IPMIInfoModal.js | 34 ++++ .../AdminPage/Server/Modals/IPMIModal.js | 50 +++++ src/components/AdminPage/Server/index.js | 178 +++++++++++++++--- 8 files changed, 452 insertions(+), 75 deletions(-) rename src/components/AdminPage/Server/{Models => Modals}/DevModal.js (61%) create mode 100644 src/components/AdminPage/Server/Modals/IPMIInfoModal.js create mode 100644 src/components/AdminPage/Server/Modals/IPMIModal.js diff --git a/route/api/server.js b/route/api/server.js index eac4877..d72f57c 100644 --- a/route/api/server.js +++ b/route/api/server.js @@ -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); diff --git a/src/components/AdminPage/Server/DevList.js b/src/components/AdminPage/Server/DevList.js index 4260c2c..6605993 100644 --- a/src/components/AdminPage/Server/DevList.js +++ b/src/components/AdminPage/Server/DevList.js @@ -6,7 +6,7 @@ class DevList extends React.Component { render() { - let {list, sel,selectDevice, openModal} = this.props; + let {list, sel,selectDevice, openModal, delData} = this.props; return ( @@ -23,7 +23,7 @@ class DevList extends React.Component { selectDevice(t.devuid)}>{t.name} null} /> + onClick={()=>delData('device', t.devuid)} /> openModal('device', 1, t)} /> diff --git a/src/components/AdminPage/Server/IPMIPage/SetListItem.js b/src/components/AdminPage/Server/IPMIPage/SetListItem.js index 1fb8334..9dbc662 100644 --- a/src/components/AdminPage/Server/IPMIPage/SetListItem.js +++ b/src/components/AdminPage/Server/IPMIPage/SetListItem.js @@ -1,14 +1,14 @@ import React from 'react'; import {Table, Button} from 'semantic-ui-react'; -const SetListItem = ({ i18n, data, openModal }) => { +const SetListItem = ({ i18n, data, openModal, delData }) => { return ( -