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.1.0.1
- * @ Author : DeZender
- * @ Release on : 29.08.2020
- * @ Official site : http://DeZender.Net
- *
- */
- class LicenseLib
- {
- const FEATURES_ALL_CUSTOMERS = '00000000000000000000000000000000000000';
- const LICENSE_UNMATCHABLE_HASH = 'XXXXX';
- const LICENSE_EXPIRES_NEVER = 'never';
- 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;
- }
- static public function getForeignRepositoriesForLicense($license, $context = CONTEXT_ALL, $repFormat = REPOSITORY_DATAFORMAT_BF_ALL)
- {
- $root = $GLOBALS['root'];
- $directory = $root . '/daemons';
- $repositories = [];
- if (($reps = RepositoryLib::getRepositories(REPOSITORY_TYPE_ALL, RESULT_IDXANNOTATIONS, $context, $repFormat)) === 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) {
- }
- }
- }
- return $repositories;
- }
- 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;
- }
- $currentLicenseDetails = LicenseLib::licenseDetails(NULL, NULL, LICENSE_UPGRADE_CHECK);
- if (($currentLicenseDetails === ERROR) || ($currentLicenseDetails['status'] == RESPONSE_DENIED)) {
- $currentLicenseDetails = [];
- $currentLicenseDetails['type'] = LICENSE_MODE_NONE;
- }
- ErrorHandler::resetError();
- $newLicenseDetails = LicenseLib::licenseDetails($filename);
- if (($newLicenseDetails === 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;
- }
- switch ($currentLicenseDetails['type']) {
- case LICENSE_MODE_SC:
- case LICENSE_MODE_MANAGED_SC:
- if ($newLicenseDetails['type'] == LICENSE_MODE_DIRECTOR) {
- 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;
- }
- break;
- case LICENSE_MODE_DIRECTOR:
- if ($newLicenseDetails['type'] != LICENSE_MODE_DIRECTOR) {
- ErrorHandler::setErrorHandler('New license is not a Tenable.sc Director 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;
- }
- break;
- case LICENSE_MODE_NONE:
- break;
- default:
- ErrorHandler::setErrorHandler('New license is not a valid 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) {
- ErrorHandler::addErrorMessage('Error initializing new License.');
- $errorMsg = MessageLib::createStaticMessage(SCMSG_STATIC_ERROR, ErrorHandler::getLogMessage(), ErrorHandler::getErrorCode());
- SCLog::log($errorMsg, LOG_LEVEL_CRITICAL, LOG_TYPE_ALL);
- return ERROR;
- }
- $job['objectID'] = NOT_SET;
- $job['objectType'] = JOB_TYPE_LICENSE_REPORT;
- $job['ownerID'] = USER_ID_ORGHEAD;
- if (JobLib::insertIntoJobQueue($job, ORG_NONE, time(), IMMEDIATE) === ERROR) {
- ErrorHandler::addErrorMessage('Error queueing licenseReport job.');
- $errorMsg = MessageLib::createStaticMessage(SCMSG_STATIC_LOGMSG, ErrorHandler::getLogMessage(), ErrorHandler::getErrorCode());
- SCLog::log($errorMsg, LOG_LEVEL_WARN, LOG_TYPE_ALL);
- }
- if (($rc = LicenseLib::verifyLicenseStatus()) === ERROR) {
- $copyErrorCode = ErrorHandler::getErrorCode();
- $copyErrorMessage = ErrorHandler::getErrorMessage();
- }
- if (isset($newLicenseDetails['features']['ACAS'])) {
- ReportDefinitionLib::enableACASReports();
- }
- $settings = [];
- $settings['FreshInstall'] = 'no';
- ConfigurationLib::updateConfig($settings);
- dbLib::getDBH()->commit();
- DaemonsLib::restartJobd();
- ErrorHandler::resetError();
- if ($newLicenseDetails['type'] == LICENSE_MODE_DIRECTOR) {
- if (LicenseLib::createDirectorDirectories() === ERROR) {
- ErrorHandler::addErrorMessage('Error initializing Filesystem for Director License.');
- $errorMsg = MessageLib::createStaticMessage(SCMSG_STATIC_ERROR, ErrorHandler::getLogMessage(), ErrorHandler::getErrorCode());
- SCLog::log($errorMsg, LOG_LEVEL_CRITICAL, LOG_TYPE_ALL);
- return ERROR;
- }
- }
- if ($rc == ERROR) {
- ErrorHandler::setErrorHandler($copyErrorMessage, $copyErrorCode);
- }
- else {
- $errorMsg = MessageLib::createStaticMessage(SCMSG_STATIC_LOGMSG, 'New License uploaded.');
- SCLog::log($errorMsg, LOG_LEVEL_INFO, LOG_TYPE_ADMIN);
- }
- return $rc;
- }
- static public function validateRemoteLicenseLiteForMVP($license, $licenseHostname)
- {
- if (($repsWithLicense = LicenseLib::getForeignRepositoriesForLicense($license)) === ERROR) {
- ErrorHandler::addErrorMessage('Failed to validate remote license while retrieving associated Repositories.');
- return ERROR;
- }
- $repsWithLicense = RepositoryLib::organizeByDataFormat($repsWithLicense);
- $ipRepositories = array_merge($repsWithLicense[REPOSITORY_DATAFORMAT_IPV4], $repsWithLicense[REPOSITORY_DATAFORMAT_IPV6]);
- $uuidRepositories = $repsWithLicense[REPOSITORY_DATAFORMAT_AGENT];
- $counts = [];
- if (($ipCount = LicenseLib::countDevicesForRepositories($ipRepositories)) === ERROR) {
- ErrorHandler::addErrorMessage('Failed to validate remote license for while retrieving total IP count of repositories.');
- return ERROR;
- }
- $counts[] = $ipCount;
- if (($uuidCount = LicenseLib::countDevicesForRepositories($uuidRepositories)) === ERROR) {
- ErrorHandler::addErrorMessage('Failed to validate remote license for while retrieving total agent count of repositories.');
- return ERROR;
- }
- $counts[] = $uuidCount;
- $deviceCount = ($counts ? max($counts) : NULL);
- if ((($license = LicenseLib::licenseDetails($license, $licenseHostname)) === ERROR) || ($license['status'] != RESPONSE_OK)) {
- ErrorHandler::addErrorMessage('Failed to validate license for repositories.');
- return ERROR;
- }
- if ($license['ipCount'] < $deviceCount) {
- ErrorHandler::setErrorHandler('License device count is \'' . $deviceCount . '\' but Repository device count for this license is \'' . $license['ipCount'] . '\'.', RESPONSE_STOPPED);
- return ERROR;
- }
- return SUCCESS;
- }
- static public function validateRemoteLicense($license, $licenseHostname)
- {
- if (($repsWithLicense = LicenseLib::getForeignRepositoriesForLicense($license)) === ERROR) {
- ErrorHandler::addErrorMessage('Failed to validate remote license while retrieving associated Repositories.');
- return ERROR;
- }
- if (($deviceCount = LicenseLib::countDevicesForRepositories($repsWithLicense)) === ERROR) {
- ErrorHandler::addErrorMessage('Failed to validate remote license for while retrieving total device count of repositories.');
- return ERROR;
- }
- if ((($license = LicenseLib::licenseDetails($license, $licenseHostname)) === ERROR) || ($license['status'] != RESPONSE_OK)) {
- ErrorHandler::addErrorMessage('Failed to validate license for repositories.');
- return ERROR;
- }
- if ($license['ipCount'] < $deviceCount) {
- ErrorHandler::setErrorHandler('License device count is \'' . $deviceCount . '\' but Repository device count for this license is \'' . $license['ipCount'] . '\'.', RESPONSE_STOPPED);
- return ERROR;
- }
- return SUCCESS;
- }
- static public function countDevicesLiteForMVP($repositoryType = REPOSITORY_TYPE_ALL, $repositoryFormatBF = REPOSITORY_DATAFORMAT_BF_DEVICE, $lock = ACQUIRE_REPOSITORY_LOCK)
- {
- $counts = [];
- if ($repositoryFormatBF & REPOSITORY_DATAFORMAT_BF_IP) {
- if (($ipCount = LicenseLib::countSpecificLicenseQualifyingDevices($repositoryType, REPOSITORY_DATAFORMAT_BF_IP, $lock)) === ERROR) {
- return ERROR;
- }
- $counts[] = $ipCount;
- }
- if ($repositoryFormatBF & REPOSITORY_DATAFORMAT_BF_AGENT) {
- if (($uuidCount = LicenseLib::countSpecificLicenseQualifyingDevices($repositoryType, REPOSITORY_DATAFORMAT_BF_AGENT, $lock)) === ERROR) {
- return ERROR;
- }
- $counts[] = $uuidCount;
- }
- return $counts ? max($counts) : NULL;
- .................................................................
- ..........................................
- ......................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement