作者 李美松

更新代码

@@ -3,18 +3,9 @@ @@ -3,18 +3,9 @@
3 namespace App\Http\Controllers\Aside\Devops; 3 namespace App\Http\Controllers\Aside\Devops;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
6 -use App\Exceptions\AsideGlobalException;  
7 -use App\Exceptions\BsideGlobalException;  
8 use App\Http\Controllers\Aside\BaseController; 6 use App\Http\Controllers\Aside\BaseController;
9 -use App\Http\Logic\Aside\Devops\ServerInformationLogic;  
10 -use App\Http\Requests\Aside\Devops\ServerInformationRequest;  
11 -use App\Models\Devops\ServerInformation;  
12 use App\Models\Devops\ServerInformationLog; 7 use App\Models\Devops\ServerInformationLog;
13 -use Illuminate\Http\JsonResponse;  
14 use Illuminate\Http\Request; 8 use Illuminate\Http\Request;
15 -use Illuminate\Support\Facades\DB;  
16 -use Psr\Container\ContainerExceptionInterface;  
17 -use Psr\Container\NotFoundExceptionInterface;  
18 9
19 class ServerInformationLogController extends BaseController 10 class ServerInformationLogController extends BaseController
20 { 11 {
@@ -25,8 +25,6 @@ class ServerInformationLogic extends BaseLogic @@ -25,8 +25,6 @@ class ServerInformationLogic extends BaseLogic
25 { 25 {
26 parent::__construct(); 26 parent::__construct();
27 27
28 - $this->model = new ServerInformation();  
29 -  
30 $this->param = $this->requestAll; 28 $this->param = $this->requestAll;
31 29
32 } 30 }
@@ -41,23 +39,23 @@ class ServerInformationLogic extends BaseLogic @@ -41,23 +39,23 @@ class ServerInformationLogic extends BaseLogic
41 { 39 {
42 $request = $this->param ?? []; 40 $request = $this->param ?? [];
43 $service = new ServerInformation(); 41 $service = new ServerInformation();
44 - $this->extracted( $request, $service );  
45 - if ( $this->checkIp( $service->ip ) ) {  
46 - return $this->fail( '服务器信息添加失败,ip已存在' ); 42 + $this->extracted($request, $service);
  43 + if ($this->checkIp($request['ip'])) {
  44 + return $this->fail('服务器信息添加失败,ip已存在');
47 } 45 }
48 DB::beginTransaction(); 46 DB::beginTransaction();
49 47
50 - if ( $service->save() ) {  
51 - $original = $service->getOriginal();  
52 - $original['type'] = $request['type']; 48 + if ($service->save()) {
  49 + $original = $service->getOriginal();
  50 + $original['type'] = $request['type'];
53 $original['belong_to'] = $request['belong_to']; 51 $original['belong_to'] = $request['belong_to'];
54 // 添加日志 52 // 添加日志
55 - $this->server_action_log( ServerInformationLog::ACTION_ADD, $original, $original, '添加服务器信息成功 - ID : ' . $service->id ); 53 + $this->server_action_log(ServerInformationLog::ACTION_ADD, $original, $original, '添加服务器信息成功 - ID : ' . $service->id);
56 DB::commit(); 54 DB::commit();
57 return $this->success(); 55 return $this->success();
58 } 56 }
59 DB::rollBack(); 57 DB::rollBack();
60 - return $this->fail( '服务器信息添加失败' ); 58 + return $this->fail('服务器信息添加失败');
61 59
62 } 60 }
63 61
@@ -69,53 +67,53 @@ class ServerInformationLogic extends BaseLogic @@ -69,53 +67,53 @@ class ServerInformationLogic extends BaseLogic
69 */ 67 */
70 public function update() 68 public function update()
71 { 69 {
72 - $service = $this->getService();  
73 - $fields_array = $service->FieldsArray();  
74 - $request = $this->param ?? [];  
75 - $original = $service->getOriginal();  
76 - $original['type'] = $service->ServiceStr( $original['type'] );  
77 - $original['belong_to'] = $service->BelongToStr( $original['belong_to'] );  
78 - $this->extracted( $request, $service, $original ); 70 + $service = $this->getService();
  71 + $fields_array = $service->FieldsArray();
  72 + $request = $this->param ?? [];
  73 + $original = $service->getOriginal();
  74 + $original['type'] = $service->ServiceStr($original['type']);
  75 + $original['belong_to'] = $service->BelongToStr($original['belong_to']);
  76 + $this->extracted($request, $service, $original);
79 // 检查ip是否存在 77 // 检查ip是否存在
80 - if ( $service->ip != $request['ip'] ) {  
81 - if ( $this->checkIp( $request['ip'] ) ) {  
82 - $this->fail( '服务器信息修改失败,ip已存在', Code::USER_ERROR ); 78 + if ($service->ip != $request['ip']) {
  79 + if ($this->checkIp($request['ip'])) {
  80 + $this->fail('服务器信息修改失败,ip已存在', Code::USER_ERROR);
83 } 81 }
84 } 82 }
85 DB::beginTransaction(); 83 DB::beginTransaction();
86 - if ( $service->save() ) { 84 + if ($service->save()) {
87 $revised = $service->getAttributes(); 85 $revised = $service->getAttributes();
88 - $diff = array_diff_assoc( $original, $revised );  
89 - unset( $diff['created_at'] );  
90 - unset( $diff['updated_at'] );  
91 - unset( $diff['deleted'] ); 86 + $diff = array_diff_assoc($original, $revised);
  87 + unset($diff['created_at']);
  88 + unset($diff['updated_at']);
  89 + unset($diff['deleted']);
92 $remarks = ''; 90 $remarks = '';
93 - if ( $diff ) { 91 + if ($diff) {
94 $remarks .= '修改ID为 ' . $service->id . ' 的服务器信息,修改内容为:'; 92 $remarks .= '修改ID为 ' . $service->id . ' 的服务器信息,修改内容为:';
95 - foreach ( $diff as $key => $value ) { 93 + foreach ($diff as $key => $value) {
96 $remarks .= $fields_array[$key] . ' 由 ' . $value . ' 修改为 ' . $revised[$key] . '; '; 94 $remarks .= $fields_array[$key] . ' 由 ' . $value . ' 修改为 ' . $revised[$key] . '; ';
97 } 95 }
98 } else { 96 } else {
99 $remarks .= '修改ID为 ' . $service->id . ' 的服务器信息,无修改'; 97 $remarks .= '修改ID为 ' . $service->id . ' 的服务器信息,无修改';
100 } 98 }
101 // 添加日志 99 // 添加日志
102 - $this->server_action_log( ServerInformationLog::ACTION_UPDATE, $original, $revised, $remarks ); 100 + $this->server_action_log(ServerInformationLog::ACTION_UPDATE, $original, $revised, $remarks);
103 DB::commit(); 101 DB::commit();
104 return $this->success(); 102 return $this->success();
105 } 103 }
106 DB::rollBack(); 104 DB::rollBack();
107 - return $this->fail( '服务器信息修改失败' ); 105 + return $this->fail('服务器信息修改失败');
108 } 106 }
109 107
110 - public function getService( int $deleted = ServerInformation::DELETED_NORMAL ) 108 + public function getService(int $deleted = ServerInformation::DELETED_NORMAL)
111 { 109 {
112 $id = $this->param['id'] ?? 0; 110 $id = $this->param['id'] ?? 0;
113 - if ( !$id ) {  
114 - return $this->fail( 'ID不能为空' ); 111 + if (!$id) {
  112 + return $this->fail('ID不能为空');
115 } 113 }
116 - $data = ServerInformation::query()->where( 'deleted', $deleted )->find( $id );  
117 - if ( !$data ) {  
118 - return $this->fail( '数据不存在!' ); 114 + $data = ServerInformation::query()->where('deleted', $deleted)->find($id);
  115 + if (!$data) {
  116 + return $this->fail('数据不存在!');
119 } 117 }
120 return $data; 118 return $data;
121 } 119 }
@@ -125,10 +123,10 @@ class ServerInformationLogic extends BaseLogic @@ -125,10 +123,10 @@ class ServerInformationLogic extends BaseLogic
125 * @param $ip 123 * @param $ip
126 * @return bool 124 * @return bool
127 */ 125 */
128 - public function checkIp( $ip ) 126 + public function checkIp($ip)
129 { 127 {
130 - $usIp = ServerInformation::query()->where( 'ip', $ip )->first();  
131 - if ( $usIp ) { 128 + $usIp = ServerInformation::query()->where('ip', $ip)->first();
  129 + if ($usIp) {
132 return true; 130 return true;
133 } else { 131 } else {
134 return false; 132 return false;
@@ -142,15 +140,15 @@ class ServerInformationLogic extends BaseLogic @@ -142,15 +140,15 @@ class ServerInformationLogic extends BaseLogic
142 * @throws AsideGlobalException 140 * @throws AsideGlobalException
143 * @throws BsideGlobalException 141 * @throws BsideGlobalException
144 */ 142 */
145 - public function serverInfo( int $deleted = ServerInformation::DELETED_NORMAL ) 143 + public function serverInfo(int $deleted = ServerInformation::DELETED_NORMAL)
146 { 144 {
147 $id = $this->param['id'] ?? 0; 145 $id = $this->param['id'] ?? 0;
148 - if ( !$id ) {  
149 - return $this->fail( 'ID不能为空' ); 146 + if (!$id) {
  147 + return $this->fail('ID不能为空');
150 } 148 }
151 - $data = ServerInformation::query()->where( 'deleted', $deleted )->find( $id, [ 'type', 'ip', 'title', 'belong_to', 'ports', 'created_at', 'updated_at' ] );  
152 - if ( !$data ) {  
153 - return $this->fail( '数据不存在!' ); 149 + $data = ServerInformation::query()->where('deleted', $deleted)->find($id, ['type', 'ip', 'title', 'belong_to', 'ports', 'created_at', 'updated_at']);
  150 + if (!$data) {
  151 + return $this->fail('数据不存在!');
154 } 152 }
155 return $data; 153 return $data;
156 } 154 }
@@ -161,10 +159,10 @@ class ServerInformationLogic extends BaseLogic @@ -161,10 +159,10 @@ class ServerInformationLogic extends BaseLogic
161 * @param array $original 原始数据 159 * @param array $original 原始数据
162 * @param array $revised 修改后数据 160 * @param array $revised 修改后数据
163 */ 161 */
164 - public function server_action_log( int $action = ServerInformationLog::ACTION_ADD, array $original = [], array $revised = [], $remarks = '' ) 162 + public function server_action_log(int $action = ServerInformationLog::ACTION_ADD, array $original = [], array $revised = [], $remarks = '')
165 { 163 {
166 $log = new ServerInformationLog(); 164 $log = new ServerInformationLog();
167 - $this->log( $log, $action, $original, $revised, $remarks ); 165 + $this->log($log, $action, $original, $revised, $remarks);
168 } 166 }
169 167
170 /** 168 /**
@@ -172,14 +170,14 @@ class ServerInformationLogic extends BaseLogic @@ -172,14 +170,14 @@ class ServerInformationLogic extends BaseLogic
172 * @param $service 170 * @param $service
173 * @return void 171 * @return void
174 */ 172 */
175 - public function extracted( array $request, $service, array $original = [] ) 173 + public function extracted(array $request, $service, array $original = [])
176 { 174 {
177 - $service->type = trim( $request['type'] ) ?? $original['type']; // 服务器类型  
178 - $service->ip = trim( $request['ip'] ) ?? $original['ip']; // 服务器ip  
179 - $service->title = trim( $request['title'] ) ?? $original['title']; // 服务器标题  
180 - $service->belong_to = trim( $request['belong_to'] ) ?? $original['belong_to']; // 服务器归属  
181 - $service->sshpass = trim( $request['sshpass'] ) ?? $original['sshpass']; // ssh密码  
182 - $service->ports = trim( $request['ports'] ) ?? $original['ports']; // ssh端口 175 + $service->type = trim($request['type']) ?? $original['type']; // 服务器类型
  176 + $service->ip = trim($request['ip']) ?? $original['ip']; // 服务器ip
  177 + $service->title = trim($request['title']) ?? $original['title']; // 服务器标题
  178 + $service->belong_to = trim($request['belong_to']) ?? $original['belong_to']; // 服务器归属
  179 + $service->sshpass = trim($request['sshpass']) ?? $original['sshpass']; // ssh密码
  180 + $service->ports = trim($request['ports']) ?? $original['ports']; // ssh端口
183 } 181 }
184 182
185 /** 183 /**
@@ -188,27 +186,27 @@ class ServerInformationLogic extends BaseLogic @@ -188,27 +186,27 @@ class ServerInformationLogic extends BaseLogic
188 * @throws AsideGlobalException 186 * @throws AsideGlobalException
189 * @throws BsideGlobalException 187 * @throws BsideGlobalException
190 */ 188 */
191 - public function get_batch_update( $action = ServerInformationLog::ACTION_DELETE, $deleted = ServerInformation::DELETED_NORMAL ) 189 + public function get_batch_update($action = ServerInformationLog::ACTION_DELETE, $deleted = ServerInformation::DELETED_NORMAL)
192 { 190 {
193 - $ids = $this->getIds();  
194 - $data = ServerInformation::query()->whereIn( 'id', $ids )->where( 'deleted', $deleted )->get();  
195 - $restore_ids = $data->pluck( 'id' )->toArray();  
196 - $actionArr = ServerInformationLog::actionArr();  
197 - $actionStr = $actionArr[$action];  
198 - if ( empty( $restore_ids ) ) {  
199 - $this->fail( $actionStr . '服务器信息不存在!', Code::USER_ERROR ); 191 + $ids = $this->getIds();
  192 + $data = ServerInformation::query()->whereIn('id', $ids)->where('deleted', $deleted)->get();
  193 + $restore_ids = $data->pluck('id')->toArray();
  194 + $actionArr = ServerInformationLog::actionArr();
  195 + $actionStr = $actionArr[$action];
  196 + if (empty($restore_ids)) {
  197 + $this->fail($actionStr . '服务器信息不存在!', Code::USER_ERROR);
200 } 198 }
201 $original = $data->toArray(); 199 $original = $data->toArray();
202 DB::beginTransaction(); 200 DB::beginTransaction();
203 try { 201 try {
204 $update = $deleted == ServerInformation::DELETED_NORMAL ? ServerInformation::DELETED_DELETE : ServerInformation::DELETED_NORMAL; 202 $update = $deleted == ServerInformation::DELETED_NORMAL ? ServerInformation::DELETED_DELETE : ServerInformation::DELETED_NORMAL;
205 - ServerInformation::query()->whereIn( 'id', $restore_ids )->update( [ 'deleted' => $update ] );  
206 - $this->server_action_log( $action, $original, $original, $actionStr . '服务器信息 - ID : ' . implode( ', ', $restore_ids ) ); 203 + ServerInformation::query()->whereIn('id', $restore_ids)->update(['deleted' => $update]);
  204 + $this->server_action_log($action, $original, $original, $actionStr . '服务器信息 - ID : ' . implode(', ', $restore_ids));
207 DB::commit(); 205 DB::commit();
208 return $this->success(); 206 return $this->success();
209 - } catch ( \Exception $e ) { 207 + } catch (\Exception $e) {
210 DB::rollBack(); 208 DB::rollBack();
211 - return $this->fail( '服务器信息' . $actionStr . '失败', Code::USER_ERROR ); 209 + return $this->fail('服务器信息' . $actionStr . '失败', Code::USER_ERROR);
212 } 210 }
213 } 211 }
214 212
@@ -221,16 +219,16 @@ class ServerInformationLogic extends BaseLogic @@ -221,16 +219,16 @@ class ServerInformationLogic extends BaseLogic
221 public function getIds() 219 public function getIds()
222 { 220 {
223 $id = $this->param['id'] ?? 0; 221 $id = $this->param['id'] ?? 0;
224 - if ( !$id ) {  
225 - return $this->fail( '参数错误' ); 222 + if (!$id) {
  223 + return $this->fail('参数错误');
226 } 224 }
227 $ids = []; 225 $ids = [];
228 - if ( !is_array( $id ) ) {  
229 - $ids = explode( ',', $id ); 226 + if (!is_array($id)) {
  227 + $ids = explode(',', $id);
230 } 228 }
231 - $ids = array_filter( $ids, 'intval' );  
232 - if ( empty( $ids ) ) {  
233 - return $this->fail( '参数错误' ); 229 + $ids = array_filter($ids, 'intval');
  230 + if (empty($ids)) {
  231 + return $this->fail('参数错误');
234 } 232 }
235 return $ids; 233 return $ids;
236 } 234 }
@@ -49,9 +49,9 @@ class DomainInfoLogic extends BaseLogic @@ -49,9 +49,9 @@ class DomainInfoLogic extends BaseLogic
49 $this->extracted($request, $domain); 49 $this->extracted($request, $domain);
50 DB::beginTransaction(); 50 DB::beginTransaction();
51 if ($domain->save()) { 51 if ($domain->save()) {
52 - $original = $domain->getOriginal(); 52 + $original = $domain->getOriginal();
53 $original['belong_to'] = $request['belong_to']; 53 $original['belong_to'] = $request['belong_to'];
54 - $original['status'] = $request['status']; 54 + $original['status'] = $request['status'];
55 // 添加日志 55 // 添加日志
56 $this->domain_action_log(DomainInfoLog::ACTION_ADD, $original, $original, '添加域名信息成功 - ID : ' . $domain->id); 56 $this->domain_action_log(DomainInfoLog::ACTION_ADD, $original, $original, '添加域名信息成功 - ID : ' . $domain->id);
57 DB::commit(); 57 DB::commit();
@@ -70,11 +70,11 @@ class DomainInfoLogic extends BaseLogic @@ -70,11 +70,11 @@ class DomainInfoLogic extends BaseLogic
70 */ 70 */
71 public function update() 71 public function update()
72 { 72 {
73 - $domain = $this->getDomain();  
74 - $original = $domain->getOriginal(); 73 + $domain = $this->getDomain();
  74 + $original = $domain->getOriginal();
75 $original['belong_to'] = $domain->BelongToStr($original['belong_to']); 75 $original['belong_to'] = $domain->BelongToStr($original['belong_to']);
76 - $original['status'] = $domain->StatusToStr($original['status']);  
77 - $request = $this->param; 76 + $original['status'] = $domain->StatusToStr($original['status']);
  77 + $request = $this->param;
78 $this->extracted($request, $domain, $original); 78 $this->extracted($request, $domain, $original);
79 // 检查ip是否存在 79 // 检查ip是否存在
80 if ($domain->domain != $request['domain']) { 80 if ($domain->domain != $request['domain']) {
@@ -85,8 +85,8 @@ class DomainInfoLogic extends BaseLogic @@ -85,8 +85,8 @@ class DomainInfoLogic extends BaseLogic
85 DB::beginTransaction(); 85 DB::beginTransaction();
86 if ($domain->save()) { 86 if ($domain->save()) {
87 $fields_array = $domain->FieldsArray(); 87 $fields_array = $domain->FieldsArray();
88 - $revised = $domain->getAttributes();  
89 - $diff = array_diff_assoc($original, $revised); 88 + $revised = $domain->getAttributes();
  89 + $diff = array_diff_assoc($original, $revised);
90 unset($diff['created_at']); 90 unset($diff['created_at']);
91 unset($diff['updated_at']); 91 unset($diff['updated_at']);
92 unset($diff['deleted']); 92 unset($diff['deleted']);
@@ -182,18 +182,15 @@ class DomainInfoLogic extends BaseLogic @@ -182,18 +182,15 @@ class DomainInfoLogic extends BaseLogic
182 * @throws AsideGlobalException 182 * @throws AsideGlobalException
183 * @throws BsideGlobalException 183 * @throws BsideGlobalException
184 */ 184 */
185 - public function extracted( array $request, $domain, array $original = []) 185 + public function extracted(array $request, $domain, array $original = [])
186 { 186 {
187 - $domain->domain = trim($request['domain']) ?? $original['domain'];  
188 - if (!$this->validateDomain($domain->domain)) {  
189 - $this->fail('域名格式错误');  
190 - }  
191 - $domain->belong_to = trim($request['belong_to']) ?? $original['belong_to']; // 域名归属 1 - 公司 2 - 客户  
192 - $domain->status = trim($request['status']) ?? $original['status']; // 域名状态 0 - 正常 1 - 关闭  
193 - $domain->domain_start_time = trim($request['domain_start_time']) ?? $original['domain_start_time']; // 域名开始时间  
194 - $domain->domain_end_time = trim($request['domain_end_time']) ?? $original['domain_end_time']; 187 + $domain->domain = trim($request['domain']) ?? $original['domain'];
  188 + $domain->belong_to = trim($request['belong_to']) ?? $original['belong_to']; // 域名归属 1 - 公司 2 - 客户
  189 + $domain->status = trim($request['status']) ?? $original['status']; // 域名状态 0 - 正常 1 - 关闭
  190 + $domain->domain_start_time = trim($request['domain_start_time']) ?? $original['domain_start_time']; // 域名开始时间
  191 + $domain->domain_end_time = trim($request['domain_end_time']) ?? $original['domain_end_time'];
195 $domain->certificate_start_time = trim($request['certificate_start_time']) ?? $original['certificate_start_time']; // 证书开始时间 192 $domain->certificate_start_time = trim($request['certificate_start_time']) ?? $original['certificate_start_time']; // 证书开始时间
196 - $domain->certificate_end_time = trim($request['certificate_end_time']) ?? $original['certificate_end_time']; // 证书结束时间 193 + $domain->certificate_end_time = trim($request['certificate_end_time']) ?? $original['certificate_end_time']; // 证书结束时间
197 } 194 }
198 195
199 /** 196 /**
@@ -204,11 +201,11 @@ class DomainInfoLogic extends BaseLogic @@ -204,11 +201,11 @@ class DomainInfoLogic extends BaseLogic
204 */ 201 */
205 public function get_batch_update($action = DomainInfoLog::ACTION_DELETE, $deleted = DomainInfo::DELETED_NORMAL) 202 public function get_batch_update($action = DomainInfoLog::ACTION_DELETE, $deleted = DomainInfo::DELETED_NORMAL)
206 { 203 {
207 - $ids = (new ServerInformationLogic())->getIds();  
208 - $data = DomainInfo::query()->whereIn('id', $ids)->where('deleted', $deleted)->get(); 204 + $ids = (new ServerInformationLogic())->getIds();
  205 + $data = DomainInfo::query()->whereIn('id', $ids)->where('deleted', $deleted)->get();
209 $restore_ids = $data->pluck('id')->toArray(); 206 $restore_ids = $data->pluck('id')->toArray();
210 - $actionArr = DomainInfoLog::actionArr();  
211 - $actionStr = $actionArr[$action]; 207 + $actionArr = DomainInfoLog::actionArr();
  208 + $actionStr = $actionArr[$action];
212 if (empty($restore_ids)) { 209 if (empty($restore_ids)) {
213 $this->fail($actionStr . '域名信息不存在!', Code::USER_ERROR); 210 $this->fail($actionStr . '域名信息不存在!', Code::USER_ERROR);
214 } 211 }
@@ -232,18 +229,18 @@ class DomainInfoLogic extends BaseLogic @@ -232,18 +229,18 @@ class DomainInfoLogic extends BaseLogic
232 */ 229 */
233 public function getDomainCertificateTime($domain) 230 public function getDomainCertificateTime($domain)
234 { 231 {
235 - $domain = trim($domain);  
236 - $data = []; 232 + $domain = trim($domain);
  233 + $data = [];
237 $context = stream_context_create(['ssl' => ['capture_peer_cert' => true]]); // Notice: only 7.0.7+ supports this 234 $context = stream_context_create(['ssl' => ['capture_peer_cert' => true]]); // Notice: only 7.0.7+ supports this
238 - $stream = stream_socket_client("ssl://$domain:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context); 235 + $stream = stream_socket_client("ssl://$domain:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
239 if ($stream) { 236 if ($stream) {
240 - $params = stream_context_get_params($stream); 237 + $params = stream_context_get_params($stream);
241 $peerCertificate = openssl_x509_parse($params['options']['ssl']['peer_certificate']); 238 $peerCertificate = openssl_x509_parse($params['options']['ssl']['peer_certificate']);
242 if ($peerCertificate) { 239 if ($peerCertificate) {
243 - $validFrom = date_create_from_format('U', $peerCertificate['validFrom_time_t']); // 有效期开始时间  
244 - $validTo = date_create_from_format('U', $peerCertificate['validTo_time_t']); // 有效期结束时间 240 + $validFrom = date_create_from_format('U', $peerCertificate['validFrom_time_t']); // 有效期开始时间
  241 + $validTo = date_create_from_format('U', $peerCertificate['validTo_time_t']); // 有效期结束时间
245 $data['validFrom'] = $validFrom->format('Y-m-d H:i:s'); 242 $data['validFrom'] = $validFrom->format('Y-m-d H:i:s');
246 - $data['validTo'] = $validTo->format('Y-m-d H:i:s'); 243 + $data['validTo'] = $validTo->format('Y-m-d H:i:s');
247 } 244 }
248 } 245 }
249 return $data; 246 return $data;
@@ -256,9 +253,9 @@ class DomainInfoLogic extends BaseLogic @@ -256,9 +253,9 @@ class DomainInfoLogic extends BaseLogic
256 public function getAllDomain() 253 public function getAllDomain()
257 { 254 {
258 return DomainInfo::query()->where('status', 1) 255 return DomainInfo::query()->where('status', 1)
259 - ->where('deleted', DomainInfo::DELETED_NORMAL)  
260 - ->orderBy('updated_at', 'desc')  
261 - ->get(); 256 + ->where('deleted', DomainInfo::DELETED_NORMAL)
  257 + ->orderBy('updated_at', 'desc')
  258 + ->get();
262 } 259 }
263 260
264 /** 261 /**
@@ -268,48 +265,18 @@ class DomainInfoLogic extends BaseLogic @@ -268,48 +265,18 @@ class DomainInfoLogic extends BaseLogic
268 public function getDomainTime($domain) 265 public function getDomainTime($domain)
269 { 266 {
270 $conJson = file_get_contents("http://openai.waimaoq.com/v1/whois_api?domain={$domain}"); 267 $conJson = file_get_contents("http://openai.waimaoq.com/v1/whois_api?domain={$domain}");
271 - $conArr = json_decode($conJson, true);  
272 - $data = []; 268 + $conArr = json_decode($conJson, true);
  269 + $data = [];
273 if ($conArr['code'] == 200) { 270 if ($conArr['code'] == 200) {
274 - $con = $conArr['text'];  
275 - $data['domain'] = $domain; 271 + $con = $conArr['text'];
  272 + $data['domain'] = $domain;
276 $data['validFrom'] = $con['creation_date']; 273 $data['validFrom'] = $con['creation_date'];
277 - $data['validTo'] = $con['expiration_date']; 274 + $data['validTo'] = $con['expiration_date'];
278 } 275 }
279 return $data; 276 return $data;
280 } 277 }
281 278
282 /** 279 /**
283 - * 验证给定的值是否是有效的域名。  
284 - *  
285 - * @param mixed $value  
286 - * @return bool  
287 - */  
288 - public function validateDomain($value)  
289 - {  
290 - // 从域中删除任何空间或路径。  
291 - $domain = preg_replace('/\s|\/.*$/', '', $value);  
292 - // 验证域是否至少包含一个句点。  
293 - if (strpos($domain, '.') === false) {  
294 - return false;  
295 - }  
296 - // 验证域是否以句点开始或结束。  
297 - if (strpos($domain, '.') === 0 || strrpos($domain, '.') === strlen($domain) - 1) {  
298 - return false;  
299 - }  
300 - // 验证域是否不包含无效字符。  
301 - if (!preg_match('/^[a-zA-Z0-9\-\.]+$/', $domain)) {  
302 - return false;  
303 - }  
304 - // 验证域是否具有有效的顶级域。  
305 - $tld = substr($domain, strrpos($domain, '.') + 1);  
306 - if (!in_array($tld, ['com', 'net', 'org'])) { // 如有必要,添加更多TLD。  
307 - return false;  
308 - }  
309 - return true;  
310 - }  
311 -  
312 - /**  
313 * 根据域名更新证书到期时间 280 * 根据域名更新证书到期时间
314 * @param $id 281 * @param $id
315 * @param $updata 282 * @param $updata
@@ -4,6 +4,7 @@ namespace App\Http\Requests\Aside\Domain; @@ -4,6 +4,7 @@ namespace App\Http\Requests\Aside\Domain;
4 4
5 use App\Models\Aside\Domain\DomainInfo; 5 use App\Models\Aside\Domain\DomainInfo;
6 use Illuminate\Foundation\Http\FormRequest; 6 use Illuminate\Foundation\Http\FormRequest;
  7 +use Illuminate\Support\Facades\Validator;
7 use Illuminate\Validation\Rule; 8 use Illuminate\Validation\Rule;
8 9
9 class DomainInfoRequest extends FormRequest 10 class DomainInfoRequest extends FormRequest
@@ -25,11 +26,14 @@ class DomainInfoRequest extends FormRequest @@ -25,11 +26,14 @@ class DomainInfoRequest extends FormRequest
25 */ 26 */
26 public function rules() 27 public function rules()
27 { 28 {
28 - $domain = new DomainInfo(); 29 + Validator::extend('validate_domain', function ($attribute, $value, $parameters, $validator) {
  30 + return $this->validateDomain($value);
  31 + });
  32 + $domain = new DomainInfo();
29 $status_tot_keys = array_keys($domain->StatusToArray()); 33 $status_tot_keys = array_keys($domain->StatusToArray());
30 - $belong_to_keys = array_keys($domain->BelongToArray()); 34 + $belong_to_keys = array_keys($domain->BelongToArray());
31 return [ 35 return [
32 - 'domain' => 'required|max:200', 36 + 'domain' => 'required|max:200|validate_domain',
33 'belong_to' => [ 37 'belong_to' => [
34 'required', 38 'required',
35 Rule::in($belong_to_keys) 39 Rule::in($belong_to_keys)
@@ -41,15 +45,46 @@ class DomainInfoRequest extends FormRequest @@ -41,15 +45,46 @@ class DomainInfoRequest extends FormRequest
41 ]; 45 ];
42 } 46 }
43 47
  48 + /**
  49 + * 验证给定的值是否是有效的域名。
  50 + *
  51 + * @param mixed $value
  52 + * @return bool
  53 + */
  54 + public function validateDomain($value)
  55 + {
  56 + // 从域中删除任何空间或路径。
  57 + $domain = preg_replace('/\s|\/.*$/', '', $value);
  58 + // 验证域是否至少包含一个句点。
  59 + if (strpos($domain, '.') === false) {
  60 + return false;
  61 + }
  62 + // 验证域是否以句点开始或结束。
  63 + if (strpos($domain, '.') === 0 || strrpos($domain, '.') === strlen($domain) - 1) {
  64 + return false;
  65 + }
  66 + // 验证域是否不包含无效字符。
  67 + if (!preg_match('/^[a-zA-Z0-9\-\.]+$/', $domain)) {
  68 + return false;
  69 + }
  70 + // 验证域是否具有有效的顶级域。
  71 + $tld = substr($domain, strrpos($domain, '.') + 1);
  72 + if (!in_array($tld, ['com', 'net', 'org'])) { // 如有必要,添加更多TLD。
  73 + return false;
  74 + }
  75 + return true;
  76 + }
  77 +
44 public function messages() 78 public function messages()
45 { 79 {
46 return [ 80 return [
47 - 'domain.required' => '域名不能为空',  
48 - 'domain.max' => '域名长度不能超过200个字符',  
49 - 'belong_to.required' => '域名所属不能为空',  
50 - 'belong_to.in' => '域名所属参数错误',  
51 - 'status.required' => '域名状态不能为空',  
52 - 'status.in' => '域名状态参数错误', 81 + 'domain.required' => '域名不能为空',
  82 + 'domain.max' => '域名长度不能超过200个字符',
  83 + 'domain.validate_domain' => '域名格式不正确',
  84 + 'belong_to.required' => '域名所属不能为空',
  85 + 'belong_to.in' => '域名所属参数错误',
  86 + 'status.required' => '域名状态不能为空',
  87 + 'status.in' => '域名状态参数错误',
53 ]; 88 ];
54 } 89 }
55 90
@@ -2,9 +2,9 @@ @@ -2,9 +2,9 @@
2 2
3 namespace App\Models\Devops; 3 namespace App\Models\Devops;
4 4
5 -use Illuminate\Database\Eloquent\Model; 5 +use App\Models\Base;
6 6
7 -class ServerInformation extends Model 7 +class ServerInformation extends Base
8 { 8 {
9 9
10 protected $table = 'gl_server_information'; 10 protected $table = 'gl_server_information';
@@ -2,9 +2,9 @@ @@ -2,9 +2,9 @@
2 2
3 namespace App\Models\Devops; 3 namespace App\Models\Devops;
4 4
5 -use Illuminate\Database\Eloquent\Model; 5 +use App\Models\Base;
6 6
7 -class ServerInformationLog extends Model 7 +class ServerInformationLog extends Base
8 { 8 {
9 protected $table = 'gl_server_information_log'; 9 protected $table = 'gl_server_information_log';
10 10