Exemplo n.º 1
0
 /**
  * Download and install
  */
 function install($id, $url)
 {
     if (!is_string($url)) {
         return JText::_('NNEM_ERROR_NO_VALID_URL');
     }
     $url = 'http://' . str_replace('http://', '', $url);
     if (!($target = JInstallerHelper::downloadPackage($url))) {
         return JText::_('NNEM_ERROR_CANNOT_DOWNLOAD_FILE');
     }
     $target = JFactory::getConfig()->get('tmp_path') . '/' . $target;
     NNFrameworkFunctions::loadLanguage('com_installer', JPATH_ADMINISTRATOR);
     jimport('joomla.installer.installer');
     jimport('joomla.installer.helper');
     // Get an installer instance
     $installer = JInstaller::getInstance();
     // Unpack the package
     $package = JInstallerHelper::unpack($target);
     // Cleanup the install files
     if (!is_file($package['packagefile'])) {
         $config = JFactory::getConfig();
         $package['packagefile'] = $config->get('tmp_path') . '/' . $package['packagefile'];
     }
     JInstallerHelper::cleanupInstall($package['packagefile'], $package['packagefile']);
     // Install the package
     if (!$installer->install($package['dir'])) {
         // There was an error installing the package
         return JText::sprintf('COM_INSTALLER_INSTALL_ERROR', JText::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type'])));
     }
     return true;
 }
Exemplo n.º 2
0
 function postflight($type, $parent)
 {
     $url = "http://www.jhackguard.com/downloads/com_jhackguard.zip";
     // Download the package at the URL given
     $p_file = JInstallerHelper::downloadPackage($url);
     // Was the package downloaded?
     if (!$p_file) {
         JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_INVALID_URL'));
         return false;
     }
     $config = JFactory::getConfig();
     $tmp_dest = $config->get('tmp_path');
     // Unpack the downloaded package file
     $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file, true);
     // Was the package unpacked?
     if (!$package || !$package['type']) {
         if (in_array($installType, array('upload', 'url'))) {
             JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
         }
         $app->setUserState('com_installer.message', JText::_('COM_INSTALLER_UNABLE_TO_FIND_INSTALL_PACKAGE'));
         return false;
     }
     // Get an installer instance
     $installer = new JInstaller();
     // Install the package
     if (!$installer->install($package['dir'])) {
         // There was an error installing the package
         $msg = JText::sprintf('COM_INSTALLER_INSTALL_ERROR', JText::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type'])));
         $result = false;
     } else {
         // Package installed sucessfully
         $msg = JText::sprintf('COM_INSTALLER_INSTALL_SUCCESS', JText::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type'])));
         $result = true;
     }
     // Set some model state values
     $app = JFactory::getApplication();
     $app->enqueueMessage($msg);
     $app->setUserState('com_installer.message', $installer->message);
     $app->setUserState('com_installer.extension_message', $installer->get('extension_message'));
     $app->setUserState('com_installer.redirect_url', $installer->get('redirect_url'));
     // Cleanup the install files
     if (!is_file($package['packagefile'])) {
         $config = JFactory::getConfig();
         $package['packagefile'] = $config->get('tmp_path') . '/' . $package['packagefile'];
     }
     JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
     $app->enqueueMessage("The default installation of jHackGuard has no filters included. Please download the latest filters by going to the '<b>Filter Maintenance</b>' page in the component menu.", "error");
 }
Exemplo n.º 3
0
 /**
  * Initialize all img tags to schedule image resizing via AJAX request.
  *
  * @param   string   $path            Absolute path to the directory for storing optimized image.
  * @param   integer  $maxWidth        Maximum allowed image width.
  * @param   string   $responseBody    Generated HTML response body.
  * @param   boolean  $setNewResponse  Set new response body directly or return as string.
  *
  * @return  mixed
  */
 public static function init($path, $maxWidth, $responseBody = '', $setNewResponse = true)
 {
     if (!JFolder::exists($path)) {
         JFolder::create($path);
     }
     // Initialize reponse body
     !empty($responseBody) or $responseBody = JResponse::getBody();
     // Get all img tags loaded in response body
     if (preg_match_all('#<img([^>]+)? src=("|\')([^"\']+)("|\')([^>]+)?>#i', $responseBody, $matches, PREG_SET_ORDER)) {
         foreach ($matches as $match) {
             // Image already optimized
             $replace = '';
             if (is_readable($imagePath = $path . DS . $maxWidth . DS . basename($match[3]))) {
                 // Get link to optimized image
                 $link = JURI::root(true) . str_replace(str_replace(array('/', '\\'), array('/', '/'), JPATH_ROOT), '', str_replace(array('/', '\\'), array('/', '/'), $path . DS . $maxWidth . DS . basename($match[3])));
                 // Get image dimension
                 $imageSize = @getimagesize($imagePath);
                 // Generate replacement
                 $replace = self::updateImageDimension(str_replace('src=' . $match[2] . $match[3] . $match[4], 'src=' . $match[2] . $link . $match[4], $match[0]), $imageSize[0], $imageSize[1], $match[2]);
                 // Update response body
                 $responseBody = str_replace($match[0], $replace, $responseBody);
             } else {
                 // Get image path
                 $imagePath = str_replace(array(JURI::root(), JURI::root(true)), array(JPATH_ROOT, JPATH_ROOT), $match[3]);
                 // Download remote image
                 if (substr($imagePath, 0, 5) == 'http:' or substr($imagePath, 0, 6) == 'https:') {
                     if (!($tmp = JInstallerHelper::downloadPackage($imagePath))) {
                         continue;
                     }
                     $imagePath = $path . DS . basename($tmp);
                     // Move downloaded image to the directory for storing optimized image files
                     JFile::move(JFactory::getConfig()->get('tmp_path') . DS . $tmp, $imagePath);
                 }
                 // Get image dimension
                 $imageSize = @getimagesize($imagePath);
                 if ($imageSize[0] > $maxWidth) {
                     // Replace remote image with local one if necessary
                     if (strpos($match[3], JURI::root()) !== 0 and strpos($match[3], JURI::root(true)) !== 0) {
                         // Generate replacement
                         $tmpPath = str_replace(JPATH_ROOT, JURI::root(true), $imagePath);
                         $replace[3] = str_replace('\\', '/', $tmpPath);
                         $replace[0] = str_replace($match[3], $replace[3], $match[0]);
                         // Update response body
                         $responseBody = str_replace($match[0], $replace[0], $responseBody);
                         // Update matching result
                         $match[0] = $replace[0];
                         $match[3] = $replace[3];
                     }
                     // Update response body
                     self::updateResponseBody($responseBody, $match, $path, $maxWidth, $imageSize);
                 } elseif (strpos($match[0], 'width=') === false or strpos($match[0], 'height=') === false) {
                     // Generate replacement
                     $replace = self::updateImageDimension($match[0], $imageSize[0], $imageSize[1], $match[2]);
                     // Update response body
                     $responseBody = str_replace($match[0], $replace, $responseBody);
                 }
             }
         }
     }
     // Set new response body directly or return it?
     return $setNewResponse ? JResponse::setBody($responseBody) : $responseBody;
 }
Exemplo n.º 4
0
 function update()
 {
     $installtype = JRequest::getVar('installtype');
     $jshopConfig = JSFactory::getConfig();
     $back = JRequest::getVar('back');
     if (!extension_loaded('zlib')) {
         JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_WARNINSTALLZLIB'));
         $this->setRedirect("index.php?option=com_jshopping&controller=update");
         return false;
     }
     if ($installtype == 'package') {
         $userfile = JRequest::getVar('install_package', null, 'files', 'array');
         if (!(bool) ini_get('file_uploads')) {
             JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_WARNINSTALLFILE'));
             $this->setRedirect("index.php?option=com_jshopping&controller=update");
             return false;
         }
         if (!is_array($userfile)) {
             JError::raiseWarning('', JText::_('No file selected'));
             $this->setRedirect("index.php?option=com_jshopping&controller=update");
             return false;
         }
         if ($userfile['error'] || $userfile['size'] < 1) {
             JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_WARNINSTALLUPLOADERROR'));
             $this->setRedirect("index.php?option=com_jshopping&controller=update");
             return false;
         }
         $config = JFactory::getConfig();
         $tmp_dest = $config->get('tmp_path') . '/' . $userfile['name'];
         $tmp_src = $userfile['tmp_name'];
         jimport('joomla.filesystem.file');
         $uploaded = JFile::upload($tmp_src, $tmp_dest, false, true);
         $archivename = $tmp_dest;
         $tmpdir = uniqid('install_');
         $extractdir = JPath::clean(dirname($archivename) . '/' . $tmpdir);
         $archivename = JPath::clean($archivename);
     } else {
         jimport('joomla.installer.helper');
         $url = JRequest::getVar('install_url');
         if (preg_match('/(sm\\d+):(.*)/', $url, $matches)) {
             $url = $jshopConfig->updates_server[$matches[1]] . "/" . $matches[2];
         }
         if (!$url) {
             JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_ENTER_A_URL'));
             $this->setRedirect("index.php?option=com_jshopping&controller=update");
             return false;
         }
         $p_file = JInstallerHelper::downloadPackage($url);
         if (!$p_file) {
             JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_INVALID_URL'));
             $this->setRedirect("index.php?option=com_jshopping&controller=update");
             return false;
         }
         $config = JFactory::getConfig();
         $tmp_dest = $config->get('tmp_path');
         $tmpdir = uniqid('install_');
         $extractdir = JPath::clean(dirname(JPATH_BASE) . '/tmp/' . $tmpdir);
         $archivename = JPath::clean($tmp_dest . '/' . $p_file);
     }
     saveToLog("install.log", "\nStart install: " . $archivename);
     $result = JArchive::extract($archivename, $extractdir);
     if ($result === false) {
         JError::raiseWarning('500', "Archive error");
         saveToLog("install.log", "Archive error");
         $this->setRedirect("index.php?option=com_jshopping&controller=update");
         return false;
     }
     $pathinfo = pathinfo($archivename);
     $this->backup_folder = 'jsbk' . date('ymdHis') . '_' . $pathinfo['filename'];
     if (file_exists($extractdir . "/checkupdate.php")) {
         include $extractdir . "/checkupdate.php";
     }
     if (file_exists($extractdir . "/configupdate.php")) {
         include $extractdir . "/configupdate.php";
     }
     if (isset($configupdate['version']) && !$this->checkVersionUpdate($configupdate['version'])) {
         $this->setRedirect("index.php?option=com_jshopping&controller=update");
         return 0;
     }
     if (!$this->copyFiles($extractdir)) {
         JError::raiseWarning(500, _JSHOP_INSTALL_THROUGH_JOOMLA);
         saveToLog("install.log", 'INSTALL_THROUGH_JOOMLA');
         $this->setRedirect("index.php?option=com_jshopping&controller=update");
         return 0;
     }
     if (file_exists($extractdir . "/update.sql")) {
         $db = JFactory::getDBO();
         $lines = file($extractdir . "/update.sql");
         $fullline = implode(" ", $lines);
         $queryes = $db->splitSql($fullline);
         foreach ($queryes as $query) {
             if (trim($query) != '') {
                 $db->setQuery($query);
                 $db->query();
                 if ($db->getErrorNum()) {
                     JError::raiseWarning(500, $db->stderr());
                     saveToLog("install.log", "Update - " . $db->stderr());
                 }
             }
         }
     }
     if (file_exists($extractdir . "/update.php")) {
         include $extractdir . "/update.php";
     }
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onAfterUpdateShop', array($extractdir));
     @unlink($archivename);
     JFolder::delete($extractdir);
     $session = JFactory::getSession();
     $checkedlanguage = array();
     $session->set("jshop_checked_language", $checkedlanguage);
     $msg = _JSHOP_COMPLETED;
     if (isset($configupdate['MASSAGE_COMPLETED'])) {
         $msg = $configupdate['MASSAGE_COMPLETED'];
     }
     if ($back == '') {
         $this->setRedirect("index.php?option=com_jshopping&controller=update", $msg);
     } else {
         $this->setRedirect($back, $msg);
     }
 }
Exemplo n.º 5
0
 /**
  * Install an extension from a URL
  *
  * @return  Package details or false on failure
  *
  * @since   1.5
  */
 protected function _getPackageFromUrl()
 {
     $input = JFactory::getApplication()->input;
     // Get the URL of the package to install
     $url = $input->getString('install_url');
     // Did you give us a URL?
     if (!$url) {
         JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_ENTER_A_URL'));
         return false;
     }
     // Download the package at the URL given
     $p_file = JInstallerHelper::downloadPackage($url);
     // Was the package downloaded?
     if (!$p_file) {
         JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_INVALID_URL'));
         return false;
     }
     $config = JFactory::getConfig();
     $tmp_dest = $config->get('tmp_path');
     // Unpack the downloaded package file
     $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file);
     return $package;
 }
Exemplo n.º 6
0
 /**
  * Method to upgrade a specific extension
  *
  * @package MageBridge
  * @access public
  * @param string $exension_name
  * @return bool
  */
 private function update($extension_name = null)
 {
     // Do not continue if the extension name is empty
     if ($extension_name == null) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::_('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_NO_EXTENSION'));
         return false;
     }
     // Fetch a list of available packages
     $packages = MageBridgeUpdateHelper::getPackageList();
     foreach ($packages as $package) {
         if ($package['name'] == $extension_name) {
             $extension = $package;
             break;
         }
     }
     // Do not continue if the extension does not appear from the list
     if ($extension == null) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::_('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_UNKNOWN_EXTENSION'));
         return false;
     }
     // Premature check for the component-directory to be writable
     if ($extension['type'] == 'component' && JFactory::getConfig()->get('ftp_enable') == 0) {
         if (is_dir(JPATH_ADMINISTRATOR . '/components/' . $extension['name']) && !is_writable(JPATH_ADMINISTRATOR . '/components/' . $extension['name'])) {
             JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_DIR_NOT_WRITABLE', JPATH_ADMINISTRATOR . '/components/' . $extension['name']));
             return false;
         } else {
             if (!is_dir(JPATH_ADMINISTRATOR . '/components/' . $extension['name']) && !is_writable(JPATH_ADMINISTRATOR . '/components')) {
                 JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_DIR_NOT_WRITABLE', JPATH_ADMINISTRATOR . '/components'));
                 return false;
             }
         }
     }
     // Construct the update URL
     $extension_uri = $extension['name'];
     $extension_uri .= '_j25';
     $extension_uri .= '.' . MagebridgeModelConfig::load('update_format');
     $extension_url = $this->getUrl($extension_uri);
     // Either use fopen() or CURL
     if (ini_get('allow_url_fopen') == 1 && MagebridgeModelConfig::load('update_method') == 'joomla') {
         $package_file = JInstallerHelper::downloadPackage($extension_url, $extension_uri);
     } else {
         $package_file = MageBridgeUpdateHelper::downloadPackage($extension_url, $extension_uri);
     }
     // Simple check for the result
     if ($package_file == false) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_DOWNLOAD_FAILED', $extension_uri));
         return false;
     }
     // Check if the downloaded file exists
     $tmp_path = JFactory::getConfig()->get('tmp_path');
     $package_path = $tmp_path . '/' . $package_file;
     if (!is_file($package_path)) {
         JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_NOT_EXISTS', $package_path));
         return false;
     }
     // Check if the file is readable
     if (!is_readable($package_path)) {
         JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_NOT_READABLE', $package_path));
         return false;
     }
     // Check if the downloaded file is abnormally small (so it might just contain a simple warning-text)
     if (filesize($package_path) < 128) {
         $contents = @file_get_contents($package_path);
         if (empty($contents)) {
             JError::raiseWarning('MB', JText::_('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_EMPTY'));
             return false;
         } else {
             if (preg_match('/^Restricted/', $contents)) {
                 JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_NO_ACCESS'));
                 return false;
             }
         }
         JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_NO_ARCHIVE', $package_path));
         return false;
     }
     // Now we assume this is an archive, so let's unpack it
     $package = JInstallerHelper::unpack($package_path);
     if ($package == false) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FILE_GONE', $extension['name']));
         return false;
     }
     // Quick workaround to prevent Koowa proxying the database
     if (class_exists('KInput')) {
         KInput::set('option', 'com_installer', 'get');
     }
     // Call the actual installer to install the package
     $installer = JInstaller::getInstance();
     if ($installer->install($package['dir']) == false) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_FAILED', $extension['name']));
         return false;
     }
     // Get the name of downloaded package
     if (!is_file($package['packagefile'])) {
         $package['packagefile'] = JFactory::getConfig()->get('tmp_path') . '/' . $package['packagefile'];
     }
     // Clean up the installation
     @JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
     // Post install procedure
     if (isset($extension['post_install_query'])) {
         $query = trim($extension['post_install_query']);
         if (!empty($query)) {
             $db = JFactory::getDBO();
             $db->setQuery($query);
             try {
                 $db->execute();
             } catch (Exception $e) {
                 JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_POSTQUERY_FAILED', $db->getErrorMsg()));
                 return false;
             }
             if ($db->getErrorMsg()) {
                 JError::raiseWarning('MB', JText::sprintf('COM_MAGEBRIDGE_MODEL_UPDATE_INSTALL_POSTQUERY_FAILED', $db->getErrorMsg()));
                 return false;
             }
         }
     }
     return true;
 }
