added configuration for webserver and AllowRoot

This commit is contained in:
fanir 2022-01-26 00:22:22 +01:00
parent 0fd673cd19
commit 8021684f77
5 changed files with 39 additions and 4 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
*.yaml
# ---> Go # ---> Go
# Binaries for programs and plugins # Binaries for programs and plugins

View file

@ -1,3 +1,13 @@
# Feedizer # Feedizer
A rewrite of the [Feedizer](https://git.zom.bi/fanir/feedizer) project originally written in PHP5. A rewrite of the [Feedizer](https://git.zom.bi/fanir/feedizer) project originally written in PHP5.
## Configuration
To write the default configuration to a file, run `feedizer [-C path/to/configfile.yaml] newconfig`
## Running as root
Feedizer will abort startup if run as root. If you want to disable this behavior,
i.e. because feedizer is running inside a docker container, you can set
`FEEDIZER_ALLOWROOT=1` in the environment or `AllowRoot: true` in the config file.

View file

@ -17,8 +17,18 @@ type DatabaseConfig struct {
Options string Options string
} }
type ServerConfig struct {
Address string
TemplateDir string
StaticDir string
}
type Config struct { type Config struct {
Database DatabaseConfig Database DatabaseConfig
Server ServerConfig
AllowRoot bool
} }
var config = Config{ var config = Config{
@ -28,6 +38,11 @@ var config = Config{
Database: "feedizer", Database: "feedizer",
Options: "sslmode=require", Options: "sslmode=require",
}, },
Server: ServerConfig{
Address: ":3000",
TemplateDir: "../../templates",
StaticDir: "../../static",
},
} }
const appName = "feedizer" const appName = "feedizer"

View file

@ -57,6 +57,15 @@ func structFromEnv(v reflect.Value, t reflect.Type, prefix string) (namesAvailab
panic(err) panic(err)
} }
fv.SetInt(x) fv.SetInt(x)
case reflect.Bool:
switch strings.ToLower(val) {
case "1", "true", "t", "on":
fv.SetBool(true)
case "0", "false", "f", "off":
fv.SetBool(false)
default:
panic(fmt.Sprintf("cannot set field for environment variable %s: cannot parse %s as boolean. Please use one of: 1, true, t, on / 0, false, f, off", envName, fk))
}
default: default:
panic(fmt.Sprintf("cannot set field for environment variable %s: type %s is not supported", envName, fk)) panic(fmt.Sprintf("cannot set field for environment variable %s: type %s is not supported", envName, fk))
} }

View file

@ -14,10 +14,6 @@ import (
) )
func main() { func main() {
if os.Geteuid() == 0 {
log.Fatalln("do not run feedizer as root")
}
configFile := flag.String("C", "", "custom config file path") configFile := flag.String("C", "", "custom config file path")
autoMigrate := flag.Bool("m", true, "Automatically migrate the database to the highest version.") autoMigrate := flag.Bool("m", true, "Automatically migrate the database to the highest version.")
flag.Parse() flag.Parse()
@ -49,6 +45,10 @@ func startApp(automigrate bool) {
log.Fatalln(err) log.Fatalln(err)
} }
if !cfg.AllowRoot && os.Geteuid() == 0 {
log.Fatalln("do not run feedizer as root")
}
db, err := database.Open(cfg.Database) db, err := database.Open(cfg.Database)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)