正在显示
1 个修改的文件
包含
84 行增加
和
23 行删除
@@ -53,33 +53,61 @@ public function checkDomainSsl() | @@ -53,33 +53,61 @@ public function checkDomainSsl() | ||
53 | $site_id = $site_list['data'][0]['id']; | 53 | $site_id = $site_list['data'][0]['id']; |
54 | $host = $site_list['data'][0]['name']; | 54 | $host = $site_list['data'][0]['name']; |
55 | 55 | ||
56 | - //获取站点可用于设置证书的域名 | ||
57 | - $site_domain_list = $this->bt->WebDoaminList($site_id); | ||
58 | - $apply_ssl_domain_list = []; | ||
59 | - foreach ($site_domain_list as $val) { | ||
60 | - if (strpos($val['name'], '*') === false && $this->check_domain_record($val['name'], ['domain' => '', 'ip' => $site_ip])) { | ||
61 | - $apply_ssl_domain_list[] = $val['name']; | 56 | + if (env('IS_SSL', false)) { |
57 | + //通配符证书 | ||
58 | + $transmitUrl = env("TRANSMIT_URL"); | ||
59 | + $resp = $this->httpPost($transmitUrl . "api/selfSiteSsl/", json_encode([])); | ||
60 | + if (isset($resp['status']) && $resp['status'] == 200) { | ||
61 | + $ssl_key = $resp['data']['ssl_key'] ?? ''; | ||
62 | + $ssl_cert = $resp['data']['ssl_cert'] ?? ''; | ||
63 | + if ($ssl_key && $ssl_cert) { | ||
64 | + //申请证书之前,还原主站配置 | ||
65 | + $config_before = file_get_contents(public_path('main_site_default.txt')); | ||
66 | + $re_config_before = $this->bt->SaveFileBody('/www/server/panel/vhost/nginx/' . $host . '.conf', $config_before, 'utf-8', 1); | ||
67 | + if (!($re_config_before['status'] ?? false)) { | ||
68 | + throw new \Exception($re_config_before['msg'] ?? '还原主站nginx配置失败'); | ||
69 | + } | ||
70 | + | ||
71 | + //设置站点证书 | ||
72 | + $this->setDomainSsl($site_id, $host, [], $ssl_key, $ssl_cert); | ||
73 | + | ||
74 | + //申请证书之后,更新主站配置 | ||
75 | + $config_after = file_get_contents(public_path('main_site_config.txt')); | ||
76 | + $re_config_after = $this->bt->SaveFileBody('/www/server/panel/vhost/nginx/' . $host . '.conf', $config_after, 'utf-8', 1); | ||
77 | + if (!($re_config_after['status'] ?? false)) { | ||
78 | + throw new \Exception($re_config_after['msg'] ?? '更新主站nginx配置失败'); | ||
79 | + } | ||
80 | + } | ||
81 | + } | ||
82 | + } else { | ||
83 | + //获取站点可用于设置证书的域名 | ||
84 | + $site_domain_list = $this->bt->WebDoaminList($site_id); | ||
85 | + $apply_ssl_domain_list = []; | ||
86 | + foreach ($site_domain_list as $val) { | ||
87 | + if (strpos($val['name'], '*') === false && $this->check_domain_record($val['name'], ['domain' => '', 'ip' => $site_ip])) { | ||
88 | + $apply_ssl_domain_list[] = $val['name']; | ||
89 | + } | ||
90 | + } | ||
91 | + if (empty($apply_ssl_domain_list)) { | ||
92 | + throw new \Exception('主站所有域名都未解析在当前服务器'); | ||
62 | } | 93 | } |
63 | - } | ||
64 | - if (empty($apply_ssl_domain_list)) { | ||
65 | - throw new \Exception('主站所有域名都未解析在当前服务器'); | ||
66 | - } | ||
67 | 94 | ||
68 | - //申请证书之前,还原主站配置 | ||
69 | - $config_before = file_get_contents(public_path('main_site_default.txt')); | ||
70 | - $re_config_before = $this->bt->SaveFileBody('/www/server/panel/vhost/nginx/' . $host . '.conf', $config_before, 'utf-8', 1); | ||
71 | - if (!($re_config_before['status'] ?? false)) { | ||
72 | - throw new \Exception($re_config_before['msg'] ?? '还原主站nginx配置失败'); | ||
73 | - } | 95 | + //申请证书之前,还原主站配置 |
96 | + $config_before = file_get_contents(public_path('main_site_default.txt')); | ||
97 | + $re_config_before = $this->bt->SaveFileBody('/www/server/panel/vhost/nginx/' . $host . '.conf', $config_before, 'utf-8', 1); | ||
98 | + if (!($re_config_before['status'] ?? false)) { | ||
99 | + throw new \Exception($re_config_before['msg'] ?? '还原主站nginx配置失败'); | ||
100 | + } | ||
74 | 101 | ||
75 | - //设置站点证书 | ||
76 | - $this->setDomainSsl($site_id, $host, $apply_ssl_domain_list); | 102 | + //设置站点证书 |
103 | + $this->setDomainSsl($site_id, $host, $apply_ssl_domain_list); | ||
77 | 104 | ||
78 | - //申请证书之后,更新主站配置 | ||
79 | - $config_after = file_get_contents(public_path('main_site_config.txt')); | ||
80 | - $re_config_after = $this->bt->SaveFileBody('/www/server/panel/vhost/nginx/' . $host . '.conf', $config_after, 'utf-8', 1); | ||
81 | - if (!($re_config_after['status'] ?? false)) { | ||
82 | - throw new \Exception($re_config_after['msg'] ?? '更新主站nginx配置失败'); | 105 | + //申请证书之后,更新主站配置 |
106 | + $config_after = file_get_contents(public_path('main_site_config.txt')); | ||
107 | + $re_config_after = $this->bt->SaveFileBody('/www/server/panel/vhost/nginx/' . $host . '.conf', $config_after, 'utf-8', 1); | ||
108 | + if (!($re_config_after['status'] ?? false)) { | ||
109 | + throw new \Exception($re_config_after['msg'] ?? '更新主站nginx配置失败'); | ||
110 | + } | ||
83 | } | 111 | } |
84 | 112 | ||
85 | $this->output('主站证书更新成功'); | 113 | $this->output('主站证书更新成功'); |
@@ -232,6 +260,39 @@ public function getDomainSslTime($domain) | @@ -232,6 +260,39 @@ public function getDomainSslTime($domain) | ||
232 | return ['from' => $valid_from, 'to' => $valid_to]; | 260 | return ['from' => $valid_from, 'to' => $valid_to]; |
233 | } | 261 | } |
234 | 262 | ||
263 | + public function httpPost($url, $data, $header = [], $is_json = true) | ||
264 | + { | ||
265 | + if (empty($header)) { | ||
266 | + $header = array( | ||
267 | + "Accept: application/json", | ||
268 | + "Content-Type:application/json;charset=utf-8", | ||
269 | + "token:" . env("SECRET_TOKEN"), | ||
270 | + "pid:" . env("MERCHANT_NUMBER") | ||
271 | + ); | ||
272 | + } | ||
273 | + $ch = curl_init(); | ||
274 | + curl_setopt($ch, CURLOPT_URL, $url); | ||
275 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | ||
276 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | ||
277 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); | ||
278 | + curl_setopt($ch, CURLOPT_HTTPHEADER, $header); | ||
279 | + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); | ||
280 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | ||
281 | + curl_setopt($ch, CURLOPT_AUTOREFERER, 1); | ||
282 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | ||
283 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
284 | + $res = curl_exec($ch); | ||
285 | + if (curl_errno($ch)) { | ||
286 | + $error_message = curl_error($ch); | ||
287 | + @file_put_contents(storage_path('logs/error.log'), var_export($error_message, true) . PHP_EOL, FILE_APPEND); | ||
288 | + } | ||
289 | + curl_close($ch); | ||
290 | + if ($is_json) { | ||
291 | + return json_decode($res, true); | ||
292 | + } | ||
293 | + return trim($res); | ||
294 | + } | ||
295 | + | ||
235 | /** | 296 | /** |
236 | * 输出处理日志 | 297 | * 输出处理日志 |
237 | * @param $message | 298 | * @param $message |
-
请 注册 或 登录 后发表评论