|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Model\Order\Order; |
|
6
|
|
|
use App\Model\Product\Product; |
|
7
|
|
|
use Illuminate\Http\Request; |
|
8
|
|
|
use Exception; |
|
9
|
|
|
|
|
10
|
|
|
class HomeController extends Controller |
|
11
|
|
|
{ |
|
12
|
|
|
/* |
|
13
|
|
|
|-------------------------------------------------------------------------- |
|
14
|
|
|
| Home Controller |
|
15
|
|
|
|-------------------------------------------------------------------------- |
|
16
|
|
|
| |
|
17
|
|
|
| This controller renders your application's "dashboard" for users that |
|
18
|
|
|
| are authenticated. Of course, you are free to change or remove the |
|
19
|
|
|
| controller as you wish. It is just here to get your app started! |
|
20
|
|
|
| |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Create a new controller instance. |
|
25
|
|
|
* |
|
26
|
|
|
* @return void |
|
|
|
|
|
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->middleware('auth', ['only' => ['index']]); |
|
31
|
|
|
$this->middleware('admin', ['only' => ['index']]); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Show the application dashboard to the user. |
|
36
|
|
|
* |
|
37
|
|
|
* @return Response |
|
38
|
|
|
*/ |
|
39
|
|
|
public function index() |
|
40
|
|
|
{ |
|
41
|
|
|
return view('themes.default1.layouts.master'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function version(Request $request, Product $product) |
|
45
|
|
|
{ |
|
46
|
|
|
$url = $request->input('response_url'); |
|
47
|
|
|
|
|
48
|
|
|
$title = $request->input('title'); |
|
49
|
|
|
//dd($title); |
|
50
|
|
|
$id = $request->input('id'); |
|
51
|
|
|
if ($id) { |
|
52
|
|
|
$product = $product->where('id', $id)->first(); |
|
53
|
|
|
} else { |
|
54
|
|
|
$product = $product->where('name', $title)->first(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if ($product) { |
|
58
|
|
|
$version = str_replace('v', '', $product->version); |
|
59
|
|
|
} else { |
|
60
|
|
|
$version = 'Not-Available'; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
echo "<form action=$url method=post name=redirect >"; |
|
64
|
|
|
echo '<input type=hidden name=_token value='.csrf_token().'>'; |
|
65
|
|
|
echo "<input type=hidden name=value value=$version />"; |
|
66
|
|
|
echo '</form>'; |
|
67
|
|
|
echo"<script language='javascript'>document.redirect.submit();</script>"; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getVersion(Request $request, Product $product) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->validate($request, [ |
|
73
|
|
|
'title' => 'required', |
|
74
|
|
|
]); |
|
75
|
|
|
$title = $request->input('title'); |
|
76
|
|
|
$product = $product->where('name', $title)->first(); |
|
77
|
|
|
if ($product) { |
|
78
|
|
|
$version = $product->version; |
|
|
|
|
|
|
79
|
|
|
} else { |
|
80
|
|
|
return 0; |
|
81
|
|
|
} |
|
82
|
|
|
return str_replace('v', '', $product->version); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function versionTest() { |
|
86
|
|
|
$s = "eyJpdiI6ImFIVDByR29vVzNpcEExM2UyNDVaWXc9PSIsInZhbHVlIjoiODNJS0MxWXFyVEtrYjhZYXFmUFlvOTJYY09NUHhGYTZBemN2eFMzckZCST0iLCJtYWMiOiI2MDdmZTU5YmRjMjQxOWRlZjE3ODUyMWI0OTk5NDM5ZmQxMWE5ZTUyNzQ3YTMyOGQyYmRmNGVkYWQyNDM5ZTNkIn0="; |
|
87
|
|
|
dd(decrypt($s)); |
|
88
|
|
|
$url = "http://localhost/billings/agorainvoicing/agorainvoicing/public/version"; |
|
|
|
|
|
|
89
|
|
|
$response = "http://localhost/billings/agorainvoicing/agorainvoicing/public/version-result"; |
|
|
|
|
|
|
90
|
|
|
$name = "faveo helpdesk community"; |
|
|
|
|
|
|
91
|
|
|
$version = $product->version; |
|
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
return str_replace('v', '', $product->version); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function versionTest() |
|
97
|
|
|
{ |
|
98
|
|
|
$url = 'http://localhost/billings/agorainvoicing/agorainvoicing/public/version'; |
|
99
|
|
|
$response = 'http://localhost/billings/agorainvoicing/agorainvoicing/public/version-result'; |
|
100
|
|
|
$name = 'faveo helpdesk community'; |
|
|
|
|
|
|
101
|
|
|
echo "<form action=$url method=post name=redirect >"; |
|
102
|
|
|
echo '<input type=hidden name=_token value=csrf_token() />'; |
|
103
|
|
|
echo "<input type=hidden name=response_url value=$response />"; |
|
104
|
|
|
echo "<input type=hidden name=title value='faveo helpdesk community' />"; |
|
105
|
|
|
echo '</form>'; |
|
106
|
|
|
echo"<script language='javascript'>document.redirect.submit();</script>"; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function versionResult(Request $request) |
|
110
|
|
|
{ |
|
111
|
|
|
dd($request->all()); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function serial(Request $request, Order $order) |
|
115
|
|
|
{ |
|
116
|
|
|
$ul = $request->input('url'); |
|
117
|
|
|
$url = str_replace('serial', 'CheckSerial', $ul); |
|
118
|
|
|
$domain = $request->input('domain'); |
|
119
|
|
|
$first = $request->input('first'); |
|
120
|
|
|
$second = $request->input('second'); |
|
121
|
|
|
$third = $request->input('third'); |
|
122
|
|
|
$forth = $request->input('forth'); |
|
123
|
|
|
$serial = $first.$second.$third.$forth; |
|
124
|
|
|
//dd($serial); |
|
125
|
|
|
$order_no = $request->input('order_no'); |
|
126
|
|
|
$order = $order->where('number', $order_no)->first(); |
|
127
|
|
|
if ($order) { |
|
128
|
|
|
if ($domain === $order->domain) { |
|
129
|
|
|
$key = $order->serial_key; |
|
130
|
|
|
if ($key === $serial) { |
|
131
|
|
|
$id1 = 'true'; |
|
132
|
|
|
echo "<form action=$url/$id1 method=post name=redirect>"; |
|
133
|
|
|
echo '<input type=hidden name=_token value=csrf_token()/>'; |
|
134
|
|
|
echo '</form>'; |
|
135
|
|
|
echo"<script language='javascript'>document.redirect.submit();</script>"; |
|
136
|
|
|
} else { |
|
137
|
|
|
$id = 'false1'; |
|
138
|
|
|
echo "<form action=$url/$id method=post name=redirect>"; |
|
139
|
|
|
echo '<input type=hidden name=_token value=csrf_token()/>'; |
|
140
|
|
|
echo '</form>'; |
|
141
|
|
|
echo"<script language='javascript'>document.redirect.submit();</script>"; |
|
142
|
|
|
} |
|
143
|
|
|
} else { |
|
144
|
|
|
$id = 'false3'; |
|
145
|
|
|
echo "<form action=$url/$id method=post name=redirect>"; |
|
146
|
|
|
echo '<input type=hidden name=_token value=csrf_token()/>'; |
|
147
|
|
|
echo '</form>'; |
|
148
|
|
|
echo"<script language='javascript'>document.redirect.submit();</script>"; |
|
149
|
|
|
} |
|
150
|
|
|
} else { |
|
151
|
|
|
$id = 'false2'; |
|
152
|
|
|
echo "<form action=$url/$id method=post name=redirect>"; |
|
153
|
|
|
echo '<input type=hidden name=_token value=csrf_token()/>'; |
|
154
|
|
|
echo '</form>'; |
|
155
|
|
|
echo"<script language='javascript'>document.redirect.submit();</script>"; |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
public static function decryptByFaveoPrivateKey($encrypted) { |
|
160
|
|
|
try { |
|
161
|
|
|
// Get the private Key |
|
162
|
|
|
$path = storage_path('app/faveo-private.key'); |
|
163
|
|
|
$key_content = file_get_contents($path); |
|
164
|
|
|
if (!$privateKey = openssl_pkey_get_private($key_content)) { |
|
165
|
|
|
throw new \Exception('Private Key failed'); |
|
166
|
|
|
} |
|
167
|
|
|
$a_key = openssl_pkey_get_details($privateKey); |
|
168
|
|
|
|
|
169
|
|
|
// Decrypt the data in the small chunks |
|
170
|
|
|
$chunkSize = ceil($a_key['bits'] / 8); |
|
171
|
|
|
$output = ''; |
|
172
|
|
|
|
|
173
|
|
|
while ($encrypted) { |
|
174
|
|
|
$chunk = substr($encrypted, 0, $chunkSize); |
|
175
|
|
|
$encrypted = substr($encrypted, $chunkSize); |
|
176
|
|
|
$decrypted = ''; |
|
177
|
|
|
if (!openssl_private_decrypt($chunk, $decrypted, $privateKey)) { |
|
178
|
|
|
die('Failed to decrypt data'); |
|
179
|
|
|
} |
|
180
|
|
|
$output .= $decrypted; |
|
181
|
|
|
} |
|
182
|
|
|
openssl_free_key($privateKey); |
|
183
|
|
|
|
|
184
|
|
|
// Uncompress the unencrypted data. |
|
185
|
|
|
$output = gzuncompress($output); |
|
186
|
|
|
|
|
187
|
|
|
return $output; |
|
188
|
|
|
} catch (\Exception $ex) { |
|
189
|
|
|
dd($ex); |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
public function getEncryptedData(Request $request) { |
|
194
|
|
|
$enc = $request->input('en'); |
|
195
|
|
|
$result = self::decryptByFaveoPrivateKey($enc); |
|
196
|
|
|
return response()->json($result); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
public function createEncryptionKeys() { |
|
200
|
|
|
try { |
|
201
|
|
|
$privateKey = openssl_pkey_new(array( |
|
202
|
|
|
'private_key_bits' => 2048, // Size of Key. |
|
203
|
|
|
'private_key_type' => OPENSSL_KEYTYPE_RSA, |
|
204
|
|
|
)); |
|
205
|
|
|
//dd($privateKey); |
|
206
|
|
|
// Save the private key to private.key file. Never share this file with anyone. |
|
207
|
|
|
openssl_pkey_export_to_file($privateKey, 'faveo-private-new.key'); |
|
208
|
|
|
|
|
209
|
|
|
// Generate the public key for the private key |
|
210
|
|
|
$a_key = openssl_pkey_get_details($privateKey); |
|
211
|
|
|
//dd($a_key); |
|
212
|
|
|
// Save the public key in public.key file. Send this file to anyone who want to send you the encrypted data. |
|
213
|
|
|
file_put_contents('faveo-public-new.key', $a_key['key']); |
|
214
|
|
|
|
|
215
|
|
|
// Free the private Key. |
|
216
|
|
|
openssl_free_key($privateKey); |
|
217
|
|
|
} catch (\Exception $ex) { |
|
218
|
|
|
dd($ex); |
|
219
|
|
|
} |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
public function checkSerialKey($faveo_encrypted_key,$order_number) { |
|
223
|
|
|
try { |
|
224
|
|
|
$order = new Order(); |
|
225
|
|
|
$faveo_decrypted_key = self::decryptByFaveoPrivateKey($faveo_encrypted_key); |
|
226
|
|
|
$this_order = $order->where('number', $order_number)->first(); |
|
227
|
|
|
if (!$this_order) { |
|
228
|
|
|
return null; |
|
229
|
|
|
} else { |
|
230
|
|
|
if($this_order->serial_key == $faveo_decrypted_key){ |
|
231
|
|
|
return $this_order->serial_key; |
|
232
|
|
|
} |
|
233
|
|
|
} |
|
234
|
|
|
return null; |
|
235
|
|
|
} catch (Exception $ex) { |
|
236
|
|
|
throw new Exception($ex->getMessage()); |
|
237
|
|
|
} |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
public function checkOrder($faveo_encrypted_order_number) { |
|
241
|
|
|
try { |
|
242
|
|
|
$order = new Order(); |
|
243
|
|
|
$faveo_decrypted_order = self::decryptByFaveoPrivateKey($faveo_encrypted_order_number); |
|
244
|
|
|
$this_order = $order->where('number', $faveo_decrypted_order)->first(); |
|
245
|
|
|
if (!$this_order) { |
|
246
|
|
|
return null; |
|
247
|
|
|
} else { |
|
248
|
|
|
return $this_order->number; |
|
249
|
|
|
} |
|
250
|
|
|
} catch (Exception $ex) { |
|
251
|
|
|
throw new Exception($ex->getMessage()); |
|
252
|
|
|
} |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
View Code Duplication |
public function checkDomain($request_url) { |
|
256
|
|
|
try { |
|
257
|
|
|
// echo $request_url; |
|
258
|
|
|
// exit(); |
|
259
|
|
|
$order = new Order(); |
|
260
|
|
|
$this_order = $order->where('domain', $request_url)->first(); |
|
261
|
|
|
if (!$this_order) { |
|
262
|
|
|
return null; |
|
263
|
|
|
} else { |
|
264
|
|
|
return $this_order->domain; |
|
265
|
|
|
} |
|
266
|
|
|
} catch (Exception $ex) { |
|
267
|
|
|
throw new Exception($ex->getMessage()); |
|
268
|
|
|
} |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
View Code Duplication |
public function verifyOrder($order_number, $serial_key, $domain) { |
|
272
|
|
|
try { |
|
273
|
|
|
|
|
274
|
|
|
$order = new Order(); |
|
275
|
|
|
$this_order = $order |
|
276
|
|
|
->where('number', $order_number) |
|
277
|
|
|
// ->where('serial_key', $serial_key) |
|
278
|
|
|
->where('domain', $domain) |
|
279
|
|
|
->first(); |
|
280
|
|
|
return $this_order; |
|
281
|
|
|
} catch (Exception $ex) { |
|
282
|
|
|
throw new Exception($ex->getMessage()); |
|
283
|
|
|
} |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
public function faveoVerification(Request $request) { |
|
287
|
|
|
try { |
|
288
|
|
|
$url = $request->input('url'); |
|
289
|
|
|
$faveo_encrypted_order_number = $request->input('order_number'); |
|
290
|
|
|
$faveo_encrypted_key = $request->input('serial_key'); |
|
291
|
|
|
$request_type = $request->input('request_type'); |
|
292
|
|
|
$faveo_name = $request->input('name'); |
|
293
|
|
|
$faveo_version = $request->input('version'); |
|
294
|
|
|
$order_number = $this->checkOrder($faveo_encrypted_order_number); |
|
295
|
|
|
$domain = $this->checkDomain($url); |
|
296
|
|
|
$serial_key = $this->checkSerialKey($faveo_encrypted_key,$order_number); |
|
297
|
|
|
//return $serial_key; |
|
298
|
|
|
$result = []; |
|
299
|
|
|
if ($request_type == 'install') { |
|
300
|
|
|
$result = $this->verificationResult($order_number, $serial_key, $domain); |
|
301
|
|
|
} |
|
302
|
|
|
if ($request_type == 'check_update') { |
|
303
|
|
|
$result = $this->checkUpdate($order_number, $serial_key, $domain, $faveo_name, $faveo_version); |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
return response()->json($result); |
|
|
|
|
|
|
307
|
|
|
} catch (Exception $ex) { |
|
308
|
|
|
$result = ['status' => 'error', 'message' => $ex->getMessage()]; |
|
309
|
|
|
return response()->json($result); |
|
310
|
|
|
} |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
public function verificationResult($order_number, $serial_key, $domain) { |
|
314
|
|
|
try { |
|
315
|
|
|
|
|
316
|
|
|
if ($order_number && $domain && $serial_key) { |
|
317
|
|
|
$order = $this->verifyOrder($order_number, $serial_key, $domain); |
|
318
|
|
|
if ($order) { |
|
319
|
|
|
return ['status' => 'success', 'message' => 'This is a valid request']; |
|
320
|
|
|
} |
|
321
|
|
|
} else { |
|
322
|
|
|
return ['status' => 'fails', 'message' => 'This is an invalid request']; |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
} catch (Exception $ex) { |
|
326
|
|
|
throw new Exception($ex->getMessage()); |
|
327
|
|
|
} |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
public function checkUpdate($order_number, $serial_key, $domain, $faveo_name, $faveo_version) { |
|
331
|
|
|
try { |
|
332
|
|
|
if ($order_number && $domain && $serial_key) { |
|
333
|
|
|
$order = $this->verifyOrder($order_number, $serial_key, $domain); |
|
334
|
|
|
//var_dump($order); |
|
335
|
|
|
if ($order) { |
|
336
|
|
|
return $this->checkFaveoDetails($order_number, $faveo_name, $faveo_version); |
|
337
|
|
|
} |
|
338
|
|
|
} else { |
|
339
|
|
|
return ['status' => 'fails', 'message' => 'This is an invalid request']; |
|
340
|
|
|
} |
|
341
|
|
|
} catch (Exception $ex) { |
|
342
|
|
|
throw new Exception($ex->getMessage()); |
|
343
|
|
|
} |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
public function checkFaveoDetails($order_number, $faveo_name, $faveo_version) { |
|
347
|
|
|
try { |
|
348
|
|
|
$order = new Order(); |
|
349
|
|
|
$product = new Product(); |
|
350
|
|
|
$this_order = $order->where('number', $order_number)->first(); |
|
351
|
|
|
if ($this_order) { |
|
352
|
|
|
$product_id = $this_order->product; |
|
353
|
|
|
if($product_id){ |
|
354
|
|
|
$this_product = $product->where('id',$product_id)->first(); |
|
355
|
|
|
if($this_product){ |
|
356
|
|
|
$version = str_replace('v', '', $this_product->version); |
|
357
|
|
|
return ['status' => 'success', 'message' => 'This is a valid request','version'=>$version]; |
|
358
|
|
|
} |
|
359
|
|
|
} |
|
360
|
|
|
} |
|
361
|
|
|
return ['status' => 'fails', 'message' => 'This is an invalid request']; |
|
362
|
|
|
|
|
363
|
|
|
} catch (Exception $ex) { |
|
364
|
|
|
throw new Exception($ex->getMessage()); |
|
365
|
|
|
} |
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
} |
|
369
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.