Portions created by the Initial Developer are Copyright (C) 2008-2024 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //set a timeout set_time_limit(15*60); //15 minutes //includes files require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once "resources/check_auth.php"; //check the permission if ( !permission_exists('upgrade_source') && !permission_exists('upgrade_schema') && !permission_exists('upgrade_apps') && !permission_exists('menu_restore') && !permission_exists('group_edit') ) { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //set a default message_timeout $message_timeout = 4*1000; //process the http post if (!empty($_POST) && @sizeof($_POST) > 0) { //get the action options: source, schema, app_defaults, menu_defaults, permisisons $action = $_POST['action']; //run source update if (!empty($action["upgrade_source"]) && permission_exists("upgrade_source") && !is_dir("/usr/share/examples/fusionpbx")) { $project_update_status = git_pull($_SERVER["PROJECT_ROOT"]); $_SESSION["response"]["upgrade_source"] = $project_update_status['message']; if (!empty($project_update_status['result'])) { message::add($text['message-upgrade_source'], null, $message_timeout); } else { message::add($text['message-upgrade_source_failed'], 'negative', $message_timeout); } } //run optional app source updates if (!empty($action["optional_apps"]) && permission_exists("upgrade_source")) { $updateable_repos = git_find_repos($_SERVER["PROJECT_ROOT"]."/app"); $apps_updated = $apps_failed = 0; if (is_array($action["optional_apps"])) { foreach ($updateable_repos as $repo => $apps) { if (array_search(basename($repo), $action["optional_apps"]) !== false) { $git_result = git_pull($repo); if ($git_result['result']) { $_SESSION["response"]["optional_apps"][basename($repo)] = $git_result['message']; $apps_updated++; } else { $apps_failed++; } } } } if ($apps_updated != 0) { message::add($text['message-optional_apps_upgrade_source'], null, $message_timeout); } if ($apps_failed != 0) { message::add($text['message-optional_apps_upgrade_source_failed'], 'negative', $message_timeout); } } //load an array of the database schema and compare it with the active database if (!empty($action["upgrade_schema"]) && permission_exists("upgrade_schema")) { require_once "resources/classes/schema.php"; $obj = new schema(); if (isset($action["data_types"]) && $action["data_types"] == 'true') { $obj->data_types = true; } $_SESSION["response"]["schema"] = $obj->schema("html"); message::add($text['message-upgrade_schema'], null, $message_timeout); } //process the apps defaults if (!empty($action["app_defaults"]) && permission_exists("upgrade_apps")) { require_once "resources/classes/domains.php"; $domain = new domains; $domain->upgrade(); message::add($text['message-upgrade_apps'], null, $message_timeout); } //restore defaults of the selected menu if (!empty($action["menu_defaults"]) && permission_exists("menu_restore")) { $sel_menu = explode('|', check_str($_POST["sel_menu"])); $menu_uuid = $sel_menu[0]; $menu_language = $sel_menu[1]; $included = true; require_once("core/menu/menu_restore_default.php"); unset($sel_menu); message::add($text['message-upgrade_menu'], null, $message_timeout); } //restore default permissions if (!empty($action["permission_defaults"]) && permission_exists("group_edit")) { $included = true; require_once("core/groups/permissions_default.php"); message::add($text['message-upgrade_permissions'], null, $message_timeout); } //redirect the browser header("Location: ".PROJECT_PATH."/core/upgrade/index.php"); exit; } //find optional apps with repos $updateable_repos = git_find_repos($_SERVER["PROJECT_ROOT"]."/app"); if (!empty($updateable_repos) && is_array($updateable_repos) && @sizeof($updateable_repos) != 0) { foreach ($updateable_repos as $app_path => $repo) { $x = 0; include $app_path.'/app_config.php'; $updateable_repos[$app_path]['app'] = $repo[0]; $updateable_repos[$app_path]['name'] = $apps[$x]['name']; $updateable_repos[$app_path]['uuid'] = $apps[$x]['uuid']; $updateable_repos[$app_path]['version'] = $apps[$x]['version']; $updateable_repos[$app_path]['description'] = $apps[$x]['description'][$_SESSION['domain']['language']['code']]; unset($apps, $updateable_repos[$app_path][0]); } } //count upgradeable repos including + main repo $repos_count = 0; if (is_array($updateable_repos)) { $repos_count = @sizeof($updateable_repos); } $repos_count++; //adjust color and initialize step counter $step = 1; $step_color = isset($_SESSION['theme']['upgrade_step_color']['text']) ? $_SESSION['theme']['upgrade_step_color']['text'] : color_adjust((!empty($_SESSION['theme']['form_table_label_background_color']['text']) ? $_SESSION['theme']['form_table_label_background_color']['text'] : '#e5e9f0'), -0.1); $step_container_style = "width: 30px; height: 30px; border: 2px solid ".$step_color."; border-radius: 50%; float: left; text-align: center; vertical-align: middle;"; $step_number_style = "font-size: 150%; font-weight: 600; color: ".$step_color.";"; //include the header and set the title $document['title'] = $text['title-upgrade']; require_once "resources/header.php"; //show the content echo "
\n"; echo "
\n"; echo "
".$text['header-upgrade']."
\n"; echo "
\n"; echo button::create(['type'=>'submit','label'=>$text['button-upgrade_execute'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','collapse'=>'never']); echo "
\n"; echo "
\n"; echo "
\n"; echo $text['description-upgrade']; echo "

