mirror of
https://github.com/pldubouilh/gossa.git
synced 2026-08-29 13:27:02 -04:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df85a1c5a2 | ||
|
|
e2aa4f149e | ||
|
|
8a7a542b22 | ||
|
|
e490853baa | ||
|
|
557b3fd50d | ||
|
|
1992815b41 | ||
|
|
97e24cc513 | ||
|
|
c1eeb9820a | ||
|
|
dd6cb90e9d | ||
|
|
682e76da1f | ||
|
|
43e8e36ea2 | ||
|
|
56f418bbff | ||
|
|
c7e92cb730 | ||
|
|
5ea4838d19 | ||
|
|
50b9bc77ba | ||
|
|
2cd2753480 | ||
|
|
a39424159d | ||
|
|
32b64da0e6 | ||
|
|
2565dcca13 | ||
|
|
39611d2df3 | ||
|
|
55e729e434 | ||
|
|
7f690bc75f | ||
|
|
308ad9461e | ||
|
|
1119146cef | ||
|
|
f0abad8b78 | ||
|
|
551c334cdd | ||
|
|
49cfc28d34 | ||
|
|
be39e6aca8 | ||
|
|
b2e0396cf1 | ||
|
|
e22ef1bc12 | ||
|
|
5c9c8983e1 | ||
|
|
31775b6ae9 |
@@ -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
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ gossa-linux-arm
|
|||||||
gossa-linux-arm64
|
gossa-linux-arm64
|
||||||
gossa-mac
|
gossa-mac
|
||||||
gossa-windows.exe
|
gossa-windows.exe
|
||||||
|
gossa_test.go
|
||||||
|
build-all
|
||||||
|
|
||||||
.vscode
|
.vscode
|
||||||
test-fixture/*
|
test-fixture/*
|
||||||
|
|||||||
@@ -1,48 +1,65 @@
|
|||||||
|
FLAGS := -ldflags "-s -w"
|
||||||
|
NOCGO := CGO_ENABLED=0
|
||||||
|
|
||||||
build:
|
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 gossa.go
|
${NOCGO} go build ${FLAGS} -o gossa
|
||||||
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
|
||||||
|
|
||||||
ci:
|
test:
|
||||||
-@cd test-fixture && ln -s ../support .
|
|
||||||
make build
|
make build
|
||||||
timeout 15 make run &
|
rm -rf gossa_test.go
|
||||||
sleep 16 && timeout 15 make run-extra &
|
-@cd test-fixture && ln -s ../support .; true
|
||||||
cp src/gossa_test.go . && go test
|
cp src/gossa_test.go .
|
||||||
rm gossa_test.go
|
|
||||||
|
-@killall gossa; true
|
||||||
|
-make run &
|
||||||
|
go test -run TestNormal
|
||||||
|
|
||||||
|
killall gossa
|
||||||
|
-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 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
|
||||||
make -C gossa-ui/
|
make -C gossa-ui/
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build gossa.go
|
${NOCGO} GOOS=linux GOARCH=amd64 go build ${FLAGS} -o build-all/gossa-linux64
|
||||||
mv gossa gossa-linux64
|
${NOCGO} GOOS=linux GOARCH=arm go build ${FLAGS} -o build-all/gossa-linux-arm
|
||||||
env GOOS=linux GOARCH=arm go build gossa.go
|
${NOCGO} GOOS=linux GOARCH=arm64 go build ${FLAGS} -o build-all/gossa-linux-arm64
|
||||||
mv gossa gossa-linux-arm
|
${NOCGO} GOOS=darwin GOARCH=amd64 go build ${FLAGS} -o build-all/gossa-mac
|
||||||
env GOOS=linux GOARCH=arm64 go build gossa.go
|
${NOCGO} GOOS=windows GOARCH=amd64 go build ${FLAGS} -o build-all/gossa-windows.exe
|
||||||
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:
|
||||||
@@ -54,3 +71,4 @@ clean:
|
|||||||
-rm gossa-linux-arm64
|
-rm gossa-linux-arm64
|
||||||
-rm gossa-mac
|
-rm gossa-mac
|
||||||
-rm gossa-windows.exe
|
-rm gossa-windows.exe
|
||||||
|
|
||||||
|
|||||||
+1
-1
Submodule gossa-ui updated: cc8fff1e26...a057f08e1d
@@ -1,30 +1,34 @@
|
|||||||
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 200 lines of code, easy to review.
|
a fast and simple webserver for your files, that's dependency-free and with under 250 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
|
* 🔍 files/directories browser & handler
|
||||||
* 📩 drag-and-drop file/directory uploader
|
* 📩 drag-and-drop uploader
|
||||||
* 🗺️ files handling - move/rename/delete
|
* 🚀 lightweight and dependency free
|
||||||
|
* 💾 90s web UI that prints in ms
|
||||||
* 📸 picture browser
|
* 📸 picture browser
|
||||||
* 📽️ video streaming
|
* 📽️ video streaming
|
||||||
* ✍️ simple text editor
|
* ✍️ simple text editor
|
||||||
* ⌨️ keyboard shortcuts
|
* ⌨️ keyboard navigation
|
||||||
* 🥂 speed - will easily fill available bandwidth
|
* 🥂 fast golang static server
|
||||||
* 🔒 safe - easy/secure multi account setup
|
* 🔒 easy/secure multi account setup, read-only mode
|
||||||
|
* ✨ PWA enabled
|
||||||
|
|
||||||
### 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
|
||||||
@@ -32,6 +36,9 @@ built blobs are available on the [release page](https://github.com/pldubouilh/go
|
|||||||
% ./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. :
|
||||||
|
|
||||||
@@ -40,8 +47,6 @@ 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. 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.
|
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.
|
||||||
|
|
||||||
### shortcuts
|
|
||||||
the default UI is fully usable by through keyboard/UI shortcuts - press `Ctrl/Cmd + h` to see them all.
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
name: gossa
|
||||||
|
version: git
|
||||||
|
summary: a fast and simple webserver for your files.
|
||||||
|
description: |
|
||||||
|
a fast and simple webserver for your files, that's dependency-free and easy to review.
|
||||||
|
confinement: strict
|
||||||
|
base: core18
|
||||||
|
parts:
|
||||||
|
gossa:
|
||||||
|
plugin: go
|
||||||
|
go-importpath: github.com/pldubouilh/gossa
|
||||||
|
source: .
|
||||||
|
source-type: git
|
||||||
|
build-packages:
|
||||||
|
- gcc
|
||||||
|
apps:
|
||||||
|
gossa:
|
||||||
|
command: gossa
|
||||||
+57
-9
@@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"archive/zip"
|
||||||
|
"compress/gzip"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
@@ -14,17 +16,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 +43,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
|
||||||
}
|
}
|
||||||
@@ -80,6 +84,8 @@ func humanize(bytes int64) string {
|
|||||||
func replyList(w http.ResponseWriter, r *http.Request, 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 += "/"
|
||||||
}
|
}
|
||||||
@@ -90,6 +96,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,11 +112,20 @@ 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})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
page.Execute(w, p)
|
if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
|
||||||
|
w.Header().Set("Content-Type", "text/html")
|
||||||
|
w.Header().Add("Content-Encoding", "gzip")
|
||||||
|
gz, _ := gzip.NewWriterLevel(w, gzip.BestSpeed) // BestSpeed is much faster than Default on a very unscientific local test, and only ~30% larger (compression remains still very effective, ~6x)
|
||||||
|
defer gz.Close()
|
||||||
|
page.Execute(gz, p)
|
||||||
|
} else {
|
||||||
|
page.Execute(w, p)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func doContent(w http.ResponseWriter, r *http.Request) {
|
func doContent(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -141,13 +157,41 @@ 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)
|
||||||
@@ -158,7 +202,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,11 +232,15 @@ 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(*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 startig on directory %s\nListening on http://%s:%s%s\n", initPath, *host, *port, *extraPath)
|
fmt.Printf("Gossa starting 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)
|
||||||
}
|
}
|
||||||
|
|||||||
+97
-14
@@ -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,11 +22,16 @@ func trimSpaces(str string) string {
|
|||||||
return space.ReplaceAllString(str, " ")
|
return space.ReplaceAllString(str, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
func get(t *testing.T, url string) string {
|
func getRaw(t *testing.T, url string) []byte {
|
||||||
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))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +89,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
|
||||||
|
|
||||||
// ~~~~~~~~~~~~~~~~~
|
// ~~~~~~~~~~~~~~~~~
|
||||||
@@ -113,6 +118,21 @@ func doTest(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"]}`)
|
||||||
@@ -229,20 +249,83 @@ 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 TestNormal(t *testing.T) {
|
||||||
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)
|
}
|
||||||
|
|
||||||
fmt.Printf("\r\n=========\r\n")
|
func TestExtra(t *testing.T) {
|
||||||
time.Sleep(10 * time.Second)
|
fmt.Println("========== testing extras options ============")
|
||||||
|
doTestRegular(t, "http://127.0.0.1:8001/fancy-path/", true)
|
||||||
|
}
|
||||||
|
|
||||||
url = "http://127.0.0.1:8001/fancy-path/"
|
func TestRo(t *testing.T) {
|
||||||
fmt.Println("========== testing at fancy path ============")
|
fmt.Println("========== testing read only ============")
|
||||||
doTest(t, url, true)
|
doTestReadonly(t, "http://127.0.0.1:8001/")
|
||||||
|
|
||||||
fmt.Printf("\r\n=========\r\n")
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
# 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"
|
ENV UID="1000" GID="1000" HOST="0.0.0.0" PORT="8001" PREFIX="/" FOLLOW_SYMLINKS="false" SKIP_HIDDEN_FILES="true" DATADIR="/shared" READONLY="false"
|
||||||
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} --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} -ro=${READONLY} --symlinks=${FOLLOW_SYMLINKS} --prefix=${PREFIX} ${DATADIR}'>> /start.sh
|
||||||
ENTRYPOINT [ "sh", "/start.sh" ]
|
ENTRYPOINT [ "sh", "/start.sh" ]
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
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" ]
|
|
||||||
+90
-7
@@ -1,27 +1,110 @@
|
|||||||
|
## 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
|
||||||
```
|
```
|
||||||
|
|
||||||
the options are settable through environment variables that can be passed starting off the docker image.
|
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.
|
||||||
|
|
||||||
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 🎉
|
## multi-account setup
|
||||||
|
|
||||||
|
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
|
||||||
# checkout the caddy config, build, and run docker image
|
myserver.com
|
||||||
% vim caddy.Dockerfile
|
|
||||||
% docker build -t gossa-caddy -f caddy.Dockerfile .
|
# proxy regular and read only instance
|
||||||
% sudo docker run -v ~/LocalDirToShare:/shared -v `pwd`/Caddyfile:/Caddyfile --net=host gossa-caddy
|
proxy / 127.0.0.1:8001
|
||||||
|
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
|
||||||
```
|
```
|
||||||
|
|
||||||
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.
|
then simply start the 2 gossa instances, and caddy
|
||||||
|
|
||||||
|
```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