Skip to content

Add FortiSase hook for endpoint configuration#351

Open
vmonnier wants to merge 3 commits intomasterfrom
VMR/REST_GENREIC/FortiSaseHook
Open

Add FortiSase hook for endpoint configuration#351
vmonnier wants to merge 3 commits intomasterfrom
VMR/REST_GENREIC/FortiSaseHook

Conversation

@vmonnier
Copy link
Copy Markdown
Contributor

@vmonnier vmonnier commented Apr 3, 2026

This pull request introduces a targeted customization to the eval_IMPORT function in rest_generic_command.php, specifically to support FortiSase integration. The main change is a conditional hook that modifies the structure of the configuration data when a certain post template marker is detected.

FortiSase-specific configuration handling:

  • Added a hook to detect if the post_template contains "ADD_ENDPOINT", and if so, wraps the configuration data in a new root element and adds an ENDPOINT field with the operation value. This enables specialized payload formatting for FortiSase integrations.

*To use by the own risk of the MS developer :)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a FortiSase-specific hook inside rest_generic_command::eval_IMPORT() to alter the IMPORT payload structure when the parser’s post_template contains an ADD_ENDPOINT marker.

Changes:

  • Detects ADD_ENDPOINT in post_template and injects an ENDPOINT field with the evaluated operation/URI.
  • Wraps the returned configuration in a new top-level ROOT element for FortiSase formatting.
  • Adds a debug dump of the (potentially modified) running configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +75 to +76
$running_conf["ENDPOINT"]=$op_eval;
$running_conf = array( "ROOT" => $running_conf );
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hook assumes $running_conf is an array and writes $running_conf["ENDPOINT"], but in REST generic $running_conf can be a SimpleXMLElement when REST_JSON is disabled (see adapters/rest_generic/rest_generic_connect.php: execute_curl_command() builds XML when rest_json is false). In that case this will fatally error ("Cannot use object of type SimpleXMLElement as array") and break IMPORT. Guard this logic with an is_array($running_conf)/$sms_sd_ctx->rest_json check, or add the ENDPOINT/root wrapper using SimpleXMLElement APIs for the XML path.

Suggested change
$running_conf["ENDPOINT"]=$op_eval;
$running_conf = array( "ROOT" => $running_conf );
if (is_array($running_conf)) {
$running_conf["ENDPOINT"] = $op_eval;
$running_conf = array("ROOT" => $running_conf);
} elseif ($running_conf instanceof SimpleXMLElement) {
$running_conf->addChild("ENDPOINT", $op_eval);
$root = new SimpleXMLElement('<ROOT/>');
$root_dom = dom_import_simplexml($root);
$running_conf_dom = dom_import_simplexml($running_conf);
$imported_dom = $root_dom->ownerDocument->importNode($running_conf_dom, true);
$root_dom->appendChild($imported_dom);
$running_conf = $root;
}

Copilot uses AI. Check for mistakes.
Comment thread adapters/rest_generic/rest_generic_command.php Outdated
Comment thread adapters/rest_generic/rest_generic_command.php Outdated
@Diyal976
Copy link
Copy Markdown
Contributor

Diyal976 commented Apr 3, 2026

Linked to cloudiamo/fortinet-ms#12

vmonnier and others added 2 commits April 7, 2026 08:37
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants