1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* /classes/DomainMOD/Api.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 Api |
25
|
|
|
{ |
26
|
|
|
public $assets; |
27
|
|
|
public $error; |
28
|
|
|
public $log; |
29
|
|
|
public $system; |
30
|
|
|
|
31
|
|
|
public function __construct() |
32
|
|
|
{ |
33
|
|
|
$this->assets = new Assets(); |
34
|
|
|
$this->error = new Error(); |
35
|
|
|
$this->log = new Log('api.class'); |
36
|
|
|
$this->system = new System(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function getKey($account_id) |
40
|
|
|
{ |
41
|
|
|
$pdo = $this->system->db(); |
42
|
|
|
|
43
|
|
|
$stmt = $pdo->prepare(" |
44
|
|
|
SELECT api_key |
45
|
|
|
FROM registrar_accounts |
46
|
|
|
WHERE id = :account_id"); |
47
|
|
|
$stmt->bindValue('account_id', $account_id, \PDO::PARAM_INT); |
48
|
|
|
$stmt->execute(); |
49
|
|
|
|
50
|
|
|
$result = $stmt->fetchColumn(); |
51
|
|
|
|
52
|
|
|
if (!$result) { |
53
|
|
|
|
54
|
|
|
$log_message = 'Unable to retrieve API Key'; |
55
|
|
|
$log_extra = array('Account ID' => $account_id, 'Registrar' => $this->assets->getRegistrar($account_id), |
56
|
|
|
'Account Username' => $this->assets->getUsername($account_id)); |
57
|
|
|
$this->log->error($log_message, $log_extra); |
|
|
|
|
58
|
|
|
return $log_message; |
59
|
|
|
|
60
|
|
|
} else { |
61
|
|
|
|
62
|
|
|
return $result; |
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
View Code Duplication |
public function getKeySecret($account_id) |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$pdo = $this->system->db(); |
70
|
|
|
|
71
|
|
|
$stmt = $pdo->prepare(" |
72
|
|
|
SELECT api_key, api_secret |
73
|
|
|
FROM registrar_accounts |
74
|
|
|
WHERE id = :account_id"); |
75
|
|
|
$stmt->bindValue('account_id', $account_id, \PDO::PARAM_INT); |
76
|
|
|
$stmt->execute(); |
77
|
|
|
|
78
|
|
|
$result = $stmt->fetch(); |
79
|
|
|
|
80
|
|
|
if (!$result) { |
81
|
|
|
|
82
|
|
|
$log_message1 = 'Unable to retrieve API Key'; |
83
|
|
|
$log_message2 = 'Unable to retrieve API Secret'; |
84
|
|
|
$log_extra = array('Account ID' => $account_id, 'Registrar' => $this->assets->getRegistrar($account_id), |
85
|
|
|
'Account Username' => $this->assets->getUsername($account_id)); |
86
|
|
|
$this->log->error($log_message1, $log_extra); |
|
|
|
|
87
|
|
|
$this->log->error($log_message2, $log_extra); |
|
|
|
|
88
|
|
|
return array($log_message1, $log_message2); |
89
|
|
|
|
90
|
|
|
} else { |
91
|
|
|
|
92
|
|
|
return array($result->api_key, $result->api_secret); |
93
|
|
|
|
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
View Code Duplication |
public function getUserKey($account_id) |
|
|
|
|
98
|
|
|
{ |
99
|
|
|
$pdo = $this->system->db(); |
100
|
|
|
|
101
|
|
|
$stmt = $pdo->prepare(" |
102
|
|
|
SELECT username, api_key |
103
|
|
|
FROM registrar_accounts |
104
|
|
|
WHERE id = :account_id"); |
105
|
|
|
$stmt->bindValue('account_id', $account_id, \PDO::PARAM_INT); |
106
|
|
|
$stmt->execute(); |
107
|
|
|
|
108
|
|
|
$result = $stmt->fetch(); |
109
|
|
|
|
110
|
|
|
if (!$result) { |
111
|
|
|
|
112
|
|
|
$log_message1 = 'Unable to retrieve Username'; |
113
|
|
|
$log_message2 = 'Unable to retrieve API Key'; |
114
|
|
|
$log_extra = array('Account ID' => $account_id, 'Registrar' => $this->assets->getRegistrar($account_id), |
115
|
|
|
'Account Username' => $this->assets->getUsername($account_id)); |
116
|
|
|
$this->log->error($log_message1, $log_extra); |
|
|
|
|
117
|
|
|
$this->log->error($log_message2, $log_extra); |
|
|
|
|
118
|
|
|
return array($log_message1, $log_message2); |
119
|
|
|
|
120
|
|
|
} else { |
121
|
|
|
|
122
|
|
|
return array($result->username, $result->api_key); |
123
|
|
|
|
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
View Code Duplication |
public function getUserAppSecret($account_id) |
|
|
|
|
128
|
|
|
{ |
129
|
|
|
$pdo = $this->system->db(); |
130
|
|
|
|
131
|
|
|
$stmt = $pdo->prepare(" |
132
|
|
|
SELECT username, api_app_name, api_secret |
133
|
|
|
FROM registrar_accounts |
134
|
|
|
WHERE id = :account_id"); |
135
|
|
|
$stmt->bindValue('account_id', $account_id, \PDO::PARAM_INT); |
136
|
|
|
$stmt->execute(); |
137
|
|
|
|
138
|
|
|
$result = $stmt->fetch(); |
139
|
|
|
|
140
|
|
|
if (!$result) { |
141
|
|
|
|
142
|
|
|
$log_message1 = 'Unable to retrieve Username'; |
143
|
|
|
$log_message2 = 'Unable to retrieve API App Name'; |
144
|
|
|
$log_message3 = 'Unable to retrieve API Secret'; |
145
|
|
|
$log_extra = array('Account ID' => $account_id, 'Registrar' => $this->assets->getRegistrar($account_id), |
146
|
|
|
'Account Username' => $this->assets->getUsername($account_id)); |
147
|
|
|
$this->log->error($log_message1, $log_extra); |
|
|
|
|
148
|
|
|
$this->log->error($log_message2, $log_extra); |
|
|
|
|
149
|
|
|
$this->log->error($log_message3, $log_extra); |
|
|
|
|
150
|
|
|
return array($log_message1, $log_message2, $log_message3); |
151
|
|
|
|
152
|
|
|
} else { |
153
|
|
|
|
154
|
|
|
return array($result->username, $result->api_app_name, $result->api_secret); |
155
|
|
|
|
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
|
View Code Duplication |
public function getUserKeyIp($account_id) |
|
|
|
|
160
|
|
|
{ |
161
|
|
|
$pdo = $this->system->db(); |
162
|
|
|
|
163
|
|
|
$stmt = $pdo->prepare(" |
164
|
|
|
SELECT ra.username, ra.api_key, ip.ip |
165
|
|
|
FROM registrar_accounts AS ra, ip_addresses AS ip |
166
|
|
|
WHERE ra.api_ip_id = ip.id |
167
|
|
|
AND ra.id = :account_id"); |
168
|
|
|
$stmt->bindValue('account_id', $account_id, \PDO::PARAM_INT); |
169
|
|
|
$stmt->execute(); |
170
|
|
|
|
171
|
|
|
$result = $stmt->fetch(); |
172
|
|
|
|
173
|
|
|
if (!$result) { |
174
|
|
|
|
175
|
|
|
$log_message1 = 'Unable to retrieve Username'; |
176
|
|
|
$log_message2 = 'Unable to retrieve API Key'; |
177
|
|
|
$log_message3 = 'Unable to retrieve IP Address'; |
178
|
|
|
$log_extra = array('Account ID' => $account_id, 'Registrar' => $this->assets->getRegistrar($account_id), |
179
|
|
|
'Account Username' => $this->assets->getUsername($account_id)); |
180
|
|
|
$this->log->error($log_message1, $log_extra); |
|
|
|
|
181
|
|
|
$this->log->error($log_message2, $log_extra); |
|
|
|
|
182
|
|
|
$this->log->error($log_message3, $log_extra); |
|
|
|
|
183
|
|
|
return array($log_message1, $log_message2, $log_message3); |
184
|
|
|
|
185
|
|
|
} else { |
186
|
|
|
|
187
|
|
|
return array($result->username, $result->api_key, $result->ip); |
188
|
|
|
|
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|
192
|
|
View Code Duplication |
public function getReselleridKey($account_id) |
|
|
|
|
193
|
|
|
{ |
194
|
|
|
$pdo = $this->system->db(); |
195
|
|
|
|
196
|
|
|
$stmt = $pdo->prepare(" |
197
|
|
|
SELECT reseller_id, api_key |
198
|
|
|
FROM registrar_accounts |
199
|
|
|
WHERE id = :account_id"); |
200
|
|
|
$stmt->bindValue('account_id', $account_id, \PDO::PARAM_INT); |
201
|
|
|
$stmt->execute(); |
202
|
|
|
|
203
|
|
|
$result = $stmt->fetch(); |
204
|
|
|
|
205
|
|
|
if (!$result) { |
206
|
|
|
|
207
|
|
|
$log_message1 = 'Unable to retrieve Reseller ID'; |
208
|
|
|
$log_message2 = 'Unable to retrieve API Key'; |
209
|
|
|
$log_extra = array('Account ID' => $account_id, 'Registrar' => $this->assets->getRegistrar($account_id), |
210
|
|
|
'Account Username' => $this->assets->getUsername($account_id)); |
211
|
|
|
$this->log->error($log_message1, $log_extra); |
|
|
|
|
212
|
|
|
$this->log->error($log_message2, $log_extra); |
|
|
|
|
213
|
|
|
return array($log_message1, $log_message2); |
214
|
|
|
|
215
|
|
|
} else { |
216
|
|
|
|
217
|
|
|
return array($result->reseller_id, $result->api_key); |
218
|
|
|
|
219
|
|
|
} |
220
|
|
|
} |
221
|
|
|
|
222
|
|
View Code Duplication |
public function getUserPass($account_id) |
|
|
|
|
223
|
|
|
{ |
224
|
|
|
$pdo = $this->system->db(); |
225
|
|
|
|
226
|
|
|
$stmt = $pdo->prepare(" |
227
|
|
|
SELECT username, `password` |
228
|
|
|
FROM registrar_accounts |
229
|
|
|
WHERE id = :account_id"); |
230
|
|
|
$stmt->bindValue('account_id', $account_id, \PDO::PARAM_INT); |
231
|
|
|
$stmt->execute(); |
232
|
|
|
|
233
|
|
|
$result = $stmt->fetch(); |
234
|
|
|
|
235
|
|
|
if (!$result) { |
236
|
|
|
|
237
|
|
|
$log_message1 = 'Unable to retrieve Username'; |
238
|
|
|
$log_message2 = 'Unable to retrieve Password'; |
239
|
|
|
$log_extra = array('Account ID' => $account_id, 'Registrar' => $this->assets->getRegistrar($account_id), |
240
|
|
|
'Account Username' => $this->assets->getUsername($account_id)); |
241
|
|
|
$this->log->error($log_message1, $log_extra); |
|
|
|
|
242
|
|
|
$this->log->error($log_message2, $log_extra); |
|
|
|
|
243
|
|
|
return array($log_message1, $log_message2); |
244
|
|
|
|
245
|
|
|
} else { |
246
|
|
|
|
247
|
|
|
return array($result->username, $result->password); |
248
|
|
|
|
249
|
|
|
} |
250
|
|
|
} |
251
|
|
|
|
252
|
|
View Code Duplication |
public function getApiRegistrarName($api_registrar_id) |
|
|
|
|
253
|
|
|
{ |
254
|
|
|
$pdo = $this->system->db(); |
255
|
|
|
|
256
|
|
|
$stmt = $pdo->prepare(" |
257
|
|
|
SELECT `name` |
258
|
|
|
FROM api_registrars |
259
|
|
|
WHERE id = :api_registrar_id"); |
260
|
|
|
$stmt->bindValue('api_registrar_id', $api_registrar_id, \PDO::PARAM_INT); |
261
|
|
|
$stmt->execute(); |
262
|
|
|
|
263
|
|
|
$result = $stmt->fetchColumn(); |
264
|
|
|
|
265
|
|
|
if (!$result) { |
266
|
|
|
|
267
|
|
|
$log_message = 'Unable to retrieve API Registrar Name'; |
268
|
|
|
$log_extra = array('API Registrar ID' => $api_registrar_id); |
269
|
|
|
$this->log->error($log_message, $log_extra); |
|
|
|
|
270
|
|
|
return $log_message; |
271
|
|
|
|
272
|
|
|
} else { |
273
|
|
|
|
274
|
|
|
return $result; |
275
|
|
|
|
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
} //@formatter:on |
280
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: