protected static function checkDirectoryMainWPDirectory($write = true) { $branding_title = "MainWP"; if (MainWPChildBranding::is_branding()) { $branding_title = MainWPChildBranding::get_branding(); } $branding_title .= " upload directory"; try { $dirs = MainWPHelper::getMainWPDir(null, false); $path = $dirs[0]; } catch (Exception $e) { return self::renderDirectoryRow($branding_title, '', 'Writable', $e->getMessage(), false); } if (!is_dir(dirname($path))) { if ($write) { return self::renderDirectoryRow($branding_title, $path, 'Writable', 'Directory not found', false); } else { return false; } } $hasWPFileSystem = MainWPHelper::getWPFilesystem(); global $wp_filesystem; if ($hasWPFileSystem && !empty($wp_filesystem)) { if (!$wp_filesystem->is_writable($path)) { if ($write) { return self::renderDirectoryRow($branding_title, $path, 'Writable', 'Directory not writable', false); } else { return false; } } } else { if (!is_writable($path)) { if ($write) { return self::renderDirectoryRow($branding_title, $path, 'Writable', 'Directory not writable', false); } else { return false; } } } if ($write) { return self::renderDirectoryRow($branding_title, $path, 'Writable', 'Writable', true); } else { return true; } }
public function extractWPZipBackup() { MainWPHelper::getWPFilesystem(); global $wp_filesystem; //First check if there is a database backup in the zip file, these can be very large and the wordpress unzip_file can not handle these! // if ($this->checkZipSupport()) // { // return $this->extractZipBackup(); // $zip = new ZipArchive(); // $zipRes = $zip->open($this->file); // if ($zipRes) // { // $stats = $zip->statName('wp-content/dbBackup.sql'); // // @$zip->extractTo(ABSPATH); // // $zip->deleteName('wp-content/dbBackup.sql'); // $zip->deleteName('clone'); // $zip->close(); // // $zip->close(); // } // } // else // { // return $this->extractZipPclBackup(); // } $tmpdir = ABSPATH; if ($wp_filesystem->method == 'ftpext' && defined('FTP_BASE')) { $ftpBase = FTP_BASE; $ftpBase = trailingslashit($ftpBase); $tmpdir = str_replace(ABSPATH, $ftpBase, $tmpdir); } unzip_file($this->file, $tmpdir); return true; }
public static function validateMainWPDir() { $done = false; $dir = MainWPHelper::getMainWPDir(); $dir = $dir[0]; if (MainWPHelper::getWPFilesystem()) { global $wp_filesystem; try { MainWPHelper::checkDir($dir, false); } catch (Exception $e) { } if (!empty($wp_filesystem)) { if ($wp_filesystem->is_writable($dir)) { $done = true; } } } if (!$done) { if (!file_exists($dir)) { @mkdirs($dir); } if (is_writable($dir)) { $done = true; } } return $done; }
public static function renderNormalRestore() { $uploadError = false; $uploadFile = false; if (isset($_REQUEST['upload'])) { if (isset($_FILES['file'])) { if (!function_exists('wp_handle_upload')) { require_once ABSPATH . 'wp-admin/includes/file.php'; } $uploadedfile = $_FILES['file']; $upload_overrides = array('test_form' => false); $movefile = wp_handle_upload($uploadedfile, $upload_overrides); if ($movefile) { $uploadFile = str_replace(ABSPATH, '', $movefile['file']); } else { $uploadError = __('File could not be uploaded.', 'mainwp-child'); } } else { $uploadError = __('File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.', 'mainwp-child'); } } $uploadSizeInBytes = min(MainWPHelper::return_bytes(ini_get('upload_max_filesize')), MainWPHelper::return_bytes(ini_get('post_max_size'))); $uploadSize = MainWPHelper::human_filesize($uploadSizeInBytes); self::renderHeader(); ?> <div id="icon-options-general" class="icon32"><br></div><h2><strong><?php _e('Option 1:', 'mainwp-child'); ?> </strong> <?php _e('Restore', 'mainwp-child'); ?> </h2><?php MainWPHelper::getWPFilesystem(); global $wp_filesystem; if (!empty($wp_filesystem) && !$wp_filesystem->is_writable(WP_CONTENT_DIR) || empty($wp_filesystem) && !is_writable(WP_CONTENT_DIR)) { echo '<div class="mainwp-child_info-box-red"><strong>' . __('Your content directory is not writable. Please set 0755 permission to ', 'mainwp-child') . basename(WP_CONTENT_DIR) . '. (' . WP_CONTENT_DIR . ')</strong></div>'; $error = true; } ?> <div class="mainwp-child_info-box-green" style="display: none;"><?php _e('Restore process completed successfully! You will now need to click ', 'mainwp-child'); ?> <a href="<?php echo admin_url('options-permalink.php'); ?> "><?php _e('here', 'mainwp-child'); ?> </a><?php _e(' to re-login to the admin and re-save permalinks.', 'mainwp-child'); ?> </div> <?php if ($uploadFile) { _e('Upload successful.', 'mainwp-child'); ?> <a href="#" id="mainwp-child_uploadclonebutton" class="button-primary" file="<?php echo $uploadFile; ?> "><?php _e('Restore Website', 'mainwp-child'); ?> </a><?php } else { if ($uploadError) { ?> <div class="mainwp-child_info-box-red"><?php echo $uploadError; ?> </div><?php } ?> <?php _e('Upload backup in .zip format (Maximum filesize for your server settings: ', 'mainwp-child'); echo $uploadSize; ?> )<br/> <i><?php _e('If you have a FULL backup created by your Network dashboard you may restore it by uploading here.', 'mainwp-child'); ?> <br /> <?php _e('A database only backup will not work.', 'mainwp-child'); ?> </i><br /><br /> <form action="<?php echo admin_url('admin.php?page=MainWPRestore&upload=yes'); ?> " method="post" enctype="multipart/form-data"><input type="file" name="file" id="file" /> <input type="submit" name="submit" id="filesubmit" disabled="disabled" value="<?php _e('Restore Website', 'mainwp-child'); ?> " /></form> <?php } self::renderCloneFromServer(); self::renderJavaScript(); }
function backup($pWrite = true) { $timeout = 20 * 60 * 60; //20minutes @set_time_limit($timeout); @ini_set('max_execution_time', $timeout); MainWPHelper::endSession(); //Cleanup pid files! $dirs = MainWPHelper::getMainWPDir('backup'); $backupdir = trailingslashit($dirs[0]); /** @var $wp_filesystem WP_Filesystem_Base */ global $wp_filesystem; MainWPHelper::getWPFilesystem(); $files = glob($backupdir . '*'); //Find old files (changes > 3 hr) foreach ($files as $file) { if (MainWPHelper::endsWith($file, '/index.php') | MainWPHelper::endsWith($file, '/.htaccess')) { continue; } if (time() - filemtime($file) > 60 * 60 * 3) { @unlink($file); } } $fileName = isset($_POST['fileUID']) ? $_POST['fileUID'] : ''; if ($_POST['type'] == 'full') { $excludes = isset($_POST['exclude']) ? explode(',', $_POST['exclude']) : array(); $excludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/uploads/mainwp'; $uploadDir = MainWPHelper::getMainWPDir(); $uploadDir = $uploadDir[0]; $excludes[] = str_replace(ABSPATH, '', $uploadDir); $excludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/object-cache.php'; if (function_exists('posix_uname')) { $uname = @posix_uname(); if (is_array($uname) && isset($uname['nodename'])) { if (stristr($uname['nodename'], 'hostgator')) { if (!isset($_POST['file_descriptors']) || $_POST['file_descriptors'] == 0 || $_POST['file_descriptors'] > 1000) { $_POST['file_descriptors'] = 1000; } $_POST['file_descriptors_auto'] = 0; $_POST['loadFilesBeforeZip'] = false; } } } $file_descriptors = isset($_POST['file_descriptors']) ? $_POST['file_descriptors'] : 0; $file_descriptors_auto = isset($_POST['file_descriptors_auto']) ? $_POST['file_descriptors_auto'] : 0; if ($file_descriptors_auto == 1) { if (function_exists('posix_getrlimit')) { $result = @posix_getrlimit(); if (isset($result['soft openfiles'])) { $file_descriptors = $result['soft openfiles']; } } } $loadFilesBeforeZip = isset($_POST['loadFilesBeforeZip']) ? $_POST['loadFilesBeforeZip'] : true; $newExcludes = array(); foreach ($excludes as $exclude) { $newExcludes[] = rtrim($exclude, '/'); } $excludebackup = isset($_POST['excludebackup']) && $_POST['excludebackup'] == 1; $excludecache = isset($_POST['excludecache']) && $_POST['excludecache'] == 1; $excludezip = isset($_POST['excludezip']) && $_POST['excludezip'] == 1; $excludenonwp = isset($_POST['excludenonwp']) && $_POST['excludenonwp'] == 1; if ($excludebackup) { //Backup buddy $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/uploads/backupbuddy_backups'; $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/uploads/backupbuddy_temp'; $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/uploads/pb_backupbuddy'; //ManageWP $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/managewp'; //InfiniteWP $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/infinitewp'; //WordPress Backup to Dropbox $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/backups'; //BackUpWordpress $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/backups'; //BackWPUp $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/uploads/backwpup*'; //WP Complete Backup $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/plugins/wp-complete-backup/storage'; //WordPress EZ Backup //This one may be hard to do since they add random text at the end for example, feel free to skip if you need to ///backup_randomkyfkj where kyfkj is random //Online Backup for WordPress $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/backups'; //XCloner $newExcludes[] = '/administrator/backups'; } if ($excludecache) { //W3 Total Cache $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/w3tc-cache'; $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/w3tc'; $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/cache/config'; $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/cache/minify'; $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/cache/page_enhanced'; $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/cache/tmp'; //WP Super Cache $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/cache/supercache'; //Quick Cache $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/cache/quick-cache'; //Hyper Cache $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/hyper-cache/cache'; //WP Fastest Cache $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/cache/all'; //WP-Rocket $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/cache/wp-rocket'; } $file = false; if (isset($_POST['f'])) { $file = $_POST['f']; } else { if (isset($_POST['file'])) { $file = $_POST['file']; } } $ext = 'zip'; if (isset($_POST['ext'])) { $ext = $_POST['ext']; } $pid = false; if (isset($_POST['pid'])) { $pid = $_POST['pid']; } $append = isset($_POST['append']) && $_POST['append'] == '1'; $res = MainWPBackup::get()->createFullBackup($newExcludes, $fileName, true, true, $file_descriptors, $file, $excludezip, $excludenonwp, $loadFilesBeforeZip, $ext, $pid, $append); if (!$res) { $information['full'] = false; } else { $information['full'] = $res['file']; $information['size'] = $res['filesize']; } $information['db'] = false; } else { if ($_POST['type'] == 'db') { $ext = 'zip'; if (isset($_POST['ext'])) { $ext = $_POST['ext']; } $res = $this->backupDB($fileName, $ext); if (!$res) { $information['db'] = false; } else { $information['db'] = $res['file']; $information['size'] = $res['filesize']; } $information['full'] = false; } else { $information['full'] = false; $information['db'] = false; } } if ($pWrite) { MainWPHelper::write($information); } return $information; }
public static function remove_readme($force = false) { if ($force || self::get_security_option('readme')) { if (@file_exists(ABSPATH . 'readme.html')) { if (!@unlink(ABSPATH . 'readme.html')) { MainWPHelper::getWPFilesystem(); global $wp_filesystem; if (!empty($wp_filesystem)) { $wp_filesystem->delete(ABSPATH . 'readme.html'); } } } } }