支持部署到阿里云全球加速

This commit is contained in:
net909 2026-02-17 14:30:57 +08:00
parent c0e72908ab
commit e25d5d76e9
2 changed files with 99 additions and 3 deletions

View File

@ -1164,6 +1164,7 @@ ctrl+x 保存退出<br/>',
['value'=>'vod', 'label'=>'视频点播'], ['value'=>'vod', 'label'=>'视频点播'],
['value'=>'fc', 'label'=>'函数计算3.0'], ['value'=>'fc', 'label'=>'函数计算3.0'],
['value'=>'fc2', 'label'=>'函数计算2.0'], ['value'=>'fc2', 'label'=>'函数计算2.0'],
['value'=>'ga', 'label'=>'全球加速'],
['value'=>'upload', 'label'=>'上传到证书管理'], ['value'=>'upload', 'label'=>'上传到证书管理'],
], ],
'value' => 'cdn', 'value' => 'cdn',
@ -1254,6 +1255,21 @@ ctrl+x 保存退出<br/>',
'note' => '进入NLB实例详情->监听列表复制监听ID只支持TCPSSL监听协议', 'note' => '进入NLB实例详情->监听列表复制监听ID只支持TCPSSL监听协议',
'required' => true, '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' => [ 'deploy_type' => [
'name' => '部署证书类型', 'name' => '部署证书类型',
'type' => 'select', 'type' => 'select',
@ -1262,21 +1278,21 @@ ctrl+x 保存退出<br/>',
['value'=>'1', 'label'=>'扩展证书'], ['value'=>'1', 'label'=>'扩展证书'],
], ],
'value' => '0', 'value' => '0',
'show' => 'product==\'clb\'||product==\'alb\'||product==\'nlb\'', 'show' => 'product==\'clb\'||product==\'alb\'||product==\'nlb\'||product==\'ga\'',
'required' => true, 'required' => true,
], ],
'clb_domain' => [ 'clb_domain' => [
'name' => '扩展域名', 'name' => '扩展域名',
'type' => 'input', 'type' => 'input',
'placeholder' => '多个域名可使用,分隔', 'placeholder' => '多个域名可使用,分隔',
'show' => 'product==\'clb\'&&deploy_type==1', 'show' => 'product==\'clb\'&&deploy_type==1||product==\'ga\'&&deploy_type==1',
'required' => true, 'required' => true,
], ],
'domain' => [ 'domain' => [
'name' => '绑定的域名', 'name' => '绑定的域名',
'type' => 'input', 'type' => 'input',
'placeholder' => '', '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, 'required' => true,
], ],
], ],

View File

@ -66,6 +66,8 @@ class aliyun implements DeployInterface
$this->deploy_alb($cert_id, $config); $this->deploy_alb($cert_id, $config);
} elseif ($config['product'] == 'nlb') { } elseif ($config['product'] == 'nlb') {
$this->deploy_nlb($cert_id, $config); $this->deploy_nlb($cert_id, $config);
} elseif ($config['product'] == 'ga') {
$this->deploy_ga($cert_id, $config);
} elseif ($config['product'] == 'upload') { } elseif ($config['product'] == 'upload') {
} else { } else {
throw new Exception('未知的产品类型'); 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) public function setLogger($func)
{ {
$this->logger = $func; $this->logger = $func;