From 32d0d2ca6c63ce4f329c2d9023369da4a2afb4d6 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Mon, 15 Feb 2016 16:59:32 -0500 Subject: [PATCH] Updated - websocket switches with SSL Automatic detection of IP address (for local only) Added binary building (not ready) Former-commit-id: 7729b642f8489c631e614b0e1190a9e6eb387443 [formerly 375f6ae8a94b41342555065ac0e35f436e338a5f] [formerly 08e05a2c6c93ad9e1db26f047951278068271f7f [formerly b549a7f6efcaedee78a5e0d74777099abf6fbb07 [formerly f934edc75732912abf21b0d764a80854ca56529e]]] Former-commit-id: cd3c0e21fbd07389ca6eba5795ed4207dd7f474d [formerly c21027b049a07d1d906d8340e64cf3da73a8fe3f] Former-commit-id: afa01eda756447cba035f4e1c40c71be3001979a Former-commit-id: 2a41a03b5cbe2878f4d495fd76ba97523eeb19c3 --- Makefile | 10 ++++++++++ main.go | 16 ++++++++++++---- routes.go | 2 ++ static/js/websockets.js | 2 +- templates/index.tmpl | 1 + templates/list.tmpl | 2 +- templates/view.tmpl | 2 +- utils.go | 19 +++++++++++++++++++ 8 files changed, 47 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 79a606d..85bf405 100644 --- a/Makefile +++ b/Makefile @@ -28,4 +28,14 @@ install: /etc/init.d/awwkoala.init restart rm -rf jinstall +binaries: + rm -rf binaries + rm -f awwkoala + mkdir binaries + env GOOS=linux GOARCH=amd64 go build -o awwkoala -v *.go + zip -9 -r awwkoala-linux-amd64.zip awwkoala static/* templates/* + rm -f awwkoala + + .PHONY: install +.PHONY: binaries \ No newline at end of file diff --git a/main.go b/main.go index a605c82..3d875d9 100644 --- a/main.go +++ b/main.go @@ -31,6 +31,7 @@ var RuntimeArgs struct { ServerKey string SourcePath string AdminKey string + Socket string } var VersionNum string @@ -45,10 +46,10 @@ func main() { flag.StringVar(&RuntimeArgs.ServerKey, "key", "", "location of ssl key") flag.StringVar(&RuntimeArgs.WikiName, "w", "AwwKoala", "custom name for wiki") flag.CommandLine.Usage = func() { - fmt.Println(`AwwKoala: A Websocket Wiki and Kind Of A List Application + fmt.Println(`AwwKoala (version ` + VersionNum + `): A Websocket Wiki and Kind Of A List Application run this to start the server and then visit localhost at the port you specify (see parameters). -Example: 'awwkoala localhost' +Example: 'awwkoala yourserver.com' Example: 'awwkoala -p :8080 localhost:8080' Example: 'awwkoala -db /var/lib/awwkoala/db.bolt localhost:8003' Example: 'awwkoala -p :8080 -crt ssl/server.crt -key ssl/server.key localhost:8080' @@ -58,7 +59,7 @@ Options:`) flag.Parse() RuntimeArgs.ExternalIP = flag.Arg(0) if RuntimeArgs.ExternalIP == "" { - log.Fatal("You need to specify the external IP address") + RuntimeArgs.ExternalIP = GetLocalIP() + RuntimeArgs.Port } RuntimeArgs.SourcePath = path.Dir(executableFile) Open(RuntimeArgs.DatabaseLocation) @@ -95,9 +96,16 @@ Options:`) r.DELETE("/listitem", deleteListItem) r.DELETE("/deletepage", deletePage) if RuntimeArgs.ServerCRT != "" && RuntimeArgs.ServerKey != "" { + RuntimeArgs.Socket = "wss" + fmt.Println("--------------------------") + fmt.Println("AwwKoala is up and running on https://" + RuntimeArgs.ExternalIP) + fmt.Println("--------------------------") r.RunTLS(RuntimeArgs.Port, RuntimeArgs.ServerCRT, RuntimeArgs.ServerKey) } else { - log.Println("No crt/key found, running non-https") + RuntimeArgs.Socket = "ws" + fmt.Println("--------------------------") + fmt.Println("AwwKoala is up and running on http://" + RuntimeArgs.ExternalIP) + fmt.Println("--------------------------") r.Run(RuntimeArgs.Port) } } diff --git a/routes.go b/routes.go index bb0db7a..7bf9129 100644 --- a/routes.go +++ b/routes.go @@ -48,6 +48,7 @@ func editNote(c *gin.Context) { "NumRows": numRows, "Versions": versions, "TotalTime": totalTime, + "SocketType": RuntimeArgs.Socket, }) } else { c.HTML(http.StatusOK, "index.tmpl", gin.H{ @@ -58,6 +59,7 @@ func editNote(c *gin.Context) { "NumRows": numRows, "Versions": versions, "TotalTime": totalTime, + "SocketType": RuntimeArgs.Socket, "NoEdit": true, }) } diff --git a/static/js/websockets.js b/static/js/websockets.js index d298448..69ed052 100644 --- a/static/js/websockets.js +++ b/static/js/websockets.js @@ -44,7 +44,7 @@ $(document).ready(function() { } // websockets - url = 'ws://'+external_ip+'/ws'; + url = socketType + '://'+external_ip+'/ws'; c = new WebSocket(url); send = function(data){ diff --git a/templates/index.tmpl b/templates/index.tmpl index 71616df..d81adf0 100644 --- a/templates/index.tmpl +++ b/templates/index.tmpl @@ -14,6 +14,7 @@ diff --git a/templates/list.tmpl b/templates/list.tmpl index 00174c4..635d624 100644 --- a/templates/list.tmpl +++ b/templates/list.tmpl @@ -28,7 +28,7 @@ - {{ .WikiName }} + {{ .Title }}