Merge branch 'master' into release

This commit is contained in:
Jay 2017-05-31 11:11:43 +08:00
commit 5c37893d1c
13 changed files with 1052 additions and 24 deletions

View File

@ -33,6 +33,7 @@ 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

View File

@ -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,28 +36,326 @@ 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 {
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();
})
.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);

View File

@ -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, delData} = this.props;
return (
<Menu vertical>
<Menu.Item>
<Menu.Header className="clearfix">
裝置列表
<Icon name="plus"
style={{float: 'right',cursor:'pointer'}}
onClick={()=>openModal('device')} />
</Menu.Header>
<Menu.Menu>
{
list.map((t,idx)=>(
<Menu.Item key={idx} active={sel == t.devuid}>
<span style={{cursor:'pointer'}} onClick={()=>selectDevice(t.devuid)}>{t.name}</span>
<Icon name="trash"
style={{cursor:'pointer'}}
onClick={()=>delData('device', t.devuid)} />
<Icon name="edit"
style={{cursor:'pointer'}}
onClick={()=>openModal('device', 1, t)} />
</Menu.Item>
))
}
</Menu.Menu>
</Menu.Item>
</Menu>
)
}
}
export default DevList;

View File

@ -0,0 +1,27 @@
import React from 'react';
import {Table, Button} from 'semantic-ui-react';
const SetListItem = ({ i18n, data, openModal, delData, bmctl, runbmctl }) => {
return (
<Table.Row>
<Table.Cell>
<Button content="修改" basic onClick={()=>openModal('ipmi', 1, data)} />
<Button content="刪除" basic onClick={()=>delData('ipmi', data.ipmuid)} />
<Button content="ShowInfo" basic onClick={()=>openModal('ipmiinfo', 0, {id: data.ipmuid})} />
</Table.Cell>
<Table.Cell>
{
bmctl.map((t,idx) => (
<Button key={idx} content={t.name} type="button" onClick={()=>runbmctl(t.uid, data.ipmuid)} />
))
}
</Table.Cell>
<Table.Cell>{data.ip}</Table.Cell>
<Table.Cell>{data.account}</Table.Cell>
<Table.Cell>{data.mac}</Table.Cell>
</Table.Row>
)
}
export default SetListItem;

View File

@ -0,0 +1,47 @@
import React from 'react';
import {Container, Segment, Button, Table} from 'semantic-ui-react';
import SelListItem from './SetListItem';
const IPMIPage = ({i18n, list, openModal, delData, bmctl, runbmctl}) => {
return (
<Container>
<Segment className="clearfix">
<Button content="新增設定"
icon="plus"
floated="right"
basic
color="green"
style={{marginBottom: '15px'}}
onClick={()=>openModal('ipmi')} />
<Table>
<Table.Header>
<Table.Row>
<Table.HeaderCell>操作</Table.HeaderCell>
<Table.HeaderCell>設備操作</Table.HeaderCell>
<Table.HeaderCell>IP</Table.HeaderCell>
<Table.HeaderCell>帳號</Table.HeaderCell>
<Table.HeaderCell>MAC Address</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
{
list.map((t,idx) => {
return (
<SelListItem key={idx}
i18n={i18n}
data={t}
openModal={openModal}
delData={delData}
bmctl={bmctl}
runbmctl={runbmctl} />
)
})
}
</Table.Body>
</Table>
</Segment>
</Container>
)
}
export default IPMIPage;

View File

@ -0,0 +1,40 @@
import React from 'react';
import {Modal, Form, Input, Button, Grid} from 'semantic-ui-react';
const DevModel = ({ i18n, open, type, data, closeModal, submitModal }) => {
return (
<Modal open={open}>
<Modal.Header content={type == 1 ? '修改裝置' : '新增裝置'} />
<Modal.Content>
<Form onSubmit={(e,d) => {
e.preventDefault();
submitModal('device', type, d.formData);
}} serializer={e=>{
let json = {};
let name = e.querySelector('input[name="name"]');
if(name && 'value' in name) json.name = name.value;
if(type == 1) json.id = data.devuid;
return json;
}}>
<Form.Field>
<Input label="裝置名稱" name="name" defaultValue={data.name} />
</Form.Field>
<Grid columns={2}>
<Grid.Column>
<Button type="submit" content="送出" basic fluid/>
</Grid.Column>
<Grid.Column>
<Button type="button" fluid content="取消" basic onClick={()=>closeModal('device')} />
</Grid.Column>
</Grid>
</Form>
</Modal.Content>
</Modal>
)
}
export default DevModel;

