2023-06-10 16:21:38 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io/fs"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
customize struct {
|
2023-10-02 19:52:24 +00:00
|
|
|
AppIcon string `json:"appIcon,omitempty" yaml:"appIcon"`
|
|
|
|
AppTitle string `json:"appTitle,omitempty" yaml:"appTitle"`
|
|
|
|
DisableAppTitle bool `json:"disableAppTitle,omitempty" yaml:"disableAppTitle"`
|
|
|
|
DisablePoweredBy bool `json:"disablePoweredBy,omitempty" yaml:"disablePoweredBy"`
|
|
|
|
DisableQRSupport bool `json:"disableQRSupport,omitempty" yaml:"disableQRSupport"`
|
|
|
|
DisableThemeSwitcher bool `json:"disableThemeSwitcher,omitempty" yaml:"disableThemeSwitcher"`
|
|
|
|
|
2023-06-26 21:01:06 +00:00
|
|
|
DisableExpiryOverride bool `json:"disableExpiryOverride,omitempty" yaml:"disableExpiryOverride"`
|
|
|
|
ExpiryChoices []int64 `json:"expiryChoices,omitempty" yaml:"expiryChoices"`
|
2023-10-02 19:52:24 +00:00
|
|
|
|
|
|
|
AcceptedFileTypes string `json:"acceptedFileTypes" yaml:"acceptedFileTypes"`
|
|
|
|
DisableFileAttachment bool `json:"disableFileAttachment" yaml:"disableFileAttachment"`
|
|
|
|
MaxAttachmentSizeTotal int64 `json:"maxAttachmentSizeTotal" yaml:"maxAttachmentSizeTotal"`
|
|
|
|
|
|
|
|
OverlayFSPath string `json:"-" yaml:"overlayFSPath"`
|
|
|
|
UseFormalLanguage bool `json:"-" yaml:"useFormalLanguage"`
|
2023-06-10 16:21:38 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-08-10 22:57:30 +00:00
|
|
|
func loadCustomize(filename string) (cust customize, err error) {
|
2023-06-10 16:21:38 +00:00
|
|
|
if filename == "" {
|
|
|
|
// None given, take a shortcut
|
2023-08-10 22:57:30 +00:00
|
|
|
cust.applyFixes()
|
|
|
|
return cust, nil
|
2023-06-10 16:21:38 +00:00
|
|
|
}
|
|
|
|
|
2023-10-04 20:53:29 +00:00
|
|
|
cf, err := os.Open(filename) //#nosec:G304 // Loading a custom file is the intention here
|
2023-06-10 16:21:38 +00:00
|
|
|
if err != nil {
|
|
|
|
if errors.Is(err, fs.ErrNotExist) {
|
|
|
|
logrus.Warn("customize file given but not found")
|
|
|
|
return cust, nil
|
|
|
|
}
|
|
|
|
return cust, errors.Wrap(err, "opening customize file")
|
|
|
|
}
|
2023-10-04 20:53:29 +00:00
|
|
|
defer func() {
|
|
|
|
if err := cf.Close(); err != nil {
|
|
|
|
logrus.WithError(err).Error("closing customize file (leaked fd)")
|
|
|
|
}
|
|
|
|
}()
|
2023-06-10 16:21:38 +00:00
|
|
|
|
2023-08-10 22:57:30 +00:00
|
|
|
if err = yaml.NewDecoder(cf).Decode(&cust); err != nil {
|
|
|
|
return cust, errors.Wrap(err, "decoding customize file")
|
|
|
|
}
|
|
|
|
|
|
|
|
cust.applyFixes()
|
|
|
|
|
|
|
|
return cust, nil
|
2023-06-10 16:21:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c customize) ToJSON() (string, error) {
|
|
|
|
j, err := json.Marshal(c)
|
|
|
|
return string(j), errors.Wrap(err, "marshalling JSON")
|
|
|
|
}
|
2023-08-10 22:57:30 +00:00
|
|
|
|
|
|
|
func (c *customize) applyFixes() {
|
|
|
|
if len(c.AppTitle) == 0 {
|
|
|
|
c.AppTitle = "OTS - One Time Secrets"
|
|
|
|
}
|
|
|
|
}
|