diff --git a/app/lib/DeployHelper.php b/app/lib/DeployHelper.php index 7548692..2fed8a3 100644 --- a/app/lib/DeployHelper.php +++ b/app/lib/DeployHelper.php @@ -397,6 +397,16 @@ class DeployHelper 'placeholder' => '1Panel面板设置->API接口', 'required' => true, ], + 'version' => [ + 'name' => '1Panel版本', + 'type' => 'radio', + 'options' => [ + 'v1' => '1.x', + 'v2' => '2.x', + ], + 'value' => 'v1', + 'required' => true, + ], 'proxy' => [ 'name' => '使用代理服务器', 'type' => 'radio', diff --git a/app/lib/deploy/opanel.php b/app/lib/deploy/opanel.php index 7f9eab3..43c54b6 100644 --- a/app/lib/deploy/opanel.php +++ b/app/lib/deploy/opanel.php @@ -14,7 +14,7 @@ class opanel implements DeployInterface public function __construct($config) { - $this->url = rtrim($config['url'], '/'); + $this->url = rtrim($config['url'], '/') . '/api/' . $config['version'] ?: 'v1'; $this->key = $config['key']; $this->proxy = $config['proxy'] == 1; } @@ -22,7 +22,7 @@ class opanel implements DeployInterface public function check() { if (empty($this->url) || empty($this->key)) throw new Exception('请填写面板地址和接口密钥'); - $this->request('/api/v1/settings/search'); + $this->request("/settings/search"); } public function deploy($fullchain, $privatekey, $config, &$info) @@ -30,9 +30,9 @@ class opanel implements DeployInterface $domains = $config['domainList']; if (empty($domains)) throw new Exception('没有设置要部署的域名'); - $params = ['page'=>1, 'pageSize'=>500]; + $params = ['page' => 1, 'pageSize' => 500]; try { - $data = $this->request('/api/v1/websites/ssl/search', $params); + $data = $this->request("/websites/ssl/search", $params); $this->log('获取证书列表成功(total=' . $data['total'] . ')'); } catch (Exception $e) { throw new Exception('获取证书列表失败:' . $e->getMessage()); @@ -45,7 +45,7 @@ class opanel implements DeployInterface if (empty($row['primaryDomain'])) continue; $cert_domains = []; $cert_domains[] = $row['primaryDomain']; - if(!empty($row['domains'])) $cert_domains += explode(',', $row['domains']); + if (!empty($row['domains'])) $cert_domains += explode(',', $row['domains']); $flag = false; foreach ($cert_domains as $domain) { if (in_array($domain, $domains)) { @@ -62,7 +62,7 @@ class opanel implements DeployInterface 'description' => '', ]; try { - $this->request('/api/v1/websites/ssl/upload', $params); + $this->request('/websites/ssl/upload', $params); $this->log("证书ID:{$row['id']}更新成功!"); $success++; } catch (Exception $e) { @@ -93,21 +93,21 @@ class opanel implements DeployInterface { $url = $this->url . $path; - $timestamp = time().''; + $timestamp = time() . ''; $token = md5('1panel' . $this->key . $timestamp); $headers = [ - '1Panel-Token: '.$token, - '1Panel-Timestamp: '.$timestamp + '1Panel-Token: ' . $token, + '1Panel-Timestamp: ' . $timestamp ]; $body = $params ? json_encode($params) : '{}'; - if($body) $headers[] = 'Content-Type: application/json'; + if ($body) $headers[] = 'Content-Type: application/json'; $response = curl_client($url, $body, null, null, $headers, $this->proxy); $result = json_decode($response['body'], true); - if(isset($result['code']) && $result['code'] == 200){ + if (isset($result['code']) && $result['code'] == 200) { return isset($result['data']) ? $result['data'] : null; - }elseif(isset($result['message'])){ + } elseif (isset($result['message'])) { throw new Exception($result['message']); - }else{ + } else { throw new Exception('请求失败(httpCode=' . $response['code'] . ')'); } }