Skip to content

Commit 34f2e47

Browse files
committed
2018年 03月 15日 星期四 23:40:15 CST修改一些逻辑
1 parent 6d1a4e7 commit 34f2e47

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

app.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const bodyParser = require('body-parser')
55
const { exec } = require('child_process')
66
const pug = require('pug')
77
const port = 8001
8+
const test = require('./model/port')
89
app.use(bodyParser.urlencoded({extended: false}));
910
app.use(bodyParser.json())
1011
app.use(express.static(path.join(__dirname,'')))
@@ -15,9 +16,7 @@ if("psinfo"==flag){
1516
exec("top -b -n 1 | head -n 30 | tail -n 30",(err,stdout,stderr)=>{
1617
res.json({"data":stdout});}
1718
)}else if ("sysinfo"==flag){
18-
exec("uname -a",(err,stdout,stderr)=>{
19-
res.json({"data":stdout});
20-
})
19+
res.json(test.getPort())
2120
}
2221
})
2322
//配置相关接口

model/port.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var execSync = require('child_process').execSync;
2+
module.exports={
3+
getPort:function(){
4+
var result = execSync('./raspi/port.sh').toString().split(',').join(',')
5+
return {
6+
data:result
7+
8+
}
9+
}
10+
}

raspi/magic.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,22 @@ check_sys(){
1717
fi
1818
}
1919

20+
#检查端口是否已经被使用
21+
check_port(){
22+
if lsof -Pi :8080 -sTCP:LISTEN -t >dev/null;then
23+
curr_port="1"
24+
else
25+
curr_port="0"
26+
fi
27+
}
28+
2029
#每次运行前先清除log
2130
if [ -f $log ];then
2231
rm ../log/magic.log
2332
fi
2433
check_root
2534
check_sys
35+
check_port
2636
if [[ ${sys_info} == "raspbian" ]];then
2737
if [ ! -d $dir ];then
2838
if [ -e $file ];then

raspi/port.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
#得到当前系统正在被使用的端口port
3+
lsof -i -P -n | grep LISTEN | awk '{print $9}' | awk -F ':' 'BEGIN {ORS=","};{print $2}'

view/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<script type="text/javascript">
3131
window.onload=function(){
3232

33+
console.log(window.location.hostname+"xxxxxxxxxxxxxx");
3334
$.ajax({
3435
type:"post",
3536
data:{flag:"sysinfo"},
@@ -95,7 +96,7 @@
9596
}
9697
$('#magic_panel').addClass('panel_current')
9798
if(result.data && result.data.status){
98-
$('.magic_status:first').html(result.data.status+"<a style='color:red' target='_blank' href='http://localhost:8080/'>访问魔镜</a>")
99+
$('.magic_status:first').html(result.data.status+"<a style='color:red' target='_blank' href='http://"+window.location.hostname+":8080'>访问魔镜</a>")
99100
if(1==result.data.type){
100101
$(".magic_start").css('display','none')
101102
$(".magic_stop").css('display','block')
@@ -127,6 +128,9 @@
127128
function stopMagic(){
128129
swal('魔镜正在停止...')
129130
}
131+
function hostname(){
132+
return window.location.hostname+":8080"
133+
}
130134
//左侧导航事件
131135
$(function(){
132136

0 commit comments

Comments
 (0)