Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
FROM golang:1.17-alpine AS go-env
FROM golang:1.25.3-alpine AS go-env
WORKDIR /go/src/github.com/wuchihsu/go-ssh-web-client/
COPY . ./
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o app .
RUN CGO_ENABLED=0 GOOS=linux go build -o app .

FROM node:14.17-alpine AS node-env
FROM node:18.20-alpine AS node-env
WORKDIR /usr/src/
COPY front ./front
RUN cd front && npm install --production

# FROM alpine:latest
FROM scratch

# set workdir to non-root user home
WORKDIR /root/

# copy app and front to non-root user home
COPY --from=go-env /go/src/github.com/wuchihsu/go-ssh-web-client/app ./
COPY --from=node-env /usr/src/front ./front

# expose and run app as non-root user
EXPOSE 8080/tcp
ENTRYPOINT ["./app"]
42 changes: 23 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,46 @@ A simple SSH web client using Go, WebSocket and Xterm.js.

## Getting Started

There are two ways to install and run the project, using Go and using Docker.
After cloning the project, copy [config.toml.sample](config.toml.sample) to `config.toml`. Modify the host, port, user and password attributes to match the target SSH server in `config.toml`.

### Go
There are two ways to install and run the project, using build script and using Docker.

After cloning the project, go into its `front` folder and install npm packages:
### 1. Script

```bash
cd go-ssh-web-client/front
npm install --production
```
Prerequisites:
- [Go](https://golang.org/doc/install)
- [Node.js](https://nodejs.org/en/download/)
- [npm](https://www.npmjs.com/get-npm)

Then go back to main folder, add configuration file and modify it:
First, execute script to run frontend dev server:

```bash
cd ..
cp config.toml.sample config.toml
vim config.toml
./scripts/front-dev.sh
```

Modify the host, port, user and password attributes to match the target SSH server, then save the file. Finally, run the program:
Then run the backend program:

```bash
go run .
./scripts/backend-dev.sh
```

Now, the HTTP server is running on port 8080, open http://localhost:8080 to use it (use http at your own risk).

### Docker
### 2. Docker

Prerequisites:
- [Docker](https://docs.docker.com/get-docker/)

In current directory, run the prebuilt image:

```bash
./scripts/build-docker.sh
```

First, prepare a configuration file, like [config.toml.sample](config.toml.sample). After preparing `config.toml` in current directory, run the prebuilt image:
Then, run the container:

```bash
docker run --name go-ssh -d \
-v `pwd`/config.toml:/root/config.toml \
-p 8080:8080 \
wuchihsu/go-ssh-web-client
./scripts/docker-dev.sh
```

Now, the HTTP server is running on port 8080, open http://localhost:8080 to use it (use http at your own risk).
239 changes: 238 additions & 1 deletion front/dist/bundle.js

Large diffs are not rendered by default.

24 changes: 13 additions & 11 deletions front/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<!doctype html>
<html>
<head>
<title>Go SSH Web Client</title>
<link rel="stylesheet" href="node_modules/xterm/css/xterm.css" />
<script src="node_modules/xterm/lib/xterm.js"></script>
</head>
<body>
<div id="terminal"></div>
<script src="dist/bundle.js" type="text/javascript"></script>
</body>
</html>
<html>
<head>
<title>Go SSH Web Client</title>
<style>
html, body { height: 100%; margin: 0; }
#terminal { height: 100vh; width: 100vw; }
</style>
</head>
<body>
<div id="terminal"></div>
<script src="dist/bundle.js" type="text/javascript"></script>
</body>
</html>
11 changes: 7 additions & 4 deletions front/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { Terminal } from 'xterm';
import { AttachAddon } from 'xterm-addon-attach';
import { FitAddon } from 'xterm-addon-fit';
import { Terminal } from '@xterm/xterm';
import { AttachAddon } from '@xterm/addon-attach';
import { FitAddon } from '@xterm/addon-fit';

import '@xterm/xterm/css/xterm.css';

const terminal = new Terminal();
const fitAddon = new FitAddon();
terminal.loadAddon(fitAddon);
terminal.open(document.getElementById('terminal'));
fitAddon.fit();

const webSocket = new WebSocket('ws://' + window.location.host + '/web-socket/ssh');
const webSocketProtocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://';
const webSocket = new WebSocket(webSocketProtocol + window.location.host + '/web-socket/ssh');

const sendSize = () => {
const windowSize = {high: terminal.rows, width: terminal.cols};
Expand Down
Loading