Merge branch 'master' into spice

This commit is contained in:
Soren L. Hansen 2021-04-19 09:54:39 -07:00
commit 1e2e11405f
16 changed files with 380 additions and 1811 deletions

9
.mailmap Normal file
View File

@ -0,0 +1,9 @@
# 'git shortlog --help' and look for mailmap for the format of each line
# Email consolidation:
# <Preferred address in AUTHORS> <other alias used by same author>
# Name consolidation:
# Preferred author spelling <preferred email>
Søren L. Hansen <sorenisanerd@gmail.com>

View File

@ -1,6 +1,6 @@
OUTPUT_DIR = ./builds
GIT_COMMIT = `git rev-parse HEAD | cut -c1-7`
VERSION = 2.1.0alpha2
VERSION = 1.1.0
BUILD_OPTIONS = -ldflags "-X main.Version=$(VERSION) -X main.CommitID=$(GIT_COMMIT)"
gotty: main.go server/*.go webtty/*.go backend/*.go Makefile asset
@ -67,6 +67,15 @@ js/node_modules/webpack:
cd js && \
npm install
README.md: README.md.in
git log --pretty=format:' * %aN' | \
grep -v 'S.*ren L. Hansen' | \
grep -v 'Iwasaki Yudai' | \
sort -u > contributors.txt.tmp
./gotty --help | sed '1,/GLOBAL OPTIONS/ d' > options.txt.tmp
sed -f README.md.sed < $< > $@
rm contributors.txt.tmp options.txt.tmp
tools:
go get github.com/tools/godep
go get github.com/mitchellh/gox
@ -77,7 +86,7 @@ test:
if [ `go fmt $(go list ./... | grep -v /vendor/) | wc -l` -gt 0 ]; then echo "go fmt error"; exit 1; fi
cross_compile:
GOARM=5 gox -os="darwin linux freebsd netbsd openbsd solaris" -arch="386 amd64 arm" -osarch="!darwin/arm" -output "${OUTPUT_DIR}/pkg/{{.OS}}_{{.Arch}}/{{.Dir}}"
GOARM=5 gox -os="darwin linux freebsd netbsd openbsd solaris" -arch="386 amd64 arm" -osarch="!darwin/386" -osarch="!darwin/arm" -output "${OUTPUT_DIR}/pkg/{{.OS}}_{{.Arch}}/{{.Dir}}"
targz:
mkdir -p ${OUTPUT_DIR}/dist
@ -89,7 +98,7 @@ shasums:
release-artifacts: asset gotty cross_compile targz shasums
release:
ghr -draft -prerelease ${VERSION} ${OUTPUT_DIR}/dist # -c ${GIT_COMMIT} --delete --prerelease -u sorenisanerd -r gotty ${VERSION}
ghr -draft ${VERSION} ${OUTPUT_DIR}/dist # -c ${GIT_COMMIT} --delete --prerelease -u sorenisanerd -r gotty ${VERSION}
clean:
rm -fr gotty builds bindata server/asset.go
rm -fr gotty builds bindata server/asset.go js/dist

19
NEWS.md
View File

@ -1,11 +1,16 @@
# GoTTY releases
## v2.1.0 (unreleased)
## v1.1.0
* Use Go modules and update cli module import path (Thanks, @svanellewee
* Fix typos (Thanks, @0xflotus, @RealCyGuy, @ygit, @Jason-Cooke and @fredster33!)
* Fix printing of ipv6 addresses (Thanks, @Felixoid!)
* Add Progressive Web App support (Thanks, @sehaas!)
* Add instructions for GNU screen (Thanks, @Immortalin!)
* Add Solaris support (Thanks, @fazalmajid!)
* Today I learned about Go's handling of versions, so re-releasing 2.1.0 as 1.1.0.
* Added path option. Thanks, @apatil!
## v2.1.0 (whoops)
* Use Go modules and update cli module import path. Thanks, @svanellewee!
* Fix typos. Thanks, @0xflotus, @RealCyGuy, @ygit, @Jason-Cooke and @fredster33!
* Fix printing of ipv6 addresses. Thanks, @Felixoid!
* Add Progressive Web App support. Thanks, @sehaas!
* Add instructions for GNU screen. Thanks, @Immortalin!
* Add Solaris support. Thanks, @fazalmajid!
* New maintainer: @sorenisanerd

View File

@ -46,31 +46,33 @@ By default, GoTTY starts a web server at port 8080. Open the URL on your web bro
```
--address value, -a value IP address to listen (default: "0.0.0.0") [$GOTTY_ADDRESS]
--port value, -p value Port number to listen (default: "8080") [$GOTTY_PORT]
--permit-write, -w Permit clients to write to the TTY (BE CAREFUL) [$GOTTY_PERMIT_WRITE]
--port value, -p value Port number to liten (default: "8080") [$GOTTY_PORT]
--path value, -m value Base path (default: "/") [$GOTTY_PATH]
--permit-write, -w Permit clients to write to the TTY (BE CAREFUL) (default: false) [$GOTTY_PERMIT_WRITE]
--credential value, -c value Credential for Basic Authentication (ex: user:pass, default disabled) [$GOTTY_CREDENTIAL]
--random-url, -r Add a random string to the URL [$GOTTY_RANDOM_URL]
--random-url, -r Add a random string to the URL (default: false) [$GOTTY_RANDOM_URL]
--random-url-length value Random URL length (default: 8) [$GOTTY_RANDOM_URL_LENGTH]
--tls, -t Enable TLS/SSL [$GOTTY_TLS]
--tls, -t Enable TLS/SSL (default: false) [$GOTTY_TLS]
--tls-crt value TLS/SSL certificate file path (default: "~/.gotty.crt") [$GOTTY_TLS_CRT]
--tls-key value TLS/SSL key file path (default: "~/.gotty.key") [$GOTTY_TLS_KEY]
--tls-ca-crt value TLS/SSL CA certificate file for client certifications (default: "~/.gotty.ca.crt") [$GOTTY_TLS_CA_CRT]
--index value Custom index.html file [$GOTTY_INDEX]
--title-format value Title format of browser window (default: "{{ .command }}@{{ .hostname }}") [$GOTTY_TITLE_FORMAT]
--reconnect Enable reconnection [$GOTTY_RECONNECT]
--reconnect Enable reconnection (default: false) [$GOTTY_RECONNECT]
--reconnect-time value Time to reconnect (default: 10) [$GOTTY_RECONNECT_TIME]
--max-connection value Maximum connection to gotty (default: 0) [$GOTTY_MAX_CONNECTION]
--once Accept only one client and exit on disconnection [$GOTTY_ONCE]
--once Accept only one client and exit on disconnection (default: false) [$GOTTY_ONCE]
--timeout value Timeout seconds for waiting a client(0 to disable) (default: 0) [$GOTTY_TIMEOUT]
--permit-arguments Permit clients to send command line arguments in URL (e.g. http://example.com:8080/?arg=AAA&arg=BBB) [$GOTTY_PERMIT_ARGUMENTS]
--permit-arguments Permit clients to send command line arguments in URL (e.g. http://example.com:8080/?arg=AAA&arg=BBB) (default: false) [$GOTTY_PERMIT_ARGUMENTS]
--width value Static width of the screen, 0(default) means dynamically resize (default: 0) [$GOTTY_WIDTH]
--height value Static height of the screen, 0(default) means dynamically resize (default: 0) [$GOTTY_HEIGHT]
--ws-origin value A regular expression that matches origin URLs to be accepted by WebSocket. No cross origin requests are acceptable by default [$GOTTY_WS_ORIGIN]
--term value Terminal name to use on the browser, one of xterm or hterm. (default: "xterm") [$GOTTY_TERM]
--term value Terminal name to use on the browser, one of xterm or hterm. (default: "hterm") [$GOTTY_TERM]
--close-signal value Signal sent to the command process when gotty close it (default: SIGHUP) (default: 1) [$GOTTY_CLOSE_SIGNAL]
--close-timeout value Time in seconds to force kill process after client is disconnected (default: -1) (default: -1) [$GOTTY_CLOSE_TIMEOUT]
--config value Config file path (default: "~/.gotty") [$GOTTY_CONFIG]
--version, -v print the version
--help, -h show help (default: false)
--version, -v print the version (default: false)
```
### Config File
@ -189,3 +191,51 @@ GoTTY uses [xterm.js](https://xtermjs.org/) and [hterm](https://groups.google.co
# License
The MIT License
# Contributors
## Original author
* Iwasaki Yudai
## Maintainer
* Søren L. Hansen
## Contributors
* 0xflotus
* Anand Patil
* Andrea Lusuardi - uovobw
* Andy Skelton
* Artem Medvedev
* Blake Jennings
* Christian Jensen
* Christopher Wilkinson
* Cyrus
* David Horsley
* Fazal Majid
* freakhill
* fredster33
* Jan-Willem Korver
* Jason Cooke
* Johan Gall
* Korenevskiy Denis
* Lin
* Manfred Touron
* Massimiliano Stucchi
* mattn
* Mikhail f. Shiryaev
* Quentin Perez
* Richard Metzler
* Robert Bittle
* Sebastian Haas
* shingt
* Shoji Ihara
* Shuanglei Tao
* Stephan van Ellewee
* The Gitter Badger
* Xinyun Zhou
* Yifa Zhang
* yogesh singh
* zlji

180
README.md.in Normal file
View File

@ -0,0 +1,180 @@
# ![](https://raw.githubusercontent.com/sorenisanerd/gotty/master/resources/favicon.png) GoTTY - Share your terminal as a web application
[![GitHub release](http://img.shields.io/github/release/sorenisanerd/gotty.svg?style=flat-square)][release]
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)][license]
[release]: https://github.com/sorenisanerd/gotty/releases
[license]: https://github.com/sorenisanerd/gotty/blob/master/LICENSE
GoTTY is a simple command line tool that turns your CLI tools into web applications.
![Screenshot](https://raw.githubusercontent.com/sorenisanerd/gotty/master/screenshot.gif)
# Installation
Download the latest stable binary file from the [Releases](https://github.com/sorenisanerd/gotty/releases) page. Note that the release marked `Pre-release` is built for testing purpose, which can include unstable or breaking changes. Download a release marked [Latest release](https://github.com/sorenisanerd/gotty/releases/latest) for a stable build.
(Files named with `darwin_amd64` are for Mac OS X users)
## Homebrew Installation
You can install GoTTY with [Homebrew](http://brew.sh/) as well.
```sh
$ brew install yudai/gotty/gotty
```
## `go get` Installation (Development)
If you have a Go language environment, you can install GoTTY with the `go get` command. However, this command builds a binary file from the latest master branch, which can include unstable or breaking changes. GoTTY requires go1.9 or later.
```sh
$ go get github.com/sorenisanerd/gotty
```
# Usage
```
Usage: gotty [options] <command> [<arguments...>]
```
Run `gotty` with your preferred command as its arguments (e.g. `gotty top`).
By default, GoTTY starts a web server at port 8080. Open the URL on your web browser and you can see the running command as if it were running on your terminal.
## Options
```
@OPTIONS@
```
### Config File
You can customize default options and your terminal (hterm) by providing a config file to the `gotty` command. GoTTY loads a profile file at `~/.gotty` by default when it exists.
```
// Listen at port 9000 by default
port = "9000"
// Enable TSL/SSL by default
enable_tls = true
// hterm preferences
// Smaller font and a little bit bluer background color
preferences {
font_size = 5
background_color = "rgb(16, 16, 32)"
}
```
See the [`.gotty`](https://github.com/sorenisanerd/gotty/blob/master/.gotty) file in this repository for the list of configuration options.
### Security Options
By default, GoTTY doesn't allow clients to send any keystrokes or commands except terminal window resizing. When you want to permit clients to write input to the TTY, add the `-w` option. However, accepting input from remote clients is dangerous for most commands. When you need interaction with the TTY for some reasons, consider starting GoTTY with tmux or GNU Screen and run your command on it (see "Sharing with Multiple Clients" section for detail).
To restrict client access, you can use the `-c` option to enable the basic authentication. With this option, clients need to input the specified username and password to connect to the GoTTY server. Note that the credentials will be transmitted between the server and clients in plain text. For more strict authentication, consider the SSL/TLS client certificate authentication described below.
The `-r` option is a little bit casualer way to restrict access. With this option, GoTTY generates a random URL so that only people who know the URL can get access to the server.
All traffic between the server and clients are NOT encrypted by default. When you send secret information through GoTTY, we strongly recommend you use the `-t` option which enables TLS/SSL on the session. By default, GoTTY loads the crt and key files placed at `~/.gotty.crt` and `~/.gotty.key`. You can overwrite these file paths with the `--tls-crt` and `--tls-key` options. When you need to generate a self-signed certification file, you can use the `openssl` command.
```sh
openssl req -x509 -nodes -days 9999 -newkey rsa:2048 -keyout ~/.gotty.key -out ~/.gotty.crt
```
(NOTE: For Safari uses, see [how to enable self-signed certificates for WebSockets](http://blog.marcon.me/post/24874118286/secure-websockets-safari) when use self-signed certificates)
For additional security, you can use the SSL/TLS client certificate authentication by providing a CA certificate file to the `--tls-ca-crt` option (this option requires the `-t` or `--tls` to be set). This option requires all clients to send valid client certificates that are signed by the specified certification authority.
## Sharing with Multiple Clients
GoTTY starts a new process with the given command when a new client connects to the server. This means users cannot share a single terminal with others by default. However, you can use terminal multiplexers for sharing a single process with multiple clients.
### Screen
After installing GNU screen, start a new session with `screen -S name-for-session` and connect to it with gotty in another terminal window/tab through `screen -x name-for-session`. All commands and activities being done in the first terminal tab/window will now be broadcasted by gotty.
### Tmux
For example, you can start a new tmux session named `gotty` with `top` command by the command below.
```sh
$ gotty tmux new -A -s gotty top
```
This command doesn't allow clients to send keystrokes, however, you can attach the session from your local terminal and run operations like switching the mode of the `top` command. To connect to the tmux session from your terminal, you can use following command.
```sh
$ tmux new -A -s gotty
```
By using terminal multiplexers, you can have the control of your terminal and allow clients to just see your screen.
### Quick Sharing on tmux
To share your current session with others by a shortcut key, you can add a line like below to your `.tmux.conf`.
```
# Start GoTTY in a new window with C-t
bind-key C-t new-window "gotty tmux attach -t `tmux display -p '#S'`"
```
## Playing with Docker
When you want to create a jailed environment for each client, you can use Docker containers like following:
```sh
$ gotty -w docker run -it --rm busybox
```
## Development
You can build a binary using the following commands. Windows is not supported now. go1.9 is required.
```sh
# Install tools
go get github.com/jteeuwen/go-bindata/...
go get github.com/tools/godep
# Build
make
```
To build the frontend part (JS files and other static files), you need `npm`.
## Architecture
GoTTY uses [xterm.js](https://xtermjs.org/) and [hterm](https://groups.google.com/a/chromium.org/forum/#!forum/chromium-hterm) to run a JavaScript based terminal on web browsers. GoTTY itself provides a websocket server that simply relays output from the TTY to clients and receives input from clients and forwards it to the TTY. This hterm + websocket idea is inspired by [Wetty](https://github.com/krishnasrinivas/wetty).
## Alternatives
### Command line client
* [gotty-client](https://github.com/moul/gotty-client): If you want to connect to GoTTY server from your terminal
### Terminal/SSH on Web Browsers
* [Secure Shell (Chrome App)](https://chrome.google.com/webstore/detail/secure-shell/pnhechapfaindjhompbnflcldabbghjo): If you are a chrome user and need a "real" SSH client on your web browser, perhaps the Secure Shell app is what you want
* [Wetty](https://github.com/krishnasrinivas/wetty): Node based web terminal (SSH/login)
* [ttyd](https://tsl0922.github.io/ttyd): C port of GoTTY with CJK and IME support
### Terminal Sharing
* [tmate](http://tmate.io/): Forked-Tmux based Terminal-Terminal sharing
* [termshare](https://termsha.re): Terminal-Terminal sharing through a HTTP server
* [tmux](https://tmux.github.io/): Tmux itself also supports TTY sharing through SSH)
# License
The MIT License
# Contributors
## Original author
* Iwasaki Yudai
## Maintainer
* Søren L. Hansen
## Contributors
@CONTRIBUTORS@

8
README.md.sed Normal file
View File

@ -0,0 +1,8 @@
/@OPTIONS@/ {
r options.txt.tmp
d
}
/@CONTRIBUTORS@/ {
r contributors.txt.tmp
d
}

View File

@ -30,6 +30,8 @@ type LocalCommand struct {
func New(command string, argv []string, options ...Option) (*LocalCommand, error) {
cmd := exec.Command(command, argv...)
cmd.Env = append(os.Environ(), "TERM=xterm-256color")
pty, err := pty.Start(cmd)
if err != nil {
// todo close cmd?

4
go.mod
View File

@ -10,7 +10,7 @@ require (
github.com/gorilla/websocket v1.4.2
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/pkg/errors v0.9.1
github.com/urfave/cli v1.22.5
github.com/urfave/cli/v2 v2.3.0
github.com/yudai/hcl v0.0.0-20151013225006-5fa2393b3552
golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750 // indirect
golang.org/x/sys v0.0.0-20210415045647-66c3f260301c // indirect
)

11
go.sum
View File

@ -36,15 +36,16 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo=
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU=
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/yudai/hcl v0.0.0-20151013225006-5fa2393b3552 h1:tjsK9T2IA3d2FFNxzDP7AJf+EXhyuPd7PB4Z2HrtAoc=
github.com/yudai/hcl v0.0.0-20151013225006-5fa2393b3552/go.mod h1:hg0ZaCmQL3rze1cH8Fh2g0a9q8vQs0uN8ESpePEwSEw=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750 h1:ZBu6861dZq7xBnG1bn5SRU0vA8nx42at4+kP07FMTog=
golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210415045647-66c3f260301c h1:6L+uOeS3OQt/f4eFHXZcTxeZrGCuz+CLElgEBjbcTA4=
golang.org/x/sys v0.0.0-20210415045647-66c3f260301c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

19
help.go
View File

@ -1,19 +0,0 @@
package main
var helpTemplate = `NAME:
{{.Name}} - {{.Usage}}
USAGE:
{{.Name}} [options] <command> [<arguments...>]
VERSION:
{{.Version}}{{if or .Author .Email}}
AUTHOR:{{if .Author}}
{{.Author}}{{if .Email}} - <{{.Email}}>{{end}}{{else}}
{{.Email}}{{end}}{{end}}
OPTIONS:
{{range .Flags}}{{.}}
{{end}}
`

24
main.go
View File

@ -9,7 +9,7 @@ import (
"strings"
"syscall"
"github.com/urfave/cli"
cli "github.com/urfave/cli/v2"
"github.com/sorenisanerd/gotty/backend/localcommand"
"github.com/sorenisanerd/gotty/pkg/homedir"
@ -22,10 +22,9 @@ func main() {
app.Name = "gotty"
app.Version = Version + "+" + CommitID
app.Usage = "Share your terminal as a web application"
app.HideHelp = true
cli.AppHelpTemplate = helpTemplate
app.HideHelpCommand = true
appOptions := &server.Options{}
if err := utils.ApplyDefaultValues(appOptions); err != nil {
exit(err, 1)
}
@ -41,16 +40,16 @@ func main() {
app.Flags = append(
cliFlags,
cli.StringFlag{
&cli.StringFlag{
Name: "config",
Value: "~/.gotty",
Usage: "Config file path",
EnvVar: "GOTTY_CONFIG",
EnvVars: []string{"GOTTY_CONFIG"},
},
)
app.Action = func(c *cli.Context) {
if len(c.Args()) == 0 {
app.Action = func(c *cli.Context) error {
if c.NArg() == 0 {
msg := "Error: No command given."
cli.ShowAppHelp(c)
exit(fmt.Errorf(msg), 1)
@ -75,15 +74,15 @@ func main() {
}
args := c.Args()
factory, err := localcommand.NewFactory(args[0], args[1:], backendOptions)
factory, err := localcommand.NewFactory(args.First(), args.Tail(), backendOptions)
if err != nil {
exit(err, 3)
}
hostname, _ := os.Hostname()
appOptions.TitleVariables = map[string]interface{}{
"command": args[0],
"argv": args[1:],
"command": args.First(),
"argv": args.Tail(),
"hostname": hostname,
}
@ -95,7 +94,7 @@ func main() {
ctx, cancel := context.WithCancel(context.Background())
gCtx, gCancel := context.WithCancel(context.Background())
log.Printf("GoTTY is starting with command: %s", strings.Join(args, " "))
log.Printf("GoTTY is starting with command: %s", strings.Join(args.Slice(), " "))
errs := make(chan error, 1)
go func() {
@ -108,6 +107,7 @@ func main() {
exit(err, 8)
}
return nil
}
app.Run(os.Args)
}

8
release-checklist.md Normal file
View File

@ -0,0 +1,8 @@
* Check that the build works, duh.
* Check that "gotty bash" works and that it does not accept input.
* Check that "gotty -w bash" works and that it DOES accept input.
* Check that "gotty -w bash" works and that it DOES accept input.
* Check that cross-compilation works.
* Ensure NEWS is up-to-date
* Ensure contributor list is up-to-date
* Ensure VERSION is set correctly in Makefile

File diff suppressed because one or more lines are too long

View File

@ -7,6 +7,7 @@ import (
type Options struct {
Address string `hcl:"address" flagName:"address" flagSName:"a" flagDescribe:"IP address to listen" default:"0.0.0.0"`
Port string `hcl:"port" flagName:"port" flagSName:"p" flagDescribe:"Port number to liten" default:"8080"`
Path string `hcl:"path" flagName:"path" flagSName:"m" flagDescribe:"Base path" default:"/"`
PermitWrite bool `hcl:"permit_write" flagName:"permit-write" flagSName:"w" flagDescribe:"Permit clients to write to the TTY (BE CAREFUL)" default:"false"`
EnableBasicAuth bool `hcl:"enable_basic_auth" default:"false"`
Credential string `hcl:"credential" flagName:"credential" flagSName:"c" flagDescribe:"Credential for Basic Authentication (ex: user:pass, default disabled)" default:""`
@ -28,7 +29,7 @@ type Options struct {
Preferences *HtermPrefernces `hcl:"preferences"`
Width int `hcl:"width" flagName:"width" flagDescribe:"Static width of the screen, 0(default) means dynamically resize" default:"0"`
Height int `hcl:"height" flagName:"height" flagDescribe:"Static height of the screen, 0(default) means dynamically resize" default:"0"`
WSOrigin string `hcl:"ws_origin" flagName:"ws-origin" flagDescribe:"A regular expression that matches origin URLs to be accepted by WebSocket. No cross origin requests are acceptable by default" default:".*"`
WSOrigin string `hcl:"ws_origin" flagName:"ws-origin" flagDescribe:"A regular expression that matches origin URLs to be accepted by WebSocket. No cross origin requests are acceptable by default" default:""`
Term string `hcl:"term" flagName:"term" flagDescribe:"Terminal name to use on the browser, one of xterm or hterm." default:"hterm"`
TitleVariables map[string]interface{}

View File

@ -106,7 +106,7 @@ func (server *Server) Run(ctx context.Context, options ...RunOption) error {
counter := newCounter(time.Duration(server.options.Timeout) * time.Second)
path := "/"
path := server.options.Path
if server.options.EnableRandomUrl {
path = "/" + randomstring.Generate(server.options.RandomUrlLength) + "/"
}

View File

@ -8,7 +8,7 @@ import (
"strings"
"github.com/fatih/structs"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
"github.com/yudai/hcl"
"github.com/sorenisanerd/gotty/pkg/homedir"
@ -28,32 +28,36 @@ func GenerateFlags(options ...interface{}) (flags []cli.Flag, mappings map[strin
mappings[flagName] = field.Name()
flagShortName := field.Tag("flagSName")
var aliases []string
if flagShortName != "" {
flagName += ", " + flagShortName
aliases = []string{flagShortName}
}
flagDescription := field.Tag("flagDescribe")
switch field.Kind() {
case reflect.String:
flags = append(flags, cli.StringFlag{
flags = append(flags, &cli.StringFlag{
Name: flagName,
Value: field.Value().(string),
Usage: flagDescription,
EnvVar: envName,
EnvVars: []string{envName},
Aliases: aliases,
})
case reflect.Bool:
flags = append(flags, cli.BoolFlag{
flags = append(flags, &cli.BoolFlag{
Name: flagName,
Usage: flagDescription,
EnvVar: envName,
EnvVars: []string{envName},
Aliases: aliases,
})
case reflect.Int:
flags = append(flags, cli.IntFlag{
flags = append(flags, &cli.IntFlag{
Name: flagName,
Value: field.Value().(int),
Usage: flagDescription,
EnvVar: envName,
EnvVars: []string{envName},
Aliases: aliases,
})
}
}