作者 刘锟

update

@@ -37,7 +37,97 @@ class Temp extends Command @@ -37,7 +37,97 @@ class Temp extends Command
37 37
38 public function handle() 38 public function handle()
39 { 39 {
40 - $this->check_cname_projects(); 40 + $this->change_cname_projects_240();
  41 + }
  42 +
  43 + /**
  44 + * 240服务器上解析cname的项目迁移
  45 + * @author Akun
  46 + * @date 2025/02/17 14:21
  47 + */
  48 + public function change_cname_projects_240()
  49 + {
  50 + $server_ip_model = new ServersIp();
  51 +
  52 + $server_ip_ids = $server_ip_model->where('servers_id', 1)->get()->pluck('id')->toArray();
  53 +
  54 + $project_list = Project::select(['id', 'serve_id'])->whereIn('serve_id', $server_ip_ids)->get();
  55 +
  56 + $domain_model = new DomainInfo();
  57 + foreach ($project_list as $value) {
  58 + $project_id = $value->id;
  59 +
  60 + $domain_info = $domain_model->read(['project_id' => $project_id, 'status' => 1], ['id', 'domain']);
  61 + if (!$domain_info) {
  62 + //过滤未绑定正式域名的项目
  63 + continue;
  64 + }
  65 + $domain_id = $domain_info['id'];
  66 + $domain = $domain_info['domain'];
  67 +
  68 + //迁移主站
  69 + $check = dns_get_record($domain, DNS_A);
  70 + $host = $check[0]['host'] ?? '';
  71 + if ($host == 'cname.globalso.com') {
  72 + //获取主站备份证书
  73 + $ssl_info = DB::table('gl_domain_ssl_backup')->select(['private_key', 'private_cert'])->where('domain', $domain)->first();
  74 + if (!$ssl_info) {
  75 + $this->output('项目id:' . $project_id . ' | 未备份主站证书');
  76 + continue;
  77 + }
  78 +
  79 + //创建主站建站任务
  80 + $task_info = DomainCreateTask::where('type', 1)->where('server_id', 20)->where('project_id', $project_id)->first();
  81 + if (!$task_info) {
  82 + $task_model = new DomainCreateTask();
  83 + $task_model->type = 1;
  84 + $task_model->server_id = 20;
  85 + $task_model->project_id = $project_id;
  86 + $task_model->domain_id = $domain_id;
  87 + $task_model->certs = json_encode(['key' => $ssl_info->private_key, 'csr' => $ssl_info->private_cert]);
  88 + $task_model->save();
  89 + }
  90 +
  91 + //更新项目所在服务器ip
  92 + $value->serve_id = 1549;
  93 + $value->save();
  94 + }
  95 +
  96 +
  97 + //迁移amp站
  98 + $domain_array = parse_url($domain);
  99 + $host = $domain_array['host'] ?? $domain_array['path'];
  100 + $host_array = explode('.', $host);
  101 + if (count($host_array) <= 2) {
  102 + array_unshift($host_array, 'm');
  103 + } else {
  104 + $host_array[0] = 'm';
  105 + }
  106 + $amp_domain = implode('.', $host_array);
  107 +
  108 + $check_amp = dns_get_record($amp_domain, DNS_A);
  109 + $host_amp = $check_amp[0]['host'] ?? '';
  110 + if ($host_amp == 'cname.globalso.com') {
  111 + //获取amp站备份证书
  112 + $ssl_info_amp = DB::table('gl_domain_ssl_backup')->select(['private_key', 'private_cert'])->where('domain', $amp_domain)->first();
  113 + if (!$ssl_info_amp) {
  114 + $this->output('项目id:' . $project_id . ' | 未备份amp站证书');
  115 + continue;
  116 + }
  117 +
  118 + //创建amp站建站任务
  119 + $task_info_amp = DomainCreateTask::where('type', 2)->where('server_id', 20)->where('project_id', $project_id)->first();
  120 + if (!$task_info_amp) {
  121 + $task_model = new DomainCreateTask();
  122 + $task_model->type = 2;
  123 + $task_model->server_id = 20;
  124 + $task_model->project_id = $project_id;
  125 + $task_model->domain_id = $domain_id;
  126 + $task_model->certs = json_encode(['key' => $ssl_info_amp->private_key, 'csr' => $ssl_info_amp->private_cert]);
  127 + $task_model->save();
  128 + }
  129 + }
  130 + }
41 } 131 }
42 132
43 /** 133 /**
@@ -426,59 +516,6 @@ class Temp extends Command @@ -426,59 +516,6 @@ class Temp extends Command
426 } 516 }
427 517
428 /** 518 /**
429 - * 检查服务器上解析cname的项目  
430 - * @author Akun  
431 - * @date 2025/02/17 14:21  
432 - */  
433 - public function check_cname_projects()  
434 - {  
435 - $server_id = 1;  
436 - $server_name = '硅谷云服务器';  
437 -  
438 - $server_ip_model = new ServersIp();  
439 -  
440 - $server_ip_ids = $server_ip_model->where('servers_id', $server_id)->get()->pluck('id')->toArray();  
441 -  
442 - $project_list = Project::select(['id', 'serve_id', 'title'])->whereIn('serve_id', $server_ip_ids)->get();  
443 -  
444 - $domain_model = new DomainInfo();  
445 - $data = [];  
446 - foreach ($project_list as $value) {  
447 - $domain_info = $domain_model->read(['project_id' => $value->id, 'status' => 1], ['id', 'domain']);  
448 - if (!$domain_info) {  
449 - //过滤未绑定正式域名的项目  
450 - continue;  
451 - }  
452 - $domain = $domain_info['domain'];  
453 -  
454 - $check = dns_get_record($domain, DNS_A);  
455 - $ip = $check[0]['ip'] ?? '';  
456 - $host = $check[0]['host'] ?? '';  
457 - if ($host == 'cname.globalso.com') {  
458 - $data[] = [  
459 - $value->id,  
460 - $value->title,  
461 - $domain,  
462 - $ip  
463 - ];  
464 - }  
465 - }  
466 - $map = ['项目id', '名称', '域名', '解析IP'];  
467 - if ($data) {  
468 - $table = new BatchExportService($server_name . '解析cname的项目');  
469 - $file = $table->head($map)->data($data)->save();  
470 - if (!$file) {  
471 - $this->output('文件生成失败,请重试');  
472 - } else {  
473 - $this->output('export success');  
474 - }  
475 - } else {  
476 - $this->output('no data');  
477 - }  
478 - }  
479 -  
480 -  
481 - /**  
482 * 检查不在所属服务器解析上的域名 519 * 检查不在所属服务器解析上的域名
483 * @author Akun 520 * @author Akun
484 * @date 2024/09/26 10:48 521 * @date 2024/09/26 10:48