mirror of
https://github.com/pldubouilh/gossa.git
synced 2026-08-29 13:27:02 -04:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
698f3ffaf8 | ||
|
|
dc1011bb5f | ||
|
|
5096f46ba4 | ||
|
|
f77b10d3de | ||
|
|
ccd6ae2bea | ||
|
|
858d30be9b | ||
|
|
0b586c5df9 | ||
|
|
d913176daa | ||
|
|
beac60f3d8 | ||
|
|
da7f60d5fc | ||
|
|
39d2d4b13f | ||
|
|
ec7168e718 | ||
|
|
95f01e47dd | ||
|
|
c9266d8849 | ||
|
|
e257d1145d | ||
|
|
698a418e5d | ||
|
|
e9eb3bf45b |
@@ -7,10 +7,10 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
- name: Set up Go 1.13
|
- name: Set up Go 1.12
|
||||||
uses: actions/setup-go@v1
|
uses: actions/setup-go@v1
|
||||||
with:
|
with:
|
||||||
go-version: 1.13
|
go-version: 1.12
|
||||||
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 test
|
run: make ci
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ 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/*
|
||||||
|
|||||||
@@ -2,57 +2,47 @@ build:
|
|||||||
cp src/gossa.go gossa.go
|
cp src/gossa.go gossa.go
|
||||||
make -C gossa-ui/
|
make -C gossa-ui/
|
||||||
go vet && go fmt
|
go vet && go fmt
|
||||||
CGO_ENABLED=0 go build
|
CGO_ENABLED=0 go build gossa.go
|
||||||
rm gossa.go
|
rm gossa.go
|
||||||
|
|
||||||
install:
|
|
||||||
sudo cp gossa /usr/local/bin
|
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
test:
|
ci:
|
||||||
make build
|
|
||||||
-rm gossa_test.go
|
|
||||||
-@cd test-fixture && ln -s ../support .
|
-@cd test-fixture && ln -s ../support .
|
||||||
cp src/gossa_test.go .
|
make build
|
||||||
-@killall gossa
|
timeout 15 make run &
|
||||||
make run &
|
sleep 16 && timeout 15 make run-extra &
|
||||||
go test -run TestNormal
|
cp src/gossa_test.go . && go test
|
||||||
killall gossa
|
rm gossa_test.go
|
||||||
make run-extra &
|
|
||||||
go test -run TestExtra
|
|
||||||
killall gossa
|
|
||||||
make run-ro &
|
|
||||||
go test -run TestRo
|
|
||||||
killall gossa
|
|
||||||
|
|
||||||
watch:
|
watch:
|
||||||
ls src/* gossa-ui/* | entr -rc make build run
|
ls src/* gossa-ui/* | entr -rc make run
|
||||||
|
|
||||||
watch-extra:
|
watch-extra:
|
||||||
ls src/* gossa-ui/* | entr -rc make build run-extra
|
ls src/* gossa-ui/* | entr -rc make run-extra
|
||||||
|
|
||||||
watch-ro:
|
watch-ci:
|
||||||
ls src/* gossa-ui/* | entr -rc make build run-ro
|
ls src/* gossa-ui/* | entr -rc make ci
|
||||||
|
|
||||||
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
|
||||||
make -C gossa-ui/
|
make -C gossa-ui/
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o gossa-linux64
|
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build gossa.go
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -o gossa-linux-arm
|
mv gossa gossa-linux64
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o gossa-linux-arm64
|
env GOOS=linux GOARCH=arm go build gossa.go
|
||||||
env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o gossa-mac
|
mv gossa gossa-linux-arm
|
||||||
env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o gossa-windows.exe
|
env GOOS=linux GOARCH=arm64 go build gossa.go
|
||||||
|
mv gossa gossa-linux-arm64
|
||||||
|
env GOOS=darwin GOARCH=amd64 go build gossa.go
|
||||||
|
mv gossa gossa-mac
|
||||||
|
env GOOS=windows GOARCH=amd64 go build gossa.go
|
||||||
|
mv gossa.exe gossa-windows.exe
|
||||||
rm gossa.go
|
rm gossa.go
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|||||||
+1
-1
Submodule gossa-ui updated: 26b93fd4bd...cc8fff1e26
@@ -1,33 +1,30 @@
|
|||||||
gossa
|
gossa
|
||||||
=============
|
=============
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
[](https://github.com/pldubouilh/gossa/actions)
|
[](https://github.com/pldubouilh/gossa/actions)
|
||||||
[](https://hub.docker.com/r/pldubouilh/gossa)
|
[](https://hub.docker.com/r/pldubouilh/gossa)
|
||||||
[](https://hub.docker.com/r/pldubouilh/gossa)
|
[](https://hub.docker.com/r/pldubouilh/gossa)
|
||||||
[](https://github.com/pldubouilh/gossa/releases)
|
[](https://github.com/pldubouilh/gossa/releases)
|
||||||
|
|
||||||
a fast and simple webserver for your files, that's dependency-free and with under 250 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 :
|
a [simple UI](https://github.com/pldubouilh/gossa-ui) comes as default, featuring :
|
||||||
|
|
||||||
* 🔍 files/directories browser & handler
|
* 🔍 files/directories browser
|
||||||
* 📩 drag-and-drop uploader
|
* 📩 drag-and-drop file/directory uploader
|
||||||
* 🚀 lightweight and dependency free
|
* 🗺️ files handling - move/rename/delete
|
||||||
* 💾 90s web UI that prints in ms
|
|
||||||
* 📸 picture browser
|
* 📸 picture browser
|
||||||
* 📽️ video streaming
|
* 📽️ video streaming
|
||||||
* ✍️ simple text editor
|
* ✍️ simple text editor
|
||||||
* ⌨️ keyboard navigation
|
* ⌨️ keyboard shortcuts
|
||||||
* 🥂 fast golang static server
|
* 🥂 speed - will easily fill available bandwidth
|
||||||
* 🔒 easy/secure multi account setup, read-only mode
|
* 🔒 safe - 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.
|
||||||
|
|
||||||
arch linux users can also install through the [user repos](https://aur.archlinux.org/packages/gossa/) - e.g. `yay -S gossa`
|
|
||||||
|
|
||||||
### usage
|
### usage
|
||||||
```sh
|
```sh
|
||||||
% ./gossa --help
|
% ./gossa --help
|
||||||
@@ -35,9 +32,6 @@ arch linux users can also install through the [user repos](https://aur.archlinux
|
|||||||
% ./gossa -h 192.168.100.33 ~/storage
|
% ./gossa -h 192.168.100.33 ~/storage
|
||||||
```
|
```
|
||||||
|
|
||||||
### shortcuts
|
|
||||||
press `Ctrl/Cmd + h` to see all the UI/keyboard shortcuts.
|
|
||||||
|
|
||||||
### fancier setups
|
### fancier setups
|
||||||
release images are pushed to [dockerhub](https://hub.docker.com/r/pldubouilh/gossa), e.g. :
|
release images are pushed to [dockerhub](https://hub.docker.com/r/pldubouilh/gossa), e.g. :
|
||||||
|
|
||||||
@@ -46,6 +40,8 @@ release images are pushed to [dockerhub](https://hub.docker.com/r/pldubouilh/gos
|
|||||||
% sudo docker run -v ~/LocalDirToShare:/shared -p 8001:8001 pldubouilh/gossa
|
% sudo docker run -v ~/LocalDirToShare:/shared -p 8001:8001 pldubouilh/gossa
|
||||||
```
|
```
|
||||||
|
|
||||||
in a do-one-thing-well mindset, HTTPS and authentication has been left to middlewares and proxies. [sample caddy configs](https://github.com/pldubouilh/gossa/blob/master/support/) are available to quickly setup multi users setups along with https.
|
in a do-one-thing-well mindset, HTTPS and authentication has been left to middlewares and proxies. for instance [caddy](https://caddyserver.com/) handles this very well - have a look at this small [caddy config](https://github.com/pldubouilh/gossa/blob/master/support/Caddyfile) with authentication and option for HTTPS that works along with gossa.
|
||||||
|
|
||||||
|
### shortcuts
|
||||||
|
the default UI is fully usable by through keyboard/UI shortcuts - press `Ctrl/Cmd + h` to see them all.
|
||||||
|
|
||||||
|
|||||||
+10
-49
@@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/zip"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
@@ -15,18 +14,17 @@ 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
|
||||||
@@ -42,7 +40,6 @@ 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
|
||||||
}
|
}
|
||||||
@@ -80,11 +77,9 @@ func humanize(bytes int64) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func replyList(w http.ResponseWriter, fullPath string, path string) {
|
func replyList(w http.ResponseWriter, r *http.Request, 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 += "/"
|
||||||
}
|
}
|
||||||
@@ -95,7 +90,6 @@ func replyList(w http.ResponseWriter, fullPath string, path string) {
|
|||||||
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 {
|
||||||
@@ -111,8 +105,7 @@ func replyList(w http.ResponseWriter, fullPath string, path string) {
|
|||||||
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(), ".")
|
||||||
ext := strings.ToLower(sl[len(sl)-1])
|
p.RowsFiles = append(p.RowsFiles, rowTemplate{el.Name(), template.HTML(href), humanize(el.Size()), strings.ToLower(sl[len(sl)-1])})
|
||||||
p.RowsFiles = append(p.RowsFiles, rowTemplate{el.Name(), template.HTML(href), humanize(el.Size()), ext})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +125,7 @@ func doContent(w http.ResponseWriter, r *http.Request) {
|
|||||||
check(errStat)
|
check(errStat)
|
||||||
|
|
||||||
if stat.IsDir() {
|
if stat.IsDir() {
|
||||||
replyList(w, fullPath, path)
|
replyList(w, r, fullPath, path)
|
||||||
} else {
|
} else {
|
||||||
fs.ServeHTTP(w, r)
|
fs.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
@@ -148,41 +141,13 @@ func upload(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Write([]byte("ok"))
|
w.Write([]byte("ok"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func walkZip(wz *zip.Writer, fp, baseInZip string) {
|
|
||||||
files, err := ioutil.ReadDir(fp)
|
|
||||||
check(err)
|
|
||||||
|
|
||||||
for _, file := range files {
|
|
||||||
if !file.IsDir() {
|
|
||||||
data, err := ioutil.ReadFile(fp + file.Name())
|
|
||||||
check(err)
|
|
||||||
f, err := wz.Create(baseInZip + file.Name())
|
|
||||||
check(err)
|
|
||||||
_, err = f.Write(data)
|
|
||||||
check(err)
|
|
||||||
} else if file.IsDir() {
|
|
||||||
newBase := fp + file.Name() + "/"
|
|
||||||
walkZip(wz, newBase, baseInZip+file.Name()+"/")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func zipRPC(w http.ResponseWriter, r *http.Request) {
|
|
||||||
zipPath := r.URL.Query().Get("zipPath")
|
|
||||||
zipName := r.URL.Query().Get("zipName")
|
|
||||||
defer exitPath(w, "zip", zipPath)
|
|
||||||
wz := zip.NewWriter(w)
|
|
||||||
w.Header().Add("Content-Disposition", "attachment; filename=\""+zipName+".zip\"")
|
|
||||||
walkZip(wz, checkPath(zipPath)+"/", "")
|
|
||||||
wz.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
func rpc(w http.ResponseWriter, r *http.Request) {
|
func rpc(w http.ResponseWriter, r *http.Request) {
|
||||||
var err error
|
var err error
|
||||||
var rpc rpcCall
|
var rpc rpcCall
|
||||||
defer exitPath(w, "rpc", rpc)
|
|
||||||
bodyBytes, _ := ioutil.ReadAll(r.Body)
|
bodyBytes, _ := ioutil.ReadAll(r.Body)
|
||||||
json.Unmarshal(bodyBytes, &rpc)
|
json.Unmarshal(bodyBytes, &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)
|
||||||
@@ -193,7 +158,7 @@ func rpc(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
check(err)
|
check(err)
|
||||||
w.Write([]byte("ok"))
|
w.Write([]byte(ret))
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkPath(p string) string {
|
func checkPath(p string) string {
|
||||||
@@ -223,15 +188,11 @@ func main() {
|
|||||||
initPath, err = filepath.Abs(initPath)
|
initPath, err = filepath.Abs(initPath)
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
if !*ro {
|
http.HandleFunc(*extraPath+"rpc", rpc)
|
||||||
http.HandleFunc(*extraPath+"rpc", rpc)
|
http.HandleFunc(*extraPath+"post", upload)
|
||||||
http.HandleFunc(*extraPath+"post", upload)
|
|
||||||
}
|
|
||||||
|
|
||||||
http.HandleFunc(*extraPath+"zip", zipRPC)
|
|
||||||
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 starting 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)
|
||||||
err = http.ListenAndServe(*host+":"+*port, nil)
|
err = http.ListenAndServe(*host+":"+*port, nil)
|
||||||
check(err)
|
check(err)
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-97
@@ -2,13 +2,13 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/sha256"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func dieMaybe(t *testing.T, err error) {
|
func dieMaybe(t *testing.T, err error) {
|
||||||
@@ -22,16 +22,11 @@ func trimSpaces(str string) string {
|
|||||||
return space.ReplaceAllString(str, " ")
|
return space.ReplaceAllString(str, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRaw(t *testing.T, url string) []byte {
|
func get(t *testing.T, url string) string {
|
||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url)
|
||||||
dieMaybe(t, err)
|
dieMaybe(t, err)
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
dieMaybe(t, err)
|
dieMaybe(t, err)
|
||||||
return body
|
|
||||||
}
|
|
||||||
|
|
||||||
func get(t *testing.T, url string) string {
|
|
||||||
body := getRaw(t, url)
|
|
||||||
return trimSpaces(string(body))
|
return trimSpaces(string(body))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +84,7 @@ func fetchAndTestDefault(t *testing.T, url string) string {
|
|||||||
return body0
|
return body0
|
||||||
}
|
}
|
||||||
|
|
||||||
func doTestRegular(t *testing.T, url string, testExtra bool) {
|
func doTest(t *testing.T, url string, testExtra bool) {
|
||||||
var payload, path, body0, body1, body2 string
|
var payload, path, body0, body1, body2 string
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~
|
||||||
@@ -118,21 +113,6 @@ func doTestRegular(t *testing.T, url string, testExtra bool) {
|
|||||||
fetchAndTestDefault(t, url+path) // extra path will just redirect to root dir
|
fetchAndTestDefault(t, url+path) // extra path will just redirect to root dir
|
||||||
}
|
}
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~
|
|
||||||
fmt.Println("\r\n~~~~~~~~~~ test zip")
|
|
||||||
bodyRaw := getRaw(t, url+"zip?zipPath=%2F%E4%B8%AD%E6%96%87%2F&zipName=%E4%B8%AD%E6%96%87")
|
|
||||||
hashStr := fmt.Sprintf("%x", sha256.Sum256(bodyRaw))
|
|
||||||
if hashStr != "b02436a76b149e6c4458bbbe622ab7c5e789bb0d26b87f604cf0f989cfaf669f" {
|
|
||||||
t.Fatal("invalid zip checksum", hashStr)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~
|
|
||||||
fmt.Println("\r\n~~~~~~~~~~ test zip invalid path")
|
|
||||||
body0 = get(t, url+"zip?zipPath=%2Ftmp&zipName=subdir")
|
|
||||||
if body0 != `error` {
|
|
||||||
t.Fatal("zip passed for invalid path")
|
|
||||||
}
|
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~
|
||||||
fmt.Println("\r\n~~~~~~~~~~ test mkdir rpc")
|
fmt.Println("\r\n~~~~~~~~~~ test mkdir rpc")
|
||||||
body0 = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["/AAA"]}`)
|
body0 = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["/AAA"]}`)
|
||||||
@@ -249,83 +229,20 @@ func doTestRegular(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 doTestReadonly(t *testing.T, url string) {
|
func TestGetFolder(t *testing.T) {
|
||||||
var payload, path, body0, body1 string
|
time.Sleep(6 * time.Second)
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~
|
|
||||||
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 TestNormal(t *testing.T) {
|
|
||||||
fmt.Println("========== testing normal path ============")
|
fmt.Println("========== testing normal path ============")
|
||||||
doTestRegular(t, "http://127.0.0.1:8001/", false)
|
url := "http://127.0.0.1:8001/"
|
||||||
}
|
doTest(t, url, false)
|
||||||
|
|
||||||
func TestExtra(t *testing.T) {
|
fmt.Printf("\r\n=========\r\n")
|
||||||
fmt.Println("========== testing extras options ============")
|
time.Sleep(10 * time.Second)
|
||||||
doTestRegular(t, "http://127.0.0.1:8001/fancy-path/", true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRo(t *testing.T) {
|
url = "http://127.0.0.1:8001/fancy-path/"
|
||||||
fmt.Println("========== testing read only ============")
|
fmt.Println("========== testing at fancy path ============")
|
||||||
doTestReadonly(t, "http://127.0.0.1:8001/")
|
doTest(t, url, true)
|
||||||
|
|
||||||
|
fmt.Printf("\r\n=========\r\n")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# Caddy config
|
||||||
|
# to enable https just set a valid domain (e.g. mydomain.com) instead of :8080 - how simple !
|
||||||
|
# authentication has been setup with 2 users, alice and bob
|
||||||
|
|
||||||
|
:8080
|
||||||
|
basicauth / alice paul
|
||||||
|
basicauth / bob dylan
|
||||||
|
proxy / 127.0.0.1:8001
|
||||||
@@ -3,9 +3,9 @@ COPY . /gossaSrc
|
|||||||
RUN cd /gossaSrc && make
|
RUN cd /gossaSrc && make
|
||||||
|
|
||||||
FROM alpine
|
FROM alpine
|
||||||
ENV UID="1000" GID="1000" HOST="0.0.0.0" PORT="8001" PREFIX="/" FOLLOW_SYMLINKS="false" SKIP_HIDDEN_FILES="true" DATADIR="/shared" READONLY="false"
|
ENV UID="1000" GID="1000" HOST="0.0.0.0" PORT="8001" PREFIX="/" FOLLOW_SYMLINKS="false" SKIP_HIDDEN_FILES="true" DATADIR="/shared"
|
||||||
EXPOSE 8001
|
EXPOSE 8001
|
||||||
RUN apk add --no-cache su-exec
|
RUN apk add --no-cache su-exec
|
||||||
COPY --from=builder /gossaSrc/gossa /gossa
|
COPY --from=builder /gossaSrc/gossa /gossa
|
||||||
RUN echo -e 'exec su-exec ${UID}:${GID} /gossa -h ${HOST} -p ${PORT} -k=${SKIP_HIDDEN_FILES} -ro=${READONLY} --symlinks=${FOLLOW_SYMLINKS} --prefix=${PREFIX} ${DATADIR}'>> /start.sh
|
RUN echo -e 'exec su-exec ${UID}:${GID} /gossa -h ${HOST} -p ${PORT} -k=${SKIP_HIDDEN_FILES} --symlinks=${FOLLOW_SYMLINKS} --prefix=${PREFIX} ${DATADIR}'>> /start.sh
|
||||||
ENTRYPOINT [ "sh", "/start.sh" ]
|
ENTRYPOINT [ "sh", "/start.sh" ]
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
FROM pldubouilh/gossa
|
||||||
|
|
||||||
|
RUN apk update && apk add curl ca-certificates caddy
|
||||||
|
|
||||||
|
ENV UID="1000" GID="1000" HOST="127.0.0.1" PORT="8001" PREFIX="/" FOLLOW_SYMLINKS="false" SKIP_HIDDEN_FILES="true" DATADIR="/shared"
|
||||||
|
EXPOSE 443
|
||||||
|
RUN echo -e 'exec su-exec ${UID}:${GID} /gossa -h ${HOST} -p ${PORT} -k=${SKIP_HIDDEN_FILES} --symlinks=${FOLLOW_SYMLINKS} --prefix=${PREFIX} ${DATADIR} & \n caddy' > /start.sh
|
||||||
|
ENTRYPOINT [ "sh", "/start.sh" ]
|
||||||
+7
-90
@@ -1,110 +1,27 @@
|
|||||||
## docker
|
|
||||||
|
|
||||||
the master branch is automatically built and pushed to [dockerhub](https://hub.docker.com/r/pldubouilh/gossa) under `pldubouilh/gossa`.
|
the master branch is automatically built and pushed to [dockerhub](https://hub.docker.com/r/pldubouilh/gossa) under `pldubouilh/gossa`.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# pull from dockerhub and run
|
# pull from dockerhub and run
|
||||||
% mkdir ~/LocalDirToShare
|
|
||||||
% sudo docker run -v ~/LocalDirToShare:/shared -p 8001:8001 pldubouilh/gossa
|
% sudo docker run -v ~/LocalDirToShare:/shared -p 8001:8001 pldubouilh/gossa
|
||||||
|
|
||||||
# options are settable through env. variabes. all the options are the build.Dockerfile
|
|
||||||
% sudo docker run -e PREFIX="/gossa/" -v ~/LocalDirToShare:/shared -p 8001:8001 pldubouilh/gossa
|
|
||||||
```
|
```
|
||||||
|
|
||||||
if you prefer building the image yourself :
|
if you prefer building the image yourself :
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# build gossa within a build container, needs to be ran within the sources, ../ from here, and run
|
# build gossa within a build container, needs to be ran within the sources, ../ from here, and run
|
||||||
% mkdir ~/LocalDirToShare
|
|
||||||
% docker build -t gossa -f support/build.Dockerfile .
|
% docker build -t gossa -f support/build.Dockerfile .
|
||||||
% sudo docker run -v ~/LocalDirToShare:/shared -p 8001:8001 gossa
|
% sudo docker run -v ~/LocalDirToShare:/shared -p 8001:8001 gossa
|
||||||
```
|
```
|
||||||
|
|
||||||
a docker-compose example image is also provided. running docker compose should be straightforward : `docker-compose up .` have a look in `docker-compose.yml` for further configuration.
|
the options are settable through environment variables that can be passed starting off the docker image.
|
||||||
|
|
||||||
## multi-account setup
|
a fancy docker image using [Caddy](https://caddyserver.com/) is also provided. have a look at the simple config file `Caddyfile`, it shows how to use http basic authentication, and automatic TLS for hands-free https 🎉
|
||||||
|
|
||||||
authentication / user routing has been left out of the design of gossa, as simple tools are already available for this purpose. [caddy](https://caddyserver.com/v1/) is used here as an example, but other proxy can be used in a similar fashion.
|
|
||||||
|
|
||||||
### example 1 root, multiple read-only users
|
|
||||||
|
|
||||||
this sample caddy config will
|
|
||||||
+ enable https on the domain myserver.com
|
|
||||||
+ password protect the access
|
|
||||||
+ route the root user requests to 1 gossa instance
|
|
||||||
+ route user1 and user2 requests to a readonly gossa instance
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
myserver.com
|
# checkout the caddy config, build, and run docker image
|
||||||
|
% vim caddy.Dockerfile
|
||||||
# proxy regular and read only instance
|
% docker build -t gossa-caddy -f caddy.Dockerfile .
|
||||||
proxy / 127.0.0.1:8001
|
% sudo docker run -v ~/LocalDirToShare:/shared -v `pwd`/Caddyfile:/Caddyfile --net=host gossa-caddy
|
||||||
proxy /ro 127.0.0.1:8002 { without /ro }
|
|
||||||
|
|
||||||
# reroute non-root user to read-only
|
|
||||||
# cm9... is the output of `printf "root:password" | base64`
|
|
||||||
rewrite {
|
|
||||||
if {>Authorization} not "Basic cm9vdDpwYXNzd29yZA=="
|
|
||||||
to /ro/{path}
|
|
||||||
}
|
|
||||||
|
|
||||||
# gate access
|
|
||||||
basicauth / root password
|
|
||||||
basicauth / ro_user1 passworduser1
|
|
||||||
basicauth / ro_user2 passworduser2
|
|
||||||
```
|
```
|
||||||
|
|
||||||
then simply start the 2 gossa instances, and caddy
|
a docker-compose example image is also provided. running docker compose should be straightforward : `docker-compose up .` have a look in `docker-compose.yml` for further configuration.
|
||||||
|
|
||||||
```sh
|
|
||||||
# start an instance in readonly
|
|
||||||
% ./gossa -ro=true -p 8002 ~/folder &
|
|
||||||
|
|
||||||
# start an instance with access to hidden files
|
|
||||||
% ./gossa -k=false -p 8001 ~/folder &
|
|
||||||
|
|
||||||
# start caddy
|
|
||||||
% ./caddy
|
|
||||||
```
|
|
||||||
|
|
||||||
### example 2 users on 2 different folders
|
|
||||||
|
|
||||||
this sample caddy config will
|
|
||||||
+ enable https on the domain myserver.com
|
|
||||||
+ password protect the access
|
|
||||||
+ route user1 to own folder
|
|
||||||
+ route user2 to own folder
|
|
||||||
+ share a folder between 2 users with a symlink
|
|
||||||
|
|
||||||
```sh
|
|
||||||
myserver.com
|
|
||||||
|
|
||||||
proxy /user1 127.0.0.1:8001 { without /user1 }
|
|
||||||
proxy /user2 127.0.0.1:8002 { without /user2 }
|
|
||||||
|
|
||||||
basicauth / user1 passworduser1
|
|
||||||
basicauth / user2 passworduser2
|
|
||||||
|
|
||||||
rewrite {
|
|
||||||
if {>Authorization} is "Basic dXNlcjE6cGFzc3dvcmR1c2VyMQ=="
|
|
||||||
to /user1/{path}
|
|
||||||
}
|
|
||||||
|
|
||||||
rewrite {
|
|
||||||
if {>Authorization} is "Basic dXNlcjI6cGFzc3dvcmR1c2VyMg=="
|
|
||||||
to /user2/{path}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
start 2 gossa instances, and caddy
|
|
||||||
|
|
||||||
```sh
|
|
||||||
# create symlink to share folder between 2 users
|
|
||||||
% ln -s /path/shared test/user1
|
|
||||||
% ln -s /path/shared test/user2
|
|
||||||
|
|
||||||
# start gossa & caddy
|
|
||||||
% ./gossa -p 8001 -symlinks=true test/user1 &
|
|
||||||
% ./gossa -p 8002 -symlinks=true test/user2 &
|
|
||||||
% ./caddy
|
|
||||||
```
|
|
||||||
Reference in New Issue
Block a user