mirror of
https://github.com/pldubouilh/gossa.git
synced 2026-08-31 06:16:54 -04:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df85a1c5a2 | ||
|
|
e2aa4f149e | ||
|
|
8a7a542b22 | ||
|
|
e490853baa | ||
|
|
557b3fd50d | ||
|
|
1992815b41 | ||
|
|
97e24cc513 | ||
|
|
c1eeb9820a | ||
|
|
dd6cb90e9d | ||
|
|
682e76da1f |
@@ -5,6 +5,7 @@ gossa-linux-arm64
|
|||||||
gossa-mac
|
gossa-mac
|
||||||
gossa-windows.exe
|
gossa-windows.exe
|
||||||
gossa_test.go
|
gossa_test.go
|
||||||
|
build-all
|
||||||
|
|
||||||
.vscode
|
.vscode
|
||||||
test-fixture/*
|
test-fixture/*
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
|
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:
|
install:
|
||||||
@@ -19,10 +22,23 @@ run-extra:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
make build
|
make build
|
||||||
-rm gossa_test.go
|
rm -rf gossa_test.go
|
||||||
-@cd test-fixture && ln -s ../support .
|
-@cd test-fixture && ln -s ../support .; true
|
||||||
cp src/gossa_test.go .
|
cp src/gossa_test.go .
|
||||||
go test
|
|
||||||
|
-@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 build run
|
ls src/* gossa-ui/* | entr -rc make build run
|
||||||
@@ -39,16 +55,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
|
${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:
|
||||||
@@ -60,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: 1d42db2870...a057f08e1d
@@ -8,24 +8,27 @@ 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
|
||||||
* 🚀 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
|
||||||
|
* ✨ 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
|
||||||
@@ -33,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. :
|
||||||
|
|
||||||
@@ -43,6 +49,4 @@ release images are pushed to [dockerhub](https://hub.docker.com/r/pldubouilh/gos
|
|||||||
|
|
||||||
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. [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
|
||||||
+46
-5
@@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"archive/zip"
|
||||||
|
"compress/gzip"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
@@ -79,7 +81,7 @@ 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()) })
|
sort.Slice(_files, func(i, j int) bool { return strings.ToLower(_files[i].Name()) < strings.ToLower(_files[j].Name()) })
|
||||||
@@ -115,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) {
|
func doContent(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -131,7 +141,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)
|
||||||
}
|
}
|
||||||
@@ -147,12 +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)
|
|
||||||
|
|
||||||
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 +236,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
@@ -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()
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user