configfile

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2023 License: MIT Imports: 38 Imported by: 0

Documentation

Overview

Package configfile handles all the base configuration-file routines. This package also holds the configuration for the webserver and notifiarr packages. In here you will find config file parsing, validation, and creation. The application can re-write its own config file from a built-in template, complete with comments. In some circumstances the application writes a brand new empty config on startup.

Index

Constants

View Source
const (
	MsgNoConfigFile = "Using env variables only. Config file not found."
	MsgConfigFailed = "Using env variables only. Could not create config file: "
	MsgConfigCreate = "Created new config file '%s'. Your Web UI '%s' user password is '%s' " +
		"and will not be printed again. Log in, and change it."
	MsgConfigFound  = "Using Config File: "
	DefaultUsername = "admin"
	DefaultHeader   = "x-webauth-user"
)

Return prefixes from FindAndReturn.

Variables

View Source
var (
	// ForceAllTmpl allows you to force some specific settings. Used to build a default template.
	ForceAllTmpl = false

	// Template is the config file template.
	Template = template.Must(template.New("config").Funcs(Funcs()).Parse(tmpl))
)
View Source
var ErrEmptyHeader = fmt.Errorf("auth header may not be empty")

Functions

func BackupFile added in v0.4.1

func BackupFile(configFile string) error

BackupFile makes a config file backup file.

func CheckPort added in v0.2.0

func CheckPort(addr string) (string, error)

CheckPort attempts to bind to a port to check if it's in use or not. We use this to check the port before starting the webserver.

func Funcs

func Funcs() template.FuncMap

Funcs returns our template functions.

func GeneratePassword added in v0.5.0

func GeneratePassword() string

GeneratePassword uses a word list to create a randmo password of two words and a number.

Types

type AllowedIPs

type AllowedIPs struct {
	Input []string
	Nets  []*net.IPNet
}

AllowedIPs determines who can set x-forwarded-for.

func MakeIPs added in v0.1.15

func MakeIPs(upstreams []string) AllowedIPs

MakeIPs turns a list of CIDR strings (or plain IPs) into a list of net.IPNet. This "allowed" list is later used to check incoming IPs from web requests.

func (AllowedIPs) Contains

func (n AllowedIPs) Contains(ip string) bool

Contains returns true if an IP is allowed.

func (AllowedIPs) String

func (n AllowedIPs) String() (s string)

String turns a list of allowedIPs into a printable masterpiece.

type AuthType added in v0.5.0

type AuthType int
const (
	AuthPassword AuthType = iota
	AuthHeader
	AuthNone
)

func (AuthType) String added in v0.5.0

func (t AuthType) String() string

type Config

type Config struct {
	HostID     string                 `json:"hostId" toml:"host_id" xml:"host_id" yaml:"hostId"`
	UIPassword CryptPass              `json:"uiPassword" toml:"ui_password" xml:"ui_password" yaml:"uiPassword"`
	BindAddr   string                 `json:"bindAddr" toml:"bind_addr" xml:"bind_addr" yaml:"bindAddr"`
	SSLCrtFile string                 `json:"sslCertFile" toml:"ssl_cert_file" xml:"ssl_cert_file" yaml:"sslCertFile"`
	SSLKeyFile string                 `json:"sslKeyFile" toml:"ssl_key_file" xml:"ssl_key_file" yaml:"sslKeyFile"`
	Upstreams  []string               `json:"upstreams" toml:"upstreams" xml:"upstreams" yaml:"upstreams"`
	AutoUpdate string                 `json:"autoUpdate" toml:"auto_update" xml:"auto_update" yaml:"autoUpdate"`
	Timeout    cnfg.Duration          `json:"timeout" toml:"timeout" xml:"timeout" yaml:"timeout"`
	Retries    int                    `json:"retries" toml:"retries" xml:"retries" yaml:"retries"`
	Snapshot   *snapshot.Config       `json:"snapshot" toml:"snapshot" xml:"snapshot" yaml:"snapshot"`
	Services   *services.Config       `json:"services" toml:"services" xml:"services" yaml:"services"`
	Service    []*services.Service    `json:"service" toml:"service" xml:"service" yaml:"service"`
	EnableApt  bool                   `json:"apt" toml:"apt" xml:"apt" yaml:"apt"`
	WatchFiles []*filewatch.WatchFile `json:"watchFiles" toml:"watch_file" xml:"watch_file" yaml:"watchFiles"`
	Commands   []*commands.Command    `json:"commands" toml:"command" xml:"command" yaml:"commands"`
	*logs.LogConfig
	*apps.Apps
	Allow AllowedIPs `json:"-" toml:"-" xml:"-" yaml:"-"`
}

