mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-11 15:10:54 +00:00
Add DNSPod to DDNS Module
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Components;
|
||||
|
||||
use App\Components\DDNS\Aliyun;
|
||||
use App\Components\DDNS\DNSPod;
|
||||
use App\Components\DDNS\Namesilo;
|
||||
use Log;
|
||||
|
||||
@@ -32,6 +33,8 @@ class DDNS
|
||||
return (new Aliyun($domain));
|
||||
case 'namesilo':
|
||||
return new Namesilo($domain);
|
||||
case 'dnspod':
|
||||
return new DNSPod($domain);
|
||||
default:
|
||||
Log::error("未知渠道:".sysConfig('ddns_mode'));
|
||||
|
||||
|
||||
@@ -149,5 +149,4 @@ class Aliyun
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
148
app/Components/DDNS/DNSPod.php
Normal file
148
app/Components/DDNS/DNSPod.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace App\Components\DDNS;
|
||||
|
||||
use Arr;
|
||||
use Http;
|
||||
use Log;
|
||||
|
||||
class DNSPod
|
||||
{
|
||||
private static $apiHost = 'https://dnsapi.cn/';
|
||||
private static $subDomain;
|
||||
|
||||
public function __construct($subDomain)
|
||||
{
|
||||
self::$subDomain = $subDomain;
|
||||
}
|
||||
|
||||
public function store($ip, $type)
|
||||
{
|
||||
$domainInfo = $this->analysisDomain();
|
||||
|
||||
if ($domainInfo) {
|
||||
return $this->send('Record.Create', [
|
||||
'domain_id' => $domainInfo[2],
|
||||
'sub_domain' => $domainInfo[1],
|
||||
'record_type' => $type,
|
||||
'record_line_id' => 0,
|
||||
'value' => $ip,
|
||||
]);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function analysisDomain()
|
||||
{
|
||||
$domainList = $this->domainList();
|
||||
if ($domainList) {
|
||||
foreach ($domainList as $key => $domain) {
|
||||
if (strpos(self::$subDomain, $domain) !== false) {
|
||||
return [$domain, rtrim(substr(self::$subDomain, 0, -(strlen($domain))), '.'), $key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function domainList()
|
||||
{
|
||||
$domainList = $this->send('Domain.List', ['type' => 'mine']);
|
||||
if ($domainList) {
|
||||
return Arr::pluck($domainList['domains'], 'name', 'id');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function send($action, $data = [])
|
||||
{
|
||||
$public = [
|
||||
'login_token' => sysConfig('ddns_key').','.sysConfig('ddns_secret'),
|
||||
'format' => 'json',
|
||||
];
|
||||
$parameters = array_merge($data, $public);
|
||||
|
||||
$response = Http::timeout(15)->asForm()->post(self::$apiHost.$action, $parameters);
|
||||
$message = $response->json();
|
||||
|
||||
if ($response->failed() || ($message && Arr::has($message, 'status.code') && $message['status']['code'] !== "1")) {
|
||||
if ($message && Arr::has($message, 'status.code') && $message['status']['code'] !== "1") {
|
||||
$error = $message['status']['message'];
|
||||
} else {
|
||||
$error = $response->body();
|
||||
}
|
||||
Log::error('[DNSPod - '.$action.'] 请求失败:'.$error);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function destroy($type)
|
||||
{
|
||||
$records = $this->getRecordId($type);
|
||||
$domainInfo = $this->analysisDomain();
|
||||
if ($records && $domainInfo) {
|
||||
$count = 0;
|
||||
foreach ($records as $record) {
|
||||
$result = $this->send('Record.Remove', ['domain_id' => $domainInfo[2], 'record_id' => $record]);
|
||||
if ($result) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getRecordId($type = null)
|
||||
{
|
||||
$domainInfo = $this->analysisDomain();
|
||||
if ($domainInfo) {
|
||||
$parameters = ['domain_id' => $domainInfo[2], 'sub_domain' => $domainInfo[1]];
|
||||
if ($type) {
|
||||
$parameters['record_type'] = $type;
|
||||
}
|
||||
$records = $this->send('Record.List', $parameters);
|
||||
if ($records && Arr::has($records, 'records')) {
|
||||
return Arr::pluck($records['records'], 'id');
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function update($ip, $type)
|
||||
{
|
||||
$recordId = $this->getRecordId($type);
|
||||
$domainInfo = $this->analysisDomain();
|
||||
if ($recordId && $domainInfo) {
|
||||
return $this->send('Record.Modify', [
|
||||
'domain_id' => $domainInfo[2],
|
||||
'record_id' => $recordId[0],
|
||||
'sub_domain' => $domainInfo[1],
|
||||
'record_type' => $type,
|
||||
'record_line_id' => 0,
|
||||
'value' => $ip,
|
||||
]);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function version()
|
||||
{
|
||||
$version = $this->send('Info.Version');
|
||||
if ($version) {
|
||||
return $version['status']['message'];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -562,13 +562,14 @@
|
||||
<option value="">关闭</option>
|
||||
<option value="namesilo">Namesilo</option>
|
||||
<option value="aliyun">阿里云(国际&国内)</option>
|
||||
<option value="dnspod">DNSPod</option>
|
||||
</select>
|
||||
<span class="text-help offset-md-3"> 添加/编辑/删除节点的【域名、ipv4、ipv6】时,自动更新对应内容至DNS服务商 </span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-lg-6">
|
||||
<div class="row">
|
||||
<label class="col-md-3 col-form-label" for="ddns_key">服务商Key</label>
|
||||
<label class="col-md-3 col-form-label" for="ddns_key">DNS服务商Key</label>
|
||||
<div class="col-md-7">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" id="ddns_key" value="{{$ddns_key}}"/>
|
||||
@@ -584,7 +585,7 @@
|
||||
</div>
|
||||
<div class="form-group col-lg-6">
|
||||
<div class="row">
|
||||
<label class="col-md-3 col-form-label" for="ddns_secret">服务商Secret</label>
|
||||
<label class="col-md-3 col-form-label" for="ddns_secret">DNS服务商Secret</label>
|
||||
<div class="col-md-7">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" id="ddns_secret" value="{{$ddns_secret}}"/>
|
||||
|
||||
Reference in New Issue
Block a user