合并分支 'akun' 到 'master'
Akun 查看合并请求 !730
正在显示
5 个修改的文件
包含
0 行增加
和
619 行删除
| 1 | -<?php | ||
| 2 | - | ||
| 3 | -namespace App\Console\Commands\Domain; | ||
| 4 | - | ||
| 5 | -use App\Models\Devops\Servers; | ||
| 6 | -use App\Models\Devops\ServersIp; | ||
| 7 | -use App\Models\Domain\DomainCreateTask; | ||
| 8 | -use App\Models\Domain\DomainInfo; | ||
| 9 | -use App\Models\Project\Project; | ||
| 10 | -use App\Utils\HttpUtils; | ||
| 11 | -use GuzzleHttp\Exception\GuzzleException; | ||
| 12 | -use Illuminate\Console\Command; | ||
| 13 | - | ||
| 14 | -class CreateSite extends Command | ||
| 15 | -{ | ||
| 16 | - /** | ||
| 17 | - * The name and signature of the console command. | ||
| 18 | - * | ||
| 19 | - * @var string | ||
| 20 | - */ | ||
| 21 | - protected $signature = 'create_domain_site'; | ||
| 22 | - | ||
| 23 | - /** | ||
| 24 | - * The console command description. | ||
| 25 | - * | ||
| 26 | - * @var string | ||
| 27 | - */ | ||
| 28 | - protected $description = '创建域名站点'; | ||
| 29 | - | ||
| 30 | - public function handle() | ||
| 31 | - { | ||
| 32 | - $model = new DomainCreateTask(); | ||
| 33 | - | ||
| 34 | - $task = $model->read(['status' => DomainCreateTask::STATUS_UN]); | ||
| 35 | - if ($task) { | ||
| 36 | - $model->edit(['status' => DomainCreateTask::STATUS_ING], ['id' => $task['id']]); | ||
| 37 | - | ||
| 38 | - $re = $this->editDomainBt($task['domain_id'], $task['type']); | ||
| 39 | - | ||
| 40 | - if (is_array($re)) { | ||
| 41 | - $model->edit(['status' => DomainCreateTask::STATUS_FAL, 'error_msg' => $re[1]], ['id' => $task['id']]); | ||
| 42 | - } else { | ||
| 43 | - $model->edit(['status' => DomainCreateTask::STATUS_SUC], ['id' => $task['id']]); | ||
| 44 | - } | ||
| 45 | - } | ||
| 46 | - } | ||
| 47 | - | ||
| 48 | - protected function editDomainBt($domain_id, $type) | ||
| 49 | - { | ||
| 50 | - //获取域名数据 | ||
| 51 | - $domain_model = new DomainInfo(); | ||
| 52 | - $domain_info = $domain_model->read(['id' => $domain_id]); | ||
| 53 | - if ($domain_info === false) { | ||
| 54 | - return [false, '获取域名数据失败']; | ||
| 55 | - } | ||
| 56 | - | ||
| 57 | - //获取项目数据 | ||
| 58 | - $project_model = new Project(); | ||
| 59 | - $project_info = $project_model->read(['id' => $domain_info['project_id']], 'serve_id'); | ||
| 60 | - if ($project_info === false) { | ||
| 61 | - return [false, '获取项目数据失败']; | ||
| 62 | - } | ||
| 63 | - | ||
| 64 | - //获取服务器数据 | ||
| 65 | - $serverIpModel = new ServersIp(); | ||
| 66 | - $serversIpInfo = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id']); | ||
| 67 | - if ($serversIpInfo === false) { | ||
| 68 | - return [false, '获取服务器数据失败1']; | ||
| 69 | - } | ||
| 70 | - $serverModel = new Servers(); | ||
| 71 | - $serverInfo = $serverModel->read(['id' => $serversIpInfo['servers_id']], ['init_domain']); | ||
| 72 | - if ($serverInfo === false) { | ||
| 73 | - return [false, '获取服务器数据失败2']; | ||
| 74 | - } | ||
| 75 | - | ||
| 76 | - if ($type == 1) { | ||
| 77 | - /*****************编辑主站*******************/ | ||
| 78 | - if ($domain_info['type'] == 2) { | ||
| 79 | - $api_url = 'http://' . $serverInfo['init_domain'] . '/api/setSsl'; | ||
| 80 | - $api_param = [ | ||
| 81 | - 'domain' => $domain_info['domain'], | ||
| 82 | - 'private_key' => $domain_info['private_key'], | ||
| 83 | - 'cert' => $domain_info['private_cert'], | ||
| 84 | - 'rewrite' => $domain_info['extend_config'], | ||
| 85 | - 'other_domain' => $domain_info['other_domain'], | ||
| 86 | - 'is_https' => $domain_info['is_https'], | ||
| 87 | - 'not_allow_country' => $domain_info['not_allow_country'], | ||
| 88 | - 'not_allow_ip' => $domain_info['not_allow_ip'], | ||
| 89 | - 'is_redirect' => $domain_info['is_redirect'] | ||
| 90 | - ]; | ||
| 91 | - } else { | ||
| 92 | - $api_url = 'http://' . $serverInfo['init_domain'] . '/api/applySsl'; | ||
| 93 | - $api_param = [ | ||
| 94 | - 'domain' => $domain_info['domain'], | ||
| 95 | - 'rewrite' => $domain_info['extend_config'], | ||
| 96 | - 'other_domain' => $domain_info['other_domain'], | ||
| 97 | - 'is_https' => $domain_info['is_https'], | ||
| 98 | - 'not_allow_country' => $domain_info['not_allow_country'], | ||
| 99 | - 'not_allow_ip' => $domain_info['not_allow_ip'], | ||
| 100 | - 'is_redirect' => $domain_info['is_redirect'] | ||
| 101 | - ]; | ||
| 102 | - } | ||
| 103 | - | ||
| 104 | - try { | ||
| 105 | - $rs = HttpUtils::get($api_url, $api_param, [], 180); | ||
| 106 | - $rs = json_decode($rs, true); | ||
| 107 | - if (isset($rs['status']) && $rs['status'] == 200) { | ||
| 108 | - $this->output($domain_info['domain'] . ',主站创建成功'); | ||
| 109 | - } else { | ||
| 110 | - return [false, $rs['message'] ?? '未知错误']; | ||
| 111 | - } | ||
| 112 | - } catch (\Exception | GuzzleException $e) { | ||
| 113 | - return [false, $e->getMessage()]; | ||
| 114 | - } | ||
| 115 | - } else { | ||
| 116 | - /*****************编辑amp站*******************/ | ||
| 117 | - if ($domain_info['amp_status']) { | ||
| 118 | - $api_url_amp = 'http://' . $serverInfo['init_domain'] . '/api/createSiteAmp'; | ||
| 119 | - $api_param_amp = [ | ||
| 120 | - 'domain' => $domain_info['domain'], | ||
| 121 | - 'not_allow_country' => $domain_info['not_allow_country'], | ||
| 122 | - 'not_allow_ip' => $domain_info['not_allow_ip'], | ||
| 123 | - 'is_redirect' => $domain_info['is_redirect'] | ||
| 124 | - ]; | ||
| 125 | - if ($domain_info['amp_type'] == 2) { | ||
| 126 | - $api_param_amp['private_key'] = $domain_info['amp_private_key']; | ||
| 127 | - $api_param_amp['cert'] = $domain_info['amp_private_cert']; | ||
| 128 | - } | ||
| 129 | - | ||
| 130 | - try { | ||
| 131 | - $rs_amp = HttpUtils::get($api_url_amp, $api_param_amp, [], 180); | ||
| 132 | - $rs_amp = json_decode($rs_amp, true); | ||
| 133 | - if (isset($rs_amp['status']) && $rs_amp['status'] == 200) { | ||
| 134 | - $this->output($domain_info['domain'] . ',amp站创建成功'); | ||
| 135 | - } else { | ||
| 136 | - return [false, $rs['message'] ?? '未知错误']; | ||
| 137 | - } | ||
| 138 | - } catch (\Exception | GuzzleException $e_amp) { | ||
| 139 | - return [false, $e_amp->getMessage()]; | ||
| 140 | - } | ||
| 141 | - } | ||
| 142 | - } | ||
| 143 | - | ||
| 144 | - return true; | ||
| 145 | - } | ||
| 146 | - | ||
| 147 | - /** | ||
| 148 | - * 输出处理日志 | ||
| 149 | - * @param $message | ||
| 150 | - */ | ||
| 151 | - public function output($message) | ||
| 152 | - { | ||
| 153 | - echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL; | ||
| 154 | - } | ||
| 155 | -} |
| @@ -4,21 +4,12 @@ namespace App\Http\Logic\Aside\Domain; | @@ -4,21 +4,12 @@ namespace App\Http\Logic\Aside\Domain; | ||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | use App\Http\Logic\Aside\BaseLogic; | 6 | use App\Http\Logic\Aside\BaseLogic; |
| 7 | -use App\Jobs\EditAmpDomainBt; | ||
| 8 | -use App\Jobs\EditCustomDomainBt; | ||
| 9 | -use App\Jobs\EditDomainBt; | ||
| 10 | use App\Models\Devops\ServerConfig; | 7 | use App\Models\Devops\ServerConfig; |
| 11 | -use App\Models\Devops\Servers; | ||
| 12 | use App\Models\Devops\ServersIp; | 8 | use App\Models\Devops\ServersIp; |
| 13 | use App\Models\Domain\DomainCreateTask; | 9 | use App\Models\Domain\DomainCreateTask; |
| 14 | use App\Models\Domain\DomainInfo; | 10 | use App\Models\Domain\DomainInfo; |
| 15 | use App\Models\Project\CountryCustom; | 11 | use App\Models\Project\CountryCustom; |
| 16 | -use App\Models\Project\DeployOptimize; | ||
| 17 | use App\Models\Project\Project; | 12 | use App\Models\Project\Project; |
| 18 | -use App\Utils\HttpUtils; | ||
| 19 | -use GuzzleHttp\Client; | ||
| 20 | -use GuzzleHttp\Exception\GuzzleException; | ||
| 21 | -use Illuminate\Support\Carbon; | ||
| 22 | use Symfony\Component\Process\Process; | 13 | use Symfony\Component\Process\Process; |
| 23 | 14 | ||
| 24 | class DomainInfoLogic extends BaseLogic | 15 | class DomainInfoLogic extends BaseLogic |
| @@ -152,98 +143,6 @@ class DomainInfoLogic extends BaseLogic | @@ -152,98 +143,6 @@ class DomainInfoLogic extends BaseLogic | ||
| 152 | } | 143 | } |
| 153 | 144 | ||
| 154 | /** | 145 | /** |
| 155 | - * 编辑网站证书 | ||
| 156 | - * @return array | ||
| 157 | - * @throws \App\Exceptions\AsideGlobalException | ||
| 158 | - * @throws \App\Exceptions\BsideGlobalException | ||
| 159 | - * @author Akun | ||
| 160 | - * @date 2023/10/17 11:52 | ||
| 161 | - */ | ||
| 162 | - public function setDomainSsl($initDomain,$domain,$rewrite,$other_domain,$is_https) | ||
| 163 | - { | ||
| 164 | - if($this->param['type'] == 2){ | ||
| 165 | - if(empty($this->param['key'])){ | ||
| 166 | - $this->fail('证书KEY值不能为空'); | ||
| 167 | - } | ||
| 168 | - if(empty($this->param['cert'])){ | ||
| 169 | - $this->fail('证书cert值不能为空'); | ||
| 170 | - } | ||
| 171 | - $api_url = 'http://'.$initDomain.'/api/setSsl'; | ||
| 172 | - $api_param = [ | ||
| 173 | - 'domain' => $domain, | ||
| 174 | - 'private_key' => $this->param['key'], | ||
| 175 | - 'cert' => $this->param['cert'], | ||
| 176 | - 'rewrite'=>$rewrite, | ||
| 177 | - 'other_domain'=>$other_domain, | ||
| 178 | - 'is_https' => $is_https | ||
| 179 | - ]; | ||
| 180 | - }else{ | ||
| 181 | - $api_url = 'http://'.$initDomain.'/api/applySsl'; | ||
| 182 | - $api_param = [ | ||
| 183 | - 'domain' => $domain, | ||
| 184 | - 'rewrite'=>$rewrite, | ||
| 185 | - 'other_domain'=>$other_domain, | ||
| 186 | - 'is_https' => $is_https | ||
| 187 | - ]; | ||
| 188 | - } | ||
| 189 | - try { | ||
| 190 | - $rs = HttpUtils::get($api_url, $api_param); | ||
| 191 | - $rs = json_decode($rs, true); | ||
| 192 | - if(isset($rs['status']) && $rs['status'] == 200){ | ||
| 193 | - return $this->success(); | ||
| 194 | - }else{ | ||
| 195 | - $this->fail($rs['message']??''); | ||
| 196 | - } | ||
| 197 | - } catch (\Exception | GuzzleException $e) { | ||
| 198 | - errorLog('创建站点', $api_param, $e); | ||
| 199 | - $this->fail('编辑证书失败'); | ||
| 200 | - } | ||
| 201 | - return $this->success(); | ||
| 202 | - } | ||
| 203 | - | ||
| 204 | - /** | ||
| 205 | - * 编辑amp网站证书 | ||
| 206 | - * @param $initDomain | ||
| 207 | - * @param $domain | ||
| 208 | - * @return array | ||
| 209 | - * @throws \App\Exceptions\AsideGlobalException | ||
| 210 | - * @throws \App\Exceptions\BsideGlobalException | ||
| 211 | - * @author Akun | ||
| 212 | - * @date 2024/02/22 14:58 | ||
| 213 | - */ | ||
| 214 | - public function setAmpDomainSsl($initDomain,$domain) | ||
| 215 | - { | ||
| 216 | - if($this->param['amp_type'] == 2){ | ||
| 217 | - if(empty($this->param['amp_key'])){ | ||
| 218 | - $this->fail('AMP站点证书KEY值不能为空'); | ||
| 219 | - } | ||
| 220 | - if(empty($this->param['amp_cert'])){ | ||
| 221 | - $this->fail('AMP站点证书cert值不能为空'); | ||
| 222 | - } | ||
| 223 | - } | ||
| 224 | - $api_url = 'http://'.$initDomain.'/api/createSiteAmp'; | ||
| 225 | - $api_param = [ | ||
| 226 | - 'domain' => $domain, | ||
| 227 | - 'private_key' => $this->param['amp_key']??'', | ||
| 228 | - 'cert' => $this->param['amp_cert']??'' | ||
| 229 | - ]; | ||
| 230 | - | ||
| 231 | - try { | ||
| 232 | - $rs = HttpUtils::get($api_url, $api_param); | ||
| 233 | - $rs = json_decode($rs, true); | ||
| 234 | - if(isset($rs['status']) && $rs['status'] == 200){ | ||
| 235 | - return $this->success(); | ||
| 236 | - }else{ | ||
| 237 | - $this->fail($rs['message']??''); | ||
| 238 | - } | ||
| 239 | - } catch (\Exception | GuzzleException $e) { | ||
| 240 | - errorLog('创建AMP站点', $api_param, $e); | ||
| 241 | - $this->fail('编辑AMP站点证书失败'); | ||
| 242 | - } | ||
| 243 | - return $this->success(); | ||
| 244 | - } | ||
| 245 | - | ||
| 246 | - /** | ||
| 247 | * @remark :保存证书相关配置 | 146 | * @remark :保存证书相关配置 |
| 248 | * @name :sslSave | 147 | * @name :sslSave |
| 249 | * @author :lyh | 148 | * @author :lyh |
| @@ -340,12 +239,6 @@ class DomainInfoLogic extends BaseLogic | @@ -340,12 +239,6 @@ class DomainInfoLogic extends BaseLogic | ||
| 340 | } | 239 | } |
| 341 | } | 240 | } |
| 342 | 241 | ||
| 343 | -// //主站生成证书 | ||
| 344 | -// EditDomainBt::dispatch($this->param['id']); | ||
| 345 | -// //amp站生成证书 | ||
| 346 | -// if($data['amp_status']){ | ||
| 347 | -// EditAmpDomainBt::dispatch($this->param['id']); | ||
| 348 | -// } | ||
| 349 | return $this->success(); | 242 | return $this->success(); |
| 350 | } | 243 | } |
| 351 | 244 | ||
| @@ -460,9 +353,6 @@ class DomainInfoLogic extends BaseLogic | @@ -460,9 +353,6 @@ class DomainInfoLogic extends BaseLogic | ||
| 460 | 'type' => DomainCreateTask::TYPE_CUSTOM | 353 | 'type' => DomainCreateTask::TYPE_CUSTOM |
| 461 | ]); | 354 | ]); |
| 462 | } | 355 | } |
| 463 | - | ||
| 464 | -// //创建站点,设置证书 | ||
| 465 | -// EditCustomDomainBt::dispatch($id); | ||
| 466 | } | 356 | } |
| 467 | 357 | ||
| 468 | return $this->success(); | 358 | return $this->success(); |
app/Jobs/EditAmpDomainBt.php
已删除
100644 → 0
| 1 | -<?php | ||
| 2 | - | ||
| 3 | -namespace App\Jobs; | ||
| 4 | - | ||
| 5 | -use App\Models\Devops\ServerConfig; | ||
| 6 | -use App\Models\Devops\Servers; | ||
| 7 | -use App\Models\Devops\ServersIp; | ||
| 8 | -use App\Models\Domain\DomainInfo; | ||
| 9 | -use App\Models\Project\Project; | ||
| 10 | -use App\Utils\HttpUtils; | ||
| 11 | -use GuzzleHttp\Exception\GuzzleException; | ||
| 12 | -use Illuminate\Bus\Queueable; | ||
| 13 | -use Illuminate\Contracts\Queue\ShouldQueue; | ||
| 14 | -use Illuminate\Foundation\Bus\Dispatchable; | ||
| 15 | -use Illuminate\Queue\InteractsWithQueue; | ||
| 16 | -use Illuminate\Queue\SerializesModels; | ||
| 17 | - | ||
| 18 | -class EditAmpDomainBt implements ShouldQueue | ||
| 19 | -{ | ||
| 20 | - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
| 21 | - | ||
| 22 | - public $tries = 1; // 可配置任务重试次数 | ||
| 23 | - | ||
| 24 | - protected $domain_id; | ||
| 25 | - | ||
| 26 | - /** | ||
| 27 | - * Create a new job instance. | ||
| 28 | - * | ||
| 29 | - * @param $domain_id | ||
| 30 | - */ | ||
| 31 | - public function __construct($domain_id) | ||
| 32 | - { | ||
| 33 | - $this->domain_id = $domain_id; | ||
| 34 | - } | ||
| 35 | - | ||
| 36 | - /** | ||
| 37 | - * Execute the job. | ||
| 38 | - * | ||
| 39 | - * @return bool | ||
| 40 | - */ | ||
| 41 | - public function handle() | ||
| 42 | - { | ||
| 43 | - //获取域名数据 | ||
| 44 | - $domain_model = new DomainInfo(); | ||
| 45 | - $domain_info = $domain_model->read(['id' => $this->domain_id]); | ||
| 46 | - if ($domain_info === false) { | ||
| 47 | - return $this->output($domain_info['domain'] . ':获取域名数据失败'); | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - //获取项目数据 | ||
| 51 | - $project_model = new Project(); | ||
| 52 | - $project_info = $project_model->read(['id' => $domain_info['project_id']], 'serve_id'); | ||
| 53 | - if ($project_info === false) { | ||
| 54 | - return $this->output($domain_info['domain'] . ':获取项目数据失败'); | ||
| 55 | - } | ||
| 56 | - | ||
| 57 | - //获取服务器数据 | ||
| 58 | - $serverIpModel = new ServersIp(); | ||
| 59 | - $serversIpInfo = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id']); | ||
| 60 | - if ($serversIpInfo === false) { | ||
| 61 | - return $this->output($domain_info['domain'] . ':获取服务器数据失败'); | ||
| 62 | - } | ||
| 63 | - $serverModel = new Servers(); | ||
| 64 | - $serverInfo = $serverModel->read(['id' => $serversIpInfo['servers_id']], ['init_domain']); | ||
| 65 | - if ($serverInfo === false) { | ||
| 66 | - return $this->output($domain_info['domain'] . ':获取服务器数据失败'); | ||
| 67 | - } | ||
| 68 | - | ||
| 69 | - //编辑amp站 | ||
| 70 | - $api_url_amp = 'http://' . $serverInfo['init_domain'] . '/api/createSiteAmp'; | ||
| 71 | - $api_param_amp = [ | ||
| 72 | - 'domain' => $domain_info['domain'], | ||
| 73 | - 'not_allow_country' => $domain_info['not_allow_country'], | ||
| 74 | - 'not_allow_ip' => $domain_info['not_allow_ip'], | ||
| 75 | - 'is_redirect' => $domain_info['is_redirect'] | ||
| 76 | - ]; | ||
| 77 | - if ($domain_info['amp_type'] == 2) { | ||
| 78 | - $api_param_amp['private_key'] = $domain_info['amp_private_key']; | ||
| 79 | - $api_param_amp['cert'] = $domain_info['amp_private_cert']; | ||
| 80 | - } | ||
| 81 | - | ||
| 82 | - try { | ||
| 83 | - $rs_amp = HttpUtils::get($api_url_amp, $api_param_amp); | ||
| 84 | - $rs_amp = json_decode($rs_amp, true); | ||
| 85 | - if (isset($rs_amp['status']) && $rs_amp['status'] == 200) { | ||
| 86 | - $this->output($domain_info['domain'] . ':amp站编辑成功'); | ||
| 87 | - } else { | ||
| 88 | - $this->output($domain_info['domain'] . ':amp站编辑失败,原因:' . ($rs_amp['message'] ?? '')); | ||
| 89 | - } | ||
| 90 | - } catch (\Exception | GuzzleException $e_amp) { | ||
| 91 | - $this->output($domain_info['domain'] . ':amp站编辑失败,原因:' . $e_amp->getMessage()); | ||
| 92 | - } | ||
| 93 | - | ||
| 94 | - return true; | ||
| 95 | - } | ||
| 96 | - | ||
| 97 | - /** | ||
| 98 | - * 输出处理日志 | ||
| 99 | - * @param $message | ||
| 100 | - * @return bool | ||
| 101 | - */ | ||
| 102 | - public function output($message) | ||
| 103 | - { | ||
| 104 | - echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL; | ||
| 105 | - return true; | ||
| 106 | - } | ||
| 107 | - | ||
| 108 | - public function failed(\Exception $exception) | ||
| 109 | - { | ||
| 110 | - return $this->output($exception->getMessage()); | ||
| 111 | - } | ||
| 112 | -} |
app/Jobs/EditCustomDomainBt.php
已删除
100644 → 0
| 1 | -<?php | ||
| 2 | - | ||
| 3 | -namespace App\Jobs; | ||
| 4 | - | ||
| 5 | -use App\Models\Devops\ServerConfig; | ||
| 6 | -use App\Models\Devops\Servers; | ||
| 7 | -use App\Models\Devops\ServersIp; | ||
| 8 | -use App\Models\Project\CountryCustom; | ||
| 9 | -use App\Models\Project\Project; | ||
| 10 | -use App\Utils\HttpUtils; | ||
| 11 | -use GuzzleHttp\Exception\GuzzleException; | ||
| 12 | -use Illuminate\Bus\Queueable; | ||
| 13 | -use Illuminate\Contracts\Queue\ShouldQueue; | ||
| 14 | -use Illuminate\Foundation\Bus\Dispatchable; | ||
| 15 | -use Illuminate\Queue\InteractsWithQueue; | ||
| 16 | -use Illuminate\Queue\SerializesModels; | ||
| 17 | - | ||
| 18 | -class EditCustomDomainBt implements ShouldQueue | ||
| 19 | -{ | ||
| 20 | - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
| 21 | - | ||
| 22 | - public $tries = 1; // 可配置任务重试次数 | ||
| 23 | - | ||
| 24 | - protected $domain_id; | ||
| 25 | - | ||
| 26 | - /** | ||
| 27 | - * Create a new job instance. | ||
| 28 | - * | ||
| 29 | - * @param $domain_id | ||
| 30 | - */ | ||
| 31 | - public function __construct($domain_id) | ||
| 32 | - { | ||
| 33 | - $this->domain_id = $domain_id; | ||
| 34 | - } | ||
| 35 | - | ||
| 36 | - /** | ||
| 37 | - * Execute the job. | ||
| 38 | - * | ||
| 39 | - * @return bool | ||
| 40 | - */ | ||
| 41 | - public function handle() | ||
| 42 | - { | ||
| 43 | - //获取域名数据 | ||
| 44 | - $domain_model = new CountryCustom(); | ||
| 45 | - $domain_info = $domain_model->read(['id' => $this->domain_id]); | ||
| 46 | - if ($domain_info === false) { | ||
| 47 | - return $this->output($domain_info['custom_domain'] . ':获取域名数据失败'); | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - //获取项目数据 | ||
| 51 | - $project_model = new Project(); | ||
| 52 | - $project_info = $project_model->read(['id' => $domain_info['project_id']], 'serve_id'); | ||
| 53 | - if ($project_info === false) { | ||
| 54 | - return $this->output($domain_info['custom_domain'] . ':获取项目数据失败'); | ||
| 55 | - } | ||
| 56 | - | ||
| 57 | - //获取服务器数据 | ||
| 58 | - $serverIpModel = new ServersIp(); | ||
| 59 | - $serversIpInfo = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id']); | ||
| 60 | - if ($serversIpInfo === false) { | ||
| 61 | - return $this->output($domain_info['custom_domain'] . ':获取服务器数据失败'); | ||
| 62 | - } | ||
| 63 | - $serverModel = new Servers(); | ||
| 64 | - $serverInfo = $serverModel->read(['id' => $serversIpInfo['servers_id']], ['init_domain']); | ||
| 65 | - | ||
| 66 | - //编辑站点 | ||
| 67 | - if ($domain_info['type'] == 2) { | ||
| 68 | - $api_url = 'http://' . $serverInfo['init_domain'] . '/api/setSsl'; | ||
| 69 | - $api_param = [ | ||
| 70 | - 'domain' => $domain_info['custom_domain'], | ||
| 71 | - 'private_key' => $domain_info['private_key'], | ||
| 72 | - 'cert' => $domain_info['private_cert'], | ||
| 73 | - 'rewrite' => [], | ||
| 74 | - 'other_domain' => [], | ||
| 75 | - 'is_https' => 1 | ||
| 76 | - ]; | ||
| 77 | - } else { | ||
| 78 | - $api_url = 'http://' . $serverInfo['init_domain'] . '/api/applySsl'; | ||
| 79 | - $api_param = [ | ||
| 80 | - 'domain' => $domain_info['custom_domain'], | ||
| 81 | - 'rewrite' => [], | ||
| 82 | - 'other_domain' => [], | ||
| 83 | - 'is_https' => 1 | ||
| 84 | - ]; | ||
| 85 | - } | ||
| 86 | - try { | ||
| 87 | - $rs = HttpUtils::get($api_url, $api_param); | ||
| 88 | - $rs = json_decode($rs, true); | ||
| 89 | - if (isset($rs['status']) && $rs['status'] == 200) { | ||
| 90 | - $this->output($domain_info['custom_domain'] . ':站点编辑成功'); | ||
| 91 | - } else { | ||
| 92 | - $this->output($domain_info['custom_domain'] . ':站点编辑失败,原因:' . ($rs['message'] ?? '')); | ||
| 93 | - } | ||
| 94 | - } catch (\Exception | GuzzleException $e) { | ||
| 95 | - $this->output($domain_info['custom_domain'] . ':站点编辑失败,原因:' . $e->getMessage()); | ||
| 96 | - } | ||
| 97 | - | ||
| 98 | - return true; | ||
| 99 | - } | ||
| 100 | - | ||
| 101 | - /** | ||
| 102 | - * 输出处理日志 | ||
| 103 | - * @param $message | ||
| 104 | - * @return bool | ||
| 105 | - */ | ||
| 106 | - public function output($message) | ||
| 107 | - { | ||
| 108 | - echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL; | ||
| 109 | - return true; | ||
| 110 | - } | ||
| 111 | - | ||
| 112 | - public function failed(\Exception $exception) | ||
| 113 | - { | ||
| 114 | - return $this->output($exception->getMessage()); | ||
| 115 | - } | ||
| 116 | -} |
app/Jobs/EditDomainBt.php
已删除
100644 → 0
| 1 | -<?php | ||
| 2 | - | ||
| 3 | -namespace App\Jobs; | ||
| 4 | - | ||
| 5 | -use App\Models\Devops\ServerConfig; | ||
| 6 | -use App\Models\Devops\Servers; | ||
| 7 | -use App\Models\Devops\ServersIp; | ||
| 8 | -use App\Models\Domain\DomainInfo; | ||
| 9 | -use App\Models\Project\Project; | ||
| 10 | -use App\Utils\HttpUtils; | ||
| 11 | -use GuzzleHttp\Exception\GuzzleException; | ||
| 12 | -use Illuminate\Bus\Queueable; | ||
| 13 | -use Illuminate\Contracts\Queue\ShouldQueue; | ||
| 14 | -use Illuminate\Foundation\Bus\Dispatchable; | ||
| 15 | -use Illuminate\Queue\InteractsWithQueue; | ||
| 16 | -use Illuminate\Queue\SerializesModels; | ||
| 17 | - | ||
| 18 | -class EditDomainBt implements ShouldQueue | ||
| 19 | -{ | ||
| 20 | - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
| 21 | - | ||
| 22 | - public $tries = 1; // 可配置任务重试次数 | ||
| 23 | - | ||
| 24 | - protected $domain_id; | ||
| 25 | - | ||
| 26 | - /** | ||
| 27 | - * Create a new job instance. | ||
| 28 | - * | ||
| 29 | - * @param $domain_id | ||
| 30 | - */ | ||
| 31 | - public function __construct($domain_id) | ||
| 32 | - { | ||
| 33 | - $this->domain_id = $domain_id; | ||
| 34 | - } | ||
| 35 | - | ||
| 36 | - /** | ||
| 37 | - * Execute the job. | ||
| 38 | - * | ||
| 39 | - * @return bool | ||
| 40 | - */ | ||
| 41 | - public function handle() | ||
| 42 | - { | ||
| 43 | - //获取域名数据 | ||
| 44 | - $domain_model = new DomainInfo(); | ||
| 45 | - $domain_info = $domain_model->read(['id' => $this->domain_id]); | ||
| 46 | - if ($domain_info === false) { | ||
| 47 | - return $this->output($domain_info['domain'] . ':获取域名数据失败'); | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - //获取项目数据 | ||
| 51 | - $project_model = new Project(); | ||
| 52 | - $project_info = $project_model->read(['id' => $domain_info['project_id']], 'serve_id'); | ||
| 53 | - if ($project_info === false) { | ||
| 54 | - return $this->output($domain_info['domain'] . ':获取项目数据失败'); | ||
| 55 | - } | ||
| 56 | - | ||
| 57 | - //获取服务器数据 | ||
| 58 | - $serverIpModel = new ServersIp(); | ||
| 59 | - $serversIpInfo = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id']); | ||
| 60 | - if ($serversIpInfo === false) { | ||
| 61 | - return $this->output($domain_info['domain'] . ':获取服务器数据失败'); | ||
| 62 | - } | ||
| 63 | - $serverModel = new Servers(); | ||
| 64 | - $serverInfo = $serverModel->read(['id' => $serversIpInfo['servers_id']], ['init_domain']); | ||
| 65 | - if ($serverInfo === false) { | ||
| 66 | - return $this->output($domain_info['domain'] . ':获取服务器数据失败'); | ||
| 67 | - } | ||
| 68 | - | ||
| 69 | - //编辑主站 | ||
| 70 | - if ($domain_info['type'] == 2) { | ||
| 71 | - $api_url = 'http://' . $serverInfo['init_domain'] . '/api/setSsl'; | ||
| 72 | - $api_param = [ | ||
| 73 | - 'domain' => $domain_info['domain'], | ||
| 74 | - 'private_key' => $domain_info['private_key'], | ||
| 75 | - 'cert' => $domain_info['private_cert'], | ||
| 76 | - 'rewrite' => $domain_info['extend_config'], | ||
| 77 | - 'other_domain' => $domain_info['other_domain'], | ||
| 78 | - 'is_https' => $domain_info['is_https'], | ||
| 79 | - 'not_allow_country' => $domain_info['not_allow_country'], | ||
| 80 | - 'not_allow_ip' => $domain_info['not_allow_ip'], | ||
| 81 | - 'is_redirect' => $domain_info['is_redirect'] | ||
| 82 | - ]; | ||
| 83 | - } else { | ||
| 84 | - $api_url = 'http://' . $serverInfo['init_domain'] . '/api/applySsl'; | ||
| 85 | - $api_param = [ | ||
| 86 | - 'domain' => $domain_info['domain'], | ||
| 87 | - 'rewrite' => $domain_info['extend_config'], | ||
| 88 | - 'other_domain' => $domain_info['other_domain'], | ||
| 89 | - 'is_https' => $domain_info['is_https'], | ||
| 90 | - 'not_allow_country' => $domain_info['not_allow_country'], | ||
| 91 | - 'not_allow_ip' => $domain_info['not_allow_ip'], | ||
| 92 | - 'is_redirect' => $domain_info['is_redirect'] | ||
| 93 | - ]; | ||
| 94 | - } | ||
| 95 | - | ||
| 96 | - try { | ||
| 97 | - $rs = HttpUtils::get($api_url, $api_param); | ||
| 98 | - $rs = json_decode($rs, true); | ||
| 99 | - if (isset($rs['status']) && $rs['status'] == 200) { | ||
| 100 | - $this->output($domain_info['domain'] . ':主站编辑成功'); | ||
| 101 | - } else { | ||
| 102 | - $this->output($domain_info['domain'] . ':主站编辑失败,原因:' . ($rs['message'] ?? '')); | ||
| 103 | - } | ||
| 104 | - } catch (\Exception | GuzzleException $e) { | ||
| 105 | - $this->output($domain_info['domain'] . ':主站编辑失败,原因:' . $e->getMessage()); | ||
| 106 | - } | ||
| 107 | - | ||
| 108 | - return true; | ||
| 109 | - } | ||
| 110 | - | ||
| 111 | - /** | ||
| 112 | - * 输出处理日志 | ||
| 113 | - * @param $message | ||
| 114 | - * @return bool | ||
| 115 | - */ | ||
| 116 | - public function output($message) | ||
| 117 | - { | ||
| 118 | - echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL; | ||
| 119 | - return true; | ||
| 120 | - } | ||
| 121 | - | ||
| 122 | - public function failed(\Exception $exception) | ||
| 123 | - { | ||
| 124 | - return $this->output($exception->getMessage()); | ||
| 125 | - } | ||
| 126 | -} |
-
请 注册 或 登录 后发表评论