witty/README.md

121 lines
6.2 KiB
Markdown
Raw Permalink Normal View History

2022-01-26 18:00:24 +01:00
<mark>**WiTTY: Web-based interactive TTY**<mark>
2022-01-17 03:17:51 +01:00
2022-01-26 18:00:24 +01:00
# Introduction
2022-01-17 22:19:53 +01:00
2022-01-26 18:00:24 +01:00
This program allows you to use terminal in the browser. Simply run the program and give it the command to execute when users connect via the browser. The design goal of this tool is to help teaching courses that use Unix-like CLI environment. WiTTY has the following features that distinguish itself from other similar tools:
1. WiTTY allows users to **easily record, replay, and share console sessions** with just a few clicks. This make it a breeze to answer course-related questions. Instead of wall of text to describe their questions, students can just send a recorded session.
2. It allows others to **view ongoing interactive sessions**. This is useful for providing live remote help.
>A challenge of this use case is that our home networks are almost always behind NAT, making it difficult to run WiTTY as a publicly accessible server. Security is also potentially a concern.
3. Great attention has been paid to ensure the cleanses of the code. This, hopefully, provides a useful example of **Do as I say and as I do**.
# User Interface
2022-01-26 18:11:30 +01:00
You can use WiTTY to run any command line programs, such as ```bash```, ```htop```, ```vi```, ```ssh```. This screenshot shows the main page of WiTTY after login. There are two tabs that list live and recorded sessions, respectively. You can click ```New Session``` to create a new interactive session. Click the <img src="assets/img/view.svg" width="16px"> icon of an interactive session opens a read-only view of that session.
<img src="extra/main.png" width="800px">
2022-01-17 22:19:53 +01:00
2022-01-26 18:00:24 +01:00
On the interactive terminal window, you can record an ongoing session.
2022-01-17 22:19:53 +01:00
2022-01-26 18:11:30 +01:00
<img src="extra/interactive.png" width="800px">
2022-01-17 22:19:53 +01:00
2022-01-26 18:00:24 +01:00
This screenshot shows three recorded sessions, you can replay <img src="assets/img/play.svg" width="16px">, download <img src="assets/img/download.svg" width="16px">, rename <img src="assets/img/edit.svg" width="16px">, and delete <img src="assets/img/delete.svg" width="16px"> recorded session.
2022-01-17 22:19:53 +01:00
2022-01-26 18:11:30 +01:00
<img src="extra/view.png" width="800px">
2022-01-17 03:17:51 +01:00
2022-01-18 14:59:32 +01:00
Here is a recorded session, where we domonstrate how to use the command line replay utility (in ```cmd/replay```) to replay another recorded session that sshes into a Raspberry Pi running
2022-01-26 18:00:24 +01:00
[pi-hole](https://pi-hole.net/). You can fully control the playback using the progress bar.
2022-01-18 14:59:32 +01:00
>The inception is strong with this one!
2022-01-17 03:17:51 +01:00
2022-01-26 18:11:30 +01:00
<img src="extra/replay.gif" width="800px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
2022-01-26 18:00:24 +01:00
2022-01-17 03:17:51 +01:00
<!--
commands to create high quality gif from mkv/mp4 files
ffmpeg -i replay.mkv -vf palettegen palette.png
ffmpeg -i replay.mkv -i palette.png -lavfi paletteuse output.gif
gifsicle -O3 .\output.gif -o replay.gif
-->
2022-01-12 03:18:19 +01:00
2022-01-12 03:38:09 +01:00
This program is written in the [go programming language](https://go.dev/), using the
[Gin web framework](https://github.com/gin-gonic/gin), [gorilla/websocket](https://github.com/gorilla/websocket), [pty](https://github.com/creack/pty), and the wonderful [xterm.js](https://xtermjs.org/)!
2022-01-06 00:04:37 +01:00
The workflow is simple, the client will initiate a terminal
2022-01-12 03:38:09 +01:00
window (xterm.js) and create a websocket with the server, which relays the data between pty and xterm. You can customize the look and feel of the HTML pages by editing files under the ```assets``` directory.
2022-01-06 00:04:37 +01:00
2022-01-26 18:00:24 +01:00
The program has been tested on Linux, WSL2, Raspberry Pi 3B (Debian), and MacOSX using Google Chrome, Firefox, and Safari.
2022-01-18 14:21:37 +01:00
Most icons were provided by [fontawesome](https://fontawesome.com/) under this [license](https://fontawesome.com/license).
2022-01-06 00:04:37 +01:00
2022-01-26 18:00:24 +01:00
# Installation
2022-01-07 15:00:44 +01:00
2022-01-23 00:21:59 +01:00
1. Install the [go](https://go.dev/) compiler. __Make sure you have go 1.17 or higher.__
2022-01-12 03:18:19 +01:00
2. Download the release and unzip it, or clone the repo
```git clone https://github.com/syssecfsu/witty.git```
2022-01-07 15:00:44 +01:00
2022-01-26 18:11:30 +01:00
3. WiTTY uses TLS to protect its traffic. You can request a free [Let's Encrypt](https://letsencrypt.org/) cert or use a self-signed cert. Here is how to create a self-signed cert in the ```tls``` sub-directory:
2022-01-12 03:18:19 +01:00
\# Generate a private key for a curve
2022-01-07 15:00:44 +01:00
2022-01-12 03:18:19 +01:00
```openssl ecparam -name prime256v1 -genkey -noout -out private-key.pem```
2022-01-07 15:00:44 +01:00
2022-01-12 03:18:19 +01:00
\# Create a self-signed certificate
2022-01-07 02:34:37 +01:00
2022-01-12 03:18:19 +01:00
```openssl req -new -x509 -key private-key.pem -out cert.pem -days 360```
2022-01-07 02:37:57 +01:00
2022-01-12 03:18:19 +01:00
4. Return to the root directory of the source code and build the program
```go build .```
2022-01-07 02:34:37 +01:00
2022-01-22 03:42:22 +01:00
5. Add a user to the user accounts, follow the instructions on screen to provide the password
```./witty adduser <username>```
2022-01-26 18:00:24 +01:00
6. Start the server and give it the command to run. By default, the server listens on 8080 (you can override it with the ```-p/-port``` option):
2022-01-12 03:18:19 +01:00
2022-01-22 03:42:22 +01:00
```./witty run htop``` or
2022-01-26 18:00:24 +01:00
```./witty run -p 9000 ssh <ssh_server_ip> -l <user_name>```
2022-01-22 03:42:22 +01:00
If so desired, you can disable user authenticate with ```-n/-naked```, (not recommended) for example:
2022-01-06 00:04:37 +01:00
2022-01-23 00:21:59 +01:00
```./witty run -naked htop```
2022-01-06 00:04:37 +01:00
2022-01-26 18:00:24 +01:00
7. Connect to the server with your browser at port 8080 or the one specified in step 6, for example
2022-01-23 00:21:59 +01:00
2022-01-26 18:00:24 +01:00
```https://<witty_server_ip>:8080```
2022-01-23 00:21:59 +01:00
2022-01-26 18:00:24 +01:00
# User Authentication
2022-01-12 03:18:19 +01:00
2022-01-26 18:00:24 +01:00
WiTTY uses username/password based authentication. The user database is stored in ```user.db```. The passwords are salted with 64 bytes of random characters and then hashed using SHA256. WiTTY has three sub-commands to manage ```user.db```.
2022-01-12 03:18:19 +01:00
2022-01-26 18:00:24 +01:00
- ```witty adduser <username>```
- ```witty deluser <username>```
- ```witty listusers```
2022-01-22 15:29:01 +01:00
2022-01-26 18:11:30 +01:00
They are pretty self-explanatory. Just follow the instructions on screen. Note that passwords must be 12 bytes or longer.
2022-01-26 18:00:24 +01:00
# Recorded Sessions
WiTTY provides two sub-commands to merge and replay recorded sessions.
- ```witty replay -w <wait_time> <recorded_session>```
- ```witty merge -o <output_file> <record1> <record2> ...```
Recorded sessions often have long delay between outputs. You can set wait_time to limit the maximum wait time between outputs, to speed up the replay.
2022-01-26 18:11:30 +01:00
You can also use ```witty merge``` to merge two or more recorded sessions, as shown below.
2022-01-26 18:00:24 +01:00
2022-01-26 18:11:30 +01:00
<img src="extra/merge.png" width="640px">
2022-01-26 18:00:24 +01:00
2022-01-26 18:11:30 +01:00
The intended use case is to record a separate session for each individual task, rename and merge them into a final session for submission. The following screenshot shows how to rename a recorded session, and combine them into the final session (you can also rename a recorded session using commands in a shell. All the recorded sessions are located under the ```records``` directory).
2022-01-26 18:00:24 +01:00
2022-01-26 18:11:30 +01:00
<img src="extra/rename.png" width="800px">