|
13 | 13 | */ |
14 | 14 | class Plugin |
15 | 15 | { |
16 | | - public static $name = 'Cloudlinux Licensing'; |
17 | | - public static $description = 'Allows selling of Cloudlinux Server and VPS License Types. More info at https://www.cloudlinux.com/'; |
18 | | - public static $help = 'It provides more than one million end users the ability to quickly install dozens of the leading open source content management systems into their web space. Must have a pre-existing cPanel license with cPanelDirect to purchase a cloudlinux license. Allow 10 minutes for activation.'; |
19 | | - public static $module = 'licenses'; |
20 | | - public static $type = 'service'; |
| 16 | + public static $name = 'Cloudlinux Licensing'; |
| 17 | + public static $description = 'Allows selling of Cloudlinux Server and VPS License Types. More info at https://www.cloudlinux.com/'; |
| 18 | + public static $help = 'It provides more than one million end users the ability to quickly install dozens of the leading open source content management systems into their web space. Must have a pre-existing cPanel license with cPanelDirect to purchase a cloudlinux license. Allow 10 minutes for activation.'; |
| 19 | + public static $module = 'licenses'; |
| 20 | + public static $type = 'service'; |
21 | 21 |
|
22 | | - /** |
23 | | - * Plugin constructor. |
24 | | - */ |
25 | | - public function __construct() |
26 | | - { |
27 | | - } |
| 22 | + /** |
| 23 | + * Plugin constructor. |
| 24 | + */ |
| 25 | + public function __construct() |
| 26 | + { |
| 27 | + } |
28 | 28 |
|
29 | | - /** |
30 | | - * @return array |
31 | | - */ |
32 | | - public static function getHooks() |
33 | | - { |
34 | | - return [ |
35 | | - 'plugin.install' => [__CLASS__, 'getInstall'], |
36 | | - 'plugin.uninstall' => [__CLASS__, 'getUninstall'], |
37 | | - self::$module.'.settings' => [__CLASS__, 'getSettings'], |
38 | | - self::$module.'.activate' => [__CLASS__, 'getActivate'], |
39 | | - self::$module.'.reactivate' => [__CLASS__, 'getActivate'], |
40 | | - self::$module.'.deactivate' => [__CLASS__, 'getDeactivate'], |
41 | | - self::$module.'.deactivate_ip' => [__CLASS__, 'getDeactivateIp'], |
42 | | - self::$module.'.change_ip' => [__CLASS__, 'getChangeIp'], |
43 | | - 'function.requirements' => [__CLASS__, 'getRequirements'], |
44 | | - 'ui.menu' => [__CLASS__, 'getMenu'] |
45 | | - ]; |
46 | | - } |
| 29 | + /** |
| 30 | + * @return array |
| 31 | + */ |
| 32 | + public static function getHooks() |
| 33 | + { |
| 34 | + return [ |
| 35 | + 'plugin.install' => [__CLASS__, 'getInstall'], |
| 36 | + 'plugin.uninstall' => [__CLASS__, 'getUninstall'], |
| 37 | + self::$module.'.settings' => [__CLASS__, 'getSettings'], |
| 38 | + self::$module.'.activate' => [__CLASS__, 'getActivate'], |
| 39 | + self::$module.'.reactivate' => [__CLASS__, 'getActivate'], |
| 40 | + self::$module.'.deactivate' => [__CLASS__, 'getDeactivate'], |
| 41 | + self::$module.'.deactivate_ip' => [__CLASS__, 'getDeactivateIp'], |
| 42 | + self::$module.'.change_ip' => [__CLASS__, 'getChangeIp'], |
| 43 | + 'function.requirements' => [__CLASS__, 'getRequirements'], |
| 44 | + 'ui.menu' => [__CLASS__, 'getMenu'] |
| 45 | + ]; |
| 46 | + } |
47 | 47 |
|
48 | | - /** |
49 | | - * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
50 | | - */ |
51 | | - public static function getInstall(GenericEvent $event) |
52 | | - { |
53 | | - $plugin = $event->getSubject(); |
54 | | - $serviceCategory = $plugin->addServiceCategory(self::$module, 'cloudlinux', 'CloudLinux'); |
55 | | - $plugin->addDefine('SERVICE_TYPES_CLOUDLINUX', $serviceCategory); |
56 | | - $serviceType = $plugin->addServiceType($serviceCategory, self::$module, 'CloudLinux'); |
57 | | - $plugin->addService($serviceCategory, $serviceType, self::$module, 'CloudLinux License', 10.00, 0, 1, 1, ''); |
58 | | - $plugin->addService($serviceCategory, $serviceType, self::$module, 'CloudLinux Type2 License', 11.95, 0, 1, 2, ''); |
59 | | - $plugin->addService($serviceCategory, $serviceType, self::$module, 'KernelCare License', 2.95, 0, 1, 16, ''); |
60 | | - } |
| 48 | + /** |
| 49 | + * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
| 50 | + */ |
| 51 | + public static function getInstall(GenericEvent $event) |
| 52 | + { |
| 53 | + $plugin = $event->getSubject(); |
| 54 | + $serviceCategory = $plugin->addServiceCategory(self::$module, 'cloudlinux', 'CloudLinux'); |
| 55 | + $plugin->addDefine('SERVICE_TYPES_CLOUDLINUX', $serviceCategory); |
| 56 | + $serviceType = $plugin->addServiceType($serviceCategory, self::$module, 'CloudLinux'); |
| 57 | + $plugin->addService($serviceCategory, $serviceType, self::$module, 'CloudLinux License', 10.00, 0, 1, 1, ''); |
| 58 | + $plugin->addService($serviceCategory, $serviceType, self::$module, 'CloudLinux Type2 License', 11.95, 0, 1, 2, ''); |
| 59 | + $plugin->addService($serviceCategory, $serviceType, self::$module, 'KernelCare License', 2.95, 0, 1, 16, ''); |
| 60 | + } |
61 | 61 |
|
62 | | - /** |
63 | | - * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
64 | | - */ |
65 | | - public static function getUninstall(GenericEvent $event) |
66 | | - { |
67 | | - $plugin = $event->getSubject(); |
68 | | - $plugin->disableServiceCategory(self::$module, 'cloudlinux'); |
69 | | - } |
| 62 | + /** |
| 63 | + * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
| 64 | + */ |
| 65 | + public static function getUninstall(GenericEvent $event) |
| 66 | + { |
| 67 | + $plugin = $event->getSubject(); |
| 68 | + $plugin->disableServiceCategory(self::$module, 'cloudlinux'); |
| 69 | + } |
70 | 70 |
|
71 | | - /** |
72 | | - * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
73 | | - * @throws \Detain\Cloudlinux\XmlRpcException |
74 | | - */ |
75 | | - public static function getActivate(GenericEvent $event) |
76 | | - { |
77 | | - $serviceClass = $event->getSubject(); |
78 | | - if ($event['category'] == get_service_define('CLOUDLINUX')) { |
79 | | - myadmin_log(self::$module, 'info', 'Cloudlinux Activation', __LINE__, __FILE__); |
80 | | - $cl = new Cloudlinux(CLOUDLINUX_LOGIN, CLOUDLINUX_KEY); |
81 | | - $response = $cl->isLicensed($serviceClass->getIp(), true); |
82 | | - myadmin_log(self::$module, 'info', 'Response: '.json_encode($response), __LINE__, __FILE__); |
83 | | - if (!is_array($response) || !in_array($event['field1'], array_values($response))) { |
84 | | - $response = $cl->license($serviceClass->getIp(), $event['field1']); |
85 | | - //$serviceExtra = $response['mainKeyNumber'].','.$response['productKey']; |
86 | | - myadmin_log(self::$module, 'info', 'Response: '.json_encode($response), __LINE__, __FILE__); |
87 | | - if ($response === false) { |
88 | | - $event['status'] = 'error'; |
89 | | - $event['status_text'] = 'Error Licensing the new IP.'; |
90 | | - } else { |
91 | | - $event['status'] = 'ok'; |
92 | | - $event['status_text'] = 'The IP Address has been licensed.'; |
93 | | - } |
94 | | - } else { |
95 | | - $event['status'] = 'ok'; |
96 | | - $event['status_text'] = 'The IP Address was already licensed.'; |
97 | | - } |
98 | | - $event->stopPropagation(); |
99 | | - } |
100 | | - } |
| 71 | + /** |
| 72 | + * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
| 73 | + * @throws \Detain\Cloudlinux\XmlRpcException |
| 74 | + */ |
| 75 | + public static function getActivate(GenericEvent $event) |
| 76 | + { |
| 77 | + $serviceClass = $event->getSubject(); |
| 78 | + if ($event['category'] == get_service_define('CLOUDLINUX')) { |
| 79 | + myadmin_log(self::$module, 'info', 'Cloudlinux Activation', __LINE__, __FILE__); |
| 80 | + $cl = new Cloudlinux(CLOUDLINUX_LOGIN, CLOUDLINUX_KEY); |
| 81 | + $response = $cl->isLicensed($serviceClass->getIp(), true); |
| 82 | + myadmin_log(self::$module, 'info', 'Response: '.json_encode($response), __LINE__, __FILE__); |
| 83 | + if (!is_array($response) || !in_array($event['field1'], array_values($response))) { |
| 84 | + $response = $cl->license($serviceClass->getIp(), $event['field1']); |
| 85 | + //$serviceExtra = $response['mainKeyNumber'].','.$response['productKey']; |
| 86 | + myadmin_log(self::$module, 'info', 'Response: '.json_encode($response), __LINE__, __FILE__); |
| 87 | + if ($response === false) { |
| 88 | + $event['status'] = 'error'; |
| 89 | + $event['status_text'] = 'Error Licensing the new IP.'; |
| 90 | + } else { |
| 91 | + $event['status'] = 'ok'; |
| 92 | + $event['status_text'] = 'The IP Address has been licensed.'; |
| 93 | + } |
| 94 | + } else { |
| 95 | + $event['status'] = 'ok'; |
| 96 | + $event['status_text'] = 'The IP Address was already licensed.'; |
| 97 | + } |
| 98 | + $event->stopPropagation(); |
| 99 | + } |
| 100 | + } |
101 | 101 |
|
102 | | - /** |
103 | | - * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
104 | | - */ |
105 | | - public static function getDeactivate(GenericEvent $event) |
106 | | - { |
107 | | - $serviceClass = $event->getSubject(); |
108 | | - if ($event['category'] == get_service_define('CLOUDLINUX')) { |
109 | | - myadmin_log(self::$module, 'info', 'Cloudlinux Deactivation', __LINE__, __FILE__); |
110 | | - function_requirements('deactivate_cloudlinux'); |
111 | | - deactivate_cloudlinux($serviceClass->getIp(), $event['field1']); |
112 | | - $event->stopPropagation(); |
113 | | - } |
114 | | - } |
| 102 | + /** |
| 103 | + * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
| 104 | + */ |
| 105 | + public static function getDeactivate(GenericEvent $event) |
| 106 | + { |
| 107 | + $serviceClass = $event->getSubject(); |
| 108 | + if ($event['category'] == get_service_define('CLOUDLINUX')) { |
| 109 | + myadmin_log(self::$module, 'info', 'Cloudlinux Deactivation', __LINE__, __FILE__); |
| 110 | + function_requirements('deactivate_cloudlinux'); |
| 111 | + deactivate_cloudlinux($serviceClass->getIp(), $event['field1']); |
| 112 | + $event->stopPropagation(); |
| 113 | + } |
| 114 | + } |
115 | 115 |
|
116 | | - /** |
117 | | - * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
118 | | - */ |
119 | | - public static function getDeactivateIp(GenericEvent $event) |
120 | | - { |
121 | | - $serviceClass = $event->getSubject(); |
122 | | - if ($event['category'] == get_service_define('CLOUDLINUX')) { |
123 | | - myadmin_log(self::$module, 'info', 'Cloudlinux Deactivation', __LINE__, __FILE__); |
124 | | - function_requirements('deactivate_cloudlinux'); |
125 | | - deactivate_cloudlinux($serviceClass->getIp()); |
126 | | - $event->stopPropagation(); |
127 | | - } |
128 | | - } |
| 116 | + /** |
| 117 | + * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
| 118 | + */ |
| 119 | + public static function getDeactivateIp(GenericEvent $event) |
| 120 | + { |
| 121 | + $serviceClass = $event->getSubject(); |
| 122 | + if ($event['category'] == get_service_define('CLOUDLINUX')) { |
| 123 | + myadmin_log(self::$module, 'info', 'Cloudlinux Deactivation', __LINE__, __FILE__); |
| 124 | + function_requirements('deactivate_cloudlinux'); |
| 125 | + deactivate_cloudlinux($serviceClass->getIp()); |
| 126 | + $event->stopPropagation(); |
| 127 | + } |
| 128 | + } |
129 | 129 |
|
130 | | - /** |
131 | | - * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
132 | | - * @throws \Detain\Cloudlinux\XmlRpcException |
133 | | - */ |
134 | | - public static function getChangeIp(GenericEvent $event) |
135 | | - { |
136 | | - if ($event['category'] == get_service_define('CLOUDLINUX')) { |
137 | | - $serviceClass = $event->getSubject(); |
138 | | - $settings = get_module_settings(self::$module); |
139 | | - myadmin_log(self::$module, 'info', 'IP Change - OLD:'.$serviceClass->getIp()." NEW:{$event['newip']} Type:{$event['field1']}", __LINE__, __FILE__); |
140 | | - $cl = new Cloudlinux(CLOUDLINUX_LOGIN, CLOUDLINUX_KEY); |
141 | | - $response = $cl->remove($serviceClass->getIp(), $event['field1']); |
142 | | - myadmin_log(self::$module, 'info', 'Response: '.json_encode($response), __LINE__, __FILE__); |
143 | | - $event['status'] = 'ok'; |
144 | | - $event['status_text'] = 'The IP Address has been changed.'; |
145 | | - if ($response === false) { |
146 | | - $event['status'] = 'error'; |
147 | | - $event['status_text'] = 'Error removing the old license.'; |
148 | | - } else { |
149 | | - $response = $cl->isLicensed($event['newip'], true); |
150 | | - myadmin_log(self::$module, 'info', 'Response: '.json_encode($response), __LINE__, __FILE__); |
151 | | - if (!is_array($response) || !in_array($event['field1'], array_values($response))) { |
152 | | - $response = $cl->license($event['newip'], $event['field1']); |
153 | | - //$serviceExtra = $response['mainKeyNumber'].','.$response['productKey']; |
154 | | - myadmin_log(self::$module, 'info', 'Response: '.json_encode($response), __LINE__, __FILE__); |
155 | | - if ($response === false) { |
156 | | - $event['status'] = 'error'; |
157 | | - $event['status_text'] = 'Error Licensing the new IP.'; |
158 | | - } |
159 | | - } |
160 | | - } |
161 | | - if ($event['status'] == 'ok') { |
162 | | - $GLOBALS['tf']->history->add($settings['TABLE'], 'change_ip', $event['newip'], $serviceClass->getId(), $serviceClass->getCustid()); |
163 | | - $serviceClass->set_ip($event['newip'])->save(); |
164 | | - } |
165 | | - $event->stopPropagation(); |
166 | | - } |
167 | | - } |
| 130 | + /** |
| 131 | + * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
| 132 | + * @throws \Detain\Cloudlinux\XmlRpcException |
| 133 | + */ |
| 134 | + public static function getChangeIp(GenericEvent $event) |
| 135 | + { |
| 136 | + if ($event['category'] == get_service_define('CLOUDLINUX')) { |
| 137 | + $serviceClass = $event->getSubject(); |
| 138 | + $settings = get_module_settings(self::$module); |
| 139 | + myadmin_log(self::$module, 'info', 'IP Change - OLD:'.$serviceClass->getIp()." NEW:{$event['newip']} Type:{$event['field1']}", __LINE__, __FILE__); |
| 140 | + $cl = new Cloudlinux(CLOUDLINUX_LOGIN, CLOUDLINUX_KEY); |
| 141 | + $response = $cl->remove($serviceClass->getIp(), $event['field1']); |
| 142 | + myadmin_log(self::$module, 'info', 'Response: '.json_encode($response), __LINE__, __FILE__); |
| 143 | + $event['status'] = 'ok'; |
| 144 | + $event['status_text'] = 'The IP Address has been changed.'; |
| 145 | + if ($response === false) { |
| 146 | + $event['status'] = 'error'; |
| 147 | + $event['status_text'] = 'Error removing the old license.'; |
| 148 | + } else { |
| 149 | + $response = $cl->isLicensed($event['newip'], true); |
| 150 | + myadmin_log(self::$module, 'info', 'Response: '.json_encode($response), __LINE__, __FILE__); |
| 151 | + if (!is_array($response) || !in_array($event['field1'], array_values($response))) { |
| 152 | + $response = $cl->license($event['newip'], $event['field1']); |
| 153 | + //$serviceExtra = $response['mainKeyNumber'].','.$response['productKey']; |
| 154 | + myadmin_log(self::$module, 'info', 'Response: '.json_encode($response), __LINE__, __FILE__); |
| 155 | + if ($response === false) { |
| 156 | + $event['status'] = 'error'; |
| 157 | + $event['status_text'] = 'Error Licensing the new IP.'; |
| 158 | + } |
| 159 | + } |
| 160 | + } |
| 161 | + if ($event['status'] == 'ok') { |
| 162 | + $GLOBALS['tf']->history->add($settings['TABLE'], 'change_ip', $event['newip'], $serviceClass->getId(), $serviceClass->getCustid()); |
| 163 | + $serviceClass->set_ip($event['newip'])->save(); |
| 164 | + } |
| 165 | + $event->stopPropagation(); |
| 166 | + } |
| 167 | + } |
168 | 168 |
|
169 | | - /** |
170 | | - * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
171 | | - */ |
172 | | - public static function getMenu(GenericEvent $event) |
173 | | - { |
174 | | - $menu = $event->getSubject(); |
175 | | - if ($GLOBALS['tf']->ima == 'admin') { |
176 | | - $menu->add_link(self::$module.'api', 'choice=none.cloudlinux_licenses_list', '/images/myadmin/list.png', 'List all CloudLinux Licenses'); |
177 | | - } |
178 | | - } |
| 169 | + /** |
| 170 | + * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
| 171 | + */ |
| 172 | + public static function getMenu(GenericEvent $event) |
| 173 | + { |
| 174 | + $menu = $event->getSubject(); |
| 175 | + if ($GLOBALS['tf']->ima == 'admin') { |
| 176 | + $menu->add_link(self::$module.'api', 'choice=none.cloudlinux_licenses_list', '/images/myadmin/list.png', __('List all CloudLinux Licenses')); |
| 177 | + } |
| 178 | + } |
179 | 179 |
|
180 | | - /** |
181 | | - * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
182 | | - */ |
183 | | - public static function getRequirements(GenericEvent $event) |
184 | | - { |
185 | | - $loader = $event->getSubject(); |
186 | | - $loader->add_page_requirement('cloudlinux_licenses_list', '/../vendor/detain/myadmin-cloudlinux-licensing/src/cloudlinux_licenses_list.php'); |
187 | | - $loader->add_requirement('deactivate_kcare', '/../vendor/detain/myadmin-cloudlinux-licensing/src/cloudlinux.inc.php'); |
188 | | - $loader->add_requirement('deactivate_cloudlinux', '/../vendor/detain/myadmin-cloudlinux-licensing/src/cloudlinux.inc.php'); |
189 | | - $loader->add_requirement('get_cloudlinux_licenses', '/../vendor/detain/myadmin-cloudlinux-licensing/src/cloudlinux.inc.php'); |
190 | | - } |
| 180 | + /** |
| 181 | + * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
| 182 | + */ |
| 183 | + public static function getRequirements(GenericEvent $event) |
| 184 | + { |
| 185 | + /** |
| 186 | + * @var \MyAdmin\Plugins\Loader $this->loader |
| 187 | + */ |
| 188 | + $loader = $event->getSubject(); |
| 189 | + $loader->add_page_requirement('cloudlinux_licenses_list', '/../vendor/detain/myadmin-cloudlinux-licensing/src/cloudlinux_licenses_list.php'); |
| 190 | + $loader->add_requirement('deactivate_kcare', '/../vendor/detain/myadmin-cloudlinux-licensing/src/cloudlinux.inc.php'); |
| 191 | + $loader->add_requirement('deactivate_cloudlinux', '/../vendor/detain/myadmin-cloudlinux-licensing/src/cloudlinux.inc.php'); |
| 192 | + $loader->add_requirement('get_cloudlinux_licenses', '/../vendor/detain/myadmin-cloudlinux-licensing/src/cloudlinux.inc.php'); |
| 193 | + } |
191 | 194 |
|
192 | | - /** |
193 | | - * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
194 | | - */ |
195 | | - public static function getSettings(GenericEvent $event) |
196 | | - { |
197 | | - $settings = $event->getSubject(); |
198 | | - $settings->add_text_setting(self::$module, 'Cloudlinux', 'cloudlinux_login', 'Cloudlinux Login:', 'Cloudlinux Login', CLOUDLINUX_LOGIN); |
199 | | - $settings->add_text_setting(self::$module, 'Cloudlinux', 'cloudlinux_key', 'Cloudlinux Key:', 'Cloudlinux Key', CLOUDLINUX_KEY); |
200 | | - $settings->add_dropdown_setting(self::$module, 'Cloudlinux', 'outofstock_licenses_cloudlinux', 'Out Of Stock CloudLinux Licenses', 'Enable/Disable Sales Of This Type', OUTOFSTOCK_LICENSES_CLOUDLINUX, ['0', '1'], ['No', 'Yes']); |
201 | | - } |
| 195 | + /** |
| 196 | + * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
| 197 | + */ |
| 198 | + public static function getSettings(GenericEvent $event) |
| 199 | + { |
| 200 | + /** |
| 201 | + * @var \MyAdmin\Settings $settings |
| 202 | + **/ |
| 203 | + $settings = $event->getSubject(); |
| 204 | + $settings->add_text_setting(self::$module, __('Cloudlinux'), 'cloudlinux_login', __('Cloudlinux Login'), __('Cloudlinux Login'), CLOUDLINUX_LOGIN); |
| 205 | + $settings->add_text_setting(self::$module, __('Cloudlinux'), 'cloudlinux_key', __('Cloudlinux Key'), __('Cloudlinux Key'), CLOUDLINUX_KEY); |
| 206 | + $settings->add_dropdown_setting(self::$module, __('Cloudlinux'), 'outofstock_licenses_cloudlinux', __('Out Of Stock CloudLinux Licenses'), __('Enable/Disable Sales Of This Type'), OUTOFSTOCK_LICENSES_CLOUDLINUX, ['0', '1'], ['No', 'Yes']); |
| 207 | + } |
202 | 208 | } |
0 commit comments