Skip to content

Commit

Permalink
Merge pull request #8 from 1kamma/main
Browse files Browse the repository at this point in the history
Get IP from headers or request


Co-authored-by: Benny Saret <[email protected]>
  • Loading branch information
jantari and 1kamma authored Sep 10, 2024
2 parents 9a619c5 + d214ad9 commit 1fc1c2f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ Commandline arguments have the highest priority and take precedence over both en
Set log verbosity: disable, error, warn, info, debug or trace (default "info")
-manifestPath string
The directory to search for package manifest files (default "./packages")
-trustedProxies string
List of IPs from which to trust Client-IP headers (comma or space to separate)
-version
Print the version information and exit
```
Expand All @@ -89,6 +91,7 @@ REWINGED_HTTPSPRIVATEKEYFILE (string)
REWINGED_LISTEN (string)
REWINGED_LOGLEVEL (string)
REWINGED_MANIFESTPATH (string)
REWINGED_TRUSTEDPROXIES (string)
```

</details>
Expand All @@ -109,7 +112,8 @@ rewinged will not look for any configuration file by default. Config file must b
"httpsPrivateKeyFile": "./private.key",
"listen": "localhost:8080",
"logLevel": "info",
"manifestPath": "./packages"
"manifestPath": "./packages",
"trustedProxies": ""
}
```

Expand Down
14 changes: 12 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strings"
"unicode"
"path/filepath"

// Configuration
"github.com/peterbourgon/ff/v3"

Expand Down Expand Up @@ -46,6 +45,7 @@ func main() {
autoInternalizePathPtr = fs.String("autoInternalizePath", "./installers", "The directory where auto-internalized installers will be stored")
autoInternalizeSkipPtr = fs.String("autoInternalizeSkip", "", "List of hostnames excluded from auto-internalization (comma or space to separate)")
logLevelPtr = fs.String("logLevel", "info", "Set log verbosity: disable, error, warn, info, debug or trace")
trustedProxiesPtr = fs.String("trustedProxies", "", "List of IPs from which to trust Client-IP headers (comma or space to separate)")
_ = fs.String("configFile", "", "Path to a json configuration file (optional)")
)

Expand Down Expand Up @@ -145,7 +145,17 @@ func main() {
}

router := gin.New()
router.SetTrustedProxies(nil)

// Users can set 0.0.0.0/0 or ::/0 to trust all proxies if need be
if (*trustedProxiesPtr != "") {
trustedProxies := strings.FieldsFunc(*trustedProxiesPtr, func(c rune) bool {
return unicode.IsSpace(c) || c == ','
})
router.SetTrustedProxies(trustedProxies)
} else {
// From my testing, both nil and '0.0.0.0' result in gin trusting noone
router.SetTrustedProxies(nil)
}
router.Use(logging.GinLogger())
router.Use(gin.Recovery())
router.Static("/installers", *autoInternalizePathPtr)
Expand Down

0 comments on commit 1fc1c2f

Please sign in to comment.