Skip to content

Commit

Permalink
ttyd-express initial patch
Browse files Browse the repository at this point in the history
  • Loading branch information
santosh0705 committed Sep 28, 2018
1 parent 1f6a6c7 commit 98362e2
Show file tree
Hide file tree
Showing 29 changed files with 4,760 additions and 5,345 deletions.
19 changes: 19 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Cmake files
CMakeCache.txt
CMakeFiles
CMakeScripts
cmake_install.cmake
install_manifest.txt
CTestTestfile.cmake
build

# Files not required for build
.git
.gitattributes
.gitignore
.travis.yml
LICENSE
README.md
config.json
html
screenshot.gif
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM ubuntu:16.04
LABEL maintainer "Shuanglei Tao - [email protected]"

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
Expand All @@ -16,7 +15,7 @@ RUN apt-get update \
libwebsockets-dev \
pkg-config \
vim-common \
&& git clone --depth=1 https://github.com/tsl0922/ttyd.git /tmp/ttyd \
&& git clone --depth=1 https://github.com/santosh0705/ttyd-express.git /tmp/ttyd \
&& cd /tmp/ttyd && mkdir build && cd build \
&& cmake -DCMAKE_BUILD_TYPE=RELEASE .. \
&& make \
Expand Down
54 changes: 54 additions & 0 deletions Dockerfile-static
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
FROM alpine:3.8 as builder

COPY . /ttyd-express/

RUN set -exo pipefail; \
\
apk add --update --no-cache \
autoconf automake bash bsd-compat-headers linux-headers \
build-base ca-certificates cmake curl file g++ libtool vim; \
\
curl -sLo- https://github.com/json-c/json-c/archive/json-c-0.13.1-20180305.tar.gz | tar xz; \
cd json-c-json-c-0.13.1-20180305; \
env CFLAGS=-fPIC ./configure; \
make install; \
cd ..; \
\
curl -sLo- https://zlib.net/zlib-1.2.11.tar.gz | tar xz; \
cd zlib-1.2.11; \
./configure; \
make install; \
cd ..; \
\
curl -sLo- https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-2.7.4.tar.gz | tar xz; \
cd libressl-2.7.4; \
cmake -DLIBRESSL_APPS=OFF -DLIBRESSL_TESTS=OFF; \
make install; \
cd ..; \
\
curl -sLo- https://github.com/warmcat/libwebsockets/archive/v3.0.1.tar.gz | tar xz; \
cd libwebsockets-3.0.1; \
cmake -DLWS_WITHOUT_TESTAPPS=ON -DLWS_STATIC_PIC=ON -DLWS_UNIX_SOCK=ON; \
make install; \
cd ..; \
sed -i 's/ websockets_shared//' /usr/local/lib/cmake/libwebsockets/LibwebsocketsConfig.cmake; \
\
cd /ttyd-express; \
sed -i '5s;^;\nSET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")\nSET(CMAKE_EXE_LINKER_FLAGS "-static")\n;' CMakeLists.txt; \
cmake .; \
make; \
make install; \
strip -s /usr/local/bin/ttyd;

FROM alpine:3.8

COPY --from=builder /usr/local/bin/ttyd /usr/bin/ttyd

RUN set -ex; \
apk add --no-cache \
dropbear-dbclient; \
chmod +x /usr/bin/ttyd

CMD ["/bin/sh"]

ENTRYPOINT ["/usr/bin/ttyd"]
68 changes: 28 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# ttyd - Share your terminal over the web [![Build Status](https://travis-ci.org/tsl0922/ttyd.svg?branch=master)](https://travis-ci.org/tsl0922/ttyd)
> **NOTE:** This project is forked from https://github.com/tsl0922/ttyd [release version 1.4.2][21]. The HTML client application has been re-written, added configuration file option, added option to run a single ttyd-express instance which can serve multiple commands configured on different URL endpoints and fixed some issues & added some improvements. Each command can be configured in a JSON configuration file (sample configuration file included) and command parameters could be templated. The template variables should be passed as URL GET query values. If running ttyd-express without configuration file option than the command will be served on webroot. The original ttyd could be replaced with ttyd-express without any changes.
ttyd is a simple command-line tool for sharing terminal over the web, inspired by [GoTTY][1].

