Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * @ This file is created by http://DeZender.Net
- * @ deZender (PHP7 Decoder for SourceGuardian Encoder)
- *
- * @ Version : 4.0.8.9
- * @ Author : DeZender
- * @ Release on : 10.05.2019
- * @ Official site : http://DeZender.Net
- *
- */
- class LicenseLib
- {
- /**
- * $filename string Absolute path to the license file, if <em>NULL</em> then default license is validated.
- * $remoteHostname string Name of hostname that should be associated with the given license. Defaults to current machine's hostname.
- *
- * Returns an array or ERROR. Array contains the license details
- */
- static public function licenseDetails($filename = NULL, $remoteHostname = NULL, $licenseCheckType = LICENSE_NORMAL_CHECK)
- {
- $root = $GLOBALS['root'];
- $licenseDetails = [];
- if (empty($filename)) {
- $filename = '/opt/tenable/' . LICENSE_FILE;
- if (!file_exists($filename)) {
- $filename = $root . '/daemons/' . LICENSE_FILE;
- }
- }
- if (!file_exists($filename)) {
- ErrorHandler::setErrorHandler('License file \'' . $filename . '\' not found.', RESPONSE_NOT_FOUND);
- $errorMsg = MessageLib::createStaticMessage(SCMSG_STATIC_ERROR, ErrorHandler::getErrorMessage());
- SCLog::log($errorMsg, LOG_LEVEL_CRITICAL, LOG_TYPE_ALL);
- return ERROR;
- }
- if (($licenseDetails = LicenseLib::licenseCheck($filename, $remoteHostname, $licenseCheckType)) === ERROR) {
- $msg = MessageLib::createStaticMessage(SCMSG_STATIC_ERROR, ErrorHandler::getLogMessage());
- SCLog::log($msg, LOG_LEVEL_CRITICAL, LOG_TYPE_ALL);
- return ERROR;
- }
- return $licenseDetails;
- }
- /**
- * @param $license Path to license to match repositories to.
- * @return Returns an array of repository IDs associated with the license.
- */
- static public function getRepositoriesForLicense($license)
- {
- $root = $GLOBALS['root'];
- $directory = $root . '/daemons';
- $repositories = [];
- if (($reps = RepositoryLib::getRepositories(REPOSITORY_TYPE_ALL, RESULT_IDXANNOTATIONS)) === ERROR) {
- return ERROR;
- }
- if (($paramDigest = @md5_file($license)) === false) {
- ErrorHandler::setErrorHandler('Unable to digest license \'' . $license . '\'.', RESPONSE_FILE_READ_ERROR);
- return ERROR;
- }
- if (($handle = @opendir($directory)) === false) {
- ErrorHandler::setErrorHandler('Unable to open the daemon directory.', RESPONSE_FILE_READ_ERROR);
- return ERROR;
- }
- while (($file = readdir($handle)) !== false) {
- $match = [];
- if (preg_match('/(?<repID>\\d+)\\.license\\.key/', $file, $match)) {
- if (($licenseDigest = @md5_file($directory . '/' . $file)) === false) {
- ErrorHandler::setErrorHandler('Unable to digest stored license \'' . $directory . '/' . $file . '\'.', RESPONSE_FILE_READ_ERROR);
- return ERROR;
- }
- if ($paramDigest === $licenseDigest) {
- array_push($repositories, $reps[$match['repID']]);
- }
- }
- }
- return $repositories;
- }
- /**
- * @param $filename Absolute path to license file to install.
- * @return Installs new license file or returns an error.
- */
- static public function store($filename)
- {
- if (!file_exists($filename)) {
- ErrorHandler::setErrorHandler('License file \'' . $filename . '\' not found.', RESPONSE_NOT_FOUND);
- $errorMsg = MessageLib::createStaticMessage(SCMSG_STATIC_ERROR, ErrorHandler::getLogMessage(), ErrorHandler::getErrorCode());
- SCLog::log($errorMsg, LOG_LEVEL_CRITICAL, LOG_TYPE_ALL);
- return ERROR;
- }
- if (($currentLicenseDetails = LicenseLib::licenseDetails(NULL, NULL, LICENSE_UPGRADE_CHECK)) === ERROR) {
- $currentLicenseDetails = [];
- $currentLicenseDetails['type'] = LICENSE_MODE_NONE;
- }
- else {
- switch ($currentLicenseDetails['status']) {
- case RESPONSE_DENIED:
- $currentLicenseDetails = [];
- $currentLicenseDetails['type'] = LICENSE_MODE_SC;
- break;
- case RESPONSE_OK:
- case RESPONSE_EXPIRED:
- break;
- }
- }
- ErrorHandler::resetError();
- if ((($newLicenseDetails = LicenseLib::licenseDetails($filename)) === ERROR) || ($newLicenseDetails['status'] != RESPONSE_OK)) {
- if ($newLicenseDetails['status'] != RESPONSE_OK) {
- ErrorHandler::setErrorHandler('License is invalid.', RESPONSE_LICENSE_ERROR);
- }
- else {
- ErrorHandler::addErrorMessage('License is invalid.');
- }
- $errorMsg = MessageLib::createStaticMessage(SCMSG_STATIC_ERROR, ErrorHandler::getLogMessage(), ErrorHandler::getErrorCode());
- SCLog::log($errorMsg, LOG_LEVEL_CRITICAL, LOG_TYPE_ALL);
- return ERROR;
- }
- if ($newLicenseDetails['type'] != LICENSE_MODE_SC) {
- ErrorHandler::setErrorHandler('New license is not a Tenable.sc license.', RESPONSE_INVALID_DATA);
- $errorMsg = MessageLib::createStaticMessage(SCMSG_STATIC_ERROR, ErrorHandler::getLogMessage(), ErrorHandler::getErrorCode());
- SCLog::log($errorMsg, LOG_LEVEL_CRITICAL, LOG_TYPE_ALL);
- return ERROR;
- }
- $licenseFile = $GLOBALS['root'] . '/daemons/' . LICENSE_FILE;
- if (!@rename($filename, $licenseFile)) {
- ErrorHandler::setErrorHandler('Error installing License file.', RESPONSE_FILESYSTEM_ERROR);
- $errorMsg = MessageLib::createStaticMessage(SCMSG_STATIC_ERROR, ErrorHandler::getLogMessage(), ErrorHandler::getErrorCode());
- SCLog::log($errorMsg, LOG_LEVEL_CRITICAL, LOG_TYPE_ALL);
- return ERROR;
- }
- if (LicenseLib::setLicenseFields(0) === ERROR) {
- .....................................................................
- .....................................
- ..............
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement