const ( // Time allowed to write the file to the client. writeWait = 10 * time.Second // Time allowed to read the next pong message from the client. pongWait = 60 * time.Second // Send pings to client with this period. Must be less than pongWait. pingPeriod = (pongWait * 9) / 10 )
var sampleSecretKey = []byte("5m3R7K4754p4m")
var ( upgrader = websocket.Upgrader{ ReadBufferSize: 1024, WriteBufferSize: 1024, } )
func corsMiddleware(next http.Handler) http.Handler
func generateJWT(username string) (string, error)
func reader(ws *websocket.Conn)
func validateToken(r *http.Request) (err error)
func writer(ws *websocket.Conn, l log.LoggerHookerIface)
CmdOpts specifies the internal web UI server command-line options
type CmdOpts struct { WebDisable bool `long:"web-disable" mapstructure:"web-disable" description:"Disable the web UI" env:"PW_WEBDISABLE"` WebAddr string `long:"web-addr" mapstructure:"web-addr" description:"TCP address in the form 'host:port' to listen on" default:":8080" env:"PW_WEBADDR"` WebUser string `long:"web-user" mapstructure:"web-user" description:"Admin login" env:"PW_WEBUSER"` WebPassword string `long:"web-password" mapstructure:"web-password" description:"Admin password" env:"PW_WEBPASSWORD"` }
type EnsureAuth struct { handler http.HandlerFunc }
func NewEnsureAuth(handlerToWrap http.HandlerFunc) *EnsureAuth
func (ea *EnsureAuth) ServeHTTP(w http.ResponseWriter, r *http.Request)
type WebUIServer struct { l log.LoggerIface http.Server CmdOpts uiFS fs.FS metricsReaderWriter metrics.ReaderWriter sourcesReaderWriter sources.ReaderWriter }
func Init(opts CmdOpts, webuifs fs.FS, mrw metrics.ReaderWriter, srw sources.ReaderWriter, logger log.LoggerIface) *WebUIServer
func (server *WebUIServer) DeleteMetric(name string) error
DeleteMetric removes the metric from the configuration
func (server *WebUIServer) DeletePreset(name string) error
DeletePreset removes the preset from the configuration
func (server *WebUIServer) DeleteSource(database string) error
DeleteSource removes the source from the list of configured sources
func (server *WebUIServer) GetMetrics() (res string, err error)
GetMetrics returns the list of metrics
func (server *WebUIServer) GetPresets() (res string, err error)
GetPresets ret urns the list of available presets
func (server *WebUIServer) GetSources() (res string, err error)
GetSources returns the list of sources fo find databases for monitoring
func (Server *WebUIServer) IsCorrectPassword(lr loginReq) bool
func (server *WebUIServer) TryConnectToDB(params []byte) (err error)
func (server *WebUIServer) UpdateMetric(name string, params []byte) error
UpdateMetric updates the stored metric information
func (server *WebUIServer) UpdatePreset(name string, params []byte) error
UpdatePreset updates the stored preset
func (server *WebUIServer) UpdateSource(params []byte) error
UpdateSource updates the configured source information
func (Server *WebUIServer) handleLogin(w http.ResponseWriter, r *http.Request)
func (Server *WebUIServer) handleMetrics(w http.ResponseWriter, r *http.Request)
func (Server *WebUIServer) handlePresets(w http.ResponseWriter, r *http.Request)
func (Server *WebUIServer) handleSources(w http.ResponseWriter, r *http.Request)
func (Server *WebUIServer) handleStatic(w http.ResponseWriter, r *http.Request)
func (Server *WebUIServer) handleTestConnect(w http.ResponseWriter, r *http.Request)
func (Server *WebUIServer) serveWsLog(w http.ResponseWriter, r *http.Request)
type loginReq struct { Username string `json:"user"` Password string `json:"password"` }