private function sendDropbox() { require_once Xpandbuddy::$pathName . "/library/Dropbox/autoload.php"; $attachments = substr(ABSPATH, 0, -1) . self::$ds . 'wp-backups' . Xpandbuddy_Twig::_subdirCreation() . Xpandbuddy_Twig::$arrOptions['file_name']; $dbxClient = Dropbox_Client(Xpandbuddy_Twig::$arrOptions['access_token']); try { $fileInSteam = @fopen($attachments, "rb"); if (!isset(Xpandbuddy_Twig::$arrOptions['return']['file_size'])) { $settings['file_size'] = @filesize($attachments); } else { $settings['file_size'] = (int) Xpandbuddy_Twig::$arrOptions['return']['file_size']; } if ($fileInSteam !== false) { if (!isset(Xpandbuddy_Twig::$arrOptions['return']['upload_id'])) { $data = ''; $bytesRemaining = 4194304; while (!feof($fileInSteam) && $bytesRemaining > 0) { $part = fread($fileInSteam, $bytesRemaining); if ($part === false) { if (isset(Xpandbuddy_Twig::$arrOptions['return'])) { return json_encode(array('error' => "Error reading from file", 'status' => false)); } } $data .= $part; $bytesRemaining -= strlen($part); } $len = strlen($data); $settings['upload_id'] = $dbxClient->chunkedUploadStart($data); //3 } else { $settings['upload_id'] = Xpandbuddy_Twig::$arrOptions['return']['upload_id']; } if (!isset(Xpandbuddy_Twig::$arrOptions['return']['range_start'])) { $settings['range_start'] = $len; } else { $settings['range_start'] = (int) Xpandbuddy_Twig::$arrOptions['return']['range_start']; } if ($settings['range_start'] < $settings['file_size']) { while (!feof($fileInSteam)) { $data = ''; $bytesRemaining = 4194304; fseek($fileInSteam, $settings['range_start']); while (!feof($fileInSteam) && $bytesRemaining > 0) { $part = fread($fileInSteam, $bytesRemaining); if ($part === false) { if (isset(Xpandbuddy_Twig::$arrOptions['return'])) { return json_encode(array('error' => "Error reading from file", 'status' => false)); } } $data .= $part; $bytesRemaining -= strlen($part); } $len = strlen($data); while (true) { $r = $dbxClient->chunkedUploadContinue($settings['upload_id'], $settings['range_start'], $data); //3 if ($r === true) { // Chunk got uploaded! $settings['range_start'] += $len; if (isset(Xpandbuddy_Twig::$arrOptions['return'])) { return json_encode(array('return' => $settings, 'status' => true)); } break; } if ($r === false) { // Server didn't recognize our upload ID // This is very unlikely since we're uploading all the chunks in sequence. if (isset(Xpandbuddy_Twig::$arrOptions['return'])) { return json_encode(array('error' => "Server forgot our uploadId", 'status' => false)); } } // Otherwise, the server is at a different byte offset from us. $settings['server_range_start'] = $r; assert($settings['server_range_start'] !== $settings['range_start']); // chunkedUploadContinue ensures this. // An earlier byte offset means the server has lost data we sent earlier. if ($settings['server_range_start'] < $settings['range_start']) { if (isset(Xpandbuddy_Twig::$arrOptions['return'])) { return json_encode(array('error' => "Server is at an ealier byte offset: us=" . $settings['range_start'] . ", server=" . $settings['server_range_start'], 'status' => false)); } } $diff = $settings['server_range_start'] - $settings['range_start']; // If the server is past where we think it could possibly be, something went wrong. if ($diff > $len) { if (isset(Xpandbuddy_Twig::$arrOptions['return'])) { return json_encode(array('error' => "Server is more than a chunk ahead: us=" . $settings['range_start'] . ", server=" . $settings['server_range_start'], 'status' => false)); } } // The normal case is that the server is a bit further along than us because of a // partially-uploaded chunk. Finish it off. $settings['range_start'] += $diff; if ($diff === $len) { break; // If the server is at the end, we're done. } $data = substr($data, $diff); } } } $dbxClient->chunkedUploadFinish($settings['upload_id'], self::$ds . str_replace(array("http://", "https://", ".", "/"), array("", "", "_", "_"), Xpandbuddy_Twig::$arrOptions['blog']['url']) . self::$ds . str_replace('wp-backups' . Xpandbuddy_Twig::_subdirCreation(), '', 'wp-backups' . Xpandbuddy_Twig::_subdirCreation() . Xpandbuddy_Twig::$arrOptions['file_name']), Dropbox_WriteMode_add()); fclose($fileInSteam); } @unlink($attachments); return 'sended'; } catch (Exception $e) { if (isset(Xpandbuddy_Twig::$arrOptions['return'])) { return json_encode(array('error' => $e->getMessage(), 'status' => false)); } } }
public static function pluginPage() { $_dropbox64Error = false; if (strlen((string) PHP_INT_MAX) < 19) { $_dropbox64Error = true; } require_once Xpandbuddy::$pathName . '/library/PclZip.php'; require_once Xpandbuddy::$pathName . '/library/TarArchive.php'; require_once Xpandbuddy::$pathName . '/library/Backup.php'; require_once Xpandbuddy::$pathName . '/library/Options.php'; require_once Xpandbuddy::$pathName . '/library/Twig.php'; require_once Xpandbuddy::$pathName . '/library/Projects.php'; $arrForm = array(); self::restoreBackupFile($arrForm); $arrForm['arrFiles'] = array(); $_object = new Xpandbuddy_Projects(); if (isset($_POST['submit_save'])) { $_projectForSave = $_projectInitial = $_POST['arrProject']; $_flgSaveId = false; if (array_sum($_projectInitial['flg_type']) > 0) { foreach ($_projectInitial['flg_type'] as $_key => $_value) { $_projectForSave = $_projectInitial; if ($_key == $_value) { $_projectForSave['settings']['user_data'] = $_projectInitial['settings']['type_' . $_value]; unset($_projectInitial['settings']['type_' . $_value]); foreach ($_projectForSave['settings'] as $_i => $_d) { if ($_i == 'type_' . $_value) { continue; } elseif (strpos($_i, 'type_') === 0) { unset($_projectForSave['settings'][$_i]); } } $_projectForSave['flg_type'] = array($_key => $_value); if ($_flgSaveId) { unset($_projectForSave['id']); // save with new id } else { $_flgSaveId = true; } $_object->setEntered($_projectForSave)->set(); } } } else { $_object->setEntered($_projectForSave)->set(); } $arrForm['action'] = 'Backup Project is activated.'; } if (isset($_GET['del']) && !empty($_GET['del'])) { $_object->withIds($_GET['del'])->del(); } self::removeBackupFile(); $_object->getList($arrForm['arrList']); foreach ($arrForm['arrList'] as &$_project) { if (isset($_GET['id']) && !empty($_GET['id']) && $_project['id'] == $_GET['id']) { $arrForm['arrProject'] = $_project; break; } } $_userInfo = get_userdata(get_current_user_id()); $arrForm['arrBlog'] = array('title' => isset($arrForm['arrProject']['settings']['blog']['title']) ? $arrForm['arrProject']['settings']['blog']['title'] : get_bloginfo('name'), 'url' => isset($arrForm['arrProject']['settings']['blog']['url']) ? $arrForm['arrProject']['settings']['blog']['url'] : home_url(), 'path' => isset($arrForm['arrProject']['settings']['blog']['path']) ? $arrForm['arrProject']['settings']['blog']['path'] : substr(ABSPATH, 0, -1), 'dashboad_username' => isset($arrForm['arrProject']['settings']['blog']['dashboad_username']) ? $arrForm['arrProject']['settings']['blog']['dashboad_username'] : (isset($_userInfo->user_login) ? $_userInfo->user_login : '******'), 'db_tableprefix' => isset($arrForm['arrProject']['settings']['blog']['db_tableprefix']) ? $arrForm['arrProject']['settings']['blog']['db_tableprefix'] : @$GLOBALS['table_prefix'], 'dashboad_password' => ''); if (!is_multisite() || is_multisite() && is_super_admin()) { $arrForm['arrBlog']['db_host'] = isset($arrForm['arrProject']['settings']['blog']['db_host']) ? $arrForm['arrProject']['settings']['blog']['db_host'] : DB_HOST; $arrForm['arrBlog']['db_name'] = isset($arrForm['arrProject']['settings']['blog']['db_name']) ? $arrForm['arrProject']['settings']['blog']['db_name'] : DB_NAME; $arrForm['arrBlog']['db_username'] = isset($arrForm['arrProject']['settings']['blog']['db_username']) ? $arrForm['arrProject']['settings']['blog']['db_username'] : DB_USER; $arrForm['arrBlog']['db_password'] = isset($arrForm['arrProject']['settings']['blog']['db_password']) ? $arrForm['arrProject']['settings']['blog']['db_password'] : DB_PASSWORD; } else { $arrForm['arrBlog']['db_host'] = $arrForm['arrBlog']['db_name'] = $arrForm['arrBlog']['db_username'] = $arrForm['arrBlog']['db_password'] = ''; } $_otherBackupFiles = array(); $_backupsDir = substr(ABSPATH, 0, -1) . DIRECTORY_SEPARATOR . 'wp-backups' . Xpandbuddy_Twig::_subdirCreation(); $_arrBackupsFiles = scandir($_backupsDir); $_homeUrlHash = str_replace(array("http://", "https://", ".", "/"), array("", "", "_", "_"), home_url()); // Filest list generation foreach ($_arrBackupsFiles as $_number => $_name) { if (strpos($_name, '.tar.gz') === false && strpos($_name, '.zip') === false) { continue; } $_flg_clone = false; // Progect LIST generetion if (!empty($arrForm['arrList'])) { foreach ($arrForm['arrList'] as &$_project) { if (strpos($_name, "-prj" . $_project['id'] . "-") !== false && strpos($_name, "backup-") !== 0) { if ($_project['settings']['blog']['url'] !== home_url()) { $_flg_clone = true; } global $current_site; $_time = @filemtime($_backupsDir . DIRECTORY_SEPARATOR . $_name); if (isset($_project['files'][$_time])) { for ($_time = $_time + 1; !isset($_project['files'][$_time + 1]); $_time++) { break; } } $_status = 'Failed'; require_once Xpandbuddy::$pathName . '/library/Logger.php'; $_logger = new Xpandbuddy_Logger('sender'); $_logger->logDate = $_project['start']; $_logger->getStepLog(); if (!empty($_logger->stepProject)) { $_status = 'In Progress'; } if (@$_project['flg_type'][1] == 1 || @array_sum($_project['flg_type']) == 0) { $_status = 'Completed'; } $_project['files'][$_time] = array('file' => $_name, 'link' => get_site_url(@$current_site->id) . '/wp-backups' . Xpandbuddy_Twig::_subdirCreation('/') . $_name, 'flg_status' => $_status, 'flg_clone' => $_flg_clone, 'date' => $_time); unset($_arrBackupsFiles[$_number]); continue 2; } } } // Progect LIST generetion end if (strpos($_name, $_homeUrlHash . '-') === false) { $_flg_clone = true; } global $current_site; if (strpos($_name, "backup-") !== 0) { $_otherBackupFiles[] = array('file' => $_name, 'link' => get_site_url(@$current_site->id) . '/wp-backups' . Xpandbuddy_Twig::_subdirCreation('/') . $_name, 'flg_status' => 'Completed', 'flg_clone' => $_flg_clone, 'date' => @filemtime($_backupsDir . DIRECTORY_SEPARATOR . $_name)); unset($_arrBackupsFiles[$_number]); } } // Filest list generation end if (!empty($arrForm['arrList'])) { foreach ($arrForm['arrList'] as &$_project) { require_once Xpandbuddy::$pathName . '/library/Logger.php'; $_logger = new Xpandbuddy_Logger('sender'); $_logger->logDate = $_project['start']; $_logger->getStepLog(); if (!empty($_logger->stepProject)) { $_project['log'] = $_logger->stepProject; } $_logger = new Xpandbuddy_Logger('step_log_file'); $_logger->logDate = $_project['start']; $_logger->getStepLog(); if (!empty($_logger->stepProject)) { $_project['log'] = $_logger->stepProject; } foreach ($_project['flg_type'] as $_type) { switch ($_type) { case '1': /**/ break; case '2': try { if (strlen((string) PHP_INT_MAX) >= 19) { require_once Xpandbuddy::$pathName . "/library/Dropbox/autoload.php"; $dbxClient = Dropbox_Client($_project['settings']['access_token']); $folderMetadata = $dbxClient->getMetadataWithChildren("/" . $_homeUrlHash); if (isset($folderMetadata['contents']) && is_array(@$folderMetadata['contents'])) { foreach (@$folderMetadata['contents'] as $_file) { $_link = $dbxClient->createTemporaryDirectLink($_file['path']); if ($_file['is_dir'] == false && strpos($_file['path'], "-prj" . $_project['id'] . "-") != false) { $_project['files'][strtotime($_file['modified'])] = array('file' => $_file['path'], 'link' => $_link[0], 'flg_status' => 'Completed', 'flg_clone' => false, 'date' => strtotime($_file['modified'])); } } } } } catch (Exception $e) { $arrForm['error'] = 'Exception: ' . $e->getMessage(); } break; case '3': if (!empty($_project['settings']['refresh_token'])) { try { require_once Xpandbuddy::$pathName . "/library/GoogleAPI/Google_Client.php"; require_once Xpandbuddy::$pathName . "/library/GoogleAPI/contrib/Google_DriveService.php"; $client = new Google_Client(); $client->setClientId($_project['settings']['google_key']); $client->setClientSecret($_project['settings']['google_secret']); $client->setRedirectUri(admin_url('admin.php?page=xpandbuddy')); $client->setScopes(array('https://www.googleapis.com/auth/drive')); $client->refreshToken($_project['settings']['refresh_token']); $accessToken = json_decode($client->getAccessToken()); $accessToken = $accessToken->access_token; $req = new Google_HttpRequest('https://www.googleapis.com/drive/v2/files?q=' . urlencode("mimeType = 'application/vnd.google-apps.folder' and title = '" . $_homeUrlHash . "' and trashed = false"), 'GET', array('Authorization' => "Bearer " . $accessToken)); $siteFolder = json_decode(Google_Client::$io->makeRequest($req)->getResponseBody()); if (isset($siteFolder->items) && count($siteFolder->items) > 0) { $req = new Google_HttpRequest('https://www.googleapis.com/drive/v2/files?q=' . urlencode("'" . $siteFolder->items[0]->id . "' in parents"), 'GET', array('Authorization' => "Bearer " . $accessToken)); $siteFiles = json_decode(Google_Client::$io->makeRequest($req)->getResponseBody()); $_fileFromGoogle = array(); $_flgHaveFileInGoogle = false; foreach ($siteFiles->items as $_file) { if (strpos($_file->originalFilename, "-prj" . $_project['id'] . "-") !== false) { $_project['files'][strtotime($_file->modifiedDate)] = array('file' => $_file->originalFilename, 'link' => $_file->alternateLink, 'flg_status' => 'Completed', 'flg_clone' => false, 'date' => strtotime($_file->modifiedDate)); } } } } catch (Exception $e) { $arrForm['error'] = 'Exception: ' . $e->getMessage(); } } break; case '4': if (!empty($_project['settings']['host']) && !empty($_project['settings']['user']) && !empty($_project['settings']['pass'])) { require_once Xpandbuddy::$pathName . "/library/Ftp.php"; $_ftp = new Xpandbuddy_Ftp(); if (!$_ftp->setChmod('0644')->setHost(urldecode($_project['settings']['host']))->setUser(urldecode($_project['settings']['user']))->setPassw(urldecode($_project['settings']['pass']))->setRoot($_project['settings']['dir_name'])->makeConnectToRootDir()) { break; } $_ftp->ls($_arrFiles); if (!empty($_arrFiles) && is_array($_arrFiles)) { foreach ($_arrFiles as $file) { $_flg_clone = false; if (strpos($file['name'], $_homeUrlHash . '-') === false) { $_flg_clone = true; } if (strpos($file['name'], "-prj" . $_project['id'] . "-") !== false) { $_time = $file['stamp']; if (isset($_project['files'][$_time])) { for ($_time = $_time; !isset($_project['files'][$_time + $i]); $_time++) { break; } } $_project['files'][$_time] = array('file' => $file['name'], 'link' => 'ftp://' . urldecode($_project['settings']['user']) . ':' . urldecode($_project['settings']['pass']) . '@' . urldecode($_project['settings']['host']) . $_project['settings']['dir_name'] . '/' . $file['name'], 'flg_status' => 'Completed', 'flg_clone' => $_flg_clone, 'date' => $_time); } } } unset($_arrFiles); } break; case '5': /*email*/ break; default: /* 0 */ break; } break; } } } if (!empty($_otherBackupFiles)) { array_unshift($arrForm['arrList'], array('files' => $_otherBackupFiles)); unset($_otherBackupFiles); } $arrForm['options'] = Xpandbuddy_Options::get(); extract($arrForm); $max_upload_size = self::getMaxUploadSize(); require_once Xpandbuddy::$pathName . '/source/plugin/form.php'; }