utils

package
v0.0.0-...-221c3f5 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CertFilePermissions = 0644
	KeyFilePermissions  = 0600
	MinTLSVersion       = tls.VersionTLS12
	MaxTLSVersion       = tls.VersionTLS13
)

Variables

View Source
var (
	Logger *logger.Logger

	LogLevelMap = map[string]int{
		"debug":    100,
		"info":     200,
		"notice":   300,
		"warning":  400,
		"error":    500,
		"critical": 502,
		"alert":    509,
	}
)

Functions

func ArePortsReachable

func ArePortsReachable(ip string, ports ...string) error

func CheckIfServiceIsActive

func CheckIfServiceIsActive(serv string) (bool, error)

func CheckIfServiceIsInstalled

func CheckIfServiceIsInstalled(serv string) (bool, error)

func CreateLinuxService

func CreateLinuxService(serviceName string, execStart string) error

func DecryptAES

func DecryptAES(ciphertext, baseKey, uuid string) (string, error)

DecryptAES decrypts ciphertext using AES with a key derived from baseKey and uuid.

func DoReq

func DoReq[response any](url string, data []byte, method string, headers map[string]string, skipTlsVerification bool) (response, int, error)

func DownloadFile

func DownloadFile(url string, headers map[string]string, fileName string, path string, skipTlsVerification bool) error

func EncryptAES

func EncryptAES(plaintext, baseKey, uuid string) (string, error)

EncryptAES encrypts plaintext using AES with a key derived from baseKey and uuid.

func ExecuteWithResult

func ExecuteWithResult(c string, dir string, arg ...string) (string, bool)

func FindLatestLog

func FindLatestLog(path string, pattern *regexp.Regexp) (string, error)

func GenerateFromTemplate

func GenerateFromTemplate(data interface{}, templateFile string, configFile string) error

func GenerateKeyByUUID

func GenerateKeyByUUID(baseKey string, uuid string) ([]byte, error)

GenerateKeyByUUID generates an AES key from baseKey and uuid.

func GetHostAliases

func GetHostAliases(hostname string) ([]string, error)

func GetIPAddress

func GetIPAddress() (string, error)

func IncrementReconnectDelay

func IncrementReconnectDelay(delay time.Duration, maxReconnectDelay time.Duration) time.Duration

func InitLogger

func InitLogger(filename string)

func IsDirEmpty

func IsDirEmpty(path string) (bool, error)

func LoadGRPCTLSCredentials

func LoadGRPCTLSCredentials(crtName string) (credentials.TransportCredentials, error)

func LoadHTTPTLSCredentials

func LoadHTTPTLSCredentials(crtName string) (*tls.Config, error)

func LoadIntegrationTLSConfig

func LoadIntegrationTLSConfig(certPath, keyPath string) (*tls.Config, error)

func LoadUserCertificatesWithStruct

func LoadUserCertificatesWithStruct(src, dest CertificateFiles) error

func PrintBanner

func PrintBanner()

func ReadFileLines

func ReadFileLines(path string) ([]string, error)

func StartService

func StartService(name string) error

func StopService

func StopService(name string) error

func TailLogFile

func TailLogFile(filePath string, logLinesChan chan string, stopChan chan struct{})

func UninstallService

func UninstallService(name string) error

func Unzip

func Unzip(zipFile, destPath string) error

func ValidateIntegrationCertificates

func ValidateIntegrationCertificates(certPath, keyPath string) error

func WatchFolder

func WatchFolder(logType string, logsPath string, logLinesChan chan string)

func WriteStringToFile

func WriteStringToFile(fileName string, body string) error

Types

type CertificateFiles

type CertificateFiles struct {
	CertPath string
	KeyPath  string
	CAPath   string
}

type LogLevels

type LogLevels struct {
	Level string `yaml:"level"`
}

type OSInfo

type OSInfo struct {
	Hostname       string
	OsType         string
	Platform       string
	CurrentUser    string
	Mac            string
	OsMajorVersion string
	OsMinorVersion string
	Aliases        string
	Addresses      string
}

func GetOsInfo

func GetOsInfo() (OSInfo, error)

type TLSStatus

type TLSStatus struct {
	Available  bool   `json:"available"`
	CertExists bool   `json:"cert_exists"`
	KeyExists  bool   `json:"key_exists"`
	CAExists   bool   `json:"ca_exists"`
	Valid      bool   `json:"valid"`
	Error      string `json:"error,omitempty"`
}

Jump to

Keyboard shortcuts

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