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 Plesk Encoder)
- *
- * @ Version : 4.0.9.0
- * @ Author : DeZender
- * @ Release on : 08.08.2019
- * @ Official site : http://DeZender.Net
- *
- */
- class Modules_Kolab_License
- {
- const CACHE = true;
- static protected $instance;
- static protected $license;
- static protected $license_count;
- static protected $license_limit;
- static protected $expiry_date;
- static protected $renewal_date;
- static private $product_name = 'ext-kolab';
- static public function get_instance()
- {
- if (!self::$instance) {
- self::$instance = new Modules_Kolab_License();
- }
- return self::$instance;
- }
- static public function is_current()
- {
- if (!self::$expiry_date) {
- self::expire_date();
- }
- if (!self::$renewal_date) {
- self::renew_date();
- }
- $now = new DateTime('now');
- if (self::$expiry_date < $now) {
- pm_Log::debug('License expired. Message ID 70.');
- return false;
- }
- if (self::$renewal_date < $now) {
- pm_Log::debug('License pending renewal. Message ID 75.');
- return true;
- }
- return true;
- }
- static public function is_licensed()
- {
- if (!self::$license) {
- $result = self::get_license();
- if (!$result) {
- pm_Log::debug('Can not validate license. Message ID 89.');
- return false;
- }
- }
- if (!self::is_current()) {
- return false;
- }
- return true;
- }
- static public function is_valid()
- {
- if (!self::$license) {
- if (!self::get_license()) {
- return false;
- }
- }
- if (!self::is_current()) {
- return false;
- }
- return true;
- }
- static public function license_count_for_domains($domains, $count_free_mailboxes)
- {
- $api = pm_ApiRpc::getService();
- $count = 0;
- foreach ($domains as $domain) {
- if (!$domain->isActive()) {
- continue;
- }
- if (!$count_free_mailboxes && !$domain->hasPermission('manage_kolab')) {
- continue;
- }
- $request = '<webspace><get><filter><id>' . $domain->getId() . '</id>' . '</filter><dataset><stat/></dataset>' . '</get></webspace>';
- $result = $api->call($request, 'admin');
- $count += $result->webspace->get->result->data->stat->box;
- }
- return $count;
- }
- static public function license_count()
- {
- if (self::$license_count) {
- return self::$license_count;
- }
- $recent = self::cache_get('license-count', false);
- if ($recent !== false) {
- $recent = json_decode($recent, true);
- if ((time() <= $recent['time'] + 600) && ($recent['time'] < (time() + 10))) {
- if ($recent['count'] == NULL) {
- return 0;
- }
- return $recent['count'];
- }
- }
- $count = self::license_count_for_domains(pm_Domain::getAllDomains(true), false);
- self::cache_set('license-count', json_encode(['time' => time(), 'count' => $count]));
- self::$license_count = $count;
- return $count;
- }
- static public function invalidate_count_cache()
- {
- pm_Settings::set('license-count', false);
- }
- static public function license_warning_threshold()
- {
- if (self::license_limit() < 0) {
- return false;
- }
- if (self::license_limit() <= 20) {
- $count_threshold = floor(self::license_limit() * 0.8);
- }
- else if (self::license_limit() <= 200) {
- $count_threshold = floor(self::license_limit() * 0.9);
- }
- else {
- $count_threshold = floor(self::license_limit() * 0.95);
- }
- if ($count_threshold <= self::license_count()) {
- return true;
- }
- return false;
- }
- static public function license_limit()
- {
- if (self::$license_limit) {
- return self::$license_limit;
- }
- if (!self::$license) {
- if (!self::get_license()) {
- return -1;
- }
- }
- if (!self::is_current()) {
- return -1;
- }
- $recent = self::cache_get('license-limit', false);
- if ($recent !== false) {
- $recent = json_decode($recent, true);
- if ((time() <= $recent['time'] + 600) && ($recent['time'] < (time() + 10))) {
- return $recent['limit'];
- }
- }
- $body = self::$license['key-body'];
- $body_parsed = openssl_x509_parse($body);
- if (!array_key_exists('extensions', $body_parsed)) {
- self::$license_limit = (int) explode(' ', self::$license['app'])[1];
- self::cache_set('license-limit', json_encode(['time' => time(), 'limit' => self::$license_limit]));
- return self::$license_limit;
- }
- if (!array_key_exists('nsComment', $body_parsed['extensions'])) {
- self::$license_limit = (int) explode(' ', self::$license['app'])[1];
- self::cache_set('license-limit', json_encode(['time' => time(), 'limit' => self::$license_limit]));
- return self::$license_limit;
- .........................................................................
- .........................................
- .................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement