예제 #1
0
파일: model.php 프로젝트: fanscky/HTPMS
 /**
  * Restore File 
  * 
  * @param  string    $backupFile 
  * @access public
  * @return object
  */
 public function restoreFile($backupFile)
 {
     $return = new stdclass();
     $return->result = true;
     $return->error = '';
     $this->app->loadClass('pclzip', true);
     $zip = new pclzip($backupFile);
     if ($zip->extract(PCLZIP_OPT_PATH, $this->app->getAppRoot() . 'www/data/') == 0) {
         $return->result = false;
         $return->error = $zip->errorInfo();
     }
     return $return;
 }
예제 #2
0
파일: model.php 프로젝트: iamazhi/zentaopms
 /**
  * Extract an extension.
  * 
  * @param  string    $extension 
  * @access public
  * @return object
  */
 public function extractPackage($extension)
 {
     $return = new stdclass();
     $return->result = 'ok';
     $return->error = '';
     /* try remove pre extracted files. */
     $extensionPath = "ext/{$extension}";
     if (is_dir($extensionPath)) {
         $this->classFile->removeDir($extensionPath);
     }
     /* Extract files. */
     $packageFile = $this->getPackageFile($extension);
     $this->app->loadClass('pclzip', true);
     $zip = new pclzip($packageFile);
     $files = $zip->listContent();
     $removePath = $files[0]['filename'];
     if ($zip->extract(PCLZIP_OPT_PATH, $extensionPath, PCLZIP_OPT_REMOVE_PATH, $removePath) == 0) {
         $return->result = 'fail';
         $return->error = $zip->errorInfo(true);
     }
     return $return;
 }
예제 #3
0
$dbRawFile = "db." . date('Ymd') . ".sql";
$password = $config->db->password ? "-p{$config->db->password}" : ' ';
$command = "\"{$mysqldump}\" -u{$config->db->user} {$password} -P {$config->db->port} {$config->db->name} > {$dbRawFile}";
echo "Backup command: " . $command . "\n";
echo "Backuping database,";
system($command, $return);
if ($return == 0) {
    $dbZipFile = $destDir . "/" . str_replace("sql", "zip", $dbRawFile);
    $archive = new pclzip($dbZipFile);
    if ($archive->create($dbRawFile)) {
        unlink($dbRawFile);
        echo " successfully saved to {$dbZipFile}\n";
    } else {
        die("Error : " . $archive->errorInfo(true));
    }
} else {
    echo "Failed to backup database!\n";
}
/* Backup the attachments. */
chdir(dirname(dirname(dirname(__FILE__))) . "/www");
if (!is_dir('data/upload')) {
    die(" No files needed backup.\n");
}
echo "Backuping files,";
$attachFile = $destDir . "/" . "file." . date('Ymd', time()) . ".zip";
$archive = new pclzip($attachFile);
if ($archive->create("data/upload", PCLZIP_OPT_REMOVE_PATH, "data")) {
    die(" successfully saved to {$attachFile}\n");
}
die("Error : " . $archive->errorInfo(true));
예제 #4
0
파일: control.php 프로젝트: XMGmen/zentao
 /**
  * Down notify.
  * 
  * @access public
  * @return void
  */
 public function downNotify()
 {
     $notifyDir = $this->app->getBasePath() . 'www/data/notify/';
     $packageFile = $notifyDir . 'notify.zip';
     $loginFile = $notifyDir . 'config.json';
     /* write login info into tmp file. */
     $loginInfo = new stdclass();
     $userInfo = new stdclass();
     $userInfo->Account = $this->app->user->account;
     $userInfo->Url = common::getSysURL() . $this->config->webRoot;
     $userInfo->PassMd5 = '';
     $userInfo->Role = $this->app->user->role;
     $userInfo->AutoSignIn = true;
     $userInfo->Lang = $this->cookie->lang;
     $loginInfo->User = $userInfo;
     $loginInfo->LastLoginTime = time() / 86400 + 25569;
     $loginInfo = json_encode($loginInfo);
     file_put_contents($loginFile, $loginInfo);
     define('PCLZIP_TEMPORARY_DIR', $notifyDir);
     $this->app->loadClass('pclzip', true);
     /* remove the old config.json, add a new one. */
     $archive = new pclzip($packageFile);
     $result = $archive->delete(PCLZIP_OPT_BY_NAME, 'config.json');
     if ($result == 0) {
         die("Error : " . $archive->errorInfo(true));
     }
     $result = $archive->add($loginFile, PCLZIP_OPT_REMOVE_ALL_PATH);
     if ($result == 0) {
         die("Error : " . $archive->errorInfo(true));
     }
     unlink($loginFile);
     $this->fetch('file', 'sendDownHeader', array('fileName' => 'notify.zip', 'zip', file_get_contents($packageFile)));
     $result = $archive->delete(PCLZIP_OPT_BY_NAME, 'config.json');
     if ($result == 0) {
         die("Error : " . $archive->errorInfo(true));
     }
 }
