diff --git a/app/lib/DnsHelper.php b/app/lib/DnsHelper.php index 182f276..e9edf69 100644 --- a/app/lib/DnsHelper.php +++ b/app/lib/DnsHelper.php @@ -119,6 +119,21 @@ class DnsHelper 'page' => false, 'add' => true, ], + 'bt' => [ + 'name' => '宝塔域名', + 'config' => [ + 'ak' => 'Access Key', + 'sk' => 'Secret Key', + 'ext' => 'Account ID', + ], + 'remark' => 2, + 'status' => true, + 'redirect' => false, + 'log' => false, + 'weight' => true, + 'page' => false, + 'add' => true, + ], 'cloudflare' => [ 'name' => 'Cloudflare', 'config' => [ @@ -147,6 +162,20 @@ class DnsHelper 'page' => true, 'add' => false, ], + 'spaceship' => [ + 'name' => 'Spaceship', + 'config' => [ + 'ak' => 'API Key', + 'sk' => 'Api Secret', + ], + 'remark' => 0, + 'status' => false, + 'redirect' => true, + 'log' => false, + 'weight' => false, + 'page' => false, + 'add' => true, + ], 'powerdns' => [ 'name' => 'PowerDNS', 'config' => [ @@ -162,20 +191,6 @@ class DnsHelper 'page' => true, 'add' => true, ], - 'spaceship' => [ - 'name' => 'Spaceship', - 'config' => [ - 'ak' => 'AccessKey', - 'sk' => 'SecretKey', - ], - 'remark' => 0, - 'status' => false, - 'redirect' => true, - 'log' => false, - 'weight' => false, - 'page' => false, - 'add' => true, - ], ]; public static $line_name = [ diff --git a/app/lib/deploy/ctyun.php b/app/lib/deploy/ctyun.php index 6302888..7d74b42 100644 --- a/app/lib/deploy/ctyun.php +++ b/app/lib/deploy/ctyun.php @@ -162,7 +162,7 @@ class ctyun implements DeployInterface } } try { - $client->request('POST', '/ctapi/v1/accessone/domain/modify_config', null, $result); + $client->request('POST', '/ctapi/v1/scdn/domain/modify_config', null, $result); } catch (Exception $e) { if (strpos($e->getMessage(), '请求已提交,请勿重复操作!') === false) { throw new Exception($e->getMessage()); diff --git a/app/lib/dns/bt.php b/app/lib/dns/bt.php new file mode 100644 index 0000000..21190ce --- /dev/null +++ b/app/lib/dns/bt.php @@ -0,0 +1,276 @@ +accountId = $config['ext']; + $this->accessKey = $config['ak']; + $this->secretKey = $config['sk']; + $this->domain = $config['domain']; + if ($config['domainid']) { + $a = explode('|', $config['domainid']); + $this->domainid = intval($a[0]); + $this->domainType = isset($a[1]) ? intval($a[1]) : 1; + } + $this->proxy = isset($config['proxy']) ? $config['proxy'] == 1 : false; + } + + public function getError() + { + return $this->error; + } + + public function check() + { + if ($this->getDomainList() != false) { + return true; + } + return false; + } + + //获取域名列表 + public function getDomainList($KeyWord = null, $PageNumber = 1, $PageSize = 20) + { + $param = ['p' => $PageNumber, 'rows' => $PageSize, 'keyword' => $KeyWord]; + $data = $this->execute('/api/v1/dns/manage/list_domains', $param); + if ($data) { + $list = []; + foreach ($data['data'] as $row) { + $list[] = [ + 'DomainId' => $row['local_id'] . '|' . $row['domain_type'], + 'Domain' => $row['full_domain'], + 'RecordCount' => $row['record_count'], + ]; + } + return ['total' => $data['total'], 'list' => $list]; + } + return false; + } + + //获取解析记录列表 + public function getDomainRecords($PageNumber = 1, $PageSize = 20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null) + { + $param = ['domain_id' => $this->domainid, 'domain_type' => $this->domainType, 'p' => $PageNumber, 'rows' => $PageSize]; + if (!isNullOrEmpty($SubDomain)) { + $param['searchKey'] = 'record'; + $param['searchValue'] = $SubDomain; + } elseif (!isNullOrEmpty($KeyWord)) { + $param['searchKey'] = 'record'; + $param['searchValue'] = $KeyWord; + } elseif (!isNullOrEmpty($Value)) { + $param['searchKey'] = 'value'; + $param['searchValue'] = $Value; + } elseif (!isNullOrEmpty($Type)) { + $param['searchKey'] = 'type'; + $param['searchValue'] = $Type; + } elseif (!isNullOrEmpty($Status)) { + $param['searchKey'] = 'state'; + $param['searchValue'] = $Status == '0' ? '1' : '0'; + } elseif (!isNullOrEmpty($Line)) { + $param['searchKey'] = 'line'; + $param['searchValue'] = $Line; + } + $data = $this->execute('/api/v1/dns/record/list', $param); + if ($data) { + $list = []; + foreach ($data['data'] as $row) { + $list[] = [ + 'RecordId' => $row['record_id'], + 'Domain' => $this->domain, + 'Name' => $row['record'], + 'Type' => $row['type'], + 'Value' => $row['value'], + 'Line' => $row['viewID'], + 'TTL' => $row['TTL'], + 'MX' => $row['MX'], + 'Status' => $row['state'] == 1 ? '0' : '1', + 'Weight' => $row['MX'], + 'Remark' => $row['remark'], + 'UpdateTime' => date('Y-m-d H:i:s', strtotime($row['created_at'])), + ]; + } + return ['total' => $data['count'], 'list' => $list]; + } + return false; + } + + //获取子域名解析记录列表 + public function getSubDomainRecords($SubDomain, $PageNumber = 1, $PageSize = 20, $Type = null, $Line = null) + { + if ($SubDomain == '') $SubDomain = '@'; + return $this->getDomainRecords($PageNumber, $PageSize, null, $SubDomain, null, $Type, $Line); + } + + //获取解析记录详细信息 + public function getDomainRecordInfo($RecordId) + { + return false; + } + + //添加解析记录 + public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null) + { + $param = ['domain_id' => $this->domainid, 'domain_type' => $this->domainType, 'type' => $Type, 'record' => $Name, 'value' => $Value, 'ttl' => intval($TTL), 'view_id' => intval($Line), 'remark' => $Remark]; + if (!$Weight) $Weight = 1; + if ($Type == 'MX') $param['mx'] = intval($MX); + else $param['mx'] = intval($Weight); + $data = $this->execute('/api/v1/dns/record/create', $param); + return $data !== false; + } + + //修改解析记录 + public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null) + { + $param = ['record_id' => $RecordId, 'domain_id' => $this->domainid, 'domain_type' => $this->domainType, 'type' => $Type, 'record' => $Name, 'value' => $Value, 'ttl' => intval($TTL), 'view_id' => intval($Line), 'remark' => $Remark]; + if (!$Weight) $Weight = 1; + if ($Type == 'MX') $param['mx'] = intval($MX); + else $param['mx'] = intval($Weight); + $data = $this->execute('/api/v1/dns/record/update', $param); + return $data !== false; + } + + //修改解析记录备注 + public function updateDomainRecordRemark($RecordId, $Remark) + { + return false; + } + + //删除解析记录 + public function deleteDomainRecord($RecordId) + { + $param = ['id' => $RecordId, 'domain_id' => $this->domainid, 'domain_type' => $this->domainType]; + $data = $this->execute('/api/v1/dns/record/delete', $param); + return $data !== false; + } + + //设置解析记录状态 + public function setDomainRecordStatus($RecordId, $Status) + { + $param = ['record_id' => $RecordId, 'domain_id' => $this->domainid, 'domain_type' => $this->domainType]; + $data = $this->execute($Status == '0' ? '/api/v1/dns/record/pause' : '/api/v1/dns/record/start', $param); + return $data !== false; + } + + //获取解析记录操作日志 + public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null) + { + return false; + } + + //获取解析线路列表 + public function getRecordLine() + { + $param = []; + $data = $this->execute('/api/v1/dns/record/get_views', $param); + if ($data) { + $list = []; + $this->processLineList($list, $data, null); + return $list; + } + return false; + } + + private function processLineList(&$list, $line_list, $parent) + { + foreach ($line_list as $row) { + if ($row['free'] && !isset($list[$row['viewId']])) { + $list[$row['viewId']] = ['name' => $row['name'], 'parent' => $parent]; + if ($row['children']) { + $this->processLineList($list, $row['children'], $row['viewId']); + } + } + } + } + + //获取域名信息 + public function getDomainInfo() + { + return false; + } + + //获取域名最低TTL + public function getMinTTL() + { + return 300; + } + + public function addDomain($Domain) + { + $param = ['full_domain' => $Domain]; + $data = $this->execute('/api/v1/dns/manage/add_external_domain', $param); + if ($data) { + return ['id' => $data['domain_id'], 'name' => $data['full_domain']]; + } + return false; + } + + private function execute($path, $params) + { + $method = 'POST'; + $timestamp = (string)time(); + $body = json_encode($params); + $signingString = implode("\n", [ + $this->accountId, + $timestamp, + $method, + $path, + $body + ]); + $signature = hash_hmac('sha256', $signingString, $this->secretKey); + $headers = [ + 'Content-Type' => 'application/json', + 'X-Account-ID' => $this->accountId, + 'X-Access-Key' => $this->accessKey, + 'X-Timestamp' => $timestamp, + 'X-Signature' => $signature + ]; + $response = $this->curl($method, $path, $headers, $body); + if (!$response) { + return false; + } + $arr = json_decode($response, true); + if ($arr) { + if ($arr['code'] == 0) { + return $arr['data']; + } else { + $this->setError($arr['msg']); + return false; + } + } else { + $this->setError('返回数据解析失败'); + return false; + } + } + + private function curl($method, $path, $header, $body = null) + { + $url = $this->baseUrl . $path; + try { + $response = http_request($url, $body, null, null, $header, $this->proxy, $method); + } catch (\Exception $e) { + $this->setError($e->getMessage()); + return false; + } + return $response['body']; + } + + private function setError($message) + { + $this->error = $message; + } +} diff --git a/app/lib/dns/dnsla.php b/app/lib/dns/dnsla.php index cc57513..75c0e71 100644 --- a/app/lib/dns/dnsla.php +++ b/app/lib/dns/dnsla.php @@ -60,19 +60,19 @@ class dnsla implements DnsInterface public function getDomainRecords($PageNumber = 1, $PageSize = 20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null) { $param = ['domainId' => $this->domainid, 'pageIndex' => $PageNumber, 'pageSize' => $PageSize]; - if (!isNullOrEmpty(($KeyWord))) { + if (!isNullOrEmpty($KeyWord)) { $param['host'] = $KeyWord; } - if (!isNullOrEmpty(($Type))) { + if (!isNullOrEmpty($Type)) { $param['type'] = $this->convertType($Type); } - if (!isNullOrEmpty(($Line))) { + if (!isNullOrEmpty($Line)) { $param['lineId'] = $Line; } - if (!isNullOrEmpty(($SubDomain))) { + if (!isNullOrEmpty($SubDomain)) { $param['host'] = $SubDomain; } - if (!isNullOrEmpty(($Value))) { + if (!isNullOrEmpty($Value)) { $param['data'] = $Value; } $data = $this->execute('GET', '/api/recordList', $param); diff --git a/app/lib/dns/spaceship.php b/app/lib/dns/spaceship.php index 1f5dabd..9546681 100644 --- a/app/lib/dns/spaceship.php +++ b/app/lib/dns/spaceship.php @@ -57,85 +57,6 @@ class spaceship implements DnsInterface } //获取解析记录列表 - - private function send_reuqest($method, $path, $params = null) - { - $url = $this->baseUrl . $path; - - $headers = [ - 'X-API-Key: ' . $this->apiKey, - 'X-API-Secret: ' . $this->apiSecret, - ]; - - $body = ''; - if ($method == 'GET') { - if ($params) { - $url .= '?' . http_build_query($params); - } - } else { - $body = json_encode($params); - $headers[] = 'Content-Type: application/json'; - } - - $ch = curl_init($url); - if ($this->proxy) { - curl_set_proxy($ch); - } - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_TIMEOUT, 10); - if ($method == 'POST') { - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $body); - } elseif ($method == 'PUT') { - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); - curl_setopt($ch, CURLOPT_POSTFIELDS, $body); - } elseif ($method == 'PATCH') { - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); - curl_setopt($ch, CURLOPT_POSTFIELDS, $body); - } elseif ($method == 'DELETE') { - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); - curl_setopt($ch, CURLOPT_POSTFIELDS, $body); - } - $response = curl_exec($ch); - $errno = curl_errno($ch); - - if ($errno) { - $this->setError('Curl error: ' . curl_error($ch)); - } - - curl_close($ch); - if ($errno) return false; - - $arr = json_decode($response, true); - if (!isset($arr['detail'])) { - return $arr; - } else { - $this->setError($response['detail']); - return false; - } - } - - //获取子域名解析记录列表 - - private function setError($message) - { - $this->error = $message; - //file_put_contents('logs.txt',date('H:i:s').' '.$message."\r\n", FILE_APPEND); - } - - //获取解析记录详细信息 - - public function getSubDomainRecords($SubDomain, $PageNumber = 1, $PageSize = 20, $Type = null, $Line = null) - { - if ($SubDomain == '') $SubDomain = '@'; - return $this->getDomainRecords($PageNumber, $PageSize, null, $SubDomain, null, $Type, $Line); - } - - //添加解析记录 - public function getDomainRecords($PageNumber = 1, $PageSize = 20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null) { $param = ['take' => $PageSize, 'skip' => ($PageNumber - 1) * $PageSize]; @@ -148,39 +69,26 @@ class spaceship implements DnsInterface foreach ($data['items'] as $row) { $type = $row['type']; $name = $row['name']; + $mx = 0; if ('MX' == $type) { $address = $row['exchange']; $mx = $row['preference']; } else if ('CNAME' == $type) { $address = $row['cname']; - $mx = 0; } else if ('TXT' == $type) { $address = $row['value']; - $mx = 0; } else if ('PTR' == $type) { $address = $row['pointer']; - $mx = 0; } else if ('NS' == $type) { $address = $row['nameserver']; - $mx = 0; - } else if ('HTTPS' == $type) { - $address = $row['targetName'] . $row['svcParams'] . '|' . $row['svcPriority']; - $mx = 0; } else if ('CAA' == $type) { - $address = $row['value']; - $mx = 0; - } else if ('TLSA' == $type) { - $address = $row['associationData']; - $mx = 0; - } else if ('SVRB' == $type) { - $address = $row['targetName'] . $row['svcParams'] . '|' . $row['svcPriority']; - $mx = 0; + $address = $row['flag'] . ' ' . $row['tag'] . ' ' . $row['value']; + } else if ('SRV' == $type) { + $address = $row['priority'] . ' ' . $row['weight'] . ' ' . $row['port'] . ' ' . $row['target']; } else if ('ALIAS' == $type) { $address = $row['aliasName']; - $mx = 0; } else { $address = $row['address']; - $mx = 0; } $list[] = [ @@ -203,67 +111,96 @@ class spaceship implements DnsInterface return false; } - //修改解析记录 + //获取子域名解析记录列表 + public function getSubDomainRecords($SubDomain, $PageNumber = 1, $PageSize = 20, $Type = null, $Line = null) + { + if ($SubDomain == '') $SubDomain = '@'; + return $this->getDomainRecords($PageNumber, $PageSize, null, $SubDomain, null, $Type, $Line); + } + //获取解析记录详细信息 public function getDomainRecordInfo($RecordId) { return false; } - //修改解析记录备注 + private function convertRecordItem($Name, $Type, $Value, $MX = 1) + { + $item = [ + 'type' => $Type, + 'name' => $Name, + ]; + if ($Type == 'MX') { + $item['exchange'] = $Value; + $item['preference'] = (int)$MX; + } else if ($Type == 'TXT') { + $item['value'] = $Value; + } else if ($Type == 'CNAME') { + $item['cname'] = $Value; + } else if ($Type == 'ALIAS') { + $item['aliasName'] = $Value; + } else if ($Type == 'NS') { + $item['nameserver'] = $Value; + } else if ($Type == 'PTR') { + $item['pointer'] = $Value; + } else if ($Type == 'CAA') { + $parts = explode(' ', $Value, 3); + if (count($parts) >= 3) { + $item['flag'] = (int)$parts[0]; + $item['tag'] = $parts[1]; + $item['value'] = trim($parts[2], '"'); + } + } else if ($Type == 'SRV') { + $parts = explode(' ', $Value, 4); + if (count($parts) >= 4) { + $item['priority'] = (int)$parts[0]; + $item['weight'] = (int)$parts[1]; + $item['port'] = (int)$parts[2]; + $item['target'] = $parts[3]; + } + } else { + $item['address'] = $Value; + } + return $item; + } + //添加解析记录 public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null) { + $item = $this->convertRecordItem($Name, $Type, $Value, $MX); + $item['ttl'] = (int)$TTL; $param = [ - 'force' => true, + 'force' => false, 'items' => [ - [ - 'type' => $this->convertType($Type), - 'name' => $Name, - 'address' => $Value, - 'ttl' => $TTL, - ] + $item ] ]; $data = $this->send_reuqest('PUT', '/dns/records/' . $this->domain, $param); return !isset($data); } - //删除解析记录 - - private function convertType($type) - { - return $type; - } - - //设置解析记录状态 - + //修改解析记录 public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null) { + $item = $this->convertRecordItem($Name, $Type, $Value, $MX); + $item['ttl'] = (int)$TTL; $param = [ 'force' => true, 'items' => [ - [ - 'type' => $this->convertType($Type), - 'name' => $Name, - 'address' => $Value, - 'ttl' => $TTL, - ] + $item ] ]; $data = $this->send_reuqest('PUT', '/dns/records/' . $this->domain, $param); return !isset($data); } - //获取解析记录操作日志 - + //修改解析记录备注 public function updateDomainRecordRemark($RecordId, $Remark) { return false; } - //获取解析线路列表 - + //删除解析记录 public function deleteDomainRecord($RecordId) { $array = explode("|", $RecordId); @@ -271,66 +208,25 @@ class spaceship implements DnsInterface $name = $array[1]; $address = $array[2]; $mx = $array[3]; - if ('MX' == $type) { - $param = [ - [ - 'type' => $type, - 'name' => $name, - 'exchange' => $address, - 'preference' => (int)$mx, - ] - ]; - } else if ('TXT' == $type) { - $param = [ - [ - 'type' => $type, - 'name' => $name, - 'value' => $address, - ] - ]; - } else if ('CNAME' == $type) { - $param = [ - [ - 'type' => $type, - 'name' => $name, - 'cname' => $address, - ] - ]; - } else if ('ALIAS' == $type) { - $param = [ - [ - 'type' => $type, - 'name' => $name, - 'aliasName' => $address, - ] - ]; - } else { - $param = [ - [ - 'type' => $type, - 'name' => $name, - 'address' => $address, - ] - ]; - } + $item = $this->convertRecordItem($name, $type, $address, $mx); + $param = [$item]; $data = $this->send_reuqest('DELETE', '/dns/records/' . $this->domain, $param); return !isset($data); } - //获取域名信息 - + //设置解析记录状态 public function setDomainRecordStatus($RecordId, $Status) { return false; } - //获取域名最低TTL - + //获取解析记录操作日志 public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null) { return false; } + //获取解析线路列表 public function getRecordLine() { return ['default' => ['name' => '默认', 'parent' => null]]; @@ -350,4 +246,43 @@ class spaceship implements DnsInterface { return false; } -} \ No newline at end of file + + private function send_reuqest($method, $path, $params = null) + { + $url = $this->baseUrl . $path; + $headers = [ + 'X-API-Key' => $this->apiKey, + 'X-API-Secret' => $this->apiSecret, + ]; + $body = ''; + if ($method == 'GET') { + if ($params) { + $url .= '?' . http_build_query($params); + } + } else { + $body = json_encode($params); + $headers['Content-Type'] = 'application/json'; + } + try { + $response = http_request($url, $body, null, null, $headers, $this->proxy, $method); + } catch (\Exception $e) { + $this->setError($e->getMessage()); + return false; + } + $arr = json_decode($response['body'], true); + if ($response['code'] == 200 || $response['code'] == 204) { + return $arr; + } elseif (isset($arr['detail'])) { + $this->setError($arr['detail']); + return false; + } else { + $this->setError('http code: ' . $response['code']); + return false; + } + } + + private function setError($message) + { + $this->error = $message; + } +} diff --git a/public/static/images/bt.ico b/public/static/images/bt.ico new file mode 100644 index 0000000..0a5d0ea Binary files /dev/null and b/public/static/images/bt.ico differ