Portions created by the Initial Developer are Copyright (C) 2008-2024 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane Luis Daniel Lucio Quiroz */ //includes files require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (permission_exists('dialplan_edit')) { //access granted } else { echo "access denied"; exit; } //get the uuids if (!empty($_REQUEST['id']) && is_uuid($_REQUEST['id'])) { $dialplan_uuid = $_REQUEST['id']; } if (!empty($_REQUEST['app_uuid']) && is_uuid($_REQUEST['app_uuid'])) { $app_uuid = $_REQUEST['app_uuid']; } $dialplan_xml = $_REQUEST['dialplan_xml'] ?? ''; //process the HTTP POST if (count($_POST) > 0 && empty($_POST["persistformvar"])) { //validate the token $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'],'negative'); header('Location: dialplans.php'); exit; } //get the dialplan xml if (is_uuid($dialplan_uuid)) { $sql = "select * from v_dialplans "; $sql .= "where dialplan_uuid = :dialplan_uuid "; $parameters['dialplan_uuid'] = $dialplan_uuid; $database = new database; $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && @sizeof($row) != 0) { $app_uuid = $row["app_uuid"]; $dialplan_context = $row["dialplan_context"]; } unset($sql, $parameters, $row); } //validate the xml $dialplan_valid = true; if (preg_match("/.*([\"\'])system([\"\']).*>/i", $dialplan_xml)) { $dialplan_valid = false; } if (preg_match("/.*([\"\'])bgsystem([\"\']).*>/i", $dialplan_xml)) { $dialplan_valid = false; } if (preg_match("/.*([\"\'])bg_spawn([\"\']).*>/i", $dialplan_xml)) { $dialplan_valid = false; } if (preg_match("/.*([\"\'])spawn([\"\']).*>/i", $dialplan_xml)) { $dialplan_valid = false; } if (preg_match("/.*([\"\'])spawn_stream([\"\']).*>/i", $dialplan_xml)) { $dialplan_valid = false; } if (preg_match("/.*{system.*/i", $dialplan_xml)) { $dialplan_valid = false; } if (preg_match("/.*{bgsystem.*/i", $dialplan_xml)) { $dialplan_valid = false; } if (preg_match("/.*{bg_spawn.*/i", $dialplan_xml)) { $dialplan_valid = false; } if (preg_match("/.*{spawn.*/i", $dialplan_xml)) { $dialplan_valid = false; } if (preg_match("/.*{spawn_stream.*/i", $dialplan_xml)) { $dialplan_valid = false; } //disable xml entities and load the xml object to test if the xml is valid if (PHP_VERSION_ID < 80000) { libxml_disable_entity_loader(true); } preg_match_all('/^\s*(?:[\S\s])+<\/extension>\s*$/mU', $dialplan_xml, $matches); foreach($matches as $match) { $xml = simplexml_load_string($match[0], 'SimpleXMLElement', LIBXML_NOCDATA); if (!$xml) { //$errors = libxml_get_errors(); $dialplan_valid = false; break; } } //save the xml to the database if ($dialplan_valid) { //build the dialplan array $x = 0; //$array['dialplans'][$x]["domain_uuid"] = $_SESSION['domain_uuid']; $array['dialplans'][$x]["dialplan_uuid"] = $dialplan_uuid; $array['dialplans'][$x]["dialplan_xml"] = $dialplan_xml; //save to the data $database = new database; $database->app_name = 'dialplans'; $database->app_uuid = is_uuid($app_uuid) ? $app_uuid : '742714e5-8cdf-32fd-462c-cbe7e3d655db'; $database->save($array); unset($array); //clear the cache $cache = new cache; if ($dialplan_context == "\${domain_name}" or $dialplan_context == "global") { $dialplan_context = "*"; } $cache->delete("dialplan:".$dialplan_context); //save the message to a session variable message::add($text['message-update']); } else { //save the message to a session variable message::add($text['message-failed'], 'negative'); } //redirect the user header("Location: dialplan_edit.php?id=".$dialplan_uuid.(is_uuid($app_uuid) ? "&app_uuid=".$app_uuid : null)); exit; } //get the dialplan xml if (is_uuid($dialplan_uuid)) { $sql = "select * from v_dialplans "; $sql .= "where dialplan_uuid = :dialplan_uuid "; $parameters['dialplan_uuid'] = $dialplan_uuid; $database = new database; $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && @sizeof($row) != 0) { $domain_uuid = $row["domain_uuid"]; $dialplan_name = $row["dialplan_name"]; $dialplan_number = $row["dialplan_number"]; $dialplan_order = $row["dialplan_order"]; $dialplan_continue = $row["dialplan_continue"]; $dialplan_context = $row["dialplan_context"]; $dialplan_xml = $row["dialplan_xml"]; $dialplan_enabled = $row["dialplan_enabled"]; $dialplan_description = $row["dialplan_description"]; } unset($sql, $parameters, $row); } //add multi-lingual support $language = new text; $text = $language->get(); // load editor preferences/defaults $setting_size = !empty($_SESSION["editor"]["font_size"]["text"]) ? $_SESSION["editor"]["font_size"]["text"] : '12px'; $setting_theme = !empty($_SESSION["editor"]["theme"]["text"]) ? $_SESSION["editor"]["theme"]["text"] : 'cobalt'; $setting_invisibles = isset($_SESSION['editor']['invisibles']['text']) ? $_SESSION['editor']['invisibles']["text"] : 'false'; $setting_indenting = isset($_SESSION['editor']['indent_guides']['text']) ? $_SESSION['editor']['indent_guides']["text"]: 'false'; $setting_numbering = isset($_SESSION['editor']['line_numbers']['text']) ? $_SESSION['editor']['line_numbers']["text"] : 'true'; //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); //show the header $document['title'] = $text['title-dialplan_edit'].' XML'; require_once "resources/header.php"; //scripts and styles echo "\n"; echo "\n"; //show the content echo "
\n"; echo "
\n"; echo "
".$text['title-dialplan_edit']." XML
\n"; echo "
\n"; echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','link'=>'dialplan_edit.php?id='.urlencode($dialplan_uuid).(!empty($app_uuid) && is_uuid($app_uuid) ? "&app_uuid=".urlencode($app_uuid) : null)]); echo button::create(['type'=>'button','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','style'=>'margin-left: 15px;','onclick'=>"set_value(); $('#frm').submit();"]); echo "
\n"; echo "
\n"; echo "
\n"; echo $text['description-dialplan-edit']."\n"; echo "
\n"; echo "
\n"; echo " "; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " \n"; echo " \n"; $themes['Light']['chrome']= 'Chrome'; $themes['Light']['clouds']= 'Clouds'; $themes['Light']['crimson_editor']= 'Crimson Editor'; $themes['Light']['dawn']= 'Dawn'; $themes['Light']['dreamweaver']= 'Dreamweaver'; $themes['Light']['eclipse']= 'Eclipse'; $themes['Light']['github']= 'GitHub'; $themes['Light']['iplastic']= 'IPlastic'; $themes['Light']['solarized_light']= 'Solarized Light'; $themes['Light']['textmate']= 'TextMate'; $themes['Light']['tomorrow']= 'Tomorrow'; $themes['Light']['xcode']= 'XCode'; $themes['Light']['kuroir']= 'Kuroir'; $themes['Light']['katzenmilch']= 'KatzenMilch'; $themes['Light']['sqlserver']= 'SQL Server'; $themes['Dark']['ambiance']= 'Ambiance'; $themes['Dark']['chaos']= 'Chaos'; $themes['Dark']['clouds_midnight']= 'Clouds Midnight'; $themes['Dark']['cobalt']= 'Cobalt'; $themes['Dark']['idle_fingers']= 'idle Fingers'; $themes['Dark']['kr_theme']= 'krTheme'; $themes['Dark']['merbivore']= 'Merbivore'; $themes['Dark']['merbivore_soft']= 'Merbivore Soft'; $themes['Dark']['mono_industrial']= 'Mono Industrial'; $themes['Dark']['monokai']= 'Monokai'; $themes['Dark']['pastel_on_dark']= 'Pastel on dark'; $themes['Dark']['solarized_dark']= 'Solarized Dark'; $themes['Dark']['terminal']= 'Terminal'; $themes['Dark']['tomorrow_night']= 'Tomorrow Night'; $themes['Dark']['tomorrow_night_blue']= 'Tomorrow Night Blue'; $themes['Dark']['tomorrow_night_bright']= 'Tomorrow Night Bright'; $themes['Dark']['tomorrow_night_eighties']= 'Tomorrow Night 80s'; $themes['Dark']['twilight']= 'Twilight'; $themes['Dark']['vibrant_ink']= 'Vibrant Ink'; echo " \n"; echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; echo "\n"; echo "\n"; //show the footer require_once "resources/footer.php"; ?>