public function execute()
 {
     // Instance media
     $this->core->media = new dcMedia($this->core);
     $this->core->media->chdir(null);
     $this->core->media->getDir();
     // Create zip
     @set_time_limit(300);
     $fp = fopen('php://output', 'wb');
     $zip = new fileZip($fp);
     $zip->addExclusion('#(^|/).(.*?)_(m|s|sq|t).jpg$#');
     $zip->addDirectory($this->core->media->root . '/', '', true);
     // Log task execution here as we sent file and stop script
     $this->log();
     // Send zip
     header('Content-Disposition: attachment;filename=' . date('Y-m-d') . '-' . $this->core->blog->id . '-' . 'media.zip');
     header('Content-Type: application/x-zip');
     $zip->write();
     unset($zip);
     exit(1);
 }
 public function execute()
 {
     // Get theme path
     $path = $this->core->blog->themes_path;
     $theme = $this->core->blog->settings->system->theme;
     $dir = path::real($path . '/' . $theme);
     if (empty($path) || empty($theme) || !is_dir($dir)) {
         return false;
     }
     // Create zip
     @set_time_limit(300);
     $fp = fopen('php://output', 'wb');
     $zip = new fileZip($fp);
     $zip->addExclusion('#(^|/).(.*?)_(m|s|sq|t).jpg$#');
     $zip->addDirectory($dir . '/', '', true);
     // Log task execution here as we sent file and stop script
     $this->log();
     // Send zip
     header('Content-Disposition: attachment;filename=theme-' . $theme . '.zip');
     header('Content-Type: application/x-zip');
     $zip->write();
     unset($zip);
     exit(1);
 }
示例#3
0
 /**
  * Backups changed files before an update.
  *
  * @param string $sZipFile
  * @param string $sZipDigests
  * @param string $sRoot
  * @param string $sRootDigests
  * @param string $sDest
  * @throws Exception
  * @return boolean
  */
 public function backup($sZipFile, $sZipDigests, $sRoot, $sRootDigests, $sDest)
 {
     if (!is_readable($sZipFile)) {
         throw new Exception(__('c_a_update_archive_not_found'));
     }
     if (!is_readable($sRootDigests)) {
         @unlink($sZipFile);
         throw new Exception(__('c_a_update_unable_read_digests'));
     }
     # Stop everything if a backup already exists and can not be overrided
     if (!is_writable(dirname($sDest)) && !file_exists($sDest)) {
         throw new Exception(__('c_a_update_root_directory_not_writable'));
     }
     if (file_exists($sDest) && !is_writable($sDest)) {
         return false;
     }
     $b_fp = @fopen($sDest, 'wb');
     if ($b_fp === false) {
         return false;
     }
     $oZip = new fileUnzip($sZipFile);
     $b_zip = new fileZip($b_fp);
     if (!$oZip->hasFile($sZipDigests)) {
         @unlink($sZipFile);
         throw new Exception(__('c_a_update_downloaded_file_not_valid_archive'));
     }
     $opts = FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES;
     $cur_digests = file($sRootDigests, $opts);
     $new_digests = explode("\n", $oZip->unzip($sZipDigests));
     $aNewFiles = $this->getNewFiles($cur_digests, $new_digests);
     $oZip->close();
     unset($opts, $cur_digests, $new_digests, $oZip);
     $aNotReadable = array();
     if (!empty($this->aForcedFiles)) {
         $aNewFiles = array_merge($aNewFiles, $this->aForcedFiles);
     }
     foreach ($aNewFiles as $file) {
         if (!$file || !file_exists($sRoot . '/' . $file)) {
             continue;
         }
         try {
             $b_zip->addFile($sRoot . '/' . $file, $file);
         } catch (Exception $e) {
             $aNotReadable[] = $file;
         }
     }
     # If only one file is not readable, stop everything now
     if (!empty($aNotReadable)) {
         $e = new Exception('Some files are not readable.', self::ERR_FILES_UNREADABLE);
         $e->bad_files = $aNotReadable;
         throw $e;
     }
     $b_zip->write();
     fclose($b_fp);
     $b_zip->close();
     return true;
 }
