magnusjt/socketty
Composer 安装命令:
composer create-project magnusjt/socketty
包简介
SSH terminal over web sockets
关键字:
README 文档
README
Interactive terminals over websockets with a php backend. It can for instance be used to create interactive SSH sessions, but should work with any command. At the same time, an existing php backend can be used to perform authorization and authentication.
Uses the following tech:
- ratchet - Websockets with PHP
- reactphp - Async IO in PHP through an event loop
- term.js - Terminal emulation in the browser
- reactjs - For the rest of the UI
- python's pty module - For emulating a pty which php can interact with using normal pipes
Usage
The project consists of a PHP backend which manages the client connections, and a frontend which
emulates the terminal. In order to run the backend server, create a composer dependency on this project,
and follow the example in ./server.php:
composer require magnusjt/socketty
Here you can customize:
- Authentication - Implement the AuthenticatorInterface. If you want to reuse sessions from an existing site, you will need to do this through memcached
- Authorization - Same as Authentication, but in this case you may also authorize the command and command arguments.
- Port to use for websockets
- Allowed hosts
- Logging - The project uses the psr LoggerInterface, so anything goes (Monolog is a nice option)
- Spawner - Generates a command string to be executed. Commands can be enabled and disabled here.
Backend example:
See ./server.php
Frontend:
Install by adding the following to npm dependencies:
"socketty": "git://github.com/magnusjt/socketty.git#master"
Frontend example (needs to be compiled with browserify and babelify):
var Socketty = require('socketty');
var domNodeId = 'app'; // ID of the dom node to open the app in
var wssUrl = 'wss://localhost:5678'; // Websocket URL
// Create some presets
var opts = [
{
name: 'SSH',
open: true,
list: [
{cmd: 'ssh vagrant@127.0.0.1', 'name': 'Vagrant SSH'},
]
},
{
name: 'Ping',
open: false,
list: [
{cmd: 'ping 127.0.0.1', 'name': 'Ping localhost'},
]
}
];
Socketty.start(domNodeId, wssUrl, opts);
Development
- Install frontend dependencies with
npm install. - Install backend dependencies with
composer install - Copy and rename a Vagrantfile and vagrant_bootstrap.sh file
- Start virtual server with
vagrant up - Start websocket server with
php server.php - Open browser and go to https://localhost:5678/login.php to pretend to login
- Open browser and go to https://localhost:5678 and spawn some terminals into the virtual server
- Build frontend stuff with
gulp buildandgulp watchify - NB: apache and haproxy may need to be started manually after a reboot:
service httpd start
/usr/local/sbin/haproxy -f /vagrant/haproxy.cfg -p /var/run/haproxy.pid -D
About SSL
In order to have secure web sockets, the vagrant install includes haproxy which terminates all ssl requests.
How it works
First of all, reactphp is used together with an event loop to acheive async calls with PHP. A sub component of reactphp called child-processes uses PHP's proc_open to connect to a child process and its pipes. For programs that require a tty (such as ssh and its interactive password prompt), we would really like to use PHP's pty pipes, but these are sadly not available on most systems. To get around this, all comands are opened through a python script, which uses the pty module to simulate a pty.
magnusjt/socketty 适用场景与选型建议
magnusjt/socketty 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 77 次下载、GitHub Stars 达 8, 最近一次更新时间为 2015 年 09 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ssh web-sockets」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 magnusjt/socketty 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 magnusjt/socketty 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 magnusjt/socketty 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Web-socket server/client with URI parse and multi-process support
A flexible FTP, SSL-FTP, and SSH-based SFTP client for PHP. This lib provides helpers that are easy to use to manage the remote files.
Altax is an extensible deployment tool for PHP.
Cisco IOS communications and configuration parsing library
Node.js web-sockets support
Real-time Messenger package for Laravel
统计信息
- 总下载量: 77
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-11