|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* @authors: Nicolaas [at] Sunny Side Up .co.nz |
|
6
|
|
|
* @package: ecommerce |
|
7
|
|
|
* @sub-package: model |
|
8
|
|
|
* @inspiration: Silverstripe Ltd, Jeremy |
|
9
|
|
|
**/ |
|
10
|
|
|
class OrderStatusLog_SecurityCheck extends OrderStatusLog |
|
|
|
|
|
|
11
|
|
|
{ |
|
12
|
|
|
private static $days_ago_to_check = 14; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
private static $db = array( |
|
|
|
|
|
|
15
|
|
|
'Bad' => 'Boolean', |
|
16
|
|
|
'Risks' => 'HTMLText', |
|
17
|
|
|
'SubTotal' => 'Currency', |
|
18
|
|
|
'Check1' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
19
|
|
|
'Check2' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
20
|
|
|
'Check3' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
21
|
|
|
'Check4' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
22
|
|
|
'Check5' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
23
|
|
|
'Check6' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
24
|
|
|
'Check7' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
25
|
|
|
'Check8' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
26
|
|
|
'Check9' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
27
|
|
|
'Check10' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
28
|
|
|
'Check11' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
29
|
|
|
'Check12' => 'Enum("To do, Done, Whitelisted Customer", "To do" )', |
|
30
|
|
|
); |
|
31
|
|
|
|
|
32
|
|
|
private static $many_many = array( |
|
|
|
|
|
|
33
|
|
|
'BlacklistItems' => 'EcommerceSecurityBaseClass' |
|
34
|
|
|
); |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* this array works as follows |
|
38
|
|
|
* array( |
|
39
|
|
|
* Check1 => array( |
|
40
|
|
|
* "Title" => "Customer Has Paid", |
|
41
|
|
|
* "MinSubTotal" => 10, |
|
42
|
|
|
* "Explanation" => "Check Payment system for $$$ coming in" |
|
43
|
|
|
* ), |
|
44
|
|
|
* Check2 => array( |
|
45
|
|
|
* "Title" => "Address Exists", |
|
46
|
|
|
* "MinSubTotal" => 50, |
|
47
|
|
|
* "Explanation" => "Check Payment system for $$$ coming in" |
|
48
|
|
|
* ) |
|
49
|
|
|
* |
|
50
|
|
|
* @var array |
|
51
|
|
|
*/ |
|
52
|
|
|
private static $checks_required = array(); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
private static $summary_fields = array( |
|
|
|
|
|
|
55
|
|
|
'Type' => 'Type', |
|
56
|
|
|
'SubTotal' => 'SubTotal', |
|
57
|
|
|
'SecurityCleared' => 'Security Cleared' |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
|
|
private static $casting = array( |
|
|
|
|
|
|
61
|
|
|
'SecurityCleared' => 'Boolean' |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
private static $defaults = array( |
|
|
|
|
|
|
65
|
|
|
'InternalUseOnly' => true |
|
66
|
|
|
); |
|
67
|
|
|
|
|
68
|
|
|
private static $field_labels = array( |
|
|
|
|
|
|
69
|
|
|
'Bad' => 'Fraudulent', |
|
70
|
|
|
'Title' => 'Value' |
|
71
|
|
|
); |
|
72
|
|
|
|
|
73
|
|
|
private static $singular_name = 'Security Check'; |
|
|
|
|
|
|
74
|
|
|
public function i18n_singular_name() |
|
75
|
|
|
{ |
|
76
|
|
|
return self::$singular_name; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
private static $plural_name = 'Security Checks'; |
|
|
|
|
|
|
80
|
|
|
public function i18n_plural_name() |
|
81
|
|
|
{ |
|
82
|
|
|
return self::$plural_name; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function canCreate($member = null) |
|
86
|
|
|
{ |
|
87
|
|
|
return false; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function canEdit($member = null) |
|
91
|
|
|
{ |
|
92
|
|
|
$order = $this->Order(); |
|
|
|
|
|
|
93
|
|
|
if ($order && $order->exists()) { |
|
94
|
|
|
$status = $order->MyStep(); |
|
95
|
|
|
if ($status && $status->Code == 'SECURITY_CHECK') { |
|
96
|
|
|
return parent::canEdit($member); |
|
97
|
|
|
} else { |
|
98
|
|
|
return false; |
|
99
|
|
|
} |
|
100
|
|
|
} else { |
|
101
|
|
|
return parent::canEdit($member); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* CMS Fields |
|
107
|
|
|
* @return FieldList |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getCMSFields() |
|
110
|
|
|
{ |
|
111
|
|
|
$order = $this->Order(); |
|
|
|
|
|
|
112
|
|
|
if ($order) { |
|
113
|
|
|
$member = $this->orderMember(); |
|
|
|
|
|
|
114
|
|
|
$fields = parent::getCMSFields(); |
|
115
|
|
|
$securityIP = ""; |
|
116
|
|
|
foreach ($this->BlacklistItems() as $item) { |
|
|
|
|
|
|
117
|
|
|
if (is_a($item, 'EcommerceSecurityIP')) { |
|
118
|
|
|
$securityIP = $item->Title; |
|
119
|
|
|
break; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
if ($securityIP) { |
|
123
|
|
|
$country = ''; |
|
124
|
|
|
if (class_exists('GeoIP')) { |
|
125
|
|
|
$country = GeoIP::ip2country($securityIP)['name']; |
|
126
|
|
|
} |
|
127
|
|
|
$fields->addFieldToTab( |
|
128
|
|
|
'Root.Main', |
|
129
|
|
|
HeaderField::create( |
|
130
|
|
|
'BadHeading', |
|
131
|
|
|
'IP Address Info: ' |
|
132
|
|
|
), |
|
133
|
|
|
'Bad' |
|
134
|
|
|
); |
|
135
|
|
|
if ($country) { |
|
136
|
|
|
$country = '<em>Country:</em> '. $country . '</br>'; |
|
137
|
|
|
} |
|
138
|
|
|
$fields->addFieldToTab( |
|
139
|
|
|
'Root.Main', |
|
140
|
|
|
LiteralField::create( |
|
141
|
|
|
'IPAddressLink', |
|
142
|
|
|
$country . '<em>Detailed Info: </em><a href="https://freegeoip.net/?q='.$securityIP.'" target="_blank">https://freegeoip.net/?q='.$securityIP.'</a>' |
|
143
|
|
|
), |
|
144
|
|
|
'Bad' |
|
145
|
|
|
); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
$fields->addFieldToTab( |
|
149
|
|
|
'Root.Main', |
|
150
|
|
|
HeaderField::create( |
|
151
|
|
|
'BadHeading', |
|
152
|
|
|
'Mark as Fraud' |
|
153
|
|
|
), |
|
154
|
|
|
'Bad' |
|
155
|
|
|
); |
|
156
|
|
|
|
|
157
|
|
|
|
|
158
|
|
|
$fields->addFieldToTab( |
|
159
|
|
|
'Root.MoreDetails', |
|
160
|
|
|
HTMLEditorField::create( |
|
161
|
|
|
'Note', |
|
162
|
|
|
'Notes' |
|
163
|
|
|
) |
|
164
|
|
|
); |
|
165
|
|
|
$fields->addFieldToTab( |
|
166
|
|
|
'Root.Main', |
|
167
|
|
|
HeaderField::create( |
|
168
|
|
|
'BadHeading', |
|
169
|
|
|
'Risks' |
|
170
|
|
|
), |
|
171
|
|
|
'Risks' |
|
172
|
|
|
); |
|
173
|
|
|
$riskField = $fields->dataFieldByName('Risks'); |
|
174
|
|
|
$riskField->setTitle(''); |
|
175
|
|
|
|
|
176
|
|
|
if ($member) { |
|
177
|
|
|
$previousOrders = Order::get() |
|
178
|
|
|
->filter( |
|
179
|
|
|
array( |
|
180
|
|
|
'MemberID' => $member->ID |
|
181
|
|
|
) |
|
182
|
|
|
) |
|
183
|
|
|
->exclude( |
|
184
|
|
|
array('ID' => $order->ID) |
|
185
|
|
|
); |
|
186
|
|
|
if ($previousOrders->count()) { |
|
187
|
|
|
$fields->addFieldToTab( |
|
188
|
|
|
"Root.PreviousOrders", |
|
189
|
|
|
new GridField( |
|
190
|
|
|
'PreviousOrdersList', |
|
191
|
|
|
'Previous Orders', |
|
192
|
|
|
$previousOrders |
|
193
|
|
|
) |
|
194
|
|
|
); |
|
195
|
|
|
} else { |
|
196
|
|
|
$fields->addFieldToTab( |
|
197
|
|
|
"Root.PreviousOrders", |
|
198
|
|
|
HeaderField::create( |
|
199
|
|
|
'NoPreviousOrders', |
|
200
|
|
|
'This customer does not have any previous orders' |
|
201
|
|
|
) |
|
202
|
|
|
); |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
} |
|
206
|
|
|
$allFields = array(); |
|
207
|
|
|
for ($i = 1; $i < 13; $i++) { |
|
208
|
|
|
$allFields["Check".$i] = "Check".$i; |
|
209
|
|
|
} |
|
210
|
|
|
$checks = $this->Config()->get('checks_required'); |
|
211
|
|
|
$fields->addFieldToTab( |
|
|
|
|
|
|
212
|
|
|
"Root.Required", |
|
213
|
|
|
HeaderField::create('RequiredChecksHeader', 'Required Checks'), |
|
214
|
|
|
'Note' |
|
215
|
|
|
); |
|
216
|
|
|
$fields->addFieldToTab( |
|
217
|
|
|
"Root.NotRequired", |
|
218
|
|
|
HeaderField::create('UnrequiredChecksHeader', 'Optional Checks'), |
|
219
|
|
|
'Note' |
|
220
|
|
|
); |
|
221
|
|
|
$hasRequiredChecks = false; |
|
222
|
|
|
$hasUnrequiredChecks = false; |
|
223
|
|
|
$memberIsWhitelisted = $this->memberIsWhitelisted(); |
|
224
|
|
|
foreach ($checks as $fieldName => $details) { |
|
225
|
|
|
unset($allFields[$fieldName]); |
|
226
|
|
|
if (floatval($this->SubTotal) > floatval($details['SubTotalMin'])) { |
|
|
|
|
|
|
227
|
|
|
$hasRequiredChecks = true; |
|
228
|
|
|
$fields->addFieldToTab( |
|
229
|
|
|
'Root.Required', |
|
230
|
|
|
$myField = $fields->dataFieldByName($fieldName) |
|
231
|
|
|
); |
|
232
|
|
|
} else { |
|
233
|
|
|
$hasUnrequiredChecks = true; |
|
234
|
|
|
$fields->addFieldToTab( |
|
235
|
|
|
'Root.NotRequired', |
|
236
|
|
|
$myField = $fields->dataFieldByName($fieldName) |
|
237
|
|
|
); |
|
238
|
|
|
} |
|
239
|
|
|
$originalOptions = $myField->getSource(); |
|
240
|
|
|
if ($memberIsWhitelisted) { |
|
|
|
|
|
|
241
|
|
|
//.. |
|
242
|
|
|
} else { |
|
243
|
|
|
unset($originalOptions['Whitelisted Customer']); |
|
244
|
|
|
} |
|
245
|
|
|
if (! $this->$fieldName) { |
|
246
|
|
|
$this->$fieldName = 'To do'; |
|
247
|
|
|
} |
|
248
|
|
|
$fields->replaceField( |
|
249
|
|
|
$myField->ID(), |
|
|
|
|
|
|
250
|
|
|
OptionsetField::create( |
|
251
|
|
|
$myField->ID(), |
|
252
|
|
|
$details['Title'], |
|
253
|
|
|
$originalOptions |
|
254
|
|
|
) |
|
255
|
|
|
); |
|
256
|
|
|
if (! empty($details['Description'])) { |
|
257
|
|
|
$myField->setRighTitle($details['Description']); |
|
|
|
|
|
|
258
|
|
|
} |
|
259
|
|
|
} |
|
260
|
|
|
foreach ($allFields as $fieldToRemove) { |
|
261
|
|
|
$fields->removeByName($fieldToRemove); |
|
262
|
|
|
} |
|
263
|
|
|
if (! $hasUnrequiredChecks) { |
|
264
|
|
|
$fields->addFieldToTab( |
|
265
|
|
|
"Root.NotRequired", |
|
266
|
|
|
HeaderField::create('UnrequiredChecksHeader', 'There are no optional checks for this order.'), |
|
267
|
|
|
'Note' |
|
268
|
|
|
); |
|
269
|
|
|
} |
|
270
|
|
|
if (! $hasRequiredChecks) { |
|
271
|
|
|
$fields->addFieldToTab( |
|
272
|
|
|
"Root.Required", |
|
273
|
|
|
HeaderField::create('RequiredChecksHeader', 'There are no required checks for this order.'), |
|
274
|
|
|
'Note' |
|
275
|
|
|
); |
|
276
|
|
|
} |
|
277
|
|
|
if ($order) { |
|
278
|
|
|
$implementers = ClassInfo::implementorsOf('EcommerceSecurityLogInterface'); |
|
279
|
|
|
if ($implementers) { |
|
|
|
|
|
|
280
|
|
|
foreach ($implementers as $implementer) { |
|
281
|
|
|
$class = Injector::inst()->get($implementer); |
|
282
|
|
|
$fields->addFieldsToTab( |
|
283
|
|
|
"Root.Main", |
|
284
|
|
|
[ |
|
285
|
|
|
$class->getSecurityHeader(), |
|
286
|
|
|
$class->getSecuritySummary($order), |
|
287
|
|
|
] |
|
288
|
|
|
); |
|
289
|
|
|
|
|
290
|
|
|
if ($class->getSecurityLogTable($order)) { |
|
291
|
|
|
$fields->addFieldsToTab( |
|
292
|
|
|
"Root.".$class->getSecurityLogTableTabName(), |
|
293
|
|
|
[ |
|
294
|
|
|
$class->getSecurityHeader(), |
|
295
|
|
|
$class->getSecurityLogTable($order) |
|
296
|
|
|
] |
|
297
|
|
|
); |
|
298
|
|
|
} |
|
299
|
|
|
} |
|
300
|
|
|
} |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
$fields->removeFieldFromTab('Root.Main', 'AuthorID'); |
|
304
|
|
|
$fields->removeFieldFromTab('Root.Main', 'Title'); |
|
305
|
|
|
$fields->removeFieldFromTab('Root.Main', 'InternalUseOnly'); |
|
306
|
|
|
$fields->makeFieldReadonly('Risks'); |
|
307
|
|
|
$fields->makeFieldReadonly('SubTotal'); |
|
308
|
|
|
return $fields; |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
protected $warningMessages = array(); |
|
312
|
|
|
|
|
313
|
|
|
protected function collateRisks() |
|
314
|
|
|
{ |
|
315
|
|
|
$order = $this->Order(); |
|
|
|
|
|
|
316
|
|
|
$billingAddress = $order->BillingAddress(); |
|
317
|
|
|
$shippingAddress = $order->ShippingAddress(); |
|
318
|
|
|
$member = $this->orderMember(); |
|
|
|
|
|
|
319
|
|
|
$payments = $order->Payments(); |
|
320
|
|
|
$html = ''; |
|
321
|
|
|
|
|
322
|
|
|
$similarArray = array(); |
|
323
|
|
|
|
|
324
|
|
|
$daysAgo = $this->Config()->get('days_ago_to_check'); |
|
325
|
|
|
$timeFilter = array('Created:GreaterThan' => date('Y-m-d', strtotime('-'.$daysAgo.' days')).' 00:00:00'); |
|
326
|
|
|
|
|
327
|
|
|
|
|
328
|
|
|
//check emails from user |
|
329
|
|
|
$emailArray = array(); |
|
330
|
|
|
if ($member) { |
|
331
|
|
|
if ($member->Email) { |
|
332
|
|
|
$emailArray[] = $member->Email; |
|
333
|
|
|
if (OrderStatusLog_WhitelistCustomer::member_is_security_risk($member)) { |
|
334
|
|
|
$html .= '<p class="message bad">This customer has been marked as a security risk.</p>'; |
|
335
|
|
|
} else { |
|
336
|
|
|
if (OrderStatusLog_WhitelistCustomer::member_is_whitelisted($member)) { |
|
337
|
|
|
$html .= '<p class="warning good">This customer is whitelisted.</p>'; |
|
338
|
|
|
} else { |
|
339
|
|
|
$html .= '<p class="message warning">This customer is NOT whitelisted.</p>'; |
|
340
|
|
|
} |
|
341
|
|
|
} |
|
342
|
|
|
} |
|
343
|
|
|
} |
|
344
|
|
|
//are there any orders with the same Member.email in the last seven days... |
|
345
|
|
|
$otherOrders = Order::get_datalist_of_orders_with_submit_record() |
|
346
|
|
|
->filter( |
|
347
|
|
|
array_merge( |
|
348
|
|
|
array('MemberID' => $member->ID), |
|
349
|
|
|
$timeFilter |
|
350
|
|
|
) |
|
351
|
|
|
) |
|
352
|
|
|
->exclude(array('ID' => $order->ID)); |
|
353
|
|
View Code Duplication |
foreach ($otherOrders as $otherOrder) { |
|
|
|
|
|
|
354
|
|
|
if (!isset($similarArray[$otherOrder->ID])) { |
|
355
|
|
|
$similarArray[$otherOrder->ID] = array(); |
|
356
|
|
|
} |
|
357
|
|
|
$similarArray[$otherOrder->ID]["Email"] = $otherOrder; |
|
358
|
|
|
} |
|
359
|
|
|
//check emails from billing address |
|
360
|
|
|
$emailArray = array(); |
|
361
|
|
|
if ($billingAddress) { |
|
362
|
|
|
if ($billingAddress->Email) { |
|
363
|
|
|
$emailArray[] = $billingAddress->Email; |
|
364
|
|
|
} |
|
365
|
|
|
} |
|
366
|
|
|
//are there any orders with the same Billing.Email in the last seven days... |
|
367
|
|
|
$otherBillingAddresses = BillingAddress::get()->filter( |
|
368
|
|
|
array('Email' => $emailArray) + $timeFilter |
|
369
|
|
|
)->exclude(array('OrderID' => $order->ID)); |
|
370
|
|
View Code Duplication |
foreach ($otherBillingAddresses as $address) { |
|
|
|
|
|
|
371
|
|
|
$otherOrder = $address->Order(); |
|
372
|
|
|
if (!isset($similarArray[$otherOrder->ID])) { |
|
373
|
|
|
$similarArray[$otherOrder->ID] = array(); |
|
374
|
|
|
} |
|
375
|
|
|
$similarArray[$otherOrder->ID]["Email"] = $otherOrder; |
|
376
|
|
|
} |
|
377
|
|
|
//adding all emails to security checks |
|
378
|
|
|
$this->blacklistCheck($emailArray, 'EcommerceSecurityEmail'); |
|
379
|
|
|
|
|
380
|
|
|
|
|
381
|
|
|
//phones |
|
382
|
|
|
$phoneArray = array(); |
|
383
|
|
|
if ($billingAddress) { |
|
384
|
|
|
if ($billingAddress->Phone) { |
|
385
|
|
|
$phoneArray[] = $billingAddress->Phone; |
|
386
|
|
|
} |
|
387
|
|
|
} |
|
388
|
|
|
if ($shippingAddress) { |
|
389
|
|
|
if ($shippingAddress->ShippingPhone) { |
|
390
|
|
|
$phoneArray[] = $shippingAddress->ShippingPhone; |
|
391
|
|
|
} |
|
392
|
|
|
} |
|
393
|
|
|
//are there any orders with the same phone in the last xxx days... |
|
394
|
|
|
$otherBillingAddresses = BillingAddress::get()->filter( |
|
395
|
|
|
array('Phone' => $phoneArray) + $timeFilter |
|
396
|
|
|
)->exclude(array('OrderID' => $order->ID)); |
|
397
|
|
View Code Duplication |
foreach ($otherBillingAddresses as $address) { |
|
|
|
|
|
|
398
|
|
|
$otherOrder = $address->Order(); |
|
399
|
|
|
if ($otherOrder && $otherOrder->ID != $order->ID) { |
|
400
|
|
|
if (!isset($similarArray[$otherOrder->ID])) { |
|
401
|
|
|
$similarArray[$otherOrder->ID] = array(); |
|
402
|
|
|
} |
|
403
|
|
|
$similarArray[$otherOrder->ID]["Phone"] = $otherOrder; |
|
404
|
|
|
} |
|
405
|
|
|
} |
|
406
|
|
|
$otherShippingAddresses = ShippingAddress::get()->filter( |
|
407
|
|
|
array('ShippingPhone' => $phoneArray) + $timeFilter |
|
408
|
|
|
)->exclude(array('OrderID' => $order->ID)); |
|
409
|
|
View Code Duplication |
foreach ($otherShippingAddresses as $address) { |
|
|
|
|
|
|
410
|
|
|
$otherOrder = $address->Order(); |
|
411
|
|
|
if ($otherOrder && $otherOrder->ID != $order->ID) { |
|
412
|
|
|
if (!isset($similarArray[$otherOrder->ID])) { |
|
413
|
|
|
$similarArray[$otherOrder->ID] = array(); |
|
414
|
|
|
} |
|
415
|
|
|
$similarArray[$otherOrder->ID]["Phone"] = $otherOrder; |
|
416
|
|
|
} |
|
417
|
|
|
} |
|
418
|
|
|
//adding all emails to security checks |
|
419
|
|
|
$this->blacklistCheck($phoneArray, 'EcommerceSecurityPhone'); |
|
420
|
|
|
|
|
421
|
|
|
//addresses |
|
422
|
|
|
$addressArray = array(); |
|
423
|
|
|
if ($billingAddress) { |
|
424
|
|
|
if ($billingAddress->Address) { |
|
425
|
|
|
$addressArray[] = $billingAddress->Address; |
|
426
|
|
|
} |
|
427
|
|
|
} |
|
428
|
|
|
if ($shippingAddress) { |
|
429
|
|
|
if ($shippingAddress->ShippingAddress) { |
|
430
|
|
|
$addressArray[] = $shippingAddress->ShippingAddress; |
|
431
|
|
|
} |
|
432
|
|
|
} |
|
433
|
|
|
//are there any orders with the same address in the last xxx days... |
|
434
|
|
|
$otherBillingAddresses = BillingAddress::get()->filter( |
|
435
|
|
|
array('Address' => $addressArray) + $timeFilter |
|
436
|
|
|
)->exclude(array('OrderID' => $order->ID)); |
|
437
|
|
View Code Duplication |
foreach ($otherBillingAddresses as $address) { |
|
|
|
|
|
|
438
|
|
|
$otherOrder = $address->Order(); |
|
439
|
|
|
if ($otherOrder && $otherOrder->ID != $order->ID) { |
|
440
|
|
|
if (!isset($similarArray[$otherOrder->ID])) { |
|
441
|
|
|
$similarArray[$otherOrder->ID] = array(); |
|
442
|
|
|
} |
|
443
|
|
|
$similarArray[$otherOrder->ID]["Address"] = $otherOrder; |
|
444
|
|
|
} |
|
445
|
|
|
} |
|
446
|
|
|
$otherShippingAddresses = ShippingAddress::get() |
|
447
|
|
|
->filter( |
|
448
|
|
|
array('ShippingAddress' => $addressArray) + $timeFilter |
|
449
|
|
|
) |
|
450
|
|
|
->exclude(array('OrderID' => $order->ID)); |
|
451
|
|
View Code Duplication |
foreach ($otherShippingAddresses as $address) { |
|
|
|
|
|
|
452
|
|
|
$otherOrder = $address->Order(); |
|
453
|
|
|
if ($otherOrder && $otherOrder->ID != $order->ID) { |
|
454
|
|
|
if (!isset($similarArray[$otherOrder->ID])) { |
|
455
|
|
|
$similarArray[$otherOrder->ID] = array(); |
|
456
|
|
|
} |
|
457
|
|
|
$similarArray[$otherOrder->ID]["Address"] = $otherOrder; |
|
458
|
|
|
} |
|
459
|
|
|
} |
|
460
|
|
|
$this->blacklistCheck($addressArray, 'EcommerceSecurityAddress'); |
|
461
|
|
|
|
|
462
|
|
|
|
|
463
|
|
|
//IP |
|
464
|
|
|
$ipArray = array(); |
|
465
|
|
|
$ipProxyArray = array(); |
|
466
|
|
|
if ($payments) { |
|
467
|
|
|
foreach ($payments as $payment) { |
|
468
|
|
|
if (strlen($payment->IP) > 10) { |
|
469
|
|
|
$ipArray[] = $payment->IP; |
|
470
|
|
|
} |
|
471
|
|
|
if (strlen($payment->ProxyIP) > 10) { |
|
472
|
|
|
$ipProxyArray[] = $payment->ProxyIP; |
|
473
|
|
|
} |
|
474
|
|
|
} |
|
475
|
|
|
} |
|
476
|
|
View Code Duplication |
if (count($ipArray)) { |
|
|
|
|
|
|
477
|
|
|
//are there any orders with the same IP in the xxx seven days... |
|
478
|
|
|
$otherPayments = EcommercePayment::get()->filter( |
|
479
|
|
|
array('IP' => $ipArray) + $timeFilter |
|
480
|
|
|
)->exclude(array('OrderID' => $order->ID)); |
|
481
|
|
|
foreach ($otherPayments as $payment) { |
|
482
|
|
|
$otherOrder = $payment->Order(); |
|
483
|
|
|
if (!isset($similarArray[$otherOrder->ID])) { |
|
484
|
|
|
$similarArray[$otherOrder->ID] = array(); |
|
485
|
|
|
} |
|
486
|
|
|
$similarArray[$otherOrder->ID]["IP"] = $otherOrder; |
|
487
|
|
|
} |
|
488
|
|
|
$this->blacklistCheck($ipArray, 'EcommerceSecurityIP'); |
|
489
|
|
|
} |
|
490
|
|
View Code Duplication |
if (count($ipProxyArray)) { |
|
|
|
|
|
|
491
|
|
|
//are there any orders with the same Proxy in the xxx seven days... |
|
492
|
|
|
$otherPayments = EcommercePayment::get()->filter( |
|
493
|
|
|
array('ProxyIP' => $ipProxyArray) + $timeFilter |
|
494
|
|
|
)->exclude(array('OrderID' => $order->ID)); |
|
495
|
|
|
foreach ($otherPayments as $payment) { |
|
496
|
|
|
$otherOrder = $payment->Order(); |
|
497
|
|
|
if (!isset($similarArray[$otherOrder->ID])) { |
|
498
|
|
|
$similarArray[$otherOrder->ID] = array(); |
|
499
|
|
|
} |
|
500
|
|
|
$similarArray[$otherOrder->ID]["ProxyIP"] = $otherOrder; |
|
501
|
|
|
} |
|
502
|
|
|
$this->blacklistCheck($ipProxyArray, 'EcommerceSecurityProxyIP'); |
|
503
|
|
|
} |
|
504
|
|
|
|
|
505
|
|
|
|
|
506
|
|
|
if (count($this->warningMessages)) { |
|
507
|
|
|
$html .= ' |
|
508
|
|
|
<h4 style="color: red;">Blacklisted Details</h4> |
|
509
|
|
|
<ul class="SecurityCheckListOfRisks warnings" style="color: red;">'; |
|
510
|
|
|
foreach ($this->warningMessages as $warningMessage) { |
|
511
|
|
|
$html .= $warningMessage; |
|
512
|
|
|
} |
|
513
|
|
|
$html .= ' |
|
514
|
|
|
</ul>'; |
|
515
|
|
|
} else { |
|
516
|
|
|
$html .= '<p class="message good">No Blacklisted Data Present</p>'; |
|
517
|
|
|
} |
|
518
|
|
|
if (count($similarArray)) { |
|
519
|
|
|
$days = $this->Config()->get('days_ago_to_check'); |
|
520
|
|
|
$html .= ' |
|
521
|
|
|
<h4>Similar orders in the last '.$days.' days</h4> |
|
522
|
|
|
<ul class="SecurityCheckListOfRisks otherRisks">'; |
|
523
|
|
|
foreach ($similarArray as $orderID => $fields) { |
|
524
|
|
|
//we just loop this so we can get the order ... |
|
525
|
|
|
foreach ($fields as $tempOrder) { |
|
526
|
|
|
break; |
|
527
|
|
|
} |
|
528
|
|
|
$html .= ' |
|
529
|
|
|
<li><a href="'.$tempOrder->CMSEditLink().'">'.$tempOrder->getTitle().'</a>: with same '.implode(', and with same ', array_keys($fields)).'</li>'; |
|
|
|
|
|
|
530
|
|
|
} |
|
531
|
|
|
$html .= ' |
|
532
|
|
|
</ul>'; |
|
533
|
|
|
} else { |
|
534
|
|
|
$html .= '<p class="message good">No similar orders in the last '.$daysAgo.' days</p>'; |
|
535
|
|
|
} |
|
536
|
|
|
|
|
537
|
|
|
return $html; |
|
538
|
|
|
} |
|
539
|
|
|
|
|
540
|
|
|
public function getSecurityCleared() |
|
541
|
|
|
{ |
|
542
|
|
|
return DBField::create_field('Boolean', ($this->pass() ? true : false)); |
|
543
|
|
|
} |
|
544
|
|
|
|
|
545
|
|
|
/** |
|
546
|
|
|
* |
|
547
|
|
|
* |
|
548
|
|
|
* |
|
549
|
|
|
* @param Order $order |
|
|
|
|
|
|
550
|
|
|
* @return bool |
|
551
|
|
|
*/ |
|
552
|
|
|
public function pass() |
|
553
|
|
|
{ |
|
554
|
|
|
$order = $this->Order(); |
|
|
|
|
|
|
555
|
|
|
if (! $order) { |
|
556
|
|
|
return false; |
|
557
|
|
|
} |
|
558
|
|
|
$checks = $this->Config()->get('checks_required'); |
|
559
|
|
|
$fieldsAvailable = $this->stat('db'); |
|
560
|
|
|
foreach ($checks as $fieldName => $fieldDetails) { |
|
561
|
|
|
if (floatval($this->SubTotal) > floatval($fieldDetails['SubTotalMin'])) { |
|
|
|
|
|
|
562
|
|
|
if (! isset($fieldsAvailable[$fieldName])) { |
|
563
|
|
|
user_error('bad field ....'); |
|
564
|
|
|
} |
|
565
|
|
|
// there is a check that needs to be TRUE, but is not ... |
|
566
|
|
|
if ($this->$fieldName == 'Done' || $this->$fieldName == 'Whitelisted Customer') { |
|
|
|
|
|
|
567
|
|
|
} else { |
|
568
|
|
|
return false; |
|
569
|
|
|
} |
|
570
|
|
|
} |
|
571
|
|
|
} |
|
572
|
|
|
return true; |
|
573
|
|
|
} |
|
574
|
|
|
|
|
575
|
|
|
private static $_saved_already = 0; |
|
576
|
|
|
|
|
577
|
|
|
public function onAfterWrite() |
|
578
|
|
|
{ |
|
579
|
|
|
parent::onAfterWrite(); |
|
580
|
|
|
$order = $this->Order(); |
|
|
|
|
|
|
581
|
|
|
if (self::$_saved_already < 3) { |
|
582
|
|
|
self::$_saved_already++; |
|
583
|
|
|
if ($order && $order->exists()) { |
|
584
|
|
|
$this->SubTotal = $order->getSubTotal(); |
|
|
|
|
|
|
585
|
|
|
$this->Risks = $this->collateRisks(); |
|
|
|
|
|
|
586
|
|
|
$this->write(); |
|
587
|
|
|
} else { |
|
588
|
|
|
$this->SubTotal = 9999; |
|
|
|
|
|
|
589
|
|
|
$this->Risks = "Error"; |
|
|
|
|
|
|
590
|
|
|
$this->write(); |
|
591
|
|
|
} |
|
592
|
|
|
if ($this->memberIsWhitelisted()) { |
|
593
|
|
|
for ($i = 1; $i < 13; $i++) { |
|
594
|
|
|
$field = "Check".$i; |
|
595
|
|
|
$this->$field = 'Whitelisted Customer'; |
|
596
|
|
|
} |
|
597
|
|
|
$this->write(); |
|
598
|
|
|
} |
|
599
|
|
|
} |
|
600
|
|
|
if ($this->Bad) { |
|
|
|
|
|
|
601
|
|
|
foreach ($this->BlacklistItems() as $blacklistItem) { |
|
|
|
|
|
|
602
|
|
|
$blacklistItem->Status = 'Bad'; |
|
603
|
|
|
$blacklistItem->write(); |
|
604
|
|
|
} |
|
605
|
|
|
if ($order && $order->exists()) { |
|
606
|
|
|
$order->Archive(true); |
|
607
|
|
|
} |
|
608
|
|
|
if ($member = $this->orderMember()) { |
|
|
|
|
|
|
609
|
|
|
$member->IsWhitelisted = false; |
|
610
|
|
|
$member->IsSecurityRisk = true; |
|
611
|
|
|
$member->write(); |
|
612
|
|
|
} |
|
613
|
|
|
} |
|
614
|
|
|
} |
|
615
|
|
|
|
|
616
|
|
|
/** |
|
617
|
|
|
* |
|
618
|
|
|
* @param EcommerceSecurityBaseClass $obj |
|
619
|
|
|
* @return bool return true if the status of the object is `Bad` |
|
620
|
|
|
*/ |
|
621
|
|
|
protected function checkSecurityObject($obj) |
|
622
|
|
|
{ |
|
623
|
|
|
if ($obj->Status == 'Bad') { |
|
|
|
|
|
|
624
|
|
|
return false; |
|
625
|
|
|
} |
|
626
|
|
|
return true; |
|
627
|
|
|
} |
|
628
|
|
|
|
|
629
|
|
|
/** |
|
630
|
|
|
* caching variable only... |
|
631
|
|
|
* |
|
632
|
|
|
* @var null | bool |
|
633
|
|
|
*/ |
|
634
|
|
|
private $_memberIsWhitelisted = null; |
|
635
|
|
|
|
|
636
|
|
|
protected function memberIsWhitelisted() |
|
637
|
|
|
{ |
|
638
|
|
|
if ($this->_memberIsWhitelisted === null) { |
|
639
|
|
|
if ($member = $this->orderMember()) { |
|
|
|
|
|
|
640
|
|
|
$this->_memberIsWhitelisted = OrderStatusLog_WhitelistCustomer::member_is_whitelisted($member); |
|
|
|
|
|
|
641
|
|
|
} |
|
642
|
|
|
} |
|
643
|
|
|
return $this->_memberIsWhitelisted; |
|
644
|
|
|
} |
|
645
|
|
|
|
|
646
|
|
|
/** |
|
647
|
|
|
* |
|
648
|
|
|
* @return null | Member |
|
649
|
|
|
*/ |
|
650
|
|
|
protected function orderMember() |
|
651
|
|
|
{ |
|
652
|
|
|
$order = $this->Order(); |
|
|
|
|
|
|
653
|
|
|
if ($order && $order->exists()) { |
|
654
|
|
|
$member = $order->Member(); |
|
655
|
|
|
if ($member && $member->exists()) { |
|
656
|
|
|
return $member; |
|
657
|
|
|
} |
|
658
|
|
|
} |
|
659
|
|
|
} |
|
660
|
|
|
|
|
661
|
|
|
protected function blacklistCheck($arrayOfValues, $securityClass) |
|
662
|
|
|
{ |
|
663
|
|
|
//adding all emails to security checks |
|
664
|
|
|
foreach ($arrayOfValues as $value) { |
|
665
|
|
|
if ($value) { |
|
666
|
|
|
$obj = $securityClass::find_or_create(array("Title" => $value)); |
|
667
|
|
|
if ($obj->exists()) { |
|
668
|
|
|
$this->BlacklistItems()->add($obj); |
|
|
|
|
|
|
669
|
|
|
if ($obj->hasRisks()) { |
|
670
|
|
|
$title = $obj->i18n_singular_name(); |
|
671
|
|
|
$message = '<li><strong>'.$title.':</strong> '.$value.'<li>'; |
|
672
|
|
|
$this->warningMessages[$message] = $message; |
|
673
|
|
|
} |
|
674
|
|
|
} |
|
675
|
|
|
} |
|
676
|
|
|
} |
|
677
|
|
|
} |
|
678
|
|
|
} |
|
679
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.