Exemple #1
0
 protected function decompress($local_path)
 {
     //Create filter object
     $filter = new Zend_Filter_Decompress(array('adapter' => 'Zend_Filter_Compress_Zip', 'options' => array('target' => dirname($local_path))));
     $filter->filter($local_path);
     return true;
 }
 public function descompactarAction()
 {
     $v = new Zend_Filter_Decompress(array('adapter' => 'Zip', 'options' => array('target' => 'D:\\aula')));
     $descompactar = $v->filter('D:\\arquivo.zip');
     var_dump($descompactar);
     exit;
 }
 public function descomprimir()
 {
     $filter = new Zend_Filter_Compress('Bz2');
     $compressed = $filter->filter('a:2:{s:4:"type";s:15:"MultiLineString";s:11:"coordinates";a:1:{i:0;a:25:{i:0;a:2:{i:0;d:323073.5208;i:1;d:6410523.3888999997;}i:1;a:2:{i:0;d:323000.85610000044;i:1;d:6410506.2089999998;}i:2;a:2:{i:0;d:322934.71009999979;i:1;d:6410512.8235999998;}i:3;a:2:{i:0;d:322875.17879999988;i:1;d:6410559.1257999996;}i:4;a:2:{i:0;d:322795.80360000022;i:1;d:6410631.8864000002;}i:5;a:2:{i:0;d:322718.0833;i:1;d:6410696.3888999997;}i:6;a:2:{i:0;d:322689.11459999997;i:1;d:6410711.8888999997;}i:7;a:2:{i:0;d:322456.5208;i:1;d:6410836.8888999997;}i:8;a:2:{i:0;d:322402.1458;i:1;d:6410989.8888999997;}i:9;a:2:{i:0;d:322379.08399999997;i:1;d:6411041.9912999999;}i:10;a:2:{i:0;d:322332.7818;i:1;d:6411088.2934999997;}i:11;a:2:{i:0;d:322272.30209999997;i:1;d:6411109.3888999997;}i:12;a:2:{i:0;d:322220.33370000031;i:1;d:6411088.2934999997;}i:13;a:2:{i:0;d:322200.48990000039;i:1;d:6411088.2934999997;}i:14;a:2:{i:0;d:322154.18769999966;i:1;d:6411114.7518999996;}i:15;a:2:{i:0;d:322107.88559999969;i:1;d:6411154.4395000003;}i:16;a:2:{i:0;d:322054.96879999997;i:1;d:6411174.2833000002;}i:17;a:2:{i:0;d:321943.61459999997;i:1;d:6411188.8888999997;}i:18;a:2:{i:0;d:321863.14549999963;i:1;d:6411233.8146000002;}i:19;a:2:{i:0;d:321830.07249999978;i:1;d:6411286.7313999999;}i:20;a:2:{i:0;d:321783.77029999997;i:1;d:6411346.2627999997;}i:21;a:2:{i:0;d:321677.93680000026;i:1;d:6411366.1065999996;}i:22;a:2:{i:0;d:321605.17619999964;i:1;d:6411419.0232999995;}i:23;a:2:{i:0;d:321494.05209999997;i:1;d:6411447.3888999997;}i:24;a:2:{i:0;d:321387.3333;i:1;d:6411434.3888999997;}}}}');
     $filter = new Zend_Filter_Decompress('Bz2');
     $decompressed = $filter->filter($compressed);
     echo $decompressed;
 }
