From 93028414cc94378b0d9177199608efce3090577d Mon Sep 17 00:00:00 2001 From: Antonio Mika Date: Sat, 2 May 2020 22:56:17 -0400 Subject: [PATCH] Added some admin console changes, made time format configurable --- cmd/sish.go | 19 +++++++++++++++++++ config.example.yml | 1 + httpmuxer/httpmuxer.go | 3 ++- sshmuxer/sshmuxer.go | 2 +- templates/console.tmpl | 4 +++- templates/header.tmpl | 4 ++++ templates/routes.tmpl | 6 +++--- 7 files changed, 33 insertions(+), 6 deletions(-) diff --git a/cmd/sish.go b/cmd/sish.go index 7c84875..531d701 100644 --- a/cmd/sish.go +++ b/cmd/sish.go @@ -38,6 +38,14 @@ var ( } ) +type logWriter struct { + TimeFmt string +} + +func (w logWriter) Write(bytes []byte) (int, error) { + return fmt.Printf("%v | %s", time.Now().Format(w.TimeFmt), string(bytes)) +} + func init() { cobra.OnInitialize(initConfig) @@ -65,6 +73,7 @@ func init() { rootCmd.PersistentFlags().StringP("admin-console-token", "j", "S3Cr3tP4$$W0rD", "The token to use for admin access") rootCmd.PersistentFlags().StringP("service-console-token", "m", "", "The token to use for service access. Auto generated if empty.") rootCmd.PersistentFlags().StringP("user-subdomain-separator", "", "", "The token to use for separating username and subdomains in a virtualhost.") + rootCmd.PersistentFlags().StringP("time-format", "", "2006/01/02 - 15:04:05", "The time format to use for both HTTP and general log messages.") rootCmd.PersistentFlags().BoolP("bind-random-subdomains", "", true, "Whether or not to force a random subdomain") rootCmd.PersistentFlags().BoolP("verify-origin", "", true, "Whether or not to verify origin on websocket connection") @@ -111,6 +120,16 @@ func initConfig() { viper.OnConfigChange(func(e fsnotify.Event) { log.Println("Reloaded configuration file.") + + log.SetFlags(0) + log.SetOutput(logWriter{ + TimeFmt: viper.GetString("time-format"), + }) + }) + + log.SetFlags(0) + log.SetOutput(logWriter{ + TimeFmt: viper.GetString("time-format"), }) } diff --git a/config.example.yml b/config.example.yml index 6e775a2..5f2ca47 100644 --- a/config.example.yml +++ b/config.example.yml @@ -37,6 +37,7 @@ proxy-protocol-version: "1" redirect-root-location: https://github.com/antoniomika/sish service-console-token: "" ssh-address: localhost:2222 +time-format: 2006/01/02 - 15:04:05 user-subdomain-separator: "" verify-origin: true verify-ssl: true diff --git a/httpmuxer/httpmuxer.go b/httpmuxer/httpmuxer.go index 0fea764..dc3922b 100644 --- a/httpmuxer/httpmuxer.go +++ b/httpmuxer/httpmuxer.go @@ -66,7 +66,7 @@ func StartHTTPHandler(state *utils.State) { } logLine := fmt.Sprintf("%v | %s |%s %3d %s| %13v | %15s |%s %-7s %s %s\n%s", - param.TimeStamp.Format("2006/01/02 - 15:04:05"), + param.TimeStamp.Format(viper.GetString("time-format")), param.Request.Host, statusColor, param.StatusCode, resetColor, param.Latency, @@ -212,6 +212,7 @@ func StartHTTPHandler(state *utils.State) { data, err := json.Marshal(map[string]interface{}{ "startTime": startTime, + "startTimePretty": startTime.Format(viper.GetString("time-format")), "currentTime": currentTime, "requestIP": c.ClientIP(), "requestTime": diffTime.Round(roundTime).String(), diff --git a/sshmuxer/sshmuxer.go b/sshmuxer/sshmuxer.go index 951517c..af6b1c6 100644 --- a/sshmuxer/sshmuxer.go +++ b/sshmuxer/sshmuxer.go @@ -131,7 +131,7 @@ func Start() { log.Println(key, value) return true }) - log.Print("========End==========\n\n") + log.Print("========End==========\n") time.Sleep(2 * time.Second) } diff --git a/templates/console.tmpl b/templates/console.tmpl index 5b38bfa..98552b2 100644 --- a/templates/console.tmpl +++ b/templates/console.tmpl @@ -5,10 +5,11 @@ + - + @@ -57,6 +58,7 @@ $("#request-list").prepend(` + diff --git a/templates/header.tmpl b/templates/header.tmpl index 7cdfb4f..dacc4a6 100644 --- a/templates/header.tmpl +++ b/templates/header.tmpl @@ -45,12 +45,16 @@ diff --git a/templates/routes.tmpl b/templates/routes.tmpl index 5468df3..46fe7fa 100644 --- a/templates/routes.tmpl +++ b/templates/routes.tmpl @@ -58,8 +58,8 @@ $(function() { $.getJSON(window.location.href.replace("console", "api/clients"), function(data) { for (var client in data.clients) { - var clientData = data.clients[client] - var elementID = clientData.remoteAddr.replace(/(\.|:)/g, "-") + var clientData = data.clients[client]; + var elementID = clientData.remoteAddr.replace(/(\.|:|\[|\])/g, "-"); $("#client-list").append(` @@ -70,7 +70,7 @@ - `) + `); $(`#${elementID}`).data("client-data", clientData); }
Date Method Path StatusTimeDuration
${requestData.startTimePretty} ${requestData.requestMethod} ${requestData.requestUrl.Path} ${requestData.responseStatus}
${clientData.listeners.length} Disconnect