|
...
|
...
|
@@ -8,12 +8,15 @@ |
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
|
|
use App\Models\Com\KeywordVideoTaskLog;
|
|
|
|
use App\Models\Domain\DomainInfo;
|
|
|
|
use App\Models\Domain\DomainRedirectTask;
|
|
|
|
use App\Models\Product\Keyword;
|
|
|
|
use App\Models\Visit\SyncSubmitTask;
|
|
|
|
use App\Models\Visit\Visit;
|
|
|
|
use App\Services\ProjectServer;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Symfony\Component\Process\Process;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class NoticeController
|
|
...
|
...
|
@@ -105,4 +108,79 @@ class NoticeController extends BaseController |
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 创建301跳转任务
|
|
|
|
* @param Request $request
|
|
|
|
* @return false|string
|
|
|
|
* @author Akun
|
|
|
|
* @date 2024/10/08 15:24
|
|
|
|
*/
|
|
|
|
public function addRedirect(Request $request)
|
|
|
|
{
|
|
|
|
$origin_domain = $request->input('origin_domain', '');
|
|
|
|
$other_domain = $request->input('other_domain', []);
|
|
|
|
$target_domain = $request->input('target_domain', '');
|
|
|
|
|
|
|
|
if ($other_domain && !is_array($other_domain)) {
|
|
|
|
return $this->error('other_domain参数必须为数组');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($origin_domain)) {
|
|
|
|
return $this->error('origin_domain参数不能为空');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($target_domain)) {
|
|
|
|
return $this->error('target_domain参数不能为空');
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$this->check_a($origin_domain,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)) {
|
|
|
|
return $this->error($ov . ' 未解析至 ' . DomainInfo::SERVER_IP_301);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//新增重定向任务
|
|
|
|
$redirect_model = new DomainRedirectTask();
|
|
|
|
$task_redirect_info = $redirect_model->read(['origin_domain'=>$origin_domain]);
|
|
|
|
if(!$task_redirect_info){
|
|
|
|
$redirect_model->add([
|
|
|
|
'origin_domain'=> $origin_domain,
|
|
|
|
'other_domain' => json_encode($other_domain),
|
|
|
|
'target_domain' => $target_domain
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|