public function backup() { include_once Xpandbuddy::$pathName . '/library/PclZip.php'; include_once Xpandbuddy::$pathName . '/library/TarArchive.php'; include_once Xpandbuddy::$pathName . '/library/Backup.php'; include_once Xpandbuddy::$pathName . '/library/Options.php'; include_once Xpandbuddy::$pathName . '/library/Twig.php'; include_once Xpandbuddy::$pathName . '/library/Projects.php'; include_once Xpandbuddy::$pathName . '/library/Logger.php'; include_once Xpandbuddy::$pathName . '/library/Sender.php'; $_object = new Xpandbuddy_Projects(); if (!empty($this->_projectId)) { $_object->withIds($this->_projectId); } if (!empty($this->_projectSettings)) { $arrList = array($this->_projectSettings); } else { $_object->getList($arrList); shuffle($arrList); } if (empty($arrList)) { return array('message' => 'No project found!'); } foreach ($arrList as &$_project) { $_nowTime = time(); if (!isset($_project['start']) && empty($this->_projectLogdate)) { $_project['start'] = $this->_projectLogdate = $_nowTime; } if ($_project['start'] >= $_nowTime && empty($this->_projectLogdate)) { continue; } if (empty($_project['start'])) { $_project['start'] = $_nowTime; } $_senderLog = new Xpandbuddy_Logger('sender'); if (!empty($this->_projectLogdate)) { $_senderLog->logDate = $this->_projectLogdate; Xpandbuddy_Twig::$logger->logDate = $this->_projectLogdate; } else { $_senderLog->logDate = $_project['start']; Xpandbuddy_Twig::$logger->logDate = $_project['start']; } $_senderLog->getStepLog(); if (!empty($_senderLog->stepProject)) { // запускаем пошаговый отправщик $_POST['type'] = $_senderLog->stepProject['sender'][$_senderLog->stepProject['send_now']]['type']; $_POST['send'] = $_senderLog->stepProject['settings']['file_name']; $_POST['project'] = $_senderLog->stepProject['id']; $_POST['return'] = (array) $_senderLog->stepProject['code']['return']; $_senderLog->stepProject['code'] = json_decode(Xpandbuddy_Sender::sendBackupFileAction(true), true); if ($_senderLog->stepProject['code']['status'] === true || $_senderLog->stepProject['code']['status'] === false) { $_checkSender = $_senderLog->setStepLog(); if (isset($_senderLog->stepProject['code']['error'])) { $_senderLog->deleteStepLog(); return array('logcode' => $_senderLog->logDate, 'flg_sender' => $_checkSender, 'error' => $_senderLog->stepProject['code']['error']) + (array) $_senderLog->stepProject['code']; } else { return array('logcode' => $_senderLog->logDate) + (array) $_senderLog->stepProject['code']; } } if ($_senderLog->stepProject['code']['status'] === 'sended') { $_senderLog->stepProject['sender'][$_senderLog->stepProject['send_now']]['flg_send'] = true; $_flgRunSender = false; foreach ($_senderLog->stepProject['sender'] as $_key => $_type) { if ($_type['flg_send'] == false) { $_senderLog->stepProject['send_now'] = $_key; $_flgRunSender = true; } } $_checkSender = $_senderLog->setStepLog(); if ($_flgRunSender) { return array('logcode' => $_senderLog->logDate) + (array) $_senderLog->stepProject['code']; } $_senderLog->deleteStepLog(); $_nextRunDate = date("U", mktime($_project['settings']['timer']['h'], $_project['settings']['timer']['m'], 0, date("n", $_nowTime), date("j", $_nowTime), date("Y", $_nowTime))) + Xpandbuddy_Cron::next($_project['settings']['user_data']['every']); $_object->withIds($_project['id'])->update('start', $_nextRunDate); return array('status' => 'sended_all', 'message' => '<span id="run_date_' . $_project['id'] . '">next run after ' . date("m/d/Y H:00", $_nextRunDate) . '</span>'); } if (isset($_senderLog->stepProject['code']['error'])) { return array('logcode' => $_senderLog->logDate, 'error' => $_senderLog->stepProject['code']['error'], 'sender' => $_senderLog->stepProject['send_now']); } else { return array('logcode' => $_senderLog->logDate, 'return' => $_senderLog->stepProject['code']); } } if (Xpandbuddy_Twig::stepByStep(Xpandbuddy_Twig::$logger->logDate, $_project, true)) { $_returnArray = array(); if (!empty(Xpandbuddy_Twig::$logString)) { $_returnArray['message'] = Xpandbuddy_Twig::$logString; } if (isset(Xpandbuddy_Twig::$logger->stepProject['settings']['file_loader'])) { global $current_site; $_returnArray['file'] = array('name' => Xpandbuddy_Twig::$logger->stepProject['settings']['file_loader'], 'link' => get_site_url(@$current_site->id) . '/wp-backups' . Xpandbuddy_Twig::_subdirCreation('/') . Xpandbuddy_Twig::$logger->stepProject['settings']['file_loader'], 'date' => date("Y-m-d H:i:s", @filemtime(substr(ABSPATH, 0, -1) . DIRECTORY_SEPARATOR . '/wp-backups' . Xpandbuddy_Twig::_subdirCreation('/') . Xpandbuddy_Twig::$logger->stepProject['settings']['file_loader']))); } if (!empty(Xpandbuddy_Twig::$logger->logDate)) { $_returnArray['logcode'] = Xpandbuddy_Twig::$logger->logDate; } if (isset(Xpandbuddy_Twig::$logger->stepProject['arrAllFilesCount'])) { $_returnArray['counters'] = array('all' => Xpandbuddy_Twig::$logger->stepProject['arrAllFilesCount'], 'now' => Xpandbuddy_Twig::$logger->stepProject['arrAllFilesCount'] - count(Xpandbuddy_Twig::$logger->stepProject['arrFiles'])); } if (isset(Xpandbuddy_Twig::$logger->stepProject['settings']['file_loader']) && !empty(Xpandbuddy_Twig::$logger->stepProject['settings']['file_loader'])) { // создаем следующий степовый файл с отправкой $_senderLog->stepProject = Xpandbuddy_Twig::$logger->stepProject; foreach ($_senderLog->stepProject['flg_type'] as $_key => $_type) { if ($_type == $_key) { $_senderLog->stepProject['sender'][$_key] = array('type' => $_type, 'flg_send' => false); $_senderLog->stepProject['send_now'] = $_key; } } $_senderLog->stepProject['code'] = array('return' => array(true)); $_senderLog->setStepLog(); } return $_returnArray; } else { // проблема с созданием бэкапа $_returnArray['message'] = Xpandbuddy_Twig::$logString . "<br/>" . Xpandbuddy_Twig::$error; if (!empty(Xpandbuddy_Twig::$logger->logDate)) { $_returnArray['logcode'] = Xpandbuddy_Twig::$logger->logDate; } if (isset(Xpandbuddy_Twig::$logger->stepProject['arrAllFilesCount'])) { $_returnArray['counters'] = array('all' => Xpandbuddy_Twig::$logger->stepProject['arrAllFilesCount'], 'now' => Xpandbuddy_Twig::$logger->stepProject['arrAllFilesCount'] - count(Xpandbuddy_Twig::$logger->stepProject['arrFiles'])); } return $_returnArray; } // not used } }
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'; }