aids

package
v0.0.0-...-91ea87c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2023 License: BSD-2-Clause Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const HTTPCookieBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%&'()*+-./:<>?@[]^_`{|}~"
View Source
const HexBytes = "0123456789abcdef"
View Source
const JWT_cookie_name string = "gdlemonitor"
View Source
const JWT_key_change_interval int64 = 1800 // seconds

JWT Key - these are server-wide keys, used to digitally sign and validate tokens. Internally

View Source
const JWT_state_lifetime int64 = 1800 // seconds
View Source
const JWTkeyBytes = " !#$%&()*+,-./0123456789:;<=>?&ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}"
View Source
const SQLpasswordBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
View Source
const URLBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_~!$&'()*+,;=:@"

Variables

View Source
var (
	IP_whitelist     []*net.IPNet
	Intel_httpClient http.Client = http.Client{Timeout: 10 * time.Second}
)
View Source
var (
	InfoLog  *log.Logger
	ErrorLog *log.Logger
	DebugLog *log.Logger
	EWInfo   *eWInfo
	EWError  *eWError
	EWDebug  *eWDebug
)
View Source
var Elog debug.Log
View Source
var ISDebug bool = false

Functions

func Access

func Access(access int) string

func ByteCountIEC

func ByteCountIEC(b uint64) string

func CheckInternalError

func CheckInternalError(err error, w *http.ResponseWriter) bool

if err != nil, writes http 500 with err.Error(), return true if no error, return false

func Check_email

func Check_email(email string) error

func Check_password

func Check_password(password string) error

func Check_security

func Check_security(security *[]models.Account_security) error

func Check_username

func Check_username(username string) error

func DropJWT

func DropJWT(w http.ResponseWriter, claimsId string)

func Format

func Format(n int) string

func GetPublicIP

func GetPublicIP() string

////////////////////////////////////////////////////////////// returns public ip address. on error, it returns 0.0.0.0

func GetUser

func GetUser() string

func Intel_Init

func Intel_Init(whitelist []string) error

Should be called before GetResult, to parse the default whitelist, and validate contact email

func IssueJWT

func IssueJWT(acct *models.Account, w http.ResponseWriter)

func LoadTails

func LoadTails()

func RandString

func RandString(n int, source string) string

func RefreshJWT

func RefreshJWT(claims *Claims, w http.ResponseWriter)

func Setup_logging

func Setup_logging()

func Sifplurral

func Sifplurral(input int) string

Types

type Claims

type Claims struct {
	models.Claim
	jwt.StandardClaims
}

func GetJWTClaims

func GetJWTClaims(w http.ResponseWriter, r *http.Request) *Claims

func VerifyAccess

func VerifyAccess(reqLevel int, w http.ResponseWriter, r *http.Request) *Claims

////////////////////////////////////////////////////////////// verify access level returns authenticated claims struct, if access level is >= reqLevel. returns nil if access level < reqLevel returns nil if client has no claims if reqLevel >= 0, sends HTTP 401

type EnvVar

type EnvVar struct {
	Name string
	Desc string
}

type GDLEMonitorConf

type GDLEMonitorConf struct {
	Gdle struct {
		Config string   `json:"config"`
		Logs   []string `json:"logs"`
	} `json:"gdle"`
	Heartbeat     int               `json:"heartbeat"`
	BindIP        string            `json:"bind_ip"`
	DomainName    string            `json:"domain_name"`
	DomainContact string            `json:"domain_contact"`
	ENV           map[string]string `json:"env"`
	SpamAddress   string            `json:"spam_address"`
	Whitelist     []string          `json:"whitelist"`
	API           struct {
		Port                  int  `json:"port"`
		RedirectNonsecurePort bool `json:"redirect_nonsecure_port"`
		AccountLimitEmail     int  `json:"account_limit_email"`
		AccountLimitIP        int  `json:"account_limit_ip"`
		AccountSQMax          int  `json:"account_sq_max"`
		AccountSQMin          int  `json:"account_sq_min"`
		AccountRequireEmail   bool `json:"require_email"`
		AccountLimitProxy     bool `json:"account_limit_proxy"`
		LoginLimitProxy       bool `json:"login_limit_proxy"`
	} `json:"api"`
}

type GDLEMonitorConfig_Dynamic

