Ejemplo n.º 1
0
 public function extract($archive, $destination, $options = array())
 {
     // Initialise variables.
     $this->_data = null;
     $this->_metadata = null;
     if (!($this->_data = MFile::read($archive))) {
         $this->set('error.message', 'Unable to read archive');
         return MError::raiseWarning(100, $this->get('error.message'));
     }
     if (!$this->_getTarInfo($this->_data)) {
         return MError::raiseWarning(100, $this->get('error.message'));
     }
     for ($i = 0, $n = count($this->_metadata); $i < $n; $i++) {
         $type = strtolower($this->_metadata[$i]['type']);
         if ($type == 'file' || $type == 'unix file') {
             $buffer = $this->_metadata[$i]['data'];
             $path = MPath::clean($destination . '/' . $this->_metadata[$i]['name']);
             // Make sure the destination folder exists
             if (!MFolder::create(dirname($path))) {
                 $this->set('error.message', 'Unable to create destination');
                 return MError::raiseWarning(100, $this->get('error.message'));
             }
             if (MFile::write($path, $buffer) === false) {
                 $this->set('error.message', 'Unable to write entry');
                 return MError::raiseWarning(100, $this->get('error.message'));
             }
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 public function extract($archive, $destination, $options = array())
 {
     // Initialise variables.
     $this->_data = null;
     if (!extension_loaded('bz2')) {
         $this->set('error.message', MText::_('MLIB_FILESYSTEM_BZIP_NOT_SUPPORTED'));
         return MError::raiseWarning(100, $this->get('error.message'));
     }
     if (!isset($options['use_streams']) || $options['use_streams'] == false) {
         // Old style: read the whole file and then parse it
         if (!($this->_data = MFile::read($archive))) {
             $this->set('error.message', 'Unable to read archive');
             return MError::raiseWarning(100, $this->get('error.message'));
         }
         $buffer = bzdecompress($this->_data);
         unset($this->_data);
         if (empty($buffer)) {
             $this->set('error.message', 'Unable to decompress data');
             return MError::raiseWarning(100, $this->get('error.message'));
         }
         if (MFile::write($destination, $buffer) === false) {
             $this->set('error.message', 'Unable to write archive');
             return MError::raiseWarning(100, $this->get('error.message'));
         }
     } else {
         // New style! streams!
         $input = MFactory::getStream();
         $input->set('processingmethod', 'bz');
         // use bzip
         if (!$input->open($archive)) {
             $this->set('error.message', MText::_('MLIB_FILESYSTEM_BZIP_UNABLE_TO_READ'));
             return MError::raiseWarning(100, $this->get('error.message'));
         }
         $output = MFactory::getStream();
         if (!$output->open($destination, 'w')) {
             $this->set('error.message', MText::_('MLIB_FILESYSTEM_BZIP_UNABLE_TO_WRITE'));
             $input->close();
             // close the previous file
             return MError::raiseWarning(100, $this->get('error.message'));
         }
         do {
             $this->_data = $input->read($input->get('chunksize', 8196));
             if ($this->_data) {
                 if (!$output->write($this->_data)) {
                     $this->set('error.message', MText::_('MLIB_FILESYSTEM_BZIP_UNABLE_TO_WRITE_FILE'));
                     return MError::raiseWarning(100, $this->get('error.message'));
                 }
             }
         } while ($this->_data);
         $output->close();
         $input->close();
     }
     return true;
 }
Ejemplo n.º 3
0
 public function _replacePrefix($query)
 {
     $mainframe = MFactory::getApplication();
     $msg = '';
     $config_file = MPATH_CONFIGURATION . '/configuration.php';
     list($prefix, $new_prefix) = sscanf(str_replace(array('`', '"', "'"), '', strtolower(trim($query))), "replace prefix %s to %s");
     if (!is_writable($config_file)) {
         echo '<h2 style="color: red;">' . sprintf(MText::_('COM_MIWOSQL_CONFIG_NOT_WRITABLE'), $config_fname) . '</h2>';
         return $msg;
     }
     $this->_db->setQuery("SHOW TABLES LIKE '" . $prefix . "%'");
     $tables = $this->_db->loadResultArray();
     foreach ($tables as $tbl) {
         $new_tbl = str_replace($prefix, $new_prefix, $tbl);
         $this->_db->setQuery('ALTER TABLE `' . $tbl . '` RENAME `' . $new_tbl . '`');
         $this->_db->query();
         if (!empty($this->_db->_errorMsg)) {
             echo '<small style="color:red;">' . $this->_db->_errorMsg . '</small><br/>';
         }
     }
     $config = MFactory::getConfig();
     if (version_compare(MVERSION, '1.6.0', 'ge')) {
         $config->set('dbprefix', $new_prefix);
     } else {
         $config->setValue('config.dbprefix', $new_prefix);
     }
     /*jimport('joomla.filesystem.path');
      	if (!$ftp['enabled'] && MPath::isOwner($config_fname) && !MPath::setPermissions($config_fname, '0644')) {
      		MError::raiseNotice('SOME_ERROR_CODE', 'Could not make configuration.php writable');
      	}*/
     mimport('framwork.filesystem.file');
     if (version_compare(MVERSION, '1.6.0', 'ge')) {
         if (!MFile::write($config_file, $config->toString('PHP', array('class' => 'MConfig', 'closingtag' => false)))) {
             $msg = MText::_('COM_MIWOSQL_DONE');
         } else {
             $msg = MText::_('ERRORCONFIGFILE');
         }
     } else {
         if (MFile::write($config_file, $config->toString('PHP', 'config', array('class' => 'MConfig')))) {
             $msg = MText::_('COM_MIWOSQL_DONE');
         } else {
             $msg = MText::_('ERRORCONFIGFILE');
         }
     }
     return $msg;
 }
Ejemplo n.º 4
0
 public static function isOwner($path)
 {
     mimport('framework.filesystem.file');
     $tmp = md5(MUserHelper::genRandomPassword(16));
     $ssp = ini_get('session.save_path');
     $jtp = MPATH_SITE . '/tmp';
     // Try to find a writable directory
     $dir = is_writable('/tmp') ? '/tmp' : false;
     $dir = !$dir && is_writable($ssp) ? $ssp : false;
     $dir = !$dir && is_writable($jtp) ? $jtp : false;
     if ($dir) {
         $test = $dir . '/' . $tmp;
         // Create the test file
         $blank = '';
         MFile::write($test, $blank, false);
         // Test ownership
         $return = fileowner($test) == fileowner($path);
         // Delete the test file
         MFile::delete($test);
         return $return;
     }
     return false;
 }
Ejemplo n.º 5
0
 private function _createZIPFile(&$contents, &$ctrlDir, $path)
 {
     $data = implode('', $contents);
     $dir = implode('', $ctrlDir);
     $buffer = $data . $dir . $this->_ctrlDirEnd . pack('v', count($ctrlDir)) . pack('v', count($ctrlDir)) . pack('V', strlen($dir)) . pack('V', strlen($data)) . "";
     if (MFile::write($path, $buffer) === false) {
         return false;
     } else {
         return true;
     }
 }