"; if (permission_exists("upgrade_source") && !is_dir("/usr/share/examples/fusionpbx") && is_writeable($_SERVER["PROJECT_ROOT"]."/.git")) { echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "
\n"; echo "
".$step."
"; echo "
".$text['label-upgrade_source']."
\n"; echo "
\n"; echo "
\n"; echo " \n"; echo "
\n"; echo "
\n"; echo "   ".$text['description-update_all_source_files']." (".$repos_count.")\n"; echo "
\n"; echo "
\n"; echo "\n"; $step++; } if (permission_exists("upgrade_schema")) { echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "
\n"; echo "
".$step."
"; echo "
".$text['label-upgrade_schema']."
\n"; echo "
\n"; echo "  ".$text['description-upgrade_schema']."\n"; echo "
\n"; echo "\n"; $step++; } if (permission_exists("upgrade_apps")) { echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "
\n"; echo "
".$step."
"; echo "
".$text['label-upgrade_apps']."
\n"; echo "
\n"; echo "  ".$text['description-upgrade_apps']."\n"; echo "
\n"; $step++; } if (permission_exists("menu_restore")) { echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "
\n"; echo "
".$step."
"; echo "
".$text['label-upgrade_menu']."
\n"; echo "
\n"; echo ""; echo ""; echo "  ".$text['description-upgrade_menu']; echo "
\n"; $step++; } if (permission_exists("group_edit")) { echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "
\n"; echo "
".$step."
"; echo "
".$text['label-upgrade_permissions']."
\n"; echo "
\n"; echo "  ".$text['description-upgrade_permissions']."\n"; echo "
\n"; $step++; } echo "
\n"; echo "

"; if (!empty($_SESSION["response"]) && is_array($_SESSION["response"])) { foreach($_SESSION["response"] as $part => $response){ echo "".$text["label-results"]." - ".$text["label-${part}"]; echo "

"; if ($part == "optional_apps") { foreach ($response as $app_name => $app_response) { echo "".$app_name."
\n"; echo "
\n";
					foreach ($app_response as $response_line) {
						echo htmlspecialchars($response_line) . "\n";
					}
					echo "
\n"; } } elseif (is_array($response)) { echo "
";
				echo implode("\n", $response);
				echo "
"; } else { echo $response; } echo "

"; } unset($_SESSION["response"]); } //include the footer require_once "resources/footer.php"; ?>