From dee4108fbcacb47df33a6f98b272f8a325172cde Mon Sep 17 00:00:00 2001 From: MickaelK Date: Fri, 8 Aug 2025 14:13:29 +1000 Subject: [PATCH] feature (license): update from agpl license --- server/plugin/index.go | 1 + server/plugin/plg_license/index.go | 53 ++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 server/plugin/plg_license/index.go diff --git a/server/plugin/index.go b/server/plugin/index.go index 09d59cf6..f279a016 100644 --- a/server/plugin/index.go +++ b/server/plugin/index.go @@ -32,6 +32,7 @@ import ( _ "github.com/mickael-kerjean/filestash/server/plugin/plg_handler_mcp" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_image_ascii" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_image_c" + _ "github.com/mickael-kerjean/filestash/server/plugin/plg_license" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_search_stateless" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_security_scanner" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_security_svg" diff --git a/server/plugin/plg_license/index.go b/server/plugin/plg_license/index.go new file mode 100644 index 00000000..0c9f1fef --- /dev/null +++ b/server/plugin/plg_license/index.go @@ -0,0 +1,53 @@ +package plg_license + +import ( + "encoding/json" + "fmt" + "os" + "time" + + . "github.com/mickael-kerjean/filestash/server/common" +) + +type license struct { + Expiry time.Time `json:"expiry"` + Name string `json:"name"` +} + +func init() { + Hooks.Register.Onload(func() { + if LICENSE != "agpl" { + return + } + data, err := DecryptString(fmt.Sprintf("%-16s", "filestash"), Config.Get("general.license").Schema(func(f *FormElement) *FormElement { + if f == nil { + f = &FormElement{} + } + f.Name = "license" + f.Type = "text" + f.Placeholder = "License Key" + f.Description = "Reach out to support@filestash.app to get your license" + lenv := os.Getenv("LICENSE") + if lenv != "" { + f.Value = os.Getenv("LICENSE") + f.ReadOnly = true + } + return f + }).String()) + if err != nil { + return + } + var lic license + if err := json.Unmarshal([]byte(data), &lic); err != nil { + return + } + if time.Now().After(lic.Expiry) { + Log.Error("License expired. expiry=%s name=%s", lic.Expiry, lic.Name) + Log.Error("Contact support at support@filestash.app") + os.Exit(1) + return + } + LICENSE = lic.Name + Log.Info("You are running Filestash \"%s\"", LICENSE) + }) +}