Files
ProxyPanel/app/Components/DDNS.php
2021-01-26 02:41:10 -05:00

81 lines
2.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Components;
use App\Components\DDNS\Aliyun;
use App\Components\DDNS\CloudFlare;
use App\Components\DDNS\DNSPod;
use App\Components\DDNS\Namesilo;
use Log;
/**
* Class DDNS 域名解析.
*/
class DDNS
{
/**
* 删除解析记录.
*
* @param string $domain 域名
* @param string|null $type
*/
public static function destroy(string $domain, $type = null)
{
if (self::dnsProvider($domain)->destroy($type)) {
Log::info("【DDNS】删除{$domain} 成功");
} else {
Log::info("【DDNS】删除{$domain} 失败,请手动删除!");
}
}
private static function dnsProvider($domain)
{
switch (sysConfig('ddns_mode')) {
case 'aliyun':
return new Aliyun($domain);
case 'namesilo':
return new Namesilo($domain);
case 'dnspod':
return new DNSPod($domain);
case 'cloudflare':
return new CloudFlare($domain);
default:
Log::error('【DDNS】未知渠道'.sysConfig('ddns_mode'));
return false;
}
}
/**
* 修改解析记录.
*
* @param string $domain 域名
* @param string $ip ip地址
* @param string $type 记录类型,默认为 A
*/
public static function update(string $domain, string $ip, string $type = 'A')
{
if (self::dnsProvider($domain)->update($ip, $type)) {
Log::info("【DDNS】更新{$ip} => {$domain} 类型:{$type} 成功");
} else {
Log::info("【DDNS】更新{$ip} => {$domain} 类型:{$type} 失败,请手动设置!");
}
}
/**
* 添加解析记录.
*
* @param string $domain 域名
* @param string $ip ip地址
* @param string $type 记录类型,默认为 A
*/
public static function store(string $domain, string $ip, string $type = 'A')
{
if (self::dnsProvider($domain)->store($ip, $type)) {
Log::info("【DDNS】添加{$ip} => {$domain} 类型:{$type} 成功");
} else {
Log::info("【DDNS】添加{$ip} => {$domain} 类型:{$type} 失败,请手动设置!");
}
}
}