Config represents the data in our config file.

func NewConfig added in v0.2.0

func NewConfig(logger mnd.Logger) *Config

NewConfig returns a fresh config with only defaults and a logger ready to go.

func (*Config) CopyConfig added in v0.3.0

func (c *Config) CopyConfig() (*Config, error)

CopyConfig returns a copy of the configuration data. Useful for writing a config file with different values than what's running.

func (*Config) FindAndReturn

func (c *Config) FindAndReturn(ctx context.Context, configFile string, write bool) (string, string, string)

FindAndReturn return a config file. Write one if requested.

func (*Config) Get

func (c *Config) Get(flag *Flags, logger *logs.Logger) (*website.Server, *triggers.Actions, error)

Get parses a config file and environment variables. Sometimes the app runs without a config file entirely. You should only run this after getting a config with NewConfig().

func (*Config) Write

func (c *Config) Write(ctx context.Context, file string, encode bool) (string, error)

Write config to a file.

type CryptPass added in v0.3.0

type CryptPass string

CryptPass allows us to validate an input password easily.

func (CryptPass) Header added in v0.5.0

func (p CryptPass) Header() string

Header returns the auth proxy header that is configured.

func (CryptPass) IsCrypted added in v0.3.0

func (p CryptPass) IsCrypted() bool

IsCrypted checks if a password string is already encrypted.

func (CryptPass) Noauth added in v0.5.0

func (p CryptPass) Noauth() bool

Noauth returns true if the password indicates skipping authentication.

func (*CryptPass) Set added in v0.3.0

func (p *CryptPass) Set(pass string) error

Set sets an encrypted password.

func (*CryptPass) SetHeader added in v0.5.0

func (p *CryptPass) SetHeader(header string) error

func (*CryptPass) SetNoAuth added in v0.5.0

func (p *CryptPass) SetNoAuth(header string) error

func (CryptPass) Type added in v0.5.0

func (p CryptPass) Type() AuthType

Type returns the authentication type configured.

func (CryptPass) Val added in v0.5.0

func (p CryptPass) Val() string

Val returns the string representation of the current password. It may or may not be encrypted.

func (CryptPass) Valid added in v0.3.0

func (p CryptPass) Valid(pass string) bool

Valid checks if a password is valid.

func (CryptPass) Webauth added in v0.3.0

func (p CryptPass) Webauth() bool

Webauth returns true if the password indicates an auth proxy (or no auth) is in use.

type Flags added in v0.1.14

type Flags struct {
	*flag.FlagSet `json:"-"`
	VerReq        bool     `json:"verReq"`
	LongVerReq    bool     `json:"longVerReq"`
	Restart       bool     `json:"restart"`
	AptHook       bool     `json:"aptHook"`
	Updated       bool     `json:"updated"`
	PSlist        bool     `json:"pslist"`
	Fortune       bool     `json:"fortune"`
	Write         string   `json:"write"`
	Reset         bool     `json:"reset"`
	Curl          string   `json:"curl"`
	ConfigFile    string   `json:"configFile"`
	ExtraConf     []string `json:"extraConf"`
	EnvPrefix     string   `json:"envPrefix"`
	Headers       []string `json:"headers"`
	Assets        string   `json:"staticDif"`
}

Flags are our CLI input flags.

func (*Flags) ParseArgs added in v0.1.14

func (f *Flags) ParseArgs(args []string)

ParseArgs stores the cli flag data into the Flags pointer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL