check for (some) bad data

This commit is contained in:
leah 2022-01-29 14:02:15 +00:00
parent 7bf9f805c1
commit 5a7c186694
1 changed files with 15 additions and 0 deletions

15
main.go
View File

@ -48,6 +48,21 @@ func loadConfig() (err error) {
err = yaml.Unmarshal(configfile, &config)
// todo: check for bad data !!
var re = regexp.MustCompile(`(((ftp|http|https):\/\/)|(\/)|(..\/))(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?`)
tocheck := [2]string{config.Panel.Host, config.Auth.GiteaURL}
for _, val := range tocheck {
if len(re.FindStringIndex(val)) == 0 {
log.Fatalf(`"%s" is not a valid url.`, val)
}
}
if config.Panel.Port > 65535 {
log.Fatalf("port is too big (max 65535)")
}
// init oauth bits
redirecturi = fmt.Sprintf("%s/login/endpoint", config.Panel.Host)
requesturl = fmt.Sprintf("%s/login/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code&state=STATE",