-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
100 lines (82 loc) · 2.86 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>cmd demo</title>
<script type="text/javascript" src="lib/jquery.js"></script>
<script type="text/javascript" src="lib/socket.io.js"></script>
<style type="text/css">
*{padding: 0; margin: 0;}
#wrapper{width:910px; margin:0 auto;}
#cmdBox{width:500px; float:left;}
#logBox {width:400px;height:370px; border: 1px solid #ccc; float:left;overflow: auto;margin-top: 38px;}
#logBox p {background: #eee; margin: 2px;font-size: 14px;font-family: Verdana, Arial, Helvetica, sans-serif;}
#logBox span {background: #393; color:#fff;}
#cmdInput {width: 81%; height: 20px;}
button {width: 9%; height:24px;}
#result {background: #eee; height: 350px; overflow-y: scroll;}
</style>
</head>
<body>
<div id="wrapper">
<div id="cmdBox">
<h1>Server Terminal</h1>
<pre id="result"></pre>
<input id="cmdInput" value="ping 172.30.1.7" autofocus /><button id="sendBtn">执行</button><button id="stopBtn">stop</button><br>
</div>
<div id="logBox"></div>
</div>
<script type="text/javascript">
$(function(){
var s=io();
s.on('connect',function(){
$('#result').append('>>> 客户端请求连接: connecting..\n')
});
s.on('error',function(){
$('#result').append('>>> 客户端请求失败: error.\n')
});
s.on('disconnect',function(){
$('#result').append('>>> 客户端断开链接: disconnect.\n')
});
s.on('message',function(m){
var dom=$('#result')
dom.append(m);
dom.scrollTop( dom[0].scrollHeight );//滚轮置底
})
//-------------------------
function runBtn(){
var time = js_yyyy_mm_dd_hh_mm_ss();
var cmd= $('#cmdInput').val();
$('#logBox').append('<p><span>['+ time +']</span> <b>'+ cmd+'</b></p>')
s.send($('#cmdInput').val());
}
$('#sendBtn').click(runBtn);
enterRun('#cmdInput', runBtn)
$('#stopBtn').click(function(){
s.send('[!!stop]');
})
//-------------------------
function enterRun(dom,callback){
$(dom).keydown(function(e){
var curKey = e.which;
if(curKey == 13){
callback();
return false;
}
});
}
//-------------------------
function js_yyyy_mm_dd_hh_mm_ss () {
now = new Date();
year = "" + now.getFullYear();
month = "" + (now.getMonth() + 1); if (month.length == 1) { month = "0" + month; }
day = "" + now.getDate(); if (day.length == 1) { day = "0" + day; }
hour = "" + now.getHours(); if (hour.length == 1) { hour = "0" + hour; }
minute = "" + now.getMinutes(); if (minute.length == 1) { minute = "0" + minute; }
second = "" + now.getSeconds(); if (second.length == 1) { second = "0" + second; }
return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
}
});
</script>
</body>
</html>