Compare commits

...
31 Commits
Author SHA1 Message Date
Pierre Dubouilh e2aa4f149e shuffle makefile & add empty go.mod
go 1.16 requires go.mod in git folders now apparently
2021-04-17 16:06:57 +02:00
Pierre Dubouilh 8a7a542b22 bump ui 2021-04-17 16:06:57 +02:00
Pierre Dubouilh e490853baa add compression on page
and strip build blobs
2021-04-17 16:06:57 +02:00
Pierre Dubouilh 557b3fd50d fix dockerbuild 2020-10-25 15:48:22 +01:00
Pierre DubouilhandSharad Bhat 1992815b41 Fixup typo
Co-authored-by: Sharad Bhat <sharad.mbhat@gmail.com>
2020-10-04 16:57:03 +02:00
Pierre Dubouilh 97e24cc513 fixup tests 2020-10-04 16:57:03 +02:00
Pierre Dubouilh c1eeb9820a archive download 2020-10-04 16:57:03 +02:00
Pierre Dubouilh dd6cb90e9d bump ui 2020-08-08 13:52:03 +02:00
Pierre Dubouilh 682e76da1f bump ui 2020-07-11 12:08:13 +02:00
Pierre Dubouilh 43e8e36ea2 Merge pull request #58 from pldubouilh/pld/bump-ui
bump ui
2020-06-28 13:11:48 +02:00
Pierre Dubouilh 56f418bbff reword readme 2020-06-28 13:10:44 +02:00
Pierre Dubouilh c7e92cb730 add install instructions to makefile 2020-06-28 12:49:03 +02:00
Pierre Dubouilh 5ea4838d19 bump ui 2020-06-28 12:48:34 +02:00
Pierre Dubouilh 50b9bc77ba Merge pull request #56 from shrmnk/patch-1
Add option for read-only mode in dockerfile
2020-06-12 10:40:05 +02:00
Sherman K 2cd2753480 Add option for read-only mode in dockerfile 2020-06-12 15:49:17 +08:00
Pierre Dubouilh a39424159d Merge pull request #54 from pldubouilh/readmes
push caddy examples
2020-06-07 17:49:55 +02:00
Pierre Dubouilh 32b64da0e6 mkdir folder before docker run 2020-06-07 17:42:16 +02:00
Pierre Dubouilh 2565dcca13 push caddy examples 2020-06-07 17:35:45 +02:00
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
29 changed files with 429 additions and 237 deletions
+5 -5
View File
@@ -1,4 +1,4 @@
name: Go
name: ci
on: [push, pull_request]
jobs:
@@ -7,16 +7,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.12
- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.12
go-version: 1.13
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v1
with:
with:
submodules: true
- name: Run
run: make ci
run: make test
+5
View File
@@ -4,10 +4,13 @@ gossa-linux-arm
gossa-linux-arm64
gossa-mac
gossa-windows.exe
gossa_test.go
build-all
.vscode
test-fixture/*
test-fixture/*/*
!test-fixture/.testhidden
!test-fixture/compress
!test-fixture/compress/foo*
!test-fixture/gzip
@@ -36,3 +39,5 @@ test-fixture/*/*
!test-fixture/hols/scotland-1761292_1920.jpg
!test-fixture/fancy-path
!test-fixture/fancy-path/*
!test-fixture/ext/*
!test-fixture/ext
-5
View File
@@ -1,5 +0,0 @@
language: go
go:
- "1.10"
script:
- make ci
+43 -25
View File
@@ -1,48 +1,65 @@
FLAGS := -ldflags "-s -w"
NOCGO := CGO_ENABLED=0
build:
cp src/gossa.go gossa.go
make -C gossa-ui/
go vet && go fmt
CGO_ENABLED=0 go build gossa.go
${NOCGO} go build ${FLAGS} -o gossa
rm gossa.go
install:
sudo cp gossa /usr/local/bin
run:
make build
./gossa test-fixture
./gossa -verb=true test-fixture
run-ro:
./gossa -verb=true -ro=true test-fixture
run-extra:
make build
./gossa -prefix="/fancy-path/" -symlinks=true test-fixture
./gossa -verb=true -prefix="/fancy-path/" -k=false -symlinks=true test-fixture
ci:
-@cd test-fixture && ln -s ../docker .
test:
make build
timeout 10 make run &
sleep 11 && timeout 10 make run-extra &
cp src/gossa_test.go . && go test
rm gossa_test.go
rm -rf gossa_test.go
-@cd test-fixture && ln -s ../support .; true
cp src/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:
ls src/* gossa-ui/* | entr -rc make run
ls src/* gossa-ui/* | entr -rc make build run
watch-extra:
ls src/* gossa-ui/* | entr -rc make run-extra
ls src/* gossa-ui/* | entr -rc make build run-extra
watch-ci:
ls src/* gossa-ui/* | entr -rc make ci
watch-ro:
ls src/* gossa-ui/* | entr -rc make build run-ro
watch-test:
ls src/* gossa-ui/* | entr -rc make test
build-all:
cp src/gossa.go gossa.go
make -C gossa-ui/
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build gossa.go
mv gossa gossa-linux64
env GOOS=linux GOARCH=arm go build gossa.go
mv gossa gossa-linux-arm
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
${NOCGO} GOOS=linux GOARCH=amd64 go build ${FLAGS} -o build-all/gossa-linux64
${NOCGO} GOOS=linux GOARCH=arm go build ${FLAGS} -o build-all/gossa-linux-arm
${NOCGO} GOOS=linux GOARCH=arm64 go build ${FLAGS} -o build-all/gossa-linux-arm64
${NOCGO} GOOS=darwin GOARCH=amd64 go build ${FLAGS} -o build-all/gossa-mac
${NOCGO} GOOS=windows GOARCH=amd64 go build ${FLAGS} -o build-all/gossa-windows.exe
rm gossa.go
clean:
@@ -54,3 +71,4 @@ clean:
-rm gossa-linux-arm64
-rm gossa-mac
-rm gossa-windows.exe
-22
View File
@@ -1,22 +0,0 @@
FROM alpine
# download and prepare caddy
RUN apk update && apk add curl ca-certificates
RUN curl -L -o caddy.tar.gz "https://github.com/mholt/caddy/releases/download/v0.11.1/caddy_v0.11.1_linux_amd64.tar.gz"
RUN tar xvzf caddy.tar.gz && mv caddy /caddy
# download and prepare gossa
RUN curl -L -o /gossa "https://github.com/pldubouilh/gossa/releases/download/v0.0.7/gossa-linux64"
RUN chmod +x /gossa /caddy
# Caddy config:
# * http basic auth is implemented here, with bob as user and dylan as password
# * to enable https just set a valid domain instead of *:8001 - how simple !
RUN echo -e '\n\
*:8001\n\
basicauth / bob dylan\n\
proxy / 127.0.0.1:8000\n\
'>> /Caddyfile
RUN echo -e '/gossa -h 127.0.0.1 -p 8000 /shared & \n /caddy'>> /start.sh
ENTRYPOINT [ "sh", "/start.sh" ]
-10
View File
@@ -1,10 +0,0 @@
FROM alpine
ENV UID="1000" GID="1000" HOST="0.0.0.0" PORT="8001" PREFIX="/" FOLLOW_SYMLINKS="false" SKIP_HIDDEN_FILES="true" DATADIR="/shared"
EXPOSE 8001
RUN apk add --no-cache su-exec
RUN wget https://github.com/pldubouilh/gossa/releases/download/v0.0.8/gossa-linux64 && mv gossa-linux64 /gossa && chmod +x /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
ENTRYPOINT [ "sh", "/start.sh" ]
-29
View File
@@ -1,29 +0,0 @@
the master branch is automatically built and pushed to [dockerhub](https://hub.docker.com/r/pldubouilh/gossa) under `pldubouilh/gossa`.
```sh
# pull from dockerhub and run
% sudo docker run -v ~/LocalDirToShare:/shared -p 8001:8001 pldubouilh/gossa
```
if you prefer building the image yourself :
```sh
# build gossa within a build container, needs to be ran within the sources, ../ from here
% docker build -t gossa -f docker/build.Dockerfile .
# and to run it simply
% sudo docker run -v ~/LocalDirToShare:/shared -p 8001:8001 gossa
```
a fancy docker image using [Caddy](https://caddyserver.com/) is also provided. a simple config is embedded in the docker file, and shows how to use http basic authentication, and automatic TLS for hands-free https 🎉
```sh
# run with caddy, checkout the config in the dockerfile
% docker build -t gossa -f caddy.Dockerfile .
# run with caddy
% sudo docker run -v ~/LocalDirToShare:/shared --net=host 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.
+3
View File
@@ -0,0 +1,3 @@
module github.com/pldubouilh/gossa
go 1.16
+23 -34
View File
@@ -1,28 +1,33 @@
gossa
=============
![e](https://user-images.githubusercontent.com/760637/52522293-942fa880-2c83-11e9-9f79-0a5b922bcc7f.gif)
![e](https://user-images.githubusercontent.com/760637/71449335-790a4200-274a-11ea-80be-4c536fbad8a1.gif)
[![build status](https://img.shields.io/travis/pldubouilh/gossa.svg?logo=travis)](https://travis-ci.org/pldubouilh/gossa)
[![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 pulls](https://img.shields.io/docker/pulls/pldubouilh/gossa.svg?logo=docker)](https://hub.docker.com/r/pldubouilh/gossa)
[![github downloads](https://img.shields.io/github/downloads/pldubouilh/gossa/total.svg?logo=github)](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 :
* 🔍 files/directories browser
* 📩 drag-and-drop file/directory uploader
* 🗺️ files handling - move/rename/delete
* 🔍 files/directories browser & handler
* 📩 drag-and-drop uploader
* 🚀 lightweight and dependency free
* 💾 90s web UI that prints in ms
* 📸 picture browser
* 📽️ video streaming from the browser
* 📽️ video streaming
* ✍️ simple text editor
* ⌨️ keyboard shortcuts
* 🥂 speed - showed rates above 100MB/s
* ⌨️ keyboard navigation
* 🥂 fast golang static server
* 🔒 easy/secure multi account setup, read-only mode
* ✨ PWA enabled
### 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
```sh
@@ -31,33 +36,17 @@ built blobs are available on the [release page](https://github.com/pldubouilh/go
% ./gossa -h 192.168.100.33 ~/storage
```
### ui shortcuts
|shortcut | action|
| ------------- |-------------|
|click new folder icon | create new folder|
|click pad icon | open file editor|
|click file icon | rename item|
|double click file icon | delete item|
|drag-and-drop item on UI | move item|
|drag-and-drop external item | upload file/folders|
### shortcuts
press `Ctrl/Cmd + h` to see all the UI/keyboard shortcuts.
### keyboard shortcuts
|shortcut | action|
|-------------|-------------|
|Arrows/Enter | browse through files/directories and pictures|
|Ctrl/Meta + C | copy URL to clipboard|
|Ctrl/Meta + E | rename file/folder|
|Ctrl/Meta + Del | delete file/folder|
|Ctrl/Meta + U | upload new file/folder|
|Ctrl/Meta + D | create a new directory|
|Ctrl/Meta + X | cut selected path|
|Ctrl/Meta + V | paste previously selected paths to directory|
|\<any letter\> | search|
### using with docker
a few docker/docker-compose files are provided in the [docker folder](https://github.com/pldubouilh/gossa/tree/master/docker). release images are also pushed to [dockerhub](https://hub.docker.com/r/pldubouilh/gossa), e.g. :
### fancier setups
release images are pushed to [dockerhub](https://hub.docker.com/r/pldubouilh/gossa), e.g. :
```sh
# pull from dockerhub and run
% 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.
+66 -16
View File
@@ -1,6 +1,8 @@
package main
import (
"archive/zip"
"compress/gzip"
"encoding/json"
"errors"
"flag"
@@ -14,6 +16,7 @@ import (
"net/url"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
)
@@ -22,8 +25,9 @@ var host = flag.String("h", "127.0.0.1", "host to listen to")
var port = flag.String("p", "8001", "port to listen to")
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", true, "verbosity")
var skipHidden = flag.Bool("k", true, "skip hidden files")
var verb = flag.Bool("verb", false, "verbosity")
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 fs http.Handler
@@ -39,6 +43,7 @@ type rowTemplate struct {
type pageTemplate struct {
Title template.HTML
ExtraPath template.HTML
Ro bool
RowsFiles []rowTemplate
RowsFolders []rowTemplate
}
@@ -76,9 +81,10 @@ 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)
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, "/") {
path += "/"
@@ -90,6 +96,7 @@ func replyList(w http.ResponseWriter, fullPath string, path string) {
p.RowsFolders = append(p.RowsFolders, rowTemplate{"../", "../", "", "folder"})
}
p.ExtraPath = template.HTML(html.EscapeString(*extraPath))
p.Ro = *ro
p.Title = template.HTML(html.EscapeString(title))
for _, el := range _files {
@@ -110,7 +117,15 @@ func replyList(w http.ResponseWriter, fullPath string, path string) {
}
}
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) {
@@ -126,7 +141,7 @@ func doContent(w http.ResponseWriter, r *http.Request) {
check(errStat)
if stat.IsDir() {
replyList(w, fullPath, path)
replyList(w, r, fullPath, path)
} else {
fs.ServeHTTP(w, r)
}
@@ -142,12 +157,41 @@ func upload(w http.ResponseWriter, r *http.Request) {
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) {
var err error
var rpc rpcCall
defer exitPath(w, "rpc", rpc)
bodyBytes, _ := ioutil.ReadAll(r.Body)
json.Unmarshal(bodyBytes, &rpc)
defer exitPath(w, "rpc", rpc)
if rpc.Call == "mkdirp" {
err = os.MkdirAll(checkPath(rpc.Args[0]), os.ModePerm)
@@ -162,11 +206,11 @@ func rpc(w http.ResponseWriter, r *http.Request) {
}
func checkPath(p string) string {
p = filepath.Join(initPath, strings.TrimPrefix(p, *extraPath))
fp, err := filepath.Abs(p)
joined := filepath.Join(initPath, strings.TrimPrefix(p, *extraPath))
fp, err := filepath.Abs(joined)
sl, _ := filepath.EvalSymlinks(fp)
if err != nil || !strings.HasPrefix(fp, initPath) || len(sl) > 0 && !*symlinks && !strings.HasPrefix(sl, initPath) {
if err != nil || !strings.HasPrefix(fp, initPath) || *skipHidden && strings.Contains(p, "/.") || !*symlinks && len(sl) > 0 && !strings.HasPrefix(sl, initPath) {
panic(errors.New("invalid path"))
}
@@ -174,23 +218,29 @@ func checkPath(p string) string {
}
func main() {
var err error
flag.Usage = func() {
fmt.Printf("\nusage: ./gossa ~/directory-to-share\n\n")
flag.PrintDefaults()
}
flag.Parse()
if len(flag.Args()) > 0 {
initPath = flag.Args()[0]
}
var err error
initPath, err = filepath.Abs(initPath)
check(err)
hostString := *host + ":" + *port
fmt.Println("Gossa startig on directory " + initPath)
fmt.Println("Listening on http://" + hostString + *extraPath)
if !*ro {
http.HandleFunc(*extraPath+"rpc", rpc)
http.HandleFunc(*extraPath+"post", upload)
}
http.HandleFunc(*extraPath+"rpc", rpc)
http.HandleFunc(*extraPath+"post", upload)
http.HandleFunc(*extraPath+"zip", zipRPC)
http.HandleFunc("/", doContent)
fs = http.StripPrefix(*extraPath, http.FileServer(http.Dir(initPath)))
err = http.ListenAndServe(hostString, nil)
fmt.Printf("Gossa starting on directory %s\nListening on http://%s:%s%s\n", initPath, *host, *port, *extraPath)
err = http.ListenAndServe(*host+":"+*port, nil)
check(err)
}
+170 -88
View File
@@ -2,13 +2,13 @@ package main
import (
"bytes"
"crypto/sha256"
"fmt"
"io/ioutil"
"net/http"
"regexp"
"strings"
"testing"
"time"
)
func dieMaybe(t *testing.T, err error) {
@@ -22,11 +22,16 @@ func trimSpaces(str string) string {
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)
dieMaybe(t, err)
body, err := ioutil.ReadAll(resp.Body)
dieMaybe(t, err)
return body
}
func get(t *testing.T, url string) string {
body := getRaw(t, url)
return trimSpaces(string(body))
}
@@ -55,39 +60,37 @@ func postJSON(t *testing.T, url string, what string) string {
}
func fetchAndTestDefault(t *testing.T, url string) string {
bodyStr := get(t, url)
body0 := get(t, url)
if !strings.Contains(bodyStr, `<title>/</title>`) {
if !strings.Contains(body0, `<title>/</title>`) {
t.Fatal("error title")
}
if !strings.Contains(bodyStr, `<h1>./</h1>`) {
if !strings.Contains(body0, `<h1 onclick="return titleClick(event)">./</h1>`) {
t.Fatal("error header")
}
if !strings.Contains(bodyStr, `href="hols">hols/</a>`) {
if !strings.Contains(body0, `href="hols">hols/</a>`) {
t.Fatal("error hols folder")
}
if !strings.Contains(bodyStr, `href="curimit@gmail.com%20%2840%25%29">curimit@gmail.com (40%)/</a>`) {
if !strings.Contains(body0, `href="curimit@gmail.com%20%2840%25%29">curimit@gmail.com (40%)/</a>`) {
t.Fatal("error curimit@gmail.com (40%) folder")
}
if !strings.Contains(bodyStr, `href="%E4%B8%AD%E6%96%87">中文/</a>`) {
if !strings.Contains(body0, `href="%E4%B8%AD%E6%96%87">中文/</a>`) {
t.Fatal("error 中文 folder")
}
if !strings.Contains(bodyStr, `href="custom_mime_type.types">custom_mime_type.types</a>`) {
if !strings.Contains(body0, `href="custom_mime_type.types">custom_mime_type.types</a>`) {
t.Fatal("error row custom_mime_type")
}
return bodyStr
return body0
}
func doTest(t *testing.T, url string, symlinkEnabled bool) {
payload := ""
path := ""
bodyStr := ""
func doTestRegular(t *testing.T, url string, testExtra bool) {
var payload, path, body0, body1, body2 string
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test fetching default path")
@@ -100,41 +103,57 @@ func doTest(t *testing.T, url string, symlinkEnabled bool) {
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test fetching regular files")
bodyStr = get(t, url+"subdir_with%20space/file_with%20space.html")
bodyStr2 := get(t, url+"fancy-path/a")
fmt.Println(bodyStr2)
if !strings.Contains(bodyStr, `<b>spacious!!</b>`) || !strings.Contains(bodyStr2, `fancy!`) {
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")
bodyStr = get(t, url+"../../../../../../../../../../etc/passwd")
if !strings.Contains(bodyStr, `error`) {
path = "../../../../../../../../../../etc/passwd"
if !testExtra && get(t, url+path) != `error` {
t.Fatal("fetching a invalid file didnt errored")
} else if testExtra {
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")
bodyStr = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["/AAA"]}`)
if !strings.Contains(bodyStr, `ok`) {
body0 = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["/AAA"]}`)
if body0 != `ok` {
t.Fatal("mkdir rpc errored")
}
bodyStr = fetchAndTestDefault(t, url)
if !strings.Contains(bodyStr, `href="AAA">AAA/</a>`) {
body0 = fetchAndTestDefault(t, url)
if !strings.Contains(body0, `href="AAA">AAA/</a>`) {
t.Fatal("mkdir rpc folder not created")
}
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test invalid mkdir rpc")
bodyStr = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["../BBB"]}`)
if !strings.Contains(bodyStr, `error`) {
body0 = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["../BBB"]}`)
if body0 != `error` {
t.Fatal("invalid mkdir rpc didnt errored #0")
}
bodyStr = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["/../BBB"]}`)
if !strings.Contains(bodyStr, `error`) {
body0 = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["/../BBB"]}`)
if body0 != `error` {
t.Fatal("invalid mkdir rpc didnt errored #1")
}
@@ -142,108 +161,171 @@ func doTest(t *testing.T, url string, symlinkEnabled bool) {
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 하"
bodyStr = postDummyFile(t, url, path, payload)
if !strings.Contains(bodyStr, `ok`) {
body0 = postDummyFile(t, url, path, payload)
body1 = get(t, url+path)
body2 = fetchAndTestDefault(t, url)
if body0 != `ok` || body1 != payload || !strings.Contains(body2, `href="%E1%84%92%E1%85%A1%20%E1%84%92%E1%85%A1">하 하</a>`) {
t.Fatal("post file errored")
}
bodyStr = get(t, url+path)
if !strings.Contains(bodyStr, payload) {
t.Fatal("post file errored reaching new file")
}
bodyStr = fetchAndTestDefault(t, url)
if !strings.Contains(bodyStr, `href="%E1%84%92%E1%85%A1%20%E1%84%92%E1%85%A1">하 하</a>`) {
t.Fatal("post file errored checking new file row")
}
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test post file incorrect path")
bodyStr = postDummyFile(t, url, "%2E%2E"+path, payload)
if !strings.Contains(bodyStr, `err`) {
body0 = postDummyFile(t, url, "%2E%2E"+path, payload)
if !strings.Contains(body0, `err`) {
t.Fatal("post file incorrect path didnt errored")
}
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test mv rpc")
bodyStr = postJSON(t, url+"rpc", `{"call":"mv","args":["/AAA", "/hols/AAA"]}`)
if !strings.Contains(bodyStr, `ok`) {
body0 = postJSON(t, url+"rpc", `{"call":"mv","args":["/AAA", "/hols/AAA"]}`)
body1 = fetchAndTestDefault(t, url)
if body0 != `ok` || strings.Contains(body1, `href="AAA">AAA/</a></td> </tr>`) {
t.Fatal("mv rpc errored")
}
bodyStr = fetchAndTestDefault(t, url)
if strings.Contains(bodyStr, `href="AAA">AAA/</a></td> </tr>`) {
t.Fatal("mv rpc folder not moved")
}
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test upload in new folder")
payload = "abcdef1234"
bodyStr = postDummyFile(t, url, "%2Fhols%2FAAA%2Fabcdef", payload)
if strings.Contains(bodyStr, `err`) {
payload = "test"
body0 = postDummyFile(t, url, "%2Fhols%2FAAA%2Fabcdef", payload)
body1 = get(t, url+"hols/AAA/abcdef")
if body0 != `ok` || body1 != payload {
t.Fatal("upload in new folder errored")
}
bodyStr = get(t, url+"hols/AAA/abcdef")
if !strings.Contains(bodyStr, payload) {
t.Fatal("upload in new folder error reaching new file")
}
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test symlink, should succeed: ", symlinkEnabled)
bodyStr = get(t, url+"/docker/readme.md")
hasReadme := strings.Contains(bodyStr, `the master branch is automatically built and pushed`)
if !symlinkEnabled && hasReadme {
fmt.Println("\r\n~~~~~~~~~~ test symlink, should succeed: ", testExtra)
body0 = get(t, url+"/support/readme.md")
hasReadme := strings.Contains(body0, `the master branch is automatically built and pushed`)
if !testExtra && hasReadme {
t.Fatal("error symlink reached where illegal")
} else if symlinkEnabled && !hasReadme {
} else if testExtra && !hasReadme {
t.Fatal("error symlink unreachable")
}
if symlinkEnabled {
fmt.Println("\r\n~~~~~~~~~~ test symlink mkdir")
bodyStr = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["/docker/testfolder"]}`)
if !strings.Contains(bodyStr, `ok`) {
if testExtra {
fmt.Println("\r\n~~~~~~~~~~ test symlink mkdir & cleanup")
body0 = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["/support/testfolder"]}`)
if body0 != `ok` {
t.Fatal("error symlink mkdir")
}
body0 = postJSON(t, url+"rpc", `{"call":"rm","args":["/support/testfolder"]}`)
if body0 != `ok` {
t.Fatal("error symlink rm")
}
}
fmt.Println("\r\n~~~~~~~~~~ test hidden file, should succeed: ", testExtra)
body0 = get(t, url+"/.testhidden")
hasHidden := strings.Contains(body0, `test`)
if !testExtra && hasHidden {
t.Fatal("error hidden file reached where illegal")
} else if testExtra && !hasHidden {
t.Fatal("error hidden file unreachable")
}
//
fmt.Println("\r\n~~~~~~~~~~ test upload in new folder")
payload = "test"
body0 = postDummyFile(t, url, "%2Fhols%2FAAA%2Fabcdef", payload)
body1 = get(t, url+"hols/AAA/abcdef")
if body0 != `ok` || body1 != payload {
t.Fatal("upload in new folder errored")
}
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test rm rpc & cleanup")
bodyStr = postJSON(t, url+"rpc", `{"call":"rm","args":["/hols/AAA"]}`)
if !strings.Contains(bodyStr, `ok`) {
body0 = postJSON(t, url+"rpc", `{"call":"rm","args":["/hols/AAA"]}`)
if body0 != `ok` {
t.Fatal("cleanup errored #0")
}
bodyStr = get(t, url+"hols/AAA")
if !strings.Contains(bodyStr, `error`) {
body0 = get(t, url+"hols/AAA")
if !strings.Contains(body0, `error`) {
t.Fatal("cleanup errored #1")
}
bodyStr = postJSON(t, url+"rpc", `{"call":"rm","args":["/하 하"]}`)
if !strings.Contains(bodyStr, `ok`) {
body0 = postJSON(t, url+"rpc", `{"call":"rm","args":["/하 하"]}`)
if body0 != `ok` {
t.Fatal("cleanup errored #2")
}
if symlinkEnabled {
bodyStr = postJSON(t, url+"rpc", `{"call":"rm","args":["/docker/testfolder"]}`)
if !strings.Contains(bodyStr, `ok`) {
t.Fatal("error symlink rm")
}
fmt.Printf("\r\n=========\r\n")
}
func doTestReadonly(t *testing.T, url string) {
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 TestGetFolder(t *testing.T) {
time.Sleep(6 * time.Second)
func TestNormal(t *testing.T) {
fmt.Println("========== testing normal path ============")
url := "http://127.0.0.1:8001/"
doTest(t, url, false)
doTestRegular(t, "http://127.0.0.1:8001/", false)
}
fmt.Printf("\r\n=========\r\n")
time.Sleep(10 * time.Second)
func TestExtra(t *testing.T) {
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/"
fmt.Println("========== testing at fancy path ============")
doTest(t, url, true)
fmt.Printf("\r\n=========\r\n")
func TestRo(t *testing.T) {
fmt.Println("========== testing read only ============")
doTestReadonly(t, "http://127.0.0.1:8001/")
}
@@ -3,9 +3,9 @@ COPY . /gossaSrc
RUN cd /gossaSrc && make
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
RUN apk add --no-cache su-exec
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" ]
+110
View File
@@ -0,0 +1,110 @@
## docker
the master branch is automatically built and pushed to [dockerhub](https://hub.docker.com/r/pldubouilh/gossa) under `pldubouilh/gossa`.
```sh
# pull from dockerhub and run
% mkdir ~/LocalDirToShare
% 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 :
```sh
# 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 .
% 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.
## 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
myserver.com
# proxy regular and read only instance
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
```
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
```
+1
View File
@@ -0,0 +1 @@
test
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File