Exemple #4
0
 /**
  * Defined by Zend_Filter_Interface
  *
  * Decrypts $value with the defined settings
  *
  * @param  string $value Content to decrypt
  * @return string The decrypted content
  * @throws Zend_Filter_Exception
  */
 public function decrypt($value)
 {
     $decrypted = "";
     $envelope = current($this->getEnvelopeKey());
     if (count($this->_keys['private']) !== 1) {
         require_once 'Zend/Filter/Exception.php';
         throw new Zend_Filter_Exception('Please give a private key for decryption with Openssl');
     }
     if (!$this->_package && empty($envelope)) {
         require_once 'Zend/Filter/Exception.php';
         throw new Zend_Filter_Exception('Please give a envelope key for decryption with Openssl');
     }
     foreach ($this->_keys['private'] as $key => $cert) {
         $keys = openssl_pkey_get_private($cert, $this->getPassphrase());
     }
     if ($this->_package) {
         $details = openssl_pkey_get_details($keys);
         if ($details !== false) {
             $fingerprint = md5($details['key']);
         } else {
             $fingerprint = md5("ZendFramework");
         }
         $count = unpack('ncount', $value);
         $count = $count['count'];
         $length = 2;
         for ($i = $count; $i > 0; --$i) {
             $header = unpack('H32print/nsize', substr($value, $length, 18));
             $length += 18;
             if ($header['print'] == $fingerprint) {
                 $envelope = substr($value, $length, $header['size']);
             }
             $length += $header['size'];
         }
         // remainder of string is the value to decrypt
         $value = substr($value, $length);
     }
     $crypt = openssl_open($value, $decrypted, $envelope, $keys);
     openssl_free_key($keys);
     if ($crypt === false) {
         require_once 'Zend/Filter/Exception.php';
         throw new Zend_Filter_Exception('Openssl was not able to decrypt you content with the given options');
     }
     // decompress after decryption
     if (!empty($this->_compression)) {
         require_once 'Zend/Filter/Decompress.php';
         $decompress = new Zend_Filter_Decompress($this->_compression);
         $decrypted = $decompress->filter($decrypted);
     }
     return $decrypted;
 }
Exemple #5
0
 /**
  * Defined by Zend_Filter_Interface
  *
  * Decrypts $value with the defined settings
  *
  * @param  string $value Content to decrypt
  * @return string The decrypted content
  */
 public function decrypt($value)
 {
     $cipher = $this->_openCipher();
     $this->_initCipher($cipher);
     $decrypted = mdecrypt_generic($cipher, $value);
     mcrypt_generic_deinit($cipher);
     $this->_closeCipher($cipher);
     // decompress after decryption
     if (!empty($this->_compression)) {
         #require_once 'Zend/Filter/Decompress.php';
         $decompress = new Zend_Filter_Decompress($this->_compression);
         $decrypted = $decompress->filter($decrypted);
     }
     return $decrypted;
 }
Exemple #6
0
 /**
  * Decompress a given plugin zip file.
  *
  * @param  $file
  */
 public function decompressFile($file)
 {
     $target = Shopware()->AppPath('Plugins_Community');
     $filter = new Zend_Filter_Decompress(array(
         'adapter' => 'Zip',
         'options' => array(
             'target' => $target
         )
     ));
     $filter->filter($file);
 }
