helper

package
v0.0.0-...-0bc30a8 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FingerprintValidator validator.Func = func(fieldLevel validator.FieldLevel) bool {
	if field, ok := fieldLevel.Field().Interface().(string); ok {
		if field == "" {
			return true
		}

		_, err := base64.RawURLEncoding.DecodeString(strings.TrimLeft(field, "SHA256:"))
		return err == nil && strings.HasPrefix(field, "SHA256:")
	}
	return false
}
View Source
var FlagLowerUp = net.Flags(1 << 16)

see https://github.com/torvalds/linux/blob/master/include/uapi/linux/if.h#L103

View Source
var IpValidator validator.Func = func(fieldLevel validator.FieldLevel) bool {
	if parent, ok := fieldLevel.Parent().Interface().(model.Network); ok {
		if parent.Client {

			return true
		}
	}
	if field, ok := fieldLevel.Field().Interface().(*types.IP); ok {
		return len(field.Raw) > 0
	}
	return false
}
View Source
var IpnetValidator validator.Func = func(fieldLevel validator.FieldLevel) bool {
	if parent, ok := fieldLevel.Parent().Interface().(model.Network); ok {
		if parent.Client {

			return true
		}
	}
	if field, ok := fieldLevel.Field().Interface().(*types.IPNet); ok {
		return len(field.Raw.IP) > 0 && len(field.Raw.Mask) > 0
	}
	return false
}
View Source
var IporcidrValidator validator.Func = func(fieldLevel validator.FieldLevel) bool {
	if field, ok := fieldLevel.Field().Interface().([]string); ok {
		for _, entry := range field {
			ip := net.ParseIP(entry)
			_, _, errCIDR := net.ParseCIDR(entry)
			if errCIDR != nil && ip == nil {
				return false
			}
		}
	}
	return true
}
View Source
var PrivateKeyValidator validator.Func = func(fieldLevel validator.FieldLevel) bool {
	if field, ok := fieldLevel.Field().Interface().(string); ok {
		if field == "" {

			return true
		}

		privateKey, err := ParseRSAPrivateKey([]byte(field))
		return privateKey != nil && err == nil
	}
	return false
}
View Source
var PublicKeyValidator validator.Func = func(fieldLevel validator.FieldLevel) bool {
	if field, ok := fieldLevel.Field().Interface().(string); ok {
		if field == "" {
			return true
		}

		publicKey, err := ParseRSAPublicKey([]byte(field))
		return publicKey != nil && err == nil
	}
	return false
}

Functions

func CacheDelete

func CacheDelete(key string)

func CacheReplace

func CacheReplace(key string, value interface{}, duration time.Duration) error

func CacheSet

func CacheSet(key string, value interface{}, duration time.Duration)

func CurrentUser

func CurrentUser(ctx *gin.Context) (*model.User, error)

func DefaultLikelihood

func DefaultLikelihood(ipid, intervalFrom, intervalTo uint, unit string) *regression.Regression

defaultLikelihood will generate an R^2 for the specified IP address against all known network profiles including the specified IP address

The interval and unit variables delimiting the data as following: * expected between from and to (unit e.g. days) * observed between from and now() (unit e.g days)

If intervalTo is smaller then one it will use all known data

func HandlerJsonError

func HandlerJsonError(msg string, err error, ctx *gin.Context)

HandlerJsonError is a generic way of printing and returning JSON error messages via the frontend

func Likelihood

func Likelihood(ipid, intervalFrom, intervalTo uint, unit string) *regression.Regression

likelihood will generate an R^2 for the specified IP address against traffic found for the specified IP address

The interval and unit variables delimiting the data as following: * expected between from and to (unit e.g. days) * observed between from and now() (unit e.g days)

If intervalTo is smaller then one it will use all known data

func Logger

func Logger(customLogger zerolog.Logger)

func ParseRSAPrivateKey

func ParseRSAPrivateKey(decodedKey []byte) (*rsa.PrivateKey, error)

ParseRSAPublicKey transforms a serialized private key into a rsa.PrivateKey

func ParseRSAPublicKey

func ParseRSAPublicKey(decodedKey []byte) (*rsa.PublicKey, error)

ParseRSAPublicKey transforms a serialized public key into a rsa.PublicKey

func PreparePortalWebRequest

func PreparePortalWebRequest(path string, body io.Reader) (*http.Request, error)

PreparePortalWebRequest sets the portal endpoint and generates the signed header

func RandomMac

func RandomMac(unicast bool) (string, error)

func RawFlagsByInterface

func RawFlagsByInterface(intf *net.Interface) (net.Flags, error)

RawFlagsByInterface returns the raw interface flags since linkFlags in https://golang.org/src/net/interface_linux.go returns only a couple of supported flags. This could change in future (see https://github.com/golang/go/issues/42488). In our case we want to detect LOWER_UP (1<<16).

XXX This function only supports linux distributions!!

func ScanWifiNetworks

func ScanWifiNetworks(intfName string) (ssid map[string]float64, err error)

func Token

func Token() (string, error)

Token returns a random 16 byte long UUID e.g. c3905f37-5217-5c22-b511-d5bc074f2d6a

Types

This section is empty.

Jump to

Keyboard shortcuts

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