public static function getFtpConnect() { if (!isset($_POST['host']) || empty($_POST['user']) || empty($_POST['pass'])) { die; } require_once Xpandbuddy::$pathName . "/library/Ftp.php"; $_ftp = new Xpandbuddy_Ftp(); $_arrDirs = '/'; if (!empty($_POST['dir'])) { $_arrDirs = $_POST['dir']; $_arrDirs = explode('/', $_arrDirs); if (end($_arrDirs) == '..') { array_pop($_arrDirs); array_pop($_arrDirs); } if ($_arrDirs === array('') || end($_arrDirs) == '.') { $_arrDirs = array('', ''); } $_arrDirs = implode('/', $_arrDirs); } if (!$_ftp->setChmod('0644')->setHost(urldecode($_POST['host']))->setUser(urldecode($_POST['user']))->setPassw(urldecode($_POST['pass']))->setRoot($_arrDirs)->makeConnectToRootDir()) { return false; } $_ftp->ls($arrRes); if ($_arrDirs != '/') { $_arrDirs = explode('/', $_arrDirs); foreach ($_arrDirs as $_k => $_dir) { if ($_dir == '' && $_k == 0) { $_dir = 'root'; $_strDirs = '/'; } elseif ($_dir != '') { $_strDirs = ''; foreach ($_arrDirs as $_l => $_n) { if ($_l <= $_k && $_n != '') { $_strDirs .= '/' . $_n; } } } if ($_k < count($_arrDirs) - 1) { echo '/<a href="" class="root_dir" rel="' . $_strDirs . '">' . $_dir . '</a>'; } else { echo '/' . $_dir; } } $_arrDirs = implode('/', $_arrDirs); } else { echo 'root/'; } echo '</br>'; foreach ($arrRes as $_file) { if ($_file['is_dir']) { if ($_arrDirs == '/' && ($_file['name'] == '..' || $_file['name'] == '.')) { continue; } $_str = '<a href="" class="ftp_open_dir">' . $_file['name'] . '</a>'; } else { if (substr($_file['name'], strrpos($_file['name'], ".")) == '.gz' || substr($_file['name'], strrpos($_file['name'], ".")) == 'zip') { $_str = '<a href="" class="ftp_use_file">' . $_file['name'] . '</a>'; } else { $_str = '<a href="" class="ftp_other_file">' . $_file['name'] . '</a>'; } } echo $_str . '</br>'; } echo '<input type="hidden" id="ftp_dir_name_load" value="' . $_arrDirs . '" >'; die; }
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'; }