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 67b54b7f
authored
Aug 23, 2015
by
Iwasaki Yudai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show command and hostname in windows title
1 parent
5ee63562
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
79 additions
and
21 deletions
Godeps/Godeps.json
Makefile
app/app.go
app/resource.go
main.go
resources/index.html
Godeps/Godeps.json
View file @
67b54b7
...
...
@@ -12,6 +12,14 @@
"Rev"
:
"d5cac425555ca5cf00694df246e04f05e6a55150"
},
{
"ImportPath"
:
"github.com/gorilla/context"
,
"Rev"
:
"1c83b3eabd45b6d76072b66b746c20815fb2872d"
},
{
"ImportPath"
:
"github.com/gorilla/mux"
,
"Rev"
:
"ee1815431e497d3850809578c93ab6705f1a19f7"
},
{
"ImportPath"
:
"github.com/gorilla/websocket"
,
"Rev"
:
"b6ab76f1fe9803ee1d59e7e5b2a797c1fe897ce5"
},
...
...
Makefile
View file @
67b54b7
gotty
:
app/resource.go main.go app/*.go
go build
resource
:
app/resource.go
resource
:
app/resource.go
app/resource.go
:
bindata/
hterm.js bindata/index.html bindata/gotty.js
go-bindata -p
kg app -ignore
=
\\
.gitkeep -o app/resource.go bindata/
app/resource.go
:
bindata/
static/hterm.js bindata/static/gotty.js bindata/templates/index.html
go-bindata -p
refix bindata -pkg app -ignore
=
\\
.gitkeep -o app/resource.go bindata/...
gofmt -w app/resource.go
bindata
:
mkdir bindata
bindata/hterm.js
:
bindata libapps/hterm/js/*.js
bindata/static
:
bindata
mkdir bindata/static
bindata/templates
:
bindata
mkdir bindata/templates
bindata/static/hterm.js
:
bindata/static libapps/hterm/js/*.js
cd
libapps
&&
\
LIBDOT_SEARCH_PATH
=
`
pwd
`
./libdot/bin/concat.sh -i ./hterm/concat/hterm_all.concat -o ../bindata/hterm.js
LIBDOT_SEARCH_PATH
=
`
pwd
`
./libdot/bin/concat.sh -i ./hterm/concat/hterm_all.concat -o ../bindata/
static/
hterm.js
bindata/
index.html
:
bindata resources/index.html
cp resources/
index.html bindata/index.html
bindata/
static/gotty.js
:
bindata/static resources/gotty.js
cp resources/
gotty.js bindata/static/gotty.js
bindata/
gotty.js
:
bindata resources/gotty.js
cp resources/
gotty.js bindata/gotty.js
bindata/
templates/index.html
:
bindata/templates resources/index.html
cp resources/
index.html bindata/templates/index.html
app/app.go
View file @
67b54b7
package
app
import
(
"bytes"
"crypto/rand"
"encoding/base64"
htemplate
"html/template"
"log"
"math/big"
"net"
"net/http"
"os"
"os/exec"
"strconv"
"strings"
ttemplate
"text/template"
"github.com/elazarl/go-bindata-assetfs"
"github.com/gorilla/websocket"
"github.com/kr/pty"
"net"
)
type
App
struct
{
...
...
@@ -28,6 +32,7 @@ type Options struct {
PermitWrite
bool
Credential
string
RandomUrl
bool
TitleFormat
string
Command
[]
string
}
...
...
@@ -44,21 +49,23 @@ func New(options Options) *App {
}
func
(
app
*
App
)
Run
()
error
{
path
:=
"
/
"
path
:=
""
if
app
.
options
.
RandomUrl
{
path
+=
generateRandomString
(
8
)
path
+=
"/"
+
generateRandomString
(
8
)
}
endpoint
:=
app
.
options
.
Address
+
":"
+
app
.
options
.
Port
indexHandler
:=
http
.
HandlerFunc
(
app
.
handleIndex
)
wsHandler
:=
http
.
HandlerFunc
(
app
.
handleWS
)
staticHandler
:=
http
.
FileServer
(
&
assetfs
.
AssetFS
{
Asset
:
Asset
,
AssetDir
:
AssetDir
,
Prefix
:
"
bindata
"
},
&
assetfs
.
AssetFS
{
Asset
:
Asset
,
AssetDir
:
AssetDir
,
Prefix
:
"
static
"
},
)
wsHandler
:=
http
.
HandlerFunc
(
app
.
handleWS
)
var
siteMux
=
http
.
NewServeMux
()
siteMux
.
Handle
(
path
,
staticHandler
)
siteMux
.
Handle
(
path
+
"ws"
,
wsHandler
)
siteMux
.
Handle
(
path
+
"/"
,
indexHandler
)
siteMux
.
Handle
(
path
+
"/static/"
,
http
.
StripPrefix
(
path
+
"/static/"
,
staticHandler
))
siteMux
.
Handle
(
path
+
"/ws"
,
wsHandler
)
siteHandler
:=
http
.
Handler
(
siteMux
)
...
...
@@ -74,10 +81,10 @@ func (app *App) Run() error {
strings
.
Join
(
app
.
options
.
Command
,
" "
),
)
if
app
.
options
.
Address
!=
""
{
log
.
Printf
(
"URL: %s"
,
"http://"
+
endpoint
+
path
)
log
.
Printf
(
"URL: %s"
,
"http://"
+
endpoint
+
path
+
"/"
)
}
else
{
for
_
,
address
:=
range
listAddresses
()
{
log
.
Printf
(
"URL: %s"
,
"http://"
+
address
+
":"
+
app
.
options
.
Port
+
path
)
log
.
Printf
(
"URL: %s"
,
"http://"
+
address
+
":"
+
app
.
options
.
Port
+
path
+
"/"
)
}
}
if
err
:=
http
.
ListenAndServe
(
endpoint
,
siteHandler
);
err
!=
nil
{
...
...
@@ -87,6 +94,36 @@ func (app *App) Run() error {
return
nil
}
type
TitleVars
struct
{
Command
string
Hostname
string
}
type
IndexVars
struct
{
Title
string
}
func
(
app
*
App
)
handleIndex
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
title
:=
make
([]
byte
,
0
)
titleBuf
:=
bytes
.
NewBuffer
(
title
)
hostname
,
_
:=
os
.
Hostname
()
titleVars
:=
TitleVars
{
Command
:
strings
.
Join
(
app
.
options
.
Command
,
" "
),
Hostname
:
hostname
,
}
titleTmpl
,
_
:=
ttemplate
.
New
(
"title"
)
.
Parse
(
app
.
options
.
TitleFormat
)
titleTmpl
.
Execute
(
titleBuf
,
titleVars
)
data
,
_
:=
Asset
(
"templates/index.html"
)
tmpl
,
_
:=
htemplate
.
New
(
"index"
)
.
Parse
(
string
(
data
))
vars
:=
IndexVars
{
Title
:
titleBuf
.
String
(),
}
tmpl
.
Execute
(
w
,
vars
)
}
func
(
app
*
App
)
handleWS
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
log
.
Printf
(
"New client connected: %s"
,
r
.
RemoteAddr
)
...
...
app/resource.go
View file @
67b54b7
This diff could not be displayed because it is too large.
main.go
View file @
67b54b7
...
...
@@ -43,6 +43,12 @@ func main() {
Usage
:
"Add a random string to the URL"
,
EnvVar
:
"GOTTY_RANDOM_URL"
,
},
cli
.
StringFlag
{
Name
:
"title-format"
,
Value
:
"GoTTY - {{ .Command }} ({{ .Hostname }})"
,
Usage
:
"Title format of browser window"
,
EnvVar
:
"GOTTY_title-format"
,
},
}
cmd
.
Action
=
func
(
c
*
cli
.
Context
)
{
if
len
(
c
.
Args
())
==
0
{
...
...
@@ -57,6 +63,7 @@ func main() {
c
.
Bool
(
"permit-write"
),
c
.
String
(
"credential"
),
c
.
Bool
(
"random-url"
),
c
.
String
(
"title-format"
),
c
.
Args
(),
},
)
...
...
resources/index.html
View file @
67b54b7
<!doctype html>
<html>
<head>
<title>
GoTTY
</title>
<title>
{{ .Title }}
</title>
<style>body
{
position
:
absolute
;
height
:
100%
;
width
:
100%
;
margin
:
0px
;}
</style>
</head>
<body>
<script
src=
"hterm.js"
></script>
<script
src=
"gotty.js"
></script>
<script
src=
"
static/
hterm.js"
></script>
<script
src=
"
static/
gotty.js"
></script>
</body>
</html>
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