mirror of
https://github.com/sorenisanerd/gotty.git
synced 2024-11-21 12:14:24 +00:00
feat: add support for specifying custom querystring arguments
This allows folks to implement token-based authentication for websocket access. Closes #82
This commit is contained in:
parent
113b502abb
commit
ba9326e417
@ -75,6 +75,7 @@ By default, GoTTY starts a web server at port 8080. Open the URL on your web bro
|
|||||||
--width value Static width of the screen, 0(default) means dynamically resize (default: 0) [$GOTTY_WIDTH]
|
--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]
|
--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]
|
--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]
|
||||||
|
--ws-query-args value Querystring arguments to append to the websocket instantiation [$GOTTY_WS_QUERY_ARGS]
|
||||||
--enable-webgl Enable WebGL renderer (default: true) [$GOTTY_ENABLE_WEBGL]
|
--enable-webgl Enable WebGL renderer (default: true) [$GOTTY_ENABLE_WEBGL]
|
||||||
--close-signal value Signal sent to the command process when gotty close it (default: SIGHUP) (default: 1) [$GOTTY_CLOSE_SIGNAL]
|
--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]
|
--close-timeout value Time in seconds to force kill process after client is disconnected (default: -1) (default: -1) [$GOTTY_CLOSE_TIMEOUT]
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,10 +1,11 @@
|
|||||||
import { OurXterm } from "./xterm";
|
|
||||||
import { Terminal, WebTTY, protocols } from "./webtty";
|
|
||||||
import { ConnectionFactory } from "./websocket";
|
import { ConnectionFactory } from "./websocket";
|
||||||
|
import { Terminal, WebTTY, protocols } from "./webtty";
|
||||||
|
import { OurXterm } from "./xterm";
|
||||||
|
|
||||||
// @TODO remove these
|
// @TODO remove these
|
||||||
declare var gotty_auth_token: string;
|
declare var gotty_auth_token: string;
|
||||||
declare var gotty_term: string;
|
declare var gotty_term: string;
|
||||||
|
declare var gotty_ws_query_args: string;
|
||||||
|
|
||||||
const elem = document.getElementById("terminal")
|
const elem = document.getElementById("terminal")
|
||||||
|
|
||||||
@ -13,7 +14,8 @@ if (elem !== null) {
|
|||||||
term = new OurXterm(elem);
|
term = new OurXterm(elem);
|
||||||
|
|
||||||
const httpsEnabled = window.location.protocol == "https:";
|
const httpsEnabled = window.location.protocol == "https:";
|
||||||
const url = (httpsEnabled ? 'wss://' : 'ws://') + window.location.host + window.location.pathname + 'ws';
|
const queryArgs = (gotty_ws_query_args === "") ? "" : "?" + gotty_ws_query_args;
|
||||||
|
const url = (httpsEnabled ? 'wss://' : 'ws://') + window.location.host + window.location.pathname + 'ws' + queryArgs;
|
||||||
const args = window.location.search;
|
const args = window.location.search;
|
||||||
const factory = new ConnectionFactory(url, protocols);
|
const factory = new ConnectionFactory(url, protocols);
|
||||||
const wt = new WebTTY(term, factory, args, gotty_auth_token);
|
const wt = new WebTTY(term, factory, args, gotty_auth_token);
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
@ -233,7 +234,12 @@ func (server *Server) handleAuthToken(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func (server *Server) handleConfig(w http.ResponseWriter, r *http.Request) {
|
func (server *Server) handleConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/javascript")
|
w.Header().Set("Content-Type", "application/javascript")
|
||||||
w.Write([]byte("var gotty_term = 'xterm';"))
|
lines := []string{
|
||||||
|
"var gotty_term = 'xterm';",
|
||||||
|
"var gotty_ws_query_args = '" + server.options.WSQueryArgs + "';",
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Write([]byte(strings.Join(lines, "\n")))
|
||||||
}
|
}
|
||||||
|
|
||||||
// titleVariables merges maps in a specified order.
|
// titleVariables merges maps in a specified order.
|
||||||
|
@ -26,10 +26,11 @@ type Options struct {
|
|||||||
Once bool `hcl:"once" flagName:"once" flagDescribe:"Accept only one client and exit on disconnection" default:"false"`
|
Once bool `hcl:"once" flagName:"once" flagDescribe:"Accept only one client and exit on disconnection" default:"false"`
|
||||||
Timeout int `hcl:"timeout" flagName:"timeout" flagDescribe:"Timeout seconds for waiting a client(0 to disable)" default:"0"`
|
Timeout int `hcl:"timeout" flagName:"timeout" flagDescribe:"Timeout seconds for waiting a client(0 to disable)" default:"0"`
|
||||||
PermitArguments bool `hcl:"permit_arguments" flagName:"permit-arguments" flagDescribe:"Permit clients to send command line arguments in URL (e.g. http://example.com:8080/?arg=AAA&arg=BBB)" default:"false"`
|
PermitArguments bool `hcl:"permit_arguments" flagName:"permit-arguments" flagDescribe:"Permit clients to send command line arguments in URL (e.g. http://example.com:8080/?arg=AAA&arg=BBB)" default:"false"`
|
||||||
PassHeaders bool `hcl:"pass_headers" flagName:"pass-headers" flagDescribe:"Pass HTTP request headers as environment variables (e.g. Cookie becomes HTTP_COOKIE)" default:"false"`
|
PassHeaders bool `hcl:"pass_headers" flagName:"pass-headers" flagDescribe:"Pass HTTP request headers as environment variables (e.g. Cookie becomes HTTP_COOKIE)" default:"false"`
|
||||||
Width int `hcl:"width" flagName:"width" flagDescribe:"Static width of the screen, 0(default) means dynamically resize" default:"0"`
|
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"`
|
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:""`
|
||||||
|
WSQueryArgs string `hcl:"ws_query_args" flagName:"ws-query-args" flagDescribe:"Querystring arguments to append to the websocket instantiation" default:""`
|
||||||
EnableWebGL bool `hcl:"enable_webgl" flagName:"enable-webgl" flagDescribe:"Enable WebGL renderer" default:"true"`
|
EnableWebGL bool `hcl:"enable_webgl" flagName:"enable-webgl" flagDescribe:"Enable WebGL renderer" default:"true"`
|
||||||
Quiet bool `hcl:"quiet" flagName:"quiet" flagDescribe:"Don't log" default:"false"`
|
Quiet bool `hcl:"quiet" flagName:"quiet" flagDescribe:"Don't log" default:"false"`
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user