代码拉取完成,页面将自动刷新
使用WebSocket通过浏览器连接linux,提供灵活的接口,可直接作为一个服务连接通过cmdb获取信息登陆服务器。基于https://github.com/huashengdun/webssh 二次开发
python >=2.7
git clone https://gitee.com/careyjike_173/webssh.git && cd webssh
pip install -r requirements.txt
python main.py
配置文件webssh/conf.py
# 监听地址
listen = '127.0.0.1'
# 监听端口
port = 8888
# debug模式
debug = False
# 日志文件
log_file_prefix = './logs/web_ssh.log'
# 用户信息,用于其它系统请求认证,格式{"username": "password", "username1": "password1"}
auth = {
'admin': 'admin'
}
# jwt secret值
secret = 'zzz'
# cmdb接口地址
cmdb_api = 'http://127.0.0.1:8000/cmdb/get/host/info/api/'
# ws进程延迟等待时间
delay = 3
直接访问
http://127.0.0.1:8888
(按实际配置),填写服务器信息即可登陆API方式
页面需要引用/
页面的css
和js
文件(也可自己实现)
/auth
认证接口, 发送post
请求类型为application/json
获取token
, 返回值格式{"status": "success", "data": "token值", "code": 0}
/
获取资产认证并开启ws进程, 发送post
请求类型为application/json
并将token
值携带到header
中的Token
上请求/
获取id
。 post data
需携带加密信息(服务端会拿着加密信息去CMDB
获取服务器认证信息,需自己和CMDB
系统协调该值), post data
格式{"data": "加密信息"}
发送ws
请求/ws?id=xx
,需携带ID
$.ajax({
url: 'http://127.0.0.1:8888/auth',
dataType: 'json',
contentType: 'application/json',
type: 'post',
data: JSON.stringify({"username": "admin", "password": "admin"}),
success: function (result) {
if (result.code === 0){
token = result.data;
Cookies.set('token', token);
} else {
console.log(result);
layer.msg("获取认证信息错误: "+ result.status)
}
},
error: function () {
layer.msg('请求错误!', {icon: 5})
}
});
$.ajax({
url: 'http://127.0.0.1:8888/',
type: 'post',
data: JSON.stringify(data),
contentType: "application/json",
processData: false,
headers: {
"Token": token
},
success: callback,
error: function () {
layer.closeAll('loading');
layer.msg('请求错误!', {icon: 5})
}
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型