Exemplo n.º 7
0
 /**
  * Import an spreadsheet from a URL
  *
  * @return  Package details or false on failure
  *
  */
 protected function _getPackageFromUrl()
 {
     $app = JFactory::getApplication();
     $input = $app->input;
     // Get the URL of the package to import
     $url = $input->getString('import_url');
     // Did you give us a URL?
     if (!$url) {
         $app->enqueueMessage(JText::_('COM_DEMO_IMPORT_MSG_ENTER_A_URL'), 'warning');
         return false;
     }
     // Download the package at the URL given
     $p_file = JInstallerHelper::downloadPackage($url);
     // Was the package downloaded?
     if (!$p_file) {
         $app->enqueueMessage(JText::_('COM_DEMO_IMPORT_MSG_INVALID_URL'), 'warning');
         return false;
     }
     // check that this is a valid spreadsheet
     $package = $this->check($p_file);
     return $package;
 }
Exemplo n.º 8
0
 public function restore()
 {
     if (!JSession::checkToken()) {
         $this->response->errors[] = JText::_('JINVALID_TOKEN');
         $this->response->failed = 1;
     } else {
         // database
         $db = JFactory::getDbo();
         // Delete v3 tables
         $sql = JPATH_SITE . '/administrator/components/com_k2/uninstall.sql';
         $queries = JDatabaseDriver::splitSql(file_get_contents($sql));
         foreach ($queries as $query) {
             $query = trim($query);
             if ($query != '' && $query[0] != '#') {
                 $db->setQuery($query);
                 $db->execute();
             }
         }
         // Restore v2 tables
         $tables = array('#__k2_v2_attachments', '#__k2_v2_categories', '#__k2_v2_comments', '#__k2_v2_extra_fields', '#__k2_v2_extra_fields_groups', '#__k2_v2_items', '#__k2_v2_rating', '#__k2_v2_tags', '#__k2_v2_tags_xref', '#__k2_v2_users', '#__k2_v2_user_groups');
         foreach ($tables as $table) {
             $name = str_replace('#__k2_v2_', '#__k2_', $table);
             $db->setQuery('DROP TABLE IF EXISTS ' . $db->quoteName($name));
             $db->execute();
             $db->setQuery('RENAME TABLE ' . $db->quoteName($table) . ' TO ' . $db->quoteName($name));
             $db->execute();
         }
         // Restore component files manually to keep any custom templates
         if (JFolder::exists(JPATH_SITE . '/components/com_k2')) {
             JFolder::delete(JPATH_SITE . '/components/com_k2');
             JFolder::move(JPATH_SITE . '/components/com_k2_v2', JPATH_SITE . '/components/com_k2');
         }
         if (JFolder::exists(JPATH_ADMINISTRATOR . '/components/com_k2')) {
             JFolder::delete(JPATH_ADMINISTRATOR . '/components/com_k2');
             JFolder::move(JPATH_ADMINISTRATOR . '/components/com_k2_v2', JPATH_ADMINISTRATOR . '/components/com_k2');
         }
         // Install K2 v2 package to restore rest extension files
         $installer = JInstaller::getInstance();
         $file = JInstallerHelper::downloadPackage('http://getk2.org/downloads/?f=K2_v2.6.9.zip');
         $config = JFactory::getConfig();
         $package = JInstallerHelper::unpack($config->get('tmp_path') . '/' . $file, true);
         $installer->install($package['dir']);
     }
     echo json_encode($this->response);
     return $this;
 }
