作者 刘锟

update

... ... @@ -84,7 +84,7 @@ class DomainInfo extends Command
//除自建站项目外,记录已解析到别的ip的域名
if ($servers_ip_info['servers_id'] != ServerConfig::SELF_SITE_ID) {
//过滤已解析到别的ip的域名
if (!$this->check_cname($v['domain'], $servers_ip_info)) {
if (!check_domain_record($v['domain'], $servers_ip_info)) {
Log::channel('analyze_other')->error('域名 [' . $v['domain'] . '] 已解析到别的IP');
continue;
}
... ... @@ -111,7 +111,7 @@ class DomainInfo extends Command
if ($servers_ip_info['servers_id'] != ServerConfig::SELF_SITE_ID) {
//过滤已解析到别的ip的AMP域名
if (!$this->check_cname($amp_domain, $servers_ip_info)) {
if (!check_domain_record($amp_domain, $servers_ip_info)) {
Log::channel('analyze_other')->error('AMP域名 [' . $amp_domain . '] 已解析到别的IP');
continue;
}
... ... @@ -158,7 +158,7 @@ class DomainInfo extends Command
}
//过滤已解析到别的ip的域名
if (!$this->check_cname($v['domain'], $servers_ip_info)) {
if (!check_domain_record($v['domain'], $servers_ip_info)) {
continue;
}
... ... @@ -215,7 +215,7 @@ class DomainInfo extends Command
}
//过滤已解析到别的ip的域名
if (!$this->check_cname($amp_domain, $servers_ip_info)) {
if (!check_domain_record($amp_domain, $servers_ip_info)) {
continue;
}
... ... @@ -262,7 +262,7 @@ class DomainInfo extends Command
}
//过滤已解析到别的ip的域名
if (!$this->check_cname($v['custom_domain'], $servers_ip_info)) {
if (!check_domain_record($v['custom_domain'], $servers_ip_info)) {
Log::channel('analyze_other')->error('自定义跳转域名 [' . $v['custom_domain'] . '] 已解析到别的IP');
continue;
}
... ... @@ -315,41 +315,4 @@ class DomainInfo extends Command
}
return ['from' => $valid_from, 'to' => $valid_to];
}
/**
* 验证是否cname或者A记录解析到目标服务器
* @param $domain
* @param $server_info
* @return mixed
* @author zbj
* @date 2023/11/13
*/
public function check_cname($domain, $server_info)
{
$process = new Process(['nslookup', '-qt=a', $domain]);
$process->run();
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line) {
if ($line) {
$checkA = strpos($line, $server_info['ip']) !== false;
if ($checkA) {
return $domain;
}
}
}
//是否cname
$process = new Process(['nslookup', '-qt=cname', $domain]);
$process->run();
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line) {
if ($line) {
$checkCname = (strpos($line, $server_info['domain']) !== false);
if ($checkCname) {
return $domain;
}
}
}
return false;
}
}
... ...
... ... @@ -40,7 +40,7 @@ class EmergencyRelieve extends Command
//判断域名是否已经解析到目标服务器
$target_server = $server_ip_model->select(['id', 'ip', 'domain'])->where('id', $value->server_ip_id)->first()->toArray();
if (!$this->check_cname($domain_info['domain'], $target_server)) {
if (!check_domain_record($domain_info['domain'], $target_server)) {
$this->output($domain_info['domain'] . ' | 未解析到目标服务器');
continue;
}
... ... @@ -86,43 +86,6 @@ class EmergencyRelieve extends Command
}
/**
* 验证是否cname或者A记录解析到目标服务器
* @param $domain
* @param $server_info
* @return mixed
* @author zbj
* @date 2023/11/13
*/
public function check_cname($domain, $server_info)
{
$process = new Process(['nslookup', '-qt=a', $domain]);
$process->run();
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line) {
if ($line) {
$checkA = strpos($line, $server_info['ip']) !== false;
if ($checkA) {
return $domain;
}
}
}
//是否cname
$process = new Process(['nslookup', '-qt=cname', $domain]);
$process->run();
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line) {
if ($line) {
$checkCname = (strpos($line, $server_info['domain']) !== false);
if ($checkCname) {
return $domain;
}
}
}
return false;
}
/**
* 输出处理日志
* @param $message
*/
... ...
... ... @@ -42,7 +42,7 @@ class EmergencyRenewSite extends Command
}
//判断域名是否已经解析到目标服务器
if (!$this->check_cname($domain_info['domain'], $target_server)) {
if (!check_domain_record($domain_info['domain'], $target_server)) {
$this->output($domain_info['domain'] . ' | 未解析到目标服务器');
continue;
}
... ... @@ -93,43 +93,6 @@ class EmergencyRenewSite extends Command
}
/**
* 验证是否cname或者A记录解析到目标服务器
* @param $domain
* @param $server_info
* @return mixed
* @author zbj
* @date 2023/11/13
*/
public function check_cname($domain, $server_info)
{
$process = new Process(['nslookup', '-qt=a', $domain]);
$process->run();
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line) {
if ($line) {
$checkA = strpos($line, $server_info['ip']) !== false;
if ($checkA) {
return $domain;
}
}
}
//是否cname
$process = new Process(['nslookup', '-qt=cname', $domain]);
$process->run();
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line) {
if ($line) {
$checkCname = (strpos($line, $server_info['domain']) !== false);
if ($checkCname) {
return $domain;
}
}
}
return false;
}
/**
* 输出处理日志
* @param $message
*/
... ...
... ... @@ -30,7 +30,7 @@ class ProjectDomainCheck extends Command
$project_info = $project_model->read(['id' => $value->project_id], ['id', 'serve_id', 'company']);
$server_ip_info = $server_ip_model->read(['id' => $project_info['serve_id']], ['ip', 'domain']);
if ($this->check_cname($value->domain, $server_ip_info)) {
if (check_domain_record($value->domain, $server_ip_info)) {
continue;
} else {
$data[] = [
... ... @@ -58,43 +58,6 @@ class ProjectDomainCheck extends Command
}
/**
* 验证是否cname或者A记录解析到目标服务器
* @param $domain
* @param $server_info
* @return mixed
* @author zbj
* @date 2023/11/13
*/
public function check_cname($domain, $server_info)
{
$process = new Process(['nslookup', '-qt=a', $domain]);
$process->run();
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line) {
if ($line) {
$checkA = strpos($line, $server_info['ip']) !== false;
if ($checkA) {
return $domain;
}
}
}
//是否cname
$process = new Process(['nslookup', '-qt=cname', $domain]);
$process->run();
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line) {
if ($line) {
$checkCname = (strpos($line, $server_info['domain']) !== false);
if ($checkCname) {
return $domain;
}
}
}
return false;
}
/**
* 输出处理日志
* @param $message
*/
... ...
... ... @@ -81,7 +81,7 @@ class Temp extends Command
*/
public function handle1()
{
$server_id = 14;
$server_id = 15;
$server_ip_model = new ServersIp();
... ... @@ -99,23 +99,17 @@ class Temp extends Command
}
$domain = $domain_info['domain'];
$check = $this->check_cname($domain);
foreach ($check as $item) {
if (strpos($item, 'Address:') !== false) {
$ip = trim(str_replace('Address:', '', $item));
if (strpos($ip, '#') === false) {
$ip_info = $server_ip_model->read(['ip' => $ip]);
if ($ip_info === false || $ip_info['servers_id'] != $server_id) {
$data[] = [
$value->id,
$value->title,
$domain,
$ip,
$ip_info ? $ip_info['servers_id'] : '',
];
}
}
}
$check = dns_get_record($domain, DNS_A);
$ip = $check[0]['ip'] ?? '';
$ip_info = $server_ip_model->read(['ip' => $ip]);
if ($ip_info === false || $ip_info['servers_id'] != $server_id) {
$data[] = [
$value->id,
$value->title,
$domain,
$ip,
$ip_info ? $ip_info['servers_id'] : '',
];
}
}
$map = ['项目id', '名称', '域名', 'IP', '服务器ID',];
... ... @@ -132,13 +126,6 @@ class Temp extends Command
}
}
public function check_cname($domain)
{
$process = new Process(['nslookup', '-qt=a', $domain]);
$process->run();
return explode(PHP_EOL, $process->getOutput());
}
/**
* 创建所有amp站页面生成任务
* @author Akun
... ...
... ... @@ -959,6 +959,31 @@ function generateRandomString($length) {
return substr(str_shuffle(str_repeat($x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length / strlen($x)))), 1, $length);
}
if (!function_exists('check_domain_record')) {
/**
* 验证是否cname或者A记录解析到目标服务器
* @param $domain
* @param $server_info
* @return bool
* @author Akun
* @date 2024/10/14 11:02
*/
function check_domain_record($domain, $server_info)
{
$records = dns_get_record($domain,DNS_A);
if(count($records) != 1){
return false;
}
$record = $records[0];
if($record['host'] == $server_info['domain'] || $record['ip'] == $server_info['ip']){
return $domain;
}else{
return false;
}
}
}
... ...
... ... @@ -134,13 +134,13 @@ class NoticeController extends BaseController
return $this->error('target_domain参数不能为空');
}
if(!$this->check_a($origin_domain,DomainInfo::SERVER_IP_301)){
if(!check_domain_record($origin_domain,['domain'=>'','ip'=>DomainInfo::SERVER_IP_301])){
return $this->error($origin_domain . ' 未解析至 ' . DomainInfo::SERVER_IP_301);
}
if($other_domain){
foreach ($other_domain as $ov) {
if (!$this->check_a($ov, DomainInfo::SERVER_IP_301)) {
if (!check_domain_record($ov, ['domain'=>'','ip'=>DomainInfo::SERVER_IP_301])) {
return $this->error($ov . ' 未解析至 ' . DomainInfo::SERVER_IP_301);
}
}
... ... @@ -159,28 +159,4 @@ class NoticeController extends BaseController
return $this->success();
}
/**
* 验证是否A记录解析到目标服务器
* @param $domain
* @param $ip
* @return bool
* @author Akun
* @date 2024/09/19 11:14
*/
public function check_a($domain, $ip)
{
$process = new Process(['nslookup', '-qt=a', $domain]);
$process->run();
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line) {
if ($line) {
$checkA = strpos($line, $ip) !== false;
if ($checkA) {
return $domain;
}
}
}
return false;
}
}
... ...
... ... @@ -175,16 +175,16 @@ class DomainInfoLogic extends BaseLogic
$this->fail('自建站服务器无法生成站点');
}
//域名是否都已经解析
if(!$this->check_cname($info['domain'], $serversIpInfo)){
if(!check_domain_record($info['domain'], $serversIpInfo)){
$this->fail('域名' . $info['domain'] . '未解析至目标服务器');
}
$domain_301 = '';
foreach ($this->param['other_domain']??[] as $other_domain){
if($other_domain && substr($other_domain,0,2) != '*.'){
if($this->check_a($other_domain,DomainInfo::SERVER_IP_301)){
if(check_domain_record($other_domain,['domain'=>'','ip'=>DomainInfo::SERVER_IP_301])){
$domain_301 = $other_domain;
}else{
if(!$this->check_cname($other_domain, $serversIpInfo)){
if(!check_domain_record($other_domain, $serversIpInfo)){
$this->fail('域名' . $other_domain . '未解析至目标服务器');
}
}
... ... @@ -202,7 +202,7 @@ class DomainInfoLogic extends BaseLogic
$host_array[0] = 'm';
}
$amp_domain = implode('.',$host_array);
if(!$this->check_cname($amp_domain, $serversIpInfo)){
if(!check_domain_record($amp_domain, $serversIpInfo)){
$this->fail('AMP站点域名' . $amp_domain . '未解析至目标服务器');
}
}
... ... @@ -286,64 +286,6 @@ class DomainInfoLogic extends BaseLogic
return $this->success();
}
/**
* 验证是否cname或者A记录解析到目标服务器
* @param $domain
* @param $server_info
* @return mixed
* @author zbj
* @date 2023/11/13
*/
public function check_cname($domain, $server_info){
$process = new Process(['nslookup', '-qt=a', $domain]);
$process->run();
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line){
if($line){
$checkA = strpos($line, $server_info['ip']) !== false;
if($checkA){
return $domain;
}
}
}
//是否cname
$process = new Process(['nslookup', '-qt=cname', $domain]);
$process->run();
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line){
if($line){
$checkCname = (strpos($line, $server_info['domain']) !== false);
if($checkCname){
return $domain;
}
}
}
return false;
}
/**
* 验证是否A记录解析到目标服务器
* @param $domain
* @param $ip
* @return mixed
*/
public function check_a($domain, $ip){
$process = new Process(['nslookup', '-qt=a', $domain]);
$process->run();
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line){
if($line){
$checkA = strpos($line, $ip) !== false;
if($checkA){
return $domain;
}
}
}
return false;
}
/**
* 设置语种自定义跳转链接
* @param $project_id
... ... @@ -386,7 +328,7 @@ class DomainInfoLogic extends BaseLogic
if($has_info && ($has_info['project_id'] != $project_id || $has_info['language_id'] != $this->param['language_id'])){
$this->fail('自定义域名已被使用');
}
if(!$this->check_cname($this->param['custom_domain'], $serversIpInfo)){
if(!check_domain_record($this->param['custom_domain'], $serversIpInfo)){
$this->fail('域名' . $this->param['custom_domain'] . '未解析至目标服务器');
}
}else{
... ...