/** * Registers the javascript code to update a license * @param array $_CORELANG Core language array * @param array $_CONFIG The configuration array * @param boolean $autoexec (optional) Wheter to perform update check automaticly or on form submit */ public function addJsUpdateCode(&$_CORELANG, $license, $intern = false, $autoexec = true) { $v = preg_split('#\\.#', $this->coreCmsVersion); $version = current($v); unset($v[key($v)]); foreach ($v as $part) { $version *= 100; $version += $part; } $userAgentRequestArguments = array('data=' . urlencode(json_encode(array('installationId' => $license->getInstallationId(), 'licenseKey' => $license->getLicenseKey(), 'edition' => $license->getEditionName(), 'version' => $this->coreCmsVersion, 'versionstate' => $this->coreCmsStatus, 'domainName' => $this->domainUrl, 'remoteAddr' => $_SERVER['REMOTE_ADDR'], 'sendTemplate' => false))), 'v=' . $version, 'userAgentRequest=true'); if (!$autoexec || $this->isTimeToUpdate()) { if (self::$javascriptRegistered) { return; } self::$javascriptRegistered = true; \JS::activate('jquery'); $objJs = \ContrexxJavascript::getInstance(); $objJs->setVariable("statusmessage_success", $_CORELANG['TXT_LICENSE_UPDATED'], "core_module/license"); $jsCode = ' cx.jQuery(document).ready(function() { var licenseMessage = cx.jQuery("#license_message"); var cloneLicenseMessage = cx.jQuery("#license_message").clone(); var reloadManager = true; var revertMessage = function(setClass, setHref, setTarget, setText) { setTimeout(function() { newLicenseMessage = cloneLicenseMessage.clone(); if (setClass) { newLicenseMessage.attr("class", "upgrade " + setClass); } if (setHref) { licenseMessage.children("a:first").attr("href", setHref); } if (setTarget) { licenseMessage.children("a:first").attr("target", setTarget); } if (setText) { licenseMessage.children("a:first").html(setText); } licenseMessage.replaceWith(newLicenseMessage); licenseMessage = newLicenseMessage; }, 1000); } //var versionCheckUrl = "../core_modules/License/versioncheck.php?force=true"; var versionCheckUrl = "../api/licup?force=true"; var versionCheckResponseHandler = function(data, allowUserAgent) {'; $sm = new \Cx\Core\Config\Controller\Config(); if (\FWUser::getFWUserObject()->objUser->getAdminStatus()) { $jsCode .= ' if (data == "false" && allowUserAgent && ' . ($sm->isWritable() ? 'true' : 'false') . ') { reloadManager = false; cx.jQuery.getScript("http://updatesrv1.contrexx.com/?' . implode('&', $userAgentRequestArguments) . '", function() { cx.jQuery.post( versionCheckUrl, {"response": JSON.stringify(licenseUpdateUserAgentRequestResponse)} ).success(function(data) { reloadManager = true; versionCheckResponseHandler(data, false) }).error(function(data) { revertMessage(); }); }).fail(function(){ revertMessage(); }); }'; } $jsCode .= ' var data = cx.jQuery.parseJSON(data); if (!data) { revertMessage(); return; } revertMessage(data[\'class\'], data.link, data.target, data.text); cx.jQuery("#jsstatemessage").html(cx.variables.get("statusmessage_success", "core_module/license")); cx.jQuery("#jsstatemessage").addClass("okbox"); cx.jQuery("#jsstatemessage").show(); if (reloadManager && ' . ($sm->isWritable() ? 'true' : 'false') . ' && data.status != "ERROR") { setTimeout(function() { window.location.href = window.location.href; }, 1500); } } var performRequest = function() { licenseMessage.attr("class", "infobox"); licenseMessage.text("' . $_CORELANG['TXT_LICENSE_UPDATING'] . '"); licenseMessage.show(); cx.jQuery.get( versionCheckUrl ).success(function(data) { versionCheckResponseHandler(data, true); }).error(function(data) { revertMessage(); }); return false; }' . ($autoexec ? '()' : '') . '; ' . ($intern ? 'cx.jQuery("input[name=update]").click(performRequest);' : '') . ' }); '; \JS::registerCode($jsCode); } }
public function getPage($post, &$_CORELANG) { $lc = LicenseCommunicator::getInstance($this->config); $lc->addJsUpdateCode($this->lang, $this->license, true, false); $sm = new \Cx\Core\Config\Controller\Config(); if (\FWUser::getFWUserObject()->objUser->getAdminStatus()) { if (isset($post['save']) && isset($post['licenseKey'])) { $license = License::getCached($this->config, $this->db); if ($license->checkSum(contrexx_input2db($post['licenseKey']))) { $license->setLicenseKey(contrexx_input2db($post['licenseKey'])); // save it before we check it, so we only change the license key $license->save($this->db); $license->check(); $this->license = $license; } } else { if (isset($post['update'])) { // This is only a backup if javascript is bogus try { $lc->update($this->license, $this->config, true, false, $this->lang); $this->license->save($this->db); } catch (\Exception $e) { } } } } if (!file_exists(ASCMS_TEMP_PATH . '/licenseManager.html')) { try { $lc->update($this->license, $this->config, true, true, $this->lang); $this->license->save($this->db); } catch (\Exception $e) { } } if (file_exists(ASCMS_TEMP_PATH . '/licenseManager.html')) { \JS::activate('cx'); $remoteTemplate = new \Cx\Core\Html\Sigma(ASCMS_TEMP_PATH); $remoteTemplate->loadTemplateFile('/licenseManager.html'); if (isset($_POST['save']) && isset($_POST['licenseKey'])) { $remoteTemplate->setVariable('STATUS_TYPE', 'okbox'); $remoteTemplate->setVariable('STATUS_MESSAGE', $this->lang['TXT_LICENSE_SAVED']); } else { if (isset($_POST['update'])) { $remoteTemplate->setVariable('STATUS_TYPE', 'okbox'); $remoteTemplate->setVariable('STATUS_MESSAGE', $this->lang['TXT_LICENSE_UPDATED']); } } $remoteTemplate->setVariable($this->lang); $this->setLicensePlaceholders($remoteTemplate); if ($remoteTemplate->blockExists('legalComponents')) { foreach ($this->license->getLegalComponentsList() as $component) { $remoteTemplate->setVariable('LICENSE_LEGAL_COMPONENT', contrexx_raw2xhtml($component)); $remoteTemplate->parse('legalComponents'); } } if ($remoteTemplate->blockExists('licenseDomain')) { foreach ($this->license->getRegisteredDomains() as $domain) { $remoteTemplate->setVariable('LICENSE_DOMAIN', contrexx_raw2xhtml($domain)); $remoteTemplate->parse('licenseDomain'); } } $message = $this->license->getMessage(false, \FWLanguage::getLanguageCodeById(BACKEND_LANG_ID), $this->lang); if (!$sm->isWritable()) { $remoteTemplate->setVariable('MESSAGE_TITLE', preg_replace('/<br \\/>/', ' ', sprintf($_CORELANG['TXT_SETTINGS_ERROR_NO_WRITE_ACCESS'], \Cx\Core\Config\Controller\Config::getSettingsFile()))); $remoteTemplate->setVariable('MESSAGE_LINK', '#'); $remoteTemplate->setVariable('MESSAGE_LINK_TARGET', '_self'); $remoteTemplate->setVariable('MESSAGE_TYPE', 'alertbox'); } else { if ($message && strlen($message->getText())) { $remoteTemplate->setVariable('MESSAGE_TITLE', contrexx_raw2xhtml($this->getReplacedMessageText($message))); $remoteTemplate->setVariable('MESSAGE_LINK', contrexx_raw2xhtml($message->getLink())); $remoteTemplate->setVariable('MESSAGE_LINK_TARGET', contrexx_raw2xhtml($message->getLinkTarget())); $remoteTemplate->setVariable('MESSAGE_TYPE', contrexx_raw2xhtml($message->getType())); } else { if ($remoteTemplate->blockExists('message')) { $remoteTemplate->setVariable('MESSAGE_TYPE', '" style="display:none;'); } } } if (\FWUser::getFWUserObject()->objUser->getAdminStatus()) { $remoteTemplate->touchBlock('licenseAdmin'); $remoteTemplate->hideBlock('licenseNotAdmin'); } else { $remoteTemplate->hideBlock('licenseAdmin'); $remoteTemplate->touchBlock('licenseNotAdmin'); $remoteTemplate->setVariable('LICENSE_ADMIN_MAIL', contrexx_raw2xhtml($this->config['coreAdminEmail'])); } $this->template->setVariable('ADMIN_CONTENT', $remoteTemplate->get()); } else { $this->template->setVariable('ADMIN_CONTENT', $this->lang['TXT_LICENSE_NO_TEMPLATE']); } }