From 636de8d9a577e94bc31fa01f71d4d20710cee226 Mon Sep 17 00:00:00 2001 From: Simplaf234-ghost <69170385+Simplaf234-ghost@users.noreply.github.com> Date: Wed, 5 Aug 2020 20:55:33 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=A1=D0=BD=D1=8F=D1=82=D0=B0=20=D0=BE?= =?UTF-8?q?=D0=B1=D1=84=D1=83=D1=81=D0=BA=D0=B0=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/OkayLicense/License.php | 343 +++++++++++++++++++++++++++++++++++- 1 file changed, 342 insertions(+), 1 deletion(-) diff --git a/src/OkayLicense/License.php b/src/OkayLicense/License.php index 0da3458..1ce7620 100644 --- a/src/OkayLicense/License.php +++ b/src/OkayLicense/License.php @@ -1,2 +1,343 @@ isUseModuleDir() && !self::sp3a9bb5(self::spa33ce8($sp81fa35->getModuleTemplatesDir()), self::sp475e42($sp81fa35->getModuleTemplatesDir()))) { return ''; } if ($sp81fa35->isUseModuleDir() === false) { $sp81fa35->setSmartyTemplatesDir($sp81fa35->getDefaultTemplatesDir()); } else { $sp212e30 = self::spa33ce8($sp81fa35->getModuleTemplatesDir()); $sp5315c5 = self::sp475e42($sp81fa35->getModuleTemplatesDir()); $sp81fa35->setSmartyTemplatesDir(array(rtrim($sp81fa35->getDefaultTemplatesDir(), '/') . "/../modules/{$sp212e30}/{$sp5315c5}/html", $sp81fa35->getModuleTemplatesDir(), $sp81fa35->getDefaultTemplatesDir())); } $sp250957 = self::$smarty->fetch($speeec82); if (self::$validLicense === false && $speeec82 == 'index.tpl' && strpos($sp81fa35->getDefaultTemplatesDir(), 'backend/design/html') !== false) { $spe8fb0a = self::$request; $sp9a73bc = $spe8fb0a::getDomainWithProtocol(); $sp87b34c = $spe8fb0a::getRootUrl(); if (!in_array(self::$request->get('controller'), array('LicenseAdmin', 'AuthAdmin'))) { $sp250957 .= strtr(self::sp54014b(7), array('$domain' => $sp87b34c)); } if (!in_array(self::$request->get('controller'), array('', 'LicenseAdmin', 'AuthAdmin'))) { self::$response->redirectTo("{$sp87b34c}/backend/index.php?controller=LicenseAdmin"); } } return $sp250957; } private static function spa33ce8($sp331fb2) { $sp331fb2 = str_replace(DIRECTORY_SEPARATOR, '/', $sp331fb2); return preg_replace('~.*/?Okay/Modules/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?.*~', '$1', $sp331fb2); } private static function sp475e42($sp331fb2) { $sp331fb2 = str_replace(DIRECTORY_SEPARATOR, '/', $sp331fb2); return preg_replace('~.*/?Okay/Modules/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?.*~', '$2', $sp331fb2); } public function startModule($spa1ff7c, $sp212e30, $sp5315c5) { if (empty(self::$module)) { return array(); } $spea06e4 = OkayContainer::getInstance(); $sp8d0077 = array(); $spa28ba8 = self::$module->getInitClassName($sp212e30, $sp5315c5); if (!empty($spa28ba8)) { $spdeabfe = new $spa28ba8((int) $spa1ff7c, $sp212e30, $sp5315c5); $spdeabfe->init(); foreach ($spdeabfe->getBackendControllers() as $sp6a0c24) { $sp6a0c24 = $sp212e30 . '.' . $sp5315c5 . '.' . $sp6a0c24; if (!in_array($sp6a0c24, $sp8d0077)) { $sp8d0077[] = $sp6a0c24; } } } $spc86378 = self::$module->getRoutes($sp212e30, $sp5315c5); if (self::sp3a9bb5($sp212e30, $sp5315c5) === false) { foreach ($spc86378 as &$sp264326) { $sp264326['mock'] = true; } } if (self::sp3a9bb5($sp212e30, $sp5315c5) === true) { $spb4734a = self::$module->getServices($sp212e30, $sp5315c5); $spea06e4->bindServices($spb4734a); $sp46edbb = self::$module->getSmartyPlugins($sp212e30, $sp5315c5); $spea06e4->bindServices($sp46edbb); foreach ($sp46edbb as $spf0ae73 => $spb38ac0) { $this->plugins[$spf0ae73] = $spb38ac0; } } self::$modulesRoutes = array_merge(self::$modulesRoutes, $spc86378); return $sp8d0077; } public function bindModulesRoutes() { Router::bindRoutes(self::$modulesRoutes); } public function registerSmartyPlugins() { if (!empty($this->plugins)) { $sp7c1a60 = ServiceLocator::getInstance(); $sp81fa35 = $sp7c1a60->getService(Design::class); $sp626f83 = $sp7c1a60->getService(Module::class); foreach ($this->plugins as $spb38ac0) { $spffa141 = $sp7c1a60->getService($spb38ac0['class']); $spffa141->register($sp81fa35, $sp626f83); } } } public function check() { $this->sp9f43f8(); return self::$validLicense; } public function name(&$spa47f5c) { if (!empty($spa47f5c) && $this->check() === true) { $spa47f5c = preg_match_all('/./us', $spa47f5c, $sp85878c); $spa47f5c = implode(array_reverse($sp85878c[0])); } } public function getLicenseDomains() { $sp04b187 = $this->spfd1692(self::$config->license); $sp337e74 = array(); foreach ($sp04b187->nl['domains'] as $sp9a73bc) { $sp337e74[] = $sp9a73bc; if (count(explode('.', $sp9a73bc)) >= 2) { $sp337e74[] = '*.' . $sp9a73bc; } } return $sp337e74; } public function getLicenseExpiration() { $sp04b187 = $this->spfd1692(self::$config->license); return $sp04b187->expiration; } private static function sp3a9bb5($sp212e30, $sp5315c5) { if ($sp212e30 != self::sp54014b(4) || self::spdb35ee() != 'lite' || in_array($sp5315c5, self::$freeModules)) { return true; } return false; } private static function sp8cf261() { return getenv('HTTP_HOST'); } private static function spdb35ee() { if (empty(self::$licenseType)) { $sp04b187 = self::spfd1692(self::$config->license); self::$licenseType = $sp04b187->nl['version_type']; } return self::$licenseType; } private static function spb0a7c0() { @($sp4f835b = self::$config->license); if (empty($sp4f835b)) { self::sp26e77c(); } $sp04b187 = self::spfd1692($sp4f835b); if (empty($sp04b187->nl) || !is_array($sp04b187->nl['domains']) || empty($sp04b187->nl['version_type'])) { self::sp26e77c(); } if (!in_array($sp04b187->nl['version_type'], array('pro', 'lite', 'start', 'standard', 'premium'))) { self::sp26e77c(); } if (!class_exists(LicenseAdmin::class) || !class_exists(OkayContainer::class)) { self::sp26e77c(); } return true; } private function spf64008(array $sp5b2f1d) { self::$validLicense = false; $sp9a73bc = self::sp8cf261(); if (in_array($sp9a73bc, $sp5b2f1d)) { self::$validLicense = true; } foreach ($sp5b2f1d as $spda007e) { $spa2f57a = array_reverse(explode('.', $spda007e)); if (count($spa2f57a) >= 2) { $sp91d44b = array_reverse(explode('.', $sp9a73bc)); foreach ($spa2f57a as $sp7a9fe5 => $sp21f09f) { if (!isset($sp91d44b[$sp7a9fe5]) || $sp21f09f != $sp91d44b[$sp7a9fe5]) { break; } if ($sp7a9fe5 == count($spa2f57a) - 1) { self::$validLicense = true; return; } } } } } private static function sp26e77c() { throw new \Exception('Some error with license'); } private static function spfd1692($spf15cf0) { $spffa141 = 13; $sp278ac5 = 3; $sp60e693 = 5; $sp74fa89 = ''; $sp11736a = $sp60e693; $sp8f604e = explode(' ', $spf15cf0); foreach ($sp8f604e as $sp5ef3b6) { for ($spd13009 = 0, $sp0b39eb = ''; $spd13009 < strlen($sp5ef3b6) && isset($sp5ef3b6[$spd13009 + 1]); $spd13009 += 2) { $sp7e80fd = base_convert($sp5ef3b6[$spd13009], 36, 10) - ($spd13009 / 2 + $sp11736a) % 27; $sp394a62 = base_convert($sp5ef3b6[$spd13009 + 1], 36, 10) - ($spd13009 / 2 + $sp11736a) % 24; $sp0b39eb .= $sp394a62 * pow($sp7e80fd, $spffa141 - $sp60e693 - 5) % $spffa141; } $sp0b39eb = base_convert($sp0b39eb, 10, 16); $sp11736a += $sp60e693; for ($sp7e80fd = 0; $sp7e80fd < strlen($sp0b39eb); $sp7e80fd += 2) { $sp74fa89 .= @chr(hexdec($sp0b39eb[$sp7e80fd] . $sp0b39eb[$sp7e80fd + 1])); } } $spe7c719 = new \stdClass(); @(list($spe7c719->domains, $spe7c719->expiration, $spe7c719->comment, $sp462573) = explode('#', $sp74fa89, 4)); $spe7c719->domains = explode(',', $spe7c719->domains); if (!empty($sp462573)) { $spdc6554 = self::sp54014b(1); $sp38324f = self::sp54014b(2); $sp636814 = self::sp54014b(3); $sp462573 = (new $spdc6554())->{$sp38324f}($sp636814($sp462573)); list($spe7c719->nl['domains'], $spe7c719->nl['version_type']) = explode('#', $sp462573, 2); if (!empty($spe7c719->nl['domains'])) { $sp337e74 = array(); foreach (explode(',', $spe7c719->nl['domains']) as $sp28ac10) { $sp337e74[] = trim(htmlspecialchars(strip_tags($sp28ac10))); } $spe7c719->nl['domains'] = $sp337e74; } } else { $spe7c719->nl['domains'] = array(); $spe7c719->nl['version_type'] = 'lite'; } return $spe7c719; } public function setResponseType($spd5cd98) { $this->responseType = $spd5cd98; } public function __destruct() { if ($this->responseType == RESPONSE_HTML && self::$validLicense === false && strpos($_SERVER['REQUEST_URI'], 'backend') === false) { print self::sp54014b(0); } } private static $freeModules = array('LigPay', 'Rozetka'); private function sp9f43f8() { if (self::$inited === false) { self::$validLicense = false; $sp7c1a60 = ServiceLocator::getInstance(); self::$config = $sp7c1a60->getService(Config::class); self::$module = $sp7c1a60->getService(Module::class); self::$smarty = $sp7c1a60->getService(Smarty::class); self::$response = $sp7c1a60->getService(Response::class); self::$request = $sp7c1a60->getService(Request::class); $sp04b187 = $this->spfd1692(self::$config->license); if (self::spb0a7c0() && $this->sp3ba4d0()) { $this->spf64008($sp04b187->nl['domains']); } self::$response->addHeader(self::sp54014b(6) . ' ' . self::$config->version . ' ' . $sp04b187->nl['version_type']); self::$inited = true; } } private function sp3ba4d0() { self::$validLicense = false; $spb5d9fc = $this->getLicenseExpiration(); if ($spb5d9fc == '*' || strtotime($spb5d9fc) >= strtotime(date('d.m.Y'))) { self::$validLicense = true; } return self::$validLicense; } private static function sp54014b($spfc800c) { $sp997ed0 = ''; if (isset(self::$codes[$spfc800c])) { foreach (self::$codes[$spfc800c] as $sp54014b) { $sp997ed0 .= chr($sp54014b); } } return $sp997ed0; } } \ No newline at end of file +namespace OkayLicense; +use Okay\Admin\Controllers\LicenseAdmin; +use Okay\Core\Config; +use Okay\Core\Design; +use Okay\Core\Modules\AbstractInit; +use Okay\Core\OkayContainer\OkayContainer; +use Okay\Core\Request; +use Okay\Core\Response; +use Okay\Core\Router; +use Okay\Core\Modules\Module; +use Okay\Core\ServiceLocator; +use Smarty; +class License +{ + private static $config; + private static $module; + private static $validLicense = false; + private static $licenseType; + private static $smarty; + private static $response; + private static $request; + private static $inited = false; + private $responseType; + private $plugins; + private static $modulesRoutes = array(); + + public static function getHtml(Design $design, $template) + { + if ($design->isUseModuleDir() && !self::checkModule(self::getVendor($design->getModuleTemplatesDir()) , self::getName($design->getModuleTemplatesDir()))) + { + return ''; + } + if ($design->isUseModuleDir() === false) + { + $design->setSmartyTemplatesDir($design->getDefaultTemplatesDir()); + } + else + { + $vendor = self::getVendor($design->getModuleTemplatesDir()); + $module_name = self::getName($design->getModuleTemplatesDir()); + $design->setSmartyTemplatesDir(array( + rtrim($design->getDefaultTemplatesDir() , '/') . "/../modules/{$vendor}/{$module_name}/html", + $design->getModuleTemplatesDir() , + $design->getDefaultTemplatesDir() + )); + } + $html = self::$smarty->fetch($template); + if (self::$validLicense === false && $template == 'index.tpl' && strpos($design->getDefaultTemplatesDir() , 'backend/design/html') !== false) + { + $h = self::$request::getDomainWithProtocol(); + $rootUrl = self::$request::getRootUrl(); + if (!in_array(self::$request->get('controller') , array( + 'LicenseAdmin', + 'AuthAdmin' + ))) + { + $html .= strtr('' , array( + '$domain' => $rootUrl + )); + } + if (!in_array(self::$request->get('controller') , array( + '', + 'LicenseAdmin', + 'AuthAdmin' + ))) + { + self::$response->redirectTo("{$rootUrl}/backend/index.php?controller=LicenseAdmin"); + } + } + return $html; + } + private static function getVendor($module) + { + $module = str_replace(DIRECTORY_SEPARATOR, '/', $module); + return preg_replace('~.*/?Okay/Modules/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?.*~', '$1', $module); + } + private static function getName($module) + { + $module = str_replace(DIRECTORY_SEPARATOR, '/', $module); + return preg_replace('~.*/?Okay/Modules/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?.*~', '$2', $module); + } + public function startModule($id, $vendor, $module_name) + { + if (empty(self::$module)) + { + return array(); + } + $container = OkayContainer::getInstance(); + $startModule = array(); + $initclass = self::$module->getInitClassName($vendor, $module_name); + if (!empty($initclass)) + { + $module = new $initclass((int)$id, $vendor, $module_name); + $module->init(); + foreach ($module->getBackendControllers() as $start) + { + $start = $vendor . '.' . $module_name . '.' . $start; + if (!in_array($start, $startModule)) + { + $startModule[] = $start; + } + } + } + $routes = self::$module->getRoutes($vendor, $module_name); + if (self::checkModule($vendor, $module_name) === false) + { + foreach ($routes as & $route) + { + $route['mock'] = true; + } + } + if (self::checkModule($vendor, $module_name) === true) + { + $services = self::$module->getServices($vendor, $module_name); + $container->bindServices($services); + $smartyplugins = self::$module->getSmartyPlugins($vendor, $module_name); + $container->bindServices($smartyplugins); + foreach ($smartyplugins as $key => $plugin) + { + $this->plugins[$key] = $plugin; + } + } + self::$modulesRoutes = array_merge(self::$modulesRoutes, $routes); + return $startModule; + } + public function bindModulesRoutes() + { + Router::bindRoutes(self::$modulesRoutes); + } + public function registerSmartyPlugins() + { + if (!empty($this->plugins)) + { + $SL = ServiceLocator::getInstance(); + $design = $SL->getService(Design::class); + $smartymodule = $SL->getService(Module::class); + foreach ($this->plugins as $plugin) + { + $service = $SL->getService($plugin['class']); + $service->register($design, $smartymodule); + } + } + } + public function check() + { + if (self::$inited === false) + { + self::$validLicense = false; + $SL = ServiceLocator::getInstance(); + self::$config = $SL->getService(Config::class); + self::$module = $SL->getService(Module::class); + self::$smarty = $SL->getService(Smarty::class); + self::$response = $SL->getService(Response::class); + self::$request = $SL->getService(Request::class); + $licenseText = $this->validate(self::$config->license); + if (self::checkForErrors() && $this->checkExpiration()) + { + $this->checkDomains($licenseText->nl['domains']); + } + self::$response->addHeader('X-Powered-CMS: OkayCMS' . ' ' . self::$config->version . ' ' . $licenseText->nl['version_type']); + self::$inited = true; + } + return self::$validLicense; + } + public function name(&$reversedText) + { + if (!empty($reversedText) && $this->check() === true) + { + $reversedText = preg_match_all('/./us', $reversedText, $ar); + $reversedText = implode(array_reverse($ar[0])); + } + } + public function getLicenseDomains() + { + $licenseText = $this->validate(self::$config->license); + $cryptdomains = array(); + foreach ($licenseText->nl['domains'] as $h) + { + $cryptdomains[] = $h; + if (count(explode('.', $h)) >= 2) + { + $cryptdomains[] = '*.' . $h; + } + } + return $cryptdomains; + } + public function getLicenseExpiration() + { + $licenseText = $this->validate(self::$config->license); + return $licenseText->expiration; + } + private static function checkModule($vendor, $module_name) + { + if ($vendor != "OkayCMS" || self::getLicenseType() != 'lite' || in_array($module_name, self::$freeModules)) + { + return true; + } + return false; + } + private static function getLicenseType() + { + if (empty(self::$licenseType)) + { + $licenseText = self::validate(self::$config->license); + self::$licenseType = $licenseText->nl['version_type']; + } + return self::$licenseType; + } + private static function checkForErrors() + { + @($license = self::$config->license); + if (empty($license)) + { + self::error(); + } + $licenseText = self::validate($license); + if (empty($licenseText->nl) || !is_array($licenseText->nl['domains']) || empty($licenseText->nl['version_type'])) + { + self::error(); + } + if (!in_array($licenseText->nl['version_type'], array( + 'pro', + 'lite', + 'start', + 'standard', + 'premium' + ))) + { + self::error(); + } + if (!class_exists(LicenseAdmin::class) || !class_exists(OkayContainer::class)) + { + self::error(); + } + return true; + } + private function checkDomains(array $domains) + { + self::$validLicense = false; + $h = getenv('HTTP_HOST'); + if (in_array($h, $domains)) + { + self::$validLicense = true; + } + foreach ($domains as $domain) + { + $reverseValid = array_reverse(explode('.', $domain)); + if (count($reverseValid) >= 2) + { + $reverseHost = array_reverse(explode('.', $h)); + foreach ($reverseValid as $level => $value) + { + if (!isset($reverseHost[$level]) || $value != $reverseHost[$level]) + { + break; + } + if ($level == count($reverseValid) - 1) + { + self::$validLicense = true; + return; + } + } + } + } + } + private static function error() + { + throw new \Exception('Some error with license'); + } + private static function validate($key) + { + $p = 13; + $x = 5; + $r = ''; + $s = $x; + $bs = explode(' ', $key); + foreach ($bs as $bl) + { + for ($i = 0, $m = '';$i < strlen($bl) && isset($bl[$i + 1]);$i += 2) + { + $a = base_convert($bl[$i], 36, 10) - ($i / 2 + $s) % 27; + $b = base_convert($bl[$i + 1], 36, 10) - ($i / 2 + $s) % 24; + $m .= $b * pow($a, $p - $x - 5) % $p; + } + $m = base_convert($m, 10, 16); + $s += $x; + for ($a = 0;$a < strlen($m);$a += 2) + { + $r .= @chr(hexdec($m[$a] . $m[$a + 1])); + } + } + $l = new \stdClass(); + @(list($l->domains, $l->expiration, $l->comment, $crypt) = explode('#', $r, 4)); + $l->domains = explode(',', $l->domains); + if (!empty($crypt)) + { + $crypt = (new \phpseclib\Crypt\Blowfish())->{decrypt}(base64_decode($crypt)); + list($l->nl['domains'], $l->nl['version_type']) = explode('#', $crypt, 2); + if (!empty($l->nl['domains'])) + { + $cryptdomains = array(); + foreach (explode(',', $l->nl['domains']) as $cryptdomain) + { + $cryptdomains[] = trim(htmlspecialchars(strip_tags($cryptdomain))); + } + $l->nl['domains'] = $cryptdomains; + } + } + else + { + $l->nl['domains'] = array(); + $l->nl['version_type'] = 'lite'; + } + return $l; + } + public function setResponseType($type) + { + $this->responseType = $type; + } + public function __destruct() + { + if ($this->responseType == RESPONSE_HTML && self::$validLicense === false && strpos($_SERVER['REQUEST_URI'], 'backend') === false) + { + print "