作者 刘锟

合并分支 'akun' 到 'master'

Akun



查看合并请求 !2421
@@ -1087,13 +1087,19 @@ if (!function_exists('check_domain_record')) { @@ -1087,13 +1087,19 @@ if (!function_exists('check_domain_record')) {
1087 1087
1088 if(!$is_record){ 1088 if(!$is_record){
1089 //解析不正确,再判断是否开启cnd 1089 //解析不正确,再判断是否开启cnd
1090 - $cnd = curlGet('http://sitebak.globalso.com/get_records?domain=' . $domain); 1090 + $top_domain = getTopDomain($domain);
  1091 + $cnd = curlGet('http://sitebak.globalso.com/get_records?domain=' . $top_domain);
1091 if (isset($cnd['data']) && $cnd['data']) { 1092 if (isset($cnd['data']) && $cnd['data']) {
  1093 + if($domain == $top_domain || substr($domain,0,4) == 'www.'){
  1094 + $check_domain = $domain;
  1095 + }else{
  1096 + $check_domain = '*.'.$domain;
  1097 + }
1092 foreach ($cnd['data'] as $vc) { 1098 foreach ($cnd['data'] as $vc) {
1093 - if ($vc['type'] == 'A' && $vc['content'] == $server_info['ip']) { 1099 + if ($vc['name'] == $check_domain && $vc['type'] == 'A' && $vc['content'] == $server_info['ip']) {
1094 $is_record = true; 1100 $is_record = true;
1095 break; 1101 break;
1096 - }elseif ($vc['type'] == 'CNAME' && $vc['content'] == $server_info['domain']){ 1102 + }elseif ($vc['name'] == $check_domain && $vc['type'] == 'CNAME' && $vc['content'] == $server_info['domain']){
1097 $is_record = true; 1103 $is_record = true;
1098 break; 1104 break;
1099 } 1105 }
@@ -1388,3 +1394,30 @@ function analysisRoute($pathInfo) @@ -1388,3 +1394,30 @@ function analysisRoute($pathInfo)
1388 return $router; 1394 return $router;
1389 } 1395 }
1390 1396
  1397 +function getTopDomain ($url) {
  1398 + $url = strtolower($url); //首先转成小写
  1399 + $url = mb_ereg_replace('^( | )+', '', trim($url));
  1400 + $url = mb_ereg_replace('( | )+$', '', $url);
  1401 + if (!preg_match('/^(http:\/\/|https)/', $url)) {
  1402 + $url = "https://".$url;
  1403 + }
  1404 + $hosts = parse_url($url);
  1405 + $host = $hosts['host'] ?? '';
  1406 + //查看是几级域名
  1407 + $data = explode('.', $host);
  1408 + $n = count($data);
  1409 + if ($n < 2) {
  1410 + return $host;
  1411 + }
  1412 + //判断是否是双后缀
  1413 + $preg = '/[\w].+\.(com|net|org|gov|edu|co|ne)\.[\w]/';
  1414 + if (($n > 2) && preg_match($preg, $host)) {
  1415 + //双后缀取后3位
  1416 + $host = $data[$n - 3].'.'.$data[$n - 2].'.'.$data[$n - 1];
  1417 + } else {
  1418 + //非双后缀取后两位
  1419 + $host = $data[$n - 2].'.'.$data[$n - 1];
  1420 + }
  1421 + return $host;
  1422 +}
  1423 +