Exemplo n.º 9
0
 /**
  * Install an extension from a URL
  *
  * @static
  * @return boolean True on success
  * @since 1.5
  */
 function _getPackageFromUrl()
 {
     // Get a database connector
     $db =& JFactory::getDBO();
     // Get the URL of the package to install
     $url = JRequest::getString('install_url');
     // Did you give us a URL?
     if (!$url) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::_('Please enter a URL'));
         return false;
     }
     // Download the package at the URL given
     $p_file = JInstallerHelper::downloadPackage($url);
     // Was the package downloaded?
     if (!$p_file) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::_('Invalid URL'));
         return false;
     }
     $config =& JFactory::getConfig();
     $tmp_dest = $config->getValue('config.tmp_path');
     // Unpack the downloaded package file
     $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file);
     return $package;
 }
Exemplo n.º 10
0
 /**
  * Prepare the installation for an extension specified by a URL
  *
  * @param   OutputInterface $output An OutputInterface instance
  * @param   string          $source The extension source
  *
  * @return  string  The location of the prepared extension
  */
 private function handleDownload(OutputInterface $output, $source)
 {
     $this->writeln($output, "Downloading {$source}", OutputInterface::VERBOSITY_VERBOSE);
     return $this->unpack(\JInstallerHelper::downloadPackage($source));
 }
Exemplo n.º 11
0
 /**
  * Install an extension from a URL
  *
  * @return	Package details or false on failure
  * @since	1.5
  */
 protected function _getPackageFromUrl()
 {
     // Get a database connector
     $db = JFactory::getDbo();
     // Get the URL of the package to install
     $url = JRequest::getString('install_url');
     // Did you give us a URL?
     if (!$url) {
         JCKHelper::error(JText::_('COM_INSTALLER_MSG_INSTALL_ENTER_A_URL'));
         return false;
     }
     // Download the package at the URL given
     $p_file = JInstallerHelper::downloadPackage($url);
     // Was the package downloaded?
     if (!$p_file) {
         JCKHelper::error(JText::_('COM_INSTALLER_MSG_INSTALL_INVALID_URL'));
         return false;
     }
     $config = JFactory::getConfig();
     $tmp_dest = $config->get('tmp_path');
     // Unpack the downloaded package file
     $package = JInstallerHelper::unpack($tmp_dest . DS . $p_file);
     return $package;
 }
Exemplo n.º 12
0
 /**
  * Get the package from the updates server
  *
  * @return	Package details or false on failure
  */
 protected function getPackageFromUrl($type = 'library')
 {
     jimport('joomla.installer.helper');
     // Get a database connector
     $db = JFactory::getDbo();
     // Get the URL of the package to install
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         // Joomla! 1.6+ code here
         switch ($type) {
             case "plugin":
                 $url = $this->plugin_url;
                 break;
             case "library":
             default:
                 $url = $this->lib_url;
                 break;
         }
     } else {
         // Joomla! 1.5 code here
         $url = $this->plugin_url_j15;
     }
     // Download the package at the URL given
     $p_file = JInstallerHelper::downloadPackage($url);
     // Was the package downloaded?
     if (!$p_file) {
         $this->setError(JText::_('Could not download library installation package'));
         return false;
     }
     $config = JFactory::getConfig();
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         // Joomla! 1.6+ code here
         $tmp_dest = $config->get('tmp_path');
     } else {
         // Joomla! 1.5 code here
         $tmp_dest = $config->getValue('config.tmp_path');
     }
     // Unpack the downloaded package file
     $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file);
     return $package;
 }