![screenshot](https://github.com/tsl0922/ttyd/raw/master/screenshot.gif)
> **CREDITS:** This project is derived from open source [ttyd][20] project hosted on github and all the credits goes to the original author(s) of the project. You can find the source code of their open source projects along with license information in the project repository mentioned above. I acknowledge and are grateful to the developer(s) for their contributions to open source.
# ttyd-express: Share your terminal over the web

ttyd-express is a simple command-line tool for sharing terminal over the web, it has been forked from [ttyd][20]. The original ttyd project is inspired by [GoTTY][1].

![screenshot](https://github.com/santosh0705/ttyd-express/raw/master/screenshot.gif)

# Features

- Built on top of [Libwebsockets][2] with C for speed
- Fully-featured terminal based on [Xterm.js][3] with [CJK][18] and IME support
- Graphical [ZMODEM][16] integration with [lrzsz][17] support
- SSL support based on [OpenSSL][4]
- SSL support based on [OpenSSL][4], (LibreSSL also works)
- Run any custom command with options
- Basic authentication support and many other custom options
- Cross platform: macOS, Linux, FreeBSD/OpenBSD, [OpenWrt][5]/[LEDE][6], Windows
Expand All @@ -18,29 +23,16 @@ ttyd is a simple command-line tool for sharing terminal over the web, inspired b

## Install on macOS

Install with [homebrew][7]:

```bash
brew install ttyd
```
Not yet tested. Check the original project for details on compiling it yourself.

## Install on Linux

- Install from ppa (ubuntu 16.04 and later):

```bash
sudo apt-get install -y software-properties-common
sudo add-apt-repository ppa:tsl0922/ttyd-dev
sudo apt-get update
sudo apt-get install ttyd
```

- Build from source (debian/ubuntu):

```bash
sudo apt-get install cmake g++ pkg-config git vim-common libwebsockets-dev libjson-c-dev libssl-dev
git clone https://github.com/tsl0922/ttyd.git
cd ttyd && mkdir build && cd build
git clone https://github.com/santosh0705/ttyd-express.git
cd ttyd-express && mkdir build && cd build
cmake ..
make && make install
```
Expand All @@ -49,27 +41,18 @@ brew install ttyd

## Install on Windows

ttyd can be built with [MSYS2][10] on windows, The build instructions is [here][13].

> **NOTE:** Native windows console programs may not work correctly due to [pty incompatibility issues][11].
As a workaround, you can use [winpty][12] as a wrapper to invoke the windows program, eg: `ttyd winpty cmd`.
Not yet tested. Check the original project for details on compiling it yourself.

## Install on OpenWrt/LEDE

[LEDE][6] `17.01.0` and later:

```bash
opkg install ttyd
```

If the install command fails, you can [compile it yourself][14].
Not yet tested. Check the original project for details on compiling it yourself.

# Usage

## Command-line Options

```
ttyd is a tool for sharing terminal over the web
ttyd-express is a tool for sharing terminal over the web
USAGE:
ttyd [options] <command> [<arguments...>]
Expand All @@ -78,16 +61,17 @@ VERSION:
1.4.2
OPTIONS:
-f, --conf-file Configuration file path (eg: /etc/ttyd/config.json)
-p, --port Port to listen (default: 7681, use `0` for random port)
-i, --interface Network interface to bind (eg: eth0), or UNIX domain socket path (eg: /var/run/ttyd.sock)
-c, --credential Credential for Basic Authentication (format: username:password)
-u, --uid User id to run with
-g, --gid Group id to run with
-s, --signal Signal to send to the command when exit it (default: 1, SIGHUP)
-r, --reconnect Time to reconnect for the client in seconds (default: 10)
-r, --reconnect Time to reconnect for the client in seconds (default: 10, disable reconnect: <= 0)
-R, --readonly Do not allow clients to write to the TTY
-t, --client-option Send option to client (format: key=value), repeat to add more options
-T, --terminal-type Terminal type to report, default: xterm-256color
-T, --terminal-type Terminal type to report, default: xterm-color
-O, --check-origin Do not allow websocket connection from different origin
-m, --max-clients Maximum clients to support (default: 0, no limit)
-o, --once Accept only one client and exit on disconnection
Expand All @@ -101,12 +85,13 @@ OPTIONS:
-v, --version Print the version and exit
-h, --help Print this text and exit
Visit https://github.com/tsl0922/ttyd to get more information and report bugs.
Visit https://github.com/santosh0705/ttyd-express to get more information and report bugs.
ttyd-express is a fork of ttyd project: https://github.com/tsl0922/ttyd
```
## Example Usage
ttyd starts web server at port `7681` by default, you can use the `-p` option to change it, the `command` will be started with `arguments` as options. For example, run:
ttyd-express starts web server at port `7681` by default, you can use the `-p` option to change it, the `command` will be started with `arguments` as options. For example, run:
```bash
ttyd -p 8080 bash -x
Expand Down Expand Up @@ -143,7 +128,7 @@ openssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.p12
openssl pkcs12 -in client.p12 -out client.pem -clcerts
```
Then start ttyd:
Then start ttyd-express:
```bash
ttyd --ssl --ssl-cert server.crt --ssl-key server.key --ssl-ca ca.crt bash
Expand All @@ -156,15 +141,16 @@ curl --insecure --cert client.p12[:password] -v https://localhost:7681
If you don't want to enable client certificate verification, remove the `--ssl-ca` option.
## Docker and ttyd
## Docker and ttyd-express
Docker containers are jailed environments which are more secure, this is useful for protecting the host system, you may use ttyd with docker like this:
Docker containers are jailed environments which are more secure, this is useful for protecting the host system, you may use ttyd-express with docker like this:
- Sharing single docker container with multiple clients: `docker run -it --rm -p 7681:7681 tsl0922/ttyd`.
- Sharing single docker container with multiple clients: `docker run -it --rm -p 7681:7681 santosh0705/ttyd-express`.
- Creating new docker container for each client: `ttyd docker run -it --rm ubuntu`.
# Credits
- [ttyd][20]: ttyd-express is a fork of ttyd with some improvements.
- [GoTTY][1]: ttyd is a port of GoTTY to `C` language with many improvements.
- [Libwebsockets][2]: is used to build the websocket server.
- [Xterm.js][3]: is used to run the terminal emulator on the web, [hterm][8] is used previously.
Expand All @@ -188,3 +174,5 @@ Docker containers are jailed environments which are more secure, this is useful
[17]: https://ohse.de/uwe/software/lrzsz.html
[18]: https://en.wikipedia.org/wiki/CJK_characters
[19]: https://cmake.org/
[20]: https://github.com/tsl0922/ttyd
[21]: https://github.com/tsl0922/ttyd/tree/1.4.2
22 changes: 22 additions & 0 deletions config.json.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"listen": {
"port": 3000,
"ip": "127.0.0.1"
},
"terminal": {
"cursorBlink": true,
"cursorStyle": "underline",
"scrollback": 1000,
"tabStopWidth": 8,
"bellStyle": "sound"
},
"service": {
"/": {
"command": "/bin/login"
},
"/ssh/": {
"command": "/usr/bin/ssh",
"args": ["{user}@{host}"]
}
}
}
3 changes: 3 additions & 0 deletions html/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "standard"
}
Binary file removed html/favicon.png
Binary file not shown.
22 changes: 11 additions & 11 deletions html/gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const gulp = require('gulp'),
clean = require('gulp-clean'),
inlinesource = require('gulp-inline-source');
const gulp = require('gulp')
const clean = require('gulp-clean')
const inlinesource = require('gulp-inline-source')

gulp.task('clean', function () {
return gulp.src('dist', {read: false})
.pipe(clean());
});
return gulp.src('dist', { read: false, allowEmpty: true })
.pipe(clean())
})

gulp.task('inlinesource', function () {
return gulp.src('dist/index.html')
.pipe(inlinesource())
.pipe(gulp.dest('../src/'));
});
return gulp.src('dist/index.html')
.pipe(inlinesource())
.pipe(gulp.dest('../src/'))
})

gulp.task('default', ['inlinesource']);
gulp.task('default', gulp.parallel('inlinesource'))
45 changes: 0 additions & 45 deletions html/index.html

This file was deleted.

Loading

0 comments on commit 98362e2

Please sign in to comment.