基于Web的ssh客户端
wizardwebssh的Python项目详细描述
简介
一个简单的web应用程序,用作ssh客户端来连接到 ssh服务器。它是用Python编写的,基于tornado,paramiko和 xterm.js公司. 在
特点
- 支持SSH密码认证,包括空密码。在
- 支持SSH公钥身份验证,包括DSA RSA ECDSA Ed25519键。在
- SSH代理支持
- 对SSH配置的Sqlite DB支持。在
- PyQT5多任务终端小部件,用于嵌入到PyQT5应用程序中。在
- 支持加密密钥。在
- 支持双因素认证(基于时间的一次性密码,双推认证)。在
- 终端支持全屏。在
- 终端窗口可调整大小。在
- 自动检测ssh服务器的默认编码。在
- 现代浏览器包括Chrome、Firefox、Safari、Edge、Opera 支持。在
预览
工作原理
+---------+ http +--------+ ssh +-----------+ | browser | <==========> | wizardwebssh | <=======> | ssh server| +---------+ websocket +--------+ ssh +-----------+
要求
- Python 2.7/3.4+
快速启动
- 安装此应用程序,运行命令pip install wizardwebssh
- 启动Web服务器,运行命令wssh
- 打开浏览器,导航到127.0.0.1:8889
- 输入你的数据,提交表格。在
服务器选项
^{pr2}$浏览器控制台
// connect to your ssh server wssh.connect(hostname,port,username,password,privatekey,passphrase,totp);// pass an object to wssh.connect varopts={hostname:'hostname',port:'port',username:'username',password:'password',privatekey:'the private key text',passphrase:'passphrase',totp:'totp'};wssh.connect(opts);// without an argument, wssh will use the form data to connect wssh.connect();// set a new encoding for client to use wssh.set_encoding(encoding);// reset encoding to use the default one wssh.reset_encoding();// send a command to the server wssh.send('ls -l');
自定义字体
要使用自定义字体,请将字体文件放在目录中 wizardwebssh/static/css/fonts/,然后重新启动服务器。在
URL参数
支持通过url(查询或片段)传递参数,如下所示 示例:
传递表单数据(密码必须用base64编码,privatekey不能 支持的)
http://localhost:8889/?hostname=xx&username=yy&password=str_base64_encoded
传递终端背景色
http://localhost:8889/#bgcolor=green
传递用户定义的标题
http://localhost:8889/?title=my-ssh-server
传递编码
http://localhost:8889/#encoding=gbk
传递登录后立即执行的命令
http://localhost:8889/?command=pwd
传递端子类型
http://localhost:8889/?term=xterm-256color
使用Pyqt5 SSH终端小部件
启动wizardwebsh ssh服务
class WizardWebssh(object): """ Threading example class The run() method will be started and it will run in the background until the application exits. """ def __init__(self, interval=1): """ Constructor :type interval: int :param interval: Check interval, in seconds """ self.interval = interval thread = threading.Thread(target=self.run, args=()) thread.daemon = True # Daemonize thread thread.start() # Start the execution def run(self): """ Method that runs forever """ while True: # Start WebSSH Service in background. print('Starting SSH websocket server in the background') import asyncio asyncio.set_event_loop(asyncio.new_event_loop()) from wizardwebssh.main import main as wssh wssh() print('Stopped SSH websocket server in the background') QApplication.processEvents() time.sleep(self.interval) wizardwebssh_service = WizardWebssh() time.sleep(.300)
根据需要嵌入小部件
win = TabbedTerminal() win.show()
复习选项卡bterminal.py对于SSH终端小部件的完整独立工作示例。在
使用Docker
启动应用程序
docker-compose up
关闭应用程序
docker-compose down
测试
要求
pip install pytest pytest-cov codecov flake8 mock
使用unittest运行所有测试
python -m unittest discover tests
使用pytest运行所有测试
python -m pytest tests
部署
在Nginx服务器后面运行
wssh --address='127.0.0.1' --port=8889 --policy=reject
# Nginx config example location/{proxy_passhttp://127.0.0.1:8889;proxy_http_version1.1;proxy_read_timeout300;proxy_set_headerUpgrade$http_upgrade;proxy_set_headerConnection"upgrade";proxy_set_headerHost$http_host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Real-PORT$remote_port;}
作为独立服务器运行
wssh --port=8080 --sslport=4433 --certfile='cert.crt' --keyfile='cert.key' --xheaders=False --policy=reject
提示
- 对于您选择的任何部署选择,不要忘记启用 SSL。在
- 默认情况下,来自公共网络的纯http请求将是 重定向或阻止,并且被重定向优先于 被封锁了。在
- 尝试使用拒绝策略作为缺少的主机密钥策略 你的确认的已知主人,这将防止中间人 攻击。其思想是检查系统主机密钥 文件(~/.ssh/known_hosts)和应用程序主机密钥 如果ssh服务器的主机名不是 找到或密钥不匹配,连接将中止。在
- 项目
标签: