WebSiteController.php
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2022/11/1
* Time: 10:31
*/
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Repositories\BtRepository;
use Illuminate\Http\Request;
/**
* Class WebSiteControllers
* @package App\Http\Controllers
*/
class WebSiteController extends Controller
{
/**
* 创建站点
* @param Request $request
* @return string
*/
public function createSite(Request $request)
{
try {
// $this->validate();
$domain = $request->input('domain');
$ssl_open = intval($request->input('ssl_open', 1)) ? 1 : 0;
$ssl_auto = intval($request->input('ssl_auto', 1)) ? 1 : 0;
$ssl_auto_day = intval($request->input('ssl_auto_day', 10));
$ssl_auto_day = $ssl_auto_day > 15 ? 15 : max($ssl_auto_day, 5);
if (empty($domain) || FALSE == filter_var($domain, FILTER_VALIDATE_URL))
return $this->error('请提交有效domain信息');
$result = app(BtRepository::class)->createBtSite($domain, $ssl_open, $ssl_auto, $ssl_auto_day);
return $result ? $this->success($result) : $this->error('创建站点失败,提交异步创建任务!');
} catch (\Exception $e) {
return $this->error($e->getMessage());
}
}
/**
* 删除站点
* @param Request $request
* @return string
*/
public function deleteSite(Request $request)
{
try {
// $this->validate();
$domain = $request->input('domain');
if (empty($domain) || filter_var($domain, FILTER_VALIDATE_URL))
return $this->error('请提交有效domain信息');
$result = app(BtRepository::class)->deleteBtSite($domain);
return $result ? $this->success() : $this->error('删除站点失败,提交异步删除任务!');
} catch (\Exception $e) {
return $this->error($e->getMessage());
}
}
/**
* 创建站点免费证书
* @param Request $request
* @return string
*/
public function createSsl(Request $request)
{
try {
// $this->validate();
$host = $request->input('host');
if (empty($host))
return $this->error('请提交有效host信息');
$result = app(BtRepository::class)->applySsl($host);
return $result ? $this->success() : $this->error('创建ssl失败,提交异步任务!');
} catch (\Exception $e) {
return $this->error($e->getMessage());
}
}
/**
* 更新站点免费证书
* @param Request $request
* @return string
*/
public function renewalSsl(Request $request)
{
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());
}
}
}