Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions adapters/rest_generic/rest_generic_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ function eval_IMPORT() {
foreach ( $parser_list as $op_eval => $sub_parsers ) {

$running_conf = sendexpectone ( __FILE__ . ':' . __LINE__, $sms_sd_ctx, $op_eval, "" );

/**************** BEGIN Hook for FortiSase ***************************/
$post_import=(string)$sub_parsers[0]->post_template;
/* if the post template of the MS contains "ADD_ENDPOINT"
change the json to add a new root element, with a new ENDPOINT
element that contains not only the call endpoint/URI
*/
if ( strpos($post_import, "ADD_ENDPOINT") !== false ){
$running_conf["ENDPOINT"]=$op_eval;
$running_conf = array( "ROOT" => $running_conf );
Comment on lines +75 to +76
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.
}
/**************** END Hook for FortiSase ***************************/

foreach ( $sub_parsers as $parser ) {
$parser->parse ( $running_conf, $objects );
}
Expand Down
Loading