1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
omnilance.php
См. документацию.
1<?php
3
4class Omnilance extends Registrar
5{
9 const BASE_ENDPOINT = 'https://api.omnilance.com/v3/';
10
15 private $apiKey;
16
21 private $secretKey;
22
27 private $http;
28
34 public function __construct(string $apiKey, string $secretKey)
35 {
36 $this->apiKey = $apiKey;
37 $this->secretKey = $secretKey;
38 $this->http = new \Bitrix\Main\Web\HttpClient;
39 $this->http->setTimeout(5);
40 }
41
48 private function setHeaders(string $endPoint, ?string $payLoad = null): void
49 {
50 if (!$payLoad)
51 {
52 $payLoad = '';
53 }
54
55 $signature = hash_hmac('sha256', $this->apiKey . $endPoint . $payLoad, $this->secretKey);
56 $this->http->setHeader('X-OMNI-APIKEY', $this->apiKey);
57 $this->http->setHeader('X-OMNI-SIGNATURE', $signature);
58 $this->http->setHeader('content-type', 'application/json');
59 }
60
67 private function sendPostCommand(string $endPoint, string $payLoad): string
68 {
69 $endPoint = $this::BASE_ENDPOINT . $endPoint;
70 $this->setHeaders($endPoint, $payLoad);
71 $this->http->post($endPoint, $payLoad);
72 return $this->http->getResult();
73 }
74
80 private function sendGetCommand(string $endPoint): string
81 {
82 $endPoint = $this::BASE_ENDPOINT . $endPoint;
83 $this->setHeaders($endPoint);
84 $this->http->get($endPoint);
85 return $this->http->getResult();
86 }
87
96 public static function checkDomain(string $user, string $password, string $domain, ?string &$error): ?bool
97 {
98 $domain = mb_strtolower($domain);
99
100 $omnilance = new self($user, $password);
101
102 $payLoad = json_encode([
103 'domainNames' => [
104 $domain
105 ]
106 ]);
107 $res = $omnilance->sendPostCommand('domains/checkAvailability', $payLoad);
108 $res = json_decode($res, true);
109
110 if (isset($res['error']))
111 {
112 $error = $res['message'] ?? $res['error'];
113 return null;
114 }
115
116 if (isset($res['results']) && is_array($res['results']))
117 {
118 foreach ($res['results'] as $item)
119 {
120 if ($item['domainName'] == $domain)
121 {
122 if ($item['status'] == 'registered')
123 {
124 return true;
125 }
126 break;
127 }
128 }
129 }
130
131 return false;
132 }
133
144 public static function suggestDomain(string $user, string $password, string $word1, string $word2, array $tlds, ?string &$error): ?array
145 {
146 // method is not allowed by provider
147 return null;
148 }
149
159 public static function createDomain(string $user, string $password, string $domain, array $params, ?string &$error): ?bool
160 {
161 $domain = mb_strtolower($domain);
162
163 $payLoad = json_encode([
164 'domain' => [
165 'domainName' => $domain,
166 'privacyEnabled' => true
167 ],
168 'years' => 1
169 ]);
170
171 $omnilance = new self($user, $password);
172 $res = $omnilance->sendPostCommand('domains/createDomain', $payLoad);
173 $res = json_decode($res, true);
174
175 if (isset($res['error']))
176 {
177 $error = $res['message'] ?? $res['error'];
178 return null;
179 }
180
181 return true;
182 }
183
192 public static function renewDomain(string $user, string $password, string $domain, ?string &$error): ?bool
193 {
194 $domain = mb_strtolower($domain);
195
196 $payLoad = json_encode([
197 'domain' => [
198 'domainName' => $domain
199 ],
200 'years' => 1
201 ]);
202
203 $omnilance = new self($user, $password);
204 $res = $omnilance->sendPostCommand('domains/renewDomain/'.$domain, $payLoad);
205 $res = json_decode($res, true);
206
207 if (isset($res['error']))
208 {
209 $error = $res['message'] ?? $res['error'];
210 return null;
211 }
212
213 return true;
214 }
215
225 public static function updateDns(string $user, string $password, string $domain, array $params, ?string &$error): ?bool
226 {
227 $error = null;
228 $domain = mb_strtolower($domain);
229
230 $first = true;
231 foreach ($params as $dns)
232 {
233 $payLoad = [
234 'type' => (isset($dns['type']) && is_string($dns['type'])) ? strtoupper($dns['type']) : null,
235 'name' => (isset($dns['name']) && is_string($dns['name'])) ? $dns['name'] : '',
236 'value' => isset($dns['value']) ? [$dns['value']] : [],
237 'ttl' => 3600
238 ];
239 $payLoad = json_encode($payLoad);
240
241 $omnilance = new self($user, $password);
242
243 if ($first)
244 {
245 $res = $omnilance->sendPostCommand('domains/createZoneRecord/'.$domain, $payLoad);
246 }
247 else
248 {
249 $res = $omnilance->sendPostCommand('domains/createDnsRecord/'.$domain, $payLoad);
250 }
251
252 $res = json_decode($res, true);
253
254 if (isset($res['error']))
255 {
256 $error = $res['message'] ?? $res['error'];
257 }
258 $first = false;
259 }
260
261 return $error === null;
262 }
263
271 public static function getDomainsList(string $user, string $password, ?string &$error): ?array
272 {
273 $list = [];
274 $currentPage = 1;
275 $omnilance = new self($user, $password);
276
277 do
278 {
279 $res = $omnilance->sendGetCommand('domains/100/' . $currentPage);
280 $res = json_decode($res, true);
281
282 if (isset($res['error']))
283 {
284 $error = $res['message'] ?? $res['error'];
285 return null;
286 }
287
288 if (!isset($res['domains']) || !isset($res['lastPage']))
289 {
290 $error = 'Unknown error';
291 return null;
292 }
293
294 foreach ($res['domains'] as $domain)
295 {
296 $list[$domain['domainName']] = [
297 'domain_name' => $domain['domainName'],
298 'creation_date' => $domain['createDate'],
299 'expiration_date' => $domain['expireDate'],
300 'status' => null
301 ];
302 }
303
304 $currentPage++;
305
306 } while ($currentPage <= $res['lastPage']);
307
308 return $list;
309 }
310}
if(isset( $_REQUEST["mode"]) &&$_REQUEST["mode"]=="ajax") if(isset($_REQUEST["mode"]) && $_REQUEST["mode"]=="save_lru" &&check_bitrix_sessid()) $first
Определения access_dialog.php:54
static renewDomain(string $user, string $password, string $domain, ?string &$error)
Определения omnilance.php:192
static updateDns(string $user, string $password, string $domain, array $params, ?string &$error)
Определения omnilance.php:225
static suggestDomain(string $user, string $password, string $word1, string $word2, array $tlds, ?string &$error)
Определения omnilance.php:144
const BASE_ENDPOINT
Определения omnilance.php:9
static checkDomain(string $user, string $password, string $domain, ?string &$error)
Определения omnilance.php:96
static createDomain(string $user, string $password, string $domain, array $params, ?string &$error)
Определения omnilance.php:159
static getDomainsList(string $user, string $password, ?string &$error)
Определения omnilance.php:271
__construct(string $apiKey, string $secretKey)
Определения omnilance.php:34
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
<? if( $useEditor3):?>< tr class="heading">< td colspan="2"><? echo GetMessage("FILEMAN_OPTION_SPELL_SET");?></td ></tr ><? if(function_exists( 'pspell_config_create')):$use_pspell_checked=(COption::GetOptionString( $module_id, "use_pspell", "Y")=="Y") ? "checked" :"";?>< tr >< td valign="top">< label for="use_pspell"><?echo GetMessage("FILEMAN_OPTION_USE_PSPELL");?></label >< br >< a title="<?echo GetMessage("FILEMAN_OPTION_ADDISH_DICS_TITLE");?> http
Определения options.php:1473
$res
Определения filter_act.php:7
$user
Определения mysql_to_pgsql.php:33
$password
Определения mysql_to_pgsql.php:34
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$currentPage
Определения options_user_settings.php:37
$error
Определения subscription_card_product.php:20