forked from tylerhall/Shine
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlicense-inapp.php
More file actions
170 lines (151 loc) · 5.15 KB
/
license-inapp.php
File metadata and controls
170 lines (151 loc) · 5.15 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
require 'includes/master.inc.php';
use UnitedPrototype\GoogleAnalytics;
$response = array(
'result' => 0,
'errorCode' => 1,
'errorMessage' => 'Empty request data'
);
if (!empty($_POST['data']) && !empty($_POST['bundle_id'])) {
$app = new Application();
$app->select($_POST['bundle_id'], 'bundle_id');
if ($app->ok()) {
$data = $app->decodeRequestData($_POST['data']);
if (!empty($data) && !empty($data['activationCode']) && !empty($data['hardwareId'])) {
$serial = $data['activationCode'];
$hwid = $data['hardwareId'];
$a = new Activation();
$params = array(
'serial_number' => $serial,
'app_id' => $app->id,
'hwid' => $hwid
);
$a->selectMultiple($params);
if ($app->use_ga == 1) {
$uuid_ga = abs(crc32($hwid)); # unsigned crc32
// Initilize GA Tracker
$tracker = new GoogleAnalytics\Tracker($app->ga_key, $app->ga_domain);
// Assemble Visitor information
// (could also get unserialized from database)
$visitor = new GoogleAnalytics\Visitor();
$visitor->setUniqueId($uuid_ga);
$visitor->setIpAddress($_SERVER['REMOTE_ADDR']);
$visitor->setUserAgent($_SERVER['HTTP_USER_AGENT']);
$visitor->setScreenResolution('1024x768');
$ga_country = null;
if ($app->ga_country == 1 && function_exists('geoip_country_code_by_name')) {
$ga_country = geoip_country_code_by_name($_SERVER['REMOTE_ADDR']);
if ($ga_country == '') $ga_country = 'XX';
}
// Assemble Session information
// (could also get unserialized from PHP session)
$session = new GoogleAnalytics\Session();
}
# If not found
if (!$a->ok()) {
# Check activations count
$db = Database::getDatabase();
$sql = "SELECT o.id, o.deactivated, o.quantity, COUNT(a.id) AS count, o.first_name, o.last_name
FROM shine_orders AS o
LEFT JOIN shine_activations AS a ON o.id = a.order_id
LEFT JOIN shine_serial_numbers AS sn ON o.id=sn.order_id
WHERE o.app_id = ".((int)$app->id)." AND (sn.serial_number = '".$db->escape($serial)."' OR o.serial_number = '".$db->escape($serial)."')";
if ($db->query($sql) && $db->hasRows()) {
$row = $db->getRow();
if ($row['quantity'] > 0 && $row['deactivated'] == 0 && $row['quantity'] > $row['count']) {
$a = new Activation();
$a->app_id = $app->id;
$a->hwid = $hwid;
$a->serial_number = $serial;
$a->dt = dater();
$a->ip = $_SERVER['REMOTE_ADDR'];
$a->order_id = $row['id'];
$a->name = $row['first_name'];
$a->name = (!empty($row['first_name']) ? $a->name.' ' : '') . $row['last_name'];
$a->insert();
if ($app->use_ga == 1) {
$ga_action = 'New Activation';
$ga_added = $ga_last = $ga_current = new DateTime($a->dt);
}
}
else if ($row['quantity'] <= 0) {
$a->id = null;
$response['errorCode'] = 7;
$response['errorMessage'] = 'Wrong serial number';
}
else if ($row['deactivated'] > 0) {
$a->id = null;
$response['errorCode'] = 6;
$response['errorMessage'] = 'License was deactivated';
}
else {
$a->id = null;
$response['errorCode'] = 5;
$response['errorMessage'] = 'Maximum users for this serial number reached';
}
}
else {
$a->id = null;
$response['errorCode'] = 4;
$response['errorMessage'] = 'Database error';
}
}
# Found, re-generate
else if ($app->use_ga == 1) {
$ga_action = 'ReActivation';
$ga_added = $ga_last = $ga_current = new DateTime($a->dt);
}
if ($a->ok()) {
if ($app->use_ga == 1) {
$visitor->setFirstVisitTime($ga_added);
$visitor->setPreviousVisitTime($ga_last);
$visitor->setCurrentVisitTime($ga_current);
// Assemble Event information
$event = new GoogleAnalytics\Event($app->name, $ga_action, $ga_country, null, true);
// Track event
$tracker->trackEvent($event, $session, $visitor);
}
# Generate license and respond
$license = $a->generateLicenseOnline($a->hwid, $a->name);
$response = array(
'result' => 1,
'licence' => base64_encode($license)
);
}
}
else {
$response['errorCode'] = 3;
$response['errorMessage'] = 'Incorrect data';
}
}
else {
$response['errorCode'] = 2;
$response['errorMessage'] = 'Application not found';
}
}
echo json_encode($response);
/*
$post = trim(file_get_contents('php://input'));
$post = base64_decode($post);
$dict = json_decode($post);
$a = new Activation();
$a->app_id = $dict->app_id;
$a->name = $dict->email;
$a->serial_number = $dict->serial;
$a->dt = dater();
$a->ip = $_SERVER['REMOTE_ADDR'];
$a->insert();
$app = new Application($a->app_id);
if(!$app->ok()) die('serial');
$o = new Order();
$o->select($a->serial_number, 'serial_number');
if(!$o->ok()) die('serial');
// Because we die before the activation is updated with the found order id,
// this has the added benefit of highlighting the activation as "fraudulent"
// in the activations list. It's not fraudulent obviously, but it does let
// us quickly see if deactivated licenses are still being used.
if($o->deactivated == 1) die('serial');
$a->order_id = $o->id;
$a->update();
$o->downloadLicense();
*/