Exemple #7
0
 /**
  * The client sends the results to Midas Server (put request).
  *
  * @param token
  *
  * @param array $args parameters
  * @throws Exception
  */
 public function resultsserver($args)
 {
     $testingmode = false;
     if (isset($_GET['testingmode']) && $_GET['testingmode'] == 1) {
         $testingmode = true;
     }
     if (!$testingmode && $_SERVER['REQUEST_METHOD'] != 'POST') {
         throw new Exception('Should be a put request.', MIDAS_INVALID_PARAMETER);
     }
     $authComponent = MidasLoader::loadComponent('Authentication');
     $userDao = $authComponent->getUser($args, Zend_Registry::get('userSession')->Dao);
     if ($userDao == false) {
         throw new Exception('Unable to authenticate as a server. Please check credentials.', MIDAS_INVALID_PARAMETER);
     }
     /** @var GroupModel $groupModel */
     $groupModel = MidasLoader::loadModel('Group');
     $groupServer = $groupModel->load(MIDAS_GROUP_SERVER_KEY);
     $users = $groupServer->getUsers();
     $isServer = false;
     foreach ($users as $user) {
         if ($user->getKey() == $userDao->getKey()) {
             $isServer = true;
         }
     }
     if ($isServer == false) {
         throw new Exception('Unable to authenticate as a server. Please check credentials.', MIDAS_INVALID_PARAMETER);
     }
     if (!file_exists(UtilityComponent::getTempDirectory() . '/remoteprocessing')) {
         mkdir(UtilityComponent::getTempDirectory() . '/remoteprocessing');
     }
     /** @var RandomComponent $randomComponent */
     $randomComponent = MidasLoader::loadComponent('Random');
     $destination = UtilityComponent::getTempDirectory() . '/remoteprocessing/' . $randomComponent->generateInt();
     while (file_exists($destination)) {
         $destination = UtilityComponent::getTempDirectory() . '/remoteprocessing/' . $randomComponent->generateInt();
     }
     mkdir($destination);
     if (!$testingmode) {
         move_uploaded_file($_FILES['file']['tmp_name'], $destination . '/results.zip');
     }
     if ($testingmode) {
         return array();
     }
     if (file_exists($destination . '/results.zip')) {
         mkdir($destination . '/content');
         $target_directory = $destination . '/content';
         $filter = new Zend_Filter_Decompress(array('adapter' => 'Zip', 'options' => array('target' => $target_directory)));
         $compressed = $filter->filter($destination . '/results.zip');
         if ($compressed && file_exists($target_directory . '/parameters.txt')) {
             $info = file_get_contents($target_directory . '/parameters.txt');
             $info = JsonComponent::decode($info);
             $job_id = $info['job_id'];
             /** @var Remoteprocessing_JobModel $jobModel */
             $jobModel = MidasLoader::loadModel('Job', 'remoteprocessing');
             $jobDao = $jobModel->load($job_id);
             $jobDao->setStatus(MIDAS_REMOTEPROCESSING_STATUS_DONE);
             $jobModel->save($jobDao);
             $info['pathResults'] = $destination . '/content';
             $info['log'] = file_get_contents($target_directory . '/log.txt');
             $info['userKey'] = $userDao->getKey();
             Zend_Registry::get('notifier')->callback($info['resultCallback'], $info);
         } else {
             throw new Exception('Error, unable to unzip results.', MIDAS_INVALID_PARAMETER);
         }
     } else {
         throw new Exception('Error, unable to find results.', MIDAS_INVALID_PARAMETER);
     }
     $this->_rrmdir($destination);
     return array();
 }
Exemple #8
0
 /**
  * Helper function to decompress zip files.
  * @param UploadedFile $file
  * @param $targetDirectory
  * @throws Exception
  */
 private function unzip(UploadedFile $file, $targetDirectory)
 {
     $filter = new \Zend_Filter_Decompress(array('adapter' => $file->getClientOriginalExtension(), 'options' => array('target' => $targetDirectory)));
     $filter->filter($file->getPath() . DIRECTORY_SEPARATOR . $file->getFilename());
 }
 /**
  * Basic usage
  *
  * @return void
  */
 public function testDecompressArchive()
 {
     $filter = new Zend_Filter_Decompress('bz2');
     $archive = dirname(__FILE__) . '/../_files/compressed.bz2';
     $filter->setArchive($archive);
     $content = $filter->compress('compress me');
     $this->assertTrue($content);
     $filter2 = new Zend_Filter_Decompress('bz2');
     $content2 = $filter2->filter($archive);
     $this->assertEquals('compress me', $content2);
 }
 private static function _updateAddOnFiles($addOnId, $tempFile)
 {
     $tempDir = $tempFile . '_extracted';
     XenForo_Helper_File::createDirectory($tempDir, false);
     XenForo_Helper_File::makeWritableByFtpUser($tempDir);
     $decompress = new Zend_Filter_Decompress(array('adapter' => 'Zip', 'options' => array('target' => $tempDir)));
     if (!$decompress->filter($tempFile)) {
         throw new XenForo_Exception('Unable to extract add-on package.', true);
     }
     $uploadDir = sprintf('%s/upload', $tempDir);
     if (!is_dir($uploadDir)) {
         throw new XenForo_Exception('Unsupported add-on package (no "upload" directory found).', true);
     }
     $xfDir = dirname(XenForo_Autoloader::getInstance()->getRootDir());
     $files = self::_verifyAddOnFiles($uploadDir, $xfDir);
     $xmlPath = self::_findXmlPath($addOnId, $tempDir, $xfDir, $files);
     self::_moveAddOnFiles($uploadDir, $xfDir, $files);
     return $xmlPath;
 }
 /**
  * Prepara el archivo y lo coloca en directorio temporal
  * @param string $hash
  */
 public function setFileHash($hash)
 {
     $this->_hash = $hash;
     $cache = Cache::iniciar();
     if ($this->_file_info = $cache->load($hash)) {
         $this->_dir_temp .= $this->_ci->string_core->rand_string(21);
         mkdir($this->_dir_temp, 0755);
         file_put_contents($this->_dir_temp . "/" . $this->_file_info["archivo_nombre"], $this->_file_info["archivo"]);
         if ($this->_file_info["tipo"] == "kmz") {
             $filter = new Zend_Filter_Decompress(array('adapter' => 'Zip', 'options' => array('target' => $this->_dir_temp)));
             $compressed = $filter->filter($this->_dir_temp . "/" . $this->_file_info["archivo_nombre"]);
             if ($compressed) {
                 unlink($this->_dir_temp . "/" . $this->_file_info["archivo_nombre"]);
             }
         }
     }
 }