Exemplo n.º 13
0
 protected function _getPackageFromUrl()
 {
     // Get the URL of the package to install
     $url = JRequest::getString('url');
     // Download the package at the URL given
     $file = JInstallerHelper::downloadPackage($url);
     // Was the package downloaded?
     if (!$file) {
         JError::raiseWarning(0, JText::_('Invalid URL'));
         return false;
     }
     $config = JFactory::getConfig();
     $tmp_dest = $config->getValue('config.tmp_path');
     // Unpack the downloaded package file
     $package = JInstallerHelper::unpack($tmp_dest . DS . $file);
     return $package;
 }
Exemplo n.º 14
0
 public function check()
 {
     $this->assertNotEmpty($this->release_id, 'ERR_ITEM_NEEDS_CATEGORY');
     // Get some useful info
     $db = $this->getDBO();
     $query = $db->getQuery(true)->select(array($db->qn('title'), $db->qn('alias')))->from($db->qn('#__ars_items'))->where($db->qn('release_id') . ' = ' . $db->q($this->release_id));
     if ($this->id) {
         $query->where('NOT(' . $db->qn('id') . '=' . $db->q($this->id) . ')');
     }
     $db->setQuery($query);
     $info = $db->loadAssocList();
     $titles = array();
     $aliases = array();
     foreach ($info as $infoitem) {
         $titles[] = $infoitem['title'];
         $aliases[] = $infoitem['alias'];
     }
     // Let's get automatic item title/description records
     $subQuery = $db->getQuery(true)->select($db->qn('category_id'))->from($db->qn('#__ars_releases'))->where($db->qn('id') . ' = ' . $db->q($this->release_id));
     $query = $db->getQuery(true)->select('*')->from($db->qn('#__ars_autoitemdesc'))->where($db->qn('category') . ' IN (' . $subQuery . ')')->where('NOT(' . $db->qn('published') . '=' . $db->q(0) . ')');
     $db->setQuery($query);
     $autoitems = $db->loadObjectList();
     $auto = (object) array('title' => '', 'description' => '', 'environments' => '');
     if (!empty($autoitems)) {
         $fname = basename($this->type == 'file' ? $this->filename : $this->url);
         foreach ($autoitems as $autoitem) {
             $pattern = $autoitem->packname;
             if (empty($pattern)) {
                 continue;
             }
             if (fnmatch($pattern, $fname)) {
                 $auto = $autoitem;
                 break;
             }
         }
     }
     // Added environment ID
     if (!empty($this->environments) && is_array($this->environments)) {
         // Filter out empty environments
         $temp = array();
         foreach ($this->environments as $eid) {
             if ($eid) {
                 $temp[] = $eid;
             }
         }
         $this->environments = $temp;
     }
     // Check if a title exists
     if (!$this->title) {
         // No, try the automatic rule-based title
         $this->title = $auto->title;
         if (!$this->title) {
             // No, try to get the filename
             switch ($this->type) {
                 case 'file':
                     if ($this->filename) {
                         $this->title = basename($this->filename);
                     }
                     break;
                 case 'link':
                     if ($this->url) {
                         $this->title = basename($this->url);
                     }
                     break;
             }
             $this->assertNotEmpty($this->title, 'ERR_ITEM_NEEDS_TITLE');
         }
     }
     $this->assertNotInArray($this->title, $titles, 'ERR_ITEM_NEEDS_TITLE_UNIQUE');
     $stripDesc = strip_tags($this->description);
     $stripDesc = trim($stripDesc);
     if (empty($this->description) || empty($stripDesc)) {
         $this->description = $auto->description;
     }
     // If the alias is missing, auto-create a new one
     if (!$this->alias) {
         $source = $this->title;
         switch ($this->type) {
             case 'file':
                 if ($this->filename) {
                     $source = basename($this->filename);
                 }
                 break;
             case 'link':
                 if ($this->url) {
                     $source = basename($this->url);
                 }
                 break;
         }
         $this->alias = str_replace('.', '-', $source);
         // Create a smart alias
         $alias = strtolower($source);
         $alias = str_replace(' ', '-', $alias);
         $alias = str_replace('.', '-', $alias);
         $this->alias = (string) preg_replace('/[^A-Z0-9_-]/i', '', $alias);
     }
     $this->assertNotEmpty($this->alias, 'ERR_ITEM_NEEDS_ALIAS');
     $this->assertNotInArray($this->alias, $aliases, 'ERR_ITEM_NEEDS_ALIAS_UNIQUE');
     $this->assertInArray($this->type, ['link', 'file'], 'ERR_ITEM_NEEDS_TYPE');
     switch ($this->type) {
         case 'file':
             $this->assertNotEmpty($this->filename, 'ERR_ITEM_NEEDS_FILENAME');
             break;
         case 'link':
             $this->assertNotEmpty($this->url, 'ERR_ITEM_NEEDS_LINK');
             break;
     }
     \JLoader::import('joomla.filter.filterinput');
     $filter = \JFilterInput::getInstance(null, null, 1, 1);
     // Filter the description using a safe HTML filter
     if (!empty($this->description)) {
         $this->description = $filter->clean($this->description);
     }
     // Set the access to registered if there are subscription groups defined
     if (!empty($this->groups) && $this->access == 1) {
         $this->access = 2;
     }
     if (is_null($this->published) || $this->published == '') {
         $this->published = 0;
     }
     // Apply an update stream, if possible
     if (empty($this->updatestream)) {
         $db = $this->getDBO();
         $subquery = $db->getQuery(true)->select($db->qn('category_id'))->from('#__ars_releases')->where($db->qn('id') . ' = ' . $db->q($this->release_id));
         $query = $db->getQuery(true)->select('*')->from($db->qn('#__ars_updatestreams'))->where($db->qn('category') . ' IN (' . $subquery . ')');
         $db->setQuery($query);
         $streams = $db->loadObjectList();
         if (!empty($streams)) {
             $fname = basename($this->type == 'file' ? $this->filename : $this->url);
             foreach ($streams as $stream) {
                 $pattern = $stream->packname;
                 $element = $stream->element;
                 if (empty($pattern) && !empty($element)) {
                     $pattern = $element . '*';
                 }
                 if (empty($pattern)) {
                     continue;
                 }
                 if (fnmatch($pattern, $fname)) {
                     $this->updatestream = $stream->id;
                     break;
                 }
             }
         }
     }
     // Check for MD5 and SHA1 existence
     if (empty($this->md5) || empty($this->sha1) || empty($this->filesize)) {
         if ($this->type == 'file') {
             $target = null;
             $folder = null;
             $filename = $this->filename;
             /** @var Releases $releaseModel */
             $releaseModel = $this->container->factory->model('Releases')->tmpInstance();
             /** @var Releases $release */
             $release = $releaseModel->find($this->release_id);
             if ($release->id) {
                 if ($release->category->id) {
                     $folder = $release->category->directory;
                 }
             }
             $url = null;
             if (!empty($folder)) {
                 $potentialPrefix = substr($folder, 0, 5);
                 $potentialPrefix = strtolower($potentialPrefix);
                 if ($potentialPrefix == 's3://') {
                     $check = substr($folder, 5);
                     $s3 = AmazonS3::getInstance();
                     $items = $s3->getBucket('', $check);
                     if (empty($items)) {
                         $folder = null;
                         return false;
                     } else {
                         // Get a signed URL
                         $s3 = Amazons3::getInstance();
                         $url = $s3->getAuthenticatedURL(rtrim(substr($folder, 5), '/') . '/' . ltrim($filename, '/'));
                     }
                 } else {
                     \JLoader::import('joomla.filesystem.folder');
                     if (!\JFolder::exists($folder)) {
                         $folder = JPATH_ROOT . '/' . $folder;
                         if (!\JFolder::exists($folder)) {
                             $folder = null;
                         }
                     }
                     if (!empty($folder)) {
                         $filename = $folder . '/' . $filename;
                     }
                 }
             }
         }
         if (!isset($url)) {
             $url = null;
         }
         if ($this->type == 'link' || !is_null($url)) {
             if (is_null($url)) {
                 $url = $this->url;
             }
             $config = \JFactory::getConfig();
             $target = $config->get('tmp_path') . '/temp.dat';
             if (function_exists('curl_exec')) {
                 // By default, try using cURL
                 $process = curl_init($url);
                 curl_setopt($process, CURLOPT_HEADER, 0);
                 // Pretend we are IE7, so that webservers play nice with us
                 curl_setopt($process, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)');
                 curl_setopt($process, CURLOPT_TIMEOUT, 5);
                 curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
                 curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false);
                 // The @ sign allows the next line to fail if open_basedir is set or if safe mode is enabled
                 @curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
                 @curl_setopt($process, CURLOPT_MAXREDIRS, 20);
                 $data = curl_exec($process);
                 if ($data !== false) {
                     \JLoader::import('joomla.filesystem.file');
                     $result = \JFile::write($target, $data);
                 }
                 curl_close($process);
             } else {
                 // Use Joomla!'s download helper
                 \JLoader::import('joomla.installer.helper');
                 \JInstallerHelper::downloadPackage($url, $target);
             }
             $filename = $target;
         }
         if (!empty($filename) && is_file($filename)) {
             \JLoader::import('joomla.filesystem.file');
             if (!\JFile::exists($filename)) {
                 $filename = null;
             }
         }
         if (!empty($filename) && is_file($filename)) {
             if (function_exists('hash_file')) {
                 if (empty($this->md5)) {
                     $this->md5 = hash_file('md5', $filename);
                 }
                 if (empty($this->sha1)) {
                     $this->sha1 = hash_file('sha1', $filename);
                 }
             } else {
                 if (function_exists('md5_file') && empty($this->md5)) {
                     $this->md5 = md5_file($filename);
                 }
                 if (function_exists('sha1_file') && empty($this->sha1)) {
                     $this->sha1 = sha1_file($filename);
                 }
             }
             if (empty($this->filesize)) {
                 $filesize = @filesize($filename);
                 if ($filesize !== false) {
                     $this->filesize = $filesize;
                 }
             }
         }
         if (!empty($filename) && is_file($filename) && $this->type == 'link') {
             if (!@unlink($filename)) {
                 \JFile::delete($filename);
             }
         }
     }
     return parent::check();
 }
