作者 刘锟

update

... ... @@ -18,55 +18,60 @@ class EmergencyRecords extends Command
//类型,1受灾,2恢复
$type = $this->argument('type');
try {
//获取服务器的所有可用ip
$server_ip_model = new ServersIp();
$server_ip_list = $server_ip_model->where('servers_id', $server_id)->where('status', 0)->get();
if ($server_ip_list->count() > 0) {
foreach ($server_ip_list as $value) {
if (empty($value->ip) || empty($value->domain)) {
$this->output('ID ' . $value->id . ' 数据错误');
continue;
}
//获取服务器的所有可用ip
$server_ip_model = new ServersIp();
$server_ip_list = $server_ip_model->where('servers_id', $server_id)->where('status', 0)->get();
if ($server_ip_list->count() > 0) {
foreach ($server_ip_list as $value) {
if (empty($value->ip) || empty($value->domain)) {
$this->output('ID ' . $value->id . ' 数据错误');
continue;
}
//获取解析记录
$domain_array = explode('.', $value->domain);
$domain_rr = $domain_array[0];
//获取解析记录
$domain_array = explode('.', $value->domain);
$domain_rr = $domain_array[0];
try {
$record = AlibabaCloudService::describeDomainRecords('globalso.com', $domain_rr);
$record_status_code = $record['statusCode'] ?? 0;
if ($record_status_code != 200) {
$this->output('获取主机记录 ' . $domain_rr . ' 解析数据失败');
continue;
}
$record_detail = $record['body']['DomainRecords']['Record'][0] ?? [];
if (!$record_detail) {
$this->output('主机记录 ' . $domain_rr . ' 解析数据不存在');
continue;
}
//目标ip跟解析记录当前ip一样的数据,不用修改
$target_ip = $type == 1 ? '43.153.1.240' : $value->ip;
if ($target_ip == $record_detail['Value']) {
$this->output('主机记录 ' . $domain_rr . ' 的值已为 ' . $target_ip);
continue;
}
} catch (\Exception $e) {
$this->output('主机记录 ' . $domain_rr . 'error:' . $e->getMessage());
continue;
}
$record_status_code = $record['statusCode'] ?? 0;
if ($record_status_code != 200) {
$this->output('获取主机记录 ' . $domain_rr . ' 解析数据失败');
continue;
}
$record_detail = $record['body']['DomainRecords']['Record'][0] ?? [];
if (!$record_detail) {
$this->output('主机记录 ' . $domain_rr . ' 解析数据不存在');
continue;
}
//修改解析记录
$record_id = $record_detail['RecordId'];
$record_rr = $record_detail['RR'];
$record_type = $record_detail['Type'];
//目标ip跟解析记录当前ip一样的数据,不用修改
$target_ip = $type == 1 ? '43.153.1.240' : $value->ip;
if ($target_ip == $record_detail['Value']) {
$this->output('主机记录 ' . $domain_rr . ' 的值已为 ' . $target_ip);
continue;
}
//修改解析记录
$record_id = $record_detail['RecordId'];
$record_rr = $record_detail['RR'];
$record_type = $record_detail['Type'];
try {
$record_edit = AlibabaCloudService::updateDomainRecord($record_id, $record_rr, $record_type, $target_ip);
$record_edit_status_code = $record_edit['statusCode'] ?? 0;
if ($record_edit_status_code == 200) {
$this->output('修改主机记录 ' . $record_rr . ' 的值为 ' . $target_ip . ' 成功');
} else {
$this->output('修改主机记录 ' . $record_rr . ' 的值为 ' . $target_ip . ' 失败');
}
} catch (\Exception $e) {
$this->output('主机记录 ' . $domain_rr . 'error:' . $e->getMessage());
continue;
}
$record_edit_status_code = $record_edit['statusCode'] ?? 0;
if ($record_edit_status_code == 200) {
$this->output('修改主机记录 ' . $record_rr . ' 的值为 ' . $target_ip . ' 成功');
} else {
$this->output('修改主机记录 ' . $record_rr . ' 的值为 ' . $target_ip . ' 失败');
}
}
} catch (\Exception $e) {
$this->output($e->getMessage());
}
}
... ...