Fortinet white logo
Fortinet white logo

Administration Guide

Lua Scripting

Lua Scripting

You can now use FortiAI to generate, explain, and troubleshoot custom Lua scripts using natural language instructions.

FortiAI introduces deep integration with the FortiWeb Lua scripting framework to reduce the complexity of maintaining and customizing security policies. The AI Assistant provides context-aware support for the script lifecycle directly within the management interface. This enhancement bridges the development skill gap by allowing security professionals to implement sophisticated custom logic without requiring extensive programming expertise.

Key Capabilities

  • Natural Language Script Generation: You can describe security requirements using natural language to generate tailored Lua scripts that follow FortiWeb requirements.

  • Intelligent Code Explanation: FortiAI provides a comprehensive breakdown of script logic, including the purpose of specific FortiWeb API calls and general data flow.

  • Interactive Script Troubleshooting: You can provide script snippets and error details to the AI Assistant to receive a root cause analysis and a corrected version of the code.

  • Contextual UI Integration: New Explain with AI action is integrated into the script management pages to provide immediate analysis of FortiWeb's predefined scripts.

The following examples demonstrate how FortiAI assists with common scripting tasks to accelerate deployment and simplify policy maintenance.

Example 1: Generating a New Custom Script

If you need a script to perform a specific action not covered by predefined signatures, you can ask the AI to draft it.

Prompt: Generate a Lua script to redirect all HTTP traffic to HTTPS while preserving the original URI.

Result: FortiAI generates the validated Lua code and provides an explanation of the implementation logic. You can then copy the generated script from the chat interface and paste it into the script editor manually.

Example 2: Explaining Legacy or Complex Scripts

You can use the AI to understand scripts created by previous administrators or third-party vendors.

Prompt: Explain what this script segment does: if not HTTP:is_https() then HTTP:redirect(...) end.

Result: FortiAI identifies the logic as a protocol check and redirection, highlighting the specific FortiWeb API calls used.

Example 3: Troubleshooting Script Execution Errors

When a custom script fails in production, you can use the AI to diagnose the failure.

Prompt: My script is throwing an error. Here is the code and the log message:

Code: HTTP:redirect("https://" .. HTTP:host() .. HTTP:url())Log: [error] lua entry thread aborted: runtime error: attempt to call method 'host' (a nil value)

Result: The AI Assistant analyzes the code and log data to identify the root cause, such as using an incorrect API syntax for the current context, and then generates a repaired version of the script.

Lua Scripting

Lua Scripting

You can now use FortiAI to generate, explain, and troubleshoot custom Lua scripts using natural language instructions.

FortiAI introduces deep integration with the FortiWeb Lua scripting framework to reduce the complexity of maintaining and customizing security policies. The AI Assistant provides context-aware support for the script lifecycle directly within the management interface. This enhancement bridges the development skill gap by allowing security professionals to implement sophisticated custom logic without requiring extensive programming expertise.

Key Capabilities

  • Natural Language Script Generation: You can describe security requirements using natural language to generate tailored Lua scripts that follow FortiWeb requirements.

  • Intelligent Code Explanation: FortiAI provides a comprehensive breakdown of script logic, including the purpose of specific FortiWeb API calls and general data flow.

  • Interactive Script Troubleshooting: You can provide script snippets and error details to the AI Assistant to receive a root cause analysis and a corrected version of the code.

  • Contextual UI Integration: New Explain with AI action is integrated into the script management pages to provide immediate analysis of FortiWeb's predefined scripts.

The following examples demonstrate how FortiAI assists with common scripting tasks to accelerate deployment and simplify policy maintenance.

Example 1: Generating a New Custom Script

If you need a script to perform a specific action not covered by predefined signatures, you can ask the AI to draft it.

Prompt: Generate a Lua script to redirect all HTTP traffic to HTTPS while preserving the original URI.

Result: FortiAI generates the validated Lua code and provides an explanation of the implementation logic. You can then copy the generated script from the chat interface and paste it into the script editor manually.

Example 2: Explaining Legacy or Complex Scripts

You can use the AI to understand scripts created by previous administrators or third-party vendors.

Prompt: Explain what this script segment does: if not HTTP:is_https() then HTTP:redirect(...) end.

Result: FortiAI identifies the logic as a protocol check and redirection, highlighting the specific FortiWeb API calls used.

Example 3: Troubleshooting Script Execution Errors

When a custom script fails in production, you can use the AI to diagnose the failure.

Prompt: My script is throwing an error. Here is the code and the log message:

Code: HTTP:redirect("https://" .. HTTP:host() .. HTTP:url())Log: [error] lua entry thread aborted: runtime error: attempt to call method 'host' (a nil value)

Result: The AI Assistant analyzes the code and log data to identify the root cause, such as using an incorrect API syntax for the current context, and then generates a repaired version of the script.