正在显示
5 个修改的文件
包含
108 行增加
和
8 行删除
| @@ -166,6 +166,84 @@ public function deleteSiteEvent($id, $param) | @@ -166,6 +166,84 @@ public function deleteSiteEvent($id, $param) | ||
| 166 | } | 166 | } |
| 167 | 167 | ||
| 168 | /** | 168 | /** |
| 169 | + * 创建ssl证书 | ||
| 170 | + * @param $id | ||
| 171 | + * @param $param | ||
| 172 | + * @return bool | ||
| 173 | + */ | ||
| 174 | + public function createSiteSsl($id, $param) | ||
| 175 | + { | ||
| 176 | + if (empty($param) || FALSE == is_array($param)) | ||
| 177 | + return false; | ||
| 178 | + $callback = $param['callback'] ?? ''; | ||
| 179 | + $host = $param['host'] ?? ''; | ||
| 180 | + if (empty($host)) { | ||
| 181 | + if (FALSE == empty($callback) && filter_var($callback, FILTER_VALIDATE_URL)) { | ||
| 182 | + $param['result_status'] = 400; | ||
| 183 | + $param['result_message'] = 'host信息错误'; | ||
| 184 | + BtEvents::createBtEvent(BtEvents::TYPE_EVENT_CALLBACK, json_encode($param)); | ||
| 185 | + } | ||
| 186 | + return $this->setEvent($id, BtEvents::STATUS_FINISH, 'host信息错误'); | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + try { | ||
| 190 | + $flag = app(BtRepository::class)->applySsl($host); | ||
| 191 | + $status = $flag ? BtEvents::STATUS_FINISH : BtEvents::STATUS_ERROR; | ||
| 192 | + $note = $flag ? '' : '删除站点失败'; | ||
| 193 | + } catch (\Exception $e) { | ||
| 194 | + $status = BtEvents::STATUS_ERROR; | ||
| 195 | + $note = $e->getMessage(); | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + if (FALSE == empty($callback) && filter_var($callback, FILTER_VALIDATE_URL)) { | ||
| 199 | + $param['result_status'] = $status == BtEvents::STATUS_FINISH ? 200 : 400; | ||
| 200 | + $param['result_message'] = $note; | ||
| 201 | + BtEvents::createBtEvent(BtEvents::TYPE_EVENT_CALLBACK, json_encode($param)); | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + return $this->setEvent($id, $status, $note); | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + /** | ||
| 208 | + * 续签证书 | ||
| 209 | + * @param $id | ||
| 210 | + * @param $param | ||
| 211 | + * @return bool | ||
| 212 | + */ | ||
| 213 | + public function renewalSiteSsl($id, $param) | ||
| 214 | + { | ||
| 215 | + if (empty($param) || FALSE == is_array($param)) | ||
| 216 | + return false; | ||
| 217 | + $callback = $param['callback'] ?? ''; | ||
| 218 | + $host = $param['host'] ?? ''; | ||
| 219 | + if (empty($host)) { | ||
| 220 | + if (FALSE == empty($callback) && filter_var($callback, FILTER_VALIDATE_URL)) { | ||
| 221 | + $param['result_status'] = 400; | ||
| 222 | + $param['result_message'] = 'host信息错误'; | ||
| 223 | + BtEvents::createBtEvent(BtEvents::TYPE_EVENT_CALLBACK, json_encode($param)); | ||
| 224 | + } | ||
| 225 | + return $this->setEvent($id, BtEvents::STATUS_FINISH, 'host信息错误'); | ||
| 226 | + } | ||
| 227 | + | ||
| 228 | + try { | ||
| 229 | + $flag = app(BtRepository::class)->renewalSsl($host); | ||
| 230 | + $status = $flag ? BtEvents::STATUS_FINISH : BtEvents::STATUS_ERROR; | ||
| 231 | + $note = $flag ? '' : '删除站点失败'; | ||
| 232 | + } catch (\Exception $e) { | ||
| 233 | + $status = BtEvents::STATUS_ERROR; | ||
| 234 | + $note = $e->getMessage(); | ||
| 235 | + } | ||
| 236 | + | ||
| 237 | + if (FALSE == empty($callback) && filter_var($callback, FILTER_VALIDATE_URL)) { | ||
| 238 | + $param['result_status'] = $status == BtEvents::STATUS_FINISH ? 200 : 400; | ||
| 239 | + $param['result_message'] = $note; | ||
| 240 | + BtEvents::createBtEvent(BtEvents::TYPE_EVENT_CALLBACK, json_encode($param)); | ||
| 241 | + } | ||
| 242 | + | ||
| 243 | + return $this->setEvent($id, $status, $note); | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | + /** | ||
| 169 | * 回调信息 | 247 | * 回调信息 |
| 170 | * @param $id | 248 | * @param $id |
| 171 | * @param $param | 249 | * @param $param |
| @@ -63,7 +63,7 @@ public function handle() | @@ -63,7 +63,7 @@ public function handle() | ||
| 63 | if ($val->ssl_status == 0) { | 63 | if ($val->ssl_status == 0) { |
| 64 | $result = app(BtRepository::class)->applySsl($sites->domain); | 64 | $result = app(BtRepository::class)->applySsl($sites->domain); |
| 65 | if (empty($result)) | 65 | if (empty($result)) |
| 66 | - BtEvents::createBtEvent(BtEvents::TYPE_CREATE_SSL, json_encode(['domain' => $sites->domain])); | 66 | + BtEvents::createBtEvent(BtEvents::TYPE_CREATE_SSL, json_encode(['host' => $sites->domain])); |
| 67 | continue; | 67 | continue; |
| 68 | } | 68 | } |
| 69 | 69 | ||
| @@ -71,10 +71,11 @@ public function handle() | @@ -71,10 +71,11 @@ public function handle() | ||
| 71 | if ($val->ssl_auto) { | 71 | if ($val->ssl_auto) { |
| 72 | $result = app(BtRepository::class)->renewalSsl($sites->domain); | 72 | $result = app(BtRepository::class)->renewalSsl($sites->domain); |
| 73 | if (empty($result)) | 73 | if (empty($result)) |
| 74 | - BtEvents::createBtEvent(BtEvents::TYPE_RENEWAL_SSL, json_encode(['domain' => $sites->domain])); | 74 | + BtEvents::createBtEvent(BtEvents::TYPE_RENEWAL_SSL, json_encode(['host' => $sites->domain])); |
| 75 | continue; | 75 | continue; |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | + sleep(2); | ||
| 78 | } | 79 | } |
| 79 | return true; | 80 | return true; |
| 80 | } | 81 | } |
| @@ -16,6 +16,7 @@ class Kernel extends ConsoleKernel | @@ -16,6 +16,7 @@ class Kernel extends ConsoleKernel | ||
| 16 | protected function schedule(Schedule $schedule) | 16 | protected function schedule(Schedule $schedule) |
| 17 | { | 17 | { |
| 18 | // $schedule->command('inspire')->hourly(); | 18 | // $schedule->command('inspire')->hourly(); |
| 19 | + $schedule->command('site:ssl_renewal')->dailyAt('01:00'); // 站点创建ssl证书, 续签 | ||
| 19 | } | 20 | } |
| 20 | 21 | ||
| 21 | /** | 22 | /** |
| @@ -56,8 +56,8 @@ public function deleteSite(Request $request) | @@ -56,8 +56,8 @@ public function deleteSite(Request $request) | ||
| 56 | 56 | ||
| 57 | $result = app(BtRepository::class)->deleteBtSite($domain); | 57 | $result = app(BtRepository::class)->deleteBtSite($domain); |
| 58 | return $result ? $this->success() : $this->error('删除站点失败,提交异步删除任务!'); | 58 | return $result ? $this->success() : $this->error('删除站点失败,提交异步删除任务!'); |
| 59 | - } catch (\Exception $d) { | ||
| 60 | - return $this->error(); | 59 | + } catch (\Exception $e) { |
| 60 | + return $this->error($e->getMessage()); | ||
| 61 | } | 61 | } |
| 62 | } | 62 | } |
| 63 | 63 | ||
| @@ -68,7 +68,17 @@ public function deleteSite(Request $request) | @@ -68,7 +68,17 @@ public function deleteSite(Request $request) | ||
| 68 | */ | 68 | */ |
| 69 | public function createSsl(Request $request) | 69 | public function createSsl(Request $request) |
| 70 | { | 70 | { |
| 71 | - return $this->error(); | 71 | + try { |
| 72 | +// $this->validate(); | ||
| 73 | + $host = $request->input('host'); | ||
| 74 | + if (empty($host)) | ||
| 75 | + return $this->error('请提交有效host信息'); | ||
| 76 | + | ||
| 77 | + $result = app(BtRepository::class)->deleteBtSite($host); | ||
| 78 | + return $result ? $this->success() : $this->error('创建ssl失败,提交异步任务!'); | ||
| 79 | + } catch (\Exception $e) { | ||
| 80 | + return $this->error($e->getMessage()); | ||
| 81 | + } | ||
| 72 | } | 82 | } |
| 73 | 83 | ||
| 74 | /** | 84 | /** |
| @@ -76,8 +86,18 @@ public function createSsl(Request $request) | @@ -76,8 +86,18 @@ public function createSsl(Request $request) | ||
| 76 | * @param Request $request | 86 | * @param Request $request |
| 77 | * @return string | 87 | * @return string |
| 78 | */ | 88 | */ |
| 79 | - public function updateSsl(Request $request) | 89 | + public function renewalSsl(Request $request) |
| 80 | { | 90 | { |
| 81 | - return $this->error(); | 91 | + try { |
| 92 | +// $this->validate(); | ||
| 93 | + $host = $request->input('host'); | ||
| 94 | + if (empty($host)) | ||
| 95 | + return $this->error('请提交有效host信息'); | ||
| 96 | + | ||
| 97 | + $result = app(BtRepository::class)->renewalSsl($host); | ||
| 98 | + return $result ? $this->success() : $this->error('续签ssl失败,提交异步任务!'); | ||
| 99 | + } catch (\Exception $e) { | ||
| 100 | + return $this->error($e->getMessage()); | ||
| 101 | + } | ||
| 82 | } | 102 | } |
| 83 | } | 103 | } |
| @@ -22,7 +22,7 @@ | @@ -22,7 +22,7 @@ | ||
| 22 | Route::any('/create_site', 'WebSiteController@createSite')->name('create_site'); | 22 | Route::any('/create_site', 'WebSiteController@createSite')->name('create_site'); |
| 23 | Route::any('/delete_site', 'WebSiteController@deleteSite')->name('delete_site'); | 23 | Route::any('/delete_site', 'WebSiteController@deleteSite')->name('delete_site'); |
| 24 | Route::any('/create_site_ssl', 'WebSiteController@createSsl')->name('create_site_ssl'); | 24 | Route::any('/create_site_ssl', 'WebSiteController@createSsl')->name('create_site_ssl'); |
| 25 | - Route::any('/update_site_ssl', 'WebSiteController@updateSsl')->name('update_site_ssl'); | 25 | + Route::any('/renewal_site_ssl', 'WebSiteController@renewalSsl')->name('renewal_site_ssl'); |
| 26 | 26 | ||
| 27 | Route::get('/create_event', 'ReceiveController@createEvent')->name('create_event'); | 27 | Route::get('/create_event', 'ReceiveController@createEvent')->name('create_event'); |
| 28 | }); | 28 | }); |
-
请 注册 或 登录 后发表评论