Merged in marcoAntonioNina/processmaker/PM-295 (pull request #799)

PM-295 Plugin Enterprise que sea parte del core SOLVED
This commit is contained in:
Julio Cesar Laura Avendaño
2014-09-19 13:59:29 -04:00
76 changed files with 11992 additions and 10 deletions

View File

@@ -0,0 +1,82 @@
<?php
require_once PATH_CORE . 'classes' . PATH_SEP . 'class.pmLicenseManager.php';
require_once PATH_CORE . "classes" . PATH_SEP . "model" . PATH_SEP . "AddonsStore.php";
require_once PATH_CORE . "classes" . PATH_SEP . "class.enterpriseUtils.php";
AddonsStore::checkLicenseStore();
$licenseManager = &pmLicenseManager::getSingleton();
$oHeadPublisher = &headPublisher::getSingleton();
if (isset($licenseManager->date) && is_array($licenseManager->date)) {
G::LoadClass( "configuration" );
$conf = new Configurations();
if ( defined('SYS_SYS') && $conf->exists("ENVIRONMENT_SETTINGS")) {
$licenseManager->date['START'] = date("Y-m-d H:i:s", strtotime($licenseManager->date['HUMAN']['START']));
$licenseManager->date['END'] = date("Y-m-d H:i:s", strtotime($licenseManager->date['HUMAN']['END']));
$licenseManager->date['START'] = $conf->getSystemDate($licenseManager->date['START']);
$licenseManager->date['END'] = $conf->getSystemDate($licenseManager->date['END']);
} else {
$licenseManager->date['START'] = date("Y-m-d H:i:s", strtotime($licenseManager->date['HUMAN']['START']));
$licenseManager->date['END'] = date("Y-m-d H:i:s", strtotime($licenseManager->date['HUMAN']['END']));
$licenseManager->date['START'] = G::getformatedDate($licenseManager->date['START'], 'M d, yyyy', SYS_LANG);
$licenseManager->date['END'] = G::getformatedDate($licenseManager->date['END'], 'M d, yyyy', SYS_LANG);
}
}
if (isset($licenseManager->result) && $licenseManager->result == "OK") {
$oHeadPublisher->assign("license_start_date",$licenseManager->date["START"]);
$oHeadPublisher->assign("license_end_date", $licenseManager->expireIn!="NEVER" ? $licenseManager->date["END"]:"NA" );
$oHeadPublisher->assign("license_user", $licenseManager->info["FIRST_NAME"] . " " . $licenseManager->info["LAST_NAME"] . " (" . $licenseManager->info["DOMAIN_WORKSPACE"] . ")");
$oHeadPublisher->assign("license_span", $licenseManager->expireIn != "NEVER" ? ceil($licenseManager->date["SPAN"]/60/60/24) : "~");
$oHeadPublisher->assign("license_name", $licenseManager->type);
$oHeadPublisher->assign("license_server", $licenseManager->server);
$oHeadPublisher->assign("license_expires", $licenseManager->expireIn);
$oHeadPublisher->assign("license_message", $licenseManager->status["message"]);
$oHeadPublisher->assign("licensed", true);
}
elseif (isset($licenseManager->info)) {
$oHeadPublisher->assign("license_start_date", $licenseManager->date["START"]);
$oHeadPublisher->assign("license_end_date", $licenseManager->date["END"]);
$oHeadPublisher->assign("license_span", $licenseManager->expireIn != "NEVER" ? ceil($licenseManager->date["SPAN"]/60/60/24) : "~");
$oHeadPublisher->assign("license_user", $licenseManager->info["FIRST_NAME"] . " " . $licenseManager->info["LAST_NAME"] . " (" . $licenseManager->info["DOMAIN_WORKSPACE"] . ")");
$oHeadPublisher->assign("license_name", $licenseManager->type);
$oHeadPublisher->assign("license_server", $licenseManager->server);
$oHeadPublisher->assign("license_expires", $licenseManager->expireIn);
$oHeadPublisher->assign("license_message", $licenseManager->status["message"]);
$oHeadPublisher->assign("licensed", false);
} else {
$oHeadPublisher->assign("license_user", "");
$oHeadPublisher->assign("license_name", "<b>Unlicensed</b>");
$oHeadPublisher->assign("license_server", "<b>no server</b>");
$oHeadPublisher->assign("license_expires", "");
$currentLicenseStatus = $licenseManager->getCurrentLicenseStatus();
$oHeadPublisher->assign("license_message", $currentLicenseStatus["message"]);
$oHeadPublisher->assign("license_start_date", "");
$oHeadPublisher->assign("license_end_date", "");
$oHeadPublisher->assign("license_span", "");
$oHeadPublisher->assign("licensed", false);
}
$oHeadPublisher->assign("license_serial", (isset($licenseManager->licenseSerial))? $licenseManager->licenseSerial : '');
$oHeadPublisher->assign("SUPPORT_FLAG", ((isset($licenseManager->supportStartDate) && $licenseManager->supportStartDate == '') || !isset($licenseManager->supportStartDate)) ? true : false );
$oHeadPublisher->assign("supportStartDate", (isset($licenseManager->supportStartDate))? $licenseManager->supportStartDate : '');
$oHeadPublisher->assign("supportEndDate", (isset($licenseManager->supportEndDate))? $licenseManager->supportEndDate : '');
G::LoadClass("system");
$oHeadPublisher->assign("PROCESSMAKER_VERSION", System::getVersion());
$oHeadPublisher->assign("PROCESSMAKER_URL", "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN );
$oHeadPublisher->assign("SYS_SKIN", SYS_SKIN);
$oHeadPublisher->assign("URL_PART_LOGIN", ((substr(SYS_SKIN, 0, 2) == "ux" && SYS_SKIN != "uxs")? "main/login" : "login/login"));
$oHeadPublisher->assign("URL_PART_SETUP", EnterpriseUtils::getUrlPartSetup());
$oHeadPublisher->assign("PATH_PLUGINS_WRITABLE", ((is_writable(PATH_PLUGINS))? 1 : 0));
$oHeadPublisher->assign("PATH_PLUGINS_WRITABLE_MESSAGE", "The directory " . PATH_PLUGINS . " have not writable.");
$oHeadPublisher->assign("SKIN_IS_UX", EnterpriseUtils::skinIsUx());
$oHeadPublisher->assign("INTERNET_CONNECTION", EnterpriseUtils::getInternetConnection());
$oHeadPublisher->addExtJsScript("enterprise/addonsStore", true);
G::RenderPage("publish", "extJs");

View File

@@ -0,0 +1,363 @@
<?php
require_once PATH_CORE . 'classes' . PATH_SEP . 'class.enterpriseUtils.php';
require_once PATH_CORE . 'classes' . PATH_SEP . 'class.pmLicenseManager.php';
require_once PATH_CORE . 'methods' . PATH_SEP . 'enterprise' . PATH_SEP . 'enterprise.php';
require_once PATH_CORE . 'classes' . PATH_SEP . 'model' . PATH_SEP . 'AddonsManagerPeer.php';
function runBgProcessmaker($task, $log)
{
require_once (PATH_CORE . "bin/tasks/cliAddons.php");
//require_once PATH_CORE . 'classes' . PATH_SEP . 'class.enterpriseUtils.php';
/*
$pmosFilename = PATH_TRUNK . "processmaker";
$cmd = "php -f \"$pmosFilename\" $task";
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
}
else {
$str = system("$cmd 1> \"$log.log\" 2> \"$log.err\" < /dev/null &", $retval);
}
*/
$task = str_replace("\"", null, $task);
$data = explode(" ", $task);
$elem = array_shift($data); //delete first element
run_addon_install($data);
}
try {
if (isset($_REQUEST["action"])) {
$action = $_REQUEST["action"];
} else {
throw (new Exception("Action undefined"));
}
if (isset($_REQUEST['addon']) && isset($_REQUEST['store'])) {
require_once (PATH_CORE . 'classes/model/AddonsManagerPeer.php');
$addon = AddonsManagerPeer::retrieveByPK($_REQUEST['addon'], $_REQUEST['store']);
$addonId = $_REQUEST['addon'];
$storeId = $_REQUEST['store'];
if ($addon === null) {
throw (new Exception("Unable to find addon (id: '{$_REQUEST['addon']}', store: '{$_REQUEST['store']}')"));
}
} else {
$addon = null;
}
$result = array();
switch (strtolower($action)) {
case "importlicense":
if (sizeof($_FILES) > 0) {
$aInfoLoadFile = $_FILES["upLicense"];
$aExtentionFile = explode(".", $aInfoLoadFile["name"]);
//validating the extention before to upload it
if (trim($aExtentionFile[sizeof($aExtentionFile) - 1]) != "dat") {
//G::SendTemporalMessage("ID_ISNT_LICENSE", "tmp-info", "labels");
$result["errors"] = "Filename does not end with .dat";
$result["success"] = false;
} else {
$dir = PATH_DATA_SITE;
G::uploadFile($aInfoLoadFile["tmp_name"], $dir, $aInfoLoadFile["name"]);
//reading the file that was uploaded
$oPmLicenseManager = &pmLicenseManager::getSingleton();
$response = $oPmLicenseManager->installLicense($dir . $aInfoLoadFile["name"]);
///////
//This command also find the following file "AddonsStore.php"
$licenseManager = &pmLicenseManager::getSingleton();
preg_match("/^license_(.*).dat$/", $licenseManager->file, $matches);
$realId = urlencode($matches[1]);
$addonLocation = "http://{$licenseManager->server}/syspmLicenseSrv/en/green/services/addonsStore?action=getInfo&licId=$realId";
///////
$cnn = Propel::getConnection("workflow");
$oCriteriaSelect = new Criteria("workflow");
$oCriteriaSelect->add(AddonsStorePeer::STORE_ID, $licenseManager->id);
$oCriteriaUpdate = new Criteria("workflow");
$oCriteriaUpdate->add(AddonsStorePeer::STORE_ID, $licenseManager->id);
$oCriteriaUpdate->add(AddonsStorePeer::STORE_LOCATION, $addonLocation);
BasePeer::doUpdate($oCriteriaSelect, $oCriteriaUpdate, $cnn);
///////
//$licenseManager = &pmLicenseManager::getSingleton();
//plugin.singleton //are all the plugins that are enabled in the SYS_SYS
$pluginRegistry = &PMPluginRegistry::getSingleton();
$arrayAddon = array();
//ee //all plugins enterprise installed in /processmaker/workflow/engine/plugins (no matter if they are enabled/disabled)
if (file_exists(PATH_DATA_SITE . "ee")) {
$arrayAddon = unserialize(trim(file_get_contents(PATH_DATA_SITE . "ee")));
}
foreach ($arrayAddon as $addon) {
$sFileName = substr($addon["sFilename"], 0, strpos($addon["sFilename"], "-"));
if (file_exists(PATH_PLUGINS . $sFileName . ".php")) {
$addonDetails = $pluginRegistry->getPluginDetails($sFileName . ".php");
$enabled = 0;
if ($addonDetails) {
$enabled = ($addonDetails->enabled)? 1 : 0;
}
if ($enabled == 1 && !in_array($sFileName, $licenseManager->features)) {
require_once (PATH_PLUGINS . $sFileName . ".php");
$pluginRegistry->disablePlugin($sFileName);
}
}
}
file_put_contents(PATH_DATA_SITE . "plugin.singleton", $pluginRegistry->serializeInstance());
///////
$message = "A license has been correctly installed. Please login again to apply the changes";
G::SendMessageText($message, "INFO");
$_SESSION["___PMEE_INSTALLED_LIC___"] = $message;
//G::header("location: ../enterprise/pluginsList"); //ok
//exit(0);
}
}
break;
case "cancel":
if ($addon === null) {
throw new Exception("No addon specified to $action");
}
if ($addon->getAddonState() == "download") {
$addon->setState("cancel");
}
break;
case "uninstall":
$status = 1;
try {
if ($addon === null) {
throw new Exception("No addon specified to $action");
}
$r = $addon->uninstall();
$result["status"] = "OK";
} catch (Exception $e) {
$result["message"] = $e->getMessage();
$status = 0;
}
if ($status == 0) {
$result["status"] = "ERROR";
}
break;
case "finish":
if ($addon === null) {
throw new Exception("No addon specified to $action");
}
$addon->setState();
break;
case "disable":
case "enable":
if ($addon === null) {
throw new Exception("No addon specified to $action");
}
$result["success"] = $addon->setEnabled(($action == "enable"));
break;
case "install":
$status = 1;
try {
if (EnterpriseUtils::getInternetConnection() == 0) {
throw (new Exception("Enterprise Plugins Manager no connected to internet."));
}
///////
$aux = explode("?", $addon->getAddonDownloadUrl());
$url = $aux[0];
if (EnterpriseUtils::checkConnectivity($url) == false) {
throw (new Exception("Server $url not available."));
}
if ($addon === null) {
throw new Exception("No addon specified to $action");
}
///////
$workspace = SYS_SYS;
$dbAdapter = DB_ADAPTER;
$addon->setAddonState("download-start");
$addon->save();
$log = $addon->getDownloadDirectory() . "/download";
runBgProcessmaker("addon-install \"$workspace\" \"$storeId\" \"$addonId\" \"$dbAdapter\"", $log);
//Check if the background process started successfully.
$failed = false;
$max_retries = 15;
$retries = 0;
while (true) {
sleep(1);
$addon->refresh();
if ($addon->getAddonState() != "download-start") {
break;
}
//$logContents = file_get_contents("$log.log", false, NULL, 0, 10);
//if (!empty($logContents))
// break;
$retries += 1;
if ($retries > $max_retries) {
$failed = true;
break;
}
}
//if ($failed) {
// //$addon->clearState(); //clearState no found
// $result["success"] = false;
//}
$result["status"] = "OK";
} catch (Exception $e) {
$result["message"] = $e->getMessage();
$status = 0;
}
if ($status == 0) {
$result["status"] = "ERROR";
}
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;
$url = "http://$server/syspmLicenseSrv/en/green/services/rest";
if (EnterpriseUtils::checkConnectivity($url) == false) {
throw (new Exception("Server \"$server\" not available."));
}
///////
$boundary = "---------------------" . substr(md5(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";
$data = $data . "Content-Transfer-Encoding: binary\n\n";
$data = $data . file_get_contents($activeLicense["LICENSE_PATH"]) . "\n";
$data = $data . "--$boundary\n";
///////
$option = array(
"http" => array(
"method" => "POST",
"header" => "Content-Type: multipart/form-data; boundary=" . $boundary,
"content" => $data
)
);
// Proxy settings
$sysConf = System::getSystemConfiguration();
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);
///////
$fileData = file_get_contents($url, false, $context);
//////////
$r = G::json_decode($fileData);
if ($r->status == "OK") {
$response["status"] = $r->status; //OK
} else {
throw (new Exception($r->message));
}
} catch (Exception $e) {
$response["message"] = $e->getMessage();
$status = 0;
}
if ($status == 0) {
$response["status"] = "ERROR";
}
echo G::json_encode($response);
exit(0);
break;
case "addonslist":
$result = AddonsStore::addonList();
break;
default:
throw (new Exception("Action \"$action\" is not valid"));
}
if (!isset($result["success"])) {
$result["success"] = true;
}
if (isset($result["addons"])) {
$result["addons"] = array_values($result["addons"]);
} else {
$result["addons"] = array();
}
echo G::json_encode($result);
} catch (Exception $e) {
echo G::json_encode(array("success" => false, "errors" => $e->getMessage()));
}

View File

@@ -0,0 +1,364 @@
<?php
require_once ("classes/model/Configuration.php");
G::LoadClass("plugin");
if (!defined("PATH_PM_ENTERPRISE")) {
define("PATH_PM_ENTERPRISE", PATH_CORE . "enterprise/");
}
if (!defined("PATH_DATA_SITE")) {
define("PATH_DATA_SITE", PATH_DATA . "sites/" . SYS_SYS . "/");
}
set_include_path(PATH_PM_ENTERPRISE . PATH_SEPARATOR . get_include_path());
class enterprisePlugin extends PMPlugin
{
public function enterprisePlugin($sNamespace, $sFilename = null)
{
$pathPluginTrunk = PATH_CORE . "enterprise";
$VERSION = System::getVersion();
$res = parent::PMPlugin($sNamespace, $sFilename);
$this->sFriendlyName = "ProcessMaker Enterprise Edition";
$this->sDescription = "ProcessMaker Enterprise Edition $VERSION";
$this->sPluginFolder = "enterprise";
$this->sSetupPage = "../enterprise/pluginsList.php";
$this->iVersion = $VERSION;
$this->iPMVersion = "2.0.31";
$this->aDependences = null;
$this->aWorkspaces = null;
$this->database = "workflow";
$this->table = array("ADDONS_STORE", "ADDONS_MANAGER", "LICENSE_MANAGER");
if (!isset($_SESSION["__EE_INSTALLATION__"])) {
$_SESSION["__EE_INSTALLATION__"] = 0;
}
if (!isset($_SESSION["__EE_SW_PMLICENSEMANAGER__"])) {
$_SESSION["__EE_SW_PMLICENSEMANAGER__"] = 1;
}
$sw = 1;
$msgf = null;
$msgd = null;
if (file_exists(PATH_CORE . "plugins" . PATH_SEP . "pmLicenseManager.php")) {
$_SESSION["__EE_INSTALLATION__"] = 1;
$_SESSION["__EE_SW_PMLICENSEMANAGER__"] = 0;
$plugin = "pmLicenseManager";
$this->pluginUninstall($plugin);
if (file_exists(PATH_CORE . "plugins" . PATH_SEP . $plugin . ".php") || file_exists(PATH_CORE . "plugins" . PATH_SEP . $plugin)) {
$msgf = $msgf . (($msgf != null)? ", " : null) . $plugin . ".php";
$msgd = $msgd . (($msgd != null)? ", " : null) . $plugin;
$sw = 0;
}
$plugin = "enterprise";
$this->pluginUninstall($plugin);
if (file_exists(PATH_CORE . "plugins" . PATH_SEP . $plugin . ".php") || file_exists(PATH_CORE . "plugins" . PATH_SEP . $plugin)) {
$msgf = $msgf . (($msgf != null)? ", " : null) . $plugin . ".php";
$msgd = $msgd . (($msgd != null)? ", " : null) . $plugin;
$sw = 0;
}
$this->uninstall();
} else {
$_SESSION["__EE_INSTALLATION__"] = $_SESSION["__EE_INSTALLATION__"] + 1;
}
if ($sw == 0) {
unset($_SESSION["__EE_INSTALLATION__"]);
unset($_SESSION["__EE_SW_PMLICENSEMANAGER__"]);
///////
$js = "window.open(\"/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/setup/main?s=PLUGINS\", \"_top\", \"\");";
if (substr(SYS_SKIN, 0, 2) == "ux" && SYS_SKIN != "uxs") {
//$js = "parent.window.location.href = \"/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/setup/main_init?s=PLUGINS\";";
//$js = "window.location.href = \"/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/setup/pluginsImport\";";
$js = "window.open(\"/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/main\", \"_top\", \"\");";
}
///////
G::SendMessageText("ProcessMaker Enterprise plug-in can't delete the files \"$msgf\" and directories \"$msgd\" of \"" . (PATH_CORE . "plugins") . "\". Before proceeding with the installation of the plug-in must remove them.", "INFO");
echo "<script type=\"text/javascript\">" . $js . "</script>";
exit(0);
}
if ($_SESSION["__EE_SW_PMLICENSEMANAGER__"] == 0 && $_SESSION["__EE_INSTALLATION__"] == 2) {
unset($_SESSION["__EE_INSTALLATION__"]);
unset($_SESSION["__EE_SW_PMLICENSEMANAGER__"]);
$this->install();
}
///////
return $res;
}
public function install()
{
}
public function uninstall()
{
}
public function setup()
{
$urlPart = substr(SYS_SKIN, 0, 2) == 'ux' && SYS_SKIN != 'uxs' ? 'main/login' : 'login/login';
$this->registerMenu("setup", "menuEnterprise.php");
//including the file inside the enterprise folder
require_once PATH_CORE . 'classes' . PATH_SEP . 'class.pmLicenseManager.php';
$this->registerTrigger(PM_LOGIN, "enterpriseSystemUpdate");
$licenseManager = &pmLicenseManager::getSingleton();
$oHeadPublisher = &headPublisher::getSingleton();
}
public function enable()
{
$this->setConfiguration();
$pluginRegistry = &PMPluginRegistry::getSingleton();
file_put_contents(PATH_DATA_SITE . "plugin.singleton", $pluginRegistry->serializeInstance());
require_once (PATH_CORE . 'classes/model/AddonsStore.php');
AddonsStore::checkLicenseStore();
$licenseManager = &pmLicenseManager::getSingleton();
AddonsStore::updateAll(false);
}
public function disable()
{
}
public function setConfiguration()
{
$confEeUid = "enterpriseConfiguration";
$criteria = new Criteria("workflow");
$criteria->addSelectColumn(ConfigurationPeer::CFG_VALUE);
$criteria->add(ConfigurationPeer::CFG_UID, "EE");
$criteria->add(ConfigurationPeer::OBJ_UID, $confEeUid);
$rsCriteria = ConfigurationPeer::doSelectRS($criteria);
if (!$rsCriteria->next()) {
$conf = new Configuration();
$data = array("internetConnection" => 1);
$conf->create(
array(
"CFG_UID" => "EE",
"OBJ_UID" => $confEeUid,
"CFG_VALUE" => serialize($data),
"PRO_UID" => "",
"USR_UID" => "",
"APP_UID" => ""
)
);
}
}
public function pluginUninstall($pluginName)
{
//define("PATH_PLUGINS", PATH_CORE . "plugins" . PATH_SEP);
if (file_exists(PATH_CORE . "plugins" . PATH_SEP . $pluginName . ".php")) {
require_once (PATH_CORE . "plugins" . PATH_SEP . $pluginName . ".php");
$pluginRegistry = &PMPluginRegistry::getSingleton();
$pluginDetail = $pluginRegistry->getPluginDetails($pluginName . ".php");
if ($pluginDetail) {
$pluginRegistry->enablePlugin($pluginDetail->sNamespace);
$pluginRegistry->disablePlugin($pluginDetail->sNamespace);
///////
$plugin = new $pluginDetail->sClassName($pluginDetail->sNamespace, $pluginDetail->sFilename);
//$this->_aPlugins[$pluginDetail->sNamespace] = $plugin;
if (method_exists($plugin, "uninstall")) {
$plugin->uninstall();
}
///////
file_put_contents(PATH_DATA_SITE . "plugin.singleton", $pluginRegistry->serializeInstance());
}
///////
unlink(PATH_CORE . "plugins" . PATH_SEP . $pluginName . ".php");
if (file_exists(PATH_CORE . "plugins" . PATH_SEP . $pluginName)) {
G::rm_dir(PATH_CORE . "plugins" . PATH_SEP . $pluginName);
}
}
}
public function registerEE($pluginFile, $pluginVersion)
{
if (file_exists(PATH_DATA_SITE . "ee")) {
$this->systemAvailable = unserialize(trim(file_get_contents(PATH_DATA_SITE . "ee")));
}
$this->systemAvailable[$pluginFile]["sFilename"] = $pluginFile . "-" . $pluginVersion . ".tar";
file_put_contents(PATH_DATA_SITE . "ee", serialize($this->systemAvailable));
return true;
}
public function checkDependencies()
{
}
public function tableBackup($tableBackup, $backupPrefix = "_", $backupSuffix = "_TEMP")
{
//Database Connections
$cnn = Propel::getConnection($this->database);
$stmt = $cnn->createStatement();
foreach ($tableBackup as $key => $table) {
$tablebak = $backupPrefix . $table . $backupSuffix;
//First Search if the Table exists
$sqlTable = "SHOW TABLES LIKE '$table'";
$rsTable = $stmt->executeQuery($sqlTable, ResultSet::FETCHMODE_ASSOC);
if ($rsTable->getRecordCount() > 0) {
//Table $table exists, so we can Backup
//If there are records in $table Backup
$sqlSelectTable = "SELECT * FROM $table";
$rsSelectTable = $stmt->executeQuery($sqlSelectTable, ResultSet::FETCHMODE_ASSOC);
if ($rsSelectTable->getRecordCount() > 0) {
//There are records in $table!! Backup!
//Delete a previous Backup if exists
$sql = "DROP TABLE IF EXISTS $tablebak;";
$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
//Create a COPY of $table in $tablebak :: Backup
$sql = "CREATE TABLE $tablebak SELECT * FROM $table";
$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
//Delete a previous $table if exists
$sql = "DROP TABLE IF EXISTS $table;";
$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
}
}
}
}
public function tableBackupRestore($tableBackup, $backupPrefix = "_", $backupSuffix = "_TEMP")
{
//Database Connections
$cnn = Propel::getConnection($this->database);
$stmt = $cnn->createStatement();
foreach ($tableBackup as $key => $table) {
$tablebak = $backupPrefix . $table . $backupSuffix;
//First Search if the $tablebak exists
$sqlTablebak = "SHOW TABLES LIKE '$tablebak'";
$rsTablebak = $stmt->executeQuery($sqlTablebak, ResultSet::FETCHMODE_ASSOC);
if ($rsTablebak->getRecordCount() > 0) {
//Table $tablebak exists, so we can Restore
$sqlSelectTablebak = "SELECT * FROM $tablebak";
$rsSelectTablebak = $stmt->executeQuery($sqlSelectTablebak, ResultSet::FETCHMODE_ASSOC);
if ($rsSelectTablebak->getRecordCount() > 0) {
$strTable = str_replace("_", " ", strtolower($table));
$strTable = str_replace(" ", null, ucwords($strTable));
require_once (PATH_PLUGINS . "enterprise" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "$strTable.php");
while ($rsSelectTablebak->next()) {
$row = $rsSelectTablebak->getRow();
//INSERT INTO TABLEN(FIELD1, FIELD2) VALUES('VALUE1', 'VALUE2')
$oTable = new $strTable();
$oTable->fromArray($row, BasePeer::TYPE_FIELDNAME); //Fill an object from of the array //Fill attributes
$oTable->save();
}
}
//Delete Backup
$sql = "DROP TABLE IF EXISTS $tablebak;";
$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
}
}
}
/*
public function tableIsInstalled()
{
G::LoadSystem("database_" . DB_ADAPTER);
$database = new database(DB_ADAPTER, DB_HOST, DB_USER, DB_PASS, DB_NAME);
$cnn = Propel::getConnection($this->database);
$stmt = $cnn->createStatement();
$sw = true;
foreach ($this->table as $key => $table) {
$rs = $stmt->executeQuery($database->generateShowTablesLikeSQL($table), ResultSet::FETCHMODE_ASSOC);
if ($rs->getRecordCount() == 0) {
$sw = false;
}
}
return ($sw);
}
*/
public function sqlExecute($sqlFile)
{
$file = fopen($sqlFile, "r");
if ($file) {
$line = null;
while (!feof($file)) {
$buffer = trim(fgets($file, 4096)); //Read a line.
if (strlen($buffer) > 0 && $buffer[0] != "#") {
//Check for valid lines
$line = $line . $buffer;
if ($buffer[strlen($buffer) - 1] == ";") {
$cnn = Propel::getConnection($this->database);
$stmt = $cnn->createStatement();
$rs = $stmt->executeQuery($line, ResultSet::FETCHMODE_NUM);
$line = null;
}
}
}
fclose($file);
}
}
}
$oPluginRegistry = &PMPluginRegistry::getSingleton();
$oPluginRegistry->registerPlugin('enterprise', __FILE__); //<- enterprise string must be in single quote, otherwise generate error
//since we are placing pmLicenseManager and EE together.. after register EE, we need to require_once the pmLicenseManager
//if( !defined("PATH_PM_LICENSE_MANAGER") ) {
// define("PATH_PM_LICENSE_MANAGER", PATH_CORE . "/plugins/pmLicenseManager/");
//}
//set_include_path(
// PATH_PM_LICENSE_MANAGER.PATH_SEPARATOR.
// get_include_path()
//);

View File

@@ -0,0 +1,70 @@
<?php
require_once ("classes/model/Configuration.php");
$option = (isset($_POST["option"]))? $_POST["option"] : null;
$response = array();
switch ($option) {
case "SETUP":
$swInternetConnection = intval($_POST["internetConnection"]);
$status = 1;
try {
$confEeUid = "enterpriseConfiguration";
$criteria = new Criteria("workflow");
$criteria->addSelectColumn(ConfigurationPeer::CFG_VALUE);
$criteria->add(ConfigurationPeer::CFG_UID, "EE");
$criteria->add(ConfigurationPeer::OBJ_UID, $confEeUid);
$rsCriteria = ConfigurationPeer::doSelectRS($criteria);
if ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
$data = unserialize($row[0]);
$data["internetConnection"] = $swInternetConnection;
//Update values
$criteria1 = new Criteria("workflow");
$criteria1->add(ConfigurationPeer::CFG_UID, "EE");
$criteria1->add(ConfigurationPeer::OBJ_UID, $confEeUid);
//Update set
$criteria2 = new Criteria("workflow");
$criteria2->add(ConfigurationPeer::CFG_VALUE, serialize($data));
BasePeer::doUpdate($criteria1, $criteria2, Propel::getConnection("workflow"));
} else {
$conf = new Configuration();
$data = array("internetConnection" => $swInternetConnection);
$conf->create(
array(
"CFG_UID" => "EE",
"OBJ_UID" => $confEeUid,
"CFG_VALUE" => serialize($data),
"PRO_UID" => "",
"USR_UID" => "",
"APP_UID" => ""
)
);
}
$response["status"] = "OK";
} catch (Exception $e) {
$response["message"] = $e->getMessage();
$status = 0;
}
if ($status == 0) {
$response["status"] = "ERROR";
}
break;
}
echo G::json_encode($response);

View File

@@ -0,0 +1,31 @@
<?php
global $G_TMP_MENU;
if (class_exists("pmLicenseManager")) {
$pmLicenseManagerO = &pmLicenseManager::getSingleton();
$licenseStatusInfo = $pmLicenseManagerO->getCurrentLicenseStatus();
$licStatusMsg = null;
if ((isset($pmLicenseManagerO->plan)) && ($pmLicenseManagerO->plan != "")) {
$lines = explode(" - ", $pmLicenseManagerO->plan);
if (isset($lines[0])) {
$licStatusMsg .= "<br><i><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $lines[0] . "</small></i>";
}
if ((isset($lines[1])) && ($lines[1] != $lines[0])) {
$licStatusMsg .= "<br><i><small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $lines[1] . "</small></i>";
}
}
if ($licenseStatusInfo["message"] != "") {
$licStatusMsg = "&nbsp;<font color=\"red\">(" . $licenseStatusInfo["message"] . ")</font>";
}
$G_TMP_MENU->AddIdRawOption("PMENTERPRISE", "../enterprise/addonsStore", "Enterprise Plugins Manager" . $licStatusMsg, "", "", "plugins");
if (isset($pmLicenseManagerO->result) && ($pmLicenseManagerO->result == "OK")) {
if (file_exists(PATH_HOME . "engine" . PATH_SEP . "methods" . PATH_SEP . "cases" . PATH_SEP . "casesListExtJs.php")) {
$G_TMP_MENU->AddIdRawOption("CASES_LIST_SETUP", "../enterprise/advancedTools/casesListSetup", "Cases Lists", "", "", "settings");
}
}
}

View File

@@ -0,0 +1,183 @@
<?php
/**
* processes_ImportFile.php
*
* ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2008 Colosa Inc.23
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*
*/
global $RBAC;
$RBAC->requirePermissions("PM_SETUP_ADVANCE");
require_once PATH_CORE . 'methods' . PATH_SEP . 'enterprise' . PATH_SEP . 'enterprise.php';
$response = array();
$status = 1;
try {
//Load the variables
G::LoadClass("plugin");
if (!isset($_FILES["form"]["error"]["PLUGIN_FILENAME"]) || $_FILES["form"]["error"]["PLUGIN_FILENAME"] == 1) {
$str = "There was an error uploading the file, probably the file size if greater than upload_max_filesize parameter in php.ini, please check this parameter and try again.";
throw (new Exception($str));
}
//save the file
if ($_FILES["form"]["error"]["PLUGIN_FILENAME"] == 0) {
$filename = $_FILES["form"]["name"]["PLUGIN_FILENAME"];
$path = PATH_DOCUMENT . "input" . PATH_SEP ;
$tempName = $_FILES["form"]["tmp_name"]["PLUGIN_FILENAME"];
G::uploadFile($tempName, $path, $filename );
}
if (!$_FILES["form"]["type"]["PLUGIN_FILENAME"] == "application/octet-stream") {
$str = "the uploaded files are invalid, expected \"application/octect-stream\" mime type file (". $_FILES["form"]["type"]["PLUGIN_FILENAME"] . ")";
throw (new Exception($str));
}
G::LoadThirdParty("pear/Archive","Tar");
$tar = new Archive_Tar($path. $filename);
$sFileName = substr($filename, 0, strrpos($filename, "."));
$sClassName = substr($filename, 0, strpos($filename, "-"));
$aFiles = $tar->listContent();
$bMainFile = false;
$bClassFile = false;
if (is_array($aFiles)) {
foreach ($aFiles as $key => $val) {
if ($val["filename"] == $sClassName . ".php") {
$bMainFile = true;
}
if ($val["filename"] == $sClassName . PATH_SEP . "class." . $sClassName . ".php") {
$bClassFile = true;
}
}
} else {
$str = "Failed to import the file default by doesn't a plugin or invalid file.";
throw (new Exception($str));
}
$oPluginRegistry = &PMPluginRegistry::getSingleton();
$pluginFile = $sClassName . '.php';
if ($bMainFile && $bClassFile) {
$sAux = $sClassName . 'Plugin';
$fVersionOld = 0.0;
if (file_exists(PATH_PLUGINS . $pluginFile)) {
if (!class_exists($sAux) && !class_exists($sClassName . 'plugin')) {
include PATH_PLUGINS . $pluginFile;
}
if (!class_exists($sAux)) {
$sAux = $sClassName . 'plugin';
}
$oClass = new $sAux($sClassName);
$fVersionOld = $oClass->iVersion;
unset($oClass);
}
$res = $tar->extract($path);
$sContent = file_get_contents($path . $pluginFile);
$sContent = str_ireplace($sAux, $sAux . '_', $sContent);
$sContent = str_ireplace('PATH_PLUGINS', "'".$path."'", $sContent);
$sContent = preg_replace("/\\\$oPluginRegistry\s*=\s*&\s*PMPluginRegistry::getSingleton\s*\(\s*\)\s*;/i", null, $sContent);
$sContent = preg_replace("/\\\$oPluginRegistry->registerPlugin\s*\(\s*[\"\']" . $sClassName . "[\"\']\s*,\s*__FILE__\s*\)\s*;/i", null, $sContent);
//header('Content-Type: text/plain');var_dump($sClassName, $sContent);die;
file_put_contents($path . $pluginFile, $sContent);
$sAux = $sAux . '_';
include ($path . $pluginFile);
$oClass = new $sAux($sClassName);
$fVersionNew = $oClass->iVersion;
if (!isset($oClass->iPMVersion)) {
$oClass->iPMVersion = 0;
}
//if ($oClass->iPMVersion > 0) {
// G::LoadClass("system");
// if (System::getVersion() > 0) {
// if ($oClass->iPMVersion > System::getVersion()) {
// //throw new Exception('This plugin needs version ' . $oClass->iPMVersion . ' or higher of ProcessMaker');
// }
// }
//}
/*
if (!isset($oClass->aDependences)) {
$oClass->aDependences = null;
}
if (!empty($oClass->aDependences)) {
foreach ($oClass->aDependences as $aDependence) {
if (file_exists(PATH_PLUGINS . $aDependence['sClassName'] . '.php')) {
require_once PATH_PLUGINS . $aDependence['sClassName'] . '.php';
if (!$oPluginRegistry->getPluginDetails($aDependence['sClassName'] . '.php')) {
throw new Exception('This plugin needs "' . $aDependence['sClassName'] . '" plugin');
}
} else {
throw new Exception('This plugin needs "' . $aDependence['sClassName'] . '" plugin');
}
}
}
unset($oClass);
if ($fVersionOld > $fVersionNew) {
throw new Exception('A recent version of this plugin was already installed.');
}
*/
$res = $tar->extract(PATH_PLUGINS);
} else {
$str = "The file $filename doesn't contain class: $sClassName ";
throw (new Exception($str));
}
if (! file_exists(PATH_PLUGINS . $sClassName . '.php')) {
$str = "File '$pluginFile' doesn't exists ";
throw (new Exception($str));
}
require_once (PATH_PLUGINS . $pluginFile);
$oPluginRegistry->registerPlugin($sClassName, PATH_PLUGINS . $sClassName . ".php");
$details = $oPluginRegistry->getPluginDetails($pluginFile);
$oPluginRegistry->installPlugin($details->sNamespace);
$oPluginRegistry->setupPlugins(); //get and setup enabled plugins
$size = file_put_contents(PATH_DATA_SITE . "plugin.singleton", $oPluginRegistry->serializeInstance());
//G::header("Location: pluginsList");
//die;
$response["success"] = true;
} catch (Exception $e) {
$response["message"] = $e->getMessage();
$status = 0;
}
if ($status == 0) {
$response["success"] = false;
}
echo G::json_encode($response);

View File

@@ -0,0 +1,369 @@
<?php
require_once PATH_CORE . 'classes' . PATH_SEP . 'class.pmLicenseManager.php';
require_once PATH_CORE . 'classes' . PATH_SEP . 'class.enterpriseUtils.php';
ini_set("max_execution_time", 0);
if (!defined("PM_VERSION")) {
if (file_exists(PATH_METHODS . "login/version-pmos.php")) {
include (PATH_METHODS . "login/version-pmos.php");
} else {
define("PM_VERSION", "2.0.0");
}
}
if (!defined("BUFSIZE")) {
define("BUFSIZE", 16384);
}
function install($file)
{
G::LoadThirdParty("pear/Archive", "Tar");
$result = array();
$status = 1;
try {
//Extract
$tar = new Archive_Tar($file);
$swTar = $tar->extract(PATH_OUTTRUNK); //true on success, false on error. //directory for extract
//$swTar = $tar->extract(PATH_PLUGINS);
if (!$swTar) {
throw (new Exception("Could not extract file."));
}
//Upgrade
$option = array(
"http" => array(
"method" => "POST"
)
);
// 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);
///////
$fileData = @fopen(EnterpriseUtils::getUrlServerName() . "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/enterprise/services/processMakerUpgrade", "rb", false, $context);
if ($fileData === false) {
throw (new Exception("Could not open services url."));
}
$resultAux = G::json_decode(stream_get_contents($fileData));
if ($resultAux->status == "OK") {
$result["status"] = $resultAux->status; //OK
$result["message"] = $resultAux->message;
} else {
throw (new Exception($resultAux->message));
}
} catch (Exception $e) {
$result["message"] = $e->getMessage();
$status = 0;
}
if ($status == 0) {
$result["status"] = "ERROR";
}
return $result;
}
$option = (isset($_POST["option"]))? $_POST["option"] : null;
switch ($option) {
case "install":
$uid = $_POST["uid"];
$version = $_POST["version"];
$versionName = $_POST["versionName"];
$processMakerVersion = $_POST["processMakerVersion"];
$response = array();
$status = 1;
try {
if (EnterpriseUtils::getInternetConnection() == 0) {
throw (new Exception("Enterprise Plugins Manager no connected to internet."));
}
///////
$versionName = EnterpriseUtils::pmVersion($versionName);
$processMakerVersion = EnterpriseUtils::pmVersion($processMakerVersion);
if (!version_compare($processMakerVersion . "", $versionName . "", "<")) {
throw (new Exception("The system can't be upgraded to a previous version."));
}
///////
$licenseManager = &pmLicenseManager::getSingleton();
$server = isset($licenseManager->server) ? $licenseManager->server : '';
$url = "http://$server/syspmLicenseSrv/en/green/services/rest";
if (EnterpriseUtils::checkConnectivity($url) == false) {
throw (new Exception("Server '$server' not available."));
}
///////
$boundary = "---------------------" . substr(md5(rand(0, 32000)), 0, 10);
$data = null;
$data = $data . "--$boundary\n";
$data = $data . "Content-Disposition: form-data; name=\"action\"\n\n" . "getPM" . "\n";
$data = $data . "--$boundary\n";
$data = $data . "Content-Disposition: form-data; name=\"OBJ_UID\"\n\n" . $uid . "\n";
$data = $data . "--$boundary\n";
$data = $data . "Content-Disposition: form-data; name=\"OBJ_VERSION\"\n\n" . $version . "\n";
$data = $data . "--$boundary\n";
$option = array(
"http" => array(
"method" => "POST",
"header" => "Content-Type: multipart/form-data; boundary=" . $boundary,
"content" => $data
)
);
// 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);
///////
$fileData = @fopen($url, "rb", false, $context);
if ($fileData === false) {
throw (new Exception("Could not open download url."));
}
//Try to get the download size and filename (ok if it fails)
$meta = stream_get_meta_data($fileData);
$fileName = null;
$fileContentType = null;
$fileLength = 0;
if ($meta["wrapper_type"] == "http") {
foreach ($meta["wrapper_data"] as $info) {
$info = explode(":", $info);
$infoVariable = (isset($info[0]))? trim($info[0]) : null;
$infoValue = (isset($info[1]))? trim($info[1]) : null;
if (preg_match("/^.*Content-Type.*$/", $infoVariable)) {
$fileContentType = $infoValue;
}
if (strcasecmp($infoVariable, "Content-Length") == 0) {
$fileLength = intval($infoValue);
}
if (strcasecmp($infoVariable, "Content-Disposition") == 0) {
foreach (explode(";", $infoValue) as $params) {
$params = explode("=", $params);
if (count($params) <= 1) {
continue;
}
if (strcasecmp(trim($params[0]), "filename") == 0) {
$fileName = trim($params[1], "\" ");
}
}
}
}
}
if (preg_match("/^.*json.*$/i", $fileContentType)) {
$r = G::json_decode(stream_get_contents($fileData));
if ($r->status == "ERROR") {
throw (new Exception($r->message));
}
}
///////
$dir = PATH_DATA . "upgrade" . PATH_SEP . "processmaker";
G::rm_dir($dir);
G::mk_dir($dir);
if (!file_exists($dir)) {
throw (new Exception("Could not create destination directory."));
}
///////
$fileName = $dir . PATH_SEP . $fileName;
$file = @fopen($fileName, "wb");
if ($file === false) {
throw (new Exception("Could not open destination file."));
}
while (!feof($fileData)) {
$data = fread($fileData, BUFSIZE);
//Just to be safe, check all error conditions
if ($data === "" || $data === false) {
break;
}
if (fwrite($file, $data) === false) {
break;
}
}
fclose($file);
fclose($fileData);
///////
$path = PATH_TRUNK;
//$path = PATH_OUTTRUNK;
if (EnterpriseUtils::checkFolderPermissions($path, true) == false) {
$str = $path . " " . "directory, its sub-directories or file is not writable. Read the wiki for <a href=\"http://wiki.processmaker.com/index.php/Upgrading_ProcessMaker\" onclick=\"window.open(this.href, \'_blank\'); return (false);\">Upgrading ProcessMaker</a>.<br /> The file is downloaded in " . $fileName . "<br />";
throw (new Exception($str));
}
///////
$result = install($fileName);
if ($result["status"] == "OK") {
$response["status"] = $result["status"]; //OK
$response["message"] = $result["message"];
} else {
throw (new Exception($result["message"]));
}
} catch (Exception $e) {
$response["message"] = $e->getMessage();
$status = 0;
}
if ($status == 0) {
$response["status"] = "ERROR";
}
echo G::json_encode($response);
break;
case "list":
$status = 1;
try {
if (EnterpriseUtils::getInternetConnection() == 0) {
throw (new Exception("Enterprise Plugins Manager no connected to internet."));
}
///////
$licenseManager = &pmLicenseManager::getSingleton();
$server = (isset($licenseManager->server)) ? $licenseManager->server : '';
$url = "http://$server/syspmLicenseSrv/en/green/services/rest";
if (EnterpriseUtils::checkConnectivity($url) == false) {
throw (new Exception("Server '$server' not available."));
}
///////
$option = array(
"http" => array(
"method" => "POST",
"header" => "Content-type: application/x-www-form-urlencoded\r\n",
"content" => http_build_query(
array(
"action" => "getPMList"
)
)
)
);
// 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);
$results = file_get_contents($url, false, $context);
$results = G::json_decode($results);
$results = $results[0];
$pmVersion = EnterpriseUtils::pmVersion(PM_VERSION);
$versions = array();
foreach ($results as $key => $result) {
$version = EnterpriseUtils::pmVersion($result->OBJ_VERSION_NAME);
if (version_compare($pmVersion . "", $version . "", "<")) {
$versions[] = $result;
}
}
if (isset($results[0])) {
$results[0]->OBJ_VERSION_NAME .= " (Stable)";
}
$response->status = "OK";
$response->results = $versions;
} catch (Exception $e) {
$response->message = $e->getMessage();
$status = 0;
}
if ($status == 0) {
$response->status = "ERROR";
}
echo G::json_encode($response);
break;
}