function fn_paypal_request($request, $post_url, $cert_file) { $extra = array('headers' => array('Connection: close'), 'ssl_cert' => $cert_file); $response = Http::post($post_url, $request, $extra); if (!empty($response)) { parse_str($response, $result); } else { $result['ERROR'] = Http::getError(); } return $result; }
/** * Prepares restore.php file. * * @return bool if all necessary information was added to restore.php */ protected function prepareRestore($package_id, $content_schema, $information_schema, $backup_filename) { $logger = Log::instance($package_id); $logger->add('Preparing restore script'); $upgrades_dir = $this->config['dir']['root'] . '/upgrades'; $source_restore_file_path = $upgrades_dir . '/source_restore.php'; $target_restore_dir_name = "{$package_id}_{$information_schema['from_version']}-{$information_schema['to_version']}"; $target_restore_file_name = 'restore_' . date('Y-m-d_H-i-s', TIME) . '.php'; $target_restore_dir_path = $upgrades_dir . "/{$target_restore_dir_name}/"; $target_restore_file_path = $target_restore_dir_path . $target_restore_file_name; $target_restore_http_path = Registry::get('config.http_location') . "/upgrades/{$target_restore_dir_name}/{$target_restore_file_name}"; $target_restore_dir_perms = 0755; $target_restore_file_perms = 0644; if (is_dir($upgrades_dir)) { $logger->add(sprintf('Upgrades directory permissions: %s', fn_get_file_perms_info($upgrades_dir))); } else { $logger->add(sprintf('Upgrades directory not found at "%s"', $upgrades_dir)); return false; } if (file_exists($source_restore_file_path)) { $logger->add(sprintf('Source restore script permissions: %s', fn_get_file_perms_info($source_restore_file_path))); if (!is_readable($source_restore_file_path)) { $logger->add('Source restore script is not readable'); return false; } } else { $logger->add(sprintf('Source restore script not found at "%s"', $source_restore_file_path)); return false; } if (fn_mkdir($target_restore_dir_path, $target_restore_dir_perms)) { $logger->add(array(sprintf('Created directory for restore script at "%s"', $target_restore_dir_path), sprintf('Directory permissions: %s', fn_get_file_perms_info($target_restore_dir_path)))); } else { $logger->add(sprintf('Unable to create directory for restore script at "%s"', $target_restore_dir_path)); return false; } $content = fn_get_contents($source_restore_file_path); $restore_key = md5(uniqid()) . md5(uniqid('', true)); $stats_data = $this->getStatsData($package_id); $restore_data = array('backup' => array('filename' => $backup_filename, 'created_at' => date('Y-m-d H:i:s', TIME), 'created_on_version' => PRODUCT_VERSION)); $content = str_replace(array("'%UC_SETTINGS%'", "'%CONFIG%'", "'%BACKUP_FILENAME%'", "'%RESTORE_KEY%'", "'%STATS_DATA%'", "'%RESTORE_DATA%'"), array(var_export($this->settings, true), var_export(Registry::get('config'), true), var_export($backup_filename, true), var_export($restore_key, true), var_export($stats_data, true), var_export($restore_data, true)), $content); if (fn_put_contents($target_restore_file_path, $content, '', $target_restore_file_perms)) { $logger->add(array(sprintf('Created restore script at "%s"', $target_restore_file_path), sprintf('Restore script permissions: %s', fn_get_file_perms_info($target_restore_file_path)))); } else { $logger->add(sprintf('Unable to create restore script at "%s"', $target_restore_file_path)); return false; } // Ensure that target restore script directory has correct permissions (0755) $logger->add('Correcting target restore script directory permissions...'); $this->chmod($target_restore_dir_path, $target_restore_dir_perms, $logger); $logger->add(sprintf('Target restore script directory permissions: %s', fn_get_file_perms_info($target_restore_dir_path))); // Restore validator could change permissions for upgrades directory to "0777" if it wasn't writable. // "0777" are not acceptable permissions for that directory because some servers restrict execution of // PHP scripts located at directory with "0777" permissions. $logger->add('Correcting upgrades directory permissions...'); $this->chmod($upgrades_dir, $target_restore_dir_perms, $logger); $logger->add(sprintf('Upgrades directory permissions: %s', fn_get_file_perms_info($upgrades_dir))); // Check if restore is available through the HTTP $logger->add('Checking restore script availability via HTTP'); $result = Http::get($target_restore_http_path); $http_error = Http::getError(); if (!empty($http_error)) { $logger->add(sprintf('HTTP error: %s', $http_error)); } if ($result != 'Access denied') { $logger->add(sprintf('Restore script is NOT available via HTTP at "%s".', $target_restore_http_path)); return false; } return array($restore_key, $target_restore_file_path, $target_restore_http_path); }