diff --git a/app/lib/DeployHelper.php b/app/lib/DeployHelper.php index 1e8cc3a..09ac2dc 100644 --- a/app/lib/DeployHelper.php +++ b/app/lib/DeployHelper.php @@ -43,6 +43,7 @@ class DeployHelper 'options' => [ '0' => '宝塔面板站点的证书', '1' => '宝塔面板本身的证书', + '2' => '宝塔邮局域名的证书', ], 'value' => '0', 'required' => true, @@ -51,8 +52,8 @@ class DeployHelper 'name' => '网站名称列表', 'type' => 'textarea', 'placeholder' => '填写要部署证书的网站名称,每行一个', - 'note' => 'PHP项目和反代项目填写创建时绑定的第一个域名,Java/Node/Go等其他项目填写项目名称', - 'show' => 'type==0', + 'note' => 'PHP项目和反代项目填写创建时绑定的第一个域名,Java/Node/Go等其他项目填写项目名称,邮局填写域名', + 'show' => 'type==0||type==2', 'required' => true, ], ], diff --git a/app/lib/deploy/btpanel.php b/app/lib/deploy/btpanel.php index 3aed11a..db790b0 100644 --- a/app/lib/deploy/btpanel.php +++ b/app/lib/deploy/btpanel.php @@ -46,13 +46,24 @@ class btpanel implements DeployInterface foreach ($sites as $site) { $siteName = trim($site); if (empty($siteName)) continue; - try { - $this->deploySite($siteName, $fullchain, $privatekey); - $this->log("网站 {$siteName} 证书部署成功"); - $success++; - } catch (Exception $e) { - $errmsg = $e->getMessage(); - $this->log("网站 {$siteName} 证书部署失败:" . $errmsg); + if ($config['type'] == '2') { + try { + $this->deployMailSys($siteName, $fullchain, $privatekey); + $this->log("邮局域名 {$siteName} 证书部署成功"); + $success++; + } catch (Exception $e) { + $errmsg = $e->getMessage(); + $this->log("邮局域名 {$siteName} 证书部署失败:" . $errmsg); + } + } else { + try { + $this->deploySite($siteName, $fullchain, $privatekey); + $this->log("网站 {$siteName} 证书部署成功"); + $success++; + } catch (Exception $e) { + $errmsg = $e->getMessage(); + $this->log("网站 {$siteName} 证书部署失败:" . $errmsg); + } } } if ($success == 0) { @@ -98,6 +109,26 @@ class btpanel implements DeployInterface } } + private function deployMailSys($domain, $fullchain, $privatekey) + { + $path = '/plugin?action=a&name=mail_sys&s=set_mail_certificate_multiple'; + $data = [ + 'domain' => $domain, + 'key' => $privatekey, + 'csr' => $fullchain, + 'act' => 'add', + ]; + $response = $this->request($path, $data); + $result = json_decode($response, true); + if (isset($result['status']) && $result['status']) { + return true; + } elseif (isset($result['msg'])) { + throw new Exception($result['msg']); + } else { + throw new Exception($response ? $response : '返回数据解析失败'); + } + } + public function setLogger($func) { $this->logger = $func; diff --git a/app/service/CertDeployService.php b/app/service/CertDeployService.php index f66fb8f..47c3a86 100644 --- a/app/service/CertDeployService.php +++ b/app/service/CertDeployService.php @@ -79,7 +79,7 @@ class CertDeployService //重置任务 public function reset() { - Db::name('cert_deploy')->where('id', $this->task['id'])->data(['status' => 0, 'retry' => 0, 'retrytime' => null, 'issend' => 0])->update(); + Db::name('cert_deploy')->where('id', $this->task['id'])->data(['status' => 0, 'retry' => 0, 'retrytime' => null, 'issend' => 0, 'islock' => 0])->update(); //$file_name = app()->getRuntimePath().'log/'.$this->task['processid'].'.log'; //if (file_exists($file_name)) unlink($file_name); $this->task['status'] = 0; diff --git a/app/service/CertOrderService.php b/app/service/CertOrderService.php index d9ff61b..7acc67e 100644 --- a/app/service/CertOrderService.php +++ b/app/service/CertOrderService.php @@ -205,7 +205,7 @@ class CertOrderService //重置订单 public function reset() { - Db::name('cert_order')->where('id', $this->order['id'])->data(['status' => 0, 'retry' => 0, 'retry2' => 0, 'retrytime' => null, 'processid' => null, 'updatetime' => date('Y-m-d H:i:s'), 'issend' => 0])->update(); + Db::name('cert_order')->where('id', $this->order['id'])->data(['status' => 0, 'retry' => 0, 'retry2' => 0, 'retrytime' => null, 'processid' => null, 'updatetime' => date('Y-m-d H:i:s'), 'issend' => 0, 'islock' => 0])->update(); $file_name = app()->getRuntimePath().'log/'.$this->order['processid'].'.log'; if (file_exists($file_name)) unlink($file_name); $this->order['status'] = 0;