Compare commits

...
16 Commits
Author SHA1 Message Date
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
9 changed files with 187 additions and 76 deletions
+19 -12
View File
@@ -2,9 +2,12 @@ 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 CGO_ENABLED=0 go build
rm gossa.go rm gossa.go
install:
sudo cp gossa /usr/local/bin
run: run:
./gossa -verb=true test-fixture ./gossa -verb=true test-fixture
@@ -19,7 +22,16 @@ test:
-rm gossa_test.go -rm gossa_test.go
-@cd test-fixture && ln -s ../support . -@cd test-fixture && ln -s ../support .
cp src/gossa_test.go . cp src/gossa_test.go .
go test -@killall gossa
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 build run ls src/* gossa-ui/* | entr -rc make build run
@@ -36,16 +48,11 @@ watch-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 env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o gossa-linux64
mv gossa gossa-linux64 env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -o gossa-linux-arm
env GOOS=linux GOARCH=arm go build gossa.go env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o gossa-linux-arm64
mv gossa gossa-linux-arm env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o gossa-mac
env GOOS=linux GOARCH=arm64 go build gossa.go env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o 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:
+14 -11
View File
@@ -8,24 +8,26 @@ gossa
[![docker pulls](https://img.shields.io/docker/pulls/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) [![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 : 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
* 🚀 lightweight, default ui weights 110kB and prints in ms * 🚀 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 shortcuts * ⌨️ keyboard navigation
* 🥂 fast golang static server, easily fills available bandwidth * 🥂 fast golang static server
* 🔒 easy/secure multi account setup * 🔒 easy/secure multi account setup, read-only mode
### 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
@@ -33,6 +35,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. :
@@ -41,8 +46,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.
+34 -2
View File
@@ -1,6 +1,7 @@
package main package main
import ( import (
"archive/zip"
"encoding/json" "encoding/json"
"errors" "errors"
"flag" "flag"
@@ -147,12 +148,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)
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)
@@ -197,9 +227,11 @@ func main() {
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 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)
} }
+27 -25
View File
@@ -2,15 +2,13 @@ package main
import ( import (
"bytes" "bytes"
"crypto/sha256"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os"
"os/exec"
"regexp" "regexp"
"strings" "strings"
"testing" "testing"
"time"
) )
func dieMaybe(t *testing.T, err error) { func dieMaybe(t *testing.T, err error) {
@@ -24,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))
} }
@@ -115,6 +118,21 @@ 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"]}`)
@@ -297,33 +315,17 @@ func doTestReadonly(t *testing.T, url string) {
fmt.Printf("\r\n=========\r\n") fmt.Printf("\r\n=========\r\n")
} }
func startGossa(what string) int { func TestNormal(t *testing.T) {
cmd := exec.Command("/usr/bin/make", what)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stdout
cmd.Start()
time.Sleep(3 * time.Second)
return cmd.Process.Pid
}
func killallgossa() {
cmd := exec.Command("/usr/bin/killall", "gossa")
cmd.Start()
}
func TestGossa(t *testing.T) {
startGossa("run")
fmt.Println("========== testing normal path ============") fmt.Println("========== testing normal path ============")
doTestRegular(t, "http://127.0.0.1:8001/", false) doTestRegular(t, "http://127.0.0.1:8001/", false)
killallgossa() }
startGossa("run-extra") func TestExtra(t *testing.T) {
fmt.Println("========== testing extras options ============") fmt.Println("========== testing extras options ============")
doTestRegular(t, "http://127.0.0.1:8001/fancy-path/", true) doTestRegular(t, "http://127.0.0.1:8001/fancy-path/", true)
killallgossa() }
startGossa("run-ro") func TestRo(t *testing.T) {
fmt.Println("========== testing read only ============") fmt.Println("========== testing read only ============")
doTestReadonly(t, "http://127.0.0.1:8001/") doTestReadonly(t, "http://127.0.0.1:8001/")
killallgossa()
} }
-8
View File
@@ -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
+2 -2
View File
@@ -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" ]
-8
View File
@@ -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
View File
@@ -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
```