diff --git a/readme.md b/readme.md index 1853fce..41249f4 100644 --- a/readme.md +++ b/readme.md @@ -8,7 +8,7 @@ gossa [](https://hub.docker.com/r/pldubouilh/gossa) [](https://github.com/pldubouilh/gossa/releases) -a fast and simple webserver for your files, that's dependency-free and with 200 lines of code, easy to review. +a fast and simple webserver for your files, that's dependency-free and with under 200 lines of code, easy to review. a [simple UI](https://github.com/pldubouilh/gossa-ui) comes as default, featuring : diff --git a/src/gossa.go b/src/gossa.go index f4d1904..f937094 100755 --- a/src/gossa.go +++ b/src/gossa.go @@ -1,7 +1,6 @@ package main import ( - "crypto/sha256" "encoding/json" "errors" "flag" @@ -17,7 +16,6 @@ import ( "path/filepath" "strconv" "strings" - "sync" ) var host = flag.String("h", "127.0.0.1", "host to listen to") @@ -26,21 +24,17 @@ var history = flag.Bool("history", true, "keep history for paths visited. defaul var extraPath = flag.String("prefix", "/", "url prefix at which gossa can be reached, e.g. /gossa/ (slashes of importance)") var symlinks = flag.Bool("symlinks", false, "follow symlinks \033[4mWARNING\033[0m: symlinks will by nature allow to escape the defined path (default: false)") var verb = flag.Bool("verb", false, "verbosity") -var skipHidden = flag.Bool("k", true, "skip hidden files") +var skipHidden = flag.Bool("k", true, "\nskip hidden files") var initPath = "." -var historyPath = "" -var state = make(map[string]string) -var stateLock = sync.RWMutex{} var fs http.Handler var page, _ = template.New("pageTemplate").Parse(`template_will_be_here`) type rowTemplate struct { - Name string - Href template.HTML - Size string - Ext string - Selected bool + Name string + Href template.HTML + Size string + Ext string } type pageTemplate struct { @@ -61,10 +55,6 @@ func check(e error) { } } -func hash(s string) string { - return fmt.Sprintf("%x", sha256.Sum256([]byte(s))) -} - func exitPath(w http.ResponseWriter, s ...interface{}) { if r := recover(); r != nil { log.Println("error", s, r) @@ -97,13 +87,10 @@ func replyList(w http.ResponseWriter, r *http.Request, fullPath string, path str title := "/" + strings.TrimPrefix(path, *extraPath) p := pageTemplate{} if path != *extraPath { - p.RowsFolders = append(p.RowsFolders, rowTemplate{"../", "../", "", "folder", false}) + p.RowsFolders = append(p.RowsFolders, rowTemplate{"../", "../", "", "folder"}) } p.ExtraPath = template.HTML(html.EscapeString(*extraPath)) p.Title = template.HTML(html.EscapeString(title)) - stateLock.Lock() - loc := state[hash(r.Header.Get("Authorization")+path)] - stateLock.Unlock() for _, el := range _files { if *skipHidden && strings.HasPrefix(el.Name(), ".") { @@ -115,10 +102,10 @@ func replyList(w http.ResponseWriter, r *http.Request, fullPath string, path str href = strings.Replace(href, "/", "", 1) } if el.IsDir() { - p.RowsFolders = append(p.RowsFolders, rowTemplate{el.Name() + "/", template.HTML(href), "", "folder", loc == hash(el.Name()+"/")}) + p.RowsFolders = append(p.RowsFolders, rowTemplate{el.Name() + "/", template.HTML(href), "", "folder"}) } else { sl := strings.Split(el.Name(), ".") - p.RowsFiles = append(p.RowsFiles, rowTemplate{el.Name(), template.HTML(href), humanize(el.Size()), strings.ToLower(sl[len(sl)-1]), loc == hash(el.Name())}) + p.RowsFiles = append(p.RowsFiles, rowTemplate{el.Name(), template.HTML(href), humanize(el.Size()), strings.ToLower(sl[len(sl)-1])}) } } @@ -160,10 +147,7 @@ func rpc(w http.ResponseWriter, r *http.Request) { bodyBytes, _ := ioutil.ReadAll(r.Body) json.Unmarshal(bodyBytes, &rpc) defer exitPath(w, "rpc", rpc) - stateLock.Lock() - defer stateLock.Unlock() ret := "ok" - key := hash(r.Header.Get("Authorization") + rpc.Args[0]) if rpc.Call == "mkdirp" { err = os.MkdirAll(checkPath(rpc.Args[0]), os.ModePerm) @@ -171,16 +155,6 @@ func rpc(w http.ResponseWriter, r *http.Request) { err = os.Rename(checkPath(rpc.Args[0]), checkPath(rpc.Args[1])) } else if rpc.Call == "rm" { err = os.RemoveAll(checkPath(rpc.Args[0])) - } else if rpc.Call == "historySet" && *history { - if rpc.Args[2] == "hash" { - state[key] = hash(rpc.Args[1]) - } else { - state[key] = rpc.Args[1] - } - f, _ := json.MarshalIndent(state, "", " ") - ioutil.WriteFile(historyPath, f, 0644) - } else if rpc.Call == "historyGet" && *history { - ret = state[key] } check(err) @@ -205,14 +179,12 @@ func main() { fmt.Printf("\nusage: ./gossa ~/directory-to-share\n\n") flag.PrintDefaults() } + flag.Parse() if len(flag.Args()) > 0 { initPath = flag.Args()[0] } - historyPath = filepath.Join(initPath, ".gossa_history") - h, _ := ioutil.ReadFile(historyPath) - _ = json.Unmarshal(h, &state) initPath, err = filepath.Abs(initPath) check(err) diff --git a/src/gossa_test.go b/src/gossa_test.go index 1bf4160..f755e97 100644 --- a/src/gossa_test.go +++ b/src/gossa_test.go @@ -61,7 +61,7 @@ func fetchAndTestDefault(t *testing.T, url string) string { t.Fatal("error title") } - if !strings.Contains(body0, `