示例#4
0
 /**
  * Make a package of a module
  *
  * @param string $id
  * @return boolean
  */
 public function dowloadModule($id)
 {
     $module_path = $full_entry = $this->path . '/' . $id;
     $filename = 'module-' . $id . '-' . date('Y-m-d-H-i') . '.zip';
     if (!is_dir($module_path) || !is_readable($module_path) || !file_exists($full_entry . '/_define.php')) {
         return false;
     }
     try {
         set_time_limit(0);
         $fp = fopen('php://output', 'wb');
         $zip = new fileZip($fp);
         $zip->addExclusion('#(^|/).svn$#');
         $zip->addDirectory($module_path, '', true);
         header('Content-Disposition: attachment;filename=' . $filename);
         header('Content-Type: application/x-zip');
         $zip->write();
         unset($zip);
         exit;
     } catch (Exception $e) {
         $this->error->set($e->getMessage());
         return false;
     }
 }
示例#5
0
 /**
  * Make a package of a template
  *
  * @param string $sId
  * @return boolean
  */
 protected function dowloadTemplate($sId)
 {
     $aTemplatesInfos = $this->getTplInfos();
     $aTplInfos = $aTemplatesInfos[$sId];
     $sFilename = $aTplInfos['id'] . '.zip';
     if (!is_dir($aTplInfos['dir']) || !is_readable($aTplInfos['dir'])) {
         return false;
     }
     try {
         set_time_limit(0);
         $fp = fopen('php://output', 'wb');
         $zip = new fileZip($fp);
         $zip->addExclusion('#(^|/).svn$#');
         $zip->addDirectory($aTplInfos['dir'], '', true);
         header('Content-Disposition: attachment;filename=' . $sFilename);
         header('Content-Type: application/x-zip');
         $zip->write();
         unset($zip);
         exit;
     } catch (Exception $e) {
         $this->okt->error->set($e->getMessage());
         return false;
     }
 }
