utomaticaly to help user * * @return array */ public static function quickFixCallback() { $json = array( 'success' => false, 'message' => '', ); $inputData = filter_input_array(INPUT_POST, array( 'id' => array( 'filter' => FILTER_SANITIZE_SPECIAL_CHARS, 'flags' => FILTER_REQUIRE_SCALAR, 'options' => array('default' => false), ), 'setup' => array( 'filter' => FILTER_SANITIZE_SPECIAL_CHARS, 'flags' => FILTER_REQUIRE_ARRAY, 'options' => array('default' => false), ), )); $setup = $inputData['setup']; $id = $inputData['id']; if (!$id || empty($setup)) { throw new Exception(__("Invalid request.", 'duplicator-pro')); } $data = array(); $isSpecial = isset($setup['special']) && is_array($setup['special']) && count($setup['special']) > 0; /* **************** * general setup * **************** */ if (isset($setup['global']) && is_array($setup['global'])) { $global = dup_pro_global_entity::getinstance(); foreach ($setup['global'] as $object => $value) { $value = dup_pro_u::valtype($value); if (isset($global->$object)) { // get current setup $current = $global->$object; // if setup is not the same - fix this if ($current !== $value) { // set new value $global->$object = $value; // check value $data[$object] = $global->$object; } } } $global->save(); } /* **************** * SPECIAL SETUP * **************** */ if ($isSpecial) { $special = $setup['special']; $stuck5percent = isset($special['stuck_5percent_pending_fix']) && $special['stuck_5percent_pending_fix'] == 1; $basicAuth = isset($special['set_basic_auth']) && $special['set_basic_auth'] == 1; $removeInstallerFiles = isset($special['remove_installer_files']) && $special['remove_installer_files'] == 1; /** * SPECIAL FIX: Package build stuck at 5% or Pending? * */ if ($stuck5percent) { $data = array_merge($data, self::quickFixStuck5Percent()); } /** * SPECIAL FIX: Set basic auth username & password * */ if ($basicAuth) { $data = array_merge($data, self::quickFixBasicAuth()); } /** * SPECIAL FIX: Remove installer files * */ if ($removeInstallerFiles) { $data = array_merge($data, self::quickFixRemoveInstallerFiles()); } } // Save new property $find = count($data); if ($find > 0) { $system_global = SystemGlobalEntity::getInstance(); if (strlen($id) > 0) { $system_global->removeFixById($id); $json['id'] = $id; } $json['success'] = true; $json['setup'] = $data; $json['fixed'] = $find; $json['recommended_fixes'] = count($system_global->recommended_fixes); } return $json; } /** * Quick fix for removing installer files * * @return array{removed_installer_files:bool} $data */ private static function quickFixRemoveInstallerFiles() { $data = array(); $fileRemoved = MigrationMng::cleanMigrationFiles(); $removeError = false; if (count($fileRemoved) > 0) { $data['removed_installer_files'] = true; } else { throw new Exception(esc_html__("Unable to remove installer files.", 'duplicator-pro')); } return $data; } /** * Quick fix for stuck at 5% or pending * * @return array $data */ private static function quickFixStuck5Percent() { $global = DUP_PRO_Global_Entity::getInstance(); $data = array(); $kickoff = true; $custom = false; if ($global->ajax_protocol === 'custom') { $custom = true; } // Do things if SSL is active if (SnapURL::isCurrentUrlSSL()) { if ($custom) { // Set default admin ajax $custom_ajax_url = admin_url('admin-ajax.php', 'https'); if ($global->custom_ajax_url != $custom_ajax_url) { $global->custom_ajax_url = $custom_ajax_url; $data['custom_ajax_url'] = $global->custom_ajax_url; $kickoff = false; } } else { // Set HTTPS protocol if ($global->ajax_protocol === 'http') { $global->ajax_protocol = 'https'; $data['ajax_protocol'] = $global->ajax_protocol; $kickoff = false; } } } else { // SSL is OFF and we must handle that if ($custom) { // Set default admin ajax $custom_ajax_url = admin_url('admin-ajax.php', 'http'); if ($global->custom_ajax_url != $custom_ajax_url) { $global->custom_ajax_url = $custom_ajax_url; $data['custom_ajax_url'] = $global->custom_ajax_url; $kickoff = false; } } else { // Set HTTP protocol if ($global->ajax_protocol === 'https') { $global->ajax_protocol = 'http'; $data['ajax_protocol'] = $global->ajax_protocol; $kickoff = false; } } } // Set KickOff true if all setups are gone if ($kickoff) { if ($global->clientside_kickoff !== true) { $global->clientside_kickoff = true; $data['clientside_kickoff'] = $global->clientside_kickoff; } } $global->save(); return $data; } /** * Quick fix for basic auth * * @return array{basic_auth_enabled:bool,basic_auth_user:string,basic_auth_password:string} */ private static function quickFixBasicAuth() { $global = DUP_PRO_Global_Entity::getInstance(); $sglobal = DUP_PRO_Secure_Global_Entity::getInstance(); $username = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : false; $password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : false; if ($username === false || $password === false) { throw new Exception(esc_html__("Username or password were not set.", 'duplicator-pro')); } $data = array(); $global->basic_auth_enabled = true; $data['basic_auth_enabled'] = true; $global->basic_auth_user = $username; $data['basic_auth_user'] = $username; $sglobal->basic_auth_password = $password; $data['basic_auth_password'] = "**Secure Info**"; $global->save(); $sglobal->save(); return $data; } }