View File

@ -0,0 +1,150 @@
import React from 'react';
import {Modal, Segment, Menu, Label, Container, Header, List, Table} from 'semantic-ui-react';
import {convertTime} from '../../../../tools';
const stateDefault = () => ({
open: false,
tabIdx: 1
})
class IPMIInfoModal extends React.Component {
state = {...stateDefault()}
componentWillReceiveProps(nextProps){
if(nextProps.open != this.state.open){
if(nextProps.open == false){
this.setState({...stateDefault()})
}else{
this.setState({
open: true
})
}
}
}
changeIdx = (idx) => {
this.setState({
tabIdx: idx
})
}
getInfoView = () => {
switch(this.state.tabIdx){
case 1:
return <BMCContent group={this.props.bmcgroup} data={this.props.bmcdata} />
case 2:
return <SensorContent sensor={this.props.sensor} />
case 3:
return <LogContent log={this.props.log} />
default:
return null;
}
}
render() {
let {closeModal} = this.props;
return (
<Modal size="fullscreen" open={this.state.open} onClose={()=>closeModal('ipmiinfo')}>
<Modal.Header content="IPMI Info" />
<Modal.Content>
<Menu attached="top" tabular>
<Menu.Item name="BMC Info" active={this.state.tabIdx == 1} onClick={()=>this.changeIdx(1)} />
<Menu.Item name="Sensor" active={this.state.tabIdx == 2} onClick={()=>this.changeIdx(2)} />
<Menu.Item name="Log" active={this.state.tabIdx == 3} onClick={()=>this.changeIdx(3)} />
</Menu>
<Segment attached="bottom">
{this.getInfoView()}
</Segment>
</Modal.Content>
</Modal>
)
}
}
const BMCContent = ({group, data}) => {
return (
<Container fluid>
{
group.map((t,idx) => (
<Segment key={idx}>
<Header as="h3" color="blue">
{t.name}
<Header.Subheader>{t.value}</Header.Subheader>
</Header>
<List>
{
data.map((t2, idx) => {
if(t2.guid != t.guid) return null;
return (
<List.Item key={idx}>
<Label content={t2.name} basic />
{t2.value}
</List.Item>
)})
}
</List>
</Segment>
))
}
</Container>
)
}
const LogContent = ({log}) => {
return (
<Container fluid>
<Table>
<Table.Header>
<Table.Row>
<Table.HeaderCell>行號</Table.HeaderCell>
<Table.HeaderCell>時間</Table.HeaderCell>
<Table.HeaderCell>內容</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
{
log.map((t,idx) => (
<Table.Row>
<Table.Cell>{t.line}</Table.Cell>
<Table.Cell>{convertTime(t.time, true)}</Table.Cell>
<Table.Cell>{t.content}</Table.Cell>
</Table.Row>
))
}
</Table.Body>
</Table>
</Container>
)
}
const SensorContent = ({sensor}) => {
return (
<Container fluid>
<Table>
<Table.Header>
<Table.Row>
<Table.HeaderCell>名稱</Table.HeaderCell>
<Table.HeaderCell>數值</Table.HeaderCell>
<Table.HeaderCell>單位</Table.HeaderCell>
<Table.HeaderCell>狀態</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
{
sensor.map((t,idx) => (
<Table.Row>
<Table.Cell>{t.name}</Table.Cell>
<Table.Cell>{t.value}</Table.Cell>
<Table.Cell>{t.unit}</Table.Cell>
<Table.Cell>{t.status}</Table.Cell>
</Table.Row>
))
}
</Table.Body>
</Table>
</Container>
)
}
export default IPMIInfoModal;

View File

