|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\License; |
|
4
|
|
|
|
|
5
|
|
|
use App\ApiKey; |
|
6
|
|
|
use App\Http\Controllers\Controller; |
|
7
|
|
|
use App\Model\Order\Order; |
|
8
|
|
|
use App\Model\Product\Product; |
|
9
|
|
|
use App\User; |
|
10
|
|
|
|
|
11
|
|
|
class LicenseController extends Controller |
|
12
|
|
|
{ |
|
13
|
|
|
private $api_key_secret; |
|
14
|
|
|
private $url; |
|
15
|
|
|
private $license; |
|
16
|
|
|
|
|
17
|
|
|
public function __construct() |
|
18
|
|
|
{ |
|
19
|
|
|
$model = new ApiKey(); |
|
20
|
|
|
$this->license = $model->first(); |
|
21
|
|
|
|
|
22
|
|
|
$this->api_key_secret = $this->license->license_api_secret; |
|
23
|
|
|
$this->url = $this->license->license_api_url; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
private function postCurl($post_url, $post_info) |
|
27
|
|
|
{ |
|
28
|
|
|
$ch = curl_init(); |
|
29
|
|
|
curl_setopt($ch, CURLOPT_URL, $post_url); |
|
30
|
|
|
curl_setopt($ch, CURLOPT_POST, 1); |
|
31
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_info); |
|
32
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
33
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
34
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
35
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
|
36
|
|
|
$result = curl_exec($ch); |
|
37
|
|
|
curl_close($ch); |
|
38
|
|
|
return $result; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/* |
|
42
|
|
|
* Add New Product |
|
43
|
|
|
*/ |
|
44
|
|
|
public function addNewProduct($product_name, $product_sku) |
|
45
|
|
|
{ |
|
46
|
|
|
$url = $this->url; |
|
47
|
|
|
$api_key_secret = $this->api_key_secret; |
|
48
|
|
|
$addProduct = $this->postCurl($url, "api_key_secret=$api_key_secret&api_function=products_add&product_title=$product_name&product_sku=$product_sku&product_status=1"); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/* |
|
52
|
|
|
* Add New User |
|
53
|
|
|
*/ |
|
54
|
|
|
public function addNewUser($first_name, $last_name, $email) |
|
55
|
|
|
{ |
|
56
|
|
|
$url = $this->url; |
|
57
|
|
|
$api_key_secret = $this->api_key_secret; |
|
58
|
|
|
$addProduct = $this->postCurl($url, "api_key_secret=$api_key_secret&api_function=clients_add |
|
59
|
|
|
&client_fname=$first_name&client_lname=$last_name&client_email=$email&client_status=1"); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/* |
|
63
|
|
|
* Edit Product |
|
64
|
|
|
*/ |
|
65
|
|
|
public function editProduct($product_name, $product_sku) |
|
66
|
|
|
{ |
|
67
|
|
|
$productId = $this->searchProductId($product_sku); |
|
68
|
|
|
$url = $this->url; |
|
69
|
|
|
$api_key_secret = $this->api_key_secret; |
|
70
|
|
|
$addProduct = $this->postCurl($url, "api_key_secret=$api_key_secret&api_function=products_edit |
|
71
|
|
|
&product_id=$productId&product_title=$product_name&product_sku=$product_sku&product_status=1"); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/* |
|
75
|
|
|
* Search for product id while updating client |
|
76
|
|
|
*/ |
|
77
|
|
|
public function searchProductId($product_sku) |
|
78
|
|
|
{ |
|
79
|
|
|
try { |
|
80
|
|
|
$productId = ''; |
|
81
|
|
|
$url = $this->url; |
|
82
|
|
|
$api_key_secret = $this->api_key_secret; |
|
83
|
|
|
$getProductId = $this->postCurl($url, "api_key_secret=$api_key_secret&api_function=search |
|
84
|
|
|
&search_type=product&search_keyword=$product_sku"); |
|
85
|
|
|
$details = json_decode($getProductId); |
|
86
|
|
|
if ($details->api_error_detected == 0 && is_array($details->page_message)) {//This is not true if Product_sku is updated |
|
|
|
|
|
|
87
|
|
|
$productId = $details->page_message[0]->product_id; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return $productId; |
|
91
|
|
|
} catch (\Exception $ex) { |
|
92
|
|
|
$result = [$ex->getMessage()]; |
|
93
|
|
|
|
|
94
|
|
|
return response()->json(compact('result'), 500); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function deleteProductFromAPL($product) |
|
99
|
|
|
{ |
|
100
|
|
|
$url = $this->url; |
|
101
|
|
|
$api_key_secret = $this->api_key_secret; |
|
102
|
|
|
$productId = $this->searchProductId($product->product_sku); |
|
103
|
|
|
$productTitle = $product->name; |
|
104
|
|
|
$productSku = $product->sku; |
|
105
|
|
|
$delProduct = $this->postCurl($url, "api_key_secret=$api_key_secret&api_function=products_edit |
|
106
|
|
|
&product_id=$productId&product_title=$productTitle&product_sku=$productSku&product_status=1&delete_record=1"); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/* |
|
110
|
|
|
* Edit User |
|
111
|
|
|
*/ |
|
112
|
|
|
public function editUserInLicensing($first_name, $last_name, $email) |
|
113
|
|
|
{ |
|
114
|
|
|
$userId = $this->searchForUserId($email); |
|
115
|
|
|
$url = $this->url; |
|
116
|
|
|
$api_key_secret = $this->api_key_secret; |
|
117
|
|
|
$addProduct = $this->postCurl($url, "api_key_secret=$api_key_secret&api_function=clients_edit&client_id=$userId |
|
118
|
|
|
&client_fname=$first_name&client_lname=$last_name&client_email=$email&client_status=1"); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/* |
|
122
|
|
|
* Search for user id while updating client |
|
123
|
|
|
*/ |
|
124
|
|
|
public function searchForUserId($email) |
|
125
|
|
|
{ |
|
126
|
|
|
$userId = ''; |
|
127
|
|
|
$url = $this->url; |
|
128
|
|
|
$api_key_secret = $this->api_key_secret; |
|
129
|
|
|
$getUserId = $this->postCurl($url, "api_key_secret=$api_key_secret&api_function=search |
|
130
|
|
|
&search_type=client&search_keyword=$email"); |
|
131
|
|
|
|
|
132
|
|
|
$details = json_decode($getUserId); |
|
133
|
|
|
if ($details->api_error_detected == 0 && is_array($details->page_message)) {//This is not true if email is updated |
|
|
|
|
|
|
134
|
|
|
$userId = $details->page_message[0]->client_id; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
return $userId; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/* |
|
141
|
|
|
* Create New License For User |
|
142
|
|
|
*/ |
|
143
|
|
|
public function createNewLicene($orderid, $product, $user_id, |
|
144
|
|
|
$licenseExpiry, $updatesExpiry, $supportExpiry, $serial_key) |
|
145
|
|
|
{ |
|
146
|
|
|
$url = $this->url; |
|
147
|
|
|
$api_key_secret = $this->api_key_secret; |
|
148
|
|
|
$sku = Product::where('id', $product)->first()->product_sku; |
|
149
|
|
|
$licenseExpiry = ($licenseExpiry != '') ? $licenseExpiry->toDateString() : ''; |
|
150
|
|
|
$updatesExpiry = ($updatesExpiry != '') ? $updatesExpiry->toDateString() : ''; |
|
151
|
|
|
$supportExpiry = ($supportExpiry != '') ? $supportExpiry->toDateString() : ''; |
|
152
|
|
|
$order = Order::where('id', $orderid)->first(); |
|
153
|
|
|
$orderNo = $order->number; |
|
154
|
|
|
$domain = $order->domain; |
|
155
|
|
|
$productId = $this->searchProductId($sku); |
|
156
|
|
|
$addLicense = $this->postCurl($url, "api_key_secret=$api_key_secret&api_function=licenses_add&product_id=$productId&license_code=$serial_key&license_require_domain=1&license_status=1&license_order_number=$orderNo&license_domain=$domain&license_limit=6&license_expire_date=$licenseExpiry&license_updates_date=$updatesExpiry&license_support_date=$supportExpiry&license_disable_ip_verification=0"); |
|
|
|
|
|
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/* |
|
160
|
|
|
* Edit Existing License |
|
161
|
|
|
*/ |
|
162
|
|
|
public function updateLicensedDomain($licenseCode, $domain, $productId, $licenseExpiry, $updatesExpiry, $supportExpiry, $orderNo) |
|
|
|
|
|
|
163
|
|
|
{ |
|
164
|
|
|
$l_expiry = ''; |
|
165
|
|
|
$s_expiry = ''; |
|
166
|
|
|
$u_expiry = ''; |
|
167
|
|
|
if (strtotime($licenseExpiry) > 1) { |
|
168
|
|
|
$l_expiry = date('Y-m-d', strtotime($licenseExpiry)); |
|
169
|
|
|
} |
|
170
|
|
|
if (strtotime($updatesExpiry) > 1) { |
|
171
|
|
|
$u_expiry = date('Y-m-d', strtotime($updatesExpiry)); |
|
172
|
|
|
} |
|
173
|
|
|
if (strtotime($supportExpiry) > 1) { |
|
174
|
|
|
$s_expiry = date('Y-m-d', strtotime($supportExpiry)); |
|
175
|
|
|
} |
|
176
|
|
|
$url = $this->url; |
|
177
|
|
|
$isIP = (bool) ip2long($domain); |
|
178
|
|
|
if ($isIP == true) { |
|
|
|
|
|
|
179
|
|
|
$requiredomain = 0; |
|
180
|
|
|
$ip = $domain; |
|
181
|
|
|
$domain = ''; |
|
182
|
|
|
} else { |
|
183
|
|
|
$requiredomain = 1; |
|
184
|
|
|
$domain = $domain; |
|
185
|
|
|
$ip = ''; |
|
186
|
|
|
} |
|
187
|
|
|
$api_key_secret = $this->api_key_secret; |
|
188
|
|
|
$searchLicense = $this->searchLicenseId($licenseCode, $productId); |
|
189
|
|
|
$licenseId = $searchLicense['licenseId']; |
|
190
|
|
|
$productId = $searchLicense['productId']; |
|
191
|
|
|
$licenseCode = $searchLicense['code']; |
|
192
|
|
|
$updateLicense = $this->postCurl($url, "api_key_secret=$api_key_secret&api_function=licenses_edit&product_id=$productId&license_code=$licenseCode&license_id=$licenseId&license_order_number=$orderNo&license_require_domain=$requiredomain&license_status=1&license_expire_date=$l_expiry&license_updates_date=$u_expiry&license_support_date=$s_expiry&license_domain=$domain&license_ip=$ip&license_limit=2"); |
|
|
|
|
|
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
public function searchLicenseId($licenseCode, $productId) |
|
196
|
|
|
{ |
|
197
|
|
|
$license = ''; |
|
198
|
|
|
$product = ''; |
|
199
|
|
|
$code = ''; |
|
200
|
|
|
$url = $this->url; |
|
201
|
|
|
$api_key_secret = $this->api_key_secret; |
|
202
|
|
|
$getLicenseId = $this->postCurl($url, "api_key_secret=$api_key_secret&api_function=search |
|
203
|
|
|
&search_type=license&search_keyword=$licenseCode"); |
|
204
|
|
|
$details = json_decode($getLicenseId); |
|
205
|
|
|
if ($details->api_error_detected == 0 && is_array($details->page_message)) { |
|
206
|
|
|
foreach ($details->page_message as $detail) { |
|
207
|
|
|
if ($detail->product_id == $productId) { |
|
208
|
|
|
$license = $detail->license_id; |
|
209
|
|
|
$product = $detail->product_id; |
|
210
|
|
|
$code = $detail->license_code; |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
return ['productId'=>$product, 'code'=>$code, 'licenseId'=>$license]; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
//Update the Installation status as Inactive after Licensed Domain Is Chnaged |
|
219
|
|
|
public function updateInstalledDomain($licenseCode, $productId) |
|
220
|
|
|
{ |
|
221
|
|
|
$url = $this->url; |
|
222
|
|
|
$api_key_secret = $this->api_key_secret; |
|
223
|
|
|
//Search for the Installation Id |
|
224
|
|
|
$searchInstallationId = $this->searchInstallationId($licenseCode); |
|
225
|
|
|
$details = json_decode($searchInstallationId); |
|
226
|
|
|
if ($details->api_error_detected == 0 && is_array($details->page_message)) { |
|
227
|
|
|
foreach ($details->page_message as $detail) { |
|
228
|
|
|
if ($detail->product_id == $productId) { |
|
229
|
|
|
$installation_id = $detail->installation_id; |
|
230
|
|
|
$installation_ip = $detail->installation_ip; |
|
231
|
|
|
//delete all existing installation |
|
232
|
|
|
$updateInstallation = $this->postCurl($url, "api_key_secret=$api_key_secret&api_function=installations_edit&installation_id=$installation_id&installation_ip=$installation_ip&installation_status=0&delete_record=1"); |
|
|
|
|
|
|
233
|
|
|
} |
|
234
|
|
|
} |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
public function searchInstallationId($licenseCode) |
|
240
|
|
|
{ |
|
241
|
|
|
$url = $this->url; |
|
242
|
|
|
$api_key_secret = $this->api_key_secret; |
|
243
|
|
|
$getInstallId = $this->postCurl($url, "api_key_secret=$api_key_secret&api_function=search |
|
244
|
|
|
&search_type=installation&search_keyword=$licenseCode"); |
|
245
|
|
|
|
|
246
|
|
|
return $getInstallId; |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
public function searchInstallationPath($licenseCode, $productId) |
|
250
|
|
|
{ |
|
251
|
|
|
$installation_domain = array(); |
|
252
|
|
|
$installation_ip = array(); |
|
253
|
|
|
$details = json_decode($this->searchInstallationId($licenseCode)); |
|
254
|
|
|
if ($details->api_error_detected == 0 && is_array($details->page_message)) { |
|
255
|
|
|
foreach ($details->page_message as $detail) { |
|
256
|
|
|
if ($detail->product_id == $productId) { |
|
257
|
|
|
$installation_domain[] = $detail->installation_domain; |
|
258
|
|
|
$installation_ip[] = $detail->installation_ip; |
|
259
|
|
|
} |
|
260
|
|
|
} |
|
261
|
|
|
} |
|
262
|
|
|
return ['installed_path' => $installation_domain , 'installed_ip' => $installation_ip]; |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
//Update Expiration Date After Renewal |
|
266
|
|
|
public function updateExpirationDate($licenseCode, $expiryDate, $productId, $domain, $orderNo, $licenseExpiry, $supportExpiry) |
|
|
|
|
|
|
267
|
|
|
{ |
|
268
|
|
|
$url = $this->url; |
|
269
|
|
|
$isIP = (bool) ip2long($domain); |
|
270
|
|
|
if ($isIP == true) { |
|
|
|
|
|
|
271
|
|
|
$requiredomain = 0; |
|
272
|
|
|
$ip = $domain; |
|
273
|
|
|
$domain = ''; |
|
274
|
|
|
} else { |
|
275
|
|
|
$requiredomain = 1; |
|
276
|
|
|
$domain = $domain; |
|
277
|
|
|
$ip = ''; |
|
278
|
|
|
} |
|
279
|
|
|
$api_key_secret = $this->api_key_secret; |
|
280
|
|
|
$searchLicense = $this->searchLicenseId($licenseCode, $productId); |
|
281
|
|
|
$licenseId = $searchLicense['licenseId']; |
|
282
|
|
|
$productId = $searchLicense['productId']; |
|
283
|
|
|
$code = $searchLicense['code']; |
|
284
|
|
|
$updateLicense = $this->postCurl($url, "api_key_secret=$api_key_secret&api_function=licenses_edit&product_id=$productId&license_code=$code&license_id=$licenseId&license_order_number=$orderNo&license_domain=$domain&license_ip=$ip&license_require_domain=$requiredomain&license_status=1&license_expire_date=$licenseExpiry&license_updates_date=$expiryDate&license_support_date=$supportExpiry&license_limit=2"); |
|
|
|
|
|
|
285
|
|
|
} |
|
286
|
|
|
} |
|
287
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.