Esempio n. 1
0
 /**
  * Installs a package
  */
 function installPackage($url, $update = false, $downloadonly)
 {
     // Download the package at the URL given
     try {
         $p_file = isJInstallerHelper::downloadPackage($url);
     } catch (Exception $e) {
         JError::raiseWarning($e->getCode(), $e->getMessage());
         return false;
     }
     if ($downloadonly) {
         return true;
     }
     // we're done
     $config =& JFactory::getConfig();
     $tmp_dest = $config->getValue('config.tmp_path');
     // Unpack the downloaded package file
     $package = isJInstallerHelper::unpack($tmp_dest . DS . $p_file);
     if (!$package) {
         JError::raiseWarning("-2", "Could not unpack file: " . basename($url));
         return false;
     }
     $installer = new isJInstaller();
     // never static
     $result = false;
     try {
         if ($update) {
             $installer->setOverwrite(true);
             $result = $installer->update($package['dir']);
         } else {
             $result = $installer->install($package['dir']);
         }
     } catch (Exception $e) {
         // Do nothing on error - result is false
     }
     // cleanup
     isJInstallerHelper::cleanupInstall($package['packagefile'], $package['dir']);
     // JFile::delete($tmp_dest.DS.$p_file);
     $msg = '';
     if (!$result) {
         // There was an error installing the package
         $msg .= JText::sprintf('INSTALLEXT', JText::_($package['type']), JText::_('Error'));
     } else {
         // Package installed sucessfully
         $msg .= JText::sprintf('INSTALLEXT', JText::_($package['type']), JText::_('Success'));
     }
     return $result;
 }
Esempio n. 2
0
 /**
  * Custom install method
  *
  * @access    public
  * @return    boolean    True on success
  * @since    1.5
  */
 function install()
 {
     global $installresults;
     $installresults = array();
     $out = array();
     // Get the extension manifest object
     $manifest =& $this->parent->getManifest();
     $this->manifest =& $manifest->document;
     $manifestpath = $this->parent->getPath('manifest');
     $sigpath = str_replace('.xml', '.sig', $manifestpath);
     $mf = new JEXPackageManifest($manifestpath);
     switch ($mf->verify) {
         case 'good':
             $msg = "Package {$mf->name} verified with openssl. Installing.";
             break;
         case 'unknown':
         case 'error':
             $msg = "Package {$mg->name} could not be checked. To verify, please install openssl. Installing.";
             break;
         case 'bad':
             $this->parent->abort(JText::_('Package') . ' ' . JText::_('Install') . ' Failed: ' . JText::_('Signature mismatch.'));
     }
     $installresults['verify'] = $mf->verify;
     $installresults['check'] = $msg;
     $out[] = "<div class='msg'>{$msg}</div>";
     # TODO verify signature
     /**
      * ---------------------------------------------------------------------------------------------
      * Manifest Document Setup Section
      * ---------------------------------------------------------------------------------------------
      */
     // Set the extensions name
     $name = $mf->name;
     $name = JFilterInput::clean($name, 'cmd');
     $this->set('name', $name);
     $description = $mf->description;
     /**
      * Load the local installer class
      */
     // If there is an install file, lets load it.
     $installScriptElement =& $this->manifest->getElementByPath('installfile');
     $installClass = $name . 'PkgInstallHooks';
     if (is_a($installScriptElement, 'JSimpleXMLElement')) {
         if (!class_exists($installClass, false)) {
             include_once $this->parent->getPath('source') . DS . $installScriptElement->data();
             call_user_func(array($installClass, 'onLoad'));
         }
     }
     if (class_exists($installClass)) {
         call_user_func(array($installClass, 'beforeInstall'));
     }
     /**
      * ---------------------------------------------------------------------------------------------
      * Filesystem Processing Section
      * ---------------------------------------------------------------------------------------------
      */
     $element =& $this->manifest->getElementByPath('files');
     if (is_a($element, 'JSimpleXMLElement') && count($element->children())) {
         if ($folder = $element->attributes('folder')) {
             $source = $this->parent->getPath('source') . DS . $folder;
         } else {
             $source = $this->parent->getPath('source');
         }
         foreach ($mf->filelist as $oFile) {
             /** @var JEXExtension */
             $oFile = $oFile;
             $file = $source . DS . $oFile->filename;
             $dest = $oFile->dest;
             $md5 = md5(file_get_contents($file));
             if ($md5 != $oFile->md5) {
                 $out[] = "<div class='msg'>Skipping File: " . basename($file) . " signature does not match.</div>";
                 continue;
             }
             if ($dest) {
                 isJInstallerHelper::extract($file, $dest, true);
                 $out[] = "<div class='msg'>Installed: " . basename($file) . " ({$md5})</div><br>\n";
                 continue;
                 // we're done with the tarball
             }
             $package = isJInstallerHelper::unpack($file);
             if (!$package) {
                 $out = "<div class='msg'>Can't extract package: " . basename($file) . ". file skipped.";
                 continue;
             }
             // Use core installer
             $installer =& JInstaller::getInstance();
             $success = $installer->install($package['dir']);
             $msg = "<div class='msg'>Installed: " . basename(basename($file)) . " Signature good: ({$md5})</div><br>\n";
             if ($installer->message) {
                 $msg .= $installer->message;
             }
             $out[] = $msg;
             if (!is_file($package['packagefile'])) {
                 $package['packagefile'] = $config->getValue('config.tmp_path') . DS . $package['packagefile'];
             }
             JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
             // End core Installer
             if (!$success) {
                 $out[] = JText::_('Package') . ' ' . JText::_($install_type) . ': ' . JText::_('There was an error installing an extension:') . basename($file);
             }
             $out[] = "<hr>\n";
         }
         // foreach
     } else {
         // Do Nothing - nothing to install
     }
     /**
      * ---------------------------------------------------------------------------------------------
      * Finalization and Cleanup Section
      * ---------------------------------------------------------------------------------------------
      */
     if (class_exists($installClass)) {
         call_user_func(array($installClass, 'afterInstall'));
     }
     // Lastly, we will copy the manifest file to its appropriate place.
     @copy($manifestpath, EXPACKAGE_MANIFEST_PATH . '/' . basename($manifestpath));
     @copy($sigpath, EXPACKAGE_MANIFEST_PATH . '/' . basename($sigpath));
     $msg = '';
     foreach ($out as $txt) {
         $msg .= "<p class='out'>{$txt}</p>\n";
     }
     $this->parent->message = $msg;
     $installresults['out'] = $out;
     $installresults['msg'] = $out;
     return true;
 }