-
Notifications
You must be signed in to change notification settings - Fork 5
/
Cryptolens.php
90 lines (78 loc) · 2.17 KB
/
Cryptolens.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
function cryptolens_activate($token, $product_id, $key, $machine_code)
{
$params =
array(
'token' => $token
, 'ProductId' => $product_id
, 'Key' => $key
, 'Sign' => 'True'
, 'MachineCode' => $machine_code
, 'SignMethod' => 1
, 'v' => 1
);
$postfields = '';
$first = TRUE;
foreach ($params as $i => $x) {
if ($first) { $first = FALSE; } else { $postfields .= '&'; }
$postfields .= urlencode($i);
$postfields .= '=';
$postfields .= urlencode($x);
}
unset($i, $x);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1
, CURLOPT_URL => 'https://app.cryptolens.io/api/key/Activate'
, CURLOPT_POST => 1
, CURLOPT_POSTFIELDS => $postfields
));
$result = curl_exec($curl);
curl_close($curl);
$resp = json_decode($result);
if ( is_null($resp)
|| !property_exists($resp, 'message')
|| $resp->{'message'} !== ''
|| !property_exists($resp, 'licenseKey')
|| !property_exists($resp, 'signature')
)
{
return FALSE;
}
$license_key_string = base64_decode($resp->{'licenseKey'});
if (!$license_key_string) { return FALSE; }
$license_key = json_decode($license_key_string);
if ( is_null($license_key)
|| !property_exists($license_key, 'ProductId')
|| !is_int($license_key->{'ProductId'})
|| !property_exists($license_key, 'Key')
|| !is_string($license_key->{'Key'})
|| !property_exists($license_key, 'Expires')
|| !is_int($license_key->{'Expires'})
|| !property_exists($license_key, 'ActivatedMachines')
//|| !is_iterable($license_key->{'ActivatedMachines'})
)
{
return FALSE;
}
if ( $license_key->{'ProductId'} !== $product_id
|| $license_key->{'Key'} !== $key
)
{
return FALSE;
}
$machine_found = FALSE;
foreach ($license_key->{'ActivatedMachines'} as $machine) {
if (!property_exists($machine, 'Mid'))
{
return FALSE;
}
if ($machine->{'Mid'} == $machine_code) { $machine_found = TRUE; }
}
unset($machine);
if (!$machine_found) { return FALSE; }
$time = time();
if ($license_key->{'Expires'} < $time) { return FALSE; }
return TRUE;
}
?>