示例#6
0
 public function process($do)
 {
     # Export a blog
     if ($do == 'export_blog' && $this->core->auth->check('admin', $this->core->blog->id)) {
         $fullname = $this->core->blog->public_path . '/.backup_' . sha1(uniqid());
         $blog_id = $this->core->con->escape($this->core->blog->id);
         try {
             $exp = new flatExport($this->core->con, $fullname, $this->core->prefix);
             fwrite($exp->fp, '///DOTCLEAR|' . DC_VERSION . "|single\n");
             $exp->export('category', 'SELECT * FROM ' . $this->core->prefix . 'category ' . "WHERE blog_id = '" . $blog_id . "'");
             $exp->export('link', 'SELECT * FROM ' . $this->core->prefix . 'link ' . "WHERE blog_id = '" . $blog_id . "'");
             $exp->export('setting', 'SELECT * FROM ' . $this->core->prefix . 'setting ' . "WHERE blog_id = '" . $blog_id . "'");
             $exp->export('post', 'SELECT * FROM ' . $this->core->prefix . 'post ' . "WHERE blog_id = '" . $blog_id . "'");
             $exp->export('meta', 'SELECT meta_id, meta_type, M.post_id ' . 'FROM ' . $this->core->prefix . 'meta M, ' . $this->core->prefix . 'post P ' . 'WHERE P.post_id = M.post_id ' . "AND P.blog_id = '" . $blog_id . "'");
             $exp->export('media', 'SELECT * FROM ' . $this->core->prefix . "media WHERE media_path = '" . $this->core->con->escape($this->core->blog->settings->system->public_path) . "'");
             $exp->export('post_media', 'SELECT media_id, M.post_id ' . 'FROM ' . $this->core->prefix . 'post_media M, ' . $this->core->prefix . 'post P ' . 'WHERE P.post_id = M.post_id ' . "AND P.blog_id = '" . $blog_id . "'");
             $exp->export('ping', 'SELECT ping.post_id, ping_url, ping_dt ' . 'FROM ' . $this->core->prefix . 'ping ping, ' . $this->core->prefix . 'post P ' . 'WHERE P.post_id = ping.post_id ' . "AND P.blog_id = '" . $blog_id . "'");
             $exp->export('comment', 'SELECT C.* ' . 'FROM ' . $this->core->prefix . 'comment C, ' . $this->core->prefix . 'post P ' . 'WHERE P.post_id = C.post_id ' . "AND P.blog_id = '" . $blog_id . "'");
             # --BEHAVIOR-- exportSingle
             $this->core->callBehavior('exportSingle', $this->core, $exp, $blog_id);
             $_SESSION['export_file'] = $fullname;
             $_SESSION['export_filename'] = $_POST['file_name'];
             $_SESSION['export_filezip'] = !empty($_POST['file_zip']);
             http::redirect($this->getURL() . '&do=ok');
         } catch (Exception $e) {
             @unlink($fullname);
             throw $e;
         }
     }
     # Export all content
     if ($do == 'export_all' && $this->core->auth->isSuperAdmin()) {
         $fullname = $this->core->blog->public_path . '/.backup_' . sha1(uniqid());
         try {
             $exp = new flatExport($this->core->con, $fullname, $this->core->prefix);
             fwrite($exp->fp, '///DOTCLEAR|' . DC_VERSION . "|full\n");
             $exp->exportTable('blog');
             $exp->exportTable('category');
             $exp->exportTable('link');
             $exp->exportTable('setting');
             $exp->exportTable('user');
             $exp->exportTable('pref');
             $exp->exportTable('permissions');
             $exp->exportTable('post');
             $exp->exportTable('meta');
             $exp->exportTable('media');
             $exp->exportTable('post_media');
             $exp->exportTable('log');
             $exp->exportTable('ping');
             $exp->exportTable('comment');
             $exp->exportTable('spamrule');
             $exp->exportTable('version');
             # --BEHAVIOR-- exportFull
             $this->core->callBehavior('exportFull', $this->core, $exp);
             $_SESSION['export_file'] = $fullname;
             $_SESSION['export_filename'] = $_POST['file_name'];
             $_SESSION['export_filezip'] = !empty($_POST['file_zip']);
             http::redirect($this->getURL() . '&do=ok');
         } catch (Exception $e) {
             @unlink($fullname);
             throw $e;
         }
     }
     # Send file content
     if ($do == 'ok') {
         if (!file_exists($_SESSION['export_file'])) {
             throw new Exception(__('Export file not found.'));
         }
         ob_end_clean();
         if (substr($_SESSION['export_filename'], -4) == '.zip') {
             $_SESSION['export_filename'] = substr($_SESSION['export_filename'], 0, -4);
             //.'.txt';
         }
         # Flat export
         if (empty($_SESSION['export_filezip'])) {
             header('Content-Disposition: attachment;filename=' . $_SESSION['export_filename']);
             header('Content-Type: text/plain; charset=UTF-8');
             readfile($_SESSION['export_file']);
             unlink($_SESSION['export_file']);
             unset($_SESSION['export_file'], $_SESSION['export_filename'], $_SESSION['export_filezip']);
             exit;
         } else {
             try {
                 $file_zipname = $_SESSION['export_filename'] . '.zip';
                 $fp = fopen('php://output', 'wb');
                 $zip = new fileZip($fp);
                 $zip->addFile($_SESSION['export_file'], $_SESSION['export_filename']);
                 header('Content-Disposition: attachment;filename=' . $file_zipname);
                 header('Content-Type: application/x-zip');
                 $zip->write();
                 unlink($_SESSION['export_file']);
                 unset($zip, $_SESSION['export_file'], $_SESSION['export_filename'], $file_zipname);
                 exit;
             } catch (Exception $e) {
                 unset($zip, $_SESSION['export_file'], $_SESSION['export_filename'], $file_zipname);
                 @unlink($_SESSION['export_file']);
                 throw new Exception(__('Failed to compress export file.'));
             }
         }
     }
 }
