作者 zhl

u

... ... @@ -166,6 +166,84 @@ public function deleteSiteEvent($id, $param)
}
/**
* 创建ssl证书
* @param $id
* @param $param
* @return bool
*/
public function createSiteSsl($id, $param)
{
if (empty($param) || FALSE == is_array($param))
return false;
$callback = $param['callback'] ?? '';
$host = $param['host'] ?? '';
if (empty($host)) {
if (FALSE == empty($callback) && filter_var($callback, FILTER_VALIDATE_URL)) {
$param['result_status'] = 400;
$param['result_message'] = 'host信息错误';
BtEvents::createBtEvent(BtEvents::TYPE_EVENT_CALLBACK, json_encode($param));
}
return $this->setEvent($id, BtEvents::STATUS_FINISH, 'host信息错误');
}
try {
$flag = app(BtRepository::class)->applySsl($host);
$status = $flag ? BtEvents::STATUS_FINISH : BtEvents::STATUS_ERROR;
$note = $flag ? '' : '删除站点失败';
} catch (\Exception $e) {
$status = BtEvents::STATUS_ERROR;
$note = $e->getMessage();
}
if (FALSE == empty($callback) && filter_var($callback, FILTER_VALIDATE_URL)) {
$param['result_status'] = $status == BtEvents::STATUS_FINISH ? 200 : 400;
$param['result_message'] = $note;
BtEvents::createBtEvent(BtEvents::TYPE_EVENT_CALLBACK, json_encode($param));
}
return $this->setEvent($id, $status, $note);
}
/**
* 续签证书
* @param $id
* @param $param
* @return bool
*/
public function renewalSiteSsl($id, $param)
{
if (empty($param) || FALSE == is_array($param))
return false;
$callback = $param['callback'] ?? '';
$host = $param['host'] ?? '';
if (empty($host)) {
if (FALSE == empty($callback) && filter_var($callback, FILTER_VALIDATE_URL)) {
$param['result_status'] = 400;
$param['result_message'] = 'host信息错误';
BtEvents::createBtEvent(BtEvents::TYPE_EVENT_CALLBACK, json_encode($param));
}
return $this->setEvent($id, BtEvents::STATUS_FINISH, 'host信息错误');
}
try {
$flag = app(BtRepository::class)->renewalSsl($host);
$status = $flag ? BtEvents::STATUS_FINISH : BtEvents::STATUS_ERROR;
$note = $flag ? '' : '删除站点失败';
} catch (\Exception $e) {
$status = BtEvents::STATUS_ERROR;
$note = $e->getMessage();
}
if (FALSE == empty($callback) && filter_var($callback, FILTER_VALIDATE_URL)) {
$param['result_status'] = $status == BtEvents::STATUS_FINISH ? 200 : 400;
$param['result_message'] = $note;
BtEvents::createBtEvent(BtEvents::TYPE_EVENT_CALLBACK, json_encode($param));
}
return $this->setEvent($id, $status, $note);
}
/**
* 回调信息
* @param $id
* @param $param
... ...
... ... @@ -63,7 +63,7 @@ public function handle()
if ($val->ssl_status == 0) {
$result = app(BtRepository::class)->applySsl($sites->domain);
if (empty($result))
BtEvents::createBtEvent(BtEvents::TYPE_CREATE_SSL, json_encode(['domain' => $sites->domain]));
BtEvents::createBtEvent(BtEvents::TYPE_CREATE_SSL, json_encode(['host' => $sites->domain]));
continue;
}
... ... @@ -71,10 +71,11 @@ public function handle()
if ($val->ssl_auto) {
$result = app(BtRepository::class)->renewalSsl($sites->domain);
if (empty($result))
BtEvents::createBtEvent(BtEvents::TYPE_RENEWAL_SSL, json_encode(['domain' => $sites->domain]));
BtEvents::createBtEvent(BtEvents::TYPE_RENEWAL_SSL, json_encode(['host' => $sites->domain]));
continue;
}
sleep(2);
}
return true;
}
... ...
... ... @@ -16,6 +16,7 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
$schedule->command('site:ssl_renewal')->dailyAt('01:00'); // 站点创建ssl证书, 续签
}
/**
... ...
... ... @@ -56,8 +56,8 @@ public function deleteSite(Request $request)
$result = app(BtRepository::class)->deleteBtSite($domain);
return $result ? $this->success() : $this->error('删除站点失败,提交异步删除任务!');
} catch (\Exception $d) {
return $this->error();
} catch (\Exception $e) {
return $this->error($e->getMessage());
}
}
... ... @@ -68,7 +68,17 @@ public function deleteSite(Request $request)
*/
public function createSsl(Request $request)
{
return $this->error();
try {
// $this->validate();
$host = $request->input('host');
if (empty($host))
return $this->error('请提交有效host信息');
$result = app(BtRepository::class)->deleteBtSite($host);
return $result ? $this->success() : $this->error('创建ssl失败,提交异步任务!');
} catch (\Exception $e) {
return $this->error($e->getMessage());
}
}
/**
... ... @@ -76,8 +86,18 @@ public function createSsl(Request $request)
* @param Request $request
* @return string
*/
public function updateSsl(Request $request)
public function renewalSsl(Request $request)
{
return $this->error();
try {
// $this->validate();
$host = $request->input('host');
if (empty($host))
return $this->error('请提交有效host信息');
$result = app(BtRepository::class)->renewalSsl($host);
return $result ? $this->success() : $this->error('续签ssl失败,提交异步任务!');
} catch (\Exception $e) {
return $this->error($e->getMessage());
}
}
}
\ No newline at end of file
... ...
... ... @@ -22,7 +22,7 @@
Route::any('/create_site', 'WebSiteController@createSite')->name('create_site');
Route::any('/delete_site', 'WebSiteController@deleteSite')->name('delete_site');
Route::any('/create_site_ssl', 'WebSiteController@createSsl')->name('create_site_ssl');
Route::any('/update_site_ssl', 'WebSiteController@updateSsl')->name('update_site_ssl');
Route::any('/renewal_site_ssl', 'WebSiteController@renewalSsl')->name('renewal_site_ssl');
Route::get('/create_event', 'ReceiveController@createEvent')->name('create_event');
});
... ...