代码拉取完成,页面将自动刷新
同步操作将从 we452366/广域网管理系统 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
const express = require('express');
const request = require('request');
const app = express();
const bodyParser = require('body-parser');
const router = express.Router();
const SUCC_REG = /^2[0-9]{2}$/
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
const headers = {
'authorization': "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZmEzYTY5OGZjNDI2ODEwODc3MDYzZDQiLCJ1c2VybmFtZSI6Im1jYWlkYW9Ac2luYS5jb20iLCJvcmciOiI1ZmFkZTkyZDljNGQ2MDQyOWRjN2RhNmMiLCJvcmdOYW1lIjoidHQiLCJhY2NvdW50IjoiNWZhM2E2OThmYzQyNjgxMDg3NzA2M2QzIiwiYWNjb3VudE5hbWUiOiJ0ZXN0IiwicGVybXMiOnsiam9icyI6MTUsImJpbGxpbmciOjMsImFjY291bnRzIjo3LCJvcmdhbml6YXRpb25zIjoxNSwiZGV2aWNlcyI6MTUsInRva2VucyI6MTUsImFwcGlkZW50aWZpY2F0aW9ucyI6MTUsIm1lbWJlcnMiOjE1LCJ0dW5uZWxzIjoxNSwiYWNjZXNzdG9rZW5zIjoxNSwibm90aWZpY2F0aW9ucyI6MTUsInBhdGhsYWJlbHMiOjE1LCJtbHBvbGljaWVzIjoxNX0sImlhdCI6MTYwODExMjcwMiwiZXhwIjoxNjA4NzE3NTAyfQ.LYFv1pBP1540gb-NRCCe4dvbQ0T9HSoZHMkD8xkMFLc",
'Content-Type': 'application/json'
},
errMsg = {
msg:'unexpected response'
},
baseUrl = 'https://10.100.37.101:3443';
// 获取所有设备接口
app.get('/api/devices',(req,res)=> {
console.log(req.url)
request({
url: `${baseUrl}${req.url}`,
method: 'GET',
headers
}, (err, response, body) => {
console.log(response.statusCode)
if(SUCC_REG.test(response.statusCode)) {
res.send({code: 200,msg:JSON.parse(response.body)})
} else {
res.send(errMsg)
}
})
});
// 获取单个设备接口
app.get('/api/devices/:id',(req,res)=> {
console.log(req.url)
request({
url: `${baseUrl}${req.url}`,
method: 'GET',
headers
}, (err, response, body) => {
console.log(response.statusCode)
if(SUCC_REG.test(response.statusCode)) {
res.send({code: 200,msg:JSON.parse(response.body)})
} else {
res.send(errMsg)
}
})
});
// 获取路由接口
app.get('/api/devices/:id/routes',(req,res)=> {
console.log(req.url)
request({
url: `https://10.100.37.101:3443/api/devices/${req.params.id}/routes`,
method: 'GET',
headers
}, (err, response, body) => {
console.log(response.statusCode)
if(SUCC_REG.test(response.statusCode)) {
res.send({code: 200,msg:JSON.parse(response.body)})
} else {
res.send(errMsg)
}
})
});
// 启动单个设备
app.post('/api/devices/:id/apply/start',(req,res)=> {
console.log(req.url);
request({
url: `${baseUrl}/api/devices/${req.params.id}/apply`,
method: 'POST',
headers,
body: JSON.stringify({
"method": "start"
})
}, (err, response, body) => {
let r = JSON.parse(body)
if(r.status == 'completed') {
res.send({code: 200,msg:'start success'})
} else {
res.send({msg: 'start error'})
}
})
});
// 停止单个设备
app.post('/api/devices/:id/apply/stop',(req,res)=> {
console.log(req.url)
request({
url: `${baseUrl}/api/devices/${req.params.id}/apply`,
method: 'POST',
headers,
body: JSON.stringify({
"method": "stop"
})
}, (err, response, body) => {
let r = JSON.parse(body)
if(r.status == 'completed') {
res.send({code: 200,msg:'stop success'})
} else {
res.send({msg: 'stop error'})
}
})
});
// 同步单个设备
app.post('/api/devices/:id/apply',(req,res)=> {
console.log(req.url)
request.post({
url: `${baseUrl}${req.url}`,
headers,
body: JSON.stringify({
"method": "sync"
})
}, (err, response, body) => {
let r = JSON.parse(body)
if(r.status == 'completed') {
res.send({code: 200,msg:'update success'})
} else {
res.send({msg: 'update error'})
}
})
});
// 删除单个设备
app.delete('/api/devices/:id',(req,res)=> {
console.log(req.url)
request({
url: `${baseUrl}${req.url}`,
method: 'DELETE',
headers
}, (err, response, body) => {
console.log(response.statusCode)
if(SUCC_REG.test(response.statusCode)) {
res.send({code: 200,msg:JSON.parse(response.body)})
} else {
res.send(errMsg)
}
})
});
// 更新设备详情
app.put('/api/devices/:id',(req,res)=> {
request({
url: `${baseUrl}${req.url}`,
method: 'PUT',
headers,
body: JSON.stringify(req.body)
}, (err, response, body) => {
console.log('put device', response.statusCode)
if(SUCC_REG.test(response.statusCode)) {
res.send({code: 200,msg:JSON.parse(response.body)})
} else {
res.send(errMsg)
console.log('error device', response.statusCode, response.body)
}
})
});
// 删除隧道接口
app.post('/api/devices/apply/delTunnel',(req,res)=> {
console.log('req.body', req.body)
request.post({
url: `${baseUrl}/api/devices/apply`,
headers,
body: JSON.stringify(req.body)
}, (err, response, body) => {
let r = JSON.parse(body)
console.log(r)
if(r.status == 'completed') {
res.send({code: 200,msg:'删除隧道成功'})
} else {
res.send({msg: r.error})
}
})
});
// 建立隧道接口
app.post('/api/devices/apply/createTunnel',(req,res)=> {
console.log(req.body)
request.post({
url: `${baseUrl}/api/devices/apply`,
headers,
body: JSON.stringify(req.body)
}, (err, response, body) => {
let r = JSON.parse(body)
console.log(r)
if(r.status == 'completed') {
res.send({code: 200,msg:r.message})
} else {
res.send({msg: r.error})
}
})
});
// 获取所有隧道接口
app.get('/api/tunnels',(req,res)=> {
console.log(req.url)
request({
url: `${baseUrl}${req.url}`,
method: 'GET',
headers
}, (err, response, body) => {
console.log(response.statusCode)
if(SUCC_REG.test(response.statusCode)) {
res.send({code: 200,msg:JSON.parse(response.body)})
} else {
res.send(errMsg)
}
})
});
app.listen(6000, '127.0.0.1', ()=>{
console.log('app server');
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。