示例#7
0
 /**
 Backups changed files before an update.
 */
 public function backup($zip_file, $zip_digests, $root, $root_digests, $dest)
 {
     if (!is_readable($zip_file)) {
         throw new Exception(__('Archive not found.'));
     }
     if (!is_readable($root_digests)) {
         @unlink($zip_file);
         throw new Exception(__('Unable to read current digests file.'));
     }
     # Stop everything if a backup already exists and can not be overrided
     if (!is_writable(dirname($dest)) && !file_exists($dest)) {
         throw new Exception(__('Root directory is not writable.'));
     }
     if (file_exists($dest) && !is_writable($dest)) {
         return false;
     }
     $b_fp = @fopen($dest, 'wb');
     if ($b_fp === false) {
         return false;
     }
     $zip = new fileUnzip($zip_file);
     $b_zip = new fileZip($b_fp);
     if (!$zip->hasFile($zip_digests)) {
         @unlink($zip_file);
         throw new Exception(__('Downloaded file seems not to be a valid archive.'));
     }
     $opts = FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES;
     $cur_digests = file($root_digests, $opts);
     $new_digests = explode("\n", $zip->unzip($zip_digests));
     $new_files = $this->getNewFiles($cur_digests, $new_digests);
     $zip->close();
     unset($opts, $cur_digests, $new_digests, $zip);
     $not_readable = array();
     if (!empty($this->forced_files)) {
         $new_files = array_merge($new_files, $this->forced_files);
     }
     foreach ($new_files as $file) {
         if (!$file || !file_exists($root . '/' . $file)) {
             continue;
         }
         try {
             $b_zip->addFile($root . '/' . $file, $file);
         } catch (Exception $e) {
             $not_readable[] = $file;
         }
     }
     # If only one file is not readable, stop everything now
     if (!empty($not_readable)) {
         $e = new Exception('Some files are not readable.', self::ERR_FILES_UNREADABLE);
         $e->bad_files = $not_readable;
         throw $e;
     }
     $b_zip->write();
     fclose($b_fp);
     $b_zip->close();
     return true;
 }
示例#8
0
 */
# Accès direct interdit
if (!defined('ON_CONFIGURATION_MODULE')) {
    die;
}
# création d'un fichier de backup
if (!empty($_GET['make_backup'])) {
    $sFilename = $sBackupFilenameBase . '-' . date('Y-m-d-H-i') . '.zip';
    $fp = fopen(OKT_ROOT_PATH . '/' . $sFilename, 'wb');
    if ($fp === false) {
        $okt->error->set(__('c_a_tools_backup_unable_write_file'));
    }
    try {
        //		@ini_set('memory_limit',-1);
        set_time_limit(0);
        $zip = new fileZip($fp);
        //$zip->addExclusion('#(^|/).(.*?)_(m|s|sq|t).jpg$#');
        $zip->addExclusion('#(^|/)_notes$#');
        $zip->addExclusion('#(^|/)_old$#');
        $zip->addExclusion('#(^|/)_source$#');
        $zip->addExclusion('#(^|/)_sources$#');
        $zip->addExclusion('#(^|/).svn$#');
        $zip->addExclusion('#(^|/)oktCache$#');
        $zip->addExclusion('#(^|/)stats$#');
        $zip->addExclusion('#(^|/)' . preg_quote($sBackupFilenameBase, '#') . '(.*?).zip$#');
        $zip->addDirectory(OKT_ROOT_PATH, $sBackupFilenameBase, true);
        $zip->write();
        fclose($fp);
        $zip->close();
        $okt->redirect('configuration.php?action=tools&bakcup_done=1');
    } catch (Exception $e) {
示例#9
0
文件: media.php 项目: nikrou/dotclear
            }
        } else {
            // Move current dir at the top of list
            unset($last_dirs[array_search($recent_dir, $last_dirs)]);
            array_unshift($last_dirs, $recent_dir);
        }
        // Store new list
        $core->auth->user_prefs->interface->put('media_last_dirs', serialize($last_dirs));
    }
}
# Zip download
if (!empty($_GET['zipdl']) && $core->auth->check('media_admin', $core->blog->id)) {
    try {
        @set_time_limit(300);
        $fp = fopen('php://output', 'wb');
        $zip = new fileZip($fp);
        $zip->addExclusion('#(^|/).(.*?)_(m|s|sq|t).jpg$#');
        $zip->addDirectory($core->media->root . '/' . $d, '', true);
        header('Content-Disposition: attachment;filename=' . date('Y-m-d') . '-' . $core->blog->id . '-' . ($d ? $d : 'media') . '.zip');
        header('Content-Type: application/x-zip');
        $zip->write();
        unset($zip);
        exit;
    } catch (Exception $e) {
        $core->error->add($e->getMessage());
    }
}
# New directory
if ($dir && !empty($_POST['newdir'])) {
    try {
        $core->media->makeDir($_POST['newdir']);