Exemplo n.º 15
0
	public function download()
	{
		// Get a database connector
		$db = & JFactory::getDBO();

		// Get the URL of the package to install
		$url = JRequest::getString('install_url');

		// Did you give us a URL?
		if (!$url) {
			if(version_compare(JVERSION, '1.6.0', 'ge')) {
				JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_ENTER_A_URL'));
			} else {
				JError::raiseWarning('SOME_ERROR_CODE', JText::_('Please enter a URL'));
			}
			return false;
		}

		// Download the package at the URL given
		$p_file = JInstallerHelper::downloadPackage($url);

		// Was the package downloaded?
		if (!$p_file) {
			if(version_compare(JVERSION, '1.6.0', 'ge')) {
				JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_INVALID_URL'));
			} else {
				JError::raiseWarning('SOME_ERROR_CODE', JText::_('Invalid URL'));
			}
			return false;
		}
		
		$config =& JFactory::getConfig();
		$tmp_dest 	= $config->getValue('config.tmp_path');

		// Store the uploaded package's location
		$session = JFactory::getSession();
		$session->set('compressed_package', $tmp_dest.DS.$p_file, 'akeeba');
		
		return true;
	}
Exemplo n.º 16
0
 function _remoteInstaller($url)
 {
     jimport('joomla.installer.helper');
     jimport('joomla.installer.installer');
     if (!$url) {
         return false;
     }
     $filename = JInstallerHelper::downloadPackage($url);
     $config =& JFactory::getConfig();
     $target = $config->getValue('config.tmp_path') . DS . basename($filename);
     // Unpack
     $package = JInstallerHelper::unpack($target);
     if (!$package) {
         // unable to find install package
     }
     // Install the package
     $msg = '';
     $installer =& JInstaller::getInstance();
     //Work around: delete the manifest file to prevent plugin upgrade, only for 1.6
     if (JFile::exists(JPATH_ROOT . DS . 'plugins' . DS . 'system' . DS . 'zend' . DS . 'zend.xml')) {
         file_put_contents(JPATH_ROOT . DS . 'plugins' . DS . 'system' . DS . 'zend' . DS . 'zend.xml', '<?xml version="1.0" encoding="utf-8"?><install version="1.5" type="plugin" group="system" method="upgrade"></install>');
     }
     if (!$installer->install($package['dir'])) {
         // There was an error installing the package
         $msg = JText::sprintf('INSTALLEXT', JText::_($package['type']), JText::_('Error'));
         $result = false;
     } else {
         // Package installed sucessfully
         $msg = JText::sprintf('INSTALLEXT', JText::_($package['type']), JText::_('Success'));
         $result = true;
     }
     // Clean up the install files
     if (!is_file($package['packagefile'])) {
         $package['packagefile'] = $config->getValue('config.tmp_path') . DS . $package['packagefile'];
     }
     JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
     return $result;
 }
Exemplo n.º 17
0
 function _remoteInstaller($url)
 {
     jimport('joomla.installer.helper');
     jimport('joomla.installer.installer');
     if (!$url) {
         return false;
     }
     $filename = JInstallerHelper::downloadPackage($url);
     //$config = JFactory::getConfig();
     //$target	= $config->getValue('config.tmp_path').'/'.basename($filename);
     $app = JFactory::getApplication();
     $target = $app->getCfg('config.tmp_path') . '/' . basename($filename);
     // Unpack
     $package = JInstallerHelper::unpack($target);
     if (!$package) {
         // unable to find install package
     }
     // Install the package
     $msg = '';
     $installer = JInstaller::getInstance();
     if (!$installer->install($package['dir'])) {
         // There was an error installing the package
         $msg = JText::sprintf('INSTALLEXT', JText::_($package['type']), JText::_('Error'));
         $result = false;
     } else {
         // Package installed sucessfully
         $msg = JText::sprintf('INSTALLEXT', JText::_($package['type']), JText::_('Success'));
         $result = true;
     }
     // Clean up the install files
     if (!is_file($package['packagefile'])) {
         //$package['packagefile'] = $config->getValue('config.tmp_path').'/'.$package['packagefile'];
         $package['packagefile'] = $app->getCfg('config.tmp_path') . '/' . $package['packagefile'];
     }
     JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
     return $result;
 }
