Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
regru.php
1<?php
3
4use \Bitrix\Main\Text\Encoding;
5
6class RegRu extends Registrar
7{
16 public static function checkDomain(string $user, string $password, string $domain, ?string &$error): ?bool
17 {
18 $domain = mb_strtolower($domain);
19 $domain = Encoding::convertEncoding($domain, SITE_CHARSET, 'UTF-8');
20
21 $result = \CMailRegru::checkDomain($user, $password, $domain, $error);
22
23 if ($result !== false)
24 {
25 if (
26 isset($result['domains'][0]['dname']) &&
27 $result['domains'][0]['dname'] == $domain
28 )
29 {
30 $result = $result['domains'][0];
31 if ($result['result'] == 'Available')
32 {
33 return false;
34 }
35 else if ($result['error_code'] == 'DOMAIN_ALREADY_EXISTS')
36 {
37 return true;
38 }
39 $error = $result['error_code'];
40 }
41 else
42 {
43 $error = 'unknown';
44 }
45 }
46
47 return null;
48 }
49
60 public static function suggestDomain(string $user, string $password, string $word1, string $word2, array $tlds, ?string &$error): ?array
61 {
62 $word1 = Encoding::convertEncoding($word1, SITE_CHARSET, 'UTF-8');
63 $word2 = Encoding::convertEncoding($word2, SITE_CHARSET, 'UTF-8');
64
65 foreach ($tlds as &$v)
66 {
67 $v = Encoding::convertEncoding($v, SITE_CHARSET, 'UTF-8');
68 }
69
70 $result = \CMailRegru::suggestDomain($user, $password, $word1, $word2, $tlds, $error);
71
72 if ($result !== false)
73 {
74 $suggestions = array();
75 if (!empty($result['suggestions']) && is_array($result['suggestions']))
76 {
77 foreach ($result['suggestions'] as $entry)
78 {
79 foreach ($entry['avail_in'] as $tlds)
80 {
81 $suggestions[] = Encoding::convertEncoding(
82 sprintf('%s.%s', $entry['name'], $tlds),
83 'UTF-8',
84 SITE_CHARSET
85 );
86 }
87 }
88 }
89
90 return $suggestions;
91 }
92
93 return null;
94 }
95
105 public static function createDomain(string $user, string $password, string $domain, array $params, ?string &$error): ?bool
106 {
107 $domain = mb_strtolower($domain);
108 $params = array_merge(
109 $params,
110 array(
111 'period' => 1,
112 'nss' => array(
113 'ns0' => 'ns1.reg.ru.',
114 'ns1' => 'ns2.reg.ru.'
115 ),
116 )
117 );
118
119 if (array_key_exists('ip', $params))
120 {
121 $params['enduser_ip'] = $params['ip'];
122 }
123
124 $domain = Encoding::convertEncoding($domain, SITE_CHARSET, 'UTF-8');
125 $params = Encoding::convertEncoding($params, SITE_CHARSET, 'UTF-8');
126
127 $result = \CMailRegru::createDomain($user, $password, $domain, $params, $error);
128
129 if ($result !== false)
130 {
131 if (isset($result['dname']) && $result['dname'] == $domain)
132 {
133 return true;
134 }
135 else
136 {
137 $error = $result['error_code'] ?? 'unknown';
138 }
139 }
140
141 return null;
142 }
143
152 public static function renewDomain(string $user, string $password, string $domain, ?string &$error): ?bool
153 {
154 $domain = Encoding::convertEncoding($domain, SITE_CHARSET, 'UTF-8');
155 $result = \CMailRegru::renewDomain($user, $password, $domain, ['period' => 1], $error);
156
157 if ($result !== false)
158 {
159 if (isset($result['dname']) && mb_strtolower($result['dname']) == mb_strtolower($domain))
160 {
161 return true;
162 }
163 else
164 {
165 $error = 'unknown';
166 }
167 }
168
169 return null;
170 }
171
181 public static function updateDns(string $user, string $password, string $domain, array $params, ?string &$error): ?bool
182 {
183 $domain = mb_strtolower($domain);
184 $domain = Encoding::convertEncoding($domain, SITE_CHARSET, 'UTF-8');
185 $params = Encoding::convertEncoding($params, SITE_CHARSET, 'UTF-8');
186
187 foreach ($params as $k => $record)
188 {
189 switch ($record['type'])
190 {
191 case 'a':
192 $params[$k] = array(
193 'action' => 'add_alias',
194 'subdomain' => '@',
195 'ipaddr' => $record['value']
196 );
197 break;
198 case 'alias':
199 $params[$k] = array(
200 'action' => 'add_alias',
201 'subdomain' => $record['name'],
202 'ipaddr' => $record['value']
203 );
204 break;
205 case 'cname':
206 $params[$k] = array(
207 'action' => 'add_cname',
208 'subdomain' => $record['name'],
209 'canonical_name' => $record['value']
210 );
211 break;
212 case 'mx':
213 $params[$k] = array(
214 'action' => 'add_mx',
215 'subdomain' => $record['name'],
216 'mail_server' => $record['value'],
217 'priority' => $record['priority']
218 );
219 break;
220 }
221 }
222
223 $result = \CMailRegru::updateDns($user, $password, $domain, $params, $error);
224
225 if ($result !== false)
226 {
227 if (isset($result['dname']) && $result['dname'] == $domain)
228 {
229 if (isset($result['result']) && $result['result'] == 'success')
230 {
231 return true;
232 }
233 else
234 {
235 $error = $result['error_code'] ?? 'unknown';
236 }
237 }
238 else
239 {
240 $error = 'unknown';
241 }
242 }
243
244 return null;
245 }
246
254 public static function getDomainsList(string $user, string $password, ?string &$error): ?array
255 {
256 $result = \CMailRegru::getDomainsList($user, $password, $error);
257
258 if ($result !== false)
259 {
260 $list = [];
261 foreach ($result as $domain)
262 {
263 if (!empty($domain['dname']))
264 {
265 $list[$domain['dname']] = [
266 'domain_name' => $domain['dname'],
267 'creation_date' => $domain['creation_date'],
268 'expiration_date' => $domain['expiration_date'],
269 'status' => $domain['state']
270 ];
271 }
272 }
273
274 return $list;
275 }
276
277 return null;
278 }
279}
static renewDomain(string $user, string $password, string $domain, ?string &$error)
Definition regru.php:152
static updateDns(string $user, string $password, string $domain, array $params, ?string &$error)
Definition regru.php:181
static suggestDomain(string $user, string $password, string $word1, string $word2, array $tlds, ?string &$error)
Definition regru.php:60
static checkDomain(string $user, string $password, string $domain, ?string &$error)
Definition regru.php:16
static createDomain(string $user, string $password, string $domain, array $params, ?string &$error)
Definition regru.php:105
static getDomainsList(string $user, string $password, ?string &$error)
Definition regru.php:254