diff --git a/app/lib/DeployHelper.php b/app/lib/DeployHelper.php index f98099f..ba719cc 100644 --- a/app/lib/DeployHelper.php +++ b/app/lib/DeployHelper.php @@ -1164,6 +1164,7 @@ ctrl+x 保存退出
', ['value'=>'vod', 'label'=>'视频点播'], ['value'=>'fc', 'label'=>'函数计算3.0'], ['value'=>'fc2', 'label'=>'函数计算2.0'], + ['value'=>'ga', 'label'=>'全球加速'], ['value'=>'upload', 'label'=>'上传到证书管理'], ], 'value' => 'cdn', @@ -1254,6 +1255,21 @@ ctrl+x 保存退出
', 'note' => '进入NLB实例详情->监听列表,复制监听ID(只支持TCPSSL监听协议)', 'required' => true, ], + 'ga_id' => [ + 'name' => '全球加速实例ID', + 'type' => 'input', + 'placeholder' => '', + 'show' => 'product==\'ga\'', + 'required' => true, + ], + 'ga_listener_id' => [ + 'name' => '监听ID', + 'type' => 'input', + 'placeholder' => '', + 'show' => 'product==\'ga\'', + 'note' => '进入实例详情->监听列表,复制监听ID(只支持HTTPS监听协议)', + 'required' => true, + ], 'deploy_type' => [ 'name' => '部署证书类型', 'type' => 'select', @@ -1262,21 +1278,21 @@ ctrl+x 保存退出
', ['value'=>'1', 'label'=>'扩展证书'], ], 'value' => '0', - 'show' => 'product==\'clb\'||product==\'alb\'||product==\'nlb\'', + 'show' => 'product==\'clb\'||product==\'alb\'||product==\'nlb\'||product==\'ga\'', 'required' => true, ], 'clb_domain' => [ 'name' => '扩展域名', 'type' => 'input', 'placeholder' => '多个域名可使用,分隔', - 'show' => 'product==\'clb\'&&deploy_type==1', + 'show' => 'product==\'clb\'&&deploy_type==1||product==\'ga\'&&deploy_type==1', 'required' => true, ], 'domain' => [ 'name' => '绑定的域名', 'type' => 'input', 'placeholder' => '', - 'show' => 'product!=\'esa\'&&product!=\'clb\'&&product!=\'alb\'&&product!=\'nlb\'&&product!=\'upload\'', + 'show' => 'product!=\'esa\'&&product!=\'clb\'&&product!=\'alb\'&&product!=\'nlb\'&&product!=\'ga\'&&product!=\'upload\'', 'required' => true, ], ], diff --git a/app/lib/deploy/aliyun.php b/app/lib/deploy/aliyun.php index d8afbdd..115ae7a 100644 --- a/app/lib/deploy/aliyun.php +++ b/app/lib/deploy/aliyun.php @@ -66,6 +66,8 @@ class aliyun implements DeployInterface $this->deploy_alb($cert_id, $config); } elseif ($config['product'] == 'nlb') { $this->deploy_nlb($cert_id, $config); + } elseif ($config['product'] == 'ga') { + $this->deploy_ga($cert_id, $config); } elseif ($config['product'] == 'upload') { } else { throw new Exception('未知的产品类型'); @@ -764,6 +766,84 @@ class aliyun implements DeployInterface } } + private function deploy_ga($cert_id, $config) + { + if (empty($config['ga_id'])) throw new Exception('全球加速实例ID不能为空'); + if (empty($config['ga_listener_id'])) throw new Exception('全球加速监听ID不能为空'); + + $client = new AliyunClient($this->AccessKeyId, $this->AccessKeySecret, 'ga.cn-hangzhou.aliyuncs.com', '2019-11-20', $this->proxy); + $cert_id = $cert_id . '-cn-hangzhou'; + $deploy_type = isset($config['deploy_type']) ? intval($config['deploy_type']) : 0; + + if ($deploy_type == 1) { + if (empty($config['clb_domain'])) throw new Exception('扩展域名不能为空'); + $param = [ + 'Action' => 'ListListenerCertificates', + 'RegionId' => 'cn-hangzhou', + 'AcceleratorId' => $config['ga_id'], + 'ListenerId' => $config['ga_listener_id'], + ]; + try { + $data = $client->request($param); + } catch (Exception $e) { + throw new Exception('扩展域名列表查询失败:' . $e->getMessage()); + } + $need_add = []; + foreach (explode(',', $config['clb_domain']) as $domain) { + $domainExists = false; + $exist_cert_id = null; + foreach ($data['Certificates'] as $cert) { + if (isset($cert['Domain']) && $domain == $cert['Domain']) { + $domainExists = true; + $exist_cert_id = $cert['CertificateId']; + } + } + if ($domainExists) { + if ($exist_cert_id == $cert_id) { + $this->log('全球加速实例监听扩展域名 ' . $domain . ' 证书已配置'); + continue; + } + $param = [ + 'Action' => 'UpdateAdditionalCertificateWithListener', + 'RegionId' => 'cn-hangzhou', + 'AcceleratorId' => $config['ga_id'], + 'ListenerId' => $config['ga_listener_id'], + 'Domain' => $domain, + 'CertificateId' => $cert_id, + ]; + $client->request($param); + $this->log('全球加速实例监听扩展域名 ' . $domain . ' 替换证书成功!'); + } else { + $need_add[] = $domain; + } + } + if (count($need_add) > 0) { + $param = [ + 'Action' => 'AssociateAdditionalCertificatesWithListener', + 'RegionId' => 'cn-hangzhou', + 'AcceleratorId' => $config['ga_id'], + 'ListenerId' => $config['ga_listener_id'], + ]; + foreach ($need_add as $index => $domain) { + $param['Certificates.' . ($index + 1) . '.Id'] = $cert_id; + $param['Certificates.' . ($index + 1) . '.Domain'] = $domain; + } + $client->request($param); + $this->log('全球加速实例监听扩展域名 ' . implode(',', $need_add) . ' 绑定证书成功!'); + } + } else { + $param = [ + 'Action' => 'UpdateListener', + 'RegionId' => 'cn-hangzhou', + 'AcceleratorId' => $config['ga_id'], + 'ListenerId' => $config['ga_listener_id'], + 'Certificates.1.Id' => $cert_id, + ]; + $client->request($param); + $this->log('全球加速实例监听默认证书更新成功!'); + } + } + public function setLogger($func) { $this->logger = $func;