Ejemplo n.º 1
0
 public function execute()
 {
     if (false === ($mod_pay = GWF_Module::getModule('Payment'))) {
         return GWF_HTML::err('ERR_MODULE_MISSING', array('Payment'));
     }
     // INIT
     $isAdmin = GWF_User::isAdminS();
     $modules = GWF_Module::loadModulesFS();
     foreach ($modules as $i => $m) {
         if (!$isAdmin) {
             if ($m->getPrice() > 100000) {
                 unset($modules[$i]);
             }
         }
     }
     GWF_Module::sortModules($modules, 'module_name', 'asc');
     $this->modules = $modules;
     // Modules to purchase
     if (false !== Common::getPost('on_order_2_x')) {
         return $this->onOrder();
     }
     // Actions
     if (Common::getPost('purchase')) {
         return $this->onPurchase();
     }
     if (false !== Common::getGet('zipper')) {
         return $this->onZip();
     }
     return $this->templatePurchase();
 }
Ejemplo n.º 2
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 '';
 }
Ejemplo n.º 3
0
 /**
  * We checked all write permissions for every file updated.
  * Now we could simply move the files around and check against the manifest.
  * @param Module_VersionClient $module
  * @return unknown_type
  */
 private function onUpdateD(Module_VersionClient $module)
 {
     $errors = 0;
     $oldFiles = 0;
     $newFiles = 0;
     $copyFiles = array();
     $dir_extracted = $this->getArchiveDir();
     foreach ($this->manifest as $mid => $manifest) {
         //			echo htmlspecialchars($manifest);
         $manifest = explode(':', $manifest);
         $isNew = $manifest[0];
         $hash = $manifest[4];
         $date = $manifest[5];
         $path = $manifest[6];
         //			var_dump('NEXT MANIFEST FILE:'.$path);
         $path = trim($path);
         $path_extracted = sprintf('%s/%s', $dir_extracted, $path);
         $hash_extracted = self::hash(file_get_contents($path_extracted));
         $path_real = $path;
         //			var_dump($path_extracted);
         //			var_dump(sprintf('%s=%s', $hash, $hash_extracted));
         if ($isNew === '1') {
             if ($hash === $hash_extracted) {
                 $copyFiles[] = $path;
                 $newFiles++;
             } else {
                 echo $module->error('err_package_broken', $path);
                 $errors++;
             }
         } else {
             // Old File
             $hash_old = self::hash(file_get_contents($path));
             if ($hash === $hash_old) {
                 $oldFiles++;
             } else {
                 echo $module->error('err_file_broken', $path);
                 $errors++;
             }
         }
     }
     if ($errors > 0) {
         return $module->error('err_update', $errors) . $this->templateUpdate($module);
     }
     foreach ($copyFiles as $path) {
         $src = $dir_extracted . '/' . $path;
         copy($src, $path);
         unlink($src);
     }
     $module->saveModuleVar('vc_datestamp', $this->datestamp);
     $back = '';
     if (false !== ($modules = GWF_Module::loadModulesFS())) {
         GWF_Module::sortModules($modules, 'module_priority', 'ASC');
         foreach ($modules as $m) {
             $m instanceof GWF_Module;
             $back .= $m->install(false);
         }
     }
     return $back . $module->message('msg_update_done', array($oldFiles, $newFiles));
 }