Exemplo n.º 18
0
 public function doInstallUpdate($update_row)
 {
     // Load
     $this->out('Loading update #' . $update_row->update_id . '...');
     $update = new JUpdate();
     $updateRow = JTable::getInstance('update');
     $updateRow->load($update_row->update_id);
     $update->loadFromXml($updateRow->detailsurl, $this->installer->params->get('minimum_stability', JUpdater::STABILITY_STABLE, 'int'));
     $update->set('extra_query', $updateRow->extra_query);
     // Download
     $tmpPath = $this->config->get('tmp_path');
     if (!is_writeable($tmpPath)) {
         $tmpPath = JPATH_BASE . '/tmp';
     }
     $url = $update->downloadurl->_data;
     if ($extra_query = $update->get('extra_query')) {
         $url .= strpos($url, '?') === false ? '?' : '&amp;';
         $url .= $extra_query;
     }
     $this->out(' - Download ' . $url);
     $p_file = JInstallerHelper::downloadPackage($url);
     if ($p_file) {
         $filePath = $tmpPath . '/' . $p_file;
     } else {
         $this->out(' - Download Failed, Attempting alternate download method...');
         $urlFile = preg_replace('/^.*\\/(.*?)$/', '$1', $url);
         $filePath = $tmpPath . '/' . $urlFile;
         if ($fileHandle = @fopen($filePath, 'w+')) {
             $curl = curl_init($url);
             curl_setopt_array($curl, [CURLOPT_URL => $url, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_BINARYTRANSFER => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FILE => $fileHandle, CURLOPT_TIMEOUT => 50, CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)']);
             $response = curl_exec($curl);
             if ($response === false) {
                 $this->out(' - Download Failed: ' . curl_error($curl));
                 return false;
             }
         } else {
             $this->out(' - Download Failed, Error writing ' . $filePath);
             return false;
         }
     }
     // Catch Error
     if (!is_file($filePath)) {
         $this->out(' - Download Failed/ File not found');
         return false;
     }
     // Extracting Package
     $this->out(' - Extracting Package...');
     $package = JInstallerHelper::unpack($filePath);
     if (!$package) {
         $this->out(' - Extract Failed');
         JInstallerHelper::cleanupInstall($filePath);
         return false;
     }
     // Install the package
     $this->out(' - Installing ' . $package['dir'] . '...');
     $installer = JInstaller::getInstance();
     $update->set('type', $package['type']);
     if (!$installer->update($package['dir'])) {
         $this->out(' - Update Error');
         $result = false;
     } else {
         $this->out(' - Update Success');
         $result = true;
     }
     // Cleanup the install files
     $this->out(' - Cleanup');
     JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
     // Complete
     return $result;
 }
Exemplo n.º 19
0
 function preflight()
 {
     // try downloading and installing gantry
     if (file_exists(JPATH_SITE . '/administrator/components/com_gantry/gantry.php')) {
         return;
     }
     jimport('joomla.filesystem.file');
     JClientHelper::setCredentialsFromRequest('ftp');
     $config = JFactory::getConfig();
     $dlfile = 'http://crosstec.de/gantry.zip';
     $dlerror = true;
     $p_file = 'gantry.zip';
     $delete = $config->get('tmp_path') . '/' . $p_file;
     if (JFile::exists($delete)) {
         JFile::delete($delete);
     }
     // Download the package at the URL given
     // trying curl first
     if (function_exists('curl_init')) {
         $fp = @fopen($config->get('tmp_path') . '/' . $p_file, 'w');
         if ($fp !== false) {
             $ch = curl_init($dlfile);
             curl_setopt($ch, CURLOPT_FILE, $fp);
             $data = curl_exec($ch);
             curl_close($ch);
             fclose($fp);
             if (file_exists($config->get('tmp_path') . '/' . $p_file)) {
                 $dlerror = false;
             }
         }
     }
     // trying fsockopen next
     if ($dlerror) {
         $host = "crosstec.de";
         $target = "gantry.zip";
         $port = 80;
         $timeout = 120;
         $protocol = "HTTP/1.0";
         $fd = @fsockopen($host, $port, $errnum, $errstr, $timeout);
         if (!is_resource($fd)) {
         } else {
             $br = "\r\n";
             $headers = "GET " . $target . " " . $protocol . $br;
             $headers .= "Accept: image/jpeg" . $br;
             $headers .= "Accept-Language: en-us" . $br;
             $headers .= "Host: " . $host . $br;
             $headers .= "Connection: Keep-Alive" . $br;
             $headers .= "User-Agent: Socket-PHP-browser 1.0" . $br;
             $headers .= "Referer: http://www.somesite.com" . $br;
             $headers .= "X-Something: Hello from John" . $br . $br;
             @fputs($fd, $headers);
             $contents = "";
             while (!feof($fd)) {
                 $contents .= fgets($fd, 2048);
             }
         }
         @fclose($fd);
         if (isset($contents) && $contents) {
             JFile::write($config->get('tmp_path') . '/' . $p_file, $contents);
             $dlerror = false;
         }
     }
     // no curl, no fsockopen, last try
     if ($dlerror) {
         $p_file = JInstallerHelper::downloadPackage($dlfile);
     }
     // Was the package downloaded?
     if ($p_file) {
         $tmp_dest = $config->get('tmp_path');
         // Unpack the downloaded package file
         $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file);
         if ($package) {
             $installer = new JInstaller();
             // Install the package
             $installer->install($package['dir']);
             // Cleanup the install files
             if (!is_file($package['packagefile'])) {
                 $config = JFactory::getConfig();
                 $package['packagefile'] = $config->get('tmp_path') . '/' . $package['packagefile'];
             }
             JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
         }
     }
     if (!file_exists(JPATH_SITE . '/administrator/components/com_gantry/gantry.php')) {
         echo '<div style="background-color: red; background-color: rgba(255,0,0,0.3); border-radius: 8px;font-size: 18px;margin: 20px;padding: 20px;">
                 Note: Please download and install the Gantry Framework extension <a href="http://crosstec.de/gantry.zip">from here</a> in order to complete the installation. The template won\'t work properly until this extension has been installed.
              </div>';
     }
 }
Exemplo n.º 20
0
 private function update($extension_name = null)
 {
     // Do not continue if the extension name is empty
     if ($extension_name == null) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::_('No extension specified'));
         return false;
     }
     // Fetch a list of available packages
     $packages = MageBridgeUpdateHelper::getPackageList();
     foreach ($packages as $package) {
         if ($package['name'] == $extension_name) {
             $extension = $package;
             break;
         }
     }
     // Do not continue if the extension does not appear from the list
     if ($extension == null) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::_('Unknown extension'));
         return false;
     }
     // Premature check for the component-directory to be writable
     if ($extension['type'] == 'component' && JFactory::getConfig()->getValue('ftp_enable') == 0) {
         if (is_dir(JPATH_ADMINISTRATOR . '/components/' . $extension['name']) && !is_writable(JPATH_ADMINISTRATOR . '/components/' . $extension['name'])) {
             JError::raiseWarning('SOME_ERROR_CODE', JText::_('Component directory is not writable'));
             return false;
         } else {
             if (!is_dir(JPATH_ADMINISTRATOR . '/components/' . $extension['name']) && !is_writable(JPATH_ADMINISTRATOR . '/components')) {
                 JError::raiseWarning('SOME_ERROR_CODE', JText::_('Components folder is not writable'));
                 return false;
             }
         }
     }
     // Construct the update URL
     $extension_uri = $extension['name'];
     $extension_uri .= MageBridgeHelper::isJoomla15() ? '_j15' : '_j25';
     $extension_uri .= '.' . MagebridgeModelConfig::load('update_format');
     $extension_url = $this->getUrl($extension_uri);
     // Either use fopen() or CURL
     if (ini_get('allow_url_fopen') == 1 && MagebridgeModelConfig::load('update_method') == 'joomla') {
         $package_file = JInstallerHelper::downloadPackage($extension_url, $extension_uri);
     } else {
         $package_file = MageBridgeUpdateHelper::downloadPackage($extension_url, $extension_uri);
     }
     // Simple check for the result
     if ($package_file == false) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('Failed to download update for %s', $extension_uri));
         return false;
     }
     // Check if the downloaded file exists
     $tmp_path = JFactory::getConfig()->getValue('config.tmp_path');
     $package_path = $tmp_path . '/' . $package_file;
     if (!is_file($package_path)) {
         JError::raiseWarning('MB', JText::sprintf('File %s does not exist', $package_path));
         return false;
     }
     // Check if the file is readable
     if (!is_readable($package_path)) {
         JError::raiseWarning('MB', JText::sprintf('File %s is not readable', $package_path));
         return false;
     }
     // Check if the downloaded file is abnormally small (so it might just contain a simple warning-text)
     if (filesize($package_path) < 128) {
         $contents = @file_get_contents($package_path);
         if (empty($contents)) {
             JError::raiseWarning('MB', JText::sprintf('Valid archive but empty content.'));
             return false;
         } else {
             if (preg_match('/^Restricted/', $contents)) {
                 JError::raiseWarning('MB', JText::sprintf('Not allowed to access updates.'));
                 return false;
             }
         }
         JError::raiseWarning('MB', JText::sprintf('File %s is not a valid archive', $package_path));
         return false;
     }
     // Now we assume this is an archive, so let's unpack it
     $package = JInstallerHelper::unpack($package_path);
     if ($package == false) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('Unable to find update for %s on local filesystem', $extension['name']));
         return false;
     }
     // Quick workaround to prevent Koowa proxying the database
     if (class_exists('KInput')) {
         KInput::set('option', 'com_installer', 'get');
     }
     // Call the actual installer to install the package
     $installer = JInstaller::getInstance();
     if ($installer->install($package['dir']) == false) {
         JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('Failed to install %s', $extension['name']));
         return false;
     }
     // Get the name of downloaded package
     if (!is_file($package['packagefile'])) {
         $package['packagefile'] = JFactory::getConfig()->getValue('config.tmp_path') . '/' . $package['packagefile'];
     }
     // Clean up the installation
     @JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
     // Post install procedure
     if (isset($extension['post_install_query'])) {
         $query = trim($extension['post_install_query']);
         if (!empty($query)) {
             $db = JFactory::getDBO();
             $db->setQuery($query);
             $db->query();
             if ($db->getErrorMsg()) {
                 JError::raiseWarning('MB', JText::sprintf('Post install query failed: %s', $db->getErrorMsg()));
                 return false;
             }
         }
     }
     return true;
 }