Exemple #12
0
 /**
  * Decompress a given plugin zip file.
  *
  * @param        $file
  * @param string $source
  * @throws Enlight_Exception
  */
 public function decompressFile($file, $source = 'Community')
 {
     $target = Shopware()->AppPath('Plugins_' . $source);
     if (!$this->isPluginDirectoryWritable($target, true)) {
         throw new Enlight_Exception("A directory or a file in " . $target . " is not writable, please change the permissions recursively");
     }
     $filter = new Zend_Filter_Decompress(array('adapter' => 'Zip', 'options' => array('target' => $target)));
     $filter->filter($file);
 }
Exemple #13
0
 public function unPack()
 {
     $response = array('success' => false);
     $files = explode(':', $this->_data['file']);
     $path = $this->cfg['path'] . $this->_data['dirPath'];
     //
     require_once 'Zend' . DIR_SEP . 'Filter.php';
     require_once 'Zend' . DIR_SEP . 'Filter' . DIR_SEP . 'Decompress.php';
     $ext = $this->_substr($files[0], $this->_strrpos($files[0], '.') + 1);
     $ext = $this->_strtolower($ext);
     $filter = new Zend_Filter_Decompress(array('adapter' => ucfirst($ext), 'options' => array('target' => $path)));
     $result = $filter->filter($path . $files[0]);
     false === $result ? $response['success'] = false : ($response['success'] = true);
     return $response;
 }
 public function addZipAction()
 {
     parent::postDispatch();
     $auth = Zend_Auth::getInstance();
     if (!$auth->hasIdentity()) {
         $this->redirect('/auth');
     }
     $adapter = new Zend_File_Transfer_Adapter_Http();
     $dbTable = new Application_Model_DbTable_Block();
     $options = array('ignoreNoFile' => true);
     $adapter->setOptions($options);
     $lastText = $dbTable->getTextById($_GET['id']);
     $this->view->block = $lastText;
     if (isset($_POST['submit'])) {
         // Enviar a atualização para o banco.
         $adapter->setDestination('c:/teste');
         $link_file = $adapter->getFileName();
         $name_file = $adapter->getFileName(null, false);
         $dbTable->update(array('date' => date('Y-m-d H:i:s'), 'name_file' => "{$name_file}", 'link_file' => "{$link_file}"), array('id = ? ' => $_GET['id']));
         $filter = new Zend_Filter_Decompress(array('adapter' => 'Zip', 'options' => array('target' => 'C:/teste/decompress')));
         $filter->filter($link_file);
         $adapter->receive();
         header('Location: ../');
     }
 }