@ -0,0 +1,50 @@
import React from 'react';
import {Modal, Form, Grid, Input, Button } from 'semantic-ui-react';
const IPMIModal = ({ i18n, open, type, data, closeModal, submitModal }) => {
return (
<Modal open={open}>
<Modal.Header content={type == 1 ? '修改設定' : '新增設定'} />
<Modal.Content>
<Form onSubmit={(e,d) => {
e.preventDefault();
submitModal('ipmi', type, d.formData);
}} serializer={e=>{
let json ={};
let ip = e.querySelector('input[name="ip"]');
if(ip && 'value' in ip) json.ip = ip.value;
let account = e.querySelector('input[name="account"]');
if(account && 'value' in account) json.account = account.value;
let pass = e.querySelector('input[name="password"]');
if(pass && 'value' in pass) json.password = pass.value;
if(type == 1 ) json.id = data.ipmuid;
return json;
}}>
<Form.Field>
<Input label="IP" name="ip" defaultValue={data.ip} />
</Form.Field>
<Form.Field>
<Input label="帳號" name="account" defaultValue={data.account} />
</Form.Field>
<Form.Field>
<Input label="密碼" name="password" defaultValue={data.password} />
</Form.Field>
<Grid columns={2}>
<Grid.Column>
<Button type="submit" content="送出" basic fluid/>
</Grid.Column>
<Grid.Column>
<Button type="button" fluid content="取消" basic onClick={()=>closeModal('ipmi')} />
</Grid.Column>
</Grid>
</Form>
</Modal.Content>
</Modal>
)
}
export default IPMIModal;

View File

@ -0,0 +1,18 @@
import React from 'react';
import {Container, Segment} from 'semantic-ui-react';
class SNMPPage extends React.Component {
render() {
return (
<Container>
<Segment>
</Segment>
</Container>
)
}
}
export default SNMPPage;

View File