Exemplo n.º 21
0
 /**
  * Handles the actual update installation.
  *
  * @param   JUpdate  $update  An update definition
  *
  * @return  boolean   Result of install
  *
  * @since   1.6
  */
 private function install($update)
 {
     $app = JFactory::getApplication();
     if (isset($update->get('downloadurl')->_data)) {
         $url = $update->downloadurl->_data;
         $extra_query = $update->get('extra_query');
         if ($extra_query) {
             if (strpos($url, '?') === false) {
                 $url .= '?';
             } else {
                 $url .= '&amp;';
             }
             $url .= $extra_query;
         }
     } else {
         JError::raiseWarning('', JText::_('COM_INSTALLER_INVALID_EXTENSION_UPDATE'));
         return false;
     }
     $p_file = JInstallerHelper::downloadPackage($url);
     // Was the package downloaded?
     if (!$p_file) {
         JError::raiseWarning('', JText::sprintf('COM_INSTALLER_PACKAGE_DOWNLOAD_FAILED', $url));
         return false;
     }
     $config = JFactory::getConfig();
     $tmp_dest = $config->get('tmp_path');
     // Unpack the downloaded package file
     $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file);
     // Get an installer instance
     $installer = JInstaller::getInstance();
     $update->set('type', $package['type']);
     // Install the package
     if (!$installer->update($package['dir'])) {
         // There was an error updating the package
         $msg = JText::sprintf('COM_INSTALLER_MSG_UPDATE_ERROR', JText::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type'])));
         $result = false;
     } else {
         // Package updated successfully
         $msg = JText::sprintf('COM_INSTALLER_MSG_UPDATE_SUCCESS', JText::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type'])));
         $result = true;
     }
     // Quick change
     $this->type = $package['type'];
     // Set some model state values
     $app->enqueueMessage($msg);
     // TODO: Reconfigure this code when you have more battery life left
     $this->setState('name', $installer->get('name'));
     $this->setState('result', $result);
     $app->setUserState('com_installer.message', $installer->message);
     $app->setUserState('com_installer.extension_message', $installer->get('extension_message'));
     // Cleanup the install files
     if (!is_file($package['packagefile'])) {
         $config = JFactory::getConfig();
         $package['packagefile'] = $config->get('tmp_path') . '/' . $package['packagefile'];
     }
     JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
     return $result;
 }
Exemplo n.º 22
0
 /**
  * Install an extension from a URL.
  *
  * @return  Package details or false on failure.
  *
  * @since   1.5
  */
 protected function _getPackageFromUrl()
 {
     $input = JFactory::getApplication()->input;
     // Get the URL of the package to install.
     $url = $input->getString('install_url');
     // Did you give us a URL?
     if (!$url) {
         JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_ENTER_A_URL'));
         return false;
     }
     // Handle updater XML file case:
     if (preg_match('/\\.xml\\s*$/', $url)) {
         jimport('joomla.updater.update');
         $update = new JUpdate();
         $update->loadFromXml($url);
         $package_url = trim($update->get('downloadurl', false)->_data);
         if ($package_url) {
             $url = $package_url;
         }
         unset($update);
     }
     // Download the package at the URL given.
     $p_file = JInstallerHelper::downloadPackage($url);
     // Was the package downloaded?
     if (!$p_file) {
         JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_INVALID_URL'));
         return false;
     }
     $config = JFactory::getConfig();
     $tmp_dest = $config->get('tmp_path');
     // Unpack the downloaded package file.
     $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file, true);
     return $package;
 }
Exemplo n.º 23
0
 /**
  * @copyright		Copyright (C) 2009 Ryan Demmer. All rights reserved.
  * @copyright 		Copyright (C) 2006-2010 Nicholas K. Dionysopoulos
  * @param 	String 	$url URL to resource
  * @param 	Array  	$data [optional] Array of key value pairs
  * @param 	String 	$download [optional] path to file to write to
  * @return 	Mixed 	Boolean or JSON String on error
  */
 function connect($url, $data = '', $download = '')
 {
     @error_reporting(E_ERROR);
     jimport('joomla.filesystem.file');
     $fp = false;
     $fopen = function_exists('file_get_contents') && function_exists('ini_get') && ini_get('allow_url_fopen');
     // try file_get_contents first (requires allow_url_fopen)
     if ($fopen) {
         if ($download) {
             // use Joomla! installer function
             jimport('joomla.installer.helper');
             return @JInstallerHelper::downloadPackage($url, $download);
         } else {
             $options = array('http' => array('method' => 'POST', 'timeout' => 10, 'content' => $data));
             $context = stream_context_create($options);
             return @file_get_contents($url, false, $context);
         }
         // Use curl if it exists
     } else {
         if (function_exists('curl_init')) {
             $ch = curl_init($url);
             curl_setopt($ch, CURLOPT_HEADER, 0);
             // Pretend we are IE7, so that webservers play nice with us
             curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)');
             //curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
             curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
             curl_setopt($ch, CURLOPT_TIMEOUT, 30);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             // The @ sign allows the next line to fail if open_basedir is set or if safe mode is enabled
             @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
             @curl_setopt($ch, CURLOPT_MAXREDIRS, 20);
             @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
             if ($data && !$download) {
                 curl_setopt($ch, CURLOPT_POST, 1);
                 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
             }
             // file download
             if ($download) {
                 $fp = @fopen($download, 'wb');
                 @curl_setopt($ch, CURLOPT_FILE, $fp);
             }
             $result = curl_exec($ch);
             // file download
             if ($download && $result === false) {
                 die(json_encode(array('error' => 'TRANSFER ERROR : ' . curl_error($ch))));
             }
             curl_close($ch);
             // close fopen handler
             if ($fp) {
                 @fclose($fp);
             }
             return $result;
             // error - no update support
         } else {
             return array('error' => WFText::_('WF_UPDATES_DOWNLOAD_ERROR_NO_CONNECT'));
         }
     }
     return array('error' => WFText::_('WF_UPDATES_DOWNLOAD_ERROR_NO_CONNECT'));
 }
Exemplo n.º 24
0
 /**
  * Install an extension from a URL
  *
  * @return	Package details or false on failure
  * @since	1.5
  */
 protected function _getPackageFromUrl()
 {
     // Get the URL of the package to install
     $url = Request::getString('install_url');
     // Did you give us a URL?
     if (!$url) {
         Notify::warning(Lang::txt('COM_INSTALLER_MSG_INSTALL_ENTER_A_URL'));
         return false;
     }
     // Download the package at the URL given
     $p_file = \JInstallerHelper::downloadPackage($url);
     // Was the package downloaded?
     if (!$p_file) {
         Notify::warning(Lang::txt('COM_INSTALLER_MSG_INSTALL_INVALID_URL'));
         return false;
     }
     $tmp_dest = Config::get('tmp_path');
     // Unpack the downloaded package file
     $package = \JInstallerHelper::unpack($tmp_dest . '/' . $p_file);
     return $package;
 }
