Compare commits

..
18 Commits
Author SHA1 Message Date
Pierre Dubouilh a1613a08e8 bump go to 1.18 (#79) 2022-04-01 14:14:25 +02:00
Pierre DubouilhandDennis 99ac521aa8 fixup paths in service file (#78)
systemd needs paths absolutely

Co-authored-by: Dennis <me@dennis.is>
2022-04-01 14:01:58 +02:00
Tim Eichholz f1dc8280f5 Dockerfile updates (#77)
* Added VERB environment variable for enabling verbosity in the Docker container
* pin the versions for golang and alpine at their current latest
* move the entrypoint script to a separate file, removed EXPOSE command from Dockerfile
2022-04-01 13:51:26 +02:00
Pierre Dubouilh cd255a21f6 fix docker release tag 2021-12-22 14:46:05 +01:00
Pierre Dubouilh bf4be929f5 rephrase service file
and move RPC structure back to gossa.go
2021-12-22 14:29:46 +01:00
Pierre DubouilhandVictor d99d975f70 multiplatform docker
cross platform build for docker images

Co-authored-by:     Victor <ViRb3@users.noreply.github.com>
2021-12-22 14:29:46 +01:00
Pierre Dubouilh 177edf4791 reproducible build 2021-12-22 14:29:46 +01:00
Pierre Dubouilh 16b31a5047 split embedder 2021-12-22 14:29:46 +01:00
Pierre Dubouilh 65a6087c60 add coverage test 2021-12-22 14:29:46 +01:00
Pierre Dubouilh 5b55ab0a0a refactor 2021-12-22 14:29:46 +01:00
Pierre Dubouilh cb4631c086 autodeploy dockerhub 2021-12-22 14:29:46 +01:00
Pierre Dubouilh de632f9ab7 add service example 2021-12-22 14:29:46 +01:00
Pierre DubouilhandVictor 4385249c94 better zip #2
stream content to clients

Co-authored-by:     Victor <ViRb3@users.noreply.github.com>
2021-12-22 14:29:46 +01:00
Pierre Dubouilh 5440b4c5a2 more test-fixture 2021-12-22 14:29:46 +01:00
Pierre Dubouilh 2f73fd9df8 better zip 2021-12-22 14:29:46 +01:00
Pierre Dubouilh 688be87923 better error handling 2021-12-22 14:29:46 +01:00
Pierre Dubouilh 166869fc04 support arm based macs 2021-12-22 14:29:46 +01:00
Pierre DubouilhandVictor a2754c616d use go static assets embedder
shift to use new static go assets embedded

Co-authored-by:     Victor <ViRb3@users.noreply.github.com>
2021-12-22 14:29:46 +01:00
17 changed files with 341 additions and 164 deletions
@@ -1,16 +1,15 @@
name: ci
on: [push, pull_request]
on: [push]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.13
- name: Set up Go 1.18
uses: actions/setup-go@v1
with:
go-version: 1.13
go-version: 1.18
id: go
- name: Check out code into the Go module directory
@@ -19,4 +18,5 @@ jobs:
submodules: true
- name: Run
run: make test
run: make ci
+39
View File
@@ -0,0 +1,39 @@
name: deploy
on:
push:
tags:
- '*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
with:
submodules: true
- name: Set env
run: echo "GIT_TAG=`echo $(git describe --tags --abbrev=0)`" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v1.2.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1.6.0
- name: Login to DockerHub
uses: docker/login-action@v1.10.0
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v2.7.0
with:
file: support/build.Dockerfile
push: true
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
tags: pldubouilh/gossa:latest,pldubouilh/gossa:${{github.ref_name}}
+7 -2
View File
@@ -4,9 +4,10 @@ gossa-linux-arm
gossa-linux-arm64
gossa-mac
gossa-windows.exe
gossa_test.go
build-all
builds
gossa.test
*.out
.vscode
test-fixture/*
test-fixture/*/*
@@ -41,3 +42,7 @@ test-fixture/*/*
!test-fixture/fancy-path/*
!test-fixture/ext/*
!test-fixture/ext
!test-fixture/.some-hidden-file
!test-fixture/hols/.hidden-folder
!test-fixture/hols/.hidden-folder/some-file
!test-fixture/compress/hols-sym
+29 -29
View File
@@ -1,12 +1,9 @@
FLAGS := -ldflags "-s -w"
FLAGS := -ldflags "-s -w" -trimpath
NOCGO := CGO_ENABLED=0
build:
cp src/gossa.go gossa.go
make -C gossa-ui/
go vet && go fmt
${NOCGO} go build ${FLAGS} -o gossa
rm gossa.go
install:
sudo cp gossa /usr/local/bin
@@ -20,51 +17,54 @@ run-ro:
run-extra:
./gossa -verb=true -prefix="/fancy-path/" -k=false -symlinks=true test-fixture
ci: build-all test
echo "done"
test:
make build
rm -rf gossa_test.go
-@cd test-fixture && ln -s ../support .; true
cp src/gossa_test.go .
go test -cover -c -tags testrunmain
-@killall gossa; true
-make run &
timeout -s SIGINT 3 ./gossa.test -test.coverprofile=normal.out -test.run '^TestRunMain' -verb=true test-fixture &
sleep 2
go test -run TestNormal
sleep 1
killall gossa
-make run-extra &
timeout -s SIGINT 3 ./gossa.test -test.coverprofile=extra.out -test.run '^TestRunMain' -prefix='/fancy-path/' -k=false -symlinks=true test-fixture &
sleep 2
go test -run TestExtra
sleep 1
killall gossa
-make run-ro &
timeout -s SIGINT 3 ./gossa.test -test.coverprofile=ro.out -test.run '^TestRunMain' -ro=true test-fixture &
sleep 2
go test -run TestRo
sleep 1
killall gossa
# gocovmerge ro.out extra.out normal.out > all.out
# go tool cover -html all.out
# go tool cover -func=all.out | grep main | grep '9.\..\%'
watch:
ls src/* gossa-ui/* | entr -rc make build run
ls gossa.go gossa_test.go gossa-ui/* | entr -rc make build run
watch-extra:
ls src/* gossa-ui/* | entr -rc make build run-extra
ls gossa.go gossa_test.go gossa-ui/* | entr -rc make build run-extra
watch-ro:
ls src/* gossa-ui/* | entr -rc make build run-ro
ls gossa.go gossa_test.go gossa-ui/* | entr -rc make build run-ro
watch-test:
ls src/* gossa-ui/* | entr -rc make test
ls gossa.go gossa_test.go gossa-ui/* | entr -rc make test
build-all:
cp src/gossa.go gossa.go
make -C gossa-ui/
${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
build-all: build
${NOCGO} GOOS=linux GOARCH=amd64 go build ${FLAGS} -o builds/gossa-linux-x64
${NOCGO} GOOS=linux GOARCH=arm go build ${FLAGS} -o builds/gossa-linux-arm
${NOCGO} GOOS=linux GOARCH=arm64 go build ${FLAGS} -o builds/gossa-linux-arm64
${NOCGO} GOOS=darwin GOARCH=amd64 go build ${FLAGS} -o builds/gossa-mac-x64
${NOCGO} GOOS=darwin GOARCH=arm64 go build ${FLAGS} -o builds/gossa-mac-arm64
${NOCGO} GOOS=windows GOARCH=amd64 go build ${FLAGS} -o builds/gossa-windows.exe
sha256sum builds/*
clean:
-rm gossa.go
-rm gossa_test.go
-rm gossa
-rm gossa-linux64
-rm gossa-linux-arm
+107 -82
View File
@@ -3,6 +3,7 @@ package main
import (
"archive/zip"
"compress/gzip"
_ "embed"
"encoding/json"
"errors"
"flag"
@@ -10,6 +11,7 @@ import (
"html"
"html/template"
"io"
"io/fs"
"io/ioutil"
"log"
"net/http"
@@ -21,38 +23,14 @@ import (
"strings"
)
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", 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
var page, _ = template.New("pageTemplate").Parse(`template_will_be_here`)
type rowTemplate struct {
Name string
Href template.HTML
Size string
Ext string
}
type pageTemplate struct {
Title template.HTML
ExtraPath template.HTML
Ro bool
RowsFiles []rowTemplate
RowsFolders []rowTemplate
}
type rpcCall struct {
Call string `json:"call"`
Args []string `json:"args"`
}
var rootPath = ""
var handler http.Handler
func check(e error) {
if e != nil {
panic(e)
@@ -101,9 +79,18 @@ func replyList(w http.ResponseWriter, r *http.Request, fullPath string, path str
for _, el := range _files {
if *skipHidden && strings.HasPrefix(el.Name(), ".") {
continue // dont print hidden files if we're not allowed
}
if !*symlinks && el.Mode()&os.ModeSymlink != 0 {
continue // dont print symlinks if were not allowed
}
el, err := os.Stat(fullPath + "/" + el.Name())
if err != nil {
log.Println("error - cant stat a file", err)
continue
}
el, _ = os.Stat(fullPath + "/" + el.Name())
href := url.PathEscape(el.Name())
if el.IsDir() && strings.HasPrefix(href, "/") {
href = strings.Replace(href, "/", "", 1)
@@ -120,97 +107,125 @@ func replyList(w http.ResponseWriter, r *http.Request, fullPath string, path str
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)
gz, err := gzip.NewWriterLevel(w, gzip.BestSpeed) // BestSpeed is Much Faster than default - base on a very unscientific local test, and only ~30% larger (compression remains still very effective, ~6x)
check(err)
defer gz.Close()
page.Execute(gz, p)
templateParsed.Execute(gz, p)
} else {
page.Execute(w, p)
templateParsed.Execute(w, p)
}
}
func doContent(w http.ResponseWriter, r *http.Request) {
if !strings.HasPrefix(r.URL.Path, *extraPath) {
http.Redirect(w, r, *extraPath, 302)
if !strings.HasPrefix(r.URL.Path, *extraPath) { // redir when were not hitting the supplementary path if one is set
http.Redirect(w, r, *extraPath, http.StatusFound)
return
}
path := html.UnescapeString(r.URL.Path)
defer exitPath(w, "get content", path)
fullPath := checkPath(path)
fullPath := enforcePath(path)
stat, errStat := os.Stat(fullPath)
check(errStat)
if stat.IsDir() {
replyList(w, r, fullPath, path)
} else {
fs.ServeHTTP(w, r)
handler.ServeHTTP(w, r)
}
}
func upload(w http.ResponseWriter, r *http.Request) {
path, _ := url.PathUnescape(r.Header.Get("gossa-path"))
path := r.Header.Get("gossa-path")
defer exitPath(w, "upload", path)
reader, _ := r.MultipartReader()
part, _ := reader.NextPart()
dst, _ := os.Create(checkPath(path))
path, err := url.PathUnescape(path)
check(err)
reader, err := r.MultipartReader()
check(err)
part, err := reader.NextPart()
if err != nil && err != io.EOF { // errs EOF when no more parts to process
check(err)
}
dst, err := os.Create(enforcePath(path))
check(err)
io.Copy(dst, part)
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)
zipFullPath := enforcePath(zipPath)
_, err := os.Lstat(zipFullPath)
check(err)
w.Header().Add("Content-Disposition", "attachment; filename=\""+zipName+".zip\"")
walkZip(wz, checkPath(zipPath)+"/", "")
wz.Close()
zipWriter := zip.NewWriter(w)
defer zipWriter.Close()
err = filepath.Walk(zipFullPath, func(path string, f fs.FileInfo, err error) error {
check(err)
if f.IsDir() {
return nil
}
rel, err := filepath.Rel(zipFullPath, path)
check(err)
if *skipHidden && (strings.HasPrefix(rel, ".") || strings.HasPrefix(f.Name(), ".")) {
return nil // hidden files not allowed
}
if f.Mode()&os.ModeSymlink != 0 {
panic(errors.New("symlink not allowed in zip downloads")) // filepath.Walk doesnt support symlinks
}
header, err := zip.FileInfoHeader(f)
check(err)
header.Name = filepath.ToSlash(rel) // make the paths consistent between OSes
header.Method = zip.Store
headerWriter, err := zipWriter.CreateHeader(header)
check(err)
file, err := os.Open(path)
check(err)
defer file.Close()
_, err = io.Copy(headerWriter, file)
check(err)
return nil
})
check(err)
}
func rpc(w http.ResponseWriter, r *http.Request) {
var err error
var rpc rpcCall
defer exitPath(w, "rpc", rpc)
bodyBytes, _ := ioutil.ReadAll(r.Body)
bodyBytes, err := ioutil.ReadAll(r.Body)
check(err)
json.Unmarshal(bodyBytes, &rpc)
if rpc.Call == "mkdirp" {
err = os.MkdirAll(checkPath(rpc.Args[0]), os.ModePerm)
err = os.MkdirAll(enforcePath(rpc.Args[0]), os.ModePerm)
} else if rpc.Call == "mv" {
err = os.Rename(checkPath(rpc.Args[0]), checkPath(rpc.Args[1]))
err = os.Rename(enforcePath(rpc.Args[0]), enforcePath(rpc.Args[1]))
} else if rpc.Call == "rm" {
err = os.RemoveAll(checkPath(rpc.Args[0]))
err = os.RemoveAll(enforcePath(rpc.Args[0]))
}
check(err)
w.Write([]byte("ok"))
}
func checkPath(p string) string {
joined := filepath.Join(initPath, strings.TrimPrefix(p, *extraPath))
func enforcePath(p string) string {
joined := filepath.Join(rootPath, strings.TrimPrefix(p, *extraPath))
fp, err := filepath.Abs(joined)
sl, _ := filepath.EvalSymlinks(fp)
sl, _ := filepath.EvalSymlinks(fp) // err skipped as it would error for unexistent files (RPC check). The actual behaviour is tested below
if err != nil || !strings.HasPrefix(fp, initPath) || *skipHidden && strings.Contains(p, "/.") || !*symlinks && len(sl) > 0 && !strings.HasPrefix(sl, initPath) {
// panic if we had a error getting absolute path,
// ... or if path doesnt contain the prefix path we expect,
// ... or if we're skipping hidden folders, and one is requested,
// ... or if we're skipping symlinks, path exists, and a symlink out of bound requested
if err != nil || !strings.HasPrefix(fp, rootPath) || *skipHidden && strings.Contains(p, "/.") || !*symlinks && len(sl) > 0 && !strings.HasPrefix(sl, rootPath) {
panic(errors.New("invalid path"))
}
@@ -218,29 +233,39 @@ func checkPath(p string) string {
}
func main() {
var err error
flag.Usage = func() {
if flag.Parse(); len(flag.Args()) > 0 {
rootPath = flag.Args()[0]
} else {
fmt.Printf("\nusage: ./gossa ~/directory-to-share\n\n")
flag.PrintDefaults()
os.Exit(1)
}
flag.Parse()
if len(flag.Args()) > 0 {
initPath = flag.Args()[0]
}
initPath, err = filepath.Abs(initPath)
var err error
rootPath, err = filepath.Abs(rootPath)
check(err)
server := &http.Server{Addr: *host + ":" + *port, Handler: handler}
// clean shutdown - used only for coverage test
// go func() {
// sigchan := make(chan os.Signal, 1)
// signal.Notify(sigchan, os.Interrupt)
// <-sigchan
// ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
// defer cancel()
// server.Shutdown(ctx)
// }()
if !*ro {
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)))
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)
handler = http.StripPrefix(*extraPath, http.FileServer(http.Dir(rootPath)))
fmt.Printf("Gossa starting on directory %s\nListening on http://%s:%s%s\n", rootPath, *host, *port, *extraPath)
if err = server.ListenAndServe(); err != http.ErrServerClosed {
check(err)
}
}
Executable
+50
View File
@@ -0,0 +1,50 @@
package main
import (
_ "embed"
"encoding/base64"
"flag"
"html/template"
"strings"
)
//go:embed gossa-ui/script.js
var scriptJs string
//go:embed gossa-ui/style.css
var styleCss string
//go:embed gossa-ui/favicon.svg
var faviconSvg []byte
//go:embed gossa-ui/ui.tmpl
var templateStr string
// fill in template
var templateCss = strings.Replace(templateStr, "css_will_be_here", styleCss, 1)
var templateCssJs = strings.Replace(templateCss, "js_will_be_here", scriptJs, 1)
var templateCssJssIcon = strings.Replace(templateCssJs, "favicon_will_be_here", base64.StdEncoding.EncodeToString(faviconSvg), 2)
var templateParsed, _ = template.New("").Parse(templateCssJssIcon)
type rowTemplate struct {
Name string
Href template.HTML
Size string
Ext string
}
type pageTemplate struct {
Title template.HTML
ExtraPath template.HTML
Ro bool
RowsFiles []rowTemplate
RowsFolders []rowTemplate
}
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", 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...)")
+53 -12
View File
@@ -1,8 +1,8 @@
package main
import (
"archive/zip"
"bytes"
"crypto/sha256"
"fmt"
"io/ioutil"
"net/http"
@@ -30,6 +30,19 @@ func getRaw(t *testing.T, url string) []byte {
return body
}
func getZip(t *testing.T, needle string, dest string) (int, bool) {
b := getRaw(t, dest)
unzipped, err := zip.NewReader(bytes.NewReader(b), int64(len(b)))
dieMaybe(t, err)
length := len(unzipped.File)
for _, file := range unzipped.File {
if file.Name == needle {
return length, true
}
}
return length, false
}
func get(t *testing.T, url string) string {
body := getRaw(t, url)
return trimSpaces(string(body))
@@ -96,6 +109,13 @@ func doTestRegular(t *testing.T, url string, testExtra bool) {
fmt.Println("\r\n~~~~~~~~~~ test fetching default path")
fetchAndTestDefault(t, url)
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test fetching another page")
body0 = get(t, url+"/hols")
if !strings.Contains(body0, "glasgow.jpg") {
t.Fatal("fetching a subfolder failed")
}
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test fetching an invalid path - redirected to root")
fetchAndTestDefault(t, url+"../../")
@@ -119,16 +139,25 @@ func doTestRegular(t *testing.T, url string, testExtra bool) {
}
// ~~~~~~~~~~~~~~~~~
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 zipping of folder 中文")
len, foundFile := getZip(t, "檔案.html", url+"zip?zipPath=%2F%E4%B8%AD%E6%96%87%2F&zipName=%E4%B8%AD%E6%96%87")
if len != 1 || !foundFile {
t.Fatal("invalid zip generated")
}
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test zipping of folder with hidden file")
_, foundHidden := getZip(t, ".hidden-folder/some-file", url+"zip?zipPath=%2fhols%2f&zipName=hols")
if foundHidden && !testExtra {
t.Fatal("invalid zip generated - shouldnt contain hidden folder")
} else if !foundHidden && testExtra {
t.Fatal("invalid zip generated - should contain hidden folder")
}
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test zip invalid path")
body0 = get(t, url+"zip?zipPath=%2Ftmp&zipName=subdir")
println(body0)
if body0 != `error` {
t.Fatal("zip passed for invalid path")
}
@@ -194,12 +223,20 @@ func doTestRegular(t *testing.T, url string, testExtra bool) {
// ~~~~~~~~~~~~~~~~~
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`)
body0 = get(t, url+"/support/")
hasListing := strings.Contains(body0, `readme.md`)
body1 = get(t, url+"/support/readme.md")
hasReadme := strings.Contains(body1, `the master branch is automatically built and pushed`)
if !testExtra && hasReadme {
t.Fatal("error symlink reached where illegal")
t.Fatal("error symlink file reached where illegal")
} else if testExtra && !hasReadme {
t.Fatal("error symlink unreachable")
t.Fatal("error symlink file unreachable")
}
if !testExtra && hasListing {
t.Fatal("error symlink folder reached where illegal")
} else if testExtra && !hasListing {
t.Fatal("error symlink folder unreachable")
}
if testExtra {
@@ -292,7 +329,7 @@ func doTestReadonly(t *testing.T, url string) {
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)
get(t, url+path)
if body0 == `ok` {
t.Fatal("post file passed - should not be allowed")
}
@@ -300,7 +337,7 @@ func doTestReadonly(t *testing.T, url string) {
// ~~~~~~~~~~~~~~~~~
fmt.Println("\r\n~~~~~~~~~~ test mv rpc")
body0 = postJSON(t, url+"rpc", `{"call":"mv","args":["/AAA", "/hols/AAA"]}`)
body1 = fetchAndTestDefault(t, url)
fetchAndTestDefault(t, url)
if body0 == `ok` {
t.Fatal("mv rpc passed - should not be allowed")
}
@@ -329,3 +366,7 @@ func TestRo(t *testing.T) {
fmt.Println("========== testing read only ============")
doTestReadonly(t, "http://127.0.0.1:8001/")
}
func TestRunMain(t *testing.T) {
main()
}
+10 -8
View File
@@ -4,7 +4,6 @@ gossa
![e](https://user-images.githubusercontent.com/760637/71449335-790a4200-274a-11ea-80be-4c536fbad8a1.gif)
[![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)
@@ -14,21 +13,24 @@ a [simple UI](https://github.com/pldubouilh/gossa-ui) comes as default, featurin
* 🔍 files/directories browser & handler
* 📩 drag-and-drop uploader
* 🚀 lightweight and dependency free
* 💾 90s web UI that prints in ms
* 📸 picture browser
* 📽️ video streaming
* ✍️ simple text editor
* ⌨️ keyboard navigation
* 🥂 fast golang static server
* 🔒 easy/secure multi account setup, read-only mode
* 💾 90s web UI that prints in milliseconds
* 📸 video streaming & picture browser
* ✍️ simple note editor
* ⌨️ keyboard navigation
* 🚀 lightweight and dependency free codebase
* 🔒 >95% test coverage and reproducible builds
* 💑 easy 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.
all builds are reproducible, checkout the hashes on the release page.
arch linux users can also install through the [user repos](https://aur.archlinux.org/packages/gossa/) - e.g. `yay -S gossa`
automatic boot-time startup can be handled with a user systemd service - see [support](https://github.com/pldubouilh/gossa/tree/master/support)
### usage
```sh
% ./gossa --help
-18
View File
@@ -1,18 +0,0 @@
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
+5 -6
View File
@@ -1,11 +1,10 @@
FROM golang:latest as builder
FROM golang:1.18 as builder
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" READONLY="false"
EXPOSE 8001
FROM alpine:3.15
ENV UID="1000" GID="1000" HOST="0.0.0.0" PORT="8001" PREFIX="/" FOLLOW_SYMLINKS="false" SKIP_HIDDEN_FILES="true" DATADIR="/shared" READONLY="false" VERB="false"
RUN apk add --no-cache su-exec
COPY ./support/entrypoint.sh /entrypoint.sh
COPY --from=builder /gossaSrc/gossa /gossa
RUN echo -e 'exec su-exec ${UID}:${GID} /gossa -h ${HOST} -p ${PORT} -k=${SKIP_HIDDEN_FILES} -ro=${READONLY} --symlinks=${FOLLOW_SYMLINKS} --prefix=${PREFIX} ${DATADIR}'>> /start.sh
ENTRYPOINT [ "sh", "/start.sh" ]
ENTRYPOINT "/entrypoint.sh"
+2
View File
@@ -0,0 +1,2 @@
#!/bin/sh
exec su-exec ${UID}:${GID} /gossa -h ${HOST} -p ${PORT} -k=${SKIP_HIDDEN_FILES} -ro=${READONLY} --symlinks=${FOLLOW_SYMLINKS} --prefix=${PREFIX} --verb=${VERB} ${DATADIR}
+17 -1
View File
@@ -1,4 +1,20 @@
## docker
## run as a service
use the `service` file provided here to use as a systemd service.
```sh
# edit service file
# copy over our service, and start. Notice no sudo with systemctl command !
% mkdir -p ~/.config/systemd/user/
% cp service ~/.config/systemd/user/gossa.service
% systemctl --user start gossa
# enable at boot time
% systemctl --user enable gossa
```
## run with docker
the master branch is automatically built and pushed to [dockerhub](https://hub.docker.com/r/pldubouilh/gossa) under `pldubouilh/gossa`.
+13
View File
@@ -0,0 +1,13 @@
[Unit]
Description=Gossa service for mytestfolder
Wants=network-online.target
After=network-online.target
# note: absolute paths are necessary here
[Service]
ExecStart=/usr/bin/gossa /home/joe/mytestfolder
Restart=always
RestartSec=30
[Install]
WantedBy=multi-user.target
+1
View File
@@ -0,0 +1 @@
hidden !
+1
View File
@@ -0,0 +1 @@
../hols
@@ -0,0 +1 @@
I'm hidden by my directory!