Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by http://DeZender.Net
  5. * @ deZender (PHP7 Decoder for Plesk Encoder)
  6. *
  7. * @ Version : 4.0.9.0
  8. * @ Author : DeZender
  9. * @ Release on : 08.08.2019
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. class Modules_Kolab_License
  15. {
  16. const CACHE = true;
  17.  
  18. static protected $instance;
  19. static protected $license;
  20. static protected $license_count;
  21. static protected $license_limit;
  22. static protected $expiry_date;
  23. static protected $renewal_date;
  24. static private $product_name = 'ext-kolab';
  25.  
  26. static public function get_instance()
  27. {
  28. if (!self::$instance) {
  29. self::$instance = new Modules_Kolab_License();
  30. }
  31.  
  32. return self::$instance;
  33. }
  34.  
  35. static public function is_current()
  36. {
  37. if (!self::$expiry_date) {
  38. self::expire_date();
  39. }
  40.  
  41. if (!self::$renewal_date) {
  42. self::renew_date();
  43. }
  44.  
  45. $now = new DateTime('now');
  46.  
  47. if (self::$expiry_date < $now) {
  48. pm_Log::debug('License expired. Message ID 70.');
  49. return false;
  50. }
  51.  
  52. if (self::$renewal_date < $now) {
  53. pm_Log::debug('License pending renewal. Message ID 75.');
  54. return true;
  55. }
  56.  
  57. return true;
  58. }
  59.  
  60. static public function is_licensed()
  61. {
  62. if (!self::$license) {
  63. $result = self::get_license();
  64.  
  65. if (!$result) {
  66. pm_Log::debug('Can not validate license. Message ID 89.');
  67. return false;
  68. }
  69. }
  70.  
  71. if (!self::is_current()) {
  72. return false;
  73. }
  74.  
  75. return true;
  76. }
  77.  
  78. static public function is_valid()
  79. {
  80. if (!self::$license) {
  81. if (!self::get_license()) {
  82. return false;
  83. }
  84. }
  85.  
  86. if (!self::is_current()) {
  87. return false;
  88. }
  89.  
  90. return true;
  91. }
  92.  
  93. static public function license_count_for_domains($domains, $count_free_mailboxes)
  94. {
  95. $api = pm_ApiRpc::getService();
  96. $count = 0;
  97.  
  98. foreach ($domains as $domain) {
  99. if (!$domain->isActive()) {
  100. continue;
  101. }
  102. if (!$count_free_mailboxes && !$domain->hasPermission('manage_kolab')) {
  103. continue;
  104. }
  105.  
  106. $request = '<webspace><get><filter><id>' . $domain->getId() . '</id>' . '</filter><dataset><stat/></dataset>' . '</get></webspace>';
  107. $result = $api->call($request, 'admin');
  108. $count += $result->webspace->get->result->data->stat->box;
  109. }
  110.  
  111. return $count;
  112. }
  113.  
  114. static public function license_count()
  115. {
  116. if (self::$license_count) {
  117. return self::$license_count;
  118. }
  119.  
  120. $recent = self::cache_get('license-count', false);
  121.  
  122. if ($recent !== false) {
  123. $recent = json_decode($recent, true);
  124. if ((time() <= $recent['time'] + 600) && ($recent['time'] < (time() + 10))) {
  125. if ($recent['count'] == NULL) {
  126. return 0;
  127. }
  128.  
  129. return $recent['count'];
  130. }
  131. }
  132.  
  133. $count = self::license_count_for_domains(pm_Domain::getAllDomains(true), false);
  134. self::cache_set('license-count', json_encode(['time' => time(), 'count' => $count]));
  135. self::$license_count = $count;
  136. return $count;
  137. }
  138.  
  139. static public function invalidate_count_cache()
  140. {
  141. pm_Settings::set('license-count', false);
  142. }
  143.  
  144. static public function license_warning_threshold()
  145. {
  146. if (self::license_limit() < 0) {
  147. return false;
  148. }
  149.  
  150. if (self::license_limit() <= 20) {
  151. $count_threshold = floor(self::license_limit() * 0.8);
  152. }
  153. else if (self::license_limit() <= 200) {
  154. $count_threshold = floor(self::license_limit() * 0.9);
  155. }
  156. else {
  157. $count_threshold = floor(self::license_limit() * 0.95);
  158. }
  159.  
  160. if ($count_threshold <= self::license_count()) {
  161. return true;
  162. }
  163.  
  164. return false;
  165. }
  166.  
  167. static public function license_limit()
  168. {
  169. if (self::$license_limit) {
  170. return self::$license_limit;
  171. }
  172.  
  173. if (!self::$license) {
  174. if (!self::get_license()) {
  175. return -1;
  176. }
  177. }
  178.  
  179. if (!self::is_current()) {
  180. return -1;
  181. }
  182.  
  183. $recent = self::cache_get('license-limit', false);
  184.  
  185. if ($recent !== false) {
  186. $recent = json_decode($recent, true);
  187. if ((time() <= $recent['time'] + 600) && ($recent['time'] < (time() + 10))) {
  188. return $recent['limit'];
  189. }
  190. }
  191.  
  192. $body = self::$license['key-body'];
  193. $body_parsed = openssl_x509_parse($body);
  194.  
  195. if (!array_key_exists('extensions', $body_parsed)) {
  196. self::$license_limit = (int) explode(' ', self::$license['app'])[1];
  197. self::cache_set('license-limit', json_encode(['time' => time(), 'limit' => self::$license_limit]));
  198. return self::$license_limit;
  199. }
  200.  
  201. if (!array_key_exists('nsComment', $body_parsed['extensions'])) {
  202. self::$license_limit = (int) explode(' ', self::$license['app'])[1];
  203. self::cache_set('license-limit', json_encode(['time' => time(), 'limit' => self::$license_limit]));
  204. return self::$license_limit;
  205. .........................................................................
  206. .........................................
  207. .................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement