Bfr90

demo_file

Apr 18th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 23.55 KB | None | 0 0
  1. <?php
  2. /*This is a partially decoded file (50%), with 697 lines of code, size 23.91 KB.
  3. /*The fully decoded file has 1416 lines of code and a size of 47.82 KB.*/
  4.  
  5. /*Rev:07.09.23r0 Php8.2.5*/
  6.  
  7. namespace CodeLathe\Core\Subsystem\System\License;
  8.  
  9. defined('TONIDO_CLOUD_ROOT_DIR') || exit('Forbidden');
  10.  
  11. class LicenseManager
  12. {
  13.     public const GROUP_ENTERPRISE_SERVER_BASE = 'ENTERPRISE_SERVER_BASE';
  14.     public const GROUP_ENTERPRISE_ONLINE_BASE = 'ENTERPRISE_ONLINE_BASE';
  15.     public const COMPONENT_TONIDOCLOUD = 'Tonido Cloud';
  16.     public const COMPONENT_SERVERLINK = 'SERVERLINK';
  17.     public const COMPONENT_FSSYNC = 'FSSYNC';
  18.     public const COMPONENT_ENTERPRISE = 'ENTERPRISE';
  19.     public const COMPONENT_SALESFORCE = 'SALESFORCE';
  20.     public const COMPONENT_RETENTION = 'RETENTION';
  21.     public const COMPONENT_PATTERNSEARCH = 'PATTERNSEARCH';
  22.     public const COMPONENT_FIPS140 = 'FIPS140';
  23.     public const COMPONENT_SIEM = 'SIEM';
  24.     public const COMPONENT_CCS = 'CCE';
  25.     public const COMPONENT_COMMUNITY = 'COMMUNITY';
  26.     public const COMPONENT_DRM = 'DRM';
  27.     public const COMPONENT_LIMITED_USER_2FA = 'LIMITED2FA';
  28.     public const COMPONENT_CASB = 'CASB';
  29.     public const COMPONENT_OCR = 'OCR';
  30.     public const COMPONENT_MSTEAMS = 'MSTEAMS';
  31.     public const COMPONENT_COMPLIANCE = 'COMPLIANCE';
  32.     public const COMPONENT_AUTOMATION_WORKFLOW = 'AUTOMATION_WORKFLOW';
  33.     public const COMPONENT_DISABLE_POWERED_BY = 'OEM_DISABLE_OPTION1';
  34.     public const COMPONENT_CAD_VIEWER = 'CAD_VIEWER';
  35.     public const COMPONENT_AD_LDAP = 'AD_LDAP';
  36.     public const COMPONENT_SSO = 'SSO';
  37.     public const COMPONENT_DLP = 'DLP';
  38.  
  39.     static  public $standaloneComponents = array('COMMUNITY', 'OEM_DISABLE_OPTION1');
  40.     private $settingsManager;
  41.     private $userDataStore;
  42.     private $keyRecordDataStore;
  43.     private $logger;
  44.  
  45.     public function __construct()
  46.     {
  47.         $this->userDataStore = \CodeLathe\Application\ContainerFacade::get('CodeLathe\\Core\\Subsystem\\User\\User\\UserDataStore');
  48.         $this->settingsManager = \CodeLathe\Application\ContainerFacade::get('CodeLathe\\Core\\Infrastructure\\Settings\\SettingsManager');
  49.         $this->keyRecordDataStore = \CodeLathe\Application\ContainerFacade::get('CodeLathe\\Core\\Common\\Utility\\KeyRecord\\KeyRecordDataStore');
  50.         $this->logger = \CodeLathe\Application\ContainerFacade::get('CodeLathe\\Application\\Service\\LoggerService');
  51.     }
  52.  
  53.     public static function isCommunityEdition(bool $safeMode = FALSE): bool
  54.     {
  55.         $settingsManager = \CodeLathe\Core\Infrastructure\Settings\SettingsManager::getInstance();
  56.         if ($safeMode && (($settingsManager->getSiteSetting()) || \CodeLathe\Core\Infrastructure\Database\Database::hasInstance())) {
  57.             throw (new \CodeLathe\Core\Common\Exception\TonidoCloudException('Internal settings have already been set'));
  58.         }
  59.  
  60.         $isOk = (new self())->isComponentOK('COMMUNITY');
  61.  
  62.         if ($safeMode) {
  63.             $settingsManager->clearSiteSetting();
  64.             \CodeLathe\Core\Infrastructure\Database\Database::destroyInstance();
  65.         }
  66.  
  67.         return $isOk;
  68.     }
  69.  
  70.     public function isComponentOK($reqComponent)
  71.     {
  72.         $result = $this->isLicenseValid($message);
  73.  
  74.         if ($result) {
  75.             $externalSource = $this->settingsManager->getSetting('TONIDOCLOUD_LICENSE_EXTERNAL_SOURCE', 'string', 'NONE');
  76.             if ($externalSource == 'NONE' || $externalSource == '') {
  77.                 $xmldata = $this->settingsManager->getSetting('INSTALL_LICENSE', 'string', '');
  78.  
  79.                 if ($xmldata == '') {
  80.                     return FALSE;
  81.                 }
  82.  
  83.                 $licensedata = $this->getLicenseData($xmldata);
  84.                 $license = $this->getLicense($licensedata);
  85.                 $component = $license->getComponent();
  86.                 $compArray = $this->getComponentArray($component);
  87.                 $isComponentInLicense = in_array($reqComponent, $compArray, TRUE);
  88.  
  89.                 if ($isComponentInLicense) {
  90.                     return TRUE;
  91.                 }
  92.  
  93.                 $isEnterpriseLicense = in_array('ENTERPRISE', $compArray, TRUE);
  94.                 $isStandaloneComponent = in_array($reqComponent, self::$standaloneComponents, TRUE);
  95.                 return $isEnterpriseLicense && !$isStandaloneComponent;
  96.             }
  97.             else {
  98.                 $ismulti = $this->settingsManager->getSetting('TONIDOCLOUD_MULTISITE_ENABLE', 'int', '0');
  99.  
  100.                 if ($ismulti == 0) {
  101.                     $obj = LicenseExternalHelper::getInstance();
  102.                     return $obj->isComponentOK($reqComponent, $message);
  103.                 }
  104.                 else {
  105.                     $message = 'Multi Site not Supported in this License.';
  106.                     $this->logger->logError($message);
  107.                     return FALSE;
  108.                 }
  109.             }
  110.         }
  111.  
  112.         return FALSE;
  113.     }
  114.  
  115.     public function isLicenseValid(&$message)
  116.     {
  117.         $message = '';
  118.         $result = FALSE;
  119.  
  120.         if ($this->getLicenseCheckFromCache($result, $message)) {
  121.             return $result;
  122.         }
  123.  
  124.         $externalSource = $this->settingsManager->getSetting('TONIDOCLOUD_LICENSE_EXTERNAL_SOURCE', 'string', 'NONE');
  125.         if ($externalSource == 'NONE' || $externalSource == '') {
  126.             $xmldata = $this->settingsManager->getSetting('INSTALL_LICENSE', 'string', '');
  127.  
  128.             if ($xmldata == '') {
  129.                 $message = 'Invalid License';
  130.                 $result = FALSE;
  131.             }
  132.             else {
  133.                 $licType = 0;
  134.                 $result = $this->checkLicenseString($xmldata, $message, $licType);
  135.             }
  136.         }
  137.         else {
  138.             $ismulti = $this->settingsManager->getSetting('TONIDOCLOUD_MULTISITE_ENABLE', 'int', '0');
  139.  
  140.             if ($ismulti == 0) {
  141.                 $obj = LicenseExternalHelper::getInstance();
  142.                 $result = $obj->checkLicense($message);
  143.             }
  144.             else {
  145.                 $message = 'Multi Site not Supported in this License.';
  146.                 $result = FALSE;
  147.             }
  148.         }
  149.  
  150.         $this->addLicenseCheckToCache($result, $message);
  151.         return $result;
  152.     }
  153.  
  154.     private function getLicenseCheckFromCache(bool &$isvalid, string &$message): bool
  155.     {
  156.         if (!(\CodeLathe\Core\Common\RequestCache::getValue('licensevalid'))) {
  157.             return FALSE;
  158.         }
  159.  
  160.         $validity = \CodeLathe\Core\Common\RequestCache::getValue('licensevalid');
  161.         list($isvalid, $message) = explode('#', $validity);
  162.         return TRUE;
  163.     }
  164.  
  165.     public function checkLicenseString($xmldata, &$message, &$licType)
  166.     {
  167.         $message = '';
  168.         $licType = 0;
  169.         $license = $this->loadLicenseFromXMLData($xmldata, $message);
  170.  
  171.         if ($license == NULL) {
  172.             $message = 'Invalid License';
  173.             return FALSE;
  174.         }
  175.  
  176.         $this->checkHost($license->getHost(), $message);
  177.  
  178.         if ($message != '') {
  179.             $message = 'Invalid License Host';
  180.             return FALSE;
  181.         }
  182.  
  183.         $this->checkLockedVersion($license->getLockedVersion(), $message);
  184.  
  185.         if ($message != '') {
  186.             return FALSE;
  187.         }
  188.  
  189.         if ($license->getSPLA() == '1') {
  190.             $licType = 1;
  191.  
  192.             if (time() < strtotime($license->getExpiryDate())) {
  193.                 $newdate = strtotime('+1 month', strtotime($license->getIssueDate()));
  194.                 $expirationdate = mktime(0, 0, 0, date('m', $newdate), 16, date('Y', $newdate));
  195.                 $finalexpirationdate = strtotime($license->getExpiryDate());
  196.                 $extensiondata = $this->settingsManager->getSetting('EXTENSION_LICENSE', 'string', '');
  197.                 $extlicense = $this->loadSPLALicenseFromXMLData($extensiondata, $message);
  198.  
  199.                 if ($extlicense != NULL) {
  200.                     $newdate = strtotime('+1 month', strtotime($extlicense->getIssueDate()));
  201.                     $extexpirationdate = mktime(0, 0, 0, date('m', $newdate), 16, date('Y', $newdate));
  202.  
  203.                     if ($expirationdate < $extexpirationdate) {
  204.                         $expirationdate = $extexpirationdate;
  205.                     }
  206.  
  207.                     if ($finalexpirationdate < $expirationdate) {
  208.                         $expirationdate = $finalexpirationdate;
  209.                     }
  210.                 }
  211.  
  212.                 if ($expirationdate < time()) {
  213.                     $message = 'License Expired';
  214.                 }
  215.             }
  216.             else {
  217.                 $message = 'License Expired';
  218.             }
  219.         }
  220.         else if (time() < strtotime($license->getExpiryDate())) {
  221.             $activeCount = $this->getActiveUsers();
  222.             $allowedCount = $license->getAccountCount();
  223.  
  224.             if ($allowedCount < $activeCount) {
  225.                 if (!($this->isWithinAdditionalGuestAccountsLimit((int) $allowedCount, $activeCount, $license->getAdditionalGuestAccounts()))) {
  226.                     $message = sprintf("The number of active users exceeds the maximum of %s license accounts. \r\n                            Before applying again, please check your user list or contact support.", $allowedCount);
  227.                 }
  228.             }
  229.  
  230.             $this->checkHost($license->getHost(), $message);
  231.         }
  232.         else {
  233.             $message = 'License Expired';
  234.         }
  235.  
  236.         if ($message == '') {
  237.             return TRUE;
  238.         }
  239.         else {
  240.             return FALSE;
  241.         }
  242.     }
  243.  
  244.     public function loadLicenseFromXMLData($xmldata, &$message)
  245.     {
  246.         if ($xmldata == '') {
  247.             return NULL;
  248.         }
  249.  
  250.         $licensedata = $this->getLicenseData($xmldata);
  251.         $signaturedata = $this->getSignatureData($xmldata);
  252.         $signaturevalue = $this->getSignatureValue($signaturedata);
  253.         $signatureindex = $this->getSignatureIndex($signaturedata);
  254.  
  255.         if (intval($signatureindex) === 0) {
  256.             $message = 'Unsupported license file version';
  257.             return NULL;
  258.         }
  259.  
  260.         $public_key = $this->getPublicKey($signatureindex);
  261.         $b64decodedSignature = base64_decode($signaturevalue);
  262.         $ok = openssl_verify($licensedata, $b64decodedSignature, $public_key, OPENSSL_ALGO_SHA1);
  263.  
  264.         if ($ok == 1) {
  265.             return $this->getLicense($licensedata);
  266.         }
  267.  
  268.         $message = 'Invalid License File';
  269.         return NULL;
  270.     }
  271.  
  272.     private function getLicenseData($xmldata)
  273.     {
  274.         $findme1 = '<LicenseData>';
  275.         $findme2 = '</LicenseData>';
  276.         $pos1 = strpos($xmldata, $findme1);
  277.         $pos2 = strpos($xmldata, $findme2) + 14;
  278.         return rtrim(ltrim(substr($xmldata, $pos1, $pos2 - $pos1)));
  279.     }
  280.  
  281.     private function getSignatureData($xmldata)
  282.     {
  283.         $findme1 = '<SignatureData>';
  284.         $findme2 = '</SignatureData>';
  285.         $pos1 = strpos($xmldata, $findme1);
  286.         $pos2 = strpos($xmldata, $findme2) + 16;
  287.         return rtrim(ltrim(substr($xmldata, $pos1, $pos2 - $pos1)));
  288.     }
  289.  
  290.     private function getSignatureValue($a_signaturedata)
  291.     {
  292.         libxml_use_internal_errors(TRUE);
  293.         $xml = simplexml_load_string($a_signaturedata);
  294.  
  295.         if ($xml !== FALSE) {
  296.             return $xml->SignatureValue;
  297.         }
  298.  
  299.         return '';
  300.     }
  301.  
  302.     private function getSignatureIndex($a_signaturedata)
  303.     {
  304.         libxml_use_internal_errors(TRUE);
  305.         $xml = simplexml_load_string($a_signaturedata);
  306.  
  307.         if ($xml !== FALSE) {
  308.             return $xml->SignatureIndex;
  309.         }
  310.  
  311.         return '';
  312.     }
  313.  
  314.     private function getPublicKey($signatureindex)
  315.     {
  316.         $key = '';
  317.  
  318.         if ($signatureindex == 1) {
  319.             $key = "-----BEGIN PUBLIC KEY-----\r\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6xS6ozD+ritoaVk5nGvI\r\nKECmKr+T0VFRQaPATIaA1A4pZgiMjnTM50UjT6/QU3fkAg09l2pDVHGDlOWPlkuc\r\naHAHDO9klyOjZBxt4yWuNo/s/9gi+x6syLvIqqpl+LMrk/RDfHEXTaBa+YdmzupZ\r\nw1742DO5V8n2/Nc6LfeGXaNEYiIaj1EHudEaUeKA7slF/ZnVyZAQentwr/Pqh9oY\r\n302+5jEmi9LQ2R/KgLiWRozgFTbw9GLoiGBVm8uquIE9gz8y6krrOgzFWKzKDMG7\r\nreP/adM4m4z/bv5VaOAiIZME6HRZ/2qCRpbdoKIqztO189aslDa5ao9PrQQLjnKi\r\nkwIDAQAB\r\n-----END PUBLIC KEY-----";
  320.         }
  321.  
  322.         return $key;
  323.     }
  324.  
  325.     public function getManifestPublicKey()
  326.     {
  327.         return "-----BEGIN PUBLIC KEY-----\r\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApQq0p/BxYuYtW540zg/N\r\nC/HIIf79A1+G8deLFCQCfkuNKSUeshTPNoldU4U79BUsxjMPcvNDAM7sE10svRt6\r\niytJmZzBI5GtNy1WHvNMnA6rnoxCrfatODO314Xoj+hy3jVFXczSW4e/DOwfGIca\r\npTBkDjSfBNVv/QF4CEPfo6lpJfBu7/nOdcAEv2hwx3ELNeG1OsfyN/GbJae4S+CI\r\nwTtXQVIsJuAHDx0YcwnVQmdkvUcXib77xsSqZHPTAhSt5E/kxKGheVR0V0lJSaP+\r\nBFM3yrxetrCFhXEW2w/7t9j0rNTenarQlQjK2MBQG8eE2iEGt4xuE0N0A/bTB2Ej\r\n6QIDAQAB\r\n-----END PUBLIC KEY-----";
  328.     }
  329.  
  330.     private function getLicense($a_licensedata): License
  331.     {
  332.         libxml_use_internal_errors(TRUE);
  333.         $xml = simplexml_load_string($a_licensedata);
  334.         $license = (new License());
  335.  
  336.         if ($xml !== FALSE) {
  337.             $license->setCompany($xml->Company);
  338.             $license->setAccountCount($xml->Accounts);
  339.             $license->setComponent($xml->Component);
  340.             $license->setExpiryDate($xml->ExpiryDate);
  341.             $license->setIssueDate($xml->IssueDate);
  342.             $license->setLevel($xml->Level);
  343.             $license->setLicenseData($a_licensedata);
  344.             $license->setLicenseString($xml->LicenseString);
  345.             $license->setName($xml->Name);
  346.             $license->setID($xml->ID);
  347.  
  348.             if (isset($xml->Host)) {
  349.                 $license->setHost($xml->Host);
  350.             }
  351.  
  352.             if (isset($xml->SPLA)) {
  353.                 $license->setSPLA($xml->SPLA);
  354.             }
  355.  
  356.             $license->setWhitelistedDomains(($xml->WhitelistedDomains ?? ''));
  357.  
  358.             if (!empty($xml->AddlGuestAccounts)) {
  359.                 $license->setAdditionalGuestAccounts((int) $xml->AddlGuestAccounts);
  360.             }
  361.  
  362.             if (isset($xml->EnforceUserLimitForSPLA)) {
  363.                 $license->setEnforceUserLimitForSpla($xml->EnforceUserLimitForSPLA);
  364.             }
  365.  
  366.             $license->setLockedVersion(($xml->LockedVersion ?? ''));
  367.         }
  368.  
  369.         return $license;
  370.     }
  371.  
  372.     private function checkHost($host, &$message)
  373.     {
  374.         if (strlen(trim($host)) == 0) {
  375.             return NULL;
  376.         }
  377.  
  378.         if ($host == '*') {
  379.             return NULL;
  380.         }
  381.  
  382.         $reqHostName = \CodeLathe\Core\Common\Utility\Utility::getHTTPHost();
  383.  
  384.         if ($reqHostName != '') {
  385.             if ($reqHostName == '127.0.0.1' || $reqHostName == 'localhost') {
  386.                 return NULL;
  387.             }
  388.  
  389.             if (filter_var($reqHostName, FILTER_VALIDATE_IP)) {
  390.                 return NULL;
  391.             }
  392.  
  393.             if (substr($reqHostName, 0, 4) == 'www.') {
  394.                 $reqHostName = substr($reqHostName, 4);
  395.             }
  396.  
  397.             $reqHostName = mb_strtolower($reqHostName);
  398.             $host = mb_strtolower($host);
  399.             $hostArray = explode(',', $host);
  400.  
  401.             foreach ($hostArray as $hostName) {
  402.                 if ($reqHostName == trim($hostName)) {
  403.                     return NULL;
  404.                 }
  405.             }
  406.  
  407.             $this->logger->logError(\CodeLathe\Core\Common\FCLogger::getCode(array(\CodeLathe\Core\Common\FCLogger::UNAUTHORIZED_SITE_HOST)) . ' Unauthorized Site Host for access: ' . $reqHostName . ' Accepted Host(s): ' . $host);
  408.             $message = 'License is invalid for Site Domain';
  409.         }
  410.     }
  411.  
  412.     private function checkLockedVersion(string $lockedVersion, string &$message): void
  413.     {
  414.         if (empty($lockedVersion)) {
  415.             return;
  416.         }
  417.  
  418.         $lockedVersionChecker = \CodeLathe\Application\ContainerFacade::get('CodeLathe\\Core\\Subsystem\\System\\License\\LockedVersionChecker');
  419.         $isValidValueObj = $lockedVersionChecker->check(\CodeLathe\Core\Common\Utility\Utility::getCurrentFileCloudVersion(), $lockedVersion, \CodeLathe\Core\Common\Utility\Utility::getManifestFileContent(), $this->getManifestPublicKey());
  420.  
  421.         if (!$isValidValueObj->isValid()) {
  422.             $message = $isValidValueObj->getErrorMsg();
  423.         }
  424.     }
  425.  
  426.     public function loadSPLALicenseFromXMLData($xmldata, &$message)
  427.     {
  428.         if ($xmldata == '') {
  429.             return NULL;
  430.         }
  431.  
  432.         $licensedata = $this->getExtensionData($xmldata);
  433.         $signaturedata = $this->getSignatureData($xmldata);
  434.         $signaturevalue = $this->getSignatureValue($signaturedata);
  435.         $signatureindex = $this->getSignatureIndex($signaturedata);
  436.  
  437.         if (intval($signatureindex) === 0) {
  438.             $message = 'Unsupported license file version';
  439.             return NULL;
  440.         }
  441.  
  442.         $public_key = $this->getPublicKey($signatureindex);
  443.         $b64decodedSignature = base64_decode($signaturevalue);
  444.         $ok = openssl_verify($licensedata, $b64decodedSignature, $public_key, OPENSSL_ALGO_SHA1);
  445.  
  446.         if ($ok == 1) {
  447.             return $this->getLicense($licensedata);
  448.         }
  449.  
  450.         $message = 'Invalid License File';
  451.         return NULL;
  452.     }
  453.  
  454.     private function getExtensionData($xmldata)
  455.     {
  456.         $findme1 = '<ExtensionData>';
  457.         $findme2 = '</ExtensionData>';
  458.         $pos1 = strpos($xmldata, $findme1);
  459.         $pos2 = strpos($xmldata, $findme2) + 16;
  460.         return rtrim(ltrim(substr($xmldata, $pos1, $pos2 - $pos1)));
  461.     }
  462.  
  463.     public function getActiveUsers()
  464.     {
  465.         $kr = $this->keyRecordDataStore->getKeyRecord('fullguestusercountcache');
  466.  
  467.         if (!empty($kr)) {
  468.             list($count, $timestamp) = explode(':', $kr->getValue());
  469.             if (!empty($count) || !(!($timestamp || !is_numeric($count) || !is_numeric($timestamp)))) {
  470.                 $isvalid = time() < ($timestamp + 900);
  471.  
  472.                 if ($isvalid) {
  473.                     return $count;
  474.                 }
  475.             }
  476.         }
  477.  
  478.         $count = $this->userDataStore->getLicensedUserCount();
  479.         $this->keyRecordDataStore->addKeyRecordPair('fullguestusercountcache', $count . ':' . time());
  480.         return $count;
  481.     }
  482.  
  483.     private function addLicenseCheckToCache(bool $isvalid, string $message): void
  484.     {
  485.         $value = ($isvalid ? '1' : '0') . '#' . $message;
  486.         \CodeLathe\Core\Common\RequestCache::add('licensevalid', $value);
  487.     }
  488.  
  489.     public function doSPLALicenseUpdate($force = FALSE)
  490.     {
  491.         $xmldata = $this->settingsManager->getSetting('INSTALL_LICENSE', 'string', '');
  492.  
  493.         if ($xmldata == '') {
  494.             $this->logger->logDebug('CRON: SPLA: License not installed, skipping');
  495.             return NULL;
  496.         }
  497.  
  498.         $license = $this->loadLicenseFromXMLData($xmldata, $message);
  499.  
  500.         if ($license == NULL) {
  501.             $this->logger->logDebug('CRON: SPLA: Invalid License, skipping');
  502.             return NULL;
  503.         }
  504.  
  505.         if ($license->getSPLA() != '1') {
  506.             $this->logger->logDebug('CRON: SPLA: Not a SPLA license, skipping');
  507.             return NULL;
  508.         }
  509.  
  510.         $keyrecord = $this->keyRecordDataStore->getKeyRecord('lastsplacheck');
  511.  
  512.         if (($keyrecord)) {
  513.             $dateInfo = date_parse_from_format('Y-m-d H:i:s', $keyrecord->getValue());
  514.             $lastRun = mktime($dateInfo['hour'], $dateInfo['minute'], $dateInfo['second'], $dateInfo['month'], $dateInfo['day'], $dateInfo['year']);
  515.             $currentInfo = date('Y-m-d H:i:s');
  516.             $currentRun = strtotime($currentInfo);
  517.             $hours = round((double) $currentRun - $lastRun / 3600, 1);
  518.             if ($hours < 6 && !$force) {
  519.                 $this->logger->logDebug('CRON: SPLA: License Check ' . $hours . ' hours ago, skipping');
  520.                 return NULL;
  521.             }
  522.         }
  523.  
  524.         $expDate = $this->getSPLALicenseExpiryDate();
  525.  
  526.         if ($expDate < time()) {
  527.             $days = (double) time() - $expDate / 86400;
  528.         }
  529.         else {
  530.             $days = (double) $expDate - time() / 86400;
  531.         }
  532.  
  533.         $this->logger->logDebug('CRON: Calc SPLA Expiry Date=' . date(DATE_RFC2822, $expDate) . ' with days remaining= ' . $days);
  534.         if ($days < 15 || $expDate < time()) {
  535.             $this->splaReport();
  536.         }
  537.         else {
  538.             $this->logger->logDebug('CRON: More than ' . $days . ' for SPLA expiry date of ' . date(DATE_RFC2822, $expDate) . ' check, Skipping');
  539.         }
  540.  
  541.         $key1 = (new \CodeLathe\Core\Common\Utility\KeyRecord\KeyRecord());
  542.         $key1->setKey('lastsplacheck');
  543.         $key1->setValue(date('Y-m-d H:i:s'));
  544.         $this->keyRecordDataStore->addKeyRecord($key1);
  545.     }
  546.  
  547.     public function getSPLALicenseExpiryDate($xmldata = '', $extensiondata = '')
  548.     {
  549.         $result = $this->isLicenseValid($message);
  550.  
  551.         if ($result) {
  552.             if ($xmldata == '') {
  553.                 $xmldata = $this->settingsManager->getSetting('INSTALL_LICENSE', 'string', '');
  554.             }
  555.  
  556.             if ($xmldata == '') {
  557.                 return FALSE;
  558.             }
  559.  
  560.             $licensedata = $this->getLicenseData($xmldata);
  561.             $license = $this->getLicense($licensedata);
  562.  
  563.             if ($license->getSPLA() == '1') {
  564.                 $newdate = strtotime('+1 month', strtotime($license->getIssueDate()));
  565.                 $expirationdate = mktime(0, 0, 0, date('m', $newdate), 16, date('Y', $newdate));
  566.                 $finalexpirationdate = strtotime($license->getExpiryDate());
  567.  
  568.                 if ($extensiondata == '') {
  569.                     $extensiondata = $this->settingsManager->getSetting('EXTENSION_LICENSE', 'string', '');
  570.                 }
  571.  
  572.                 $extlicense = $this->loadSPLALicenseFromXMLData($extensiondata, $message);
  573.  
  574.                 if ($extlicense != NULL) {
  575.                     $newdate = strtotime('+1 month', strtotime($extlicense->getIssueDate()));
  576.                     $extexpirationdate = mktime(0, 0, 0, date('m', $newdate), 16, date('Y', $newdate));
  577.  
  578.                     if ($expirationdate < $extexpirationdate) {
  579.                         $expirationdate = $extexpirationdate;
  580.                     }
  581.  
  582.                     if ($finalexpirationdate < $expirationdate) {
  583.                         $expirationdate = $finalexpirationdate;
  584.                     }
  585.                 }
  586.  
  587.                 return $expirationdate;
  588.             }
  589.  
  590.             return strtotime($license->getExpiryDate());
  591.         }
  592.  
  593.         return time();
  594.     }
  595.  
  596.     public function splaReport()
  597.     {
  598.         $this->logger->logDebug('Doing SPLA Check...');
  599.         $this->keyRecordDataStore->deleteKeyRecord('splacheckerror');
  600.  
  601.         if (!extension_loaded('curl')) {
  602.             $key1 = (new \CodeLathe\Core\Common\Utility\KeyRecord\KeyRecord());
  603.             $key1->setKey('splacheckerror');
  604.             $key1->setValue('Activation Error: PHP CURL Not Found');
  605.             $this->keyRecordDataStore->addKeyRecord($key1);
  606.             return NULL;
  607.         }
  608.  
  609.         $url = 'https://portal.getfilecloud.com/admin/';
  610.         $rootDir = TONIDO_CLOUD_ROOT_DIR;
  611.         $certfile = $rootDir . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Core' . DIRECTORY_SEPARATOR . 'cacert.pem';
  612.         $options = array(CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_HEADER => FALSE, CURLOPT_FOLLOWLOCATION => FALSE, CURLOPT_ENCODING => '', CURLOPT_USERAGENT => 'fcserveragent', CURLOPT_AUTOREFERER => TRUE, CURLOPT_CONNECTTIMEOUT => 120, CURLOPT_TIMEOUT => 120, CURLOPT_MAXREDIRS => 10, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_CAINFO => $certfile, CURLOPT_SSL_VERIFYHOST => 0);
  613.         $count = $this->getActiveUsers();
  614.         $serverurl = $this->settingsManager->getServerUrl(FALSE);
  615.         $license = $this->getLicenseInfo();
  616.         $params = 'op=splareport&licenseemailid=' . rawurlencode($license->getID()) . '&licensename=' . rawurlencode($license->getName()) . '&licensecompany=' . rawurlencode($license->getCompany()) . '&issuedate=' . rawurlencode($license->getIssueDate()) . '&expirydate=' . rawurlencode($license->getExpiryDate()) . '&sitehost=' . rawurlencode(gethostname()) . '&serverurl=' . rawurlencode($serverurl) . '&count=' . rawurlencode($count);
  617.         $this->logger->logDebug($params);
  618.         $ch = curl_init($url);
  619.         curl_setopt_array($ch, $options);
  620.         curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  621.         $settingsMgr = \CodeLathe\Core\Infrastructure\Settings\SettingsManager::getInstance();
  622.         $proxyurl = $settingsMgr->getProxyUrl();
  623.         $proxyauth = $settingsMgr->getProxyAuth();
  624.  
  625.         if ($proxyurl != '') {
  626.             curl_setopt($ch, CURLOPT_PROXY, $proxyurl);
  627.  
  628.             if ($proxyauth != '') {
  629.                 curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
  630.             }
  631.         }
  632.  
  633.         $content = curl_exec($ch);
  634.         $errmsg = curl_error($ch);
  635.         curl_close($ch);
  636.  
  637.         if ($content !== FALSE) {
  638.             $message = '';
  639.             $extlicense = $this->loadSPLALicenseFromXMLData($content, $message);
  640.  
  641.             if ($extlicense != NULL) {
  642.                 $key1 = (new \CodeLathe\Core\Common\Utility\KeyRecord\KeyRecord());
  643.                 $key1->setKey('splalastreportedcount');
  644.                 $key1->setValue($count);
  645.                 $this->keyRecordDataStore->addKeyRecord($key1);
  646.                 $key1 = (new \CodeLathe\Core\Common\Utility\KeyRecord\KeyRecord());
  647.                 $key1->setKey('splalastreporteddate');
  648.                 $key1->setValue(date('Y-m-d H:i:s'));
  649.                 $this->keyRecordDataStore->addKeyRecord($key1);
  650.                 $this->settingsManager->setSetting('EXTENSION_LICENSE', $content);
  651.             }
  652.             else {
  653.                 libxml_use_internal_errors(TRUE);
  654.                 $xml = simplexml_load_string($content);
  655.  
  656.                 if ($xml !== FALSE) {
  657.                     $result = (int) $xml->command->result;
  658.                     $message = (string) $xml->command->message;
  659.                     $this->logger->logError(\CodeLathe\Core\Common\FCLogger::getCode(array(\CodeLathe\Core\Common\FCLogger::UNABLE_TO_GET_SPLA_INFO, \CodeLathe\Core\Common\FCLogger::XML_FAILED_FOR_URL)) . ' SPLA Extension, Server Failure. Result: ' . $result . ' Message: ' . $message);
  660.                     $key1 = (new \CodeLathe\Core\Common\Utility\KeyRecord\KeyRecord());
  661.                     $key1->setKey('splacheckerror');
  662.                     $key1->setValue('Server Activation Error');
  663.  
  664.                     if ($result == 2) {
  665.                         if ($message == 'Invalid License Expiry Date') {
  666.                             $key1->setValue('License Expiration Date is Invalid. Please update your license');
  667.                         }
  668.                         else {
  669.                             $key1->setValue('SPLA Disabled');
  670.                         }
  671.                     }
  672.  
  673.                     $this->keyRecordDataStore->addKeyRecord($key1);
  674.                 }
  675.                 else {
  676.                     $this->logger->logError(\CodeLathe\Core\Common\FCLogger::getCode(array(\CodeLathe\Core\Common\FCLogger::INVALID_SPLA_INFO, \CodeLathe\Core\Common\FCLogger::XML_FAILED_FOR_URL)) . ' SPLA Extension, Server Bad Data Error: ' . $content);
  677.                     $key1 = (new \CodeLathe\Core\Common\Utility\KeyRecord\KeyRecord());
  678.                     $key1->setKey('splacheckerror');
  679.                     $key1->setValue('Activation Response Error');
  680.                     $this->keyRecordDataStore->addKeyRecord($key1);
  681.                 }
  682.             }
  683.         }
  684.         else {
  685.             $key1 = (new \CodeLathe\Core\Common\Utility\KeyRecord\KeyRecord());
  686.             $key1->setKey('splacheckerror');
  687.             $key1->setValue('Activation Network Error');
  688.             $this->keyRecordDataStore->addKeyRecord($key1);
  689.             $this->logger->logDebug('SPLA Extension, Network Error, CURL said: ' . $errmsg);
  690.         }
  691.  
  692.         $this->logger->logDebug('SPLA Check Complete...');
  693.     }
  694.  
  695.     public function getLicenseInfo()
  696.     {
  697.         $xmldata = $this->settingsManager->
  698.  
  699. /*This is a partially decoded file.*/
  700.  
  701. ?>
Add Comment
Please, Sign In to add comment