From 1f0c30529bc3cc283ef8cc702445fb027f33d98f Mon Sep 17 00:00:00 2001 From: markjcrane Date: Fri, 14 Jul 2023 20:44:40 -0600 Subject: [PATCH] Add dialplan condition regex --- app/dialplans/resources/classes/dialplan.php | 46 +++++++++++++++----- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/app/dialplans/resources/classes/dialplan.php b/app/dialplans/resources/classes/dialplan.php index 294c8f4cf7..1d698924d1 100644 --- a/app/dialplans/resources/classes/dialplan.php +++ b/app/dialplans/resources/classes/dialplan.php @@ -681,7 +681,8 @@ $sql .= "p.dialplan_uuid asc, \n"; $sql .= "s.dialplan_detail_group asc, \n"; $sql .= "case s.dialplan_detail_tag \n"; - $sql .= "when 'condition' then 1 \n"; + $sql .= "when 'condition' then 0 \n"; + $sql .= "when 'regex' then 1 \n"; $sql .= "when 'action' then 2 \n"; $sql .= "when 'anti-action' then 3 \n"; $sql .= "else 100 end, \n"; @@ -739,7 +740,12 @@ $condition_attribute = ""; $condition_tag_status = "closed"; } - else if ($condition && (!empty($condition))) { + else if (!empty($condition) && substr($condition, -1) == ">") { + $xml .= " ".$condition; + $condition = ""; + $condition_tag_status = "closed"; + } + else if (!empty($condition)) { $xml .= " ".$condition . "/>"; $condition = ""; $condition_tag_status = "closed"; @@ -771,7 +777,7 @@ $condition = ""; $condition_attribute = ""; } - if ($dialplan_detail_tag == "condition") { + if (isset($dialplan_detail_tag) && $dialplan_detail_tag == "condition" || $dialplan_detail_tag == "regex") { //determine the type of condition if ($dialplan_detail_type == "hour") { $condition_type = 'time'; @@ -813,9 +819,14 @@ $condition_type = 'default'; } - // finalize any previous pending condition statements + //finalize any previous pending condition statements if ($condition_tag_status == "open") { - if (!empty($condition)) { + if (!empty($condition) && substr($condition, -1) == ">") { + $xml .= $condition . "\n"; + $condition = ''; + $condition_tag_status = "closed"; + } + else if (!empty($condition)) { $xml .= $condition . "/>\n"; $condition = ''; $condition_tag_status = "closed"; @@ -846,7 +857,15 @@ //condition tag but leave off the ending if ($condition_type == "default") { - $condition = " "; + } + elseif (isset($dialplan_detail_type) && $dialplan_detail_tag == 'regex') { + $condition = " "; + } + else { + $condition = " \n"; $condition_attribute = ""; } - else if ($condition && (!empty($condition))) { + else if (!empty($condition) && !empty($condition_tag_status) && substr($condition, -1) == ">") { + $xml .= $condition . "\n"; + $condition = ""; + } + else if (!empty($condition) && !empty($condition_tag_status)) { $xml .= $condition . ">\n"; $condition = ""; } @@ -924,7 +947,7 @@ } unset($row); - // prevent partial dialplan (pass=nil may be error in sql or empty resultset) + //prevent partial dialplan (pass=nil may be error in sql or empty resultset) if (isset($pass) && $pass == false) { if (!empty($results)) { echo 'error while build context: ' . $this->context; @@ -934,10 +957,13 @@ //close the extension tag if it was left open if ($dialplan_tag_status == "open") { if ($condition_tag_status == "open") { - if ($condition_attribute and (!empty($condition_attribute))) { + if ($condition_attribute && (!empty($condition_attribute))) { $xml .= " \n"; } - else if ($condition && (!empty($condition))) { + else if (!empty($condition) && substr($string, -1) == ">") { + $xml .= $condition . "\n"; + } + else if (!empty($condition)) { $xml .= $condition . "/>\n"; } else {