Documentation
¶
Index ¶
- Variables
- 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 LoaderModMail(L *lua.LState) int
- func LoaderModMisc(L *lua.LState) int
- func LoaderModPassword(L *lua.LState) int
- func PackagePath(L *lua.LState) error
- func RegisterBackendResultType(L *lua.LState, methods ...string)
- func RegisterLibraries(L *lua.LState)
- func SendMail(smtpClient smtp.Client) lua.LGFunction
- func SetStatusMessage(status **string) lua.LGFunction
- type CommonRequest
- type Context
- type CustomLogKeyValue
- type Done
- type LuaBackendResult
Constants ¶
This section is empty.
Variables ¶
var SmtpClient *smtp.EmailClient
SmtpClient represents an instance of the EmailClient struct, which is a real SMTP client used for sending emails. SmtpClient is a variable of type *smtp.EmailClient. The EmailClient struct has a SendMail method that sends an email using the provided MailOptions configuration. If the options parameter is nil, it returns an error; otherwise, it passes the non-nil options to the smtp.SendMail method and returns its result. The SendMail method of the EmailClient struct is used to send emails with the EmailClient instance and the SendMail method from the smtp package.
Functions ¶
func AddCustomLog ¶
func AddCustomLog(keyval *CustomLogKeyValue) lua.LGFunction
func CheckBackendConnection ¶
func CheckBackendConnection(monitor monitoring.Monitor) lua.LGFunction
CheckBackendConnection is a Lua function that checks the connection to a backend server. It receives the server IP address, port number, a boolean flag indicating whether the server runs with HAProxy V2 protocol, and a boolean flag indicating whether TLS should be used. The function calls the CheckBackendConnection method of the provided monitoring.Monitor instance and returns an error message if there is an error, or nil if the connection is successful.
Params:
- monitor monitoring.Monitor : The monitoring.Monitor instance used to check the backend connection.
Returns:
- int : The number of return values pushed to the Lua stack, always 1.
Lua stack requirements:
- 4 arguments are expected in the following order: 1. string : The server IP address. 2. int : The server port number. 3. boolean : Whether the server runs with HAProxy V2 protocol. 4. boolean : Whether TLS should be used.
- The arguments should be of the expected types; otherwise, an error will be raised.
- The function expects to have 1 return value on the stack - nil if the connection is successful, or a string with an error message if there is an error.
Example:
connection_error = check_backend_connection("192.168.0.1", 8080, false, true)
if connection_error ~= nil then
log("Connection failed: " .. connection_error)
else
log("Connection successful")
end
Note: The above example is in Lua language and should be executed in a Lua environment.
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 LoaderModMail ¶ added in v1.2.1
func LoaderModMail(L *lua.LState) int
LoaderModMail initializes a new module for the "nauthilus_mail" module in Lua. It sets the functions from the "exportsModMail" 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 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 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 RegisterLibraries ¶ added in v1.2.1
RegisterLibraries registers various libraries to the given LState. It preloads libraries, registers the backend result type, and preloads a module.
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
// 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
}
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
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.