update
This commit is contained in:
parent
58057bcfa0
commit
d702c63eb6
@ -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;
|
@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import {Table, Button} from 'semantic-ui-react';
|
||||
|
||||
const SetListItem = ({ i18n, data, openModal, delData }) => {
|
||||
const SetListItem = ({ i18n, data, openModal, delData, bmctl, runbmctl }) => {
|
||||
|
||||
return (
|
||||
<Table.Row>
|
||||
@ -10,6 +10,13 @@ const SetListItem = ({ i18n, data, openModal, delData }) => {
|
||||
<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>
|
||||
|
@ -2,7 +2,7 @@ import React from 'react';
|
||||
import {Container, Segment, Button, Table} from 'semantic-ui-react';
|
||||
import SelListItem from './SetListItem';
|
||||
|
||||
const IPMIPage = ({i18n, list, openModal, delData}) => {
|
||||
const IPMIPage = ({i18n, list, openModal, delData, bmctl, runbmctl}) => {
|
||||
return (
|
||||
<Container>
|
||||
<Segment className="clearfix">
|
||||
@ -16,7 +16,8 @@ const IPMIPage = ({i18n, list, openModal, delData}) => {
|
||||
<Table>
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.HeaderCell>操作</Table.HeaderCell>
|
||||
<Table.HeaderCell>操作</Table.HeaderCell>
|
||||
<Table.HeaderCell>設備操作</Table.HeaderCell>
|
||||
<Table.HeaderCell>IP</Table.HeaderCell>
|
||||
<Table.HeaderCell>帳號</Table.HeaderCell>
|
||||
<Table.HeaderCell>MAC Address</Table.HeaderCell>
|
||||
@ -30,7 +31,9 @@ const IPMIPage = ({i18n, list, openModal, delData}) => {
|
||||
i18n={i18n}
|
||||
data={t}
|
||||
openModal={openModal}
|
||||
delData={delData} />
|
||||
delData={delData}
|
||||
bmctl={bmctl}
|
||||
runbmctl={runbmctl} />
|
||||
)
|
||||
})
|
||||
}
|
||||
|
@ -72,12 +72,14 @@ const BMCContent = ({group, data}) => {
|
||||
</Header>
|
||||
<List>
|
||||
{
|
||||
data.map((t2, idx) => (
|
||||
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>
|
||||
|
@ -9,6 +9,7 @@ import IPMIInfoModal from './Modals/IPMIInfoModal';
|
||||
|
||||
const stateDefault = ()=>({
|
||||
list: [],
|
||||
bmctl: [],
|
||||
devSel: {
|
||||
id: null,
|
||||
type: null,
|
||||
@ -42,6 +43,7 @@ class ServerPage extends React.Component {
|
||||
|
||||
componentDidMount(){
|
||||
this.getDevList();
|
||||
this.getBMCtl();
|
||||
}
|
||||
|
||||
getDevList = () => {
|
||||
@ -58,6 +60,18 @@ class ServerPage extends React.Component {
|
||||
})
|
||||
}
|
||||
|
||||
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;
|
||||
@ -106,7 +120,9 @@ class ServerPage extends React.Component {
|
||||
list={this.state.devSel.data.ipmi}
|
||||
openModal={this.openModal}
|
||||
closeModal={this.closeModal}
|
||||
delData={this.delData} />
|
||||
delData={this.delData}
|
||||
bmctl={this.state.bmctl}
|
||||
runbmctl={this.runbmctl} />
|
||||
|
||||
default:
|
||||
return null;
|
||||
@ -246,6 +262,19 @@ class ServerPage extends React.Component {
|
||||
})
|
||||
}
|
||||
|
||||
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 (
|
||||
|
Loading…
Reference in New Issue
Block a user