From 7da25057cfc6b12218a26536476786ee8b005273 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Sat, 20 Aug 2016 22:00:15 +0200 Subject: [PATCH] Default HTTP(S) port to -1 + random port on config set to 0 --- http/http.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/http/http.go b/http/http.go index 7a5da46..df01d76 100644 --- a/http/http.go +++ b/http/http.go @@ -5,6 +5,7 @@ import ( "fmt" "log" + "math/rand" "net/http" "strconv" "strings" @@ -28,13 +29,15 @@ const ( RETURN_VALUE_OK = "OK" RETURN_VALUE_NOK = "NOK" + MAX_PORT_VAL = 65535 + StatusUnknownError = 520 StatusUnreachable = 523 ) var ( - HttpPortBind = 9090 - HttpsPortBind = 9093 + HttpPortBind = -1 + HttpsPortBind = -1 CertPath = "./cert.pem" KeyPath = "./key.pem" @@ -43,8 +46,11 @@ var ( MaxTimeout = 300 // 5 min ) +func init() { + rand.Seed(time.Now().UTC().UnixNano()) +} + func indexHandler(w http.ResponseWriter, r *http.Request) { - // TODO fmt.Fprintf(w, "Welcome to HTTP authentification over XMPP") } @@ -120,9 +126,15 @@ func Run() { if HttpPortBind > 0 { go runHttp() + } else if HttpPortBind == 0 { + HttpPortBind = rand.Intn(MAX_PORT_VAL) + go runHttp() } if HttpsPortBind > 0 { go runHttps() + } else if HttpsPortBind == 0 { + HttpsPortBind = rand.Intn(MAX_PORT_VAL) + go runHttps() } }