Exemple #1
0
package origincfg

import "github.com/hlandau/degoutils/web/origin/originfuncs"
import "gopkg.in/hlandau/easyconfig.v1/cflag"

// The trust function to be used. Can be set by configurable 'trustforwarded'.
var TrustPolicy = "last"
var trustForwardedFlag = cflag.StringVar(nil, &TrustPolicy, "trustforwarded", "last", "What Forwarded headers to trust? (last|forwarded/1|x-real-ip)")

// Registered trust functions.
var trustFuncs = map[string]originfuncs.LegFunc{}

func RegisterTrustFunc(name string, tf originfuncs.LegFunc) {
	trustFuncs[name] = tf
}

func init() {
	// Register trust functions.
	RegisterTrustFunc("forwarded/1", originfuncs.TrustForwardedN(1))
	RegisterTrustFunc("x-real-ip", originfuncs.TrustXRealIP)
	RegisterTrustFunc("last", originfuncs.TrustLast)
}

func TrustByConfig(leg *originfuncs.Leg, distance int) bool {
	v := trustForwardedFlag.Value()
	f, ok := trustFuncs[v]
	return ok && f(leg, distance)
}

// Get trusted legs based on configuration.
func TrustedLegs(legs []originfuncs.Leg) []originfuncs.Leg {
Exemple #2
0
// Development mode? In development mode, the application server may behave
// differently. Errors may be reported differently, assets may be reloaded
// automatically, etc.
//
// Configurable 'devmode'.
var DevMode bool

var devModeFlag = cflag.BoolVar(nil, &DevMode, "devmode", false, "Development mode?")

// Base directory. Some files may be looked for relative to this directory; templates, assets, etc.
//
// Configurable 'basedir'.
var BaseDir string

var baseDirFlag = cflag.StringVar(nil, &BaseDir, "basedir", "", "Base dir (containing assets, tpl directories, etc.)")

// Base URL. This is the canonical base URL, which will be used in e.g. e.
// mails. It should not have a trailing slash.
//
// Configurable 'baseurl'.
var BaseURL string

var baseURLFlag = cflag.StringVar(nil, &BaseURL, "baseurl", "", "Base URL (e.g. https://DOMAIN)")

// Base domain. This may be used in circumstances in which an URL is not appropriate, but rather
// a domain name is needed.
//
// Configurable 'basedomain'.
var BaseDomain string