mirror of
https://github.com/netcccyun/dnsmgr.git
synced 2024-11-16 03:32:28 +08:00
格式化代码
增加代理连通性测试
This commit is contained in:
parent
410a33e870
commit
a3b26085a6
|
@ -102,12 +102,14 @@ abstract class BaseController
|
|||
if ($url) {
|
||||
$url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : (string)$this->app->route->buildUrl($url);
|
||||
}
|
||||
if(empty($msg)) $msg = '未知错误';
|
||||
if (empty($msg)) {
|
||||
$msg = '未知错误';
|
||||
}
|
||||
|
||||
if (request()->isApi) {
|
||||
if ($this->request->isApi) {
|
||||
return json(['code' => $code == 'success' ? 0 : -1, 'msg' => $msg]);
|
||||
}
|
||||
if (request()->isAjax()) {
|
||||
if ($this->request->isAjax()) {
|
||||
return json(['code' => $code == 'success' ? 0 : -1, 'msg' => $msg, 'url' => $url]);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
@ -42,7 +43,8 @@ class Dmtask extends Command
|
|||
}
|
||||
}
|
||||
|
||||
private function runtask(){
|
||||
private function runtask()
|
||||
{
|
||||
\Co::set(['hook_flags' => SWOOLE_HOOK_ALL]);
|
||||
\Co\run(function () {
|
||||
$date = date("Ymd");
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
|
175
app/common.php
175
app/common.php
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
// 应用公共文件
|
||||
use think\facade\Db;
|
||||
use think\facade\Request;
|
||||
|
||||
function get_curl($url, $post = 0, $referer = 0, $cookie = 0, $header = 0, $ua = 0, $nobody = 0, $addheader = 0)
|
||||
{
|
||||
|
@ -31,8 +32,7 @@ function get_curl($url, $post=0, $referer=0, $cookie=0, $header=0, $ua=0, $nobod
|
|||
}
|
||||
if ($ua) {
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; U; Android 4.0.4; es-mx; HTC_One_X Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0");
|
||||
}
|
||||
if ($nobody) {
|
||||
|
@ -45,10 +45,11 @@ function get_curl($url, $post=0, $referer=0, $cookie=0, $header=0, $ua=0, $nobod
|
|||
return $ret;
|
||||
}
|
||||
|
||||
function real_ip($type=0){
|
||||
function real_ip($type = 0)
|
||||
{
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
if ($type <= 0 && isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
|
||||
foreach ($matches[0] AS $xip) {
|
||||
foreach ($matches[0] as $xip) {
|
||||
if (filter_var($xip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
|
||||
$ip = $xip;
|
||||
break;
|
||||
|
@ -64,11 +65,13 @@ function real_ip($type=0){
|
|||
return $ip;
|
||||
}
|
||||
|
||||
function strexists($string, $find) {
|
||||
function strexists($string, $find)
|
||||
{
|
||||
return !(strpos($string, $find) === FALSE);
|
||||
}
|
||||
|
||||
function dstrpos($string, $arr) {
|
||||
function dstrpos($string, $arr)
|
||||
{
|
||||
if (empty($string)) return false;
|
||||
foreach ((array)$arr as $v) {
|
||||
if (strpos($string, $v) !== false) {
|
||||
|
@ -78,16 +81,19 @@ function dstrpos($string, $arr) {
|
|||
return false;
|
||||
}
|
||||
|
||||
function checkmobile() {
|
||||
function checkmobile()
|
||||
{
|
||||
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
|
||||
$ualist = array('android', 'midp', 'nokia', 'mobile', 'iphone', 'ipod', 'blackberry', 'windows phone');
|
||||
if((dstrpos($useragent, $ualist) || strexists($_SERVER['HTTP_ACCEPT'], "VND.WAP") || strexists($_SERVER['HTTP_VIA'],"wap")))
|
||||
if ((dstrpos($useragent, $ualist) || strexists($_SERVER['HTTP_ACCEPT'], "VND.WAP") || strexists($_SERVER['HTTP_VIA'], "wap"))) {
|
||||
return true;
|
||||
else
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
|
||||
function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0)
|
||||
{
|
||||
$ckey_length = 4;
|
||||
$key = md5($key);
|
||||
$keya = md5(substr($key, 0, 16));
|
||||
|
@ -128,7 +134,8 @@ function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
|
|||
}
|
||||
}
|
||||
|
||||
function random($length, $numeric = 0) {
|
||||
function random($length, $numeric = 0)
|
||||
{
|
||||
$seed = base_convert(md5(microtime().$_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
|
||||
$seed = $numeric ? (str_replace('0', '', $seed).'012340567890') : ($seed.'zZ'.strtoupper($seed));
|
||||
$hash = '';
|
||||
|
@ -139,7 +146,8 @@ function random($length, $numeric = 0) {
|
|||
return $hash;
|
||||
}
|
||||
|
||||
function checkDomain($domain){
|
||||
function checkDomain($domain)
|
||||
{
|
||||
if (empty($domain) || !preg_match('/^[-$a-z0-9_*.]{2,512}$/i', $domain) || (stripos($domain, '.') === false) || substr($domain, -1) == '.' || substr($domain, 0, 1) == '.' || substr($domain, 0, 1) == '*' && substr($domain, 1, 1) != '.' || substr_count($domain, '*') > 1 || strpos($domain, '*') > 0 || strlen($domain) < 4) return false;
|
||||
return true;
|
||||
}
|
||||
|
@ -157,40 +165,57 @@ function getSubstr($str, $leftStr, $rightStr)
|
|||
}
|
||||
}
|
||||
|
||||
function checkRefererHost(){
|
||||
if(!request()->header('referer'))return false;
|
||||
$url_arr = parse_url(request()->header('referer'));
|
||||
$http_host = request()->header('host');
|
||||
if(strpos($http_host,':'))$http_host = substr($http_host, 0, strpos($http_host, ':'));
|
||||
function checkRefererHost()
|
||||
{
|
||||
if (!Request::header('referer')) {
|
||||
return false;
|
||||
}
|
||||
$url_arr = parse_url(Request::header('referer'));
|
||||
$http_host = Request::header('host');
|
||||
if (strpos($http_host, ':')) {
|
||||
$http_host = substr($http_host, 0, strpos($http_host, ':'));
|
||||
}
|
||||
return $url_arr['host'] === $http_host;
|
||||
}
|
||||
|
||||
function checkIfActive($string) {
|
||||
function checkIfActive($string)
|
||||
{
|
||||
$array = explode(',', $string);
|
||||
$action = request()->action();
|
||||
$action = Request::action();
|
||||
if (in_array($action, $array)) {
|
||||
return 'active';
|
||||
}else
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function getSid() {
|
||||
function getSid()
|
||||
{
|
||||
return md5(uniqid(mt_rand(), true) . microtime());
|
||||
}
|
||||
function getMd5Pwd($pwd, $salt=null) {
|
||||
function getMd5Pwd($pwd, $salt = null)
|
||||
{
|
||||
return md5(md5($pwd) . md5('1277180438'.$salt));
|
||||
}
|
||||
|
||||
function isNullOrEmpty($str){
|
||||
function isNullOrEmpty($str)
|
||||
{
|
||||
return $str === null || $str === '';
|
||||
}
|
||||
|
||||
function checkPermission($type, $domain = null){
|
||||
$user = request()->user;
|
||||
if(empty($user)) return false;
|
||||
if($user['level'] == 2) return true;
|
||||
function checkPermission($type, $domain = null)
|
||||
{
|
||||
$user = Request()->user;
|
||||
if (empty($user)) {
|
||||
return false;
|
||||
}
|
||||
if ($user['level'] == 2) {
|
||||
return true;
|
||||
}
|
||||
if ($type == 1 && $user['level'] == 1 || $type == 0 && $user['level'] >= 0) {
|
||||
if($domain == null) return true;
|
||||
if ($domain == null) {
|
||||
return true;
|
||||
}
|
||||
if (in_array($domain, $user['permission'])) {
|
||||
return true;
|
||||
}
|
||||
|
@ -198,7 +223,8 @@ function checkPermission($type, $domain = null){
|
|||
return false;
|
||||
}
|
||||
|
||||
function getAdminSkin(){
|
||||
function getAdminSkin()
|
||||
{
|
||||
$skin = cookie('admin_skin');
|
||||
if (empty($skin)) {
|
||||
$skin = config_get('admin_skin');
|
||||
|
@ -231,13 +257,19 @@ function getMillisecond()
|
|||
return (int)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
|
||||
}
|
||||
|
||||
function getDnsType($value){
|
||||
if(filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))return 'A';
|
||||
else if(filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))return 'AAAA';
|
||||
else return 'CNAME';
|
||||
function getDnsType($value)
|
||||
{
|
||||
if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
|
||||
return 'A';
|
||||
} elseif (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
||||
return 'AAAA';
|
||||
} else {
|
||||
return 'CNAME';
|
||||
}
|
||||
}
|
||||
|
||||
function convert_second($s){
|
||||
function convert_second($s)
|
||||
{
|
||||
$m = floor($s / 60);
|
||||
if ($m == 0) {
|
||||
return $s.'秒';
|
||||
|
@ -252,3 +284,78 @@ function convert_second($s){
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function check_proxy($url, $proxy_server, $proxy_port, $type, $proxy_user, $proxy_pwd)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
if ($type == 'https') {
|
||||
$proxy_type = CURLPROXY_HTTPS;
|
||||
} elseif ($type == 'sock4') {
|
||||
$proxy_type = CURLPROXY_SOCKS4;
|
||||
} elseif ($type == 'sock5') {
|
||||
$proxy_type = CURLPROXY_SOCKS5;
|
||||
} else {
|
||||
$proxy_type = CURLPROXY_HTTP;
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
|
||||
curl_setopt($ch, CURLOPT_PROXY, $proxy_server);
|
||||
curl_setopt($ch, CURLOPT_PROXYPORT, intval($proxy_port));
|
||||
if (!empty($proxy_user) && !empty($proxy_pwd)) {
|
||||
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_user . ':' . $proxy_pwd);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_PROXYTYPE, $proxy_type);
|
||||
$httpheader[] = "Accept: */*";
|
||||
$httpheader[] = "Accept-Language: zh-CN,zh;q=0.8";
|
||||
$httpheader[] = "Connection: close";
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36');
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
|
||||
curl_exec($ch);
|
||||
$errno = curl_errno($ch);
|
||||
if ($errno) {
|
||||
$errmsg = curl_error($ch);
|
||||
curl_close($ch);
|
||||
throw new Exception($errmsg);
|
||||
}
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
if ($httpCode >= 200 && $httpCode < 400) {
|
||||
return true;
|
||||
} else {
|
||||
throw new Exception('HTTP状态码异常:' . $httpCode);
|
||||
}
|
||||
}
|
||||
|
||||
function clearDirectory($dir): bool
|
||||
{
|
||||
// 确保路径是目录
|
||||
if (!is_dir($dir)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 打开目录
|
||||
$items = scandir($dir);
|
||||
foreach ($items as $item) {
|
||||
// 跳过 '.' 和 '..'
|
||||
if ($item == '.' || $item == '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 完整路径
|
||||
$path = $dir . DIRECTORY_SEPARATOR . $item;
|
||||
|
||||
// 如果是目录,递归删除其内容
|
||||
if (is_dir($path)) {
|
||||
clearDirectory($path);
|
||||
// 删除空目录
|
||||
rmdir($path);
|
||||
} else {
|
||||
// 删除文件
|
||||
unlink($path);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
|
@ -1,29 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use app\BaseController;
|
||||
use Exception;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
use app\lib\DnsHelper;
|
||||
|
||||
class Auth extends BaseController
|
||||
{
|
||||
|
||||
public function verifycode()
|
||||
public function login()
|
||||
{
|
||||
return captcha();
|
||||
}
|
||||
|
||||
public function login(){
|
||||
$login_limit_count = 5; //登录失败次数
|
||||
$login_limit_file = app()->getRuntimePath() . '@login.lock';
|
||||
|
||||
if(request()->islogin){
|
||||
if ($this->request->islogin) {
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
if(request()->isAjax()){
|
||||
if ($this->request->isAjax()) {
|
||||
$username = input('post.username', null, 'trim');
|
||||
$password = input('post.password', null, 'trim');
|
||||
$code = input('post.code', null, 'trim');
|
||||
|
@ -37,7 +31,7 @@ class Auth extends BaseController
|
|||
if (file_exists($login_limit_file)) {
|
||||
$login_limit = unserialize(file_get_contents($login_limit_file));
|
||||
if ($login_limit['count'] >= $login_limit_count && $login_limit['time'] > time() - 7200) {
|
||||
exit(json_encode(['code' => -1, 'msg' => '多次登录失败,暂时禁止登录。可删除/runtime/@login.lock文件解除限制', 'vcode'=>1]));
|
||||
return json(['code' => -1, 'msg' => '多次登录失败,暂时禁止登录。可删除/runtime/@login.lock文件解除限制', 'vcode' => 1]);
|
||||
}
|
||||
}
|
||||
$user = Db::name('user')->where('username', $username)->find();
|
||||
|
@ -115,4 +109,9 @@ class Auth extends BaseController
|
|||
cookie('user_token', $token, ['expire' => $expiretime, 'httponly' => true]);
|
||||
return redirect('/record/' . $row['id']);
|
||||
}
|
||||
|
||||
public function verifycode()
|
||||
{
|
||||
return captcha();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use app\BaseController;
|
||||
|
@ -6,7 +7,6 @@ use Exception;
|
|||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
use think\facade\Cache;
|
||||
use app\lib\DnsHelper;
|
||||
|
||||
class Dmonitor extends BaseController
|
||||
{
|
||||
|
@ -36,7 +36,8 @@ class Dmonitor extends BaseController
|
|||
return View::fetch();
|
||||
}
|
||||
|
||||
public function task_data(){
|
||||
public function task_data()
|
||||
{
|
||||
if (!checkPermission(2)) return json(['total' => 0, 'rows' => []]);
|
||||
$type = input('post.type/d', 1);
|
||||
$kw = input('post.kw', null, 'trim');
|
||||
|
@ -71,7 +72,7 @@ class Dmonitor extends BaseController
|
|||
{
|
||||
if (!checkPermission(2)) return $this->alert('error', '无权限');
|
||||
$action = input('param.action');
|
||||
if(request()->isPost()){
|
||||
if ($this->request->isPost()) {
|
||||
if ($action == 'add') {
|
||||
$task = [
|
||||
'did' => input('post.did/d'),
|
||||
|
@ -197,7 +198,8 @@ class Dmonitor extends BaseController
|
|||
return View::fetch();
|
||||
}
|
||||
|
||||
public function tasklog_data(){
|
||||
public function tasklog_data()
|
||||
{
|
||||
if (!checkPermission(2)) return json(['total' => 0, 'rows' => []]);
|
||||
$taskid = input('param.id/d');
|
||||
$offset = input('post.offset/d');
|
||||
|
@ -217,7 +219,7 @@ class Dmonitor extends BaseController
|
|||
public function noticeset()
|
||||
{
|
||||
if (!checkPermission(2)) return $this->alert('error', '无权限');
|
||||
if(request()->isPost()){
|
||||
if ($this->request->isPost()) {
|
||||
$params = input('post.');
|
||||
if (isset($params['mail_type']) && isset($params['mail_name2']) && $params['mail_type'] > 0) {
|
||||
$params['mail_name'] = $params['mail_name2'];
|
||||
|
@ -238,7 +240,7 @@ class Dmonitor extends BaseController
|
|||
public function proxyset()
|
||||
{
|
||||
if (!checkPermission(2)) return $this->alert('error', '无权限');
|
||||
if(request()->isPost()){
|
||||
if ($this->request->isPost()) {
|
||||
$params = input('post.');
|
||||
foreach ($params as $key => $value) {
|
||||
if (empty($key)) {
|
||||
|
@ -257,7 +259,7 @@ class Dmonitor extends BaseController
|
|||
if (!checkPermission(2)) return $this->alert('error', '无权限');
|
||||
$mail_name = config_get('mail_recv') ? config_get('mail_recv') : config_get('mail_name');
|
||||
if (empty($mail_name)) return json(['code' => -1, 'msg' => '您还未设置邮箱!']);
|
||||
$result = \app\lib\MsgNotice::send_mail($mail_name,'邮件发送测试。','这是一封测试邮件!<br/><br/>来自:'.request()->root(true));
|
||||
$result = \app\lib\MsgNotice::send_mail($mail_name, '邮件发送测试。', '这是一封测试邮件!<br/><br/>来自:' . $this->request->root(true));
|
||||
if ($result === true) {
|
||||
return json(['code' => 0, 'msg' => '邮件发送成功!']);
|
||||
} else {
|
||||
|
@ -271,7 +273,7 @@ class Dmonitor extends BaseController
|
|||
$tgbot_token = config_get('tgbot_token');
|
||||
$tgbot_chatid = config_get('tgbot_chatid');
|
||||
if (empty($tgbot_token) || empty($tgbot_chatid)) return json(['code' => -1, 'msg' => '请先保存设置']);
|
||||
$content = "<strong>消息发送测试</strong>\n\n这是一封测试消息!\n\n来自:".request()->root(true);
|
||||
$content = "<strong>消息发送测试</strong>\n\n这是一封测试消息!\n\n来自:" . $this->request->root(true);
|
||||
$result = \app\lib\MsgNotice::send_telegram_bot($content);
|
||||
if ($result === true) {
|
||||
return json(['code' => 0, 'msg' => '消息发送成功!']);
|
||||
|
@ -280,10 +282,30 @@ class Dmonitor extends BaseController
|
|||
}
|
||||
}
|
||||
|
||||
public function proxytest()
|
||||
{
|
||||
if (!checkPermission(2)) return $this->alert('error', '无权限');
|
||||
$proxy_server = trim($_POST['proxy_server']);
|
||||
$proxy_port = $_POST['proxy_port'];
|
||||
$proxy_user = trim($_POST['proxy_user']);
|
||||
$proxy_pwd = trim($_POST['proxy_pwd']);
|
||||
$proxy_type = $_POST['proxy_type'];
|
||||
try {
|
||||
check_proxy('https://dl.amh.sh/ip.htm', $proxy_server, $proxy_port, $proxy_type, $proxy_user, $proxy_pwd);
|
||||
} catch (Exception $e) {
|
||||
try {
|
||||
check_proxy('https://myip.ipip.net/', $proxy_server, $proxy_port, $proxy_type, $proxy_user, $proxy_pwd);
|
||||
} catch (Exception $e) {
|
||||
return json(['code' => -1, 'msg' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
return json(['code' => 0]);
|
||||
}
|
||||
|
||||
public function clean()
|
||||
{
|
||||
if (!checkPermission(2)) return $this->alert('error', '无权限');
|
||||
if(request()->isPost()){
|
||||
if ($this->request->isPost()) {
|
||||
$days = input('post.days/d');
|
||||
if (!$days || $days < 0) return json(['code' => -1, 'msg' => '参数错误']);
|
||||
Db::execute("DELETE FROM `" . config('database.connections.mysql.prefix') . "dmlog` WHERE `date`<'" . date("Y-m-d H:i:s", strtotime("-" . $days . " days")) . "'");
|
||||
|
|
|
@ -12,15 +12,17 @@ use Exception;
|
|||
class Domain extends BaseController
|
||||
{
|
||||
|
||||
public function account(){
|
||||
public function account()
|
||||
{
|
||||
if (!checkPermission(2)) return $this->alert('error', '无权限');
|
||||
View::assign('dnsconfig', DnsHelper::$dns_config);
|
||||
return view();
|
||||
}
|
||||
|
||||
public function account_data(){
|
||||
public function account_data()
|
||||
{
|
||||
if (!checkPermission(2)) return json(['total' => 0, 'rows' => []]);
|
||||
$kw = input('post.kw', null, 'trim');
|
||||
$kw = $this->request->post('kw', null, 'trim');
|
||||
$offset = input('post.offset/d');
|
||||
$limit = input('post.limit/d');
|
||||
|
||||
|
@ -40,7 +42,8 @@ class Domain extends BaseController
|
|||
return json(['total' => $total, 'rows' => $list]);
|
||||
}
|
||||
|
||||
public function account_op(){
|
||||
public function account_op()
|
||||
{
|
||||
if (!checkPermission(2)) return $this->alert('error', '无权限');
|
||||
$act = input('param.act');
|
||||
if ($act == 'get') {
|
||||
|
@ -80,7 +83,6 @@ class Domain extends BaseController
|
|||
Db::rollback();
|
||||
return json(['code' => -1, 'msg' => 'DNS模块(' . $type . ')不存在']);
|
||||
}
|
||||
|
||||
} elseif ($act == 'edit') {
|
||||
$id = input('post.id/d');
|
||||
$row = Db::name('account')->where('id', $id)->find();
|
||||
|
@ -126,7 +128,8 @@ class Domain extends BaseController
|
|||
}
|
||||
|
||||
|
||||
public function domain(){
|
||||
public function domain()
|
||||
{
|
||||
if (request()->user['type'] == 'domain') {
|
||||
return redirect('/record/' . request()->user['id']);
|
||||
}
|
||||
|
@ -147,7 +150,8 @@ class Domain extends BaseController
|
|||
return view();
|
||||
}
|
||||
|
||||
public function domain_data(){
|
||||
public function domain_data()
|
||||
{
|
||||
if (!checkPermission(1)) return json(['total' => 0, 'rows' => []]);
|
||||
$kw = input('post.kw', null, 'trim');
|
||||
$type = input('post.type', null, 'trim');
|
||||
|
@ -176,7 +180,8 @@ class Domain extends BaseController
|
|||
return json(['total' => $total, 'rows' => $list]);
|
||||
}
|
||||
|
||||
public function domain_op(){
|
||||
public function domain_op()
|
||||
{
|
||||
if (!checkPermission(1)) return $this->alert('error', '无权限');
|
||||
$act = input('param.act');
|
||||
if ($act == 'get') {
|
||||
|
@ -229,7 +234,8 @@ class Domain extends BaseController
|
|||
return json(['code' => -3]);
|
||||
}
|
||||
|
||||
public function domain_list(){
|
||||
public function domain_list()
|
||||
{
|
||||
if (!checkPermission(2)) return $this->alert('error', '无权限');
|
||||
$aid = input('post.aid/d');
|
||||
$kw = input('post.kw', null, 'trim');
|
||||
|
@ -249,7 +255,8 @@ class Domain extends BaseController
|
|||
}
|
||||
|
||||
//获取解析线路和最小TTL
|
||||
private function get_line_and_ttl($drow){
|
||||
private function get_line_and_ttl($drow)
|
||||
{
|
||||
$recordLine = cache('record_line_' . $drow['id']);
|
||||
$minTTL = cache('min_ttl_' . $drow['id']);
|
||||
if (empty($recordLine)) {
|
||||
|
@ -266,7 +273,8 @@ class Domain extends BaseController
|
|||
return [$recordLine, $minTTL];
|
||||
}
|
||||
|
||||
public function domain_info(){
|
||||
public function domain_info()
|
||||
{
|
||||
$id = input('param.id/d');
|
||||
$drow = Db::name('domain')->where('id', $id)->find();
|
||||
if (!$drow) {
|
||||
|
@ -299,7 +307,8 @@ class Domain extends BaseController
|
|||
return json(['code' => 0, 'data' => $drow]);
|
||||
}
|
||||
|
||||
public function record(){
|
||||
public function record()
|
||||
{
|
||||
$id = input('param.id/d');
|
||||
$drow = Db::name('domain')->where('id', $id)->find();
|
||||
if (!$drow) {
|
||||
|
@ -326,7 +335,8 @@ class Domain extends BaseController
|
|||
return view();
|
||||
}
|
||||
|
||||
public function record_data(){
|
||||
public function record_data()
|
||||
{
|
||||
$id = input('param.id/d');
|
||||
$keyword = input('post.keyword', null, 'trim');
|
||||
$subdomain = input('post.subdomain', null, 'trim');
|
||||
|
@ -370,7 +380,8 @@ class Domain extends BaseController
|
|||
return json(['total' => $domainRecords['total'], 'rows' => $domainRecords['list']]);
|
||||
}
|
||||
|
||||
public function record_list(){
|
||||
public function record_list()
|
||||
{
|
||||
if (!checkPermission(2)) return $this->alert('error', '无权限');
|
||||
$id = input('post.id/d');
|
||||
$rr = input('post.rr', null, 'trim');
|
||||
|
@ -394,7 +405,8 @@ class Domain extends BaseController
|
|||
return json(['code' => 0, 'data' => $domainRecords['list']]);
|
||||
}
|
||||
|
||||
public function record_add(){
|
||||
public function record_add()
|
||||
{
|
||||
$id = input('param.id/d');
|
||||
$drow = Db::name('domain')->where('id', $id)->find();
|
||||
if (!$drow) {
|
||||
|
@ -425,7 +437,8 @@ class Domain extends BaseController
|
|||
}
|
||||
}
|
||||
|
||||
public function record_update(){
|
||||
public function record_update()
|
||||
{
|
||||
$id = input('param.id/d');
|
||||
$drow = Db::name('domain')->where('id', $id)->find();
|
||||
if (!$drow) {
|
||||
|
@ -457,7 +470,8 @@ class Domain extends BaseController
|
|||
}
|
||||
}
|
||||
|
||||
public function record_delete(){
|
||||
public function record_delete()
|
||||
{
|
||||
$id = input('param.id/d');
|
||||
$drow = Db::name('domain')->where('id', $id)->find();
|
||||
if (!$drow) {
|
||||
|
@ -480,7 +494,8 @@ class Domain extends BaseController
|
|||
}
|
||||
}
|
||||
|
||||
public function record_status(){
|
||||
public function record_status()
|
||||
{
|
||||
$id = input('param.id/d');
|
||||
$drow = Db::name('domain')->where('id', $id)->find();
|
||||
if (!$drow) {
|
||||
|
@ -505,7 +520,8 @@ class Domain extends BaseController
|
|||
}
|
||||
}
|
||||
|
||||
public function record_remark(){
|
||||
public function record_remark()
|
||||
{
|
||||
$id = input('param.id/d');
|
||||
$drow = Db::name('domain')->where('id', $id)->find();
|
||||
if (!$drow) {
|
||||
|
@ -529,7 +545,8 @@ class Domain extends BaseController
|
|||
}
|
||||
}
|
||||
|
||||
public function record_batch(){
|
||||
public function record_batch()
|
||||
{
|
||||
$id = input('param.id/d');
|
||||
$drow = Db::name('domain')->where('id', $id)->find();
|
||||
if (!$drow) {
|
||||
|
@ -586,7 +603,8 @@ class Domain extends BaseController
|
|||
return json(['code' => 0, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
public function record_batch_edit(){
|
||||
public function record_batch_edit()
|
||||
{
|
||||
$id = input('param.id/d');
|
||||
$drow = Db::name('domain')->where('id', $id)->find();
|
||||
if (!$drow) {
|
||||
|
@ -608,7 +626,8 @@ class Domain extends BaseController
|
|||
|
||||
$dns = DnsHelper::getModel($drow['aid'], $drow['name'], $drow['thirdid']);
|
||||
|
||||
$success = 0; $fail = 0;
|
||||
$success = 0;
|
||||
$fail = 0;
|
||||
foreach ($recordinfo as $record) {
|
||||
$recordid = $dns->updateDomainRecord($record['recordid'], $record['name'], $type, $value, $record['line'], $record['ttl'], $record['mx'], $record['weight'], $record['remark']);
|
||||
if ($recordid) {
|
||||
|
@ -619,7 +638,6 @@ class Domain extends BaseController
|
|||
}
|
||||
}
|
||||
return json(['code' => 0, 'msg' => '批量修改解析记录,成功' . $success . '条,失败' . $fail . '条']);
|
||||
|
||||
} else if ($action == 'line') {
|
||||
$line = input('post.line', null, 'trim');
|
||||
|
||||
|
@ -629,7 +647,8 @@ class Domain extends BaseController
|
|||
|
||||
$dns = DnsHelper::getModel($drow['aid'], $drow['name'], $drow['thirdid']);
|
||||
|
||||
$success = 0; $fail = 0;
|
||||
$success = 0;
|
||||
$fail = 0;
|
||||
foreach ($recordinfo as $record) {
|
||||
$recordid = $dns->updateDomainRecord($record['recordid'], $record['name'], $record['type'], $record['value'], $line, $record['ttl'], $record['mx'], $record['weight'], $record['remark']);
|
||||
if ($recordid) {
|
||||
|
@ -643,7 +662,8 @@ class Domain extends BaseController
|
|||
}
|
||||
}
|
||||
|
||||
public function record_batch_add(){
|
||||
public function record_batch_add()
|
||||
{
|
||||
$id = input('param.id/d');
|
||||
$drow = Db::name('domain')->where('id', $id)->find();
|
||||
if (!$drow) {
|
||||
|
@ -666,7 +686,8 @@ class Domain extends BaseController
|
|||
|
||||
$dns = DnsHelper::getModel($drow['aid'], $drow['name'], $drow['thirdid']);
|
||||
|
||||
$success = 0; $fail = 0;
|
||||
$success = 0;
|
||||
$fail = 0;
|
||||
foreach ($recordlist as $record) {
|
||||
$record = trim($record);
|
||||
$arr = explode(' ', $record);
|
||||
|
@ -701,7 +722,8 @@ class Domain extends BaseController
|
|||
return view('batchadd');
|
||||
}
|
||||
|
||||
public function record_log(){
|
||||
public function record_log()
|
||||
{
|
||||
$id = input('param.id/d');
|
||||
$drow = Db::name('domain')->where('id', $id)->find();
|
||||
if (!$drow) {
|
||||
|
@ -724,7 +746,8 @@ class Domain extends BaseController
|
|||
return view('log');
|
||||
}
|
||||
|
||||
private function add_log($domain, $action, $data){
|
||||
private function add_log($domain, $action, $data)
|
||||
{
|
||||
Db::name('log')->insert(['uid' => request()->user['id'], 'domain' => $domain, 'action' => $action, 'data' => $data, 'addtime' => date("Y-m-d H:i:s")]);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use app\BaseController;
|
||||
|
@ -12,20 +13,20 @@ class Index extends BaseController
|
|||
{
|
||||
public function index()
|
||||
{
|
||||
if(request()->user['type'] == 'domain'){
|
||||
return redirect('/record/'.request()->user['id']);
|
||||
if ($this->request->user['type'] == 'domain') {
|
||||
return redirect('/record/' . $this->request->user['id']);
|
||||
}
|
||||
if(request()->isAjax()){
|
||||
if ($this->request->isAjax()) {
|
||||
if (input('post.do') == 'stat') {
|
||||
$stat = ['domains' => 0, 'users' => 0, 'records' => 0, 'types' => count(DnsHelper::$dns_config)];
|
||||
if(request()->user['level'] == 2){
|
||||
if ($this->request->user['level'] == 2) {
|
||||
$stat['domains'] = Db::name('domain')->count();
|
||||
$stat['users'] = Db::name('user')->count();
|
||||
$stat['records'] = Db::name('domain')->sum('recordcount');
|
||||
} else {
|
||||
$stat['domains'] = Db::name('domain')->where('name', 'in', request()->user['permission'])->count();
|
||||
$stat['domains'] = Db::name('domain')->where('name', 'in', $this->request->user['permission'])->count();
|
||||
$stat['users'] = 1;
|
||||
$stat['records'] = Db::name('domain')->where('name', 'in', request()->user['permission'])->sum('recordcount');
|
||||
$stat['records'] = Db::name('domain')->where('name', 'in', $this->request->user['permission'])->sum('recordcount');
|
||||
}
|
||||
return json($stat);
|
||||
}
|
||||
|
@ -53,7 +54,8 @@ class Index extends BaseController
|
|||
return view();
|
||||
}
|
||||
|
||||
private function db_update(){
|
||||
private function db_update()
|
||||
{
|
||||
$sqls = file_get_contents(app()->getAppPath() . 'sql/update.sql');
|
||||
$mysql_prefix = env('database.prefix', 'dnsmgr_');
|
||||
$sqls = explode(';', $sqls);
|
||||
|
@ -64,14 +66,14 @@ class Index extends BaseController
|
|||
try {
|
||||
Db::execute($value);
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function changeskin(){
|
||||
public function changeskin()
|
||||
{
|
||||
$skin = input('post.skin');
|
||||
if(request()->user['level'] == 2){
|
||||
if ($this->request->user['level'] == 2) {
|
||||
if (cookie('admin_skin')) {
|
||||
cookie('admin_skin', null);
|
||||
}
|
||||
|
@ -83,21 +85,26 @@ class Index extends BaseController
|
|||
return json(['code' => 0, 'msg' => 'succ']);
|
||||
}
|
||||
|
||||
public function cleancache(){
|
||||
public function cleancache()
|
||||
{
|
||||
if (!checkPermission(1)) return $this->alert('error', '无权限');
|
||||
Cache::clear();
|
||||
clearDirectory(app()->getRuntimePath().'cache/');
|
||||
clearDirectory(app()->getRuntimePath().'temp/');
|
||||
return json(['code' => 0, 'msg' => 'succ']);
|
||||
}
|
||||
|
||||
public function doc(){
|
||||
public function doc()
|
||||
{
|
||||
if (!checkPermission(1)) return $this->alert('error', '无权限');
|
||||
View::assign('siteurl', request()->root(true));
|
||||
View::assign('siteurl', $this->request->root(true));
|
||||
return view();
|
||||
}
|
||||
|
||||
public function setpwd(){
|
||||
public function setpwd()
|
||||
{
|
||||
if (!checkPermission(1)) return $this->alert('error', '无权限');
|
||||
if(request()->isPost()){
|
||||
if ($this->request->isPost()) {
|
||||
$oldpwd = input('post.oldpwd');
|
||||
$newpwd = input('post.newpwd');
|
||||
$newpwd2 = input('post.newpwd2');
|
||||
|
@ -107,16 +114,22 @@ class Index extends BaseController
|
|||
if ($newpwd != $newpwd2) {
|
||||
return json(['code' => -1, 'msg' => '两次输入的密码不一致']);
|
||||
}
|
||||
if(!password_verify($oldpwd, request()->user['password'])){
|
||||
if (!password_verify($oldpwd, $this->request->user['password'])) {
|
||||
return json(['code' => -1, 'msg' => '原密码错误']);
|
||||
}
|
||||
Db::name('user')->where('id', request()->user['id'])->update(['password'=>password_hash($newpwd, PASSWORD_DEFAULT)]);
|
||||
Db::name('user')->where('id', $this->request->user['id'])->update(['password' => password_hash($newpwd, PASSWORD_DEFAULT)]);
|
||||
return json(['code' => 0, 'msg' => 'succ']);
|
||||
}
|
||||
return view();
|
||||
}
|
||||
|
||||
public function test(){
|
||||
|
||||
public function test()
|
||||
{
|
||||
//$a = \app\lib\DnsQueryUtils::query_dns_doh('www.cccyun.cc', 'A');
|
||||
//print_r($a);
|
||||
$dnsList = json_decode('{"cccyun.net":[{"name":"@","type":"CAA","value":"0 issue \"letsencrypt.org\""},{"name":"verify","type":"TXT","value":"TXTTEST1"},{"name":"verify","type":"TXT","value":"TXTTEST2"}],"yuncname.com":[{"name":"@","type":"CAA","value":"0 issue \"letsencrypt.org\""},{"name":"verify.testhost1","type":"CNAME","value":"i.trust.com"},{"name":"verify.testhost2","type":"CNAME","value":"i.trust.com"}]}', true);
|
||||
\app\lib\CertDnsUtils::addDns($dnsList, function ($txt) {
|
||||
echo $txt . PHP_EOL;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use PDO;
|
||||
use Exception;
|
||||
use app\BaseController;
|
||||
use think\facade\View;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Request;
|
||||
|
||||
class Install extends BaseController
|
||||
{
|
||||
|
@ -14,7 +15,7 @@ class Install extends BaseController
|
|||
if (file_exists(app()->getRootPath() . '.env')) {
|
||||
return '当前已经安装成功,如果需要重新安装,请手动删除根目录.env文件';
|
||||
}
|
||||
if(request()->isPost()){
|
||||
if (Request::isPost()) {
|
||||
$mysql_host = input('post.mysql_host', null, 'trim');
|
||||
$mysql_port = intval(input('post.mysql_port', '3306'));
|
||||
$mysql_user = input('post.mysql_user', null, 'trim');
|
||||
|
@ -28,8 +29,8 @@ class Install extends BaseController
|
|||
return json(['code' => 0, 'msg' => '必填项不能为空']);
|
||||
}
|
||||
|
||||
$configdata = file_get_contents(app()->getRootPath().'.example.env');
|
||||
$configdata = str_replace(['{dbhost}','{dbname}','{dbuser}','{dbpwd}','{dbport}','{dbprefix}'], [$mysql_host, $mysql_name, $mysql_user, $mysql_pwd, $mysql_port, $mysql_prefix], $configdata);
|
||||
$configData = file_get_contents(app()->getRootPath() . '.example.env');
|
||||
$configData = str_replace(['{dbhost}', '{dbname}', '{dbuser}', '{dbpwd}', '{dbport}', '{dbprefix}'], [$mysql_host, $mysql_name, $mysql_user, $mysql_pwd, $mysql_port, $mysql_prefix], $configData);
|
||||
|
||||
try {
|
||||
$DB = new PDO("mysql:host=" . $mysql_host . ";dbname=" . $mysql_name . ";port=" . $mysql_port, $mysql_user, $mysql_pwd);
|
||||
|
@ -56,7 +57,9 @@ class Install extends BaseController
|
|||
$sqls[] = "REPLACE INTO `" . $mysql_prefix . "config` VALUES ('sys_key', '" . random(16) . "')";
|
||||
$sqls[] = "INSERT INTO `" . $mysql_prefix . "user` (`username`,`password`,`level`,`regtime`,`lasttime`,`status`) VALUES ('" . addslashes($admin_username) . "', '$password', 2, NOW(), NOW(), 1)";
|
||||
|
||||
$success=0;$error=0;$errorMsg=null;
|
||||
$success = 0;
|
||||
$error = 0;
|
||||
$errorMsg = null;
|
||||
foreach ($sqls as $value) {
|
||||
$value = trim($value);
|
||||
if (empty($value)) continue;
|
||||
|
@ -70,7 +73,7 @@ class Install extends BaseController
|
|||
}
|
||||
}
|
||||
if (empty($errorMsg)) {
|
||||
if(!file_put_contents(app()->getRootPath().'.env', $configdata)){
|
||||
if (!file_put_contents(app()->getRootPath() . '.env', $configData)) {
|
||||
return json(['code' => 0, 'msg' => '保存失败,请确保网站根目录有写入权限']);
|
||||
}
|
||||
Cache::clear();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use app\BaseController;
|
||||
|
@ -13,7 +14,7 @@ class Optimizeip extends BaseController
|
|||
public function opipset()
|
||||
{
|
||||
if (!checkPermission(2)) return $this->alert('error', '无权限');
|
||||
if(request()->isPost()){
|
||||
if ($this->request->isPost()) {
|
||||
$params = input('post.');
|
||||
foreach ($params as $key => $value) {
|
||||
if (empty($key)) {
|
||||
|
@ -33,7 +34,8 @@ class Optimizeip extends BaseController
|
|||
return View::fetch();
|
||||
}
|
||||
|
||||
public function opiplist_data(){
|
||||
public function opiplist_data()
|
||||
{
|
||||
if (!checkPermission(2)) return json(['total' => 0, 'rows' => []]);
|
||||
$type = input('post.type/d', 1);
|
||||
$kw = input('post.kw', null, 'trim');
|
||||
|
@ -58,7 +60,7 @@ class Optimizeip extends BaseController
|
|||
{
|
||||
if (!checkPermission(2)) return $this->alert('error', '无权限');
|
||||
$action = input('param.action');
|
||||
if(request()->isPost()){
|
||||
if ($this->request->isPost()) {
|
||||
if ($action == 'add') {
|
||||
$task = [
|
||||
'did' => input('post.did/d'),
|
||||
|
|
|
@ -10,7 +10,8 @@ use think\facade\Request;
|
|||
class User extends BaseController
|
||||
{
|
||||
|
||||
public function user(){
|
||||
public function user()
|
||||
{
|
||||
if (!checkPermission(2)) return $this->alert('error', '无权限');
|
||||
$list = Db::name('domain')->select();
|
||||
$domains = [];
|
||||
|
@ -21,7 +22,8 @@ class User extends BaseController
|
|||
return view();
|
||||
}
|
||||
|
||||
public function user_data(){
|
||||
public function user_data()
|
||||
{
|
||||
if (!checkPermission(2)) return json(['total' => 0, 'rows' => []]);
|
||||
$kw = input('post.kw', null, 'trim');
|
||||
$offset = input('post.offset/d');
|
||||
|
@ -37,13 +39,16 @@ class User extends BaseController
|
|||
return json(['total' => $total, 'rows' => $rows]);
|
||||
}
|
||||
|
||||
public function user_op(){
|
||||
public function user_op()
|
||||
{
|
||||
if (!checkPermission(2)) return $this->alert('error', '无权限');
|
||||
$act = input('param.act');
|
||||
if ($act == 'get') {
|
||||
$id = input('post.id/d');
|
||||
$row = Db::name('user')->where('id', $id)->find();
|
||||
if(!$row) return json(['code'=>-1, 'msg'=>'用户不存在']);
|
||||
if (!$row) {
|
||||
return json(['code' => -1, 'msg' => '用户不存在']);
|
||||
}
|
||||
$row['permission'] = Db::name('permission')->where('uid', $id)->column('domain');
|
||||
return json(['code' => 0, 'data' => $row]);
|
||||
} elseif ($act == 'add') {
|
||||
|
@ -52,8 +57,12 @@ class User extends BaseController
|
|||
$is_api = input('post.is_api/d');
|
||||
$apikey = input('post.apikey', null, 'trim');
|
||||
$level = input('post.level/d');
|
||||
if(empty($username) || empty($password)) return json(['code'=>-1, 'msg'=>'用户名或密码不能为空']);
|
||||
if($is_api ==1 && empty($apikey)) return json(['code'=>-1, 'msg'=>'API密钥不能为空']);
|
||||
if (empty($username) || empty($password)) {
|
||||
return json(['code' => -1, 'msg' => '用户名或密码不能为空']);
|
||||
}
|
||||
if ($is_api == 1 && empty($apikey)) {
|
||||
return json(['code' => -1, 'msg' => 'API密钥不能为空']);
|
||||
}
|
||||
if (Db::name('user')->where('username', $username)->find()) {
|
||||
return json(['code' => -1, 'msg' => '用户名已存在']);
|
||||
}
|
||||
|
@ -86,12 +95,18 @@ class User extends BaseController
|
|||
$apikey = input('post.apikey', null, 'trim');
|
||||
$level = input('post.level/d');
|
||||
$repwd = input('post.repwd', null, 'trim');
|
||||
if(empty($username)) return json(['code'=>-1, 'msg'=>'用户名不能为空']);
|
||||
if($is_api ==1 && empty($apikey)) return json(['code'=>-1, 'msg'=>'API密钥不能为空']);
|
||||
if (empty($username)) {
|
||||
return json(['code' => -1, 'msg' => '用户名不能为空']);
|
||||
}
|
||||
if ($is_api == 1 && empty($apikey)) {
|
||||
return json(['code' => -1, 'msg' => 'API密钥不能为空']);
|
||||
}
|
||||
if (Db::name('user')->where('username', $username)->where('id', '<>', $id)->find()) {
|
||||
return json(['code' => -1, 'msg' => '用户名已存在']);
|
||||
}
|
||||
if($level == 1 && ($id == 1000 || $id == request()->user['id'])) $level = 2;
|
||||
if ($level == 1 && ($id == 1000 || $id == $this->request->user['id'])) {
|
||||
$level = 2;
|
||||
}
|
||||
Db::name('user')->where('id', $id)->update([
|
||||
'username' => $username,
|
||||
'is_api' => $is_api,
|
||||
|
@ -116,25 +131,35 @@ class User extends BaseController
|
|||
} elseif ($act == 'set') {
|
||||
$id = input('post.id/d');
|
||||
$status = input('post.status/d');
|
||||
if($id == 1000) return json(['code'=>-1, 'msg'=>'此用户无法修改状态']);
|
||||
if($id == request()->user['id']) return json(['code'=>-1, 'msg'=>'当前登录用户无法修改状态']);
|
||||
if ($id == 1000) {
|
||||
return json(['code' => -1, 'msg' => '此用户无法修改状态']);
|
||||
}
|
||||
if ($id == $this->request->user['id']) {
|
||||
return json(['code' => -1, 'msg' => '当前登录用户无法修改状态']);
|
||||
}
|
||||
Db::name('user')->where('id', $id)->update(['status' => $status]);
|
||||
return json(['code' => 0]);
|
||||
} elseif ($act == 'del') {
|
||||
$id = input('post.id/d');
|
||||
if($id == 1000) return json(['code'=>-1, 'msg'=>'此用户无法删除']);
|
||||
if($id == request()->user['id']) return json(['code'=>-1, 'msg'=>'当前登录用户无法删除']);
|
||||
if ($id == 1000) {
|
||||
return json(['code' => -1, 'msg' => '此用户无法删除']);
|
||||
}
|
||||
if ($id == $this->request->user['id']) {
|
||||
return json(['code' => -1, 'msg' => '当前登录用户无法删除']);
|
||||
}
|
||||
Db::name('user')->where('id', $id)->delete();
|
||||
return json(['code' => 0]);
|
||||
}
|
||||
return json(['code' => -3]);
|
||||
}
|
||||
|
||||
public function log(){
|
||||
public function log()
|
||||
{
|
||||
return view();
|
||||
}
|
||||
|
||||
public function log_data(){
|
||||
public function log_data()
|
||||
{
|
||||
$uid = input('post.uid', null, 'trim');
|
||||
$kw = input('post.kw', null, 'trim');
|
||||
$domain = input('post.domain', null, 'trim');
|
||||
|
@ -142,10 +167,10 @@ class User extends BaseController
|
|||
$limit = input('post.limit/d');
|
||||
|
||||
$select = Db::name('log');
|
||||
if(request()->user['type'] == 'domain'){
|
||||
$select->where('domain', request()->user['name']);
|
||||
}elseif(request()->user['level'] == 1){
|
||||
$select->where('uid', request()->user['id']);
|
||||
if ($this->request->user['type'] == 'domain') {
|
||||
$select->where('domain', $this->request->user['name']);
|
||||
} elseif ($this->request->user['level'] == 1) {
|
||||
$select->where('uid', $this->request->user['id']);
|
||||
} elseif (!empty($uid)) {
|
||||
$select->where('uid', $uid);
|
||||
}
|
||||
|
@ -160,5 +185,4 @@ class User extends BaseController
|
|||
|
||||
return json(['total' => $total, 'rows' => $rows]);
|
||||
}
|
||||
|
||||
}
|
|
@ -72,7 +72,8 @@ class CheckUtils
|
|||
return ['status' => $status, 'errmsg' => $errmsg, 'usetime' => $usetime];
|
||||
}
|
||||
|
||||
public static function tcp($target, $port, $timeout){
|
||||
public static function tcp($target, $port, $timeout)
|
||||
{
|
||||
if (!filter_var($target, FILTER_VALIDATE_IP) && checkDomain($target)) {
|
||||
$target = gethostbyname($target);
|
||||
if (!$target) return ['status' => false, 'error' => 'DNS resolve failed', 'usetime' => 0];
|
||||
|
@ -90,7 +91,8 @@ class CheckUtils
|
|||
return ['status' => $status, 'errmsg' => $errStr, 'usetime' => $usetime];
|
||||
}
|
||||
|
||||
public static function ping($target){
|
||||
public static function ping($target)
|
||||
{
|
||||
if (!function_exists('exec')) return ['status' => false, 'error' => 'exec函数不可用', 'usetime' => 0];
|
||||
if (!filter_var($target, FILTER_VALIDATE_IP) && checkDomain($target)) {
|
||||
$target = gethostbyname($target);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace app\lib;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
class DnsHelper
|
||||
|
@ -10,7 +11,7 @@ class DnsHelper
|
|||
'name' => '阿里云',
|
||||
'config' => [
|
||||
'ak' => 'AccessKeyId',
|
||||
'sk' => 'AccessKeySecret'
|
||||
'sk' => 'AccessKeySecret',
|
||||
],
|
||||
'remark' => 1, //是否支持备注,1单独设置备注,2和记录一起设置
|
||||
'status' => true, //是否支持启用暂停
|
||||
|
@ -22,7 +23,7 @@ class DnsHelper
|
|||
'name' => '腾讯云',
|
||||
'config' => [
|
||||
'ak' => 'SecretId',
|
||||
'sk' => 'SecretKey'
|
||||
'sk' => 'SecretKey',
|
||||
],
|
||||
'remark' => 1,
|
||||
'status' => true,
|
||||
|
@ -34,7 +35,7 @@ class DnsHelper
|
|||
'name' => '华为云',
|
||||
'config' => [
|
||||
'ak' => 'AccessKeyId',
|
||||
'sk' => 'SecretAccessKey'
|
||||
'sk' => 'SecretAccessKey',
|
||||
],
|
||||
'remark' => 2,
|
||||
'status' => true,
|
||||
|
@ -46,7 +47,7 @@ class DnsHelper
|
|||
'name' => '百度云',
|
||||
'config' => [
|
||||
'ak' => 'AccessKey',
|
||||
'sk' => 'SecretKey'
|
||||
'sk' => 'SecretKey',
|
||||
],
|
||||
'remark' => 2,
|
||||
'status' => false,
|
||||
|
@ -58,7 +59,7 @@ class DnsHelper
|
|||
'name' => '西部数码',
|
||||
'config' => [
|
||||
'ak' => '用户名',
|
||||
'sk' => 'API密码'
|
||||
'sk' => 'API密码',
|
||||
],
|
||||
'remark' => 0,
|
||||
'status' => true,
|
||||
|
@ -70,7 +71,7 @@ class DnsHelper
|
|||
'name' => '火山引擎',
|
||||
'config' => [
|
||||
'ak' => 'AccessKeyId',
|
||||
'sk' => 'SecretAccessKey'
|
||||
'sk' => 'SecretAccessKey',
|
||||
],
|
||||
'remark' => 2,
|
||||
'status' => true,
|
||||
|
@ -82,7 +83,7 @@ class DnsHelper
|
|||
'name' => 'DNSLA',
|
||||
'config' => [
|
||||
'ak' => 'APIID',
|
||||
'sk' => 'API密钥'
|
||||
'sk' => 'API密钥',
|
||||
],
|
||||
'remark' => 0,
|
||||
'status' => true,
|
||||
|
@ -94,7 +95,7 @@ class DnsHelper
|
|||
'name' => 'Cloudflare',
|
||||
'config' => [
|
||||
'ak' => '邮箱地址',
|
||||
'sk' => 'API密钥/令牌'
|
||||
'sk' => 'API密钥/令牌',
|
||||
],
|
||||
'remark' => 2,
|
||||
'status' => false,
|
||||
|
@ -104,17 +105,32 @@ class DnsHelper
|
|||
],
|
||||
];
|
||||
|
||||
public static $line_name = [
|
||||
'aliyun' => ['DEF' => 'default', 'CT' => 'telecom', 'CU' => 'unicom', 'CM' => 'mobile', 'AB' => 'oversea'],
|
||||
'dnspod' => ['DEF' => '0', 'CT' => '10=0', 'CU' => '10=1', 'CM' => '10=3', 'AB' => '3=0'],
|
||||
'huawei' => ['DEF' => 'default_view', 'CT' => 'Dianxin', 'CU' => 'Liantong', 'CM' => 'Yidong', 'AB' => 'Abroad'],
|
||||
'west' => ['DEF' => '', 'CT' => 'LTEL', 'CU' => 'LCNC', 'CM' => 'LMOB', 'AB' => 'LFOR'],
|
||||
'dnsla' => ['DEF' => '', 'CT' => '84613316902921216', 'CU' => '84613316923892736', 'CM' => '84613316953252864', 'AB' => ''],
|
||||
'huoshan' => ['DEF' => 'default', 'CT' => 'telecom', 'CU' => 'unicom', 'CM' => 'mobile', 'AB' => 'oversea'],
|
||||
'baidu' => ['DEF' => 'default', 'CT' => 'ct', 'CU' => 'cnc', 'CM' => 'cmnet', 'AB' => ''],
|
||||
'cloudflare' => ['DEF' => '0'],
|
||||
];
|
||||
|
||||
public static function getList()
|
||||
{
|
||||
return self::$dns_config;
|
||||
}
|
||||
|
||||
private static function getConfig($aid){
|
||||
private static function getConfig($aid)
|
||||
{
|
||||
$account = Db::name('account')->where('id', $aid)->find();
|
||||
if (!$account) return false;
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DnsInterface|false
|
||||
*/
|
||||
public static function getModel($aid, $domain = null, $domainid = null)
|
||||
{
|
||||
$config = self::getConfig($aid);
|
||||
|
@ -130,6 +146,9 @@ class DnsHelper
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DnsInterface|false
|
||||
*/
|
||||
public static function getModel2($config)
|
||||
{
|
||||
$dnstype = $config['type'];
|
||||
|
|
|
@ -31,5 +31,4 @@ interface DnsInterface
|
|||
function getRecordLine();
|
||||
|
||||
function getMinTTL();
|
||||
|
||||
}
|
|
@ -32,8 +32,12 @@ class MsgNotice
|
|||
$lasttime = convert_second(time() - $task['switchtime']);
|
||||
$mail_content .= '。<br/>异常持续时间:'.$lasttime;
|
||||
}
|
||||
if(!empty($task['remark'])) $mail_title .= '('.$task['remark'].')';
|
||||
if(!empty($task['remark'])) $mail_content .= '<br/>备注:'.$task['remark'];
|
||||
if (!empty($task['remark'])) {
|
||||
$mail_title .= '('.$task['remark'].')';
|
||||
}
|
||||
if (!empty($task['remark'])) {
|
||||
$mail_content .= '<br/>备注:'.$task['remark'];
|
||||
}
|
||||
$mail_content .= '<br/>'.self::$sitename.'<br/>'.date('Y-m-d H:i:s');
|
||||
|
||||
if (config_get('notice_mail') == 1) {
|
||||
|
@ -51,7 +55,8 @@ class MsgNotice
|
|||
}
|
||||
}
|
||||
|
||||
public static function send_mail($to, $sub, $msg){
|
||||
public static function send_mail($to, $sub, $msg)
|
||||
{
|
||||
$mail_type = config_get('mail_type');
|
||||
if ($mail_type == 1) {
|
||||
$mail = new \app\lib\mail\Sendcloud(config_get('mail_apiuser'), config_get('mail_apikey'));
|
||||
|
@ -93,7 +98,8 @@ class MsgNotice
|
|||
}
|
||||
}
|
||||
|
||||
public static function send_wechat_tplmsg($title, $content){
|
||||
public static function send_wechat_tplmsg($title, $content)
|
||||
{
|
||||
$wechat_apptoken = config_get('wechat_apptoken');
|
||||
$wechat_appuid = config_get('wechat_appuid');
|
||||
if (!$wechat_apptoken || !$wechat_appuid) return false;
|
||||
|
@ -108,7 +114,8 @@ class MsgNotice
|
|||
}
|
||||
}
|
||||
|
||||
public static function send_telegram_bot($content){
|
||||
public static function send_telegram_bot($content)
|
||||
{
|
||||
$tgbot_token = config_get('tgbot_token');
|
||||
$tgbot_chatid = config_get('tgbot_chatid');
|
||||
if (!$tgbot_token || !$tgbot_chatid) return false;
|
||||
|
@ -123,7 +130,8 @@ class MsgNotice
|
|||
}
|
||||
}
|
||||
|
||||
private static function telegram_curl($url, $post){
|
||||
private static function telegram_curl($url, $post)
|
||||
{
|
||||
$ch = curl_init();
|
||||
if (config_get('tgbot_proxy') == 1) {
|
||||
$proxy_server = config_get('proxy_server');
|
||||
|
|
|
@ -7,22 +7,13 @@ use think\facade\Db;
|
|||
|
||||
class OptimizeService
|
||||
{
|
||||
private static $line_name = [
|
||||
'aliyun' => ['DEF'=>'default', 'CT'=>'telecom', 'CU'=>'unicom', 'CM'=>'mobile', 'AB'=>'oversea'],
|
||||
'dnspod' => ['DEF'=>'0', 'CT'=>'10=0', 'CU'=>'10=1', 'CM'=>'10=3', 'AB'=>'3=0'],
|
||||
'huawei' => ['DEF'=>'default_view', 'CT'=>'Dianxin', 'CU'=>'Liantong', 'CM'=>'Yidong', 'AB'=>'Abroad'],
|
||||
'west' => ['DEF'=>'', 'CT'=>'LTEL', 'CU'=>'LCNC', 'CM'=>'LMOB', 'AB'=>'LFOR'],
|
||||
'dnsla' => ['DEF'=>'', 'CT'=>'84613316902921216', 'CU'=>'84613316923892736', 'CM'=>'84613316953252864', 'AB'=>''],
|
||||
'huoshan' => ['DEF'=>'default', 'CT'=>'telecom', 'CU'=>'unicom', 'CM'=>'mobile', 'AB'=>'oversea'],
|
||||
'baidu' => ['DEF'=>'default', 'CT'=>'ct', 'CU'=>'cnc', 'CM'=>'cmnet', 'AB'=>''],
|
||||
];
|
||||
|
||||
private $ip_address = [];
|
||||
private $add_num = 0;
|
||||
private $change_num = 0;
|
||||
private $del_num = 0;
|
||||
|
||||
public static function get_license($api, $key){
|
||||
public static function get_license($api, $key)
|
||||
{
|
||||
if ($api == 2) {
|
||||
throw new Exception('当前接口暂不支持');
|
||||
} elseif ($api == 1) {
|
||||
|
@ -41,7 +32,8 @@ class OptimizeService
|
|||
}
|
||||
}
|
||||
|
||||
public function get_ip_address($cdn_type = 1, $ip_type = 'v4'){
|
||||
public function get_ip_address($cdn_type = 1, $ip_type = 'v4')
|
||||
{
|
||||
$api = config_get('optimize_ip_api', 0);
|
||||
if ($api == 2) {
|
||||
$url = 'https://api.345673.xyz/get_data';
|
||||
|
@ -74,22 +66,32 @@ class OptimizeService
|
|||
}
|
||||
}
|
||||
|
||||
public function get_ip_address2($cdn_type = 1, $ip_type = 'v4'){
|
||||
public function get_ip_address2($cdn_type = 1, $ip_type = 'v4')
|
||||
{
|
||||
$key = $cdn_type.'_'.$ip_type;
|
||||
if (!isset($this->ip_address[$key])) {
|
||||
$info = $this->get_ip_address($cdn_type, $ip_type);
|
||||
$res = [];
|
||||
if(isset($info['DEF'])) $res['DEF'] = $info['DEF'];
|
||||
if(isset($info['CT'])) $res['CT'] = $info['CT'];
|
||||
if(isset($info['CU'])) $res['CU'] = $info['CU'];
|
||||
if(isset($info['CM'])) $res['CM'] = $info['CM'];
|
||||
if (isset($info['DEF'])) {
|
||||
$res['DEF'] = $info['DEF'];
|
||||
}
|
||||
if (isset($info['CT'])) {
|
||||
$res['CT'] = $info['CT'];
|
||||
}
|
||||
if (isset($info['CU'])) {
|
||||
$res['CU'] = $info['CU'];
|
||||
}
|
||||
if (isset($info['CM'])) {
|
||||
$res['CM'] = $info['CM'];
|
||||
}
|
||||
$this->ip_address[$key] = $res;
|
||||
}
|
||||
return $this->ip_address[$key];
|
||||
}
|
||||
|
||||
//批量执行优选任务
|
||||
public function execute(){
|
||||
public function execute()
|
||||
{
|
||||
$list = Db::name('optimizeip')->where('active', 1)->select();
|
||||
echo '开始执行IP优选任务,共获取到'.count($list).'个待执行任务'."\n";
|
||||
foreach ($list as $row) {
|
||||
|
@ -105,19 +107,22 @@ class OptimizeService
|
|||
}
|
||||
|
||||
//执行单个优选任务
|
||||
public function execute_one($row){
|
||||
public function execute_one($row)
|
||||
{
|
||||
$this->add_num = 0;
|
||||
$this->change_num = 0;
|
||||
$this->del_num = 0;
|
||||
$ip_types = explode(',', $row['ip_type']);
|
||||
foreach ($ip_types as $ip_type) {
|
||||
if(empty($ip_type)) continue;
|
||||
if (empty($ip_type)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$drow = Db::name('domain')->alias('A')->join('account B', 'A.aid = B.id')->where('A.id', $row['did'])->field('A.*,B.type,B.ak,B.sk,B.ext')->find();
|
||||
if (!$drow) {
|
||||
throw new Exception('域名不存在(ID:'.$row['did'].')');
|
||||
}
|
||||
if(!isset(self::$line_name[$drow['type']])){
|
||||
if (!isset(DnsHelper::$line_name[$drow['type']])) {
|
||||
throw new Exception('不支持的DNS服务商');
|
||||
}
|
||||
|
||||
|
@ -129,14 +134,24 @@ class OptimizeService
|
|||
throw new Exception('获取记录列表失败,'.$dns->getError());
|
||||
}
|
||||
|
||||
if($row['type'] == 1 && isset($info['DEF']) && !empty($info['DEF'])) $row['type'] = 0;
|
||||
if ($row['type'] == 1 && isset($info['DEF']) && !empty($info['DEF'])) {
|
||||
$row['type'] = 0;
|
||||
}
|
||||
|
||||
foreach ($info as $line => $iplist) {
|
||||
if(empty($iplist)) continue;
|
||||
if (empty($iplist)) {
|
||||
continue;
|
||||
}
|
||||
$get_ips = array_column($iplist, 'ip');
|
||||
if($drow['type']=='huawei') {sort($get_ips); $get_ips = [implode(',',$get_ips)]; $row['recordnum'] = 1;}
|
||||
if($row['type'] == 1 && $line == 'CT') $line = 'DEF';
|
||||
$line_name = self::$line_name[$drow['type']][$line];
|
||||
if ($drow['type'] == 'huawei') {
|
||||
sort($get_ips);
|
||||
$get_ips = [implode(',', $get_ips)];
|
||||
$row['recordnum'] = 1;
|
||||
}
|
||||
if ($row['type'] == 1 && $line == 'CT') {
|
||||
$line = 'DEF';
|
||||
}
|
||||
$line_name = DnsHelper::$line_name[$drow['type']][$line];
|
||||
$this->process_dns_line($dns, $row, $domainRecords['list'], $get_ips, $line_name, $ip_type);
|
||||
}
|
||||
}
|
||||
|
@ -145,7 +160,8 @@ class OptimizeService
|
|||
}
|
||||
|
||||
//处理单个线路的解析记录
|
||||
private function process_dns_line($dns, $row, $record_list, $get_ips, $line_name, $ip_type){
|
||||
private function process_dns_line($dns, $row, $record_list, $get_ips, $line_name, $ip_type)
|
||||
{
|
||||
$record_num = $row['recordnum'];
|
||||
$records = array_filter($record_list, function ($v) use ($line_name) {
|
||||
return $v['Line'] == $line_name;
|
||||
|
@ -207,7 +223,9 @@ class OptimizeService
|
|||
}
|
||||
$this->add_num++;
|
||||
$correct_count++;
|
||||
if($correct_count >= $record_num) break;
|
||||
if ($correct_count >= $record_num) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace app\lib;
|
||||
|
||||
use app\lib\NewDb;
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace app\lib\dns;
|
||||
|
||||
use app\lib\DnsInterface;
|
||||
|
||||
class aliyun implements DnsInterface {
|
||||
class aliyun implements DnsInterface
|
||||
{
|
||||
private $AccessKeyId;
|
||||
private $AccessKeySecret;
|
||||
private $Endpoint = 'alidns.aliyuncs.com'; //API接入域名
|
||||
|
@ -13,17 +15,20 @@ class aliyun implements DnsInterface {
|
|||
private $domainid;
|
||||
private $domainInfo;
|
||||
|
||||
function __construct($config){
|
||||
public function __construct($config)
|
||||
{
|
||||
$this->AccessKeyId = $config['ak'];
|
||||
$this->AccessKeySecret = $config['sk'];
|
||||
$this->domain = $config['domain'];
|
||||
}
|
||||
|
||||
public function getError(){
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function check(){
|
||||
public function check()
|
||||
{
|
||||
if ($this->getDomainList() != false) {
|
||||
return true;
|
||||
}
|
||||
|
@ -31,7 +36,8 @@ class aliyun implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名列表
|
||||
public function getDomainList($KeyWord=null, $PageNumber=1, $PageSize=20){
|
||||
public function getDomainList($KeyWord = null, $PageNumber = 1, $PageSize = 20)
|
||||
{
|
||||
$param = ['Action' => 'DescribeDomains', 'KeyWord' => $KeyWord, 'PageNumber' => $PageNumber, 'PageSize' => $PageSize];
|
||||
$data = $this->request($param, true);
|
||||
if ($data) {
|
||||
|
@ -49,7 +55,8 @@ class aliyun implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取解析记录列表
|
||||
public function getDomainRecords($PageNumber=1, $PageSize=20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null){
|
||||
public function getDomainRecords($PageNumber = 1, $PageSize = 20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null)
|
||||
{
|
||||
$param = ['Action' => 'DescribeDomainRecords', 'DomainName' => $this->domain, 'PageNumber' => $PageNumber, 'PageSize' => $PageSize];
|
||||
if (!empty($SubDomain) || !empty($Type) || !empty($Line) || !empty($Value)) {
|
||||
$param += ['SearchMode' => 'ADVANCED', 'RRKeyWord' => $SubDomain, 'ValueKeyWord' => $Value, 'Type' => $Type, 'Line' => $Line];
|
||||
|
@ -85,7 +92,8 @@ class aliyun implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取子域名解析记录列表
|
||||
public function getSubDomainRecords($SubDomain, $PageNumber=1, $PageSize=20, $Type = null, $Line = null){
|
||||
public function getSubDomainRecords($SubDomain, $PageNumber = 1, $PageSize = 20, $Type = null, $Line = null)
|
||||
{
|
||||
$param = ['Action' => 'DescribeSubDomainRecords', 'SubDomain' => $SubDomain . '.' . $this->domain, 'PageNumber' => $PageNumber, 'PageSize' => $PageSize, 'Type' => $Type, 'Line' => $Line];
|
||||
$data = $this->request($param, true);
|
||||
if ($data) {
|
||||
|
@ -112,7 +120,8 @@ class aliyun implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取解析记录详细信息
|
||||
public function getDomainRecordInfo($RecordId){
|
||||
public function getDomainRecordInfo($RecordId)
|
||||
{
|
||||
$param = ['Action' => 'DescribeDomainRecordInfo', 'RecordId' => $RecordId];
|
||||
$data = $this->request($param, true);
|
||||
if ($data) {
|
||||
|
@ -135,7 +144,8 @@ class aliyun implements DnsInterface {
|
|||
}
|
||||
|
||||
//添加解析记录
|
||||
public function addDomainRecord($Name, $Type, $Value, $Line = 'default', $TTL = 600, $MX = null, $Weight = null, $Remark = null){
|
||||
public function addDomainRecord($Name, $Type, $Value, $Line = 'default', $TTL = 600, $MX = null, $Weight = null, $Remark = null)
|
||||
{
|
||||
$param = ['Action' => 'AddDomainRecord', 'DomainName' => $this->domain, 'RR' => $Name, 'Type' => $Type, 'Value' => $Value, 'Line' => $this->convertLineCode($Line), 'TTL' => intval($TTL)];
|
||||
if ($MX) {
|
||||
$param['Priority'] = intval($MX);
|
||||
|
@ -148,7 +158,8 @@ class aliyun implements DnsInterface {
|
|||
}
|
||||
|
||||
//修改解析记录
|
||||
public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = 'default', $TTL = 600, $MX = null, $Weight = null, $Remark = null){
|
||||
public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = 'default', $TTL = 600, $MX = null, $Weight = null, $Remark = null)
|
||||
{
|
||||
$param = ['Action' => 'UpdateDomainRecord', 'RecordId' => $RecordId, 'RR' => $Name, 'Type' => $Type, 'Value' => $Value, 'Line' => $this->convertLineCode($Line), 'TTL' => intval($TTL)];
|
||||
if ($MX) {
|
||||
$param['Priority'] = intval($MX);
|
||||
|
@ -157,32 +168,37 @@ class aliyun implements DnsInterface {
|
|||
}
|
||||
|
||||
//修改解析记录备注
|
||||
public function updateDomainRecordRemark($RecordId, $Remark){
|
||||
public function updateDomainRecordRemark($RecordId, $Remark)
|
||||
{
|
||||
$param = ['Action' => 'UpdateDomainRecordRemark', 'RecordId' => $RecordId, 'Remark' => $Remark];
|
||||
return $this->request($param);
|
||||
}
|
||||
|
||||
//删除解析记录
|
||||
public function deleteDomainRecord($RecordId){
|
||||
public function deleteDomainRecord($RecordId)
|
||||
{
|
||||
$param = ['Action' => 'DeleteDomainRecord', 'RecordId' => $RecordId];
|
||||
return $this->request($param);
|
||||
}
|
||||
|
||||
//删除子域名的解析记录
|
||||
public function deleteSubDomainRecords($SubDomain){
|
||||
public function deleteSubDomainRecords($SubDomain)
|
||||
{
|
||||
$param = ['Action' => 'DeleteSubDomainRecords', 'DomainName' => $this->domain, 'RR' => $SubDomain];
|
||||
return $this->request($param);
|
||||
}
|
||||
|
||||
//设置解析记录状态
|
||||
public function setDomainRecordStatus($RecordId, $Status){
|
||||
public function setDomainRecordStatus($RecordId, $Status)
|
||||
{
|
||||
$Status = $Status == '1' ? 'Enable' : 'Disable';
|
||||
$param = ['Action' => 'SetDomainRecordStatus', 'RecordId' => $RecordId, 'Status' => $Status];
|
||||
return $this->request($param);
|
||||
}
|
||||
|
||||
//获取解析记录操作日志
|
||||
public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null){
|
||||
public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null)
|
||||
{
|
||||
$param = ['Action' => 'DescribeRecordLogs', 'DomainName' => $this->domain, 'PageNumber' => $PageNumber, 'PageSize' => $PageSize, 'KeyWord' => $KeyWord, 'StartDate' => $StartDate, 'endDate' => $endDate, 'Lang' => 'zh'];
|
||||
$data = $this->request($param, true);
|
||||
if ($data) {
|
||||
|
@ -196,7 +212,8 @@ class aliyun implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取解析线路列表
|
||||
public function getRecordLine(){
|
||||
public function getRecordLine()
|
||||
{
|
||||
$data = $this->getDomainInfo();
|
||||
if ($data) {
|
||||
$list = [];
|
||||
|
@ -209,7 +226,8 @@ class aliyun implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名信息
|
||||
public function getDomainInfo(){
|
||||
public function getDomainInfo()
|
||||
{
|
||||
if (!empty($this->domainInfo)) return $this->domainInfo;
|
||||
$param = ['Action' => 'DescribeDomainInfo', 'DomainName' => $this->domain, 'NeedDetailAttributes' => 'true'];
|
||||
$data = $this->request($param, true);
|
||||
|
@ -221,7 +239,8 @@ class aliyun implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名最低TTL
|
||||
public function getMinTTL(){
|
||||
public function getMinTTL()
|
||||
{
|
||||
$data = $this->getDomainInfo();
|
||||
if ($data) {
|
||||
return $data['MinTtl'];
|
||||
|
@ -229,7 +248,8 @@ class aliyun implements DnsInterface {
|
|||
return false;
|
||||
}
|
||||
|
||||
private function convertLineCode($line){
|
||||
private function convertLineCode($line)
|
||||
{
|
||||
$convert_dict = ['0' => 'default', '10=1' => 'unicom', '10=0' => 'telecom', '10=3' => 'mobile', '10=2' => 'edu', '3=0' => 'oversea', '10=22' => 'btvn', '80=0' => 'search', '7=0' => 'internal'];
|
||||
if (array_key_exists($line, $convert_dict)) {
|
||||
return $convert_dict[$line];
|
||||
|
@ -257,7 +277,8 @@ class aliyun implements DnsInterface {
|
|||
$replace = ['%20', '%2A', '~'];
|
||||
return str_replace($search, $replace, urlencode($str));
|
||||
}
|
||||
private function request($param, $returnData=false){
|
||||
private function request($param, $returnData = false)
|
||||
{
|
||||
if (empty($this->AccessKeyId) || empty($this->AccessKeySecret)) return false;
|
||||
$result = $this->request_do($param, $returnData);
|
||||
if (!$returnData && $result !== true) {
|
||||
|
@ -266,7 +287,8 @@ class aliyun implements DnsInterface {
|
|||
}
|
||||
return $result;
|
||||
}
|
||||
private function request_do($param, $returnData=false){
|
||||
private function request_do($param, $returnData = false)
|
||||
{
|
||||
if (empty($this->AccessKeyId) || empty($this->AccessKeySecret)) return false;
|
||||
$url = 'https://' . $this->Endpoint . '/';
|
||||
$data = array(
|
||||
|
@ -276,7 +298,8 @@ class aliyun implements DnsInterface {
|
|||
'SignatureMethod' => 'HMAC-SHA1',
|
||||
'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'),
|
||||
'SignatureVersion' => '1.0',
|
||||
'SignatureNonce' => random(8));
|
||||
'SignatureNonce' => random(8)
|
||||
);
|
||||
$data = array_merge($data, $param);
|
||||
$data['Signature'] = $this->aliyunSignature($data, $this->AccessKeySecret, 'POST');
|
||||
$ch = curl_init($url);
|
||||
|
@ -307,7 +330,8 @@ class aliyun implements DnsInterface {
|
|||
}
|
||||
}
|
||||
|
||||
private function setError($message){
|
||||
private function setError($message)
|
||||
{
|
||||
$this->error = $message;
|
||||
//file_put_contents('logs.txt',date('H:i:s').' '.$message."\r\n", FILE_APPEND);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace app\lib\dns;
|
||||
|
||||
use app\lib\DnsInterface;
|
||||
|
||||
class baidu implements DnsInterface {
|
||||
class baidu implements DnsInterface
|
||||
{
|
||||
private $AccessKeyId;
|
||||
private $SecretAccessKey;
|
||||
private $endpoint = "dns.baidubce.com";
|
||||
|
@ -11,18 +13,21 @@ class baidu implements DnsInterface {
|
|||
private $domain;
|
||||
private $domainid;
|
||||
|
||||
function __construct($config){
|
||||
public function __construct($config)
|
||||
{
|
||||
$this->AccessKeyId = $config['ak'];
|
||||
$this->SecretAccessKey = $config['sk'];
|
||||
$this->domain = $config['domain'];
|
||||
$this->domainid = $config['domainid'];
|
||||
}
|
||||
|
||||
public function getError(){
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function check(){
|
||||
public function check()
|
||||
{
|
||||
if ($this->getDomainList() != false) {
|
||||
return true;
|
||||
}
|
||||
|
@ -30,7 +35,8 @@ class baidu implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名列表
|
||||
public function getDomainList($KeyWord=null, $PageNumber=1, $PageSize=20){
|
||||
public function getDomainList($KeyWord = null, $PageNumber = 1, $PageSize = 20)
|
||||
{
|
||||
$query = ['name' => $KeyWord];
|
||||
$data = $this->send_reuqest('GET', '/v1/dns/zone', $query);
|
||||
if ($data) {
|
||||
|
@ -48,7 +54,8 @@ class baidu implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取解析记录列表
|
||||
public function getDomainRecords($PageNumber=1, $PageSize=20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null){
|
||||
public function getDomainRecords($PageNumber = 1, $PageSize = 20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null)
|
||||
{
|
||||
$query = ['rr' => $KeyWord];
|
||||
if (!isNullOrEmpty($SubDomain)) {
|
||||
$query['rr'] = $SubDomain;
|
||||
|
@ -78,13 +85,15 @@ class baidu implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取子域名解析记录列表
|
||||
public function getSubDomainRecords($SubDomain, $PageNumber=1, $PageSize=20, $Type = null, $Line = null){
|
||||
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){
|
||||
public function getDomainRecordInfo($RecordId)
|
||||
{
|
||||
$query = ['id' => $RecordId];
|
||||
$data = $this->send_reuqest('GET', '/v1/dns/zone/'.$this->domain.'/record', $query);
|
||||
if ($data && !empty($data['records'])) {
|
||||
|
@ -108,7 +117,8 @@ class baidu implements DnsInterface {
|
|||
}
|
||||
|
||||
//添加解析记录
|
||||
public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null){
|
||||
public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null)
|
||||
{
|
||||
$params = ['rr' => $Name, 'type' => $this->convertType($Type), 'value' => $Value, 'line' => $Line, 'ttl' => intval($TTL), 'description' => $Remark];
|
||||
if ($Type == 'MX') $params['priority'] = intval($MX);
|
||||
$query = ['clientToken' => getSid()];
|
||||
|
@ -116,7 +126,8 @@ class baidu implements DnsInterface {
|
|||
}
|
||||
|
||||
//修改解析记录
|
||||
public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null){
|
||||
public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null)
|
||||
{
|
||||
$params = ['rr' => $Name, 'type' => $this->convertType($Type), 'value' => $Value, 'line' => $Line, 'ttl' => intval($TTL), 'description' => $Remark];
|
||||
if ($Type == 'MX') $params['priority'] = intval($MX);
|
||||
$query = ['clientToken' => getSid()];
|
||||
|
@ -124,30 +135,35 @@ class baidu implements DnsInterface {
|
|||
}
|
||||
|
||||
//修改解析记录备注
|
||||
public function updateDomainRecordRemark($RecordId, $Remark){
|
||||
public function updateDomainRecordRemark($RecordId, $Remark)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//删除解析记录
|
||||
public function deleteDomainRecord($RecordId){
|
||||
public function deleteDomainRecord($RecordId)
|
||||
{
|
||||
$query = ['clientToken' => getSid()];
|
||||
return $this->send_reuqest('DELETE', '/v1/dns/zone/'.$this->domain.'/record/'.$RecordId, $query);
|
||||
}
|
||||
|
||||
//设置解析记录状态
|
||||
public function setDomainRecordStatus($RecordId, $Status){
|
||||
public function setDomainRecordStatus($RecordId, $Status)
|
||||
{
|
||||
$Status = $Status == '1' ? 'enable' : 'disable';
|
||||
$query = [$Status => '', 'clientToken' => getSid()];
|
||||
return $this->send_reuqest('PUT', '/v1/dns/zone/'.$this->domain.'/record/'.$RecordId, $query);
|
||||
}
|
||||
|
||||
//获取解析记录操作日志
|
||||
public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null){
|
||||
public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//获取解析线路列表
|
||||
public function getRecordLine(){
|
||||
public function getRecordLine()
|
||||
{
|
||||
return [
|
||||
'default' => ['name' => '默认', 'parent' => null],
|
||||
'ct' => ['name' => '电信', 'parent' => null],
|
||||
|
@ -159,7 +175,8 @@ class baidu implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名概览信息
|
||||
public function getDomainInfo(){
|
||||
public function getDomainInfo()
|
||||
{
|
||||
$res = $this->getDomainList($this->domain);
|
||||
if ($res && !empty($res['list'])) {
|
||||
return $res['list'][0];
|
||||
|
@ -168,15 +185,18 @@ class baidu implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名最低TTL
|
||||
public function getMinTTL(){
|
||||
public function getMinTTL()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private function convertType($type){
|
||||
private function convertType($type)
|
||||
{
|
||||
return $type;
|
||||
}
|
||||
|
||||
private function send_reuqest($method, $path, $query = null, $params = null){
|
||||
private function send_reuqest($method, $path, $query = null, $params = null)
|
||||
{
|
||||
if (!empty($query)) {
|
||||
$query = array_filter($query, function ($a) { return $a !== null;});
|
||||
}
|
||||
|
@ -209,7 +229,8 @@ class baidu implements DnsInterface {
|
|||
return $this->curl($method, $url, $body, $header);
|
||||
}
|
||||
|
||||
private function generateSign($method, $path, $query, $headers, $time){
|
||||
private function generateSign($method, $path, $query, $headers, $time)
|
||||
{
|
||||
$algorithm = "bce-auth-v1";
|
||||
|
||||
// step 1: build canonical request string
|
||||
|
@ -264,7 +285,8 @@ class baidu implements DnsInterface {
|
|||
return substr($canonicalQueryString, 1);
|
||||
}
|
||||
|
||||
private function getCanonicalHeaders($oldheaders){
|
||||
private function getCanonicalHeaders($oldheaders)
|
||||
{
|
||||
$headers = array();
|
||||
foreach ($oldheaders as $key => $value) {
|
||||
$headers[strtolower($key)] = trim($value);
|
||||
|
@ -282,7 +304,8 @@ class baidu implements DnsInterface {
|
|||
return [$canonicalHeaders, $signedHeaders];
|
||||
}
|
||||
|
||||
private function curl($method, $url, $body, $header){
|
||||
private function curl($method, $url, $body, $header)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
|
@ -319,7 +342,8 @@ class baidu implements DnsInterface {
|
|||
}
|
||||
}
|
||||
|
||||
private function setError($message){
|
||||
private function setError($message)
|
||||
{
|
||||
$this->error = $message;
|
||||
//file_put_contents('logs.txt',date('H:i:s').' '.$message."\r\n", FILE_APPEND);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace app\lib\dns;
|
||||
|
||||
use app\lib\DnsInterface;
|
||||
|
||||
class cloudflare implements DnsInterface {
|
||||
class cloudflare implements DnsInterface
|
||||
{
|
||||
private $Email;
|
||||
private $ApiKey;
|
||||
private $baseUrl = 'https://api.cloudflare.com/client/v4';
|
||||
|
@ -11,27 +13,34 @@ class cloudflare implements DnsInterface {
|
|||
private $domain;
|
||||
private $domainid;
|
||||
|
||||
function __construct($config){
|
||||
function __construct($config)
|
||||
{
|
||||
$this->Email = $config['ak'];
|
||||
$this->ApiKey = $config['sk'];
|
||||
$this->domain = $config['domain'];
|
||||
$this->domainid = $config['domainid'];
|
||||
}
|
||||
|
||||
public function getError(){
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function check(){
|
||||
if($this->getDomainList() != false){
|
||||
public function check()
|
||||
{
|
||||
if ($this->getDomainList() !== false) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//获取域名列表
|
||||
public function getDomainList($KeyWord=null, $PageNumber=1, $PageSize=20){
|
||||
$param = ['page' => $PageNumber, 'per_page' => $PageSize, 'name' => $KeyWord];
|
||||
public function getDomainList($KeyWord = null, $PageNumber = 1, $PageSize = 20)
|
||||
{
|
||||
$param = ['page' => $PageNumber, 'per_page' => $PageSize];
|
||||
if (!empty($KeyWord)) {
|
||||
$param['name'] = $KeyWord;
|
||||
}
|
||||
$data = $this->send_reuqest('GET', '/zones', $param);
|
||||
if ($data) {
|
||||
$list = [];
|
||||
|
@ -48,7 +57,8 @@ class cloudflare implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取解析记录列表
|
||||
public function getDomainRecords($PageNumber=1, $PageSize=20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null){
|
||||
public function getDomainRecords($PageNumber = 1, $PageSize = 20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null)
|
||||
{
|
||||
if (!isNullOrEmpty($SubDomain)) {
|
||||
if ($SubDomain == '@') $SubDomain = $this->domain;
|
||||
else $SubDomain .= '.' . $this->domain;
|
||||
|
@ -84,12 +94,14 @@ class cloudflare implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取子域名解析记录列表
|
||||
public function getSubDomainRecords($SubDomain, $PageNumber=1, $PageSize=20, $Type = null, $Line = null){
|
||||
public function getSubDomainRecords($SubDomain, $PageNumber = 1, $PageSize = 20, $Type = null, $Line = null)
|
||||
{
|
||||
return $this->getDomainRecords($PageNumber, $PageSize, null, $SubDomain, null, $Type, $Line);
|
||||
}
|
||||
|
||||
//获取解析记录详细信息
|
||||
public function getDomainRecordInfo($RecordId){
|
||||
public function getDomainRecordInfo($RecordId)
|
||||
{
|
||||
$data = $this->send_reuqest('GET', '/zones/'.$this->domainid.'/dns_records/'.$RecordId);
|
||||
if ($data) {
|
||||
$name = $data['result']['zone_name'] == $data['result']['name'] ? '@' : str_replace('.' . $data['result']['zone_name'], '', $data['result']['name']);
|
||||
|
@ -112,7 +124,8 @@ class cloudflare implements DnsInterface {
|
|||
}
|
||||
|
||||
//添加解析记录
|
||||
public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $Weight = null, $MX = 1, $Remark = null){
|
||||
public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null)
|
||||
{
|
||||
$param = ['name' => $Name, 'type' => $this->convertType($Type), 'content' => $Value, 'proxied' => $Line == '1', 'ttl' => intval($TTL), 'comment' => $Remark];
|
||||
if ($Type == 'MX') $param['priority'] = intval($MX);
|
||||
if ($Type == 'CAA' || $Type == 'SRV') {
|
||||
|
@ -124,7 +137,8 @@ class cloudflare implements DnsInterface {
|
|||
}
|
||||
|
||||
//修改解析记录
|
||||
public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = '0', $TTL = 600, $Weight = null, $MX = 1, $Remark = null){
|
||||
public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null)
|
||||
{
|
||||
$param = ['name' => $Name, 'type' => $this->convertType($Type), 'content' => $Value, 'proxied' => $Line == '1', 'ttl' => intval($TTL), 'comment' => $Remark];
|
||||
if ($Type == 'MX') $param['priority'] = intval($MX);
|
||||
if ($Type == 'CAA' || $Type == 'SRV') {
|
||||
|
@ -136,33 +150,39 @@ class cloudflare implements DnsInterface {
|
|||
}
|
||||
|
||||
//修改解析记录备注
|
||||
public function updateDomainRecordRemark($RecordId, $Remark){
|
||||
public function updateDomainRecordRemark($RecordId, $Remark)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//删除解析记录
|
||||
public function deleteDomainRecord($RecordId){
|
||||
public function deleteDomainRecord($RecordId)
|
||||
{
|
||||
$data = $this->send_reuqest('DELETE', '/zones/'.$this->domainid.'/dns_records/'.$RecordId);
|
||||
return is_array($data);
|
||||
}
|
||||
|
||||
//设置解析记录状态
|
||||
public function setDomainRecordStatus($RecordId, $Status){
|
||||
public function setDomainRecordStatus($RecordId, $Status)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//获取解析记录操作日志
|
||||
public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null){
|
||||
public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//获取解析线路列表
|
||||
public function getRecordLine(){
|
||||
public function getRecordLine()
|
||||
{
|
||||
return ['0' => ['name' => '仅DNS', 'parent' => null], '1' => ['name' => '已代理', 'parent' => null]];
|
||||
}
|
||||
|
||||
//获取域名信息
|
||||
public function getDomainInfo(){
|
||||
public function getDomainInfo()
|
||||
{
|
||||
$data = $this->send_reuqest('GET', '/zones/'.$this->domainid);
|
||||
if ($data) {
|
||||
return $data['result'];
|
||||
|
@ -171,11 +191,13 @@ class cloudflare implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名最低TTL
|
||||
public function getMinTTL(){
|
||||
public function getMinTTL()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private function convertType($type){
|
||||
private function convertType($type)
|
||||
{
|
||||
$convert_dict = ['REDIRECT_URL' => 'URI', 'FORWARD_URL' => 'URI'];
|
||||
if (array_key_exists($type, $convert_dict)) {
|
||||
return $convert_dict[$type];
|
||||
|
@ -183,7 +205,8 @@ class cloudflare implements DnsInterface {
|
|||
return $type;
|
||||
}
|
||||
|
||||
private function convertValue($value, $type){
|
||||
private function convertValue($value, $type)
|
||||
{
|
||||
if ($type == 'SRV') {
|
||||
$arr = explode(' ', $value);
|
||||
if (count($arr) > 3) {
|
||||
|
@ -211,7 +234,8 @@ class cloudflare implements DnsInterface {
|
|||
return $data;
|
||||
}
|
||||
|
||||
private function send_reuqest($method, $path, $params = null){
|
||||
private function send_reuqest($method, $path, $params = null)
|
||||
{
|
||||
$url = $this->baseUrl . $path;
|
||||
|
||||
if (preg_match('/^[0-9a-z]+$/i', $this->ApiKey)) {
|
||||
|
@ -275,7 +299,8 @@ class cloudflare implements DnsInterface {
|
|||
}
|
||||
}
|
||||
|
||||
private function setError($message){
|
||||
private function setError($message)
|
||||
{
|
||||
$this->error = $message;
|
||||
//file_put_contents('logs.txt',date('H:i:s').' '.$message."\r\n", FILE_APPEND);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace app\lib\dns;
|
||||
|
||||
use app\lib\DnsInterface;
|
||||
|
||||
class dnsla implements DnsInterface {
|
||||
class dnsla implements DnsInterface
|
||||
{
|
||||
private $apiid;
|
||||
private $apisecret;
|
||||
private $baseUrl = 'https://api.dns.la';
|
||||
|
@ -12,18 +14,21 @@ class dnsla implements DnsInterface {
|
|||
private $domain;
|
||||
private $domainid;
|
||||
|
||||
function __construct($config){
|
||||
public function __construct($config)
|
||||
{
|
||||
$this->apiid = $config['ak'];
|
||||
$this->apisecret = $config['sk'];
|
||||
$this->domain = $config['domain'];
|
||||
$this->domainid = $config['domainid'];
|
||||
}
|
||||
|
||||
public function getError(){
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function check(){
|
||||
public function check()
|
||||
{
|
||||
if ($this->getDomainList() != false) {
|
||||
return true;
|
||||
}
|
||||
|
@ -31,7 +36,8 @@ class dnsla implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名列表
|
||||
public function getDomainList($KeyWord=null, $PageNumber=1, $PageSize=20){
|
||||
public function getDomainList($KeyWord = null, $PageNumber = 1, $PageSize = 20)
|
||||
{
|
||||
$param = ['pageIndex' => $PageNumber, 'pageSize' => $PageSize];
|
||||
$data = $this->execute('GET', '/api/domainList', $param);
|
||||
if ($data) {
|
||||
|
@ -49,7 +55,8 @@ class dnsla implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取解析记录列表
|
||||
public function getDomainRecords($PageNumber=1, $PageSize=20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null){
|
||||
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))) {
|
||||
$param['host'] = $KeyWord;
|
||||
|
@ -91,64 +98,83 @@ class dnsla implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取子域名解析记录列表
|
||||
public function getSubDomainRecords($SubDomain, $PageNumber=1, $PageSize=20, $Type = null, $Line = null){
|
||||
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){
|
||||
public function getDomainRecordInfo($RecordId)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//添加解析记录
|
||||
public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null){
|
||||
public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null)
|
||||
{
|
||||
$param = ['domainId' => $this->domainid, 'type' => $this->convertType($Type), 'host' => $Name, 'data' => $Value, 'ttl' => intval($TTL), 'lineId' => $Line];
|
||||
if ($Type == 'MX') $param['preference'] = intval($MX);
|
||||
if($Type == 'REDIRECT_URL'){$param['type'] = 256;$param['dominant'] = true;}
|
||||
elseif($Type == 'FORWARD_URL'){$param['type'] = 256;$param['dominant'] = false;}
|
||||
if ($Type == 'REDIRECT_URL') {
|
||||
$param['type'] = 256;
|
||||
$param['dominant'] = true;
|
||||
} elseif ($Type == 'FORWARD_URL') {
|
||||
$param['type'] = 256;
|
||||
$param['dominant'] = false;
|
||||
}
|
||||
if ($Weight > 0) $param['weight'] = $Weight;
|
||||
$data = $this->execute('POST', '/api/record', $param);
|
||||
return is_array($data) ? $data['id'] : false;
|
||||
}
|
||||
|
||||
//修改解析记录
|
||||
public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null){
|
||||
public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null)
|
||||
{
|
||||
$param = ['id' => $RecordId, 'type' => $this->convertType($Type), 'host' => $Name, 'data' => $Value, 'ttl' => intval($TTL), 'lineId' => $Line];
|
||||
if ($Type == 'MX') $param['preference'] = intval($MX);
|
||||
if($Type == 'REDIRECT_URL'){$param['type'] = 256;$param['dominant'] = true;}
|
||||
elseif($Type == 'FORWARD_URL'){$param['type'] = 256;$param['dominant'] = false;}
|
||||
if ($Type == 'REDIRECT_URL') {
|
||||
$param['type'] = 256;
|
||||
$param['dominant'] = true;
|
||||
} elseif ($Type == 'FORWARD_URL') {
|
||||
$param['type'] = 256;
|
||||
$param['dominant'] = false;
|
||||
}
|
||||
if ($Weight > 0) $param['weight'] = $Weight;
|
||||
$data = $this->execute('PUT', '/api/record', $param);
|
||||
return $data !== false;
|
||||
}
|
||||
|
||||
//修改解析记录备注
|
||||
public function updateDomainRecordRemark($RecordId, $Remark){
|
||||
public function updateDomainRecordRemark($RecordId, $Remark)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//删除解析记录
|
||||
public function deleteDomainRecord($RecordId){
|
||||
public function deleteDomainRecord($RecordId)
|
||||
{
|
||||
$param = ['id' => $RecordId];
|
||||
$data = $this->execute('DELETE', '/api/record', $param);
|
||||
return $data !== false;
|
||||
}
|
||||
|
||||
//设置解析记录状态
|
||||
public function setDomainRecordStatus($RecordId, $Status){
|
||||
public function setDomainRecordStatus($RecordId, $Status)
|
||||
{
|
||||
$param = ['id' => $RecordId, 'disable' => $Status == '0' ? true : false];
|
||||
$data = $this->execute('PUT', '/api/recordDisable', $param);
|
||||
return $data !== false;
|
||||
}
|
||||
|
||||
//获取解析记录操作日志
|
||||
public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null){
|
||||
public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//获取解析线路列表
|
||||
public function getRecordLine(){
|
||||
public function getRecordLine()
|
||||
{
|
||||
$param = ['domain' => $this->domain];
|
||||
$data = $this->execute('GET', '/api/availableLine', $param);
|
||||
if ($data) {
|
||||
|
@ -164,14 +190,16 @@ class dnsla implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名信息
|
||||
public function getDomainInfo(){
|
||||
public function getDomainInfo()
|
||||
{
|
||||
$param = ['id' => $this->domainid];
|
||||
$data = $this->execute('GET', '/api/domain', $param);
|
||||
return $data;
|
||||
}
|
||||
|
||||
//获取域名最低TTL
|
||||
public function getMinTTL(){
|
||||
public function getMinTTL()
|
||||
{
|
||||
$param = ['id' => $this->domainid];
|
||||
$data = $this->execute('GET', '/api/dnsMeasures', $param);
|
||||
if ($data && isset($data['minTTL'])) {
|
||||
|
@ -180,17 +208,20 @@ class dnsla implements DnsInterface {
|
|||
return false;
|
||||
}
|
||||
|
||||
private function convertType($type){
|
||||
private function convertType($type)
|
||||
{
|
||||
$typeList = array_flip($this->typeList);
|
||||
return $typeList[$type];
|
||||
}
|
||||
|
||||
private function convertTypeId($typeId, $domaint){
|
||||
private function convertTypeId($typeId, $domaint)
|
||||
{
|
||||
if ($typeId == 256) return $domaint ? 'REDIRECT_URL' : 'FORWARD_URL';
|
||||
return $this->typeList[$typeId];
|
||||
}
|
||||
|
||||
private function execute($method, $path, $params = null){
|
||||
private function execute($method, $path, $params = null)
|
||||
{
|
||||
$token = base64_encode($this->apiid.':'.$this->apisecret);
|
||||
$header = ['Authorization: Basic '.$token, 'Content-Type: application/json; charset=utf-8'];
|
||||
if ($method == 'POST' || $method == 'PUT') {
|
||||
|
@ -218,7 +249,8 @@ class dnsla implements DnsInterface {
|
|||
}
|
||||
}
|
||||
|
||||
private function curl($method, $path, $header, $body = null, $isPut = false){
|
||||
private function curl($method, $path, $header, $body = null, $isPut = false)
|
||||
{
|
||||
$url = $this->baseUrl . $path;
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
|
@ -249,7 +281,8 @@ class dnsla implements DnsInterface {
|
|||
}
|
||||
}
|
||||
|
||||
private function setError($message){
|
||||
private function setError($message)
|
||||
{
|
||||
$this->error = $message;
|
||||
//file_put_contents('logs.txt',date('H:i:s').' '.$message."\r\n", FILE_APPEND);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace app\lib\dns;
|
||||
|
||||
use app\lib\DnsInterface;
|
||||
|
||||
class dnspod implements DnsInterface {
|
||||
class dnspod implements DnsInterface
|
||||
{
|
||||
private $SecretId;
|
||||
private $SecretKey;
|
||||
private $endpoint = "dnspod.tencentcloudapi.com";
|
||||
|
@ -14,17 +16,20 @@ class dnspod implements DnsInterface {
|
|||
private $domainid;
|
||||
private $domainInfo;
|
||||
|
||||
function __construct($config){
|
||||
public function __construct($config)
|
||||
{
|
||||
$this->SecretId = $config['ak'];
|
||||
$this->SecretKey = $config['sk'];
|
||||
$this->domain = $config['domain'];
|
||||
}
|
||||
|
||||
public function getError(){
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function check(){
|
||||
public function check()
|
||||
{
|
||||
if ($this->getDomainList() != false) {
|
||||
return true;
|
||||
}
|
||||
|
@ -32,7 +37,8 @@ class dnspod implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名列表
|
||||
public function getDomainList($KeyWord=null, $PageNumber=1, $PageSize=20){
|
||||
public function getDomainList($KeyWord = null, $PageNumber = 1, $PageSize = 20)
|
||||
{
|
||||
$action = 'DescribeDomainList';
|
||||
$offset = ($PageNumber - 1) * $PageSize;
|
||||
$param = ['Offset' => $offset, 'Limit' => $PageSize, 'Keyword' => $KeyWord];
|
||||
|
@ -52,7 +58,8 @@ class dnspod implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取解析记录列表
|
||||
public function getDomainRecords($PageNumber=1, $PageSize=20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null){
|
||||
public function getDomainRecords($PageNumber = 1, $PageSize = 20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null)
|
||||
{
|
||||
$offset = ($PageNumber - 1) * $PageSize;
|
||||
if (!isNullOrEmpty($Status) || !isNullOrEmpty($Value)) {
|
||||
$action = 'DescribeRecordFilterList';
|
||||
|
@ -98,13 +105,15 @@ class dnspod implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取子域名解析记录列表
|
||||
public function getSubDomainRecords($SubDomain, $PageNumber=1, $PageSize=20, $Type = null, $Line = null){
|
||||
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){
|
||||
public function getDomainRecordInfo($RecordId)
|
||||
{
|
||||
$action = 'DescribeRecord';
|
||||
$param = ['Domain' => $this->domain, 'RecordId' => intval($RecordId)];
|
||||
$data = $this->send_reuqest($action, $param);
|
||||
|
@ -128,7 +137,8 @@ class dnspod implements DnsInterface {
|
|||
}
|
||||
|
||||
//添加解析记录
|
||||
public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null){
|
||||
public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null)
|
||||
{
|
||||
$action = 'CreateRecord';
|
||||
$param = ['Domain' => $this->domain, 'SubDomain' => $Name, 'RecordType' => $this->convertType($Type), 'Value' => $Value, 'RecordLine' => $Line, 'RecordLineId' => $this->convertLineCode($Line), 'TTL' => intval($TTL), 'Weight' => $Weight];
|
||||
if ($Type == 'MX') $param['MX'] = intval($MX);
|
||||
|
@ -137,7 +147,8 @@ class dnspod implements DnsInterface {
|
|||
}
|
||||
|
||||
//修改解析记录
|
||||
public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null){
|
||||
public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null)
|
||||
{
|
||||
$action = 'ModifyRecord';
|
||||
$param = ['Domain' => $this->domain, 'RecordId' => intval($RecordId), 'SubDomain' => $Name, 'RecordType' => $this->convertType($Type), 'Value' => $Value, 'RecordLine' => $Line, 'RecordLineId' => $this->convertLineCode($Line), 'TTL' => intval($TTL), 'Weight' => $Weight];
|
||||
if ($Type == 'MX') $param['MX'] = intval($MX);
|
||||
|
@ -146,7 +157,8 @@ class dnspod implements DnsInterface {
|
|||
}
|
||||
|
||||
//修改解析记录备注
|
||||
public function updateDomainRecordRemark($RecordId, $Remark){
|
||||
public function updateDomainRecordRemark($RecordId, $Remark)
|
||||
{
|
||||
$action = 'ModifyRecordRemark';
|
||||
$param = ['Domain' => $this->domain, 'RecordId' => intval($RecordId), 'Remark' => $Remark];
|
||||
$data = $this->send_reuqest($action, $param);
|
||||
|
@ -154,7 +166,8 @@ class dnspod implements DnsInterface {
|
|||
}
|
||||
|
||||
//删除解析记录
|
||||
public function deleteDomainRecord($RecordId){
|
||||
public function deleteDomainRecord($RecordId)
|
||||
{
|
||||
$action = 'DeleteRecord';
|
||||
$param = ['Domain' => $this->domain, 'RecordId' => intval($RecordId)];
|
||||
$data = $this->send_reuqest($action, $param);
|
||||
|
@ -162,7 +175,8 @@ class dnspod implements DnsInterface {
|
|||
}
|
||||
|
||||
//设置解析记录状态
|
||||
public function setDomainRecordStatus($RecordId, $Status){
|
||||
public function setDomainRecordStatus($RecordId, $Status)
|
||||
{
|
||||
$Status = $Status == '1' ? 'ENABLE' : 'DISABLE';
|
||||
$action = 'ModifyRecordStatus';
|
||||
$param = ['Domain' => $this->domain, 'RecordId' => intval($RecordId), 'Status' => $Status];
|
||||
|
@ -171,7 +185,8 @@ class dnspod implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取解析记录操作日志
|
||||
public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null){
|
||||
public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null)
|
||||
{
|
||||
$action = 'DescribeDomainLogList';
|
||||
$offset = ($PageNumber - 1) * $PageSize;
|
||||
$param = ['Domain' => $this->domain, 'Offset' => $offset, 'Limit' => $PageSize];
|
||||
|
@ -187,7 +202,8 @@ class dnspod implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取解析线路列表
|
||||
public function getRecordLine(){
|
||||
public function getRecordLine()
|
||||
{
|
||||
$action = 'DescribeRecordLineCategoryList';
|
||||
$param = ['Domain' => $this->domain];
|
||||
$data = $this->send_reuqest($action, $param);
|
||||
|
@ -208,7 +224,8 @@ class dnspod implements DnsInterface {
|
|||
return false;
|
||||
}
|
||||
|
||||
private function processLineList(&$list, $line_list, $parent){
|
||||
private function processLineList(&$list, $line_list, $parent)
|
||||
{
|
||||
foreach ($line_list as $row) {
|
||||
if (isNullOrEmpty($row['LineId'])) $row['LineId'] = 'N.' . $row['LineName'];
|
||||
if ($row['Useful'] && !isset($list[$row['LineId']])) {
|
||||
|
@ -221,7 +238,8 @@ class dnspod implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名概览信息
|
||||
public function getDomainInfo(){
|
||||
public function getDomainInfo()
|
||||
{
|
||||
$action = 'DescribeDomain';
|
||||
$param = ['Domain' => $this->domain];
|
||||
$data = $this->send_reuqest($action, $param);
|
||||
|
@ -233,7 +251,8 @@ class dnspod implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名权限
|
||||
public function getDomainPurview(){
|
||||
public function getDomainPurview()
|
||||
{
|
||||
$action = 'DescribeDomainPurview';
|
||||
$param = ['Domain' => $this->domain];
|
||||
$data = $this->send_reuqest($action, $param);
|
||||
|
@ -244,7 +263,8 @@ class dnspod implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名最低TTL
|
||||
public function getMinTTL(){
|
||||
public function getMinTTL()
|
||||
{
|
||||
if ($this->domainInfo) {
|
||||
return $this->domainInfo['TTL'];
|
||||
}
|
||||
|
@ -260,7 +280,8 @@ class dnspod implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取等级允许的线路
|
||||
public function getRecordLineByGrade(){
|
||||
public function getRecordLineByGrade()
|
||||
{
|
||||
$action = 'DescribeRecordLineList';
|
||||
$param = ['Domain' => $this->domain, 'DomainGrade' => ''];
|
||||
$data = $this->send_reuqest($action, $param);
|
||||
|
@ -277,7 +298,8 @@ class dnspod implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取用户信息
|
||||
public function getAccountInfo(){
|
||||
public function getAccountInfo()
|
||||
{
|
||||
$action = 'DescribeUserDetail';
|
||||
$param = [];
|
||||
$data = $this->send_reuqest($action, $param);
|
||||
|
@ -287,7 +309,8 @@ class dnspod implements DnsInterface {
|
|||
return false;
|
||||
}
|
||||
|
||||
private function convertLineCode($line){
|
||||
private function convertLineCode($line)
|
||||
{
|
||||
$convert_dict = ['default' => '0', 'unicom' => '10=1', 'telecom' => '10=0', 'mobile' => '10=3', 'edu' => '10=2', 'oversea' => '3=0', 'btvn' => '10=22', 'search' => '80=0', 'internal' => '7=0'];
|
||||
if (array_key_exists($line, $convert_dict)) {
|
||||
return $convert_dict[$line];
|
||||
|
@ -295,7 +318,8 @@ class dnspod implements DnsInterface {
|
|||
return $line;
|
||||
}
|
||||
|
||||
private function convertType($type){
|
||||
private function convertType($type)
|
||||
{
|
||||
$convert_dict = ['REDIRECT_URL' => '显性URL', 'FORWARD_URL' => '隐性URL'];
|
||||
if (array_key_exists($type, $convert_dict)) {
|
||||
return $convert_dict[$type];
|
||||
|
@ -303,7 +327,8 @@ class dnspod implements DnsInterface {
|
|||
return $type;
|
||||
}
|
||||
|
||||
private function convertTypeId($type){
|
||||
private function convertTypeId($type)
|
||||
{
|
||||
$convert_dict = ['显性URL' => 'REDIRECT_URL', '隐性URL' => 'FORWARD_URL'];
|
||||
if (array_key_exists($type, $convert_dict)) {
|
||||
return $convert_dict[$type];
|
||||
|
@ -312,7 +337,8 @@ class dnspod implements DnsInterface {
|
|||
}
|
||||
|
||||
|
||||
private function send_reuqest($action, $param){
|
||||
private function send_reuqest($action, $param)
|
||||
{
|
||||
$param = array_filter($param, function ($a) { return $a !== null;});
|
||||
if (!$param) $param = (object)[];
|
||||
$payload = json_encode($param);
|
||||
|
@ -328,7 +354,8 @@ class dnspod implements DnsInterface {
|
|||
return $this->curl_post($payload, $header);
|
||||
}
|
||||
|
||||
private function generateSign($payload, $time){
|
||||
private function generateSign($payload, $time)
|
||||
{
|
||||
$algorithm = "TC3-HMAC-SHA256";
|
||||
|
||||
// step 1: build canonical request string
|
||||
|
@ -368,7 +395,8 @@ class dnspod implements DnsInterface {
|
|||
return $authorization;
|
||||
}
|
||||
|
||||
private function curl_post($payload, $header){
|
||||
private function curl_post($payload, $header)
|
||||
{
|
||||
$url = 'https://'.$this->endpoint.'/';
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
|
@ -400,7 +428,8 @@ class dnspod implements DnsInterface {
|
|||
}
|
||||
}
|
||||
|
||||
private function setError($message){
|
||||
private function setError($message)
|
||||
{
|
||||
$this->error = $message;
|
||||
//file_put_contents('logs.txt',date('H:i:s').' '.$message."\r\n", FILE_APPEND);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace app\lib\dns;
|
||||
|
||||
use app\lib\DnsInterface;
|
||||
|
||||
class huawei implements DnsInterface {
|
||||
class huawei implements DnsInterface
|
||||
{
|
||||
private $AccessKeyId;
|
||||
private $SecretAccessKey;
|
||||
private $endpoint = "dns.myhuaweicloud.com";
|
||||
|
@ -11,18 +13,21 @@ class huawei implements DnsInterface {
|
|||
private $domain;
|
||||
private $domainid;
|
||||
|
||||
function __construct($config){
|
||||
public function __construct($config)
|
||||
{
|
||||
$this->AccessKeyId = $config['ak'];
|
||||
$this->SecretAccessKey = $config['sk'];
|
||||
$this->domain = $config['domain'];
|
||||
$this->domainid = $config['domainid'];
|
||||
}
|
||||
|
||||
public function getError(){
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function check(){
|
||||
public function check()
|
||||
{
|
||||
if ($this->getDomainList() != false) {
|
||||
return true;
|
||||
}
|
||||
|
@ -30,7 +35,8 @@ class huawei implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名列表
|
||||
public function getDomainList($KeyWord=null, $PageNumber=1, $PageSize=20){
|
||||
public function getDomainList($KeyWord = null, $PageNumber = 1, $PageSize = 20)
|
||||
{
|
||||
$offset = ($PageNumber - 1) * $PageSize;
|
||||
$query = ['offset' => $offset, 'limit' => $PageSize, 'name' => $KeyWord];
|
||||
$data = $this->send_reuqest('GET', '/v2/zones', $query);
|
||||
|
@ -49,7 +55,8 @@ class huawei implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取解析记录列表
|
||||
public function getDomainRecords($PageNumber=1, $PageSize=20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null){
|
||||
public function getDomainRecords($PageNumber = 1, $PageSize = 20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null)
|
||||
{
|
||||
$offset = ($PageNumber - 1) * $PageSize;
|
||||
$query = ['type' => $Type, 'line_id' => $Line, 'name' => $KeyWord, 'offset' => $offset, 'limit' => $PageSize];
|
||||
if (!isNullOrEmpty($Status)) {
|
||||
|
@ -88,12 +95,14 @@ class huawei implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取子域名解析记录列表
|
||||
public function getSubDomainRecords($SubDomain, $PageNumber=1, $PageSize=20, $Type = null, $Line = null){
|
||||
public function getSubDomainRecords($SubDomain, $PageNumber = 1, $PageSize = 20, $Type = null, $Line = null)
|
||||
{
|
||||
return $this->getDomainRecords($PageNumber, $PageSize, null, $SubDomain, null, $Type, $Line);
|
||||
}
|
||||
|
||||
//获取解析记录详细信息
|
||||
public function getDomainRecordInfo($RecordId){
|
||||
public function getDomainRecordInfo($RecordId)
|
||||
{
|
||||
$data = $this->send_reuqest('GET', '/v2.1/zones/'.$this->domainid.'/recordsets/'.$RecordId);
|
||||
if ($data) {
|
||||
if ($data['name'] == $data['zone_name']) $data['name'] = '@';
|
||||
|
@ -117,7 +126,8 @@ class huawei implements DnsInterface {
|
|||
}
|
||||
|
||||
//添加解析记录
|
||||
public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null){
|
||||
public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null)
|
||||
{
|
||||
$Name = $this->getHost($Name);
|
||||
if ($Type == 'TXT' && substr($Value, 0, 1) != '"') $Value = '"' . $Value . '"';
|
||||
$records = explode(',', $Value);
|
||||
|
@ -129,7 +139,8 @@ class huawei implements DnsInterface {
|
|||
}
|
||||
|
||||
//修改解析记录
|
||||
public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null){
|
||||
public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null)
|
||||
{
|
||||
$Name = $this->getHost($Name);
|
||||
if ($Type == 'TXT' && substr($Value, 0, 1) != '"') $Value = '"' . $Value . '"';
|
||||
$records = explode(',', $Value);
|
||||
|
@ -141,18 +152,21 @@ class huawei implements DnsInterface {
|
|||
}
|
||||
|
||||
//修改解析记录备注
|
||||
public function updateDomainRecordRemark($RecordId, $Remark){
|
||||
public function updateDomainRecordRemark($RecordId, $Remark)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//删除解析记录
|
||||
public function deleteDomainRecord($RecordId){
|
||||
public function deleteDomainRecord($RecordId)
|
||||
{
|
||||
$data = $this->send_reuqest('DELETE', '/v2.1/zones/'.$this->domainid.'/recordsets/'.$RecordId);
|
||||
return is_array($data);
|
||||
}
|
||||
|
||||
//设置解析记录状态
|
||||
public function setDomainRecordStatus($RecordId, $Status){
|
||||
public function setDomainRecordStatus($RecordId, $Status)
|
||||
{
|
||||
$Status = $Status == '1' ? 'ENABLE' : 'DISABLE';
|
||||
$params = ['status' => $Status];
|
||||
$data = $this->send_reuqest('PUT', '/v2.1/recordsets/'.$RecordId.'/statuses/set', null, $params);
|
||||
|
@ -160,12 +174,14 @@ class huawei implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取解析记录操作日志
|
||||
public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null){
|
||||
public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//获取解析线路列表
|
||||
public function getRecordLine(){
|
||||
public function getRecordLine()
|
||||
{
|
||||
$file_path = app()->getBasePath().'data'.DIRECTORY_SEPARATOR.'huawei_line.json';
|
||||
$content = file_get_contents($file_path);
|
||||
$data = json_decode($content, true);
|
||||
|
@ -180,7 +196,8 @@ class huawei implements DnsInterface {
|
|||
return false;
|
||||
}
|
||||
|
||||
private function processLineList(&$list, $line_list, $parent, $rootId = null, $rootName = null){
|
||||
private function processLineList(&$list, $line_list, $parent, $rootId = null, $rootName = null)
|
||||
{
|
||||
foreach ($line_list as $row) {
|
||||
if ($rootId && $rootId !== 1) {
|
||||
$row['id'] = $rootId.'_'.$row['id'];
|
||||
|
@ -196,27 +213,32 @@ class huawei implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名概览信息
|
||||
public function getDomainInfo(){
|
||||
public function getDomainInfo()
|
||||
{
|
||||
return $this->send_reuqest('GET', '/v2/zones/'.$this->domainid);
|
||||
}
|
||||
|
||||
//获取域名最低TTL
|
||||
public function getMinTTL(){
|
||||
public function getMinTTL()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private function convertType($type){
|
||||
private function convertType($type)
|
||||
{
|
||||
return $type;
|
||||
}
|
||||
|
||||
private function getHost($Name){
|
||||
private function getHost($Name)
|
||||
{
|
||||
if ($Name == '@') $Name = '';
|
||||
else $Name .= '.';
|
||||
$Name .= $this->domain . '.';
|
||||
return $Name;
|
||||
}
|
||||
|
||||
private function send_reuqest($method, $path, $query = null, $params = null){
|
||||
private function send_reuqest($method, $path, $query = null, $params = null)
|
||||
{
|
||||
if (!empty($query)) {
|
||||
$query = array_filter($query, function ($a) { return $a !== null;});
|
||||
}
|
||||
|
@ -249,7 +271,8 @@ class huawei implements DnsInterface {
|
|||
return $this->curl($method, $url, $body, $header);
|
||||
}
|
||||
|
||||
private function generateSign($method, $path, $query, $headers, $body, $time){
|
||||
private function generateSign($method, $path, $query, $headers, $body, $time)
|
||||
{
|
||||
$algorithm = "SDK-HMAC-SHA256";
|
||||
|
||||
// step 1: build canonical request string
|
||||
|
@ -300,7 +323,8 @@ class huawei implements DnsInterface {
|
|||
return substr($canonicalQueryString, 1);
|
||||
}
|
||||
|
||||
private function getCanonicalHeaders($oldheaders){
|
||||
private function getCanonicalHeaders($oldheaders)
|
||||
{
|
||||
$headers = array();
|
||||
foreach ($oldheaders as $key => $value) {
|
||||
$headers[strtolower($key)] = trim($value);
|
||||
|
@ -317,7 +341,8 @@ class huawei implements DnsInterface {
|
|||
return [$canonicalHeaders, $signedHeaders];
|
||||
}
|
||||
|
||||
private function curl($method, $url, $body, $header){
|
||||
private function curl($method, $url, $body, $header)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
|
@ -353,7 +378,8 @@ class huawei implements DnsInterface {
|
|||
}
|
||||
}
|
||||
|
||||
private function setError($message){
|
||||
private function setError($message)
|
||||
{
|
||||
$this->error = $message;
|
||||
//file_put_contents('logs.txt',date('H:i:s').' '.$message."\r\n", FILE_APPEND);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace app\lib\dns;
|
||||
|
||||
use app\lib\DnsInterface;
|
||||
|
||||
class huoshan implements DnsInterface {
|
||||
class huoshan implements DnsInterface
|
||||
{
|
||||
private $AccessKeyId;
|
||||
private $SecretAccessKey;
|
||||
private $endpoint = "open.volcengineapi.com";
|
||||
|
@ -23,18 +25,21 @@ class huoshan implements DnsInterface {
|
|||
'ultimate_exclusive_inner' => ['level' => 5, 'name' => '尊享版', 'ttl' => 1],
|
||||
];
|
||||
|
||||
function __construct($config){
|
||||
public function __construct($config)
|
||||
{
|
||||
$this->AccessKeyId = $config['ak'];
|
||||
$this->SecretAccessKey = $config['sk'];
|
||||
$this->domain = $config['domain'];
|
||||
$this->domainid = $config['domainid'];
|
||||
}
|
||||
|
||||
public function getError(){
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function check(){
|
||||
public function check()
|
||||
{
|
||||
if ($this->getDomainList() != false) {
|
||||
return true;
|
||||
}
|
||||
|
@ -42,7 +47,8 @@ class huoshan implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名列表
|
||||
public function getDomainList($KeyWord=null, $PageNumber=1, $PageSize=20){
|
||||
public function getDomainList($KeyWord = null, $PageNumber = 1, $PageSize = 20)
|
||||
{
|
||||
$query = ['PageNumber' => $PageNumber, 'PageSize' => $PageSize, 'Key' => $KeyWord];
|
||||
$data = $this->send_reuqest('GET', 'ListZones', $query);
|
||||
if ($data) {
|
||||
|
@ -62,7 +68,8 @@ class huoshan implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取解析记录列表
|
||||
public function getDomainRecords($PageNumber=1, $PageSize=20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null){
|
||||
public function getDomainRecords($PageNumber = 1, $PageSize = 20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null)
|
||||
{
|
||||
$query = ['ZID' => intval($this->domainid), 'PageNumber' => $PageNumber, 'PageSize' => $PageSize, 'SearchOrder' => 'desc'];
|
||||
if (!empty($SubDomain) || !empty($Type) || !empty($Line) || !empty($Value)) {
|
||||
$query += ['Host' => $SubDomain, 'Value' => $Value, 'Type' => $Type, 'Line' => $Line];
|
||||
|
@ -95,12 +102,14 @@ class huoshan implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取子域名解析记录列表
|
||||
public function getSubDomainRecords($SubDomain, $PageNumber=1, $PageSize=20, $Type = null, $Line = null){
|
||||
public function getSubDomainRecords($SubDomain, $PageNumber = 1, $PageSize = 20, $Type = null, $Line = null)
|
||||
{
|
||||
return $this->getDomainRecords($PageNumber, $PageSize, null, $SubDomain, null, $Type, $Line);
|
||||
}
|
||||
|
||||
//获取解析记录详细信息
|
||||
public function getDomainRecordInfo($RecordId){
|
||||
public function getDomainRecordInfo($RecordId)
|
||||
{
|
||||
$data = $this->send_reuqest('GET', 'QueryRecord', ['RecordID' => $RecordId]);
|
||||
if ($data) {
|
||||
if ($data['name'] == $data['zone_name']) $data['name'] = '@';
|
||||
|
@ -124,7 +133,8 @@ class huoshan implements DnsInterface {
|
|||
}
|
||||
|
||||
//添加解析记录
|
||||
public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null){
|
||||
public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null)
|
||||
{
|
||||
$params = ['ZID' => intval($this->domainid), 'Host' => $Name, 'Type' => $this->convertType($Type), 'Value' => $Value, 'Line' => $Line, 'TTL' => intval($TTL), 'Remark' => $Remark];
|
||||
if ($Type == 'MX') $params['Value'] = intval($MX) . ' ' . $Value;
|
||||
if ($Weight > 0) $params['Weight'] = $Weight;
|
||||
|
@ -133,7 +143,8 @@ class huoshan implements DnsInterface {
|
|||
}
|
||||
|
||||
//修改解析记录
|
||||
public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null){
|
||||
public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null)
|
||||
{
|
||||
$params = ['RecordID' => $RecordId, 'Host' => $Name, 'Type' => $this->convertType($Type), 'Value' => $Value, 'Line' => $Line, 'TTL' => intval($TTL), 'Remark' => $Remark];
|
||||
if ($Type == 'MX') $params['Value'] = intval($MX) . ' ' . $Value;
|
||||
if ($Weight > 0) $params['Weight'] = $Weight;
|
||||
|
@ -142,30 +153,35 @@ class huoshan implements DnsInterface {
|
|||
}
|
||||
|
||||
//修改解析记录备注
|
||||
public function updateDomainRecordRemark($RecordId, $Remark){
|
||||
public function updateDomainRecordRemark($RecordId, $Remark)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//删除解析记录
|
||||
public function deleteDomainRecord($RecordId){
|
||||
public function deleteDomainRecord($RecordId)
|
||||
{
|
||||
$data = $this->send_reuqest('POST', 'DeleteRecord', ['RecordID' => $RecordId]);
|
||||
return $data;
|
||||
}
|
||||
|
||||
//设置解析记录状态
|
||||
public function setDomainRecordStatus($RecordId, $Status){
|
||||
public function setDomainRecordStatus($RecordId, $Status)
|
||||
{
|
||||
$params = ['RecordID' => $RecordId, 'Enable' => $Status == '1'];
|
||||
$data = $this->send_reuqest('POST', 'UpdateRecordStatus', $params);
|
||||
return is_array($data);
|
||||
}
|
||||
|
||||
//获取解析记录操作日志
|
||||
public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null){
|
||||
public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//获取解析线路列表
|
||||
public function getRecordLine(){
|
||||
public function getRecordLine()
|
||||
{
|
||||
$domainInfo = $this->getDomainInfo();
|
||||
if (!$domainInfo) return false;
|
||||
$level = $this->getTradeInfo($domainInfo['TradeCode'])['level'];
|
||||
|
@ -193,7 +209,8 @@ class huoshan implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名概览信息
|
||||
public function getDomainInfo(){
|
||||
public function getDomainInfo()
|
||||
{
|
||||
if (!empty($this->domainInfo)) return $this->domainInfo;
|
||||
$query = ['ZID' => intval($this->domainid)];
|
||||
$data = $this->send_reuqest('GET', 'QueryZone', $query);
|
||||
|
@ -205,7 +222,8 @@ class huoshan implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名最低TTL
|
||||
public function getMinTTL(){
|
||||
public function getMinTTL()
|
||||
{
|
||||
$domainInfo = $this->getDomainInfo();
|
||||
if ($domainInfo) {
|
||||
$ttl = $this->getTradeInfo($domainInfo['TradeCode'])['ttl'];
|
||||
|
@ -214,11 +232,13 @@ class huoshan implements DnsInterface {
|
|||
return false;
|
||||
}
|
||||
|
||||
private function convertType($type){
|
||||
private function convertType($type)
|
||||
{
|
||||
return $type;
|
||||
}
|
||||
|
||||
private function getTradeInfo($trade_code){
|
||||
private function getTradeInfo($trade_code)
|
||||
{
|
||||
if (array_key_exists($trade_code, self::$trade_code_list)) {
|
||||
$trade_code = $trade_code;
|
||||
} else {
|
||||
|
@ -227,7 +247,8 @@ class huoshan implements DnsInterface {
|
|||
return self::$trade_code_list[$trade_code];
|
||||
}
|
||||
|
||||
private function send_reuqest($method, $action, $params = []){
|
||||
private function send_reuqest($method, $action, $params = [])
|
||||
{
|
||||
if (!empty($params)) {
|
||||
$params = array_filter($params, function ($a) { return $a !== null;});
|
||||
}
|
||||
|
@ -266,7 +287,8 @@ class huoshan implements DnsInterface {
|
|||
return $this->curl($method, $url, $body, $header);
|
||||
}
|
||||
|
||||
private function generateSign($method, $path, $query, $headers, $body, $time){
|
||||
private function generateSign($method, $path, $query, $headers, $body, $time)
|
||||
{
|
||||
$algorithm = "HMAC-SHA256";
|
||||
|
||||
// step 1: build canonical request string
|
||||
|
@ -325,7 +347,8 @@ class huoshan implements DnsInterface {
|
|||
return substr($canonicalQueryString, 1);
|
||||
}
|
||||
|
||||
private function getCanonicalHeaders($oldheaders){
|
||||
private function getCanonicalHeaders($oldheaders)
|
||||
{
|
||||
$headers = array();
|
||||
foreach ($oldheaders as $key => $value) {
|
||||
$headers[strtolower($key)] = trim($value);
|
||||
|
@ -342,7 +365,8 @@ class huoshan implements DnsInterface {
|
|||
return [$canonicalHeaders, $signedHeaders];
|
||||
}
|
||||
|
||||
private function curl($method, $url, $body, $header){
|
||||
private function curl($method, $url, $body, $header)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
|
@ -380,7 +404,8 @@ class huoshan implements DnsInterface {
|
|||
}
|
||||
}
|
||||
|
||||
private function setError($message){
|
||||
private function setError($message)
|
||||
{
|
||||
$this->error = $message;
|
||||
//file_put_contents('logs.txt',date('H:i:s').' '.$message."\r\n", FILE_APPEND);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace app\lib\dns;
|
||||
|
||||
use app\lib\DnsInterface;
|
||||
|
@ -6,7 +7,8 @@ use app\lib\DnsInterface;
|
|||
/**
|
||||
* @see http://apipost.west.cn/
|
||||
*/
|
||||
class west implements DnsInterface {
|
||||
class west implements DnsInterface
|
||||
{
|
||||
private $username;
|
||||
private $api_password;
|
||||
private $baseUrl = 'https://api.west.cn/api/v2';
|
||||
|
@ -14,17 +16,20 @@ class west implements DnsInterface {
|
|||
private $domain;
|
||||
private $domainid;
|
||||
|
||||
function __construct($config){
|
||||
public function __construct($config)
|
||||
{
|
||||
$this->username = $config['ak'];
|
||||
$this->api_password = $config['sk'];
|
||||
$this->domain = $config['domain'];
|
||||
}
|
||||
|
||||
public function getError(){
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function check(){
|
||||
public function check()
|
||||
{
|
||||
if ($this->getDomainList() != false) {
|
||||
return true;
|
||||
}
|
||||
|
@ -32,7 +37,8 @@ class west implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名列表
|
||||
public function getDomainList($KeyWord=null, $PageNumber=1, $PageSize=20){
|
||||
public function getDomainList($KeyWord = null, $PageNumber = 1, $PageSize = 20)
|
||||
{
|
||||
$param = ['act' => 'getdomains', 'page' => $PageNumber, 'limit' => $PageSize, 'domain' => $KeyWord];
|
||||
$data = $this->execute('/domain/', $param);
|
||||
if ($data) {
|
||||
|
@ -50,7 +56,8 @@ class west implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取解析记录列表
|
||||
public function getDomainRecords($PageNumber=1, $PageSize=20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null){
|
||||
public function getDomainRecords($PageNumber = 1, $PageSize = 20, $KeyWord = null, $SubDomain = null, $Value = null, $Type = null, $Line = null, $Status = null)
|
||||
{
|
||||
$param = ['act' => 'getdnsrecord', 'domain' => $this->domain, 'type' => $Type, 'line' => $Line, 'host' => $KeyWord, 'value' => $Value, 'pageno' => $PageNumber, 'limit' => $PageSize];
|
||||
if (!isNullOrEmpty(($SubDomain))) {
|
||||
$param['host'] = $SubDomain;
|
||||
|
@ -80,56 +87,65 @@ class west implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取子域名解析记录列表
|
||||
public function getSubDomainRecords($SubDomain, $PageNumber=1, $PageSize=20, $Type = null, $Line = null){
|
||||
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){
|
||||
public function getDomainRecordInfo($RecordId)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//添加解析记录
|
||||
public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null){
|
||||
public function addDomainRecord($Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null)
|
||||
{
|
||||
$param = ['act' => 'adddnsrecord', 'domain' => $this->domain, 'host' => $Name, 'type' => $this->convertType($Type), 'value' => $Value, 'level' => $MX, 'ttl' => intval($TTL), 'line' => $Line];
|
||||
$data = $this->execute('/domain/', $param);
|
||||
return is_array($data) ? $data['id'] : false;
|
||||
}
|
||||
|
||||
//修改解析记录
|
||||
public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null){
|
||||
public function updateDomainRecord($RecordId, $Name, $Type, $Value, $Line = '0', $TTL = 600, $MX = 1, $Weight = null, $Remark = null)
|
||||
{
|
||||
$param = ['act' => 'moddnsrecord', 'domain' => $this->domain, 'id' => $RecordId, 'type' => $this->convertType($Type), 'value' => $Value, 'level' => $MX, 'ttl' => intval($TTL), 'line' => $Line];
|
||||
$data = $this->execute('/domain/', $param);
|
||||
return is_array($data);
|
||||
}
|
||||
|
||||
//修改解析记录备注
|
||||
public function updateDomainRecordRemark($RecordId, $Remark){
|
||||
public function updateDomainRecordRemark($RecordId, $Remark)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//删除解析记录
|
||||
public function deleteDomainRecord($RecordId){
|
||||
public function deleteDomainRecord($RecordId)
|
||||
{
|
||||
$param = ['act' => 'deldnsrecord', 'domain' => $this->domain, 'id' => $RecordId];
|
||||
$data = $this->execute('/domain/', $param);
|
||||
return is_array($data);
|
||||
}
|
||||
|
||||
//设置解析记录状态
|
||||
public function setDomainRecordStatus($RecordId, $Status){
|
||||
public function setDomainRecordStatus($RecordId, $Status)
|
||||
{
|
||||
$param = ['act' => 'pause', 'domain' => $this->domain, 'id' => $RecordId, 'val' => $Status == '1' ? '0' : '1'];
|
||||
$data = $this->execute('/domain/', $param);
|
||||
return $data !== false;
|
||||
}
|
||||
|
||||
//获取解析记录操作日志
|
||||
public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null){
|
||||
public function getDomainRecordLog($PageNumber = 1, $PageSize = 20, $KeyWord = null, $StartDate = null, $endDate = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//获取解析线路列表
|
||||
public function getRecordLine(){
|
||||
public function getRecordLine()
|
||||
{
|
||||
return [
|
||||
'' => ['name' => '默认', 'parent' => null],
|
||||
'LTEL' => ['name' => '电信', 'parent' => null],
|
||||
|
@ -142,20 +158,24 @@ class west implements DnsInterface {
|
|||
}
|
||||
|
||||
//获取域名信息
|
||||
public function getDomainInfo(){
|
||||
public function getDomainInfo()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//获取域名最低TTL
|
||||
public function getMinTTL(){
|
||||
public function getMinTTL()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private function convertType($type){
|
||||
private function convertType($type)
|
||||
{
|
||||
return $type;
|
||||
}
|
||||
|
||||
private function execute($path, $params){
|
||||
private function execute($path, $params)
|
||||
{
|
||||
$params['username'] = $this->username;
|
||||
$params['time'] = $this->getMillisecond();
|
||||
$params['token'] = md5($this->username.$this->api_password.$params['time']);
|
||||
|
@ -175,7 +195,8 @@ class west implements DnsInterface {
|
|||
}
|
||||
}
|
||||
|
||||
private function curl($path, $params = null){
|
||||
private function curl($path, $params = null)
|
||||
{
|
||||
$url = $this->baseUrl . $path;
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
|
@ -202,7 +223,8 @@ class west implements DnsInterface {
|
|||
return (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
|
||||
}
|
||||
|
||||
private function setError($message){
|
||||
private function setError($message)
|
||||
{
|
||||
$this->error = $message;
|
||||
//file_put_contents('logs.txt',date('H:i:s').' '.$message."\r\n", FILE_APPEND);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace app\lib\mail;
|
||||
|
||||
class Aliyun
|
||||
|
@ -6,7 +7,7 @@ class Aliyun
|
|||
private $AccessKeyId;
|
||||
private $AccessKeySecret;
|
||||
|
||||
function __construct($AccessKeyId, $AccessKeySecret)
|
||||
public function __construct($AccessKeyId, $AccessKeySecret)
|
||||
{
|
||||
$this->AccessKeyId = $AccessKeyId;
|
||||
$this->AccessKeySecret = $AccessKeySecret;
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace app\lib\mail;
|
||||
|
||||
class Sendcloud {
|
||||
class Sendcloud
|
||||
{
|
||||
private $apiUser;
|
||||
private $apiKey;
|
||||
|
||||
function __construct($apiUser, $apiKey){
|
||||
public function __construct($apiUser, $apiKey)
|
||||
{
|
||||
$this->apiUser = $apiUser;
|
||||
$this->apiKey = $apiKey;
|
||||
}
|
||||
public function send($to, $sub, $msg, $from, $from_name){
|
||||
public function send($to, $sub, $msg, $from, $from_name)
|
||||
{
|
||||
if (empty($this->apiUser) || empty($this->apiKey)) return false;
|
||||
$url = 'http://api.sendcloud.net/apiv2/mail/send';
|
||||
$data = array(
|
||||
|
@ -19,7 +23,8 @@ class Sendcloud {
|
|||
'fromName' => $from_name,
|
||||
'to' => $to,
|
||||
'subject' => $sub,
|
||||
'html' => $msg);
|
||||
'html' => $msg
|
||||
);
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\middleware;
|
||||
|
@ -19,9 +20,15 @@ class AuthApi
|
|||
return json(['code' => -1, 'msg' => '时间戳不合法'])->code(403);
|
||||
}
|
||||
$user = Db::name('user')->where('id', $uid)->find();
|
||||
if(!$user) return json(['code'=>-1, 'msg'=>'用户不存在'])->code(403);
|
||||
if($user['status'] == 0) return json(['code'=>-1, 'msg'=>'该用户已被封禁'])->code(403);
|
||||
if($user['is_api'] == 0) return json(['code'=>-1, 'msg'=>'该用户未开启API权限'])->code(403);
|
||||
if (!$user) {
|
||||
return json(['code' => -1, 'msg' => '用户不存在'])->code(403);
|
||||
}
|
||||
if ($user['status'] == 0) {
|
||||
return json(['code' => -1, 'msg' => '该用户已被封禁'])->code(403);
|
||||
}
|
||||
if ($user['is_api'] == 0) {
|
||||
return json(['code' => -1, 'msg' => '该用户未开启API权限'])->code(403);
|
||||
}
|
||||
if (md5($uid.$timestamp.$user['apikey']) !== $sign) {
|
||||
return json(['code' => -1, 'msg' => '签名错误'])->code(403);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\middleware;
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\middleware;
|
||||
|
||||
|
||||
class CheckLogin
|
||||
{
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
if (!request()->islogin) {
|
||||
if (!$request->islogin) {
|
||||
if ($request->isAjax() || !$request->isGet()) {
|
||||
return json(['code' => -1, 'msg' => '未登录'])->code(401);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\middleware;
|
||||
|
@ -20,7 +21,7 @@ class LoadConfig
|
|||
public function handle($request, \Closure $next)
|
||||
{
|
||||
if (!file_exists(app()->getRootPath().'.env')) {
|
||||
if(strpos(request()->url(),'/install')===false){
|
||||
if (strpos($this->request->url(), '/install') === false) {
|
||||
return redirect((string)url('/install'))->header([
|
||||
'Cache-Control' => 'no-store, no-cache, must-revalidate',
|
||||
'Pragma' => 'no-cache',
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\middleware;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\middleware;
|
||||
|
|
|
@ -56,7 +56,7 @@ a{color:#444}
|
|||
<div class="input-group-addon"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span></div>
|
||||
<input type="text" class="form-control input-lg" placeholder="验证码" name="code" autocomplete="off" required="required"/>
|
||||
<span class="input-group-addon" style="padding: 0">
|
||||
<img id="verifycode" src="/verifycode" height="45" onclick="this.src='/verifycode?r='+Math.random();" title="点击更换验证码">
|
||||
<img id="verifycode" src="{:captcha_src()}" height="45" onclick="this.src='{:captcha_src()}?r='+Math.random();" title="点击更换验证码">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
|
|
@ -33,7 +33,8 @@
|
|||
</select></div>
|
||||
</div><br/>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-3 col-sm-9"><input type="submit" name="submit" value="保存" class="btn btn-primary btn-block"/></div>
|
||||
<div class="col-sm-offset-3 col-sm-9"><input type="submit" name="submit" value="保存" class="btn btn-primary btn-block"/><br/>
|
||||
<a href="javascript:proxytest()" class="btn btn-default btn-block">测试连通性</a></div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -48,16 +49,6 @@ var items = $("select[default]");
|
|||
for (i = 0; i < items.length; i++) {
|
||||
$(items[i]).val($(items[i]).attr("default")||0);
|
||||
}
|
||||
$("select[name='mail_type']").change(function(){
|
||||
if($(this).val() == 0){
|
||||
$("#frame_set1").show();
|
||||
$("#frame_set2").hide();
|
||||
}else{
|
||||
$("#frame_set1").hide();
|
||||
$("#frame_set2").show();
|
||||
}
|
||||
});
|
||||
$("select[name='mail_type']").change();
|
||||
function saveSetting(obj){
|
||||
var ii = layer.load(2, {shade:[0.1,'#fff']});
|
||||
$.ajax({
|
||||
|
@ -85,38 +76,28 @@ function saveSetting(obj){
|
|||
});
|
||||
return false;
|
||||
}
|
||||
function mailtest(){
|
||||
function proxytest(){
|
||||
var proxy_server = $("input[name='proxy_server']").val();
|
||||
var proxy_port = $("input[name='proxy_port']").val();
|
||||
var proxy_user = $("input[name='proxy_user']").val();
|
||||
var proxy_pwd = $("input[name='proxy_pwd']").val();
|
||||
var proxy_type = $("select[name='proxy_type']").val();
|
||||
if(proxy_server=='' || proxy_port==''){
|
||||
layer.alert('代理服务器和端口不能为空!');
|
||||
return false;
|
||||
}
|
||||
var ii = layer.load(2, {shade:[0.1,'#fff']});
|
||||
$.ajax({
|
||||
type : 'GET',
|
||||
url : '/dmonitor/mailtest',
|
||||
type : 'POST',
|
||||
url : '/dmonitor/proxytest',
|
||||
data : {proxy_server:proxy_server, proxy_port:proxy_port, proxy_user:proxy_user, proxy_pwd:proxy_pwd, proxy_type:proxy_type},
|
||||
dataType : 'json',
|
||||
success : function(data) {
|
||||
layer.close(ii);
|
||||
if(data.code == 0){
|
||||
layer.alert(data.msg, {icon: 1});
|
||||
layer.alert('连通性测试成功!', {icon: 1})
|
||||
}else{
|
||||
layer.alert(data.msg, {icon: 2})
|
||||
}
|
||||
},
|
||||
error:function(data){
|
||||
layer.close(ii);
|
||||
layer.msg('服务器错误');
|
||||
}
|
||||
});
|
||||
}
|
||||
function tgbottest(){
|
||||
var ii = layer.load(2, {shade:[0.1,'#fff']});
|
||||
$.ajax({
|
||||
type : 'GET',
|
||||
url : '/dmonitor/tgbottest',
|
||||
dataType : 'json',
|
||||
success : function(data) {
|
||||
layer.close(ii);
|
||||
if(data.code == 0){
|
||||
layer.alert(data.msg, {icon: 1});
|
||||
}else{
|
||||
layer.alert(data.msg, {icon: 2})
|
||||
layer.alert('连通性测试失败:'+data.msg, {icon: 2})
|
||||
}
|
||||
},
|
||||
error:function(data){
|
||||
|
|
|
@ -145,7 +145,7 @@ $(document).ready(function(){
|
|||
field: 'typename',
|
||||
title: '平台账户',
|
||||
formatter: function(value, row, index) {
|
||||
return '<span title="'+row.aremark+'" data-toggle="tooltip" data-placement="right" title="Tooltip on right"><img src="/static/images/'+row.type+'.ico" class="type-logo"></img>'+value+'('+row.aid+')</span>';
|
||||
return '<img src="/static/images/'+row.type+'.ico" class="type-logo"></img>'+(row.aremark?row.aremark:value+'('+row.aid+')');
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -193,10 +193,7 @@ $(document).ready(function(){
|
|||
return html;
|
||||
}
|
||||
},
|
||||
],
|
||||
onLoadSuccess: function(data) {
|
||||
$('[data-toggle="tooltip"]').tooltip()
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
$("#form-store select[name=aid]").change(function(){
|
||||
|
|
|
@ -68,7 +68,7 @@ if (!function_exists('parse_args')) {
|
|||
break;
|
||||
}
|
||||
|
||||
$result[] = is_int($key) ? $value : "'{$key}' => {$value}";
|
||||
$result[] = is_int($key) ? $value : sprintf('\'%s\' => %s', htmlentities($key), $value);
|
||||
}
|
||||
|
||||
return implode(', ', $result);
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
<div class="small-box bg-red">
|
||||
<div class="inner">
|
||||
<h3 id="count4">0</h3>
|
||||
<p>平台数量</p>
|
||||
<p>DNS平台数量</p>
|
||||
</div>
|
||||
<div class="icon">
|
||||
<i class="fa fa-connectdevelop"></i>
|
||||
|
|
|
@ -1,26 +1,43 @@
|
|||
{
|
||||
"name": "topthink/think",
|
||||
"description": "the new thinkphp framework",
|
||||
"name": "netcccyun/dnsmgr",
|
||||
"description": "聚合DNS管理系统",
|
||||
"type": "project",
|
||||
"keywords": [
|
||||
"framework",
|
||||
"thinkphp",
|
||||
"ORM"
|
||||
"dns",
|
||||
"dnsmanager",
|
||||
"cccyun"
|
||||
],
|
||||
"homepage": "https://www.thinkphp.cn/",
|
||||
"homepage": "https://blog.cccyun.cn/post-526.html",
|
||||
"license": "Apache-2.0",
|
||||
"authors": [
|
||||
{
|
||||
"name": "liu21st",
|
||||
"email": "liu21st@gmail.com"
|
||||
"email": "liu21st@gmail.com",
|
||||
"role": "Framework Developer"
|
||||
},
|
||||
{
|
||||
"name": "yunwuxin",
|
||||
"email": "448901948@qq.com"
|
||||
"email": "448901948@qq.com",
|
||||
"role": "Framework Developer"
|
||||
},
|
||||
{
|
||||
"name": "netcccyun",
|
||||
"homepage": "https://blog.cccyun.cn",
|
||||
"role": "Project Owner"
|
||||
},
|
||||
{
|
||||
"name": "coolxitech",
|
||||
"email": "admin@kuxi.tech",
|
||||
"homepage": "https://www.kuxi.tech",
|
||||
"role": "Project Developer"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.2.5",
|
||||
"php": ">=7.4.0",
|
||||
"ext-pdo": "*",
|
||||
"ext-gd": "*",
|
||||
"ext-curl": "*",
|
||||
"topthink/framework": "^6.0.0",
|
||||
"topthink/think-orm": "^2.0",
|
||||
"topthink/think-view": "^1.0",
|
||||
|
|
|
@ -31,7 +31,7 @@ return [
|
|||
'show_error_msg' => true,
|
||||
'exception_tmpl' => \think\facade\App::getAppPath() . 'view/exception.tpl',
|
||||
|
||||
'version' => '1017',
|
||||
'version' => '1018',
|
||||
|
||||
'dbversion' => '1011'
|
||||
];
|
||||
|
|
|
@ -30,7 +30,8 @@ return [
|
|||
'imageH' => 0,
|
||||
// 验证码图片宽度
|
||||
'imageW' => 0,
|
||||
|
||||
// 验证成功后是否重置
|
||||
'reset' => true,
|
||||
// 添加额外的验证码设置
|
||||
// verify => [
|
||||
// 'length'=>4,
|
||||
|
|
|
@ -8,19 +8,23 @@
|
|||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
use app\middleware\AuthApi;
|
||||
use app\middleware\CheckLogin;
|
||||
use app\middleware\ViewOutput;
|
||||
use think\facade\Route;
|
||||
use think\middleware\SessionInit;
|
||||
|
||||
Route::pattern([
|
||||
'id' => '\d+',
|
||||
]);
|
||||
|
||||
Route::any('/install', 'install/index')
|
||||
->middleware(\app\middleware\ViewOutput::class);
|
||||
->middleware(ViewOutput::class);
|
||||
|
||||
Route::get('/verifycode', 'auth/verifycode')->middleware(\think\middleware\SessionInit::class)
|
||||
->middleware(\app\middleware\ViewOutput::class);
|
||||
Route::any('/login', 'auth/login')->middleware(\think\middleware\SessionInit::class)
|
||||
->middleware(\app\middleware\ViewOutput::class);
|
||||
Route::get('/verifycode', 'auth/verifycode')->middleware(SessionInit::class)
|
||||
->middleware(ViewOutput::class);
|
||||
Route::any('/login', 'auth/login')->middleware(SessionInit::class)
|
||||
->middleware(ViewOutput::class);
|
||||
Route::get('/logout', 'auth/logout');
|
||||
Route::any('/quicklogin', 'auth/quicklogin');
|
||||
Route::any('/dmtask/status', 'dmonitor/status');
|
||||
|
@ -72,6 +76,7 @@ Route::group(function () {
|
|||
Route::any('/dmonitor/proxyset', 'dmonitor/proxyset');
|
||||
Route::get('/dmonitor/mailtest', 'dmonitor/mailtest');
|
||||
Route::get('/dmonitor/tgbottest', 'dmonitor/tgbottest');
|
||||
Route::post('/dmonitor/proxytest', 'dmonitor/proxytest');
|
||||
Route::post('/dmonitor/clean', 'dmonitor/clean');
|
||||
|
||||
Route::any('/optimizeip/opipset', 'optimizeip/opipset');
|
||||
|
@ -80,8 +85,8 @@ Route::group(function () {
|
|||
Route::get('/optimizeip/opiplist', 'optimizeip/opiplist');
|
||||
Route::any('/optimizeip/opipform/:action', 'optimizeip/opipform');
|
||||
|
||||
})->middleware(\app\middleware\CheckLogin::class)
|
||||
->middleware(\app\middleware\ViewOutput::class);
|
||||
})->middleware(CheckLogin::class)
|
||||
->middleware(ViewOutput::class);
|
||||
|
||||
Route::group('api', function () {
|
||||
Route::post('/domain/:id', 'domain/domain_info');
|
||||
|
@ -95,7 +100,7 @@ Route::group('api', function () {
|
|||
Route::post('/record/remark/:id', 'domain/record_remark');
|
||||
Route::post('/record/batch/:id', 'domain/record_batch');
|
||||
|
||||
})->middleware(\app\middleware\AuthApi::class);
|
||||
})->middleware(AuthApi::class);
|
||||
|
||||
Route::miss(function() {
|
||||
return response('404 Not Found')->code(404);
|
||||
|
|
Loading…
Reference in New Issue
Block a user