type GDLEMonitorConfig_Dynamic struct {
	Origin       string `json:"origin"`    // set in service.go@gdlemonitormain(), used in templating, API ref, javascript
	ACServerName string `json:"title"`     // set in service.go@readServerConfig(), used in templating, API ref, javascript
	ACServer     string `json:"ac_server"` // set in service.go@readServerConfig()(), used in templating, API ref, javascript
	PublicIP     string `json:"public_ip"` // set in service.go@gdlemonitormain(), used in templating, API ref, javascript, domain, tls certs
}

type IP_Result

type IP_Result struct {
	LastChecked   time.Time `json:"last_checked"`
	ContinentCode string    `json:"continentCode"`
	CountryCode   string    `json:"countryCode"`
	Region        string    `json:"region"`
	City          string    `json:"city"`
	Lat           float64   `json:"lat"`
	Lon           float64   `json:"lon"`
	Offset        int       `json:"offset"`
	Reverse       string    `json:"reverse"`
	Mobile        bool      `json:"mobile"`
	Proxy         bool      `json:"proxy"`
	Hosting       bool      `json:"hosting"`
}

type Persistance

type Persistance struct {
	C          GDLEMonitorConf           `json:"config"`
	Cd         GDLEMonitorConfig_Dynamic `json:"conf"`
	GDLEcfg    map[string]interface{}    `json:"gdle"`
	GDLEcfg_ts time.Time                 `json:"gdle_ts"`
	Dirty      bool                      `json:"-"`

	JWTKeys   map[string]string `json:"jwt_keys"`
	JWTKeys_m sync.Mutex        `json:"-"`

	JWTState   map[string]*Claims `json:"jwt_state"`
	JWTState_m sync.Mutex         `json:"-"`

	IP   map[string]*IP_Result `json:"ip"`
	IP_m sync.Mutex            `json:"-"`

	UserLimiter   map[string]*Userlimiter `json:"-"`
	UserLimiter_m sync.Mutex              `json:"-"`

	GlobalLimiter *ratelimit.Bucket `json:"-"`

	TLS   map[string]*TLSCert `json:"tls"`
	TLS_m sync.Mutex          `json:"-"`
}
var P *Persistance

////////////////////////////////////////////////////////////// Persistance Cache in-memory database, with periodic marshals to json mostly to persist state for development; most can be nulled in production. //////////////////////////////////////////////////////////////

func (*Persistance) HeartBeat

func (per *Persistance) HeartBeat()

split up the various types into their own cleanup routines.

func (*Persistance) Intel_Cleanup

func (per *Persistance) Intel_Cleanup()

func (*Persistance) JWTKeys_Cleanup

func (per *Persistance) JWTKeys_Cleanup()

func (*Persistance) JWTState_Add

func (per *Persistance) JWTState_Add(claims *Claims)

func (*Persistance) JWTState_Cleanup

func (per *Persistance) JWTState_Cleanup()

func (*Persistance) JWTState_Del

func (per *Persistance) JWTState_Del(Id string)

func (*Persistance) New

func (per *Persistance) New() *Persistance

func (*Persistance) Pull_ip

func (per *Persistance) Pull_ip(ip string) *IP_Result

Internal getResult

func (*Persistance) Read

func (per *Persistance) Read() bool

func (*Persistance) UserLimiter_Cleanup

func (per *Persistance) UserLimiter_Cleanup()

func (*Persistance) UserrateLimiter_Get

func (per *Persistance) UserrateLimiter_Get(ip string) *Userlimiter

func (*Persistance) Write

func (per *Persistance) Write()

type TLSCert

type TLSCert struct {
	Subject string `json:"subject"`

	Provider string   `json:"provider"`
	Domain   []string `json:"domain"`
	IP       []net.IP `json:"ip"`

	CRT    []byte    `json:"crt"`
	KEY    []byte    `json:"key"`
	Serial int64     `json:"serial"`
	Iss    time.Time `json:"iss"`
	Exp    time.Time `json:"exp"`

	Tls *tls.Certificate `json:"-"`
}

func GetCert

func GetCert(subject string) *TLSCert

LOCKS TLSCert | Loads or generates key, requires Subject

func (*TLSCert) Generate

func (tlscrt *TLSCert) Generate() error

Expects LOCKED TLSCert | Sets CRT, KEY, Serial, Iss, Exp; requires Domain, IP

type Userlimiter

type Userlimiter struct {
	RateLimiter *ratelimit.Bucket
	LastSeen    time.Time
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL