Ejemplo n.º 1
0
     }
     break;
 case "available":
     $addonId = $_POST["addonId"];
     $response = array();
     $status = 1;
     try {
         if (EnterpriseUtils::getInternetConnection() == 0) {
             throw new Exception("Enterprise Plugins Manager no connected to internet.");
         }
         ///////
         $licenseManager =& pmLicenseManager::getSingleton();
         $server = $licenseManager->server;
         $workspace = isset($licenseManager->workspace) ? $licenseManager->workspace : 'pmLicenseSrv';
         $url = "http://{$server}/sys" . $workspace . "/en/green/services/rest";
         if (EnterpriseUtils::checkConnectivity($url) == false) {
             throw new Exception("Server \"{$server}\" not available.");
         }
         ///////
         $boundary = "---------------------" . substr(G::encryptOld(rand(0, 32000)), 0, 10);
         $data = null;
         $data = $data . "--{$boundary}\n";
         $data = $data . "Content-Disposition: form-data; name=\"action\"\n\n" . "requestToSales" . "\n";
         $data = $data . "--{$boundary}\n";
         $data = $data . "Content-Disposition: form-data; name=\"OBJ_NAME\"\n\n" . $addonId . "\n";
         $data = $data . "--{$boundary}\n";
         ///////
         //$licenseManager = &pmLicenseManager::getSingleton();
         $activeLicense = $licenseManager->getActiveLicense();
         $data = $data . "Content-Disposition: form-data; name=\"licenseFile\"; filename=\"" . $licenseManager->file . "\"\n";
         $data = $data . "Content-Type: text/plain\n";
Ejemplo n.º 2
0
 /**
  * Update this store information from the store location.
  *
  * @return bool true if updated, false otherwise
  */
 public function update($force = false, $type = 'plugin')
 {
     require_once PATH_CORE . 'classes' . PATH_SEP . 'class.pmLicenseManager.php';
     if (!class_exists('AddonsManagerPeer')) {
         require_once 'classes/model/AddonsManager.php';
     }
     //If we have any addon that is installing or updating, don't update store
     $criteria = new Criteria(AddonsManagerPeer::DATABASE_NAME);
     $criteria->add(AddonsManagerPeer::ADDON_STATE, '', Criteria::NOT_EQUAL);
     $criteria->add(AddonsManagerPeer::ADDON_TYPE, $type);
     if (AddonsManagerPeer::doCount($criteria) > 0) {
         return false;
     }
     $this->clear($type);
     //Fill with local information
     //List all plugins installed
     $oPluginRegistry =& PMPluginRegistry::getSingleton();
     $aPluginsPP = array();
     if (file_exists(PATH_DATA_SITE . 'ee')) {
         $aPluginsPP = unserialize(trim(file_get_contents(PATH_DATA_SITE . 'ee')));
     }
     $pmLicenseManagerO =& pmLicenseManager::getSingleton();
     $localPlugins = array();
     if ($type == 'plugin') {
         foreach ($aPluginsPP as $aPlugin) {
             $sClassName = substr($aPlugin['sFilename'], 0, strpos($aPlugin['sFilename'], '-'));
             if (file_exists(PATH_PLUGINS . $sClassName . '.php')) {
                 require_once PATH_PLUGINS . $sClassName . '.php';
                 $oDetails = $oPluginRegistry->getPluginDetails($sClassName . '.php');
                 if ($oDetails) {
                     $sStatus = $oDetails->enabled ? G::LoadTranslation('ID_ENABLED') : G::LoadTranslation('ID_DISABLED');
                     if (isset($oDetails->aWorkspaces)) {
                         if (!in_array(SYS_SYS, $oDetails->aWorkspaces)) {
                             continue;
                         }
                     }
                     if ($sClassName == "pmLicenseManager" || $sClassName == "pmTrial") {
                         continue;
                     }
                     $sEdit = $oDetails->sSetupPage != '' && $oDetails->enabled ? G::LoadTranslation('ID_SETUP') : ' ';
                     $aPlugin = array();
                     $aPluginId = $sClassName;
                     $aPluginTitle = $oDetails->sFriendlyName;
                     $aPluginDescription = $oDetails->sDescription;
                     $aPluginVersion = $oDetails->iVersion;
                     if (@in_array($sClassName, $pmLicenseManagerO->features)) {
                         $aPluginStatus = $sStatus;
                         $aPluginLinkStatus = 'pluginsChange?id=' . $sClassName . '.php&status=' . $oDetails->enabled;
                         $aPluginEdit = $sEdit;
                         $aPluginLinkEdit = 'pluginsSetup?id=' . $sClassName . '.php';
                         $aPluginStatusA = $sStatus == "Enabled" ? "installed" : 'disabled';
                         $enabledStatus = true;
                     } else {
                         $aPluginStatus = "";
                         $aPluginLinkStatus = '';
                         $aPluginEdit = '';
                         $aPluginLinkEdit = '';
                         $aPluginStatusA = 'minus-circle';
                         $enabledStatus = false;
                     }
                     $addon = new AddonsManager();
                     //G::pr($addon);
                     $addon->setAddonId($aPluginId);
                     $addon->setStoreId($this->getStoreId());
                     //Don't trust external data
                     $addon->setAddonName($aPluginId);
                     $addon->setAddonDescription($aPluginDescription);
                     $addon->setAddonNick($aPluginTitle);
                     $addon->setAddonVersion("");
                     $addon->setAddonStatus($aPluginStatusA);
                     $addon->setAddonType("plugin");
                     $addon->setAddonPublisher("Colosa");
                     $addon->setAddonDownloadUrl("");
                     $addon->setAddonDownloadMd5("");
                     $addon->setAddonReleaseDate(null);
                     $addon->setAddonReleaseType('localRegistry');
                     $addon->setAddonReleaseNotes("");
                     $addon->setAddonState("");
                     $addon->save();
                     $localPlugins[$aPluginId] = $addon;
                 }
             }
         }
     } else {
         $list = unserialize($pmLicenseManagerO->licensedfeaturesList);
         if (is_array($list)) {
             foreach ($list['addons'] as $key => $feature) {
                 $addon = new AddonsManager();
                 $addon->setAddonId($feature['name']);
                 $addon->setStoreId($feature['guid']);
                 $addon->setAddonName($feature['name']);
                 $addon->setAddonDescription($feature['description']);
                 $addon->setAddonNick($feature['nick']);
                 $addon->setAddonVersion("");
                 $addon->setAddonStatus($feature['status']);
                 $addon->setAddonType("features");
                 $addon->setAddonPublisher("Colosa");
                 $addon->setAddonDownloadUrl("");
                 $addon->setAddonDownloadMd5("");
                 $addon->setAddonReleaseDate(null);
                 $addon->setAddonReleaseType('localRegistry');
                 $addon->setAddonReleaseNotes("");
                 $addon->setAddonState("");
                 $addon->save();
             }
         }
     }
     $this->setStoreLastUpdated(time());
     $this->save();
     $url = $this->getStoreLocation();
     //Validate url
     $licenseInfo = $pmLicenseManagerO->getActiveLicense();
     $licenseId = str_replace('.dat', '', str_replace('license_', '', basename($licenseInfo['LICENSE_PATH'])));
     $url = explode('&', $url);
     $url[count($url) - 1] = 'licId=' . urlencode($licenseId);
     $url = implode('&', $url);
     if (EnterpriseUtils::getInternetConnection() == 1 && EnterpriseUtils::checkConnectivity($url) == true) {
         $option = array("http" => array("method" => "POST", "header" => "Content-type: application/x-www-form-urlencoded\r\n", "content" => http_build_query(array("pmVersion" => System::getVersion(), "version" => STORE_VERSION))));
         // Proxy settings
         $sysConf = System::getSystemConfiguration();
         if (isset($sysConf['proxy_host'])) {
             if ($sysConf['proxy_host'] != '') {
                 if (!is_array($option['http'])) {
                     $option['http'] = array();
                 }
                 $option['http']['request_fulluri'] = true;
                 $option['http']['proxy'] = 'tcp://' . $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '');
                 if ($sysConf['proxy_user'] != '') {
                     if (!isset($option['http']['header'])) {
                         $option['http']['header'] = '';
                     }
                     $option['http']['header'] .= 'Proxy-Authorization: Basic ' . base64_encode($sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : ''));
                 }
             }
         }
         $context = stream_context_create($option);
         //This may block for a while, always use AJAX to call this method
         $url = $url . '&type=' . strtoupper($type);
         $data = file_get_contents($url, false, $context);
         if ($data === false) {
             throw new Exception("Could not contact store");
         }
         $serverData = G::json_decode($data);
         //Don't trust external data
         if (empty($serverData)) {
             throw new Exception("Store data invalid ('{$data}')");
         }
         if (isset($serverData->error)) {
             throw new Exception("Store sent us an error: {$serverData->error}");
         }
         if (!isset($serverData->version)) {
             throw new Exception("Store version not found");
         }
         if ($serverData->version != STORE_VERSION) {
             throw new Exception("Store version '{$serverData->version}' unsupported");
         }
         if (!isset($serverData->addons)) {
             throw new Exception("Addons not found on store data");
         }
         $this->clear($type);
         try {
             //Add each item to this stores addons
             $addons = @get_object_vars($serverData->addons);
             if (!empty($addons)) {
                 foreach (get_object_vars($serverData->addons) as $addonId => $addonInfo) {
                     $addon = new AddonsManager();
                     $addon->setAddonId($addonId);
                     $addon->setStoreId($this->getStoreId());
                     //Don't trust external data
                     $addon->setAddonName(isset($addonInfo->name) ? $addonInfo->name : $addonId);
                     $addon->setAddonDescription(isset($addonInfo->description) ? $addonInfo->description : "");
                     $addon->setAddonNick(isset($addonInfo->nick) ? $addonInfo->nick : "");
                     $addon->setAddonVersion(isset($addonInfo->version) ? $addonInfo->version : "");
                     $addon->setAddonStatus(isset($addonInfo->status) ? $addonInfo->status : "");
                     $addon->setAddonType(isset($addonInfo->type) ? $addonInfo->type : "");
                     $addon->setAddonPublisher(isset($addonInfo->publisher) ? $addonInfo->publisher : "");
                     $workspace = isset($pmLicenseManagerO->workspace) ? $pmLicenseManagerO->workspace : 'pmLicenseSrv';
                     $addon->setAddonDownloadUrl(isset($addonInfo->download_url) ? $addonInfo->download_url : "http://" . $pmLicenseManagerO->server . "/sys" . $workspace . "/en/green/services/rest?action=getPlugin&OBJ_UID=" . $addonInfo->guid);
                     $addon->setAddonDownloadMd5(isset($addonInfo->download_md5) ? $addonInfo->download_md5 : "");
                     $addon->setAddonReleaseDate(isset($addonInfo->release_date) ? $addonInfo->release_date : "");
                     $addon->setAddonReleaseType(isset($addonInfo->release_type) ? $addonInfo->release_type : '');
                     $addon->setAddonReleaseNotes(isset($addonInfo->release_notes) ? $addonInfo->release_notes : "");
                     $addon->setAddonState("");
                     $addon->save();
                     if (isset($localPlugins[$addonId])) {
                         unset($localPlugins[$addonId]);
                     }
                 }
                 foreach ($localPlugins as $keyPlugin => $addonA) {
                     //G::pr($addonA );
                     //$addonA->save();
                     $addon = new AddonsManager();
                     //G::pr($addon);
                     $addon->setAddonId($addonA->getAddonId());
                     $addon->setStoreId($addonA->getStoreId());
                     //Don't trust external data
                     $addon->setAddonName($addonA->getAddonName());
                     $addon->setAddonDescription($addonA->getAddonDescription());
                     $addon->setAddonNick($addonA->getAddonNick());
                     $addon->setAddonVersion("");
                     $addon->setAddonStatus($addonA->getAddonStatus());
                     $addon->setAddonType($addonA->getAddonType());
                     $addon->setAddonPublisher($addonA->getAddonPublisher());
                     $addon->setAddonDownloadUrl($addonA->getAddonDownloadUrl());
                     $addon->setAddonDownloadMd5($addonA->getAddonDownloadMd5());
                     $addon->setAddonReleaseDate(null);
                     $addon->setAddonReleaseType('localRegistry');
                     $addon->setAddonReleaseNotes("");
                     $addon->setAddonState("");
                     $addon->save();
                 }
             }
             $this->setStoreLastUpdated(time());
             $this->save();
         } catch (Exception $e) {
             //If we had issues, don't keep only a part of the items
             $this->clear($type);
             throw $e;
         }
     }
     return true;
 }