mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Updated - websocket switches with SSL
Automatic detection of IP address (for local only) Added binary building (not ready)
This commit is contained in:
parent
59cd27fca2
commit
f934edc757
10
Makefile
10
Makefile
@ -28,4 +28,14 @@ install:
|
|||||||
/etc/init.d/awwkoala.init restart
|
/etc/init.d/awwkoala.init restart
|
||||||
rm -rf jinstall
|
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: install
|
||||||
|
.PHONY: binaries
|
16
main.go
16
main.go
@ -31,6 +31,7 @@ var RuntimeArgs struct {
|
|||||||
ServerKey string
|
ServerKey string
|
||||||
SourcePath string
|
SourcePath string
|
||||||
AdminKey string
|
AdminKey string
|
||||||
|
Socket string
|
||||||
}
|
}
|
||||||
var VersionNum string
|
var VersionNum string
|
||||||
|
|
||||||
@ -45,10 +46,10 @@ func main() {
|
|||||||
flag.StringVar(&RuntimeArgs.ServerKey, "key", "", "location of ssl key")
|
flag.StringVar(&RuntimeArgs.ServerKey, "key", "", "location of ssl key")
|
||||||
flag.StringVar(&RuntimeArgs.WikiName, "w", "AwwKoala", "custom name for wiki")
|
flag.StringVar(&RuntimeArgs.WikiName, "w", "AwwKoala", "custom name for wiki")
|
||||||
flag.CommandLine.Usage = func() {
|
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
|
run this to start the server and then visit localhost at the port you specify
|
||||||
(see parameters).
|
(see parameters).
|
||||||
Example: 'awwkoala localhost'
|
Example: 'awwkoala yourserver.com'
|
||||||
Example: 'awwkoala -p :8080 localhost:8080'
|
Example: 'awwkoala -p :8080 localhost:8080'
|
||||||
Example: 'awwkoala -db /var/lib/awwkoala/db.bolt localhost:8003'
|
Example: 'awwkoala -db /var/lib/awwkoala/db.bolt localhost:8003'
|
||||||
Example: 'awwkoala -p :8080 -crt ssl/server.crt -key ssl/server.key localhost:8080'
|
Example: 'awwkoala -p :8080 -crt ssl/server.crt -key ssl/server.key localhost:8080'
|
||||||
@ -58,7 +59,7 @@ Options:`)
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
RuntimeArgs.ExternalIP = flag.Arg(0)
|
RuntimeArgs.ExternalIP = flag.Arg(0)
|
||||||
if RuntimeArgs.ExternalIP == "" {
|
if RuntimeArgs.ExternalIP == "" {
|
||||||
log.Fatal("You need to specify the external IP address")
|
RuntimeArgs.ExternalIP = GetLocalIP() + RuntimeArgs.Port
|
||||||
}
|
}
|
||||||
RuntimeArgs.SourcePath = path.Dir(executableFile)
|
RuntimeArgs.SourcePath = path.Dir(executableFile)
|
||||||
Open(RuntimeArgs.DatabaseLocation)
|
Open(RuntimeArgs.DatabaseLocation)
|
||||||
@ -95,9 +96,16 @@ Options:`)
|
|||||||
r.DELETE("/listitem", deleteListItem)
|
r.DELETE("/listitem", deleteListItem)
|
||||||
r.DELETE("/deletepage", deletePage)
|
r.DELETE("/deletepage", deletePage)
|
||||||
if RuntimeArgs.ServerCRT != "" && RuntimeArgs.ServerKey != "" {
|
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)
|
r.RunTLS(RuntimeArgs.Port, RuntimeArgs.ServerCRT, RuntimeArgs.ServerKey)
|
||||||
} else {
|
} 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)
|
r.Run(RuntimeArgs.Port)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ func editNote(c *gin.Context) {
|
|||||||
"NumRows": numRows,
|
"NumRows": numRows,
|
||||||
"Versions": versions,
|
"Versions": versions,
|
||||||
"TotalTime": totalTime,
|
"TotalTime": totalTime,
|
||||||
|
"SocketType": RuntimeArgs.Socket,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
c.HTML(http.StatusOK, "index.tmpl", gin.H{
|
c.HTML(http.StatusOK, "index.tmpl", gin.H{
|
||||||
@ -58,6 +59,7 @@ func editNote(c *gin.Context) {
|
|||||||
"NumRows": numRows,
|
"NumRows": numRows,
|
||||||
"Versions": versions,
|
"Versions": versions,
|
||||||
"TotalTime": totalTime,
|
"TotalTime": totalTime,
|
||||||
|
"SocketType": RuntimeArgs.Socket,
|
||||||
"NoEdit": true,
|
"NoEdit": true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// websockets
|
// websockets
|
||||||
url = 'ws://'+external_ip+'/ws';
|
url = socketType + '://'+external_ip+'/ws';
|
||||||
c = new WebSocket(url);
|
c = new WebSocket(url);
|
||||||
|
|
||||||
send = function(data){
|
send = function(data){
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
<script>
|
<script>
|
||||||
external_ip = '{{ .ExternalIP }}'
|
external_ip = '{{ .ExternalIP }}'
|
||||||
title_name = '{{ .Title }}'
|
title_name = '{{ .Title }}'
|
||||||
|
socketType = '{{ .SocketType }}'
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
<span class="icon-bar"></span>
|
<span class="icon-bar"></span>
|
||||||
<span class="icon-bar"></span>
|
<span class="icon-bar"></span>
|
||||||
</button>
|
</button>
|
||||||
<a class="navbar-brand" href="/">{{ .WikiName }}</a>
|
<a class="navbar-brand" href="/">{{ .Title }}</a>
|
||||||
</div>
|
</div>
|
||||||
<div id="navbar" class="collapse navbar-collapse">
|
<div id="navbar" class="collapse navbar-collapse">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
|
@ -28,7 +28,7 @@ a.deleteable {
|
|||||||
<span class="icon-bar"></span>
|
<span class="icon-bar"></span>
|
||||||
<span class="icon-bar"></span>
|
<span class="icon-bar"></span>
|
||||||
</button>
|
</button>
|
||||||
<a class="navbar-brand" href="/">{{ .WikiName }}</a>
|
<a class="navbar-brand" href="/">{{ .Title }}</a>
|
||||||
</div>
|
</div>
|
||||||
<div id="navbar" class="collapse navbar-collapse">
|
<div id="navbar" class="collapse navbar-collapse">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
|
19
utils.go
19
utils.go
@ -5,6 +5,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"net"
|
||||||
"path"
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@ -216,3 +217,21 @@ func RandStringBytesMaskImprSrc(n int) string {
|
|||||||
|
|
||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetLocalIP returns the local ip address
|
||||||
|
func GetLocalIP() string {
|
||||||
|
addrs, err := net.InterfaceAddrs()
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
bestIP := ""
|
||||||
|
for _, address := range addrs {
|
||||||
|
// check the address type and if it is not a loopback the display it
|
||||||
|
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
||||||
|
if ipnet.IP.To4() != nil && (strings.Contains(ipnet.IP.String(), "192.168.1") || strings.Contains(ipnet.IP.String(), "192.168")) {
|
||||||
|
return ipnet.IP.String()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bestIP
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user