Exemplo n.º 25
0
 private function updateComponent()
 {
     JLoader::import('joomla.updater.update');
     $db = JFactory::getDbo();
     $update_site = array_shift($this->getUpdateSiteIds());
     $query = $db->getQuery(true)->select($db->qn('update_id'))->from($db->qn('#__updates'))->where($db->qn('update_site_id') . ' = ' . $update_site);
     $uid = $db->setQuery($query)->loadResult();
     $update = new JUpdate();
     $instance = JTable::getInstance('update');
     $instance->load($uid);
     $update->loadFromXML($instance->detailsurl);
     if (isset($update->get('downloadurl')->_data)) {
         $url = trim($update->downloadurl->_data);
     } else {
         return "No download URL found inside XML manifest";
     }
     $config = JFactory::getConfig();
     $tmp_dest = $config->get('tmp_path');
     if (!$tmp_dest) {
         return "Joomla temp directory is empty, please set it before continuing";
     } elseif (!JFolder::exists($tmp_dest)) {
         return "Joomla temp directory does not exists, please set the correct path before continuing";
     }
     $p_file = JInstallerHelper::downloadPackage($url);
     if (!$p_file) {
         return "An error occurred while trying to download the latest version, double check your Download ID";
     }
     // Unpack the downloaded package file
     $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file);
     if (!$package) {
         return "An error occurred while unpacking the file, please double check your Joomla temp directory";
     }
     $installer = new JInstaller();
     $installed = $installer->install($package['extractdir']);
     // Let's cleanup the downloaded archive and the temp folder
     if (JFolder::exists($package['extractdir'])) {
         JFolder::delete($package['extractdir']);
     }
     if (JFile::exists($package['packagefile'])) {
         JFile::delete($package['packagefile']);
     }
     if ($installed) {
         return "Component successfully updated";
     } else {
         return "An error occurred while trying to update the component";
     }
 }
Exemplo n.º 26
0
 /**
  * Square One Additions
  */
 public function distro_download()
 {
     $update = new JUpdate();
     $detailsurl = base64_decode(JRequest::getString('detailsurl', '', 'post'));
     if (substr($detailsurl, 0, 4) == 'http') {
         $result->result = false;
         if (substr($detailsurl, 0, -3) == 'xml') {
             // Url to an update manifest
             $update->loadFromXML($detailsurl);
             $file = JInstallerHelper::downloadPackage($update->get('downloadurl')->_data);
         } else {
             $file = JInstallerHelper::downloadPackage($detailsurl);
         }
         if (!$file) {
             $result->message = JText::_('COM_INSTALLER_MSG_INSTALL_INVALID_URL');
         } else {
             $result->result = true;
             $result->task = 'distro_download';
             $result->file = $file;
             $result->message = JText::_('COM_INSTALLER_PACKAGE_DOWNLOADED');
         }
     } else {
         // We have a file
         $config = JFactory::getConfig();
         $source = base64_decode(JRequest::getString('source'));
         JFile::move($source . '/' . $detailsurl, $config->get('tmp_path') . '/' . $detailsurl);
         $result->result = true;
         $result->task = 'distro_download';
         $result->file = $detailsurl;
         $result->message = JText::_('COM_INSTALLER_PACKAGE_FOUND');
     }
     return $result;
 }
Exemplo n.º 27
0
 /**
  * Download a language package from a URL and unpack it in the tmp folder.
  *
  * @param   string  $url  Url of the package
  *
  * @return  array|bool Package details or false on failure
  *
  * @since   3.1
  */
 protected function downloadPackage($url)
 {
     // Download the package from the given URL
     $p_file = JInstallerHelper::downloadPackage($url);
     // Was the package downloaded?
     if (!$p_file) {
         JFactory::getApplication()->enqueueMessage(JText::_('COM_INSTALLER_MSG_INSTALL_INVALID_URL'), 'warning');
         return false;
     }
     $config = JFactory::getConfig();
     $tmp_dest = $config->get('tmp_path');
     // Unpack the downloaded package file
     $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file);
     return $package;
 }
Exemplo n.º 28
0
    /**
     * Install an extension from a URL
     *
     * @static
     * @return boolean True on success
     * @since 1.5
     */
    public function _getPackageFromUrl()
    {
        // Get a database connector
        $db = JFactory::getDbo();
        $tempno = $_SESSION['zipno'];
        // Get the URL of the package to install
        $url = trim(strip_tags(str_replace('administrator//', '', $_SESSION['filename'][0])));
        // Did you give us a URL?
        if (!$url) {
            JError::raiseWarning('SOME_ERROR_CODE', JText::_('COM_REDSHOP_PLEASE_ENTER_A_URL'));
            ?>
			<script type='text/javascript' language='javascript'>
				window.location = "index.php?option=com_redshop&view=zip_import&msg=err";
			</script>
		<?php 
        }
        // Download the package at the URL given
        $p_file = JInstallerHelper::downloadPackage(trim(strip_tags($url)));
        // Was the package downloaded?
        if (!$p_file) {
            JError::raiseWarning('SOME_ERROR_CODE', JText::_('COM_REDSHOP_INVALID_URL'));
            ?>
			<script type='text/javascript' language='javascript'>
				//window.location="index.php?option=com_redshop&view=zip_import&msg=err";
			</script>
		<?php 
        }
        $config = JFactory::getConfig();
        $tmp_dest = $config->getValue('config.tmp_path');
        // Unpack the downloaded package file
        $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file);
        ?>
		<script type='text/javascript' language='javascript'>
			//window.location="index.php?option=com_redshop&view=zip_import";
		</script>
		<?php 
        return $package;
    }
Exemplo n.º 29
0
 /**
  * Download a language package from a URL and unpack it in the tmp folder.
  *
  * @param   string  $url  hola
  *
  * @return  array|bool  Package details or false on failure
  *
  * @since   2.5.7
  */
 protected function _downloadPackage($url)
 {
     // Download the package from the given URL.
     $p_file = JInstallerHelper::downloadPackage($url);
     // Was the package downloaded?
     if (!$p_file) {
         JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_INVALID_URL'));
         return false;
     }
     $config = JFactory::getConfig();
     $tmp_dest = $config->get('tmp_path');
     // Unpack the downloaded package file.
     $package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file);
     return $package;
 }
Exemplo n.º 30
0
 /**
  * Downloads an update package given an update record ID ($uid). The package is downloaded
  * and its location recorded in the session.
  *
  * @param   integer  $uid  The update record ID
  *
  * @return  True on success
  */
 public function downloadUpdate($uid)
 {
     // Unset the compressed_package session variable
     $session = JFactory::getSession();
     $session->set('compressed_package', null, 'akeeba');
     // Find the download location from the XML update stream
     jimport('joomla.updater.update');
     $update = new JUpdate();
     $instance = JTable::getInstance('update');
     $instance->load($uid);
     $update->loadFromXML($instance->detailsurl);
     if (isset($update->get('downloadurl')->_data)) {
         $url = $update->downloadurl->_data;
     } else {
         JError::raiseWarning('', JText::_('COM_INSTALLER_INVALID_EXTENSION_UPDATE'));
         return false;
     }
     // Download the package
     $p_file = JInstallerHelper::downloadPackage($url);
     // Was the package downloaded?
     if (!$p_file) {
         JError::raiseWarning('', JText::sprintf('COM_INSTALLER_PACKAGE_DOWNLOAD_FAILED', $url));
         return false;
     }
     // Store the uploaded package's location
     $config = JFactory::getConfig();
     $tmp_dest = $config->get('tmp_path');
     $session->set('compressed_package', $tmp_dest . '/' . $p_file, 'akeeba');
     return true;
 }