forgot to come back for trusted headers

This commit is contained in:
Ethan Knowlton 2023-10-08 18:39:18 -04:00
parent 967931fd25
commit d70ee291d4
3 changed files with 10 additions and 8 deletions

View File

@ -140,6 +140,7 @@ ECHOIP_LISTEN=":8080"
ECHOIP_TEMPLATE_DIR="html/" ECHOIP_TEMPLATE_DIR="html/"
ECHOIP_REDIS_URL="redis://localhost:6379" ECHOIP_REDIS_URL="redis://localhost:6379"
ECHOIP_DATABASE="ipstack" ECHOIP_DATABASE="ipstack"
ECHOIP_TRUSTED_HEADERS="X-Real-IP,X-Forwaded-For"
ECHOIP_IPSTACK_API_KEY="askdfj39sjdkf29dsjfk39sdfkj3" ECHOIP_IPSTACK_API_KEY="askdfj39sjdkf29dsjfk39sdfkj3"
ECHOIP_GEOIP_COUNTRY_FILE="/full/path/to/file.db" ECHOIP_GEOIP_COUNTRY_FILE="/full/path/to/file.db"
ECHOIP_GEOIP_CITY_FILE="/full/path/to/file.db" ECHOIP_GEOIP_CITY_FILE="/full/path/to/file.db"

View File

@ -46,9 +46,7 @@ func main() {
if err != nil { if err != nil {
log.Printf("Error opening config file (/etc/echoip/config.toml): %s", err) log.Printf("Error opening config file (/etc/echoip/config.toml): %s", err)
} } else {
if err == nil {
var b []byte var b []byte
b, err = io.ReadAll(file) b, err = io.ReadAll(file)
if err != nil { if err != nil {

View File

@ -3,6 +3,7 @@ package config
import ( import (
"os" "os"
"strconv" "strconv"
"strings"
) )
type IPStack struct { type IPStack struct {
@ -36,11 +37,10 @@ type Config struct {
func GetConfig() (Config, error) { func GetConfig() (Config, error) {
defaultConfig := Config{ defaultConfig := Config{
Listen: getenv_string("ECHOIP_LISTEN", ":8080"), Listen: getenv_string("ECHOIP_LISTEN", ":8080"),
TemplateDir: getenv_string("ECHOIP_TEMPLATE_DIR", "html/"), TemplateDir: getenv_string("ECHOIP_TEMPLATE_DIR", "html/"),
RedisUrl: getenv_string("ECHOIP_REDIS_URL", ""), RedisUrl: getenv_string("ECHOIP_REDIS_URL", ""),
TrustedHeaders: nil, Database: getenv_string("ECHOIP_DATABASE", "geoip"),
Database: getenv_string("ECHOIP_DATABASE", "geoip"),
IPStack: IPStack{ IPStack: IPStack{
ApiKey: getenv_string("ECHOIP_IPSTACK_API_KEY", ""), ApiKey: getenv_string("ECHOIP_IPSTACK_API_KEY", ""),
}, },
@ -93,6 +93,9 @@ func GetConfig() (Config, error) {
} }
defaultConfig.IPStack.EnableSecurity = ipStackEnableSecurity defaultConfig.IPStack.EnableSecurity = ipStackEnableSecurity
trustedHeaders := getenv_string("ECHOIP_TRUSTED_HEADERS", "")
defaultConfig.TrustedHeaders = strings.Split(trustedHeaders, ",")
return defaultConfig, nil return defaultConfig, nil
} }