Example #1
0
 public function getLicenseInfo($licensekey, $extensionName, $domain)
 {
     $licensekey = trim($licensekey);
     // check license for old license key
     if ($oldLicenseInfo = $this->_decrypt($licensekey)) {
         $license = Mage::getModel('magenotification/license')->loadByLicenseExtension($licensekey, $extensionName);
         if (!$license->getId()) {
             // Request first time when using old license key
             try {
                 $xmlRpc = new Zend_XmlRpc_Client(self::SERVER_URL . 'api/xmlrpc/');
                 $session = $xmlRpc->call('login', array('username' => self::WEBSERVICE_USER, 'password' => self::WEBSERVICE_PASS));
                 $result = $xmlRpc->call('call', array('sessionId' => $session, 'apiPath' => 'licensemanager.active', 'args' => array($licensekey, $extensionName, $domain)));
                 $dataObject = new Varien_Object($result);
             } catch (Exception $e) {
                 return new Varien_Object(array('response_code' => 101));
             }
             $license->setResponseCode($dataObject->getResponseCode())->setDomains($dataObject->getDomains());
             if ($dataObject->getActivatedTime()) {
                 $license->setActiveAt(substr($dataObject->getActivatedTime(), 0, 10));
             } else {
                 $license->setActiveAt(now(true));
             }
             try {
                 $license->setSumCode($this->_getSumCode($license));
                 $license->save();
             } catch (Exception $e) {
             }
             return $dataObject;
         }
         $result = new Varien_Object($license->getData());
         $result->addData(array('users' => 1, 'created_time' => date('Y-m-d H:m:s', $oldLicenseInfo['created_time']), 'activated_time' => $license->getActiveAt(), 'type' => $oldLicenseInfo['type'], 'status' => 1, 'expired_time' => $oldLicenseInfo['expired_time']));
         if ($license->getSumCode() != $this->_getSumCode($license)) {
             try {
                 $license->setResponseCode(self::GENERAL_ERROR);
                 $license->setSumCode($this->_getSumCode($license))->save();
             } catch (Exception $e) {
             }
         } elseif ($result->getType() == self::TRIAL_VERSION && $license->getResponseCode() > self::LIMITED_DOMAIN_ERROR) {
             $expiredTime = strtotime($license->getActiveAt()) + (int) $result->getExpiredTime() * 24 * 3600;
             if ($expiredTime < time()) {
                 try {
                     $license->setResponseCode(self::EXPIRED_TRIAL_LICENSE_KEY_ERROR);
                     $license->setSumCode($this->_getSumCode($license))->save();
                 } catch (Exception $e) {
                 }
             }
         }
         return $result->setResponseCode($license->getResponseCode());
     }
     // check new license key
     if ($licenseInfo = $this->_newkeyDecrypt($licensekey, $extensionName, $domain)) {
         $license = Mage::getModel('magenotification/license')->loadByLicenseExtension($licensekey, $extensionName);
         if (!$license->getId()) {
             $license->setActiveAt(now(true))->setDomains($licenseInfo->getDomains());
             $responseCode = self::NEW_DOMAIN_SUCCESS;
             $licenseDomain = strlen($domain) > 38 ? substr($domain, 0, 38) : $domain;
             if ($licenseDomain != $licenseInfo->getDomains()) {
                 $responseCode = self::LIMITED_DOMAIN_ERROR;
             }
             try {
                 $license->setResponseCode($responseCode);
                 $license->setSumCode($this->_getSumCode($license))->save();
             } catch (Exception $e) {
             }
         }
         $result = new Varien_Object($license->getData());
         $createdTime = $licenseInfo->getCreatedDate() ? $licenseInfo->getCreatedDate() : $license->getActiveAt();
         $result->addData(array('users' => 1, 'created_time' => date('Y-m-d H:m:s', strtotime($createdTime)), 'activated_time' => $license->getActiveAt(), 'type' => $this->getOldLicenseType($licenseInfo->getType()), 'status' => 1, 'expired_time' => $licenseInfo->getExpiredTime()));
         if ($license->getSumCode() != $this->_getSumCode($license)) {
             try {
                 $license->setResponseCode(self::GENERAL_ERROR);
                 $license->setSumCode($this->_getSumCode($license))->save();
             } catch (Exception $e) {
             }
         } elseif (($result->getType() == self::TRIAL_VERSION || $result->getType() == self::DEVELOPMENT) && $license->getResponseCode() > self::LIMITED_DOMAIN_ERROR) {
             $expiredTime = strtotime($license->getActiveAt()) + (int) $result->getExpiredTime() * 24 * 3600;
             if ($expiredTime < time()) {
                 try {
                     $license->setResponseCode(self::EXPIRED_TRIAL_LICENSE_KEY_ERROR);
                     $license->setSumCode($this->_getSumCode($license))->save();
                 } catch (Exception $e) {
                 }
             }
         }
         return $result->setResponseCode($license->getResponseCode());
     }
     return new Varien_Object(array('response_code' => self::GENERAL_ERROR));
 }