1
|
|
|
<?php |
2
|
|
|
namespace Checkdomain\Comodo; |
3
|
|
|
|
4
|
|
|
use Checkdomain\Comodo\Model\Exception\AccountException; |
5
|
|
|
use Checkdomain\Comodo\Model\Exception\ArgumentException; |
6
|
|
|
use Checkdomain\Comodo\Model\Exception\CSRException; |
7
|
|
|
use Checkdomain\Comodo\Model\Exception\RequestException; |
8
|
|
|
use Checkdomain\Comodo\Model\Exception\UnknownApiException; |
9
|
|
|
use Checkdomain\Comodo\Model\Exception\UnknownException; |
10
|
|
|
|
11
|
|
|
use Checkdomain\Comodo\Model\Result\AutoApplyResult; |
12
|
|
|
use Checkdomain\Comodo\Model\Result\AutoReplaceResult; |
13
|
|
|
use Checkdomain\Comodo\Model\Result\CollectSslResult; |
14
|
|
|
use Checkdomain\Comodo\Model\Result\GetDCVEMailAddressListResult; |
15
|
|
|
use Checkdomain\Comodo\Model\Result\GetMDCDomainDetailsResult; |
16
|
|
|
use Checkdomain\Comodo\Model\Result\UpdateUserEvClickThroughResult; |
17
|
|
|
use Checkdomain\Comodo\Model\Result\SslCheckerResult; |
18
|
|
|
use Checkdomain\Comodo\Model\Result\WebHostReportResult; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class Util |
22
|
|
|
* Provides functions to communicate with the Comodo API,requires an Account object, given to the Communication-adapter |
23
|
|
|
*/ |
24
|
|
|
class Util |
25
|
|
|
{ |
26
|
|
|
const AUTO_REFUND_REASON_VALIDATION = 1; |
27
|
|
|
const AUTO_REFUND_REASON_INACTIVE = 2; |
28
|
|
|
const AUTO_REFUND_REASON_TYPE = 3; |
29
|
|
|
const AUTO_REFUND_REASON_BRAND = 4; |
30
|
|
|
const AUTO_REFUND_REASON_REJECTED = 5; |
31
|
|
|
const AUTO_REFUND_REASON_MALWARE = 6; |
32
|
|
|
const AUTO_REFUND_REASON_PHISHING = 7; |
33
|
|
|
const AUTO_REFUND_REASON_SAFE_BROWSING = 8; |
34
|
|
|
const AUTO_REFUND_REASON_AUTHORITY = 9; |
35
|
|
|
const AUTO_REFUND_REASON_PRICE = 10; |
36
|
|
|
const AUTO_REFUND_REASON_OTHER = 11; |
37
|
|
|
|
38
|
|
|
const COMODO_AUTO_REFUND_URL = 'https://secure.comodo.net/products/!AutoRefund'; |
39
|
|
|
const COMODO_AUTO_APPLY_URL = 'https://secure.comodo.net/products/!AutoApplySSL'; |
40
|
|
|
const COMODO_AUTO_REVOKE_URL = 'https://secure.comodo.net/products/!AutoRevokeSSL'; |
41
|
|
|
const COMODO_DCV_MAIL_URL = 'https://secure.comodo.net/products/!GetDCVEmailAddressList'; |
42
|
|
|
const COMODO_DCV_RESEND_URL = 'https://secure.comodo.net/products/!ResendDCVEmail'; |
43
|
|
|
const COMODO_AUTO_UPDATE_DCV_URL = 'https://secure.comodo.net/products/!AutoUpdateDCV'; |
44
|
|
|
const COMODO_PROVIDE_EV_DETAILS_URL = 'https://secure.comodo.net/products/!ProvideEVDetails'; |
45
|
|
|
const COMODO_MDC_DOMAIN_DETAILS_URL = 'https://secure.comodo.net/products/!GetMDCDomainDetails'; |
46
|
|
|
const COMODO_AUTO_REPLACE_URL = 'https://secure.comodo.net/products/!AutoReplaceSSL'; |
47
|
|
|
const COMODO_COLLECT_SSL_URL = 'https://secure.comodo.net/products/download/CollectSSL'; |
48
|
|
|
const COMODO_UPDATE_USER_EV_CLICK_THROUGH = 'https://secure.comodo.net/products/!UpdateUserEvClickThrough'; |
49
|
|
|
const COMODO_WEB_HOST_REPORT = 'https://secure.comodo.net/products/!WebHostReport'; |
50
|
|
|
const COMODO_SSLCHECKER = 'https://secure.comodo.com/sslchecker'; |
51
|
|
|
|
52
|
|
|
const COMODO_DCV_CODE_URL = 'https://secure.comodo.net/products/EnterDCVCode2'; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var CommunicationAdapter |
56
|
|
|
*/ |
57
|
|
|
protected $communicationAdapter; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var ImapAdapter |
61
|
|
|
*/ |
62
|
|
|
protected $imapAdapter; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var ImapHelper |
66
|
|
|
*/ |
67
|
|
|
protected $imapHelper; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Constructs the Util with a communicationAdapter |
71
|
|
|
* |
72
|
|
|
* @param CommunicationAdapter|null $communicationAdapter |
73
|
|
|
* @param ImapAdapter|null $imapAdapter |
74
|
|
|
* @param ImapHelper|null $imapHelper |
75
|
|
|
*/ |
76
|
|
|
public function __construct(CommunicationAdapter $communicationAdapter, ImapAdapter $imapAdapter, ImapHelper $imapHelper) |
77
|
|
|
{ |
78
|
|
|
$this->communicationAdapter = $communicationAdapter; |
79
|
|
|
$this->imapAdapter = $imapAdapter; |
80
|
|
|
$this->imapHelper = $imapHelper; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return CommunicationAdapter |
86
|
|
|
*/ |
87
|
|
|
public function getCommunicationAdapter() |
88
|
|
|
{ |
89
|
|
|
return $this->communicationAdapter; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param CommunicationAdapter $communicationAdapter |
94
|
|
|
* |
95
|
|
|
* @return Util |
96
|
|
|
*/ |
97
|
|
|
public function setCommunicationAdapter(CommunicationAdapter $communicationAdapter) |
98
|
|
|
{ |
99
|
|
|
$this->communicationAdapter = $communicationAdapter; |
100
|
|
|
|
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return ImapHelper |
106
|
|
|
*/ |
107
|
|
|
public function getImapHelper() |
108
|
|
|
{ |
109
|
|
|
return $this->imapHelper; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param ImapHelper $imapHelper |
114
|
|
|
* |
115
|
|
|
* @return Util |
116
|
|
|
*/ |
117
|
|
|
public function setImapHelper(ImapHelper $imapHelper) |
118
|
|
|
{ |
119
|
|
|
$this->imapHelper = $imapHelper; |
120
|
|
|
|
121
|
|
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return ImapAdapter |
126
|
|
|
*/ |
127
|
|
|
public function getImapAdapter() |
128
|
|
|
{ |
129
|
|
|
return $this->imapAdapter; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param ImapAdapter $imapAdapter |
134
|
|
|
* |
135
|
|
|
* @return Util |
136
|
|
|
*/ |
137
|
|
|
public function setImapAdapter(ImapAdapter $imapAdapter) |
138
|
|
|
{ |
139
|
|
|
$this->imapAdapter = $imapAdapter; |
140
|
|
|
|
141
|
|
|
return $this; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Refunds a ordered certificate |
146
|
|
|
* |
147
|
|
|
* @param array $params |
148
|
|
|
* |
149
|
|
|
* @return bool |
150
|
|
|
* |
151
|
|
|
* @throws AccountException |
152
|
|
|
* @throws ArgumentException |
153
|
|
|
* @throws CSRException |
154
|
|
|
* @throws RequestException |
155
|
|
|
* @throws UnknownApiException |
156
|
|
|
* @throws UnknownException |
157
|
|
|
*/ |
158
|
|
|
public function autoRefund(array $params) |
159
|
|
|
{ |
160
|
|
|
if (false === isset($params['refundReasonCode'])) { |
161
|
|
|
$params['refundReasonCode'] = 11; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
$response = $this |
165
|
|
|
->communicationAdapter |
166
|
|
|
->sendToApi( |
167
|
|
|
self::COMODO_AUTO_REFUND_URL, |
168
|
|
|
$params, |
169
|
|
|
CommunicationAdapter::RESPONSE_URL_ENCODED |
170
|
|
|
); |
171
|
|
|
|
172
|
|
|
if ($response['errorCode'] == 0) { |
173
|
|
|
return true; |
174
|
|
|
} else { |
175
|
|
|
throw $this->createException($response); |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Function apply for a certificate |
181
|
|
|
* |
182
|
|
|
* See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/ |
183
|
|
|
* |
184
|
|
|
* @param array $params |
185
|
|
|
* |
186
|
|
|
* @return AutoApplyResult |
187
|
|
|
* @throws Model\Exception\AccountException |
188
|
|
|
* @throws Model\Exception\ArgumentException |
189
|
|
|
* @throws Model\Exception\CSRException |
190
|
|
|
* @throws Model\Exception\RequestException |
191
|
|
|
* @throws Model\Exception\UnknownApiException |
192
|
|
|
* @throws Model\Exception\UnknownException |
193
|
|
|
*/ |
194
|
|
|
public function autoApplySSL(array $params) |
195
|
|
|
{ |
196
|
|
|
// Two choices, we want url-encoded |
197
|
|
|
$params['responseFormat'] = CommunicationAdapter::RESPONSE_URL_ENCODED; |
198
|
|
|
$params['showCertificateID'] = 'Y'; |
199
|
|
|
|
200
|
|
|
// Send request |
201
|
|
|
$arr = $this |
202
|
|
|
->communicationAdapter |
203
|
|
|
->sendToApi(self::COMODO_AUTO_APPLY_URL, $params, CommunicationAdapter::RESPONSE_URL_ENCODED); |
204
|
|
|
|
205
|
|
|
// Successful |
206
|
|
|
if ($arr['errorCode'] == 1 || $arr['errorCode'] == 0) { |
207
|
|
|
$result = new AutoApplyResult(); |
208
|
|
|
|
209
|
|
|
if ($arr['errorCode'] == 0) { |
210
|
|
|
$paid = true; |
211
|
|
|
} else { |
212
|
|
|
$paid = false; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
$result |
216
|
|
|
->setPaid($paid) |
217
|
|
|
->setCertificateID($arr['certificateID']) |
218
|
|
|
->setExpectedDeliveryTime($arr['expectedDeliveryTime']) |
219
|
|
|
->setOrderNumber($arr['orderNumber']) |
220
|
|
|
->setTotalCost($arr['totalCost']) |
221
|
|
|
->setRequestQuery($arr['requestQuery']); |
222
|
|
|
|
223
|
|
|
if (isset($arr['uniqueValue'])) { |
224
|
|
|
$result->setUniqueValue($arr['uniqueValue']); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
return $result; |
228
|
|
|
} else { |
229
|
|
|
throw $this->createException($arr); |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @param array $params |
235
|
|
|
* |
236
|
|
|
* @return UpdateUserEvClickThroughResult |
237
|
|
|
* @throws AccountException |
238
|
|
|
* @throws ArgumentException |
239
|
|
|
* @throws CSRException |
240
|
|
|
* @throws RequestException |
241
|
|
|
* @throws UnknownApiException |
242
|
|
|
* @throws UnknownException |
243
|
|
|
*/ |
244
|
|
|
public function updateUserEvClickThrough(array $params) |
245
|
|
|
{ |
246
|
|
|
// Send request |
247
|
|
|
$arr = $this |
248
|
|
|
->communicationAdapter |
249
|
|
|
->sendToApi( |
250
|
|
|
self::COMODO_UPDATE_USER_EV_CLICK_THROUGH, |
251
|
|
|
$params, |
252
|
|
|
CommunicationAdapter::RESPONSE_URL_ENCODED |
253
|
|
|
); |
254
|
|
|
|
255
|
|
|
// Successful |
256
|
|
|
if ($arr['errorCode'] == 0) { |
257
|
|
|
$result = new UpdateUserEvClickThroughResult(); |
258
|
|
|
|
259
|
|
|
$result |
260
|
|
|
->setStatus($arr['status']); |
261
|
|
|
|
262
|
|
|
return $result; |
263
|
|
|
} else { |
264
|
|
|
throw $this->createException($arr); |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* Function update for a certificate |
270
|
|
|
* |
271
|
|
|
* See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/ |
272
|
|
|
* |
273
|
|
|
* @param array $params |
274
|
|
|
* |
275
|
|
|
* @return AutoReplaceResult |
276
|
|
|
* @throws Model\Exception\AccountException |
277
|
|
|
* @throws Model\Exception\ArgumentException |
278
|
|
|
* @throws Model\Exception\CSRException |
279
|
|
|
* @throws Model\Exception\RequestException |
280
|
|
|
* @throws Model\Exception\UnknownApiException |
281
|
|
|
* @throws Model\Exception\UnknownException |
282
|
|
|
*/ |
283
|
|
|
public function autoReplaceSSL(array $params) |
284
|
|
|
{ |
285
|
|
|
// Two choices, we want url-encoded |
286
|
|
|
$params['responseFormat'] = CommunicationAdapter::RESPONSE_URL_ENCODED; |
287
|
|
|
|
288
|
|
|
// Send request |
289
|
|
|
$arr = $this |
290
|
|
|
->communicationAdapter |
291
|
|
|
->sendToApi( |
292
|
|
|
self::COMODO_AUTO_REPLACE_URL, |
293
|
|
|
$params, |
294
|
|
|
CommunicationAdapter::RESPONSE_URL_ENCODED |
295
|
|
|
); |
296
|
|
|
|
297
|
|
|
// Successful |
298
|
|
|
if ($arr['errorCode'] == 0) { |
299
|
|
|
$result = new AutoReplaceResult(); |
300
|
|
|
|
301
|
|
|
$result |
302
|
|
|
->setCertificateID($arr['certificateID']) |
303
|
|
|
->setExpectedDeliveryTime($arr['expectedDeliveryTime']); |
304
|
|
|
|
305
|
|
|
if (isset($arr['uniqueValue'])) { |
306
|
|
|
$result->setUniqueValue($arr['uniqueValue']); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
return $result; |
310
|
|
|
} else { |
311
|
|
|
throw $this->createException($arr); |
312
|
|
|
} |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* Function to revoke order |
317
|
|
|
* |
318
|
|
|
* See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/ |
319
|
|
|
* |
320
|
|
|
* @param array $params |
321
|
|
|
* |
322
|
|
|
* @return bool |
323
|
|
|
* @throws Model\Exception\AccountException |
324
|
|
|
* @throws Model\Exception\ArgumentException |
325
|
|
|
* @throws Model\Exception\RequestException |
326
|
|
|
* @throws Model\Exception\UnknownApiException |
327
|
|
|
* @throws Model\Exception\UnknownException |
328
|
|
|
*/ |
329
|
|
|
public function autoRevokeSSL(array $params) |
330
|
|
|
{ |
331
|
|
|
// Two choices, we want url-encoded |
332
|
|
|
$params['responseFormat'] = CommunicationAdapter::RESPONSE_URL_ENCODED; |
333
|
|
|
|
334
|
|
|
return $this->sendBooleanRequest( |
335
|
|
|
self::COMODO_AUTO_REVOKE_URL, |
336
|
|
|
$params, |
337
|
|
|
CommunicationAdapter::RESPONSE_URL_ENCODED |
338
|
|
|
); |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* Function to auto update dcv |
343
|
|
|
* |
344
|
|
|
* See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/ |
345
|
|
|
* |
346
|
|
|
* @param array $params |
347
|
|
|
* |
348
|
|
|
* @return bool |
349
|
|
|
* @throws Model\Exception\AccountException |
350
|
|
|
* @throws Model\Exception\ArgumentException |
351
|
|
|
* @throws Model\Exception\RequestException |
352
|
|
|
* @throws Model\Exception\UnknownApiException |
353
|
|
|
* @throws Model\Exception\UnknownException |
354
|
|
|
*/ |
355
|
|
|
public function autoUpdateDCV(array $params) |
356
|
|
|
{ |
357
|
|
|
return $this->sendBooleanRequest( |
358
|
|
|
self::COMODO_AUTO_UPDATE_DCV_URL, |
359
|
|
|
$params, |
360
|
|
|
CommunicationAdapter::RESPONSE_URL_ENCODED |
361
|
|
|
); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* Function to get details of a certificate |
366
|
|
|
* |
367
|
|
|
* See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/ |
368
|
|
|
* |
369
|
|
|
* @param array $params |
370
|
|
|
* |
371
|
|
|
* @return CollectSslResult |
372
|
|
|
* @throws Model\Exception\AccountException |
373
|
|
|
* @throws Model\Exception\ArgumentException |
374
|
|
|
* @throws Model\Exception\CSRException |
375
|
|
|
* @throws Model\Exception\RequestException |
376
|
|
|
* @throws Model\Exception\UnknownApiException |
377
|
|
|
* @throws Model\Exception\UnknownException |
378
|
|
|
*/ |
379
|
|
|
public function collectSsl(array $params) |
380
|
|
|
{ |
381
|
|
|
// Not decode the following indexes |
382
|
|
|
$notDecode = array('caCertificate', 'certificate', 'netscapeCertificateSequence', 'zipFile'); |
383
|
|
|
|
384
|
|
|
// Force threating as array |
385
|
|
|
$forceArray = array('caCertificate'); |
386
|
|
|
|
387
|
|
|
// Two choices, we want url-encoded |
388
|
|
|
$params['responseFormat'] = CommunicationAdapter::RESPONSE_URL_ENCODED; |
389
|
|
|
|
390
|
|
|
// Send request |
391
|
|
|
$arr = $this |
392
|
|
|
->communicationAdapter |
393
|
|
|
->sendToApi( |
394
|
|
|
self::COMODO_COLLECT_SSL_URL, |
395
|
|
|
$params, |
396
|
|
|
CommunicationAdapter::RESPONSE_URL_ENCODED, |
397
|
|
|
$notDecode, |
398
|
|
|
$forceArray |
399
|
|
|
); |
400
|
|
|
|
401
|
|
|
// Successful |
402
|
|
|
if ($arr['errorCode'] >= 0) { |
403
|
|
|
$result = new CollectSslResult(); |
404
|
|
|
|
405
|
|
|
$this->fill($result, $arr, array('notBefore', 'notAfter')); |
|
|
|
|
406
|
|
|
|
407
|
|
|
/* |
408
|
|
|
* Comodo does not provide these data, when not a EV certificate (Bug?). So we fill this manually to "not required". |
409
|
|
|
* |
410
|
|
|
* https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/CollectSSL%20v1.17.pdf |
411
|
|
|
*/ |
412
|
|
|
if (!isset($arr['evClickThroughStatus'])) { |
413
|
|
|
$result->setEvClickThroughStatus(-1); |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
if (!isset($arr['brandValStatus'])) { |
417
|
|
|
$result->setBrandValStatus(-1); |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
return $result; |
421
|
|
|
} else { |
422
|
|
|
throw $this->createException($arr); |
423
|
|
|
} |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* Function to resend the DCV Email |
428
|
|
|
* |
429
|
|
|
* See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/ |
430
|
|
|
* |
431
|
|
|
* @param array $params |
432
|
|
|
* |
433
|
|
|
* @return bool |
434
|
|
|
* @throws Model\Exception\AccountException |
435
|
|
|
* @throws Model\Exception\ArgumentException |
436
|
|
|
* @throws Model\Exception\RequestException |
437
|
|
|
* @throws Model\Exception\UnknownApiException |
438
|
|
|
* @throws Model\Exception\UnknownException |
439
|
|
|
*/ |
440
|
|
|
public function resendDCVEMail(array $params) |
441
|
|
|
{ |
442
|
|
|
return $this |
443
|
|
|
->sendBooleanRequest( |
444
|
|
|
self::COMODO_DCV_RESEND_URL, |
445
|
|
|
$params, |
446
|
|
|
CommunicationAdapter::RESPONSE_URL_ENCODED |
447
|
|
|
); |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* @param array $params |
452
|
|
|
* |
453
|
|
|
* @deprecated Comodo support told this function doesn't have any effect anymore |
454
|
|
|
* |
455
|
|
|
* @return bool |
456
|
|
|
* @throws Model\Exception\AccountException |
457
|
|
|
* @throws Model\Exception\ArgumentException |
458
|
|
|
* @throws Model\Exception\CSRException |
459
|
|
|
* @throws Model\Exception\RequestException |
460
|
|
|
* @throws Model\Exception\UnknownApiException |
461
|
|
|
* @throws Model\Exception\UnknownException |
462
|
|
|
*/ |
463
|
|
|
public function provideEVDetails(array $params) |
464
|
|
|
{ |
465
|
|
|
return $this->sendBooleanRequest( |
466
|
|
|
self::COMODO_PROVIDE_EV_DETAILS_URL, |
467
|
|
|
$params, |
468
|
|
|
CommunicationAdapter::RESPONSE_URL_ENCODED |
469
|
|
|
); |
470
|
|
|
} |
471
|
|
|
|
472
|
|
|
/** |
473
|
|
|
* Function to get the DCV e-mail address-list |
474
|
|
|
* |
475
|
|
|
* See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/ |
476
|
|
|
* |
477
|
|
|
* @param array $params |
478
|
|
|
* |
479
|
|
|
* @return GetDCVEMailAddressListResult |
480
|
|
|
* @throws AccountException |
481
|
|
|
* @throws ArgumentException |
482
|
|
|
* @throws CSRException |
483
|
|
|
* @throws RequestException |
484
|
|
|
* @throws UnknownApiException |
485
|
|
|
* @throws UnknownException |
486
|
|
|
*/ |
487
|
|
|
public function getDCVEMailAddressList(array $params) |
488
|
|
|
{ |
489
|
|
|
// Force threating as array |
490
|
|
|
$forceArray = array('whois_email', 'level2_email', 'level3_email'); |
491
|
|
|
|
492
|
|
|
// Response is always new line encoded |
493
|
|
|
$responseArray = $this |
494
|
|
|
->communicationAdapter |
495
|
|
|
->sendToApi( |
496
|
|
|
self::COMODO_DCV_MAIL_URL, |
497
|
|
|
$params, |
498
|
|
|
CommunicationAdapter::RESPONSE_NEW_LINE, |
499
|
|
|
null, |
500
|
|
|
$forceArray |
501
|
|
|
); |
502
|
|
|
|
503
|
|
|
if ($responseArray['errorCode'] == 0) { |
504
|
|
|
$result = new GetDCVEMailAddressListResult(); |
505
|
|
|
|
506
|
|
|
if (isset($responseArray['whois_email'][0]) && $responseArray['whois_email'][0] == 'none') { |
507
|
|
|
unset($responseArray['whois_email'][0]); |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
$result |
511
|
|
|
->setDomainName($responseArray['domain_name']) |
512
|
|
|
->setWhoisEmail($responseArray['whois_email']) |
513
|
|
|
->setLevel2Emails($responseArray['level2_email']) |
514
|
|
|
->setRequestQuery($responseArray['requestQuery']); |
515
|
|
|
|
516
|
|
|
if (isset($responseArray['level3_email'])) { |
517
|
|
|
$result->setLevel3Emails($responseArray['level3_email']); |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
return $result; |
521
|
|
|
} else { |
522
|
|
|
throw $this->createException($responseArray); |
523
|
|
|
} |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
/** |
527
|
|
|
* Function to get details of a order-number (this API support just one domain) |
528
|
|
|
* |
529
|
|
|
* https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/GetMDCDomainDetails%20v1.00.pdf |
530
|
|
|
* |
531
|
|
|
* @param array $params |
532
|
|
|
* |
533
|
|
|
* @return GetMDCDomainDetailsResult |
534
|
|
|
* |
535
|
|
|
* @throws Model\Exception\AccountException |
536
|
|
|
* @throws Model\Exception\ArgumentException |
537
|
|
|
* @throws Model\Exception\CSRException |
538
|
|
|
* @throws Model\Exception\RequestException |
539
|
|
|
* @throws Model\Exception\UnknownApiException |
540
|
|
|
* @throws Model\Exception\UnknownException |
541
|
|
|
*/ |
542
|
|
View Code Duplication |
public function getMDCDomainDetails(array $params) |
|
|
|
|
543
|
|
|
{ |
544
|
|
|
// Response is always new line encoded |
545
|
|
|
$responseArray = $this |
546
|
|
|
->communicationAdapter |
547
|
|
|
->sendToApi( |
548
|
|
|
self::COMODO_MDC_DOMAIN_DETAILS_URL, |
549
|
|
|
$params, |
550
|
|
|
CommunicationAdapter::RESPONSE_URL_ENCODED |
551
|
|
|
); |
552
|
|
|
|
553
|
|
|
if ($responseArray['errorCode'] == 0) { |
554
|
|
|
$result = new GetMDCDomainDetailsResult(); |
555
|
|
|
|
556
|
|
|
$result |
557
|
|
|
->setDomainName($responseArray['1_domainName']) |
558
|
|
|
->setDcvMethod($responseArray['1_dcvMethod']) |
559
|
|
|
->setDcvStatus($responseArray['1_dcvStatus']); |
560
|
|
|
|
561
|
|
|
return $result; |
562
|
|
|
} else { |
563
|
|
|
throw $this->createException($responseArray); |
564
|
|
|
} |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
/** |
568
|
|
|
* Function to do a sslcheck |
569
|
|
|
* |
570
|
|
|
* https://secure.comodo.net/api/pdf/latest/SSLChecker.pdf |
571
|
|
|
* |
572
|
|
|
* @param array $params |
573
|
|
|
* |
574
|
|
|
* @return GetMDCDomainDetailsResult |
575
|
|
|
* |
576
|
|
|
* @throws Model\Exception\AccountException |
577
|
|
|
* @throws Model\Exception\ArgumentException |
578
|
|
|
* @throws Model\Exception\CSRException |
579
|
|
|
* @throws Model\Exception\RequestException |
580
|
|
|
* @throws Model\Exception\UnknownApiException |
581
|
|
|
* @throws Model\Exception\UnknownException |
582
|
|
|
*/ |
583
|
|
|
public function sslChecker(array $params) |
584
|
|
|
{ |
585
|
|
|
// Response is always new line encoded |
586
|
|
|
$responseArray = $this |
587
|
|
|
->communicationAdapter |
588
|
|
|
->sendToApi( |
589
|
|
|
self::COMODO_SSLCHECKER, |
590
|
|
|
$params, |
591
|
|
|
CommunicationAdapter::RESPONSE_URL_ENCODED |
592
|
|
|
); |
593
|
|
|
|
594
|
|
|
if ($responseArray['error_code'] == 0) { |
595
|
|
|
$result = new SslCheckerResult(); |
596
|
|
|
|
597
|
|
|
$result |
598
|
|
|
->setServerUrl($responseArray['server_url']) |
599
|
|
|
->setServerDomainIsIDN($responseArray['server_domain_isIDN']) |
600
|
|
|
->setServerDomainUtf8($responseArray['server_domain_utf8']) |
601
|
|
|
->setServerDomainAce($responseArray['server_domain_ace']) |
602
|
|
|
->setServerIp($responseArray['server_ip']) |
603
|
|
|
->setServerPort($responseArray['server_port']) |
604
|
|
|
->setServerSoftware($responseArray['server_software']) |
605
|
|
|
->setCertNotBeforeFromUnixTimestamp($responseArray['cert_notBefore']) |
606
|
|
|
->setCertNotAfterFromUnixTimestamp($responseArray['cert_notAfter']) |
607
|
|
|
->setCertValidityNotBefore($responseArray['cert_validity_notBefore']) |
608
|
|
|
->setCertValidityNotAfter($responseArray['cert_validity_notAfter']) |
609
|
|
|
->setCertKeyAlgorithm($responseArray['cert_key_algorithm']) |
610
|
|
|
->setCertKeySize($responseArray['cert_key_size']) |
611
|
|
|
->setCertSubjectCN($responseArray['cert_subject_DN']) |
612
|
|
|
->setCertSubjectCN($responseArray['cert_subject_CN']) |
613
|
|
|
->setCertSubjectOU($responseArray['cert_subject_OU']) |
614
|
|
|
->setCertSubjectOrganization($responseArray['cert_subject_O']) |
615
|
|
|
->setCertSubjectStreetAddress1($responseArray['cert_subject_streetAddress_1']) |
616
|
|
|
->setCertSubjectStreetAddress2($responseArray['cert_subject_streetAddress_2']) |
617
|
|
|
->setCertSubjectStreetAddress3($responseArray['cert_subject_streetAddress_3']) |
618
|
|
|
->setCertSubjectLocality($responseArray['cert_subject_L']) |
619
|
|
|
->setCertSubjectState($responseArray['cert_subject_S']) |
620
|
|
|
->setCertSubjectPostalCode($responseArray['cert_subject_postalCode']) |
621
|
|
|
->setCertSubjectCountry($responseArray['cert_subject_C']) |
622
|
|
|
->setCertIsMultiDomain($responseArray['cert_isMultiDomain']) |
623
|
|
|
->setCertIsWildcard($responseArray['cert_isWildcard']) |
624
|
|
|
->setCertIssuerDN($responseArray['cert_issuer_DN']) |
625
|
|
|
->setCertIssuerCN($responseArray['cert_issuer_CN']) |
626
|
|
|
->setCertIssuerOrganization($responseArray['cert_issuer_O']) |
627
|
|
|
->setCertIssuerOrganization($responseArray['cert_issuer_C']) |
628
|
|
|
->setCertIssuerBrand($responseArray['cert_issuer_brand']) |
629
|
|
|
->setCertPolicyOID($responseArray['cert_policyOID']) |
630
|
|
|
->setCertValidation($responseArray['cert_validation']); |
631
|
|
|
|
632
|
|
|
return $result; |
633
|
|
|
} else { |
634
|
|
|
throw $this->createException($responseArray); |
635
|
|
|
} |
636
|
|
|
} |
637
|
|
|
|
638
|
|
|
/** |
639
|
|
|
* Function to call WebHostReport api |
640
|
|
|
* |
641
|
|
|
* https://secure.comodo.net/products/!WebHostReport |
642
|
|
|
* |
643
|
|
|
* Details for params usage: |
644
|
|
|
* https://secure.comodo.net/api/pdf/latest/WebHostReport.pdf |
645
|
|
|
* |
646
|
|
|
* @param array $params |
647
|
|
|
* |
648
|
|
|
* @return WebHostReportResult |
649
|
|
|
* |
650
|
|
|
* @throws Model\Exception\AccountException |
651
|
|
|
* @throws Model\Exception\ArgumentException |
652
|
|
|
* @throws Model\Exception\CSRException |
653
|
|
|
* @throws Model\Exception\RequestException |
654
|
|
|
* @throws Model\Exception\UnknownApiException |
655
|
|
|
* @throws Model\Exception\UnknownException |
656
|
|
|
*/ |
657
|
|
View Code Duplication |
public function webHostReport(array $params) { |
|
|
|
|
658
|
|
|
|
659
|
|
|
if (empty($params['lastResultNo'])) { |
660
|
|
|
$params['lastResultNo'] = 10; |
661
|
|
|
} |
662
|
|
|
|
663
|
|
|
// Response is always new line encoded |
664
|
|
|
$responseArray = $this |
665
|
|
|
->communicationAdapter |
666
|
|
|
->sendToApi( |
667
|
|
|
self::COMODO_WEB_HOST_REPORT, |
668
|
|
|
$params, |
669
|
|
|
CommunicationAdapter::RESPONSE_URL_ENCODED |
670
|
|
|
); |
671
|
|
|
if ($responseArray['error_code'] == 0) { |
672
|
|
|
$result = new WebHostReportResult(); |
673
|
|
|
$result->importEntries($responseArray); |
|
|
|
|
674
|
|
|
return $result; |
675
|
|
|
} else { |
676
|
|
|
throw $this->createException($responseArray); |
677
|
|
|
} |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
/** |
681
|
|
|
* Function to enter the DCV code, coming from DCV E-Mail |
682
|
|
|
* |
683
|
|
|
* @param array $params |
684
|
|
|
* |
685
|
|
|
* @return bool |
686
|
|
|
* @throws Model\Exception\UnknownException |
687
|
|
|
* @throws Model\Exception\ArgumentException |
688
|
|
|
*/ |
689
|
|
|
public function enterDCVCode(array $params) |
690
|
|
|
{ |
691
|
|
|
// Check parameters |
692
|
|
|
if (!isset($params['dcvCode'])) { |
693
|
|
|
throw new ArgumentException(-3, 'Please provide an order-number', 'dcvCode', ''); |
694
|
|
|
} |
695
|
|
|
|
696
|
|
|
if (!isset($params['orderNumber'])) { |
697
|
|
|
throw new ArgumentException(-3, 'Please provide an order-number', 'orderNumber', ''); |
698
|
|
|
} |
699
|
|
|
|
700
|
|
|
// this is not a official request, so we need to use the website |
701
|
|
|
$responseString = $this |
702
|
|
|
->communicationAdapter |
703
|
|
|
->sendToWebsite(self::COMODO_DCV_CODE_URL, $params); |
704
|
|
|
|
705
|
|
|
// Decode answer from website |
706
|
|
|
if (stristr($responseString, 'You have entered the correct Domain Control Validation code') !== false) { |
707
|
|
|
return true; |
708
|
|
|
} elseif (stristr($responseString, 'the certificate has already been issued') !== false) { |
709
|
|
|
throw new ArgumentException(-104, 'The certificate has already been issued', 'certificate', $responseString); |
710
|
|
|
} elseif (stristr($responseString, 'Invalid Validation Code!') !== false) { |
711
|
|
|
throw new ArgumentException(-103, 'Invalid Validation Code', 'validation-code', $responseString); |
712
|
|
|
} else { |
713
|
|
|
throw new UnknownException(99, 'UnknownException', $responseString); |
714
|
|
|
} |
715
|
|
|
} |
716
|
|
|
|
717
|
|
|
/** |
718
|
|
|
* @param string $domainName |
719
|
|
|
* @param null $orderNumbers |
720
|
|
|
* @param \Closure $callbackFunction |
721
|
|
|
* |
722
|
|
|
* @return array |
723
|
|
|
*/ |
724
|
|
|
public function getMails($domainName, $orderNumbers = null, \Closure $callbackFunction = null) |
725
|
|
|
{ |
726
|
|
|
$orList = ' OR '; |
727
|
|
|
$whereList = ' BODY "'.$domainName.'"'; |
728
|
|
|
$whereList .= ' SUBJECT "'.$domainName.'"'; |
729
|
|
|
|
730
|
|
|
if (is_array($orderNumbers)) { |
731
|
|
|
foreach ($orderNumbers as $orderNumber) { |
732
|
|
|
$orList .= ' OR OR '; |
733
|
|
|
$whereList .= ' BODY "'.$orderNumber.'"'; |
734
|
|
|
$whereList .= ' SUBJECT "'.$orderNumber.'"'; |
735
|
|
|
} |
736
|
|
|
} |
737
|
|
|
|
738
|
|
|
$search = $orList.' '.$whereList; |
739
|
|
|
|
740
|
|
|
return $this |
741
|
|
|
->imapHelper |
742
|
|
|
->fetchMails($this->imapAdapter, $search, false, false, $callbackFunction); |
743
|
|
|
} |
744
|
|
|
|
745
|
|
|
/** |
746
|
|
|
* @param bool $markProcessed |
747
|
|
|
* @param \Closure $callbackFunction |
748
|
|
|
* |
749
|
|
|
* @return array |
750
|
|
|
*/ |
751
|
|
|
public function getUnprocessedMails($markProcessed = true, \Closure $callbackFunction = null) |
752
|
|
|
{ |
753
|
|
|
$search = ' NOT KEYWORD "'.ImapHelper::PROCESSED_FLAG.'"'; |
754
|
|
|
|
755
|
|
|
return $this |
756
|
|
|
->imapHelper |
757
|
|
|
->fetchMails( |
758
|
|
|
$this->imapAdapter, |
759
|
|
|
$search, |
760
|
|
|
$markProcessed, |
761
|
|
|
true, |
762
|
|
|
$callbackFunction |
763
|
|
|
); |
764
|
|
|
} |
765
|
|
|
|
766
|
|
|
/** |
767
|
|
|
* Function to create an exception for API errorcodes |
768
|
|
|
* |
769
|
|
|
* @param array|mixed $responseArray |
770
|
|
|
* |
771
|
|
|
* @return AccountException|ArgumentException|CSRException|RequestException|UnknownApiException|UnknownException |
772
|
|
|
* |
773
|
|
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity) |
774
|
|
|
*/ |
775
|
|
|
protected function createException($responseArray) |
776
|
|
|
{ |
777
|
|
|
if (is_array($responseArray) === false) { |
778
|
|
|
return new UnknownException( |
779
|
|
|
0, |
780
|
|
|
'Internal error', |
781
|
|
|
$responseArray['responseString'] |
782
|
|
|
); |
783
|
|
|
} |
784
|
|
|
|
785
|
|
|
switch ($responseArray['errorCode']) { |
786
|
|
|
case -1: // Not using https: |
787
|
|
|
case -17: // Wrong HTTP-method |
788
|
|
|
return new RequestException( |
789
|
|
|
$responseArray['errorCode'], |
790
|
|
|
$responseArray['errorMessage'], |
791
|
|
|
$responseArray['responseString'] |
792
|
|
|
); |
793
|
|
|
|
794
|
|
|
case -2: // unrecognized argument |
795
|
|
|
case -3: // missing argument |
796
|
|
|
case -4: // invalid argument |
797
|
|
|
case -7: // invalid ISO Country |
798
|
|
|
case -18: // Name = Fully-Qualified Domain Name |
799
|
|
|
case -35: // Name = = IP |
800
|
|
|
case -19: // Name = = Accessible IP |
801
|
|
|
return new ArgumentException( |
802
|
|
|
$responseArray['errorCode'], |
803
|
|
|
$responseArray['errorMessage'], |
804
|
|
|
((isset($responseArray['errorItem'])) ? $responseArray['errorItem'] : null), |
805
|
|
|
$responseArray['responseString'] |
806
|
|
|
); |
807
|
|
|
|
808
|
|
|
case -16: // Permission denied |
809
|
|
|
case -15: // insufficient credits |
810
|
|
|
return new AccountException( |
811
|
|
|
$responseArray['errorCode'], |
812
|
|
|
$responseArray['errorMessage'], |
813
|
|
|
$responseArray['responseString'] |
814
|
|
|
); |
815
|
|
|
|
816
|
|
|
case -5: // contains wildcard |
817
|
|
|
case -6: // no wildcard, but must have |
818
|
|
|
case -8: // missing field |
819
|
|
|
case -9: // base64 decode exception |
820
|
|
|
case -10: // decode exception |
821
|
|
|
case -11: // unsupported algorithm |
822
|
|
|
case -12: // invalid signature |
823
|
|
|
case -13: // unsupported key size |
824
|
|
|
case -20: // Already rejected / Order relevated |
825
|
|
|
case -21: // Already revoked |
826
|
|
|
case -26: // current being issued |
827
|
|
|
case -40: // key compromised |
828
|
|
|
return new CSRException( |
829
|
|
|
$responseArray['errorCode'], |
830
|
|
|
$responseArray['errorMessage'], |
831
|
|
|
$responseArray['responseString'] |
832
|
|
|
); |
833
|
|
|
|
834
|
|
|
case -14: |
835
|
|
|
return new UnknownApiException( |
836
|
|
|
$responseArray['errorCode'], |
837
|
|
|
$responseArray['errorMessage'], |
838
|
|
|
$responseArray['responseString'] |
839
|
|
|
); |
840
|
|
|
|
841
|
|
|
default: |
842
|
|
|
return new UnknownException( |
843
|
|
|
$responseArray['errorCode'], |
844
|
|
|
$responseArray['errorMessage'], |
845
|
|
|
$responseArray['responseString'] |
846
|
|
|
); |
847
|
|
|
} |
848
|
|
|
} |
849
|
|
|
|
850
|
|
|
/** |
851
|
|
|
* @param CollectSslResult $object |
852
|
|
|
* @param array $arr |
853
|
|
|
* @param array $timestampFields |
854
|
|
|
* |
855
|
|
|
* @return $this |
856
|
|
|
*/ |
857
|
|
|
protected function fill(CollectSslResult $object, array $arr, array $timestampFields = array()) |
858
|
|
|
{ |
859
|
|
|
foreach ($arr as $key => $value) { |
860
|
|
|
if (in_array($key, $timestampFields)) { |
861
|
|
|
$value = new \DateTime('@'.$value); |
862
|
|
|
} |
863
|
|
|
|
864
|
|
|
$function = 'set'.ucfirst($key); |
865
|
|
|
|
866
|
|
|
// For example setErrorCode does not exists, so check before |
867
|
|
|
if (method_exists($object, $function)) { |
868
|
|
|
call_user_func(array($object, $function), $value); |
869
|
|
|
} |
870
|
|
|
} |
871
|
|
|
|
872
|
|
|
return $this; |
873
|
|
|
} |
874
|
|
|
|
875
|
|
|
/** |
876
|
|
|
* @param string $url |
877
|
|
|
* @param array $params |
878
|
|
|
* @param int $type |
879
|
|
|
* |
880
|
|
|
* @return bool |
881
|
|
|
* @throws AccountException |
882
|
|
|
* @throws ArgumentException |
883
|
|
|
* @throws CSRException |
884
|
|
|
* @throws RequestException |
885
|
|
|
* @throws UnknownApiException |
886
|
|
|
* @throws UnknownException |
887
|
|
|
*/ |
888
|
|
|
protected function sendBooleanRequest($url, array $params, $type) |
889
|
|
|
{ |
890
|
|
|
// Response is always url encoded |
891
|
|
|
$responseArray = $this |
892
|
|
|
->communicationAdapter |
893
|
|
|
->sendToApi( |
894
|
|
|
$url, |
895
|
|
|
$params, |
896
|
|
|
$type |
897
|
|
|
); |
898
|
|
|
|
899
|
|
|
if ($responseArray['errorCode'] == 0) { |
900
|
|
|
return true; |
901
|
|
|
} else { |
902
|
|
|
throw $this->createException($responseArray); |
903
|
|
|
} |
904
|
|
|
} |
905
|
|
|
} |
906
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.