Esempio n. 1
0
 *  2015-2016 DOGS
 *  @author J.Podracky, L.Fisher
 *  @copyright  2015-2016 F2FCREATIVE
 */
if (!defined('_PS_ADMIN_DIR_')) {
    define('_PS_ADMIN_DIR_', getcwd());
}
include _PS_ADMIN_DIR_ . '/../config/config.inc.php';
if (!Context::getContext()->employee->isLoggedBack()) {
    Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminLogin'));
}
$tabAccess = Profile::getProfileAccess(Context::getContext()->employee->id_profile, Tab::getIdFromClassName('AdminBackup'));
if ($tabAccess['view'] !== '1') {
    die(Tools::displayError('You do not have permission to view this.'));
}
$backupdir = realpath(PrestaShopBackup::getBackupPath());
if ($backupdir === false) {
    die(Tools::displayError('There is no "/backup" directory.'));
}
if (!($backupfile = Tools::getValue('filename'))) {
    die(Tools::displayError('No file has been specified.'));
}
// Check the realpath so we can validate the backup file is under the backup directory
$backupfile = realpath($backupdir . DIRECTORY_SEPARATOR . $backupfile);
if ($backupfile === false or strncmp($backupdir, $backupfile, strlen($backupdir)) != 0) {
    die(Tools::dieOrLog('The backup file does not exist.'));
}
if (substr($backupfile, -4) == '.bz2') {
    $contentType = 'application/x-bzip2';
} elseif (substr($backupfile, -3) == '.gz') {
    $contentType = 'application/x-gzip';
Esempio n. 2
0
 /**
  * Deletes a range of backup files
  *
  * @return bool True on success
  */
 public function deleteSelection($list)
 {
     foreach ($list as $file) {
         $backup = new PrestaShopBackup($file);
         if (!$backup->delete()) {
             $this->error = $backup->error;
             return false;
         }
     }
     return true;
 }
Esempio n. 3
0
 public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = null)
 {
     if (!Validate::isTableOrIdentifier($this->table)) {
         die('filter is corrupted');
     }
     if (empty($order_by)) {
         $order_by = Tools::getValue($this->table . 'Orderby', $this->_defaultOrderBy);
     }
     if (empty($order_way)) {
         $order_way = Tools::getValue($this->table . 'Orderway', 'ASC');
     }
     // Try and obtain getList arguments from $_GET
     $order_by = Tools::getValue($this->table . 'Orderby');
     $order_way = Tools::getValue($this->table . 'Orderway');
     // Validate the orderBy and orderWay fields
     switch ($order_by) {
         case 'filename':
         case 'filesize':
         case 'date':
         case 'age':
             break;
         default:
             $order_by = 'date';
     }
     switch ($order_way) {
         case 'asc':
         case 'desc':
             break;
         default:
             $order_way = 'desc';
     }
     if (empty($limit)) {
         $limit = !isset($this->context->cookie->{$this->table . '_pagination'}) ? $this->_pagination[0] : ($limit = $this->context->cookie->{$this->table . '_pagination'});
     }
     $limit = (int) Tools::getValue('pagination', $limit);
     $this->context->cookie->{$this->table . '_pagination'} = $limit;
     /* Determine offset from current page */
     if (!empty($_POST['submitFilter' . $this->table]) && is_numeric($_POST['submitFilter' . $this->table])) {
         $start = (int) $_POST['submitFilter' . $this->table] - 1 * $limit;
     }
     $this->_lang = (int) $id_lang;
     $this->_orderBy = $order_by;
     $this->_orderWay = strtoupper($order_way);
     $this->_list = array();
     // Find all the backups
     $dh = @opendir(PrestaShopBackup::getBackupPath());
     if ($dh === false) {
         $this->errors[] = Tools::displayError('Unable to open your backup directory');
         return;
     }
     while (($file = readdir($dh)) !== false) {
         if (preg_match('/^([\\d]+-[a-z\\d]+)\\.sql(\\.gz|\\.bz2)?$/', $file, $matches) == 0) {
             continue;
         }
         $timestamp = (int) $matches[1];
         $date = date('Y-m-d H:i:s', $timestamp);
         $age = time() - $timestamp;
         if ($age < 3600) {
             $age = '< 1 ' . $this->l('Hour', 'AdminTab', false, false);
         } else {
             if ($age < 86400) {
                 $age = floor($age / 3600);
                 $age = $age . ' ' . ($age == 1 ? $this->l('Hour', 'AdminTab', false, false) : $this->l('Hours', 'AdminTab', false, false));
             } else {
                 $age = floor($age / 86400);
                 $age = $age . ' ' . ($age == 1 ? $this->l('Day') : $this->l('Days', 'AdminTab', false, false));
             }
         }
         $size = filesize(PrestaShopBackup::getBackupPath($file));
         $this->_list[] = array('filename' => $file, 'age' => $age, 'date' => $date, 'filesize' => number_format($size / 1000, 2) . ' Kb', 'timestamp' => $timestamp, 'filesize_sort' => $size);
     }
     closedir($dh);
     $this->_listTotal = count($this->_list);
     // Sort the _list based on the order requirements
     switch ($this->_orderBy) {
         case 'filename':
             $this->sort_by = 'filename';
             $sorter = 'strSort';
             break;
         case 'filesize':
             $this->sort_by = 'filesize_sort';
             $sorter = 'intSort';
             break;
         case 'age':
         case 'date':
             $this->sort_by = 'timestamp';
             $sorter = 'intSort';
             break;
     }
     usort($this->_list, array($this, $sorter));
     $this->_list = array_slice($this->_list, $start, $limit);
 }
Esempio n. 4
0
 public static function list_database_backups()
 {
     $dh = @opendir(PrestaShopBackup::getBackupPath());
     if ($dh === false) {
         echo "Error, cannot read database backup directory {$dh}\n";
         return false;
     }
     $table = new Cli\Table();
     $table->setHeaders(array('Filename', 'Size', 'Date'));
     while ($file = readdir($dh)) {
         if (preg_match('/^([_a-zA-Z0-9\\-]*[\\d]+-[a-z\\d]+)\\.sql(\\.gz|\\.bz2)?$/', $file, $matches) == 0) {
             continue;
         }
         $filename = $file;
         $size = number_format(filesize(PrestaShopBackup::getBackupPath($file)) / 1000, 2) . ' Kb';
         $date = date('Y-m-d H:i:s', (int) $matches[1]);
         $table->addRow(array($filename, $size, $date));
     }
     $table->display();
     return true;
 }