37 Star 181 Fork 68

careyjike / webssh

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

webssh

项目介绍

使用WebSocket通过浏览器连接linux,提供灵活的接口,可直接作为一个服务连接通过cmdb获取信息登陆服务器。基于https://github.com/huashengdun/webssh 二次开发

python版本

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方式

    • 页面需要引用/页面的cssjs文件(也可自己实现)

    • /auth 认证接口, 发送post请求类型为application/json获取token, 返回值格式{"status": "success", "data": "token值", "code": 0}

    • / 获取资产认证并开启ws进程, 发送post请求类型为application/json并将token值携带到header中的Token上请求/获取idpost data需携带加密信息(服务端会拿着加密信息去CMDB获取服务器认证信息,需自己和CMDB系统协调该值), post data格式{"data": "加密信息"}

    • 发送ws请求/ws?id=xx,需携带ID

js例子
  • 获取认证信息
$.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})
  }
});
  • 获取资产认证信息并生成ws进程
$.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})
  }
});
The MIT License (MIT) Copyright (c) 2018 careyjike Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

使用WebSocket通过浏览器连接linux,提供灵活的接口,可直接作为一个服务连接通过cmdb获取信息登陆服务器。 展开 收起
Python 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/careyjike_173/webssh.git
git@gitee.com:careyjike_173/webssh.git
careyjike_173
webssh
webssh
master

搜索帮助