diff --git a/internal/myclipboard/clipboard.go b/internal/myclipboard/clipboard.go index eaf78e5..e84aa6a 100644 --- a/internal/myclipboard/clipboard.go +++ b/internal/myclipboard/clipboard.go @@ -3,6 +3,8 @@ package myclipboard import ( "encoding/json" "time" + + "github.com/patrickhener/goshs/internal/mylog" ) // Clipboard is the in memory clipboard to hold the copy-pasteable content @@ -49,7 +51,8 @@ func (c *Clipboard) AddEntry(con string) error { func (c *Clipboard) DeleteEntry(id int) error { entries := c.Entries entries = append(entries[:id], entries[id+1:]...) - c.Entries = entries + newEntries := reindex(entries) + c.Entries = newEntries return nil } @@ -74,3 +77,16 @@ func (c *Clipboard) Download() ([]byte, error) { } return e, nil } + +func reindex(entries []Entry) []Entry { + var newEntries []Entry + for i, e := range entries { + mylog.Debugf("Entry #%d: %+v\n", i, e) + newEntries = append(newEntries, Entry{ + ID: i, + Content: e.Content, + Time: e.Time, + }) + } + return newEntries +} diff --git a/internal/myhttp/fileserver.go b/internal/myhttp/fileserver.go index e464774..81cad46 100644 --- a/internal/myhttp/fileserver.go +++ b/internal/myhttp/fileserver.go @@ -262,9 +262,13 @@ func (fs *FileServer) handler(w http.ResponseWriter, req *http.Request) { if upath == "/favicon.ico" { return } + upath = path.Clean(upath) + upath = filepath.Clean(upath) + + mylog.Debugf("Cleaned upath is: %+v", upath) // Define absolute path - open := fs.Webroot + path.Clean(upath) + open := fs.Webroot + upath // Check if you are in a dir // disable G304 (CWE-22): Potential file inclusion via variable diff --git a/internal/mylog/log.go b/internal/mylog/log.go index b180b15..3f14591 100644 --- a/internal/mylog/log.go +++ b/internal/mylog/log.go @@ -1,7 +1,6 @@ package mylog import ( - "fmt" "net/http" "os" @@ -15,10 +14,9 @@ func LogRequest(req *http.Request, status int) { return } logger.Infof("%s - - \"%s %s %s\" - %+v", req.RemoteAddr, req.Method, req.URL, req.Proto, status) - fmt.Println(req.URL.Query()) if req.URL.Query() != nil { for k, v := range req.URL.Query() { - logger.Infof("Parameter %s is %s", k, v) + logger.Debugf("Parameter %s is %s", k, v) } } } diff --git a/main.go b/main.go index 289b5dd..bc003ef 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ import ( "github.com/patrickhener/goshs/internal/myutils" ) -const goshsVersion = "v0.1.6" +const goshsVersion = "v0.1.7" var ( port = 8000