Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
haoqu.ma
/
gotty
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a4e77b2b
authored
Oct 05, 2015
by
Quentin Perez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added handling of —permit-arguments option
1 parent
7715f935
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
5 deletions
README.md
app/app.go
main.go
resources/gotty.js
README.md
View file @
a4e77b2
...
...
@@ -66,6 +66,7 @@ By default, GoTTY starts a web server at port 8080. Open the URL on your web bro
--once Accept only one client and exit on disconnection [$GOTTY_ONCE]
--config "~/.gotty" Config file path [$GOTTY_CONFIG]
--version, -v print the version
--permit-arguments Allow to send arguments like this http://exemple.com:8080/?arg=AAA&arg=BBB
```
...
...
app/app.go
View file @
a4e77b2
...
...
@@ -5,6 +5,7 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/base64"
"encoding/json"
"errors"
"io/ioutil"
"log"
...
...
@@ -26,6 +27,11 @@ import (
"github.com/kr/pty"
)
type
InitMessage
struct
{
Arguments
string
`json:"Arguments,omitempty"`
AuthToken
string
`json:"AuthToken,omitempty"`
}
type
App
struct
{
command
[]
string
options
*
Options
...
...
@@ -54,6 +60,7 @@ type Options struct {
EnableReconnect
bool
`hcl:"enable_reconnect"`
ReconnectTime
int
`hcl:"reconnect_time"`
Once
bool
`hcl:"once"`
PermitArguments
bool
`hcl:"permit_arguments"`
Preferences
map
[
string
]
interface
{}
`hcl:"preferences"`
}
...
...
@@ -272,14 +279,42 @@ func (app *App) handleWS(w http.ResponseWriter, r *http.Request) {
return
}
_
,
initMessage
,
err
:=
conn
.
ReadMessage
()
if
err
!=
nil
||
string
(
initMessage
)
!=
app
.
options
.
Credential
{
_
,
stream
,
err
:=
conn
.
ReadMessage
()
if
err
!=
nil
{
log
.
Print
(
"Failed to authenticate websocket connection"
)
conn
.
Close
()
return
}
var
init
InitMessage
cmd
:=
exec
.
Command
(
app
.
command
[
0
],
app
.
command
[
1
:
]
...
)
err
=
json
.
Unmarshal
(
stream
,
&
init
)
if
err
!=
nil
{
log
.
Printf
(
"Failed to parse init message %v"
,
err
)
conn
.
Close
()
return
}
if
init
.
AuthToken
!=
app
.
options
.
Credential
{
log
.
Print
(
"Failed to authenticate websocket connection"
)
conn
.
Close
()
return
}
argv
:=
app
.
command
[
1
:
]
if
app
.
options
.
PermitArguments
{
if
init
.
Arguments
==
""
{
init
.
Arguments
=
"?"
}
query
,
err
:=
url
.
Parse
(
init
.
Arguments
)
if
err
!=
nil
{
log
.
Print
(
"Failed to parse arguments"
)
conn
.
Close
()
return
}
params
:=
query
.
Query
()[
"arg"
]
if
len
(
params
)
!=
0
{
argv
=
append
(
argv
,
params
...
)
}
}
cmd
:=
exec
.
Command
(
app
.
command
[
0
],
argv
...
)
ptyIo
,
err
:=
pty
.
Start
(
cmd
)
if
err
!=
nil
{
log
.
Print
(
"Failed to execute command"
)
...
...
main.go
View file @
a4e77b2
...
...
@@ -34,6 +34,7 @@ func main() {
flag
{
"reconnect"
,
""
,
"Enable reconnection"
},
flag
{
"reconnect-time"
,
""
,
"Time to reconnect"
},
flag
{
"once"
,
""
,
"Accept only one client and exit on disconnection"
},
flag
{
"permit-arguments"
,
""
,
"Allow to send arguments like this http://exemple.com:8080/?arg=AAA&arg=BBB"
},
}
mappingHint
:=
map
[
string
]
string
{
...
...
resources/gotty.js
View file @
a4e77b2
(
function
()
{
var
httpsEnabled
=
window
.
location
.
protocol
==
"https:"
;
var
args
=
window
.
location
.
search
;
var
url
=
(
httpsEnabled
?
'wss://'
:
'ws://'
)
+
window
.
location
.
host
+
window
.
location
.
pathname
+
'ws'
;
var
protocols
=
[
"gotty"
];
var
autoReconnect
=
-
1
;
...
...
@@ -12,8 +13,7 @@
var
pingTimer
;
ws
.
onopen
=
function
(
event
)
{
ws
.
send
(
gotty_auth_token
);
ws
.
send
(
JSON
.
stringify
({
Arguments
:
args
,
AuthToken
:
gotty_auth_token
,}));
pingTimer
=
setInterval
(
sendPing
,
30
*
1000
,
ws
);
hterm
.
defaultStorage
=
new
lib
.
Storage
.
Local
();
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment