Compare commits

..
13 Commits
Author SHA1 Message Date
Pierre Dubouilh 39611d2df3 Merge pull request #45 from pldubouilh/phone-pics-nav
bump ui
2020-03-21 16:58:55 +01:00
Pierre Dubouilh 55e729e434 bump ui 2020-03-21 16:56:17 +01:00
Pierre Dubouilh 7f690bc75f Merge pull request #44 from pldubouilh/fix-rename-ui
bump ui
2020-03-14 19:50:53 +01:00
Pierre Dubouilh 308ad9461e bump ui 2020-03-14 19:48:45 +01:00
Pierre Dubouilh 1119146cef Merge pull request #37 from pldubouilh/ro
read only mode
2020-02-09 22:33:42 +01:00
Pierre Dubouilh f0abad8b78 bump ui 2020-02-08 16:08:48 +01:00
Pierre Dubouilh 551c334cdd try shorten ci 2020-01-21 18:16:47 +01:00
Pierre Dubouilh 49cfc28d34 read only mode 2020-01-19 14:38:15 +01:00
Pierre Dubouilh be39e6aca8 case insensitive indexing 2020-01-18 16:33:10 +01:00
Pierre Dubouilh b2e0396cf1 Merge pull request #35 from pldubouilh/bump-ui
Bump ui
2019-12-25 22:47:25 +01:00
Pierre Dubouilh e22ef1bc12 fix test jitter 2019-12-25 22:44:25 +01:00
Pierre Dubouilh 5c9c8983e1 bump ui 2019-12-25 19:24:09 +01:00
Pierre Dubouilh 31775b6ae9 refactor 2019-12-15 19:06:59 +01:00
7 changed files with 132 additions and 39 deletions
+3 -3
View File
@@ -7,10 +7,10 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Set up Go 1.12 - name: Set up Go 1.13
uses: actions/setup-go@v1 uses: actions/setup-go@v1
with: with:
go-version: 1.12 go-version: 1.13
id: go id: go
- name: Check out code into the Go module directory - name: Check out code into the Go module directory
@@ -19,4 +19,4 @@ jobs:
submodules: true submodules: true
- name: Run - name: Run
run: make ci run: make test
+1
View File
@@ -4,6 +4,7 @@ gossa-linux-arm
gossa-linux-arm64 gossa-linux-arm64
gossa-mac gossa-mac
gossa-windows.exe gossa-windows.exe
gossa_test.go
.vscode .vscode
test-fixture/* test-fixture/*
+15 -12
View File
@@ -6,29 +6,32 @@ build:
rm gossa.go rm gossa.go
run: run:
make build
./gossa -verb=true test-fixture ./gossa -verb=true test-fixture
run-ro:
./gossa -verb=true -ro=true test-fixture
run-extra: run-extra:
make build
./gossa -verb=true -prefix="/fancy-path/" -k=false -symlinks=true test-fixture ./gossa -verb=true -prefix="/fancy-path/" -k=false -symlinks=true test-fixture
ci: test:
-@cd test-fixture && ln -s ../support .
make build make build
timeout 15 make run & -rm gossa_test.go
sleep 16 && timeout 15 make run-extra & -@cd test-fixture && ln -s ../support .
cp src/gossa_test.go . && go test cp src/gossa_test.go .
rm gossa_test.go go test
watch: watch:
ls src/* gossa-ui/* | entr -rc make run ls src/* gossa-ui/* | entr -rc make build run
watch-extra: watch-extra:
ls src/* gossa-ui/* | entr -rc make run-extra ls src/* gossa-ui/* | entr -rc make build run-extra
watch-ci: watch-ro:
ls src/* gossa-ui/* | entr -rc make ci ls src/* gossa-ui/* | entr -rc make build run-ro
watch-test:
ls src/* gossa-ui/* | entr -rc make test
build-all: build-all:
cp src/gossa.go gossa.go cp src/gossa.go gossa.go
+4 -3
View File
@@ -1,7 +1,7 @@
gossa gossa
============= =============
![e](https://user-images.githubusercontent.com/760637/64541706-a3163080-d322-11e9-85ef-a4d8001fa6a5.gif) ![e](https://user-images.githubusercontent.com/760637/71449335-790a4200-274a-11ea-80be-4c536fbad8a1.gif)
[![build status](https://github.com/pldubouilh/gossa/workflows/ci/badge.svg)](https://github.com/pldubouilh/gossa/actions) [![build status](https://github.com/pldubouilh/gossa/workflows/ci/badge.svg)](https://github.com/pldubouilh/gossa/actions)
[![docker build status](https://img.shields.io/docker/cloud/build/pldubouilh/gossa.svg?logo=docker)](https://hub.docker.com/r/pldubouilh/gossa) [![docker build status](https://img.shields.io/docker/cloud/build/pldubouilh/gossa.svg?logo=docker)](https://hub.docker.com/r/pldubouilh/gossa)
@@ -14,13 +14,14 @@ a [simple UI](https://github.com/pldubouilh/gossa-ui) comes as default, featurin
* 🔍 files/directories browser * 🔍 files/directories browser
* 📩 drag-and-drop file/directory uploader * 📩 drag-and-drop file/directory uploader
* 🚀 lightweight, default ui weights 110kB and prints in ms
* 🗺️ files handling - move/rename/delete * 🗺️ files handling - move/rename/delete
* 📸 picture browser * 📸 picture browser
* 📽️ video streaming * 📽️ video streaming
* ✍️ simple text editor * ✍️ simple text editor
* ⌨️ keyboard shortcuts * ⌨️ keyboard shortcuts
* 🥂 speed - will easily fill available bandwidth * 🥂 fast golang static server, easily fills available bandwidth
* 🔒 safe - easy/secure multi account setup * 🔒 easy/secure multi account setup
### build ### build
built blobs are available on the [release page](https://github.com/pldubouilh/gossa/releases) - or simply `make build` this repo. built blobs are available on the [release page](https://github.com/pldubouilh/gossa/releases) - or simply `make build` this repo.
+15 -8
View File
@@ -14,17 +14,18 @@ import (
"net/url" "net/url"
"os" "os"
"path/filepath" "path/filepath"
"sort"
"strconv" "strconv"
"strings" "strings"
) )
var host = flag.String("h", "127.0.0.1", "host to listen to") var host = flag.String("h", "127.0.0.1", "host to listen to")
var port = flag.String("p", "8001", "port to listen to") var port = flag.String("p", "8001", "port to listen to")
var history = flag.Bool("history", true, "keep history for paths visited. default location is path/.gossa_history")
var extraPath = flag.String("prefix", "/", "url prefix at which gossa can be reached, e.g. /gossa/ (slashes of importance)") 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 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 verb = flag.Bool("verb", false, "verbosity")
var skipHidden = flag.Bool("k", true, "\nskip hidden files") var skipHidden = flag.Bool("k", true, "\nskip hidden files")
var ro = flag.Bool("ro", false, "read only mode (no upload, rename, move, etc...)")
var initPath = "." var initPath = "."
var fs http.Handler var fs http.Handler
@@ -40,6 +41,7 @@ type rowTemplate struct {
type pageTemplate struct { type pageTemplate struct {
Title template.HTML Title template.HTML
ExtraPath template.HTML ExtraPath template.HTML
Ro bool
RowsFiles []rowTemplate RowsFiles []rowTemplate
RowsFolders []rowTemplate RowsFolders []rowTemplate
} }
@@ -77,9 +79,11 @@ func humanize(bytes int64) string {
} }
} }
func replyList(w http.ResponseWriter, r *http.Request, fullPath string, path string) { func replyList(w http.ResponseWriter, fullPath string, path string) {
_files, err := ioutil.ReadDir(fullPath) _files, err := ioutil.ReadDir(fullPath)
check(err) check(err)
sort.Slice(_files, func(i, j int) bool { return strings.ToLower(_files[i].Name()) < strings.ToLower(_files[j].Name()) })
if !strings.HasSuffix(path, "/") { if !strings.HasSuffix(path, "/") {
path += "/" path += "/"
} }
@@ -90,6 +94,7 @@ func replyList(w http.ResponseWriter, r *http.Request, fullPath string, path str
p.RowsFolders = append(p.RowsFolders, rowTemplate{"../", "../", "", "folder"}) p.RowsFolders = append(p.RowsFolders, rowTemplate{"../", "../", "", "folder"})
} }
p.ExtraPath = template.HTML(html.EscapeString(*extraPath)) p.ExtraPath = template.HTML(html.EscapeString(*extraPath))
p.Ro = *ro
p.Title = template.HTML(html.EscapeString(title)) p.Title = template.HTML(html.EscapeString(title))
for _, el := range _files { for _, el := range _files {
@@ -105,7 +110,8 @@ func replyList(w http.ResponseWriter, r *http.Request, fullPath string, path str
p.RowsFolders = append(p.RowsFolders, rowTemplate{el.Name() + "/", template.HTML(href), "", "folder"}) p.RowsFolders = append(p.RowsFolders, rowTemplate{el.Name() + "/", template.HTML(href), "", "folder"})
} else { } else {
sl := strings.Split(el.Name(), ".") 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])}) ext := strings.ToLower(sl[len(sl)-1])
p.RowsFiles = append(p.RowsFiles, rowTemplate{el.Name(), template.HTML(href), humanize(el.Size()), ext})
} }
} }
@@ -125,7 +131,7 @@ func doContent(w http.ResponseWriter, r *http.Request) {
check(errStat) check(errStat)
if stat.IsDir() { if stat.IsDir() {
replyList(w, r, fullPath, path) replyList(w, fullPath, path)
} else { } else {
fs.ServeHTTP(w, r) fs.ServeHTTP(w, r)
} }
@@ -147,7 +153,6 @@ func rpc(w http.ResponseWriter, r *http.Request) {
bodyBytes, _ := ioutil.ReadAll(r.Body) bodyBytes, _ := ioutil.ReadAll(r.Body)
json.Unmarshal(bodyBytes, &rpc) json.Unmarshal(bodyBytes, &rpc)
defer exitPath(w, "rpc", rpc) defer exitPath(w, "rpc", rpc)
ret := "ok"
if rpc.Call == "mkdirp" { if rpc.Call == "mkdirp" {
err = os.MkdirAll(checkPath(rpc.Args[0]), os.ModePerm) err = os.MkdirAll(checkPath(rpc.Args[0]), os.ModePerm)
@@ -158,7 +163,7 @@ func rpc(w http.ResponseWriter, r *http.Request) {
} }
check(err) check(err)
w.Write([]byte(ret)) w.Write([]byte("ok"))
} }
func checkPath(p string) string { func checkPath(p string) string {
@@ -188,8 +193,10 @@ func main() {
initPath, err = filepath.Abs(initPath) initPath, err = filepath.Abs(initPath)
check(err) check(err)
http.HandleFunc(*extraPath+"rpc", rpc) if !*ro {
http.HandleFunc(*extraPath+"post", upload) http.HandleFunc(*extraPath+"rpc", rpc)
http.HandleFunc(*extraPath+"post", upload)
}
http.HandleFunc("/", doContent) http.HandleFunc("/", doContent)
fs = http.StripPrefix(*extraPath, http.FileServer(http.Dir(initPath))) fs = http.StripPrefix(*extraPath, http.FileServer(http.Dir(initPath)))
fmt.Printf("Gossa startig on directory %s\nListening on http://%s:%s%s\n", initPath, *host, *port, *extraPath) fmt.Printf("Gossa startig on directory %s\nListening on http://%s:%s%s\n", initPath, *host, *port, *extraPath)
+93 -12
View File
@@ -5,6 +5,8 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os"
"os/exec"
"regexp" "regexp"
"strings" "strings"
"testing" "testing"
@@ -84,7 +86,7 @@ func fetchAndTestDefault(t *testing.T, url string) string {
return body0 return body0
} }
func doTest(t *testing.T, url string, testExtra bool) { func doTestRegular(t *testing.T, url string, testExtra bool) {
var payload, path, body0, body1, body2 string var payload, path, body0, body1, body2 string
// ~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~
@@ -229,20 +231,99 @@ func doTest(t *testing.T, url string, testExtra bool) {
if body0 != `ok` { if body0 != `ok` {
t.Fatal("cleanup errored #2") t.Fatal("cleanup errored #2")
} }
fmt.Printf("\r\n=========\r\n")
} }
func TestGetFolder(t *testing.T) { func doTestReadonly(t *testing.T, url string) {
time.Sleep(6 * time.Second) var payload, path, body0, body1 string
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test fetching default path")
fetchAndTestDefault(t, url)
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test fetching an invalid path - redirected to root")
fetchAndTestDefault(t, url+"../../")
fetchAndTestDefault(t, url+"hols/../../")
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test fetching regular files")
body0 = get(t, url+"subdir_with%20space/file_with%20space.html")
body1 = get(t, url+"fancy-path/a")
if body0 != `<b>spacious!!</b> ` || body1 != `fancy! ` {
t.Fatal("fetching a regular file errored")
}
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test fetching a invalid file")
path = "../../../../../../../../../../etc/passwd"
if get(t, url+path) != `error` {
t.Fatal("fetching a invalid file didnt errored")
}
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test mkdir rpc")
body0 = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["/AAA"]}`)
if body0 == `ok` {
t.Fatal("mkdir rpc passed - should not be allowed")
}
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test post file")
path = "%2F%E1%84%92%E1%85%A1%20%E1%84%92%E1%85%A1" // "하 하" encoded
payload = "123 하"
body0 = postDummyFile(t, url, path, payload)
body1 = get(t, url+path)
if body0 == `ok` {
t.Fatal("post file passed - should not be allowed")
}
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test mv rpc")
body0 = postJSON(t, url+"rpc", `{"call":"mv","args":["/AAA", "/hols/AAA"]}`)
body1 = fetchAndTestDefault(t, url)
if body0 == `ok` {
t.Fatal("mv rpc passed - should not be allowed")
}
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test rm rpc & cleanup")
body0 = postJSON(t, url+"rpc", `{"call":"rm","args":["/hols/AAA"]}`)
if body0 == `ok` {
t.Fatal("cleanup passed - should not be allowed")
}
fmt.Printf("\r\n=========\r\n")
}
func startGossa(what string) int {
cmd := exec.Command("/usr/bin/make", what)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stdout
cmd.Start()
time.Sleep(3 * time.Second)
return cmd.Process.Pid
}
func killallgossa() {
cmd := exec.Command("/usr/bin/killall", "gossa")
cmd.Start()
}
func TestGossa(t *testing.T) {
startGossa("run")
fmt.Println("========== testing normal path ============") fmt.Println("========== testing normal path ============")
url := "http://127.0.0.1:8001/" doTestRegular(t, "http://127.0.0.1:8001/", false)
doTest(t, url, false) killallgossa()
fmt.Printf("\r\n=========\r\n") startGossa("run-extra")
time.Sleep(10 * time.Second) fmt.Println("========== testing extras options ============")
doTestRegular(t, "http://127.0.0.1:8001/fancy-path/", true)
killallgossa()
url = "http://127.0.0.1:8001/fancy-path/" startGossa("run-ro")
fmt.Println("========== testing at fancy path ============") fmt.Println("========== testing read only ============")
doTest(t, url, true) doTestReadonly(t, "http://127.0.0.1:8001/")
killallgossa()
fmt.Printf("\r\n=========\r\n")
} }