@ -0,0 +1,333 @@
import React from 'react';
import { Container, Segment, Menu, List, Grid } from 'semantic-ui-react';
import {getRequest} from '../../../actions';
import DevList from './DevList';
import IPMIPage from './IPMIPage';
import DevModal from './Modals/DevModal';
import IPMIModal from './Modals/IPMIModal';
import IPMIInfoModal from './Modals/IPMIInfoModal';
const stateDefault = ()=>({
list: [],
bmctl: [],
devSel: {
id: null,
type: null,
data: {
snmp: [],
ipmi: []
}
},
devModal: {
open: false,
type: 0,
data: {}
},
ipmiModal: {
open: false,
type: 0,
data: {}
},
ipmiInfo: {
open: false,
ipmi: [],
log: [],
sensor: [],
bmcdata: [],
bmcgroup: []
}
})
class ServerPage extends React.Component {
state = {...stateDefault()}
componentDidMount(){
this.getDevList();
this.getBMCtl();
}
getDevList = () => {
let {showDialog, toggleLoading} = this.props;
toggleLoading(1);
fetch('/api/server/getdevicelist', getRequest())
.then(response => response.json())
.then(json => {
toggleLoading(0);
if(json.status != 1) return showDialog(json.message);
this.setState({
list: json.data.record || []
})
})
}
getBMCtl = () => {
fetch('/api/server/getbmctl', getRequest())
.then(response=>response.json())
.then(json => {
if(json.status == 1) {
this.setState({
bmctl: json.data.record || []
})
}
})
}
selectDevice = (id, refresh = false) => {
if(!id) return ;
let {showDialog, toggleLoading} = this.props;
toggleLoading(1);
fetch('/api/server/getdevice', getRequest({id}))
.then(response=>response.json())
.then(json => {
toggleLoading(0);
if(json.status != 1) return showDialog(json.message);
let ipmi = json.data.rt.ipmi || [];
let snmp = json.data.rt.snmp || [];
let jdata = {
...stateDefault().devSel,
id,
data: {
ipmi,
snmp
}
};
if(refresh) jdata.type = this.state.devSel.type;
this.setState({
devSel: jdata
})
})
}
selectDataType = (type) => {
this.setState({
devSel: {
...this.state.devSel,
type: type
}
})
}
genSubPage = () => {
let {i18n, showDialog, toggleLoading, callConfirm} = this.props;
switch(this.state.devSel.type){
case 'ipmi':
return <IPMIPage i18n={i18n}
showDialog={showDialog}
toggleLoading={toggleLoading}
callConfirm={callConfirm}
list={this.state.devSel.data.ipmi}
openModal={this.openModal}
closeModal={this.closeModal}
delData={this.delData}
bmctl={this.state.bmctl}
runbmctl={this.runbmctl} />
default:
return null;
}
}
openModal = (mtype, type = 0, data = {}) => {
switch(mtype){
case 'device':
this.setState({
devModal: {
open: true,
type,
data
}
})
break;
case 'ipmi':
this.setState({
ipmiModal:{
open: true,
type,
data
}
});
break;
case 'ipmiinfo':
this.getIPMIData(data.id);
break;
default:
return null;
}
}
closeModal = (mtype, cb = null) => {
switch(mtype){
case 'device':
this.setState({devModal: {...stateDefault().devModal}});
break;
case 'ipmi':
this.setState({ipmiModal:{...stateDefault().ipmiModal}});
break;
case 'ipmiinfo':
this.setState({ipmiInfo: {...stateDefault().ipmiInfo}});
break;
}
if(cb && typeof cb == 'function') cb();
}
submitModal = (mtype, type = 0, data = {}) => {
if(!mtype) return ;
let {i18n, showDialog, toggleLoading, callConfirm} = this.props;
let url = '';
switch(mtype){
case 'device':
if(type == 1 && !data.id) return showDialog('資料讀取錯誤');
if(!data.name) return showDialog('請填寫設備名稱');
url = type == 1 ? '/api/server/editdevice' : '/api/server/adddevice';
fetch(url, getRequest(data))
.then(response => response.json())
.then(json => {
if(json.status != 1) return showDialog(json.message);
this.closeModal(mtype, ()=>{this.getDevList()});
});
break;
case 'ipmi':
if(type == 1 && !data.id) return showDialog('資料讀取錯誤');
if(!data.ip) return showDialog('請填寫IP');
if(!data.account) return showDialog('請填寫帳號');
if(!data.password) return showDialog('請填寫密碼');
data.devuid = this.state.devSel.id;
url = type == 1 ? '/api/server/editipmi' : '/api/server/addipmi';
fetch(url, getRequest(data))
.then(response=>response.json())
.then(json => {
if(json.status != 1) return showDialog(json.message);
this.closeModal(mtype, ()=>{ this.selectDevice(this.state.devSel.id, true); })
})
default :
return null;
}
}
delData = (mtype, id) => {
if(!mtype || !id) return ;
let {i18n, showDialog, toggleLoading, callConfirm} = this.props;
switch(mtype) {
case 'device':
callConfirm('確定刪除此裝置?', ()=>{
fetch('/api/server/deldevice', getRequest({id}))
.then(response=>response.json())
.then(json => {
if(json.status != 1) return showDialog(json.message);
this.getDevList();
})
});
break;
case 'ipmi':
callConfirm('確定刪除此筆設定?', ()=>{
fetch('/api/server/delipmi', getRequest({id}))
.then(response=>response.json())
.then(json => {
if(json.status != 1) return showDialog(json.message);
this.selectDevice(this.state.devSel.id, true);
});
});
break;
}
}
getIPMIData = (id) => {
if(!id) return ;
let {i18n, showDialog, toggleLoading, callConfirm} = this.props;
toggleLoading(1);
fetch('/api/server/getipmiinfo', getRequest({id}))
.then(response=>response.json())
.then(json => {
toggleLoading(0);
if(json.status != 1) return showDialog(json.message);
let ipmi = json.data.record || [];
let sensor = json.data.rt.sensor || [];
let log = json.data.rt.log || [];
let bmcgroup = json.data.rt.bmcgroup || [];
let bmcdata = json.data.rt.bmcdata || [];
this.setState({
ipmiInfo: {
open: true,
log,
sensor,
ipmi,
bmcdata,
bmcgroup
}
})
})
}
runbmctl = (ctlid, ipmuid) => {
if(!ctlid || !ipmuid) return ;
let {i18n, showDialog, toggleLoading, callConfirm} = this.props;
toggleLoading(1);
fetch('/api/server/runbmctl', getRequest({ctlid, ipmuid}))
.then(response=>response.json())
.then(json => {
toggleLoading(0);
if(json.status != 1) return showDialog(json.message);
return showDialog('命令執行完成');
})
}
render() {
let {i18n, showDialog, toggleLoading, callConfirm} = this.props;
return (
<Container fluid>
<Grid>
<Grid.Column width={3}>
<DevList i18n={i18n}
toggleLoading={toggleLoading}
showDialog={showDialog}
callConfirm={callConfirm}
sel={this.state.devSel.id}
selectDevice={this.selectDevice}
list={this.state.list}
openModal={this.openModal}
delData={this.delData} />
</Grid.Column>
<Grid.Column width={13}>
{
this.state.devSel.id != null ?
(
<Container style={{marginBottom: '10px'}}>
<Menu fluid widths={2}>
<Menu.Item name="SNMP"
active={this.state.devSel.type == 'snmp'}
onClick={()=>this.selectDataType('snmp')}/>
<Menu.Item name="IPMI"
active={this.state.devSel.type == 'ipmi'}
onClick={()=>this.selectDataType('ipmi')}/>
</Menu>
</Container>
) : null
}
{this.genSubPage()}
</Grid.Column>
</Grid>
<DevModal i18n={i18n}
open={this.state.devModal.open}
type={this.state.devModal.type}
data={this.state.devModal.data}
closeModal={this.closeModal}
submitModal={this.submitModal} />
<IPMIModal i18n={i18n}
open={this.state.ipmiModal.open}
type={this.state.ipmiModal.type}
data={this.state.ipmiModal.data}
closeModal={this.closeModal}
submitModal={this.submitModal} />
<IPMIInfoModal i18n={i18n}
{...this.state.ipmiInfo}
closeModal={this.closeModal} />
</Container>
)
}
}
export default ServerPage;

