public static function backupDownloadFile($pSiteId, $pType, $pUrl, $pFile) { $dir = dirname($pFile) . '/'; @mkdir($dir, 0777, true); if (!file_exists($dir . 'index.php')) { @touch($dir . 'index.php'); } //Clean old backups from our system $maxBackups = get_option('mainwp_backupsOnServer'); if ($maxBackups === false) { $maxBackups = 1; } $dbBackups = array(); $fullBackups = array(); if (file_exists($dir) && ($dh = opendir($dir))) { while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..') { $theFile = $dir . $file; if ($pType == 'db' && MainWPUtility::isSQLFile($file)) { $dbBackups[filemtime($theFile) . $file] = $theFile; } if ($pType == 'full' && MainWPUtility::isArchive($file) && !MainWPUtility::isSQLArchive($file)) { $fullBackups[filemtime($theFile) . $file] = $theFile; } } } closedir($dh); } krsort($dbBackups); krsort($fullBackups); $cnt = 0; foreach ($dbBackups as $key => $dbBackup) { $cnt++; if ($cnt >= $maxBackups) { @unlink($dbBackup); } } $cnt = 0; foreach ($fullBackups as $key => $fullBackup) { $cnt++; if ($cnt >= $maxBackups) { @unlink($fullBackup); } } $website = MainWPDB::Instance()->getWebsiteById($pSiteId); MainWPUtility::endSession(); $what = null; if ($pType == 'db') { MainWPUtility::downloadToFile(MainWPUtility::getGetDataAuthed($website, $pUrl, 'fdl'), $pFile, false, $website->http_user, $website->http_pass); } if ($pType == 'full') { MainWPUtility::downloadToFile(MainWPUtility::getGetDataAuthed($website, $pUrl, 'fdl'), $pFile, false, $website->http_user, $website->http_pass); } return true; }
public static function openSiteRestore($website, $file, $size) { ?> <div class="wrap"><a href="https://mainwp.com" id="mainwplogo" title="MainWP" target="_blank"><img src="<?php echo plugins_url('images/logo.png', dirname(__FILE__)); ?> " height="50" alt="MainWP" /></a> <h2><i class="fa fa-globe"></i> <?php echo stripslashes($website->name); ?> </h2><div style="clear: both;"></div><br/> <div id="mainwp_background-box"> <?php _e('Will redirect to your website immediately.', 'mainwp'); $url = isset($website->siteurl) && $website->siteurl != '' ? $website->siteurl : $website->url; $url .= substr($url, -1) != '/' ? '/' : ''; $postdata = MainWPUtility::getGetDataAuthed($website, $file, MainWPUtility::getFileParameter($website), true); $postdata['size'] = $size; ?> <form method="POST" action="<?php echo $url; ?> " id="redirectForm"> <?php foreach ($postdata as $name => $value) { echo '<input type="hidden" name="' . $name . '" value="' . $value . '" />'; } ?> </form> </div> </div> <?php }