1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* /classes/DomainMOD/AboveCom.php |
4
|
|
|
* |
5
|
|
|
* This file is part of DomainMOD, an open source domain and internet asset manager. |
6
|
|
|
* Copyright (c) 2010-2017 Greg Chetcuti <[email protected]> |
7
|
|
|
* |
8
|
|
|
* Project: http://domainmod.org Author: http://chetcuti.com |
9
|
|
|
* |
10
|
|
|
* DomainMOD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public |
11
|
|
|
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later |
12
|
|
|
* version. |
13
|
|
|
* |
14
|
|
|
* DomainMOD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
15
|
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License along with DomainMOD. If not, see |
18
|
|
|
* http://www.gnu.org/licenses/. |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
//@formatter:off |
22
|
|
|
namespace DomainMOD; |
23
|
|
|
|
24
|
|
|
class AboveCom |
25
|
|
|
{ |
26
|
|
|
public $format; |
27
|
|
|
public $log; |
28
|
|
|
public $system; |
29
|
|
|
|
30
|
|
|
public function __construct() |
31
|
|
|
{ |
32
|
|
|
$this->format = new Format(); |
33
|
|
|
$this->log = new Log('abovecom.class'); |
34
|
|
|
$this->system = new System(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
View Code Duplication |
public function getApiUrl($api_key, $command) |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$base_url = 'https://www.above.com/registrar/api/query.html?key=' . $api_key; |
40
|
|
|
if ($command == 'domainlist') { |
41
|
|
|
return $base_url . '&query=my_domains&limit=1000'; |
42
|
|
|
} else { |
43
|
|
|
return 'Unable to build API URL'; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
View Code Duplication |
public function apiCall($full_url) |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$handle = curl_init($full_url); |
50
|
|
|
curl_setopt( $handle, CURLOPT_RETURNTRANSFER, true ); |
51
|
|
|
$result = curl_exec($handle); |
52
|
|
|
curl_close($handle); |
53
|
|
|
return $result; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getDomainList($api_key, $account_id) |
57
|
|
|
{ |
58
|
|
|
$domain_list = array(); |
59
|
|
|
$domain_count = 0; |
60
|
|
|
|
61
|
|
|
$api_url = $this->getApiUrl($api_key, 'domainlist'); |
62
|
|
|
$api_results = $this->apiCall($api_url); |
63
|
|
|
$array_results = $this->convertToArray($api_results); |
64
|
|
|
|
65
|
|
|
// confirm that the api call was successful |
66
|
|
|
if ($array_results[0]['@attributes']['code'] == '100') { |
67
|
|
|
|
68
|
|
|
$tmpq = $this->system->db()->prepare(" |
69
|
|
|
INSERT INTO domain_queue_temp |
70
|
|
|
(account_id, domain, expiry_date, ns1, ns2, ns3, ns4, ns5, ns6, ns7, ns8, ns9, ns10, autorenew, privacy) |
71
|
|
|
VALUES |
72
|
|
|
(:account_id, :domain, :expiry_date, :ns1, :ns2, :ns3, :ns4, :ns5, :ns6, :ns7, :ns8, :ns9, :ns10, |
73
|
|
|
:autorenew, :privacy)"); |
74
|
|
|
|
75
|
|
|
foreach ($array_results[0]['domains']['r'] as $value) { |
76
|
|
|
|
77
|
|
|
$domain_list[] = $value['@attributes']['domain']; |
78
|
|
|
$expiry_date = $this->processExpiry($value['expiry']); |
79
|
|
|
if ($value['dns1'] != '') $ns1 = $value['dns1']; |
80
|
|
|
if ($value['dns2'] != '') $ns2 = $value['dns2']; |
81
|
|
|
if ($value['dns3'] != '') $ns3 = $value['dns3']; |
82
|
|
|
if ($value['dns4'] != '') $ns4 = $value['dns4']; |
83
|
|
|
if ($value['dns5'] != '') $ns5 = $value['dns5']; |
84
|
|
|
if ($value['dns6'] != '') $ns6 = $value['dns6']; |
85
|
|
|
if ($value['dns7'] != '') $ns7 = $value['dns7']; |
86
|
|
|
if ($value['dns8'] != '') $ns8 = $value['dns8']; |
87
|
|
|
if ($value['dns9'] != '') $ns9 = $value['dns9']; |
88
|
|
|
if ($value['dns10'] != '') $ns10 = $value['dns10']; |
89
|
|
|
$autorenew = $this->processAutorenew($value['autorenew']); |
90
|
|
|
$privacy = $this->processPrivacy($value['privacy']); |
91
|
|
|
|
92
|
|
|
$tmpq->execute(['account_id' => $account_id, |
93
|
|
|
'domain' => $domain_list[$domain_count], |
94
|
|
|
'expiry_date' => $expiry_date, |
95
|
|
|
'ns1' => $ns1, |
96
|
|
|
'ns2' => $ns2, |
97
|
|
|
'ns3' => $ns3, |
98
|
|
|
'ns4' => $ns4, |
99
|
|
|
'ns5' => $ns5, |
100
|
|
|
'ns6' => $ns6, |
101
|
|
|
'ns7' => $ns7, |
102
|
|
|
'ns8' => $ns8, |
103
|
|
|
'ns9' => $ns9, |
104
|
|
|
'ns10' => $ns10, |
105
|
|
|
'autorenew' => $autorenew, |
106
|
|
|
'privacy' => $privacy]); |
107
|
|
|
|
108
|
|
|
$domain_count++; |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
} else { |
113
|
|
|
|
114
|
|
|
$log_message = 'Unable to get domain list'; |
115
|
|
|
$log_extra = array('API Key' => $this->format->obfusc($api_key), 'Account ID' => $account_id); |
116
|
|
|
$this->log->error($log_message, $log_extra); |
|
|
|
|
117
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
return array($domain_count, $domain_list); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
View Code Duplication |
public function getFullInfo($account_id, $domain) |
|
|
|
|
124
|
|
|
{ |
125
|
|
|
$expiration_date = ''; |
126
|
|
|
$dns_servers = array(); |
127
|
|
|
$privacy_status = ''; |
128
|
|
|
$autorenewal_status = ''; |
129
|
|
|
|
130
|
|
|
$tmpq = $this->system->db()->prepare(" |
131
|
|
|
SELECT id, expiry_date, ns1, ns2, ns3, ns4, ns5, ns6, ns7, ns8, ns9, ns10, autorenew, privacy |
132
|
|
|
FROM domain_queue_temp |
133
|
|
|
WHERE account_id = :account_id |
134
|
|
|
AND domain = :domain |
135
|
|
|
ORDER BY id ASC"); |
136
|
|
|
$tmpq->execute(['account_id' => $account_id, |
137
|
|
|
'domain' => $domain]); |
138
|
|
|
$result = $tmpq->fetch(); |
139
|
|
|
|
140
|
|
|
if (!$result) { |
141
|
|
|
|
142
|
|
|
$log_message = 'Unable to get domain details'; |
143
|
|
|
$log_extra = array('Domain' => $domain, 'Account ID' => $account_id); |
144
|
|
|
$this->log->error($log_message, $log_extra); |
|
|
|
|
145
|
|
|
|
146
|
|
|
} else { |
147
|
|
|
|
148
|
|
|
$expiration_date = $result->expiry_date; |
149
|
|
|
|
150
|
|
|
$dns_result[0] = $result->ns1; |
|
|
|
|
151
|
|
|
$dns_result[1] = $result->ns2; |
152
|
|
|
$dns_result[2] = $result->ns3; |
153
|
|
|
$dns_result[3] = $result->ns4; |
154
|
|
|
$dns_result[4] = $result->ns5; |
155
|
|
|
$dns_result[5] = $result->ns6; |
156
|
|
|
$dns_result[6] = $result->ns7; |
157
|
|
|
$dns_result[7] = $result->ns8; |
158
|
|
|
$dns_result[8] = $result->ns9; |
159
|
|
|
$dns_result[9] = $result->ns10; |
160
|
|
|
$dns_servers = $this->processDns($dns_result); |
161
|
|
|
|
162
|
|
|
$privacy_status = $result->privacy; |
163
|
|
|
|
164
|
|
|
$autorenewal_status = $result->autorenew; |
165
|
|
|
|
166
|
|
|
$tmpq = $this->system->db()->prepare(" |
167
|
|
|
DELETE FROM domain_queue_temp |
168
|
|
|
WHERE id = :id"); |
169
|
|
|
$tmpq->execute(['id' => $result->id]); |
170
|
|
|
|
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
return array($expiration_date, $dns_servers, $privacy_status, $autorenewal_status); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function convertToArray($api_result) |
177
|
|
|
{ |
178
|
|
|
$xml = simplexml_load_string($api_result); |
179
|
|
|
$json = json_encode((array($xml)), true); |
180
|
|
|
return json_decode($json, true); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function processExpiry($expiry_result) |
184
|
|
|
{ |
185
|
|
|
$unix_expiration_date = strtotime($expiry_result); |
186
|
|
|
return gmdate("Y-m-d", $unix_expiration_date); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
View Code Duplication |
public function processDns($dns_result) |
|
|
|
|
190
|
|
|
{ |
191
|
|
|
$dns_servers = array(); |
192
|
|
|
if (!empty($dns_result)) { |
193
|
|
|
$dns_servers = array_filter($dns_result); |
194
|
|
|
} else { |
195
|
|
|
$dns_servers[0] = 'no.dns-servers.1'; |
196
|
|
|
$dns_servers[1] = 'no.dns-servers.2'; |
197
|
|
|
} |
198
|
|
|
return $dns_servers; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
public function processPrivacy($privacy_result) |
202
|
|
|
{ |
203
|
|
|
if ($privacy_result == 'on') { |
204
|
|
|
$privacy_status = '1'; |
205
|
|
|
} else { |
206
|
|
|
$privacy_status = '0'; |
207
|
|
|
} |
208
|
|
|
return $privacy_status; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
public function processAutorenew($autorenewal_result) |
212
|
|
|
{ |
213
|
|
|
if ($autorenewal_result == 'on') { |
214
|
|
|
$autorenewal_status = '1'; |
215
|
|
|
} else { // result messages - 'do not renew', 'no renew option' |
216
|
|
|
$autorenewal_status = '0'; |
217
|
|
|
} |
218
|
|
|
return $autorenewal_status; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
} //@formatter:on |
222
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.