View File

@ -22,6 +22,7 @@ const MainMenu = ({i18n, show, toggleMenu, children, permissions, showDashboard,
<MItem toLink="/admin/link" txt={i18n && 't' in i18n ? i18n.t('menu.item.link') : ''} permission={permissions.link} onClick={()=>toggleMenu()} />
<MItem toLink="/admin/ipcam" txt={i18n && 't' in i18n ? i18n.t('menu.item.ipcam') : ''} permission={permissions.ipcam} onClick={()=>toggleMenu()} />
<MItem toLink="/admin/wristband" txt={i18n && 't' in i18n ? i18n.t('menu.item.wristband') : ''} permission={permissions.wristband} onClick={()=>toggleMenu()} />
<MItem toLink="/admin/server" txt="伺服器(Server)" permission={permissions.server} onClick={()=>toggleMenu()} />
<MItem toLink="/admin" txt={i18n && 't' in i18n ? i18n.t('menu.item.logout') : ''} permission={true} onClick={()=>{
sessionStorage.clear();
location.replace('/');

View File

@ -0,0 +1,21 @@
import { connect } from 'react-redux';
import { add_dialog_msg, toggle_loading, add_confirm } from '../../actions';
import ServerPage from '../../components/AdminPage/Server';
const mapStateToProps = (state) => ({
i18n: state.i18n
});
const mapDispatchToProps = (dispatch, ownProps) => ({
showDialog: (msg) => {
dispatch(add_dialog_msg(msg));
},
toggleLoading: (flag = false) => {
dispatch(toggle_loading(flag));
},
callConfirm: (msg, act = null) => {
dispatch(add_confirm(msg, act));
}
})
export default connect(mapStateToProps, mapDispatchToProps)(ServerPage);

View File

@ -17,6 +17,7 @@ import ActionLinkAdd from './containers/AdminPage/ActionLinkAdd';
import IPCam from './containers/AdminPage/IPCam';
import Wristband from './containers/AdminPage/Wristband';
import ModbusPreview from './containers/AdminPage/ModbusPreview';
import ServerPage from './containers/AdminPage/Server';
const Routes = (
<Route path="/admin" component={AdminPage}>
@ -36,6 +37,7 @@ const Routes = (
<Route path="modbuslog" component={ModbusLog} />
<Route path="ipcam" component={IPCam} />
<Route path="wristband" component={Wristband} />
<Route path="server" component={ServerPage} />
</Route>
);