util

package
v0.0.0-...-9d1dd97 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteSize

func ByteSize(bytes uint64) string

ByteSize formats a given number of bytes into a human-readable string representation. If the number is less than 1024, it will be displayed in bytes (e.g., "256B"). Otherwise, the number will be converted into a larger unit (e.g., 1.5KB, 20MB, etc.).

func CheckStrings

func CheckStrings(elements ...any) string

CheckStrings checks a list of strings and returns the first that is non-empty.

func ComparePasswords

func ComparePasswords(hashPassword string, plainPassword string) (bool, error)

ComparePasswords takes a plain password and creates a hash. Then it compares the hashed passwords and returns true, if bothe passwords are equal. If an error occurs, the result is false for the compare operation and the error is returned.

func DebugModule

func DebugModule(module global.DbgModule, keyvals ...any)

func GetHash

func GetHash(value string) string

GetHash creates an SHA-256 hash of a plain text password and returns the first 128 bits.

func GetProxyAddress

func GetProxyAddress(request *http.Request, clientIP string, clientPort string) (string, string)

func MapBytesToString

func MapBytesToString(data map[string]any)

MapBytesToString is a helper for MySQL databases that converts the values from a slice of bytes to strings.

func NewDNSResolver

func NewDNSResolver() (resolver *net.Resolver)

func NewRedisClient

func NewRedisClient() (redisHandle redis.UniversalClient)

NewRedisClient constructs a new Redis fail over client or a regular client depending on the configuration done in Config.

func NewRedisReplicaClient

func NewRedisReplicaClient() redis.UniversalClient

NewRedisReplicaClient constructs a new Redis slave server if Nauthilus is not configured to use Redis sentinels and if the configuration settings for RedisRO are different from the default Redis settings.

func PreparePassword

func PreparePassword(password string) string

func ProtoErrToFields

func ProtoErrToFields(err error) (fields []zap.Field)

func RemoveCRLFFromQueryOrFilter

func RemoveCRLFFromQueryOrFilter(value string, sep string) string

func ResolveIPAddress

func ResolveIPAddress(address string) (hostname string)

ResolveIPAddress returns the hostname for a given IP address.

func WithNotAvailable

func WithNotAvailable(elements ...any) string

WithNotAvailable checks a list of string. If none of the strings does have a content, we return the global.NotAvailable string.

Types

type CryptPassword

type CryptPassword struct {
	global.Algorithm
	global.PasswordOption
	Password string
	Salt     []byte
}

CryptPassword is a container for an encrypted password typically used in SQL fields.

func (*CryptPassword) Generate

func (c *CryptPassword) Generate(plainPassword string, salt []byte, alg global.Algorithm, pwOption global.PasswordOption) (
	string, error,
)

Generate creates the encrypted form of a plain text password.

func (*CryptPassword) GetParameters

func (c *CryptPassword) GetParameters(cryptedPassword string) (
	salt []byte, alg global.Algorithm, pwOption global.PasswordOption, err error,
)

GetParameters splits an encoded password into its components.

type MacroSource

type MacroSource struct {
	Username    string
	XLocalIP    string
	XPort       string
	ClientIP    string
	XClientPort string
	TOTPSecret  *string
	Protocol    config.Protocol
}

MacroSource holds all values that might be used in macros.

func (*MacroSource) ReplaceMacros

func (m *MacroSource) ReplaceMacros(source string) (dest string)

ReplaceMacros replaces several macros with values found in the Authentication object.

%Modifiers{long variables}

Modifiers: (Optional): L - Lower U - Upper

R - Reverse the string T - Trim the string

Long variavles: user - full username, i.e. localpart@domain.tld username - the local part of {user}, if user has a domain part, else user and username are the same domain - the domain part of {user}. Empty string, if {user} did not contain a domain part service - The service name, i.e. imap, pop3, lmtp local_ip - local IP address local_port - local port remote_ip - remote client IP address remote_port - remote client port.

type RedisLogger

type RedisLogger struct{}

RedisLogger implements the interface redis.Logging

func (*RedisLogger) Printf

func (r *RedisLogger) Printf(_ context.Context, format string, values ...any)

Printf implements the printf function from Redis.

Jump to

Keyboard shortcuts

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