예제 #5
0
 /**
  * Down notify.
  * 
  * @access public
  * @return void
  */
 public function downNotify()
 {
     $notifyDir = $this->app->getBasePath() . 'www/data/notify/';
     $packageFile = $notifyDir . 'notify.zip';
     $tmpDir = $notifyDir . 'notify';
     $loginFile = $tmpDir . '/notify/logininfo';
     $this->app->loadClass('pclzip', true);
     $sourceZip = new pclzip($packageFile);
     $files = $sourceZip->extract(PCLZIP_OPT_PATH, $notifyDir);
     if ($files == 0) {
         die("Error : " . $sourceZip->errorInfo(true));
     }
     $loginInfo = new stdclass();
     $loginInfo->account = $this->app->user->account;
     $loginInfo->password = $this->app->user->password;
     $loginInfo->zentaoRoot = common::getSysURL() . $this->config->webRoot;
     $loginInfo = json_encode($loginInfo);
     file_put_contents($loginFile, $loginInfo);
     unlink($packageFile);
     $newZip = new pclzip($packageFile);
     if ($newZip->create($tmpDir, PCLZIP_OPT_REMOVE_PATH, $notifyDir)) {
         $this->zfile = $this->app->loadClass('zfile');
         $this->zfile->removeDir($tmpDir);
     }
     $this->fetch('file', 'sendDownHeader', array('fileName' => 'notify.zip', 'zip', file_get_contents($packageFile)));
 }
예제 #6
0
         $file = fopen($filename, "w");
         foreach ($unitIDs as $unitID) {
             fwrite($file, trim($unitID) . "\n");
         }
         fclose($file);
         $tpl->show();
     }
 } elseif (array_key_exists(DTX_COOKIE_NAME . "_project", $_COOKIE)) {
     // Step 3: The last cookie is the project Id cookie, so we know
     // that we can create the zip file from the dtx files.
     // create zip
     $zipname = tempnam("", "jh_");
     $zip = new pclzip($zipname);
     $addResult = $zip->add($outDirName . "/", PCLZIP_OPT_REMOVE_ALL_PATH);
     if ($addResult == 0) {
         $msg = "Error creating zip file:" . $zip->errorInfo(true);
         $tpl->SetVariable("MESSAGE", $msg);
         $tpl->Show();
     } else {
         $projectInfos = GetProjectInfos($_COOKIE[DTX_COOKIE_NAME . "_project"]);
         $filename = $projectInfos["Name"] . ".zip";
         // we have the zip, send it
         header("Content-Type: archive/zip");
         // replace by text/plain for debug
         header('Content-Disposition: attachment; filename="' . $filename . '"');
         // don't use file_get_contents, it might be too recent
         //        echo file_get_contents($zipname);
         $file = fopen($zipname, "rb");
         while (!feof($file)) {
             echo fread($file, 1024);
         }
예제 #7
0
 /**
  * Extract template package.
  * 
  * @param  string    $package 
  * @access public
  * @return void
  */
 public function extractPackage($package)
 {
     $packageFile = $this->app->getDataRoot() . "template/{$package}.zip";
     $this->app->loadClass('pclzip', true);
     $zip = new pclzip($packageFile);
     $files = $zip->listContent();
     $tempPath = $this->app->getDataRoot() . 'template/' . $package . DS;
     if (is_dir($tempPath)) {
         $fileClass = $this->app->loadClass('zfile');
         $fileClass->removeDir($tempPath);
     }
     $return = new stdclass();
     $removePath = $files[0]['filename'];
     if ($zip->extract(PCLZIP_OPT_PATH, $tempPath, PCLZIP_OPT_REMOVE_PATH, $removePath) == 0) {
         $return->result = 'fail';
         $return->error = $zip->errorInfo(true);
     }
     return true;
 }