input->get('no-verify', 999); $this->verifySSL = $noVerifyValue != 999; // Get the backup profile and description $profile = $this->input->get('profile', 1, 'int'); if ($profile <= 0) { $profile = 1; } $version = AKEEBA_VERSION; $date = AKEEBA_DATE; $quietMode = $this->input->get('quiet', -1, 'int'); if ($quietMode == -1) { $year = gmdate('Y'); echo <<getMessage() . "\n\n"; echo "Path to " . basename(__FILE__) . ":" . __DIR__ . "\n"; echo "Path to factory file: $factoryPath\n"; die("\n"); } } $startup_check = true; // Assign the correct platform Platform::addPlatform('joomla3x', JPATH_COMPONENT_ADMINISTRATOR . '/BackupPlatform/Joomla3x'); // Get the live site's URL $url = Platform::getInstance()->get_platform_configuration_option('siteurl', ''); if (empty($url)) { echo <<get_platform_configuration_option('akeebabackup', 'legacyapi_enabled'); $secret = Platform::getInstance()->get_platform_configuration_option('frontend_secret_word', ''); if (!$frontend_enabled) { echo <<input->get('method', '', 'cmd'); if (!empty($overridemethod)) { $method = $overridemethod; } if (empty($method)) { echo <<close(255); } echo <<fetchURL($url, $method); //echo "[{$timestamp}] Got $result\n"; if (empty($result) || ($result === false)) { echo "[{$timestamp}] No message received\n"; echo <<close(100); } elseif (strpos($result, '301 More work required') !== false) { // Extract the backup ID $backupId = null; $startPos = strpos($result, 'BACKUPID ###'); $endPos = false; if ($startPos !== false) { $endPos = strpos($result, '###', $startPos + 11); } if ($endPos !== false) { $backupId = substr($result, $startPos + 12, $endPos - $startPos - 12); } // Construct the new URL and access it if ($step == 0) { $prototypeURL = $url; } $step++; $url = $prototypeURL . '&task=step&step=' . $step; if (!is_null($backupId)) { $url .= '&backupid=' . urlencode($backupId); } echo "[{$timestamp}] Backup progress signal received\n"; } elseif (strpos($result, '200 OK') !== false) { echo "[{$timestamp}] Backup finalization message received\n"; echo <<close(0); } elseif (strpos($result, '500 ERROR -- ') !== false) { // Backup error echo "[{$timestamp}] Error signal received\n"; echo <<close(2); } elseif (strpos($result, '403 ') !== false) { // This should never happen: invalid authentication or front-end backup disabled echo "[{$timestamp}] Connection denied (403) message received\n"; echo <<close(103); } else { // Unknown result?! echo "[{$timestamp}] Could not parse the server response.\n"; echo <<close(1); } } } /** * Fetches a remote URL using curl, fsockopen or fopen * * @param string $url The remote URL to fetch * @param string $method The method to use: curl, fsockopen or fopen (optional) * * @return string The contents of the URL which was fetched */ private function fetchURL($url, $method = 'curl') { switch ($method) { case 'curl': $caCertPath = class_exists('\\Composer\\CaBundle\\CaBundle') ? \Composer\CaBundle\CaBundle::getBundledCaBundlePath() : JPATH_LIBRARIES . '/src/Http/Transport/cacert.pem'; $ch = curl_init($url); if (file_exists($caCertPath)) { @curl_setopt($ch, CURLOPT_CAINFO, $caCertPath); } @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); @curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); @curl_setopt($ch, CURLOPT_HEADER, false); @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verifySSL); @curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->verifySSL ? 2 : 0); @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 180); @curl_setopt($ch, CURLOPT_TIMEOUT, 180); $result = curl_exec($ch); curl_close($ch); return $result; break; case 'fsockopen': $pos = strpos($url, '://'); $protocol = strtolower(substr($url, 0, $pos)); $req = substr($url, $pos + 3); $pos = strpos($req, '/'); if ($pos === false) { $pos = strlen($req); } $host = substr($req, 0, $pos); if (strpos($host, ':') !== false) { [$host, $port] = explode(':', $host); } else { $host = $host; $port = ($protocol == 'https') ? 443 : 80; } $uri = substr($req, $pos); if ($uri == '') { $uri = '/'; } $crlf = "\r\n"; $req = 'GET ' . $uri . ' HTTP/1.0' . $crlf . 'Host: ' . $host . $crlf . $crlf; $fp = fsockopen(($protocol == 'https' ? 'ssl://' : '') . $host, $port); fwrite($fp, $req); $response = ''; while (is_resource($fp) && $fp && !feof($fp)) { $response .= fread($fp, 1024); } fclose($fp); // split header and body $pos = strpos($response, $crlf . $crlf); if ($pos === false) { return ($response); } $header = substr($response, 0, $pos); $body = substr($response, $pos + 2 * strlen($crlf)); // parse headers $headers = []; $lines = explode($crlf, $header); foreach ($lines as $line) { if (($pos = strpos($line, ':')) !== false) { $headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos + 1)); } } //redirection? if (isset($headers['location'])) { return $this->fetchURL($headers['location'], $method); } else { return ($body); } break; case 'fopen': $opts = [ 'http' => [ 'method' => "GET", 'header' => "Accept-language: en\r\n", ], ]; $context = stream_context_create($opts); $result = @file_get_contents($url, false, $context); break; } return $result; } } // Instantiate and run the application FOFApplicationCLI::getInstance('AkeebaBackupAltCLI')->execute();