作者 刘锟

合并分支 'akun' 到 'master'

Akun



查看合并请求 !783
@@ -8,7 +8,10 @@ use App\Models\Devops\ServerConfig; @@ -8,7 +8,10 @@ use App\Models\Devops\ServerConfig;
8 use App\Models\Devops\ServersIp; 8 use App\Models\Devops\ServersIp;
9 use App\Models\Domain\DomainInfo; 9 use App\Models\Domain\DomainInfo;
10 use App\Models\Project\Project; 10 use App\Models\Project\Project;
  11 +use App\Models\Project\ProjectServerBackup;
  12 +use App\Services\BatchExportService;
11 use Illuminate\Console\Command; 13 use Illuminate\Console\Command;
  14 +use Symfony\Component\Process\Process;
12 15
13 class Temp extends Command 16 class Temp extends Command
14 { 17 {
@@ -26,8 +29,79 @@ class Temp extends Command @@ -26,8 +29,79 @@ class Temp extends Command
26 */ 29 */
27 protected $description = '临时脚本'; 30 protected $description = '临时脚本';
28 31
  32 +
  33 + /**
  34 + * 检查不在所属服务器解析上的域名
  35 + * @author Akun
  36 + * @date 2024/09/26 10:48
  37 + */
29 public function handle() 38 public function handle()
30 { 39 {
  40 + $server_id = 14;
  41 +
  42 + $server_ip_model = new ServersIp();
  43 +
  44 + $server_ip_ids = $server_ip_model->where('servers_id', $server_id)->get()->pluck('id')->toArray();
  45 +
  46 + $project_list = Project::select(['id', 'serve_id', 'title'])->whereIn('serve_id', $server_ip_ids)->get();
  47 +
  48 + $domain_model = new DomainInfo();
  49 + $data = [];
  50 + foreach ($project_list as $value) {
  51 + $domain_info = $domain_model->read(['project_id' => $value->id, 'status' => 1], ['id', 'domain']);
  52 + if (!$domain_info) {
  53 + //过滤未绑定正式域名的项目
  54 + continue;
  55 + }
  56 + $domain = $domain_info['domain'];
  57 +
  58 + $check = $this->check_cname($domain);
  59 + foreach ($check as $item) {
  60 + if (strpos($item, 'Address:') !== false) {
  61 + $ip = trim(str_replace('Address:', '', $item));
  62 + if (strpos($ip,'#') === false) {
  63 + $ip_info = $server_ip_model->read(['ip' => $ip]);
  64 + if ($ip_info === false || $ip_info['servers_id'] != $server_id) {
  65 + $data[] = [
  66 + $value->id,
  67 + $value->title,
  68 + $domain,
  69 + $ip,
  70 + $ip_info ? $ip_info['servers_id'] : '',
  71 + ];
  72 + }
  73 + }
  74 + }
  75 + }
  76 + }
  77 + $map = ['项目id', '名称', '域名', 'IP', '服务器ID',];
  78 + if ($data) {
  79 + $table = new BatchExportService("美服2项目解析未在当前服务器项目");
  80 + $file = $table->head($map)->data($data)->save();
  81 + if (!$file) {
  82 + $this->output('文件生成失败,请重试');
  83 + }else{
  84 + $this->output('export success');
  85 + }
  86 + }else{
  87 + $this->output('no data');
  88 + }
  89 + }
  90 +
  91 + public function check_cname($domain)
  92 + {
  93 + $process = new Process(['nslookup', '-qt=a', $domain]);
  94 + $process->run();
  95 + return explode(PHP_EOL, $process->getOutput());
  96 + }
  97 +
  98 + /**
  99 + * 创建所有amp站页面生成任务
  100 + * @author Akun
  101 + * @date 2024/09/26 10:48
  102 + */
  103 + public function handle2()
  104 + {
31 $notify_model = new Notify(); 105 $notify_model = new Notify();
32 $project_model = new Project(); 106 $project_model = new Project();
33 $serve_ip_model = new ServersIp(); 107 $serve_ip_model = new ServersIp();