Documentation
¶
Index ¶
- func AddCustomLog(keyval *CustomLogKeyValue) lua.LGFunction
- func CheckBackendConnection(monitor monitoring.Monitor) lua.LGFunction
- func CompileLua(filePath string) (*lua.FunctionProto, error)
- func ContextDelete(ctx *Context) lua.LGFunction
- func ContextGet(ctx *Context) lua.LGFunction
- func ContextSet(ctx *Context) lua.LGFunction
- func DoCompiledFile(L *lua.LState, proto *lua.FunctionProto) error
- func GetAllHTTPRequestHeaders(httpRequest *http.Request) lua.LGFunction
- func GetHTTPRequestBody(httpRequest *http.Request) lua.LGFunction
- func GetHTTPRequestHeader(httpRequest *http.Request) lua.LGFunction
- func LoaderModContext(ctx *Context) lua.LGFunction
- func LoaderModHTTPRequest(httpRequest *http.Request) lua.LGFunction
- func LoaderModMisc(L *lua.LState) int
- func LoaderModPassword(L *lua.LState) int
- func LoaderModSoftWhitelist(L *lua.LState) int
- func PackagePath(L *lua.LState) error
- func RegisterBackendResultType(L *lua.LState, methods ...string)
- func RegisterCommonLuaLibraries(L *lua.LState, ctx context.Context, modName string, registry map[string]bool, ...)
- func SendMail(smtpClient smtp.Client) lua.LGFunction
- func SetStatusMessage(status **string) lua.LGFunction
- type CommonRequest
- type Context
- type CustomLogKeyValue
- type Done
- type LuaBackendResult
- type MailModule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddCustomLog ¶
func AddCustomLog(keyval *CustomLogKeyValue) lua.LGFunction
func CheckBackendConnection ¶
func CheckBackendConnection(monitor monitoring.Monitor) lua.LGFunction
CheckBackendConnection attempts to verify the connection to a backend server using the provided monitor. It extracts necessary configuration details such as protocol, IP address, port, and credentials from the given Lua table. The function then calls the monitor's CheckBackendConnection method to perform the actual connectivity check. If the connection check encounters an error, this error is pushed onto the Lua stack. If the connection check is successful, a nil value is pushed onto the Lua stack. It returns an integer indicating the number of results pushed onto the Lua stack.
func CompileLua ¶
func CompileLua(filePath string) (*lua.FunctionProto, error)
CompileLua reads the passed lua file from disk and compiles it.
func ContextDelete ¶
func ContextDelete(ctx *Context) lua.LGFunction
ContextDelete is a wrapper function to Context.Delete(...). The argument ctx provides the Lua context for the underlying Lua function.
func ContextGet ¶
func ContextGet(ctx *Context) lua.LGFunction
ContextGet is a wrapper function to Context.Get(...). The argument ctx provides the Lua context for the underlying Lua function.
func ContextSet ¶
func ContextSet(ctx *Context) lua.LGFunction
ContextSet is a wrapper function to Context.Set(...). The argument ctx provides the Lua context for the underlying Lua function.
func DoCompiledFile ¶
func DoCompiledFile(L *lua.LState, proto *lua.FunctionProto) error
DoCompiledFile takes a FunctionProto, as returned by CompileLua, and runs it in the LState. It is equivalent to calling DoFile on the LState with the original source file.
func GetAllHTTPRequestHeaders ¶
func GetAllHTTPRequestHeaders(httpRequest *http.Request) lua.LGFunction
GetAllHTTPRequestHeaders returns a LGFunction that creates a Lua table containing all headers from the http.Request object The table is indexed by the lowercase header name and each header's value is a list of strings The function expects a *http.Request object as its parameter
Example usage:
headers := getAllHeaders(request) L.SetGlobal("getAllHeaders", L.NewClosure(headers)) result := L.DoString(` local headers = getAllHeaders() print(headers["content-type"][1]) -- print the first value of the "content-type" header `) if result != nil { fmt.Println("Error:", result) }
func GetHTTPRequestBody ¶ added in v1.2.2
func GetHTTPRequestBody(httpRequest *http.Request) lua.LGFunction
GetHTTPRequestBody reads the HTTP request body and returns it as a Lua string. The function expects one parameter: the HTTP request object. It returns the request body as a Lua string. If an error occurs, it raises a Lua error with the error message and returns 0. The read request body is then assigned back to the request's body for the next handler.
func GetHTTPRequestHeader ¶ added in v1.1.0
func GetHTTPRequestHeader(httpRequest *http.Request) lua.LGFunction
GetHTTPRequestHeader returns a LGFunction that retrieves a specific header from the http.Request object The function expects a *http.Request object as its parameter and the name of the requested header as a string If the requested header exists, it creates a Lua table containing the header's value as a list of strings The table is indexed by the lowercase header name createHeaderTable is a helper function that creates a Lua table for a header value It takes an LState, an LTable, the header name, and a list of header values as parameters
func LoaderModContext ¶ added in v1.2.2
func LoaderModContext(ctx *Context) lua.LGFunction
func LoaderModHTTPRequest ¶ added in v1.2.2
func LoaderModHTTPRequest(httpRequest *http.Request) lua.LGFunction
LoaderModHTTPRequest is a function that returns a LGFunction which sets up a Lua module for handling HTTP requests. The module creates Lua functions that can be used to retrieve HTTP request headers and body.
Parameters: - httpRequest: A pointer to the http.Request object.
Returns: - A LGFunction that creates the Lua module and sets up the Lua functions.
func LoaderModMisc ¶ added in v1.2.1
LoaderModMisc initializes a new module for the "nauthilus_misc" module in Lua. It sets the functions from the "exportsModMisc" map into a new lua.LTable. The module table is then pushed onto the top of the stack. Finally, it returns 1 to indicate that one value has been returned to Lua.
func LoaderModPassword ¶ added in v1.2.1
LoaderModPassword takes a *lua.LState as input and initializes a new module by setting the functions from `exportsModPassword` into a new lua.LTable. The module table is then pushed onto the top of the stack. Finally, it returns 1 to indicate that one value has been returned to Lua.
func LoaderModSoftWhitelist ¶ added in v1.4.0
func LoaderModSoftWhitelist(L *lua.LState) int
LoaderModSoftWhitelist registers and exposes the soft whitelist module functions to the provided Lua state.
func PackagePath ¶
PackagePath sets the Lua package path to include the directory where the Lua modules reside. It appends the Lua package path with the value returned by `config.LoadableConfig.GetLuaPackagePath()`. This function takes a Lua state (`*lua.LState`) as an argument and returns an error.
func RegisterBackendResultType ¶ added in v1.2.2
func RegisterBackendResultType(L *lua.LState, methods ...string)
RegisterBackendResultType registers the Lua type "nauthilus_backend_result" in the given Lua state. It sets the type metatable with the given name and creates the necessary static attributes and methods.
func RegisterCommonLuaLibraries ¶ added in v1.2.3
func RegisterCommonLuaLibraries(L *lua.LState, ctx context.Context, modName string, registry map[string]bool, httpClient *stdhttp.Client)
RegisterCommonLuaLibraries registers common Lua libraries based on the modName value. The function takes an *lua.Lstate, modName string, and registry map[string]bool as input parameters. It uses a switch statement to compare modName with pre-defined constants to determine which library to register. For each matched modName, it calls the corresponding Preload function to register the library. After registering the library, it adds the modName to the registry map to keep track of registered libraries. If modName does not match any pre-defined constants, the function returns without registering any library.
Note: The implementation of Preload functions for each library is not shown in this documentation. Please refer to the individual module documentations for more details on each Preload function. Please also note that the declaration codes for the constants used in the switch cases are not shown here. Refer to the module documentations for the declaration codes of the constants.
func SendMail ¶ added in v1.1.0
SendMail sends an email using the provided Client implementation.
Parameters: - smtpClient: An implementation of the Client interface for sending emails.
Returns: - Returns a Lua LGFunction that accepts a Lua state and sends the email using the provided parameters. - If an error occurs during sending the email, a LuaString with the error message is pushed onto the Lua stack. - If the email is sent successfully, a LuaNil is pushed onto the Lua stack.
Example usage: ``` // Create a real SMTP client instance smtpClient := &lualib.EmailClient{}
// Create a Lua state L := lua.NewState()
// Register the SendMail function with the Lua state L.SetGlobal("SendMail", lualib.SendMail(smtpClient)) ```
Note: The Client interface is defined as follows: ```
type Client interface { SendMail(options *MailOptions) error }
```
func SetStatusMessage ¶
func SetStatusMessage(status **string) lua.LGFunction
Types ¶
type CommonRequest ¶
type CommonRequest struct { // Debug is a flag indicating if the action is executed in debug mode. Debug bool // Repeating is a flag indicating if the action would be repeated. Repeating bool // UserFound is a flag indicating if the user executing the action was found in the system. UserFound bool // Authenticated is a flag indicating if the user is authenticated. Authenticated bool // NoAuth is a flag indicating if the action requires no authentication. NoAuth bool // BruteForceCounter keeps track of unsuccessful login attempts for the user. BruteForceCounter uint // Service is the http routers endpoint name. Service string // Session stores the unique session identifier. Session string // GUID // ClientIP stores the IP address of the client. ClientIP string // ClientPort stores the port number used by the client. ClientPort string // ClientNet stores the network used by the client. ClientNet string // ClientHost stores the hostname of the client. ClientHost string // ClientID stores the unique identifier for the client. ClientID string // UserAgent stores toe User-Agent of the client. UserAgent string // LocalIP stores the IP address of the local machine. LocalIP string // LocalPort stores the port number used by the local machine. LocalPort string // Username stores the username of the user that was used to authenticate. Username string // Account stores the user's account information. Account string // AccountField stores the user's account field. AccountField string // UniqueUserID stores the unique user identifier. UniqueUserID string // DisplayName stores the user's display name. DisplayName string // Password stores the user's password. Password string // Protocol stores the protocol that the user used to authenticate. Protocol string // BruteForceName stores the name of the brute force protection mechanism. BruteForceName string // FeatureName is a feature that triggered the action. FeatureName string // StatusMessage is a configurable message that is returned to the client upon errors (not tempfail). StatusMessage *string // XSSL contains SSL information. XSSL string // XSSLSessionID is the SSL session identifier. XSSLSessionID string // XSSLClientVerify indicates whether SSL client is verified. XSSLClientVerify string // XSSLClientDN is the client's Distinguished Name in the SSL certificate. XSSLClientDN string // XSSLClientCN is the client's Common Name in the SSL certificate. XSSLClientCN string // XSSLIssuer is the issuer of the SSL certificate. XSSLIssuer string // XSSLClientNotBefore is the date before which the SSL certificate is not valid. XSSLClientNotBefore string // XSSLClientNotAfter is the date after which the SSL certificate is not valid. XSSLClientNotAfter string // XSSLSubjectDN is the Subject's Distinguished Name in the SSL certificate. XSSLSubjectDN string // XSSLIssuerDN is the Issuer's Distinguished Name in the SSL certificate. XSSLIssuerDN string // XSSLClientSubjectDN is the client's Subject Distinguished Name in the SSL certificate. XSSLClientSubjectDN string // XSSLClientIssuerDN is the client's Issuer Distinguished Name in the SSL certificate. XSSLClientIssuerDN string // XSSLProtocol is the SSL protocol used. XSSLProtocol string // XSSLCipher is the encryption cipher used in the SSL protocol. XSSLCipher string // SSLSerial is the serial number of the SSL certificate used for secure communication. SSLSerial string // SSLFingerprint represents the SSL certificate's fingerprint for the client in the request. SSLFingerprint string }
CommonRequest represents a common request object with various properties used in different functionalities.
func (*CommonRequest) SetupRequest ¶
func (c *CommonRequest) SetupRequest(request *lua.LTable) *lua.LTable
SetupRequest sets up the request object with the common request properties
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is a system-wide Lua context designed to exchange Lua LValues between all Lua levels. Even it implements all methodes from Context, its use is limitted to data exchange. It can not be used to abort running threads. Usage of this context is thread safe.
func (*Context) Get ¶
Get returns the lua.LValue value aquired by key from the Lua Context. If no key was found, it returns nil.
type CustomLogKeyValue ¶
type CustomLogKeyValue []any
func (*CustomLogKeyValue) Set ¶ added in v1.2.6
func (c *CustomLogKeyValue) Set(key string, value any)
Set appends a key-value pair to the CustomLogKeyValue slice. If the receiver pointer c is nil, no action is taken. The key is appended to the slice followed by the value.
type LuaBackendResult ¶
type LuaBackendResult struct { // Authenticated represents whether the user is authenticated or not Authenticated bool // UserFound indicates whether the user was found in the system or not UserFound bool // AccountField is the field associated with the user's account AccountField string // TOTPSecretField is the field that holds the user's TOTP Secret TOTPSecretField string // TOTPRecoveryField is the field for the user's TOTP recovery code TOTPRecoveryField string // UniqueUserIDField is the unique user id field UniqueUserIDField string // DisplayNameField is the display name associated with the user's account DisplayNameField string // Err captures any error that occurred during the backend process Err error // Attributes holds any other attributes related to the user's account Attributes map[any]any // Logs is a pointer to a custom log key-value pair associated with the Lua script. Logs *CustomLogKeyValue }
LuaBackendResult holds the response returned by the Lua backend. Information about user authentication, user account, and error details are encapsulated in this data structure.
type MailModule ¶ added in v1.3.0
type MailModule struct {
// contains filtered or unexported fields
}
MailModule provides functionalities for sending emails using an SMTP client.
func NewMailModule ¶ added in v1.3.0
func NewMailModule(smtpClient smtp.Client) *MailModule
NewMailModule creates a new MailModule instance with the provided smtp.Client.
func (*MailModule) Loader ¶ added in v1.3.0
func (m *MailModule) Loader(L *lua.LState) int
Loader registers the mail module and its functions in Lua state L. The module provides Lua bindings for sending emails using SMTP via the SendMail function. Returns the number of results pushed onto the Lua stack, which is always 1 in this method.