作者 刘锟

合并分支 'akun' 到 'master'

Akun



查看合并请求 !793
@@ -18,55 +18,60 @@ class EmergencyRecords extends Command @@ -18,55 +18,60 @@ class EmergencyRecords extends Command
18 //类型,1受灾,2恢复 18 //类型,1受灾,2恢复
19 $type = $this->argument('type'); 19 $type = $this->argument('type');
20 20
21 - try {  
22 - //获取服务器的所有可用ip  
23 - $server_ip_model = new ServersIp();  
24 - $server_ip_list = $server_ip_model->where('servers_id', $server_id)->where('status', 0)->get();  
25 - if ($server_ip_list->count() > 0) {  
26 - foreach ($server_ip_list as $value) {  
27 - if (empty($value->ip) || empty($value->domain)) {  
28 - $this->output('ID ' . $value->id . ' 数据错误');  
29 - continue;  
30 - } 21 + //获取服务器的所有可用ip
  22 + $server_ip_model = new ServersIp();
  23 + $server_ip_list = $server_ip_model->where('servers_id', $server_id)->where('status', 0)->get();
  24 + if ($server_ip_list->count() > 0) {
  25 + foreach ($server_ip_list as $value) {
  26 + if (empty($value->ip) || empty($value->domain)) {
  27 + $this->output('ID ' . $value->id . ' 数据错误');
  28 + continue;
  29 + }
31 30
32 - //获取解析记录  
33 - $domain_array = explode('.', $value->domain);  
34 - $domain_rr = $domain_array[0]; 31 + //获取解析记录
  32 + $domain_array = explode('.', $value->domain);
  33 + $domain_rr = $domain_array[0];
  34 + try {
35 $record = AlibabaCloudService::describeDomainRecords('globalso.com', $domain_rr); 35 $record = AlibabaCloudService::describeDomainRecords('globalso.com', $domain_rr);
36 - $record_status_code = $record['statusCode'] ?? 0;  
37 - if ($record_status_code != 200) {  
38 - $this->output('获取主机记录 ' . $domain_rr . ' 解析数据失败');  
39 - continue;  
40 - }  
41 - $record_detail = $record['body']['DomainRecords']['Record'][0] ?? [];  
42 - if (!$record_detail) {  
43 - $this->output('主机记录 ' . $domain_rr . ' 解析数据不存在');  
44 - continue;  
45 - }  
46 -  
47 - //目标ip跟解析记录当前ip一样的数据,不用修改  
48 - $target_ip = $type == 1 ? '43.153.1.240' : $value->ip;  
49 - if ($target_ip == $record_detail['Value']) {  
50 - $this->output('主机记录 ' . $domain_rr . ' 的值已为 ' . $target_ip);  
51 - continue;  
52 - } 36 + } catch (\Exception $e) {
  37 + $this->output('主机记录 ' . $domain_rr . 'error:' . $e->getMessage());
  38 + continue;
  39 + }
  40 + $record_status_code = $record['statusCode'] ?? 0;
  41 + if ($record_status_code != 200) {
  42 + $this->output('获取主机记录 ' . $domain_rr . ' 解析数据失败');
  43 + continue;
  44 + }
  45 + $record_detail = $record['body']['DomainRecords']['Record'][0] ?? [];
  46 + if (!$record_detail) {
  47 + $this->output('主机记录 ' . $domain_rr . ' 解析数据不存在');
  48 + continue;
  49 + }
53 50
54 - //修改解析记录  
55 - $record_id = $record_detail['RecordId'];  
56 - $record_rr = $record_detail['RR'];  
57 - $record_type = $record_detail['Type']; 51 + //目标ip跟解析记录当前ip一样的数据,不用修改
  52 + $target_ip = $type == 1 ? '43.153.1.240' : $value->ip;
  53 + if ($target_ip == $record_detail['Value']) {
  54 + $this->output('主机记录 ' . $domain_rr . ' 的值已为 ' . $target_ip);
  55 + continue;
  56 + }
58 57
  58 + //修改解析记录
  59 + $record_id = $record_detail['RecordId'];
  60 + $record_rr = $record_detail['RR'];
  61 + $record_type = $record_detail['Type'];
  62 + try {
59 $record_edit = AlibabaCloudService::updateDomainRecord($record_id, $record_rr, $record_type, $target_ip); 63 $record_edit = AlibabaCloudService::updateDomainRecord($record_id, $record_rr, $record_type, $target_ip);
60 - $record_edit_status_code = $record_edit['statusCode'] ?? 0;  
61 - if ($record_edit_status_code == 200) {  
62 - $this->output('修改主机记录 ' . $record_rr . ' 的值为 ' . $target_ip . ' 成功');  
63 - } else {  
64 - $this->output('修改主机记录 ' . $record_rr . ' 的值为 ' . $target_ip . ' 失败');  
65 - } 64 + } catch (\Exception $e) {
  65 + $this->output('主机记录 ' . $domain_rr . 'error:' . $e->getMessage());
  66 + continue;
  67 + }
  68 + $record_edit_status_code = $record_edit['statusCode'] ?? 0;
  69 + if ($record_edit_status_code == 200) {
  70 + $this->output('修改主机记录 ' . $record_rr . ' 的值为 ' . $target_ip . ' 成功');
  71 + } else {
  72 + $this->output('修改主机记录 ' . $record_rr . ' 的值为 ' . $target_ip . ' 失败');
66 } 73 }
67 } 74 }
68 - } catch (\Exception $e) {  
69 - $this->output($e->getMessage());  
70 } 75 }
71 } 76 }
72 77