DDNS细节优化与Namesilo多域名账号支持

This commit is contained in:
兔姬桑
2020-10-12 06:00:59 +08:00
parent a774eafddb
commit 590de93b58
4 changed files with 24 additions and 19 deletions

View File

@@ -20,12 +20,12 @@ class DDNS
* @param string|null $type
* @return false|int
*/
public static function destory($domain, $type = null)
public static function destroy($domain, $type = null)
{
return self::getClient($domain)->destroy($type);
return self::dnsProvider($domain)->destroy($type);
}
public static function getClient($domain)
private static function dnsProvider($domain)
{
switch (sysConfig('ddns_mode')) {
case 'aliyun':
@@ -49,7 +49,7 @@ class DDNS
*/
public static function update($domain, $ip, $type = 'A')
{
return self::getClient($domain)->update($ip, $type);
return self::dnsProvider($domain)->update($ip, $type);
}
/**
@@ -62,7 +62,7 @@ class DDNS
*/
public static function store($domain, $ip, $type = 'A')
{
return self::getClient($domain)->store($ip, $type);
return self::dnsProvider($domain)->store($ip, $type);
}
}

View File

@@ -8,6 +8,7 @@ use Log;
class Aliyun
{
private static $apiHost = 'https://alidns.aliyuncs.com/';
private static $subDomain;
public function __construct($subDomain)
@@ -26,7 +27,7 @@ class Aliyun
return false;
}
private function analysisDomain()
protected function analysisDomain()
{
$domainList = $this->domainList();
if ($domainList) {
@@ -67,7 +68,7 @@ class Aliyun
$parameters = array_merge(['Action' => $action], $data, $public);
$parameters['Signature'] = $this->computeSignature($parameters);
$response = Http::timeout(15)->post('https://alidns.aliyuncs.com/?'.http_build_query($parameters));
$response = Http::timeout(15)->post(self::$apiHost.http_build_query($parameters));
$message = $response->json();
if ($response->failed()) {

View File

@@ -7,6 +7,7 @@ use Log;
class Namesilo
{
private static $apiHost = 'https://www.namesilo.com/api/';
private static $subDomain;
public function __construct($subDomain)
@@ -30,15 +31,18 @@ class Namesilo
return false;
}
private function analysisDomain()
protected function analysisDomain()
{
// TODO: 尚未进行,多域名环境下,获取信息测试
$domainList = $this->domainList();
if ($domainList) {
foreach ($domainList as $domain) {
if (strpos(self::$subDomain, $domain) !== false) {
return [$domain, rtrim(substr(self::$subDomain, 0, -(strlen($domain))), '.')];
if (is_array($domainList)) {
foreach ($domainList as $domain) {
if (strpos(self::$subDomain, $domain) !== false) {
return [$domain, rtrim(substr(self::$subDomain, 0, -(strlen($domain))), '.')];
}
}
} elseif (strpos(self::$subDomain, $domainList) !== false) {
return [$domainList, rtrim(substr(self::$subDomain, 0, -(strlen($domainList))), '.')];
}
}
@@ -49,7 +53,7 @@ class Namesilo
{
$data = $this->send('listDomains');
if ($data) {
return $data['domains'];
return $data['domains']['domain'];
}
return false;
@@ -64,7 +68,7 @@ class Namesilo
];
$query = array_merge($params, $data);
$result = file_get_contents('https://www.namesilo.com/api/'.$operation.'?'.http_build_query($query));
$result = file_get_contents(self::$apiHost.$operation.'?'.http_build_query($query));
$result = json_decode(json_encode(simplexml_load_string(trim($result))), true);
if ($result && $result['reply']['code'] === '300' && $result['reply']['detail'] === 'success') {
@@ -118,7 +122,7 @@ class Namesilo
return false;
}
public function destory($type)
public function destroy($type)
{
$records = $this->getRecordId($type);
$domainInfo = $this->analysisDomain();

View File

@@ -46,7 +46,7 @@ class NodeObserver
$changes = $node->getChanges();
if (Arr::hasAny($changes, ['ip', 'ipv6', 'server'])) {
if (Arr::exists($changes, 'server')) {
DDNS::destory($node->getOriginal('server'));
DDNS::destroy($node->getOriginal('server'));
if ($node->ip) {
DDNS::store($node->server, $node->ip);
}
@@ -60,7 +60,7 @@ class NodeObserver
} elseif ($node->ip) {
DDNS::store($node->server, $node->ip);
} else {
DDNS::destory($node->server, 'A');
DDNS::destroy($node->server, 'A');
}
}
if (Arr::exists($changes, 'ipv6')) {
@@ -69,7 +69,7 @@ class NodeObserver
} elseif ($node->ipv6) {
DDNS::store($node->server, $node->ipv6, 'AAAA');
} else {
DDNS::destory($node->server, 'AAAA');
DDNS::destroy($node->server, 'AAAA');
}
}
}
@@ -113,7 +113,7 @@ class NodeObserver
}
if ($node->is_ddns == 0 && $node->server && sysConfig('ddns_mode')) {
DDNS::destory($node->server);
DDNS::destroy($node->server);
}
}
}