-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
230 lines (213 loc) · 9.74 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, shrink-to-fit=no"/>
<meta name="renderer" content="webkit"/>
<meta name="force-rendering" content="webkit"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<!-- MDUI CSS -->
<link rel="stylesheet" href="https://unpkg.com/mdui@1.0.2/dist/css/mdui.min.css"/>
<link rel="stylesheet" href="main.css"/>
<title>SSH命令执行</title>
<link rel="shortcut icon" href="favicon.svg" type="image/x-icon" />
<script src="/socket.io/socket.io.js"></script>
<script>
let socket;
function connectToServer() {
socket = io();
socket.on('connect', () => {
console.log('实时连接建立');
// mdui snackbar
mdui.snackbar({
message: '实时连接建立',
position: 'top',
timeout: 500
});
});
//连接断开
socket.on('disconnect', () => {
console.log('实时连接断开');
// mdui snackbar
mdui.snackbar({
message: '实时连接断开',
position: 'top',
timeout: 500
});
});
socket.on('output', (data) => {
//将data中的\n替换为<br>
data = data.replace(/\n/g, '<br>');
document.getElementById('output').innerHTML += data;
});
}
function executeCommand() {
// if (!socket) {
connectToServer();
// }
const host = document.getElementById('host').value;
const port = document.getElementById('port').value;
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
const command = document.getElementById('command').value;
document.getElementById('output').innerHTML = '';
socket.emit('execute', command, host, port, username, password);
}
</script>
</head>
<body class="mdui-theme-primary-teal mdui-theme-accent-blue mdui-theme-layout-auto">
<div class="mdui-appbar">
<div class="mdui-toolbar mdui-color-theme">
<a href="/" class="mdui-typo-title">SSH命令执行</a>
<div class="mdui-toolbar-spacer"></div>
<a href="https://github.com/SkyAerope/SSH-Web" target="_blank" class="mdui-btn mdui-btn-icon mdui-ripple mdui-ripple-white" mdui-tooltip="{content: '查看 Github'}">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 36 36" enable-background="new 0 0 36 36" xml:space="preserve" class="mdui-icon" style="width: 24px;height:24px;">
<path fill-rule="evenodd" clip-rule="evenodd" fill="#ffffff" d="M18,1.4C9,1.4,1.7,8.7,1.7,17.7c0,7.2,4.7,13.3,11.1,15.5c0.8,0.1,1.1-0.4,1.1-0.8c0-0.4,0-1.4,0-2.8c-4.5,1-5.5-2.2-5.5-2.2c-0.7-1.9-1.8-2.4-1.8-2.4c-1.5-1,0.1-1,0.1-1c1.6,0.1,2.5,1.7,2.5,1.7c1.5,2.5,3.8,1.8,4.7,1.4c0.1-1.1,0.6-1.8,1-2.2c-3.6-0.4-7.4-1.8-7.4-8.1c0-1.8,0.6-3.2,1.7-4.4c-0.2-0.4-0.7-2.1,0.2-4.3c0,0,1.4-0.4,4.5,1.7c1.3-0.4,2.7-0.5,4.1-0.5c1.4,0,2.8,0.2,4.1,0.5c3.1-2.1,4.5-1.7,4.5-1.7c0.9,2.2,0.3,3.9,0.2,4.3c1,1.1,1.7,2.6,1.7,4.4c0,6.3-3.8,7.6-7.4,8c0.6,0.5,1.1,1.5,1.1,3c0,2.2,0,3.9,0,4.5c0,0.4,0.3,0.9,1.1,0.8c6.5-2.2,11.1-8.3,11.1-15.5C34.3,8.7,27,1.4,18,1.4z"></path>
</svg>
</a>
</div>
</div>
<div class="mdui-container">
<div class="mdui-textfield mdui-textfield-floating-label mdui-col-xs-8 mdui-col-sm-10">
<i class="mdui-icon material-icons">computer</i>
<label class="mdui-textfield-label">主机</label>
<input class="mdui-textfield-input" type="text" id="host" required/>
</div>
<div class="mdui-textfield mdui-textfield-floating-label mdui-col-xs-4 mdui-col-sm-2">
<i class="mdui-icon material-icons">settings_input_hdmi</i>
<label class="mdui-textfield-label">端口</label>
<input class="mdui-textfield-input" type="text" id="port" value="22" required/>
</div>
<div class="mdui-textfield mdui-textfield-floating-label mdui-col-xs-12 mdui-col-sm-12">
<i class="mdui-icon material-icons">account_circle</i>
<label class="mdui-textfield-label">用户名</label>
<input class="mdui-textfield-input" type="text" id="username" required/>
</div>
<div class="mdui-textfield mdui-textfield-floating-label mdui-col-xs-12 mdui-col-sm-12">
<i class="mdui-icon material-icons">vpn_key</i>
<label class="mdui-textfield-label">密码</label>
<input class="mdui-textfield-input" type="password" id="password" required/>
</div>
<!--记住密码选项-->
<div class="mdui-m-l-3">
<label class="mdui-checkbox">
<input type="checkbox" id="rempwd" />
<i class="mdui-checkbox-icon"></i>
记住密码
</label>
</div>
</div>
<div class="mdui-container">
<div class="mdui-row mdui-valign">
<div class="mdui-textfield mdui-textfield-floating-label mdui-col-xs-12 mdui-col-sm-11 mdui-float-left">
<i class="mdui-icon material-icons">code</i>
<label class="mdui-textfield-label">命令</label>
<input class="mdui-textfield-input" type="text" id="command" required/>
</div>
<button class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-theme-accent mdui-hidden-xs mdui-col-sm-1 mdui-center mdui-m-t-3" onclick="executeCommand()">执行</button>
</div>
<!--手机端执行按钮-->
<button class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-theme-accent mdui-hidden-sm-up mdui-col-xs-12 mdui-center" onclick="executeCommand()">执行</button>
</div>
<p></p>
<div class="mdui-container mdui-typo">
<div class="mdui-typo-caption-opacity">将使用wss协议加密传输至后端,由后端代为发送SSH指令。</div>
<div class="mdui-typo-headline mdui-m-l-2">输出</div>
<div class="mdui-card mdui-center">
<div class="mdui-card-content">
<!-- <div class="mdui-card-primary-title">输出</div> -->
<div class="mdui-card-content">
<code id="output"></code>
</div>
</div>
</div>
</div>
<!-- MDUI JavaScript -->
<script src="https://unpkg.com/mdui@1.0.2/dist/js/mdui.min.js"></script>
<!-- 将用户输入存到cookie -->
<script>
function setCookie(cname, cvalue, exdays) {
const d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
const expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
const name = cname + "=";
const ca = document.cookie.split(';');
for(let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1);
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
// 读取cookie并显示至网页
document.getElementById('host').value = getCookie('host');
// 如果不存在port,就设置为22,否则从cookie获取
if (getCookie('port') === '') {
setCookie('port', '22', 365);
} else {
document.getElementById('port').value = getCookie('port');
}
document.getElementById('username').value = getCookie('username');
// 如果勾选了记住密码,就执行从cookie获取密码
if (getCookie('rempwd') === 'true') {
document.getElementById('password').value = getCookie('password');
}
//如果上次勾选了记住密码,就继续勾选
if (getCookie('rempwd') === 'true') {
document.getElementById('rempwd').checked = true;
}
document.getElementById('command').value = getCookie('command');
// 从网页输入写入cookie
document.getElementById('host').onchange = () => {
setCookie('host', document.getElementById('host').value, 365);
};
document.getElementById('port').onchange = () => {
setCookie('port', document.getElementById('port').value, 365);
};
document.getElementById('username').onchange = () => {
setCookie('username', document.getElementById('username').value, 365);
};
// 如果勾选了记住密码,就保存密码
document.getElementById('password').onchange = () => {
if (document.getElementById('rempwd').checked) {
setCookie('password', document.getElementById('password').value, 365);
}
};
// 如果刚刚勾选了记住密码,就先保存密码
document.getElementById('rempwd').onchange = () => {
if (document.getElementById('rempwd').checked) {
//二次确认弹窗
mdui.confirm('<p class="mdui-text-color-red">请注意,密码将以明文形式存储在本地cookie中,如果您的设备被他人使用,您的密码可能会泄露。</p>', '确认记住密码?', () => {},
() => {
// 选择取消则取消打勾
document.getElementById('rempwd').checked = false;
setCookie('rempwd', 'false', 365);
setCookie('password', '', 365);
}, {confirmText: '确认', cancelText: '取消'
});
setCookie('rempwd', 'true', 365);
setCookie('password', document.getElementById('password').value, 365);
} else {
setCookie('rempwd', 'false', 365);
setCookie('password', '', 365);
}
};
// // 选择取消则取消打勾
// function CancelRemPwd(){
// document.getElementById('rempwd').checked = false;
// setCookie('rempwd', 'false', 365);
// setCookie('password', '', 365);
// }
document.getElementById('command').onchange = () => {
setCookie('command', document.getElementById('command').value, 365);
};
</script>
</body>
</html>