72 行
2.1 KiB
PHP
72 行
2.1 KiB
PHP
<?php
|
|
require_once '../config.php';
|
|
require_once '../lib/AliyunDnsClient.php';
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
$config = require '../config.php';
|
|
|
|
$allowedIps = $config['api']['allowed_ips'];
|
|
$clientIp = $_SERVER['REMOTE_ADDR'];
|
|
|
|
if ($allowedIps !== '*' && !in_array($clientIp, $allowedIps)) {
|
|
echo json_encode(['code' => 403, 'message' => 'Access denied']);
|
|
exit;
|
|
}
|
|
|
|
$token = $_POST['token'] ?? $_GET['token'] ?? null;
|
|
if ($token !== $config['api']['token']) {
|
|
echo json_encode(['code' => 403, 'message' => 'Invalid token']);
|
|
exit;
|
|
}
|
|
|
|
$domainName = $_GET['domain_name'] ?? null;
|
|
$rrKeyWord = $_GET['rr_keyword'] ?? null;
|
|
$type = $_GET['type'] ?? null;
|
|
$pageNumber = $_GET['page'] ?? 1;
|
|
$pageSize = $_GET['page_size'] ?? 20;
|
|
|
|
if (!$domainName) {
|
|
echo json_encode(['code' => 400, 'message' => 'Missing required parameter: domain_name']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$client = new AliyunDnsClient(
|
|
$config['aliyun']['access_key_id'],
|
|
$config['aliyun']['access_key_secret'],
|
|
$config['aliyun']['endpoint'],
|
|
$config['aliyun']['region_id']
|
|
);
|
|
|
|
$result = $client->describeDomainRecords($domainName, $rrKeyWord, $type, $pageNumber, $pageSize);
|
|
|
|
$records = [];
|
|
if (isset($result['DomainRecords']['Record'])) {
|
|
foreach ($result['DomainRecords']['Record'] as $record) {
|
|
$records[] = [
|
|
'record_id' => $record['RecordId'],
|
|
'rr' => $record['RR'],
|
|
'type' => $record['Type'],
|
|
'value' => $record['Value'],
|
|
'ttl' => $record['TTL'],
|
|
'priority' => $record['Priority'] ?? null,
|
|
'status' => $record['Status']
|
|
];
|
|
}
|
|
}
|
|
|
|
echo json_encode([
|
|
'code' => 200,
|
|
'message' => 'Success',
|
|
'data' => [
|
|
'total' => $result['TotalCount'] ?? 0,
|
|
'page' => $pageNumber,
|
|
'page_size' => $pageSize,
|
|
'records' => $records
|
|
]
|
|
]);
|
|
} catch (Exception $e) {
|
|
echo json_encode(['code' => 500, 'message' => $e->getMessage()]);
|
|
}
|
|
?>
|