diff --git a/route/api/index.js b/route/api/index.js index 796f9d9..e621ed0 100644 --- a/route/api/index.js +++ b/route/api/index.js @@ -8,19 +8,19 @@ router .get('/', (req, res) => { res.send({ name: 'WebIO API System' }); }) - .all('*', (req,res,n)=>{ - if('x-auth-token' in req.headers) { + .all('*', (req, res, n) => { + if ('x-auth-token' in req.headers) { let token = req.headers['x-auth-token']; - if(so.chkKey(token)){ + if (so.chkKey(token)) { let obj = so.get(token); - if(obj != null) { + if (obj != null) { so.set(token, obj); } } } n(); }) - .get('/showallso', (req,res)=>{ + .get('/showallso', (req, res) => { res.send(so.show()); }) .use('/system', require('./system.js')) @@ -33,11 +33,12 @@ router .use('/link', require('./link.js')) .use('/modbus', require('./modbus.js')) .use('/ipcam', require('./ipcam.js')) + .use('/server', require('./server.js')) .use('/wristband', require('./wristband.js')); // api error handler router.use((err, req, res, n) => { - if ('db' in res && typeof res.db == 'object' && 'close' in res.db && typeof res.db.close == 'function') res.db.close(); + if ('db' in res && typeof res.db == 'object' && 'close' in res.db && typeof res.db.close == 'function') res.db.close(); if ('db' in res && typeof res.db == 'object' && 'release' in res.db && typeof res.db.release == 'function') res.db.release(); let lngs = req.headers['accept-language'] || ''; @@ -52,7 +53,7 @@ router.use((err, req, res, n) => { status: 0 }; - if('sys_err' in res && process.env.NODE_ENV != 'production') json.sys_err = res.sys_err; + if ('sys_err' in res && process.env.NODE_ENV != 'production') json.sys_err = res.sys_err; res.send(json); }) diff --git a/route/api/server.js b/route/api/server.js index 1cb1d51..eac4877 100644 --- a/route/api/server.js +++ b/route/api/server.js @@ -22,11 +22,11 @@ router } n(); }) - .post('/getserverlist', (req, res, n) => { + .post('/getdevicelist', (req, res, n) => { if (!config.permission.server) return n('ERR9000'); let query = "select * from ??.??"; - let param = [config.db.db11, 'jciocservert']; + let param = [config.db.db11, 'dev']; res.db.query(query, param, (err, row) => { if (err) return rt.err(res, err, n, 'ERR8000'); @@ -36,27 +36,105 @@ router n(); }) }) - .post('/addserver', (req, res, n) => { + .post('/getdevice', 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'); + + let query = "select * from ??.?? where `devuid` = ?"; + let param = [config.db.db11, 'dev', arr.data.id]; + try { + let dev = await tool.promiseQuery(res, query, param); + if (dev.data.length == 0) return n('ERR8000'); + + let ipmi_param = [config.db.db11, 'ipmi', arr.data.id]; + let ipmi = await tool.promiseQuery(res, query, ipmi_param); + + let snmp_param = [config.db.db11, 'snmp', arr.data.id]; + let snmp = await tool.promiseQuery(res, query, snmp_param); + + res.api_res = { + record: tool.checkArray(dev.data), + rt: { + ipmi: tool.checkArray(ipmi.data), + snmp: tool.checkArray(snmp.data) + } + } + + } catch (e) { + return rt.err(res, e, n, 'ERR8000'); + } + + n(); + }) + .post('/adddevice', 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.name) return n('ERR0026'); - if (arr.data.iip) { - if (!arr.data.iaccount) return n('ERR0016'); - if (!arr.data.ipassword) return n('ERR0017'); - if (!arr.data.imac) return n('ERR0064'); - if (!arr.data.itype) return n('ERR0009'); - } - if (arr.data.sip) { - if (!arr.data.smac) return n('ERR0064'); - if (!arr.data.stype) return n('ERR0009'); - if (!arr.data.sname) return n('ERR0026'); - if (!arr.data.sver) return n('ERR0065'); - if (arr.data.sver == 'v3' && !arr.data.v3level) return n('ERR0066'); - if (arr.data.v3level) { - } + 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 ??.?? (`name`, `ctime`, `cuser`, `mtime`, `muser`) values \ + (?, unix_timestamp(), ?, unix_timestamp(), ?)"; + let param = [config.db.db11, 'dev', arr.data.name, u, u]; + + await tool.promiseQuery(res, query, param); + } catch (e) { + return rt.err(res, e, n, 'ERR8001'); + } + + res.api_res = { + record: [] + }; + n(); + }) + .post('/editdevice', 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.name) return n('ERR0026'); + + 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 \ + `name` = ?, \ + `muser` = ?, \ + `mtime` = unix_timestamp() \ + where \ + `devuid` = ?"; + let param = [config.db.db11, 'dev', arr.data.name, u, arr.data.id]; + await tool.promiseQuery(res, query, param); + } catch (e) { + return rt.err(res, e, n, 'ERR8002'); + } + + res.api_res = { + record: [] + }; + n(); + }) + .post('/deldevice', 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 { + + } catch (err) { + return rt.err(res, err, n, 'ERR8003'); } }) .all('*', rt.send); diff --git a/src/components/AdminPage/Server/DevList.js b/src/components/AdminPage/Server/DevList.js new file mode 100644 index 0000000..4260c2c --- /dev/null +++ b/src/components/AdminPage/Server/DevList.js @@ -0,0 +1,40 @@ +import React from 'react'; +import { Menu, List, Icon } from 'semantic-ui-react'; + + +class DevList extends React.Component { + + + render() { + let {list, sel,selectDevice, openModal} = this.props; + return ( + + + + 裝置列表 + openModal('device')} /> + + + { + list.map((t,idx)=>( + + selectDevice(t.devuid)}>{t.name} + null} /> + openModal('device', 1, t)} /> + + )) + } + + + + ) + } +} + +export default DevList; \ No newline at end of file diff --git a/src/components/AdminPage/Server/IPMIPage/SetListItem.js b/src/components/AdminPage/Server/IPMIPage/SetListItem.js new file mode 100644 index 0000000..1fb8334 --- /dev/null +++ b/src/components/AdminPage/Server/IPMIPage/SetListItem.js @@ -0,0 +1,20 @@ +import React from 'react'; +import {Table, Button} from 'semantic-ui-react'; + +const SetListItem = ({ i18n, data, openModal }) => { + + return ( + + +