SHARE
TWEET

Untitled

a guest May 13th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by http://DeZender.Net
  5. * @ deZender (PHP7 Decoder for SourceGuardian Encoder)
  6. *
  7. * @ Version         :   4.0.8.9
  8. * @ Author          :   DeZender
  9. * @ Release on      :   10.05.2019
  10. * @ Official site   :   http://DeZender.Net
  11. *
  12. */
  13.  
  14. class LicenseLib
  15. {
  16.     /**
  17.      * $filename string Absolute path to the license file, if <em>NULL</em> then default license is validated.
  18.      * $remoteHostname string Name of hostname that should be associated with the given license.  Defaults to current machine's hostname.
  19.      *
  20.      * Returns an array or ERROR.  Array contains the license details
  21.      */
  22.     static public function licenseDetails($filename = NULL, $remoteHostname = NULL, $licenseCheckType = LICENSE_NORMAL_CHECK)
  23.     {
  24.         $root = $GLOBALS['root'];
  25.         $licenseDetails = [];
  26.  
  27.         if (empty($filename)) {
  28.             $filename = '/opt/tenable/' . LICENSE_FILE;
  29.  
  30.             if (!file_exists($filename)) {
  31.                 $filename = $root . '/daemons/' . LICENSE_FILE;
  32.             }
  33.         }
  34.  
  35.         if (!file_exists($filename)) {
  36.             ErrorHandler::setErrorHandler('License file \'' . $filename . '\' not found.', RESPONSE_NOT_FOUND);
  37.             $errorMsg = MessageLib::createStaticMessage(SCMSG_STATIC_ERROR, ErrorHandler::getErrorMessage());
  38.             SCLog::log($errorMsg, LOG_LEVEL_CRITICAL, LOG_TYPE_ALL);
  39.             return ERROR;
  40.         }
  41.  
  42.         if (($licenseDetails = LicenseLib::licenseCheck($filename, $remoteHostname, $licenseCheckType)) === ERROR) {
  43.             $msg = MessageLib::createStaticMessage(SCMSG_STATIC_ERROR, ErrorHandler::getLogMessage());
  44.             SCLog::log($msg, LOG_LEVEL_CRITICAL, LOG_TYPE_ALL);
  45.             return ERROR;
  46.         }
  47.  
  48.         return $licenseDetails;
  49.     }
  50.  
  51.     /**
  52.      * @param $license Path to license to match repositories to.
  53.      * @return Returns an array of repository IDs associated with the license.
  54.      */
  55.     static public function getRepositoriesForLicense($license)
  56.     {
  57.         $root = $GLOBALS['root'];
  58.         $directory = $root . '/daemons';
  59.         $repositories = [];
  60.  
  61.         if (($reps = RepositoryLib::getRepositories(REPOSITORY_TYPE_ALL, RESULT_IDXANNOTATIONS)) === ERROR) {
  62.             return ERROR;
  63.         }
  64.  
  65.         if (($paramDigest = @md5_file($license)) === false) {
  66.             ErrorHandler::setErrorHandler('Unable to digest license \'' . $license . '\'.', RESPONSE_FILE_READ_ERROR);
  67.             return ERROR;
  68.         }
  69.  
  70.         if (($handle = @opendir($directory)) === false) {
  71.             ErrorHandler::setErrorHandler('Unable to open the daemon directory.', RESPONSE_FILE_READ_ERROR);
  72.             return ERROR;
  73.         }
  74.  
  75.         while (($file = readdir($handle)) !== false) {
  76.             $match = [];
  77.  
  78.             if (preg_match('/(?<repID>\\d+)\\.license\\.key/', $file, $match)) {
  79.                 if (($licenseDigest = @md5_file($directory . '/' . $file)) === false) {
  80.                     ErrorHandler::setErrorHandler('Unable to digest stored license \'' . $directory . '/' . $file . '\'.', RESPONSE_FILE_READ_ERROR);
  81.                     return ERROR;
  82.                 }
  83.  
  84.                 if ($paramDigest === $licenseDigest) {
  85.                     array_push($repositories, $reps[$match['repID']]);
  86.                 }
  87.             }
  88.         }
  89.  
  90.         return $repositories;
  91.     }
  92.  
  93.     /**
  94.      * @param $filename Absolute path to license file to install.
  95.      * @return Installs new license file or returns an error.
  96.      */
  97.     static public function store($filename)
  98.     {
  99.         if (!file_exists($filename)) {
  100.             ErrorHandler::setErrorHandler('License file \'' . $filename . '\' not found.', RESPONSE_NOT_FOUND);
  101.             $errorMsg = MessageLib::createStaticMessage(SCMSG_STATIC_ERROR, ErrorHandler::getLogMessage(), ErrorHandler::getErrorCode());
  102.             SCLog::log($errorMsg, LOG_LEVEL_CRITICAL, LOG_TYPE_ALL);
  103.             return ERROR;
  104.         }
  105.  
  106.         if (($currentLicenseDetails = LicenseLib::licenseDetails(NULL, NULL, LICENSE_UPGRADE_CHECK)) === ERROR) {
  107.             $currentLicenseDetails = [];
  108.             $currentLicenseDetails['type'] = LICENSE_MODE_NONE;
  109.         }
  110.         else {
  111.             switch ($currentLicenseDetails['status']) {
  112.             case RESPONSE_DENIED:
  113.                 $currentLicenseDetails = [];
  114.                 $currentLicenseDetails['type'] = LICENSE_MODE_SC;
  115.                 break;
  116.             case RESPONSE_OK:
  117.             case RESPONSE_EXPIRED:
  118.                 break;
  119.             }
  120.         }
  121.  
  122.         ErrorHandler::resetError();
  123.         if ((($newLicenseDetails = LicenseLib::licenseDetails($filename)) === ERROR) || ($newLicenseDetails['status'] != RESPONSE_OK)) {
  124.             if ($newLicenseDetails['status'] != RESPONSE_OK) {
  125.                 ErrorHandler::setErrorHandler('License is invalid.', RESPONSE_LICENSE_ERROR);
  126.             }
  127.             else {
  128.                 ErrorHandler::addErrorMessage('License is invalid.');
  129.             }
  130.  
  131.             $errorMsg = MessageLib::createStaticMessage(SCMSG_STATIC_ERROR, ErrorHandler::getLogMessage(), ErrorHandler::getErrorCode());
  132.             SCLog::log($errorMsg, LOG_LEVEL_CRITICAL, LOG_TYPE_ALL);
  133.             return ERROR;
  134.         }
  135.  
  136.         if ($newLicenseDetails['type'] != LICENSE_MODE_SC) {
  137.             ErrorHandler::setErrorHandler('New license is not a Tenable.sc license.', RESPONSE_INVALID_DATA);
  138.             $errorMsg = MessageLib::createStaticMessage(SCMSG_STATIC_ERROR, ErrorHandler::getLogMessage(), ErrorHandler::getErrorCode());
  139.             SCLog::log($errorMsg, LOG_LEVEL_CRITICAL, LOG_TYPE_ALL);
  140.             return ERROR;
  141.         }
  142.  
  143.         $licenseFile = $GLOBALS['root'] . '/daemons/' . LICENSE_FILE;
  144.  
  145.         if (!@rename($filename, $licenseFile)) {
  146.             ErrorHandler::setErrorHandler('Error installing License file.', RESPONSE_FILESYSTEM_ERROR);
  147.             $errorMsg = MessageLib::createStaticMessage(SCMSG_STATIC_ERROR, ErrorHandler::getLogMessage(), ErrorHandler::getErrorCode());
  148.             SCLog::log($errorMsg, LOG_LEVEL_CRITICAL, LOG_TYPE_ALL);
  149.             return ERROR;
  150.         }
  151.  
  152.         if (LicenseLib::setLicenseFields(0) === ERROR) {
  153. .....................................................................
  154. .....................................
  155. ..............
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top