* @link https://www.cloudxns.net/ * @copyright Copyright (c) 2015 Cloudxns. */ require_once '../vendor/autoload.php'; use CloudXNS\Api; $api->setApiKey('xxxxxxxxxx'); $api->setSecretKey('xxxxxxxxxx'); $protocol = true; $action = isset($_POST['action']) ? $_POST['action'] : 'domainList'; if (empty($apiKey) || empty($secretKey)) { ajaxReturn(20000, 'API KEY或者SECRET KEY不能为空!'); } $api = new Api(); $api->setApiKey($apiKey); $api->setSecretKey($secretKey); if ($protocol) { $api->setProtocol(false); } else { $api->setProtocol(true); } switch ($action) { case 'domainList': domainList($api); break; case 'domainAdd': domainAdd($api); break; case 'domainDelete': domainDelete($api); break; case 'typeList': typeList($api); break; case 'nsList': nsList($api); break; case 'hostList': hostList($api); break; case 'hostDelete': hostDelete($api); break; case 'lineList': lineList($api); break; case 'regionList': regionList($api); break; case 'ispList': ispList($api); break; case 'statisticsList': statisticsList($api); break; case 'recordList': recordList($api); break; case 'recordAdd': recordAdd($api); break; case 'spareAdd': spareAdd($api); break; case 'recordUpdate': recordUpdate($api); break; case 'recordDelete': recordDelete($api); break; default: return false; } /** * 域名列表 * * @return string */ function domainList($api) { $domain = json_decode($api->domain->domainList(), true); $html = '暂无数据'; if (!empty($domain['data'])) { $html = ''; foreach ($domain['data'] as $k => $v) { $html .= " {$v['id']} {$v['domain']} {$v['status']} {$v['take_over_status']} {$v['level']} {$v['ttl']} 删除 "; } } ajaxReturn(1, $html); } /** * 域名的添加 * * @return string */ function domainAdd($api) { $domainName = isset($_POST['domain']) ? $_POST['domain'] : ''; if (empty($domainName)) { ajaxReturn(30000, '域名不能为空!'); } echo $api->domain->domainAdd($domainName); } /** * 域名的删除 * * @return string */ function domainDelete($api) { $id = isset($_POST['id']) ? intval($_POST['id']) : 0; if (empty($id)) { ajaxReturn(30001, '域名ID不能为空!'); } echo $api->domain->domainDelete($id); } /** * 记录类型列表 * * @return string */ function typeList($api) { $type = json_decode($api->recordType->typeList(), true); $html = ''; if (!empty($type['data'])) { $data = implode(', ', $type['data']); $html .= " {$data} "; } ajaxReturn(1, $html); } /** * ns服务器列表 * * @return string */ function nsList($api) { $ns = json_decode($api->ns->nsList(), true); $html = ''; if (!empty($ns['data'])) { foreach ($ns['data'] as $k => $v) { $server = implode(', ', $v['ns_server']); $html .= " 域名等级:{$v['level']} {$server} "; } } ajaxReturn(1, $html); } /** * 主机列表 * * @return string */ function hostList($api) { $id = isset($_POST['id']) ? intval($_POST['id']) : 0; if (empty($id)) { ajaxReturn(30001, '域名ID不能为空!'); } $host = json_decode($api->host->hostList($id), true); $html = '暂无数据'; if (!empty($host['hosts'])) { $html = ''; foreach ($host['hosts'] as $k => $v) { $html .= " {$v['id']} {$v['host']} {$v['record_num']} {$v['domain_name']} 删除 "; } } ajaxReturn(1, $html); } /** * 删除主机 * * @return string */ function hostDelete($api) { $id = isset($_POST['id']) ? intval($_POST['id']) : 0; if (empty($id)) { ajaxReturn(30001, '域名ID不能为空!'); } echo $api->host->hostDelete($id); } /** * 线路列表 * * @return string */ function lineList($api) { $line = json_decode($api->line->lineList(), true); $html = ''; if (!empty($line['data'])) { $html .= '' . '' . '' . '' . '' . '' . '
默认运营商区域组省份
'; $html .= doLine($line['data']); } ajaxReturn(1, $html); } /** * 区域列表 * * @return string */ function regionList($api) { $region = json_decode($api->line->regionList(), true); $html = ''; if (!empty($region['data'])) { $html = '' . '' . '' . '' . '' . ''; foreach ($region['data'] as $k => $v) { $html .= ""; } $html .= '
组成区域的线路id中文名称英文名称
{$v['id']} {$v['chinese_name']} {$v['english_name']}
'; } ajaxReturn(1, $html); } /** * isp列表 * * @return string */ function ispList($api) { $isp = json_decode($api->line->ispList(), true); $html = ''; if (!empty($isp['data'])) { $html = '' . '' . '' . '' . '' . ''; foreach ($isp['data'] as $k => $v) { $html .= ""; } $html .= '
组成ISP的线路id中文名称英文名称
{$v['id']} {$v['chinese_name']} {$v['english_name']}
'; } ajaxReturn(1, $html); } /** * 处理线路列表的数据 */ function doLine($arr) { $html = ''; foreach ($arr as $k => $v) { $html .= ""; $html .= ""; if (array_key_exists('children', $v) && !empty($v['children'])) { $html .= ""; } $html .= ""; } $html .= '
{$v['chinese_name']}[{$v['id']}]"; $html .= doLine($v['children']); $html .= "
'; return $html; } /** * 域名的统计 */ function statisticsList($api) { $id = isset($_POST['id']) ? intval($_POST['id']) : 0; $host = isset($_POST['host']) ? $_POST['host'] : 'all'; $code = isset($_POST['code']) ? $_POST['code'] : 'all'; $startTime = isset($_POST['startTime']) ? $_POST['startTime'] : 0; $endTime = isset($_POST['endTime']) ? $_POST['endTime'] : 0; echo $api->statistics->statisticsList($id, $host, $code, $startTime, $endTime); } /** * 解析记录列表 * * @return string */ function recordList($api) { $id = isset($_POST['id']) ? intval($_POST['id']) : 0; $hostId = isset($_POST['hostId']) ? intval($_POST['hostId']) : 0; $record = json_decode($api->record->recordList($id, $hostId, 0, 30), true); $html = '暂无数据'; if (!empty($record['data'])) { $html = ''; foreach ($record['data'] as $k => $v) { if (array_key_exists('spare_value', $v)) { $spareHtml = ""; $bakIp = $v['spare_value']; } else { $spareHtml = "添加备IP"; $bakIp = ''; } $html .= " {$v['host']} {$v['type']} {$v['line_zh']} {$v['mx']} {$v['value']}{$spareHtml} {$v['status']} 编辑 删除 "; } } ajaxReturn(1, $html); } /** * 新增解析记录 * * @return string */ function recordAdd($api) { $id = isset($_POST['id']) ? intval($_POST['id']) : 0; $host = isset($_POST['host']) ? $_POST['host'] : ''; $value = isset($_POST['value']) ? $_POST['value'] : ''; $type = isset($_POST['type']) ? $_POST['type'] : ''; $mx = isset($_POST['mx']) ? $_POST['mx'] : ''; $ttl = isset($_POST['ttl']) ? $_POST['ttl'] : ''; $lineId = isset($_POST['lineId']) ? intval($_POST['lineId']) : 1; echo $api->record->recordAdd($id, $host, $value, $type, $mx, $ttl, $lineId); } /** * 新增备记录 * * @return string */ function spareAdd($api) { $id = isset($_POST['id']) ? intval($_POST['id']) : 0; $hostId = isset($_POST['hostId']) ? intval($_POST['hostId']) : 0; $recordId = isset($_POST['recordId']) ? intval($_POST['recordId']) : 0; $value = isset($_POST['value']) ? $_POST['value'] : ''; echo $api->record->spareAdd($id, $hostId, $recordId, $value); } /** * 更新解析记录 * * @return string */ function recordUpdate($api) { $id = isset($_POST['id']) ? intval($_POST['id']) : 0; $host = isset($_POST['host']) ? $_POST['host'] : ''; $value = isset($_POST['value']) ? $_POST['value'] : ''; $type = isset($_POST['type']) ? $_POST['type'] : ''; $mx = isset($_POST['mx']) ? $_POST['mx'] : ''; $ttl = isset($_POST['ttl']) ? $_POST['ttl'] : ''; $lineId = isset($_POST['lineId']) ? intval($_POST['lineId']) : 1; $bakIp = isset($_POST['bakIp']) ? $_POST['bakIp'] : ''; $recordId = isset($_POST['record']) ? intval($_POST['record']) : 0; echo $api->record->recordUpdate($id, $host, $value, $type, $mx, $ttl, $lineId, $bakIp, $recordId); } /** * 删除解析记录 * * @return string */ function recordDelete($api) { $id = isset($_POST['id']) ? intval($_POST['id']) : 0; $record = isset($_POST['record']) ? intval($_POST['record']) : 0; echo $api->record->recordDelete($record, $id); } /** * * @param integer $code 状态码 * @param string $msg 消息提示 * @param array $data 数据的展示 */ function ajaxReturn($code, $msg = '', $data = array()) { echo json_encode(array('code' => $code, 'message' => $msg, 'data' => $data)); exit; }