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 ''; }
public function onZipC() { # Create ZIP $archive = new GWF_ZipArchive(); chdir(GWF_PATH); $archivename = $this->getArchiveName(); if (false === $archive->open($archivename, ZipArchive::CREATE | ZipArchive::CM_REDUCE_4)) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # ZIP STUFF # Core if (false === $this->zipDir($archive, 'core/inc')) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # ZIP Module(Groups) foreach ($_POST as $group => $checked) { if (!Common::startsWith($group, 'mod_')) { continue; } # zip dir recursive, do not ignore style if (false === $this->zipDir($archive, 'core/module/' . substr($group, 4), true, false)) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } } # 3rd Party Core // if (false === ($this->zipDir($archive, 'inc3p'))) { // return $this->module->error('err_zip', array(__FILE__, __LINE__)); // } # Smarty // if (false === ($this->zipDir($archive, 'smarty_lib'))) { // return $this->module->error('err_zip', array(__FILE__, __LINE__)); // } # JS if (false === $this->zipDir($archive, 'www/js')) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # Installer if (false === $this->zipDir($archive, 'www/install')) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # Base Lang if (false === $this->zipDir($archive, 'core/lang')) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # Images if (false === $this->zipDir($archive, 'www/img', false)) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } // if (false === ($this->zipDir($archive, 'img/default/country', false))) { // return $this->module->error('err_zip', array(__FILE__, __LINE__)); // } // if (false === ($this->zipDir($archive, 'img/default/smile', false))) { // return $this->module->error('err_zip', array(__FILE__, __LINE__)); // } # Temp if (false === $this->addEmptyDirs($archive, self::$tempdirs)) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # Fonts if (false === $this->zipDir($archive, 'extra/font')) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # Templates if (false === $this->zipDir($archive, 'www/tpl', true, false)) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # Root Files if (false === $this->addFiles($archive, self::$rootfiles)) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # Protected Dirs // if (false === $this->zipDirs($archive, self::$protected_dirs)) { // return $this->module->error('err_zip', array(__FILE__, __LINE__)); // } # Protected Files if (false === $this->addFiles($archive, self::$protected_files)) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } # Module Extra Files and Dirs if (false === $this->zipDirs($archive, $this->getModuleExtraDirs())) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } if (false === $this->addFiles($archive, $this->getModuleExtraFiles())) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } // chdir(GWF_WWW_PATH); $total_files = $archive->getTotalFilesCounter(); if (false === $archive->close()) { return $this->module->error('err_zip', array(__FILE__, __LINE__)); } $this->has_error = false; return $this->module->message('msg_zipped', array($archivename, GWF_Upload::humanFilesize(filesize($archivename)), $total_files)); }
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 ''; }
<?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;
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())); }
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); }