Example #1
0
 public static function hook(GWF_User $user, GWF_Download $dl)
 {
     $dlid = $dl->getID();
     if ($dlid > 2) {
         return true;
     }
     $demo = $dlid == 2;
     if (false === ($row = BAIM_MC::generate($user, $demo))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     $mime = $dl->getVar('dl_mime');
     $path = $dl->getDownloadPath();
     $temp_path = GWF_PATH . 'extra/temp/baim/' . $user->getVar('user_id') . '_' . $row->getToken();
     if (!Common::isFile($path)) {
         return GWF_HTML::err('ERR_FILE_NOT_FOUND', htmlspecialchars($path));
     }
     if (Common::isFile($temp_path)) {
         if (false === unlink($temp_path)) {
             return GWF_HTML::err('ERR_WRITE_FILE', array($temp_path));
         }
     }
     if ($mime === 'application/zip') {
         if (false === copy($path, $temp_path)) {
             return GWF_HTML::err('ERR_WRITE_FILE', array($temp_path));
         }
         $have_zip = true;
     } else {
         $have_zip = false;
     }
     $zip = new GWF_ZipArchive();
     if (false === $zip->open($temp_path, GWF_ZipArchive::CREATE)) {
         return GWF_HTML::err('ERR_WRITE_FILE', array($temp_path));
     }
     if ($have_zip === false) {
         $filename = $dl->getVar('dl_filename');
         $zip->addFile($path, $filename);
         $dl->setCustomDownloadName($filename . '.zip');
     }
     if (false === $zip->addFromString('B.AiM/key.dat', self::getIniContent($row))) {
         return GWF_HTML::error('BAIM', 'The download slot is not a zip archive!');
     }
     $zip->addFromString('B.AiM/readme.txt', self::getReadmeContent($row));
     $zip->addFromString('B.AiM/release_notes.txt', self::getReleaseNotes($row));
     $zip->close();
     $dl->setCustomDownloadPath($temp_path);
     return '';
 }
Example #2
0
 private function addFiles(GWF_ZipArchive $archive, array $files)
 {
     foreach ($files as $file) {
         if (!$this->isFileWanted($file)) {
             continue;
         }
         if (!Common::isFile($file)) {
             echo GWF_HTML::err('ERR_FILE_NOT_FOUND', array(GWF_HTML::display($file)));
             return false;
         }
         if (false === $archive->addFile($file)) {
             echo GWF_HTML::err('ERR_FILE_NOT_FOUND', array(GWF_HTML::display($file)));
             return false;
         }
     }
     return true;
 }
Example #3
0
 private function templateUpgrade()
 {
     $haveError = false;
     $modules = GWF_Module::loadModulesFS();
     GWF_Module::sortModules($modules, 'module_name', 'asc');
     # No ZIP extension?
     if (!class_exists('ZipArchive', false)) {
         return $this->module->error('err_no_zip');
     }
     //		require_once 'core/inc/util/GWF_ZipArchive.php';
     # Populate the DB again
     GWF_VersionFiles::populateAll();
     # Open temp manifest file.
     $manifestName = sprintf('extra/temp/upgrade_manifest_%s_%s.gwf_manifest', $this->client->getVar('vsc_uid'), $this->datestamp);
     if (false === ($fhManifest = fopen($manifestName, 'w'))) {
         return GWF_HTML::err('ERR_WRITE_FILE', array($manifestName));
     }
     # Create ZIP
     $archive = new GWF_ZipArchive();
     $archivename = sprintf('extra/temp/upgrade_%s_%s.zip', $this->client->getVar('vsc_uid'), $this->datestamp);
     if (false === $archive->open($archivename, ZipArchive::CREATE | ZipArchive::CM_REDUCE_4)) {
         fclose($fhManifest);
         return $this->module->error('err_zip', __FILE__, __LINE__);
     }
     $files = GDO::table('GWF_VersionFiles');
     if (false === ($result = $files->queryReadAll('', 'vsf_path ASC'))) {
         //		if (false === ($result = $files->queryReadAll("vsf_date>='$this->datestamp'", "vsf_path ASC"))) {
         //		if (false === ($result = $files->queryAll())) {
         fclose($fhManifest);
         $archive->close();
         @unlink($archivename);
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     fprintf($fhManifest, 'GWF2:DATESTAMP:%s' . PHP_EOL, date('YmdHis'));
     while (false !== ($file = $files->fetchObject($result))) {
         //			echo GWF_HTML::message('VS_Upgrade', 'Adding File: '.$file->getVar('vsf_path'));
         $file instanceof GWF_VersionFiles;
         if (!$this->client->ownsModule($file->getVar('vsf_module'))) {
             continue;
         }
         if (!$this->client->ownsDesign($file->getVar('vsf_design'))) {
             continue;
         }
         $path = $file->getVar('vsf_path');
         if (!file_exists($path)) {
             $file->delete();
             continue;
         }
         if (!is_readable($path)) {
             echo GWF_HTML::err('ERR_FILE_NOT_FOUND', array($path));
             $haveError = true;
             break;
         }
         // is file new?
         $isNew = $file->getVar('vsf_date') >= $this->datestamp;
         if ($isNew) {
             // add it to archive
             if (false === $archive->addFile($path)) {
                 echo GWF_HTML::err('ERR_WRITE_FILE', array($file->getVar('vsf_path')));
                 $haveError = true;
                 break;
             }
         }
         //			echo GWF_HTML::message('VS_Upgrade', 'Added File: '.$file->getVar('vsf_path'));
         // write manifest info
         fwrite($fhManifest, $file->asManifest($isNew));
     }
     fclose($fhManifest);
     if (false === $archive->addFile($manifestName)) {
         echo GWF_HTML::err('ERR_WRITE_FILE', array($manifestName));
         $haveError = true;
     }
     if (false === $archive->close()) {
         echo GWF_HTML::err('ERR_WRITE_FILE', array($archivename));
         $haveError = true;
     }
     if (!$haveError) {
         GWF_Upload::outputFile($archivename);
     }
     // Delete stuff??
     @unlink($manifestName);
     @unlink($archivename);
     return '';
 }
Example #4
0
<?php

chdir('../../../../');
require_once 'protected/config.php';
require_once '../gwf3.class.php';
$gwf = new GWF3(getcwd(), array('website_init' => true, 'autoload_modules' => true, 'load_module' => false, 'get_user' => true, 'do_logging' => true, 'blocking' => true, 'no_session' => false, 'store_last_url' => true, 'ignore_user_abort' => true));
//GWF_Session::start();
//GWF_Language::init();
//GWF_HTML::init();
$wechall = GWF_Module::loadModuleDB('WeChall');
require_once GWF_CORE_PATH . 'module/WeChall/WC_CryptoChall.php';
$jpg_path = 'challenge/training/stegano/attachment/the.jpg';
$jpg_file = file_get_contents($jpg_path);
$solution = WC_CryptoChall::generateSolution('YouLikeAttachmentEh', true, false);
$zip_path = GWF_PATH . 'extra/temp/steganoattach/' . GWF_Session::getSessID() . '.zip';
$zip = new GWF_ZipArchive();
if (false === $zip->open($zip_path, GWF_ZipArchive::CREATE)) {
    die('zip error 1');
}
if (false === $zip->addFromString('solution.txt', $solution)) {
    die('zip error 2');
}
if (false === $zip->close()) {
    die('zip error 3');
}
$jpg_file .= file_get_contents($zip_path);
unlink($zip_path);
header('Content-Type: image/jpeg');
echo $jpg_file;
die;
Example #5
0
 private function onBundleTarget($target)
 {
     # Create ZIP
     $archive = new GWF_ZipArchive();
     $archivename = sprintf('protected/zipped/language_bundle_%s.zip', $target);
     if (false === $archive->open($archivename, ZipArchive::CREATE)) {
         return $this->module->error('err_zip', __FILE__, __LINE__);
     }
     $files = $this->getLanguageFiles($target);
     foreach ($files as $file) {
         $archive->addFile($file);
     }
     if (false === $archive->close()) {
         return $this->module->error('err_zip', __FILE__, __LINE__);
     }
     return $this->module->message('msg_bundled', array($archivename, $archive->getTotalFilesCounter()));
 }
Example #6
0
 private function onUpdateB(Module_VersionClient $module)
 {
     $archivename = $this->getArchiveName();
     $archivedir = $this->getArchiveDir();
     if (false === mkdir($archivedir, GWF_CHMOD)) {
         return GWF_HTML::err('ERR_WRITE_FILE', array($archivedir));
     }
     $archive = new GWF_ZipArchive();
     if (true !== $archive->open($archivename)) {
         return GWF_HTML::err('ERR_FILE_NOT_FOUND', array($archivename));
     }
     if (false === $archive->extractTo($archivedir)) {
         return GWF_HTML::err('ERR_WRITE_FILE', array($archivedir));
     }
     if (false === $archive->close()) {
         return GWF_HTML::err('ERR_WRITE_FILE', array($archivename));
     }
     if (false !== ($error = $this->cacheManifest($module))) {
         return $error;
     }
     return $this->onUpdateC($module);
 }