Merge branch 'master' of ssh://github.com/mickael-kerjean/filestash

This commit is contained in:
MickaelK 2025-06-19 13:13:42 +10:00
commit 88e4816a46
20 changed files with 51 additions and 52 deletions

View file

@ -17,7 +17,7 @@ import (
"fmt"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
"io/ioutil"
"io"
"os"
)
@ -44,7 +44,7 @@ func LoadConfig() ([]byte, error) {
}
return nil, err
}
cFile, err := ioutil.ReadAll(file)
cFile, err := io.ReadAll(file)
file.Close()
if err != nil {
return nil, err

View file

@ -11,7 +11,6 @@ import (
"encoding/hex"
"hash/fnv"
"io"
"io/ioutil"
"math/big"
mathrand "math/rand"
"os"
@ -179,7 +178,7 @@ func decompress(something []byte) ([]byte, error) {
return []byte(""), nil
}
r.Close()
return ioutil.ReadAll(r)
return io.ReadAll(r)
}
func sign(something []byte) ([]byte, error) {

View file

@ -5,7 +5,7 @@ import (
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"io/ioutil"
"io"
"os"
)
@ -45,7 +45,7 @@ func pullCertificateFromFS() (*x509.Certificate, []byte, error) {
return nil, nil, err
}
defer file.Close()
certPEM, err := ioutil.ReadAll(file)
certPEM, err := io.ReadAll(file)
if err != nil {
return nil, nil, err
}

View file

@ -5,7 +5,7 @@ import (
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"io/ioutil"
"io"
"os"
)
@ -43,7 +43,7 @@ func pullPrivateKeyFromFS() (*rsa.PrivateKey, []byte, error) {
}
defer file.Close()
keyPEM, err := ioutil.ReadAll(file)
keyPEM, err := io.ReadAll(file)
if err != nil {
return nil, nil, err
}

View file

@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"strconv"
"strings"
)
@ -78,11 +77,11 @@ func NewStringFromInterface(val interface{}) string {
}
func NewReadCloserFromBytes(t []byte) io.ReadCloser {
return ioutil.NopCloser(bytes.NewReader(t))
return io.NopCloser(bytes.NewReader(t))
}
func NewReadCloserFromReader(r io.Reader) io.ReadCloser {
return ioutil.NopCloser(r)
return io.NopCloser(r)
}
func PrettyPrint(json_dirty []byte) []byte {

View file

@ -5,7 +5,6 @@ import (
. "github.com/mickael-kerjean/filestash/server/common"
"golang.org/x/crypto/bcrypt"
"io"
"io/ioutil"
"net/http"
"os"
"strconv"
@ -56,7 +55,7 @@ func AdminSessionAuthenticate(ctx *App, res http.ResponseWriter, req *http.Reque
return
}
var params map[string]string
b, _ := ioutil.ReadAll(req.Body)
b, _ := io.ReadAll(req.Body)
json.Unmarshal(b, &params)
if err := bcrypt.CompareHashAndPassword([]byte(admin), []byte(params["password"])); err != nil {
SendErrorResult(res, ErrInvalidPassword)

View file

@ -2,7 +2,7 @@ package ctrl
import (
. "github.com/mickael-kerjean/filestash/server/common"
"io/ioutil"
"io"
"net/http"
)
@ -13,7 +13,7 @@ func PrivateConfigHandler(ctx *App, res http.ResponseWriter, req *http.Request)
}
func PrivateConfigUpdateHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
b, _ := ioutil.ReadAll(req.Body)
b, _ := io.ReadAll(req.Body)
if err := SaveConfig(b); err != nil {
SendErrorResult(res, err)
return

View file

@ -2,9 +2,10 @@ package ctrl
import (
"fmt"
. "github.com/mickael-kerjean/filestash/server/common"
"net/http"
"os"
. "github.com/mickael-kerjean/filestash/server/common"
)
func ReportHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
@ -21,6 +22,7 @@ func WellKnownSecurityHandler(ctx *App, res http.ResponseWriter, req *http.Reque
func HealthHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
res.Header().Set("Access-Control-Allow-Origin", "*")
res.Header().Set("Content-Type", "application/json")
// CHECK 1: open the config file
file, err := os.OpenFile(
GetAbsolutePath(CONFIG_PATH, "config.json"),
@ -69,5 +71,7 @@ func HealthHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
// SUCCESS!!
res.WriteHeader(http.StatusOK)
res.Write([]byte(`{"status": "pass"}`))
if req.Method != "HEAD" {
res.Write([]byte(`{"status": "pass"}`))
}
}

View file

@ -307,6 +307,7 @@ func SessionAuthMiddleware(ctx *App, res http.ResponseWriter, req *http.Request)
// - identity provider redirection uri. eg: oauth2, openid, ...
templateBind, err := plugin.Callback(formData, idpParams, res)
if err == ErrAuthenticationFailed {
Log.Warning("failed authentication - %s", err.Error())
http.Redirect(
res, req,
req.URL.Path+"?action=redirect",

View file

@ -2,7 +2,7 @@ package main
import (
"fmt"
"io/ioutil"
"io"
"os"
)
@ -15,7 +15,7 @@ func main() {
}
defer f.Close()
j, err := ioutil.ReadAll(f)
j, err := io.ReadAll(f)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)

View file

@ -3,7 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"os"
)
@ -16,7 +16,7 @@ func main() {
}
defer f.Close()
j, err := ioutil.ReadAll(f)
j, err := io.ReadAll(f)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)

View file

@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"
. "github.com/mickael-kerjean/filestash/server/common"
"io/ioutil"
"io"
"net/http"
"strings"
)
@ -12,7 +12,7 @@ import (
func BodyParser(fn HandlerFunc) HandlerFunc {
extractBody := func(req *http.Request) (map[string]interface{}, error) {
body := map[string]interface{}{}
byt, err := ioutil.ReadAll(req.Body)
byt, err := io.ReadAll(req.Body)
if err != nil {
return body, err
}

View file

@ -6,7 +6,6 @@ import (
"fmt"
. "github.com/mickael-kerjean/filestash/server/common"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
@ -162,7 +161,7 @@ func (this ArtifactoryStorage) Ls(path string) ([]os.FileInfo, error) {
if err != nil {
return nil, err
}
jsonStr, err := ioutil.ReadAll(res.Body)
jsonStr, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
Log.Debug("plg_backend_artifactory::ls readall data[%s] status[%d]", string(jsonStr), res.StatusCode)
@ -190,7 +189,7 @@ func (this ArtifactoryStorage) Cat(path string) (io.ReadCloser, error) {
if err != nil {
return nil, err
}
jsonStr, err := ioutil.ReadAll(res.Body)
jsonStr, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
Log.Debug("plg_backend_artifactory::cat readall data[%s] status[%d]", string(jsonStr), res.StatusCode)
@ -269,7 +268,7 @@ func (this ArtifactoryStorage) Mkdir(path string) error {
if err != nil {
return err
}
jsonStr, err := ioutil.ReadAll(res.Body)
jsonStr, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
Log.Debug("plg_backend_artifactory::mkdir readall status[%d] data[%s]", res.StatusCode, string(jsonStr))
@ -307,7 +306,7 @@ func (this ArtifactoryStorage) Rm(path string) error {
if err != nil {
return err
}
jsonStr, err := ioutil.ReadAll(res.Body)
jsonStr, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
Log.Debug("plg_backend_artifactory::rm readall status[%d] data[%s]", res.StatusCode, string(jsonStr))
@ -336,7 +335,7 @@ func (this ArtifactoryStorage) Mv(from, to string) error {
if err != nil {
return err
}
jsonStr, err := ioutil.ReadAll(res.Body)
jsonStr, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
Log.Debug("plg_backend_artifactory::mv readall status[%d] data[%s]", res.StatusCode, string(jsonStr))
@ -367,7 +366,7 @@ func (this ArtifactoryStorage) Save(path string, content io.Reader) error {
if err != nil {
return err
}
jsonStr, err := ioutil.ReadAll(res.Body)
jsonStr, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
Log.Debug("plg_backend_artifactory::save readall status[%d] data[%s]", res.StatusCode, string(jsonStr))

View file

@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
@ -56,7 +55,7 @@ func (this Backblaze) Init(params map[string]string, app *App) (IBackend, error)
if err != nil {
return nil, err
}
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
return nil, err
@ -79,7 +78,7 @@ func (this Backblaze) Init(params map[string]string, app *App) (IBackend, error)
if err != nil {
return nil, err
}
body, err = ioutil.ReadAll(res.Body)
body, err = io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
return nil, err
@ -153,7 +152,7 @@ func (this Backblaze) Ls(path string) ([]os.FileInfo, error) {
if err != nil {
return nil, err
}
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
return nil, err
@ -222,7 +221,7 @@ func (this Backblaze) Mkdir(path string) error {
if err != nil {
return err
}
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
return err
@ -260,7 +259,7 @@ func (this Backblaze) Rm(path string) error {
if err != nil {
return err
}
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
return err
@ -289,7 +288,7 @@ func (this Backblaze) Rm(path string) error {
if err != nil {
return err
}
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
return err
@ -317,7 +316,7 @@ func (this Backblaze) Rm(path string) error {
if err != nil {
return err
}
if body, err = ioutil.ReadAll(res.Body); err != nil {
if body, err = io.ReadAll(res.Body); err != nil {
return err
}
res.Body.Close()
@ -349,7 +348,7 @@ func (this Backblaze) Touch(path string) error {
if err != nil {
return err
}
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
return err
@ -378,7 +377,7 @@ func (this Backblaze) Touch(path string) error {
if err != nil {
return err
}
body, err = ioutil.ReadAll(res.Body)
body, err = io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
return err
@ -406,7 +405,7 @@ func (this Backblaze) Save(path string, file io.Reader) error {
if err != nil {
return err
}
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
return err
@ -468,7 +467,7 @@ func (this Backblaze) Save(path string, file io.Reader) error {
if err != nil {
return err
}
body, err = ioutil.ReadAll(res.Body)
body, err = io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
return err

View file

@ -5,7 +5,6 @@ import (
"fmt"
. "github.com/mickael-kerjean/filestash/server/common"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
@ -201,7 +200,7 @@ func (this Dav) Mv(from string, to string) error {
if err != nil {
return err
}
d, err := ioutil.ReadAll(reader)
d, err := io.ReadAll(reader)
if err != nil {
return ErrNotValid
}

View file

@ -4,7 +4,6 @@ import (
"encoding/json"
. "github.com/mickael-kerjean/filestash/server/common"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
@ -123,7 +122,7 @@ func (d Dropbox) Cat(path string) (io.ReadCloser, error) {
arg := struct {
Path string `json:"path"`
}{d.path(path)}
json, _ := ioutil.ReadAll(d.toReader(arg))
json, _ := io.ReadAll(d.toReader(arg))
req.Header.Set("Dropbox-API-Arg", string(json))
})
if err != nil {
@ -184,7 +183,7 @@ func (d Dropbox) Save(path string, file io.Reader) error {
AutoRename bool `json:"autorename"`
Mode string `json:"mode"`
}{d.path(path), false, "overwrite"}
json, _ := ioutil.ReadAll(d.toReader(arg))
json, _ := io.ReadAll(d.toReader(arg))
req.Header.Set("Dropbox-API-Arg", string(json))
req.Header.Set("Content-Type", "application/octet-stream")
})

View file

@ -282,6 +282,9 @@ func wopiDiscovery(ctx *App, fullpath string) (string, error) {
p := u.Query()
p.Set("WOPISrc", wopiSRC)
p.Set("access_token", ctx.Authorization)
if len(ctx.Languages) > 0 {
p.Set("lang", ctx.Languages[0])
}
u.RawQuery = p.Encode()
if newHost := rewrite_url(); newHost != "" {
if p, err := url.Parse(newHost); err == nil {

View file

@ -4,7 +4,6 @@ import (
"github.com/h2non/bimg"
. "github.com/mickael-kerjean/filestash/server/common"
"io"
"io/ioutil"
"net/http"
)
@ -28,7 +27,7 @@ func (this thumbnailer) Generate(reader io.ReadCloser, ctx *App, res *http.Respo
return reader, nil
}
b, err := ioutil.ReadAll(reader)
b, err := io.ReadAll(reader)
if err != nil {
return reader, err
}

View file

@ -3,7 +3,6 @@ package plg_security_svg
import (
. "github.com/mickael-kerjean/filestash/server/common"
"io"
"io/ioutil"
"net/http"
"regexp"
)
@ -42,7 +41,7 @@ func init() {
(*res).Header().Set("Content-Security-Policy", "script-src 'none'; default-src 'none'; img-src 'self'")
(*res).Header().Set("Content-Type", "text/plain")
// XML bomb
txt, _ := ioutil.ReadAll(reader)
txt, _ := io.ReadAll(reader)
if regexp.MustCompile("(?is)entity").Match(txt) {
txt = []byte("")
}

View file

@ -103,7 +103,7 @@ func Build(r *mux.Router, a App) {
r.HandleFunc(WithBase("/robots.txt"), NewMiddlewareChain(RobotsHandler, []Middleware{}, a))
r.HandleFunc(WithBase("/manifest.json"), NewMiddlewareChain(ManifestHandler, []Middleware{}, a)).Methods("GET")
r.HandleFunc(WithBase("/.well-known/security.txt"), NewMiddlewareChain(WellKnownSecurityHandler, []Middleware{}, a)).Methods("GET")
r.HandleFunc(WithBase("/healthz"), NewMiddlewareChain(HealthHandler, []Middleware{}, a)).Methods("GET")
r.HandleFunc(WithBase("/healthz"), NewMiddlewareChain(HealthHandler, []Middleware{}, a)).Methods("GET", "HEAD")
r.HandleFunc(WithBase("/custom.css"), NewMiddlewareChain(CustomCssHandler, []Middleware{}, a)).Methods("GET")
r.PathPrefix(WithBase("/doc")).Handler(NewMiddlewareChain(DocPage, []Middleware{}, a)).Methods("GET", "POST", "PUT", "DELETE", "OPTIONS")