合并分支 'akun' 到 'master'
Akun 查看合并请求 !563
正在显示
6 个修改的文件
包含
85 行增加
和
13 行删除
| @@ -9,7 +9,9 @@ | @@ -9,7 +9,9 @@ | ||
| 9 | 9 | ||
| 10 | namespace App\Console\Commands\Domain; | 10 | namespace App\Console\Commands\Domain; |
| 11 | 11 | ||
| 12 | +use App\Models\Devops\ServerConfig; | ||
| 12 | use App\Models\Project\CountryCustom; | 13 | use App\Models\Project\CountryCustom; |
| 14 | +use App\Models\Project\Project; | ||
| 13 | use Illuminate\Console\Command; | 15 | use Illuminate\Console\Command; |
| 14 | use App\Models\Domain\DomainInfo as DomainInfoModel; | 16 | use App\Models\Domain\DomainInfo as DomainInfoModel; |
| 15 | 17 | ||
| @@ -83,6 +85,7 @@ class DomainInfo extends Command | @@ -83,6 +85,7 @@ class DomainInfo extends Command | ||
| 83 | public function startUpdateCert() | 85 | public function startUpdateCert() |
| 84 | { | 86 | { |
| 85 | $domainModel = new DomainInfoModel(); | 87 | $domainModel = new DomainInfoModel(); |
| 88 | + $projectModel = new Project(); | ||
| 86 | $end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期 | 89 | $end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期 |
| 87 | $list = $domainModel->where('status', '!=', 2)->where(function ($query) use ($end_day) { | 90 | $list = $domainModel->where('status', '!=', 2)->where(function ($query) use ($end_day) { |
| 88 | $query->whereNull('certificate_end_time')->orWhere('certificate_end_time', '<', $end_day); | 91 | $query->whereNull('certificate_end_time')->orWhere('certificate_end_time', '<', $end_day); |
| @@ -95,8 +98,9 @@ class DomainInfo extends Command | @@ -95,8 +98,9 @@ class DomainInfo extends Command | ||
| 95 | $ssl['from'] && $data['certificate_start_time'] = $ssl['from']; | 98 | $ssl['from'] && $data['certificate_start_time'] = $ssl['from']; |
| 96 | $ssl['to'] && $data['certificate_end_time'] = $ssl['to']; | 99 | $ssl['to'] && $data['certificate_end_time'] = $ssl['to']; |
| 97 | 100 | ||
| 98 | - if ($v['type'] == 1 && $ssl['to'] < $end_day) { | ||
| 99 | - //申请免费证书 | 101 | + $project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']); |
| 102 | + if ($v['type'] == 1 && $ssl['to'] < $end_day && $project_info['serve_id'] != ServerConfig::SELF_SITE_ID) { | ||
| 103 | + //非自建站项目,申请免费证书 | ||
| 100 | $this->updatePrivate($v); | 104 | $this->updatePrivate($v); |
| 101 | 105 | ||
| 102 | $ssl_new = $this->updateDomainSsl($v['domain']); | 106 | $ssl_new = $this->updateDomainSsl($v['domain']); |
| @@ -116,6 +120,7 @@ class DomainInfo extends Command | @@ -116,6 +120,7 @@ class DomainInfo extends Command | ||
| 116 | public function startUpdateAmpCert() | 120 | public function startUpdateAmpCert() |
| 117 | { | 121 | { |
| 118 | $domainModel = new DomainInfoModel(); | 122 | $domainModel = new DomainInfoModel(); |
| 123 | + $projectModel = new Project(); | ||
| 119 | $end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期 | 124 | $end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期 |
| 120 | $list = $domainModel->where('status', '!=', 2)->where('amp_status', 1)->where(function ($query) use ($end_day) { | 125 | $list = $domainModel->where('status', '!=', 2)->where('amp_status', 1)->where(function ($query) use ($end_day) { |
| 121 | $query->whereNull('amp_certificate_end_time')->orWhere('amp_certificate_end_time', '<', $end_day); | 126 | $query->whereNull('amp_certificate_end_time')->orWhere('amp_certificate_end_time', '<', $end_day); |
| @@ -137,8 +142,9 @@ class DomainInfo extends Command | @@ -137,8 +142,9 @@ class DomainInfo extends Command | ||
| 137 | $ssl['from'] && $data['amp_certificate_start_time'] = $ssl['from']; | 142 | $ssl['from'] && $data['amp_certificate_start_time'] = $ssl['from']; |
| 138 | $ssl['to'] && $data['amp_certificate_end_time'] = $ssl['to']; | 143 | $ssl['to'] && $data['amp_certificate_end_time'] = $ssl['to']; |
| 139 | 144 | ||
| 140 | - if ($v['amp_type'] == 1 && $ssl['to'] < $end_day) { | ||
| 141 | - //申请免费证书 | 145 | + $project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']); |
| 146 | + if ($v['amp_type'] == 1 && $ssl['to'] < $end_day && $project_info['serve_id'] != ServerConfig::SELF_SITE_ID) { | ||
| 147 | + //非自建站项目,申请免费证书 | ||
| 142 | $this->updateAmpPrivate($v['domain']); | 148 | $this->updateAmpPrivate($v['domain']); |
| 143 | 149 | ||
| 144 | $ssl_new = $this->updateDomainSsl($v['domain']); | 150 | $ssl_new = $this->updateDomainSsl($v['domain']); |
| @@ -283,9 +289,9 @@ class DomainInfo extends Command | @@ -283,9 +289,9 @@ class DomainInfo extends Command | ||
| 283 | ], | 289 | ], |
| 284 | ]); | 290 | ]); |
| 285 | $stream = stream_socket_client('ssl://' . $domain . ':443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context); | 291 | $stream = stream_socket_client('ssl://' . $domain . ':443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context); |
| 286 | - if($stream){ | 292 | + if ($stream) { |
| 287 | $remote_cert = stream_context_get_params($stream)['options']['ssl']['peer_certificate']; | 293 | $remote_cert = stream_context_get_params($stream)['options']['ssl']['peer_certificate']; |
| 288 | - if($remote_cert){ | 294 | + if ($remote_cert) { |
| 289 | $valid_from = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validFrom_time_t']); | 295 | $valid_from = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validFrom_time_t']); |
| 290 | $valid_to = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validTo_time_t']); | 296 | $valid_to = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validTo_time_t']); |
| 291 | } | 297 | } |
| @@ -10,9 +10,13 @@ | @@ -10,9 +10,13 @@ | ||
| 10 | namespace App\Http\Controllers\Bside\BCom; | 10 | namespace App\Http\Controllers\Bside\BCom; |
| 11 | 11 | ||
| 12 | use App\Enums\Common\Code; | 12 | use App\Enums\Common\Code; |
| 13 | +use App\Helper\Arr; | ||
| 13 | use App\Http\Controllers\Bside\BaseController; | 14 | use App\Http\Controllers\Bside\BaseController; |
| 15 | +use App\Models\Com\Notify; | ||
| 14 | use App\Models\Com\UpdateNotify; | 16 | use App\Models\Com\UpdateNotify; |
| 15 | use App\Models\Com\UpdateProgress; | 17 | use App\Models\Com\UpdateProgress; |
| 18 | +use App\Models\Devops\ServerConfig; | ||
| 19 | +use App\Models\Domain\DomainInfo; | ||
| 16 | use App\Models\Project\Country as CountryModel; | 20 | use App\Models\Project\Country as CountryModel; |
| 17 | use App\Models\Project\Project; | 21 | use App\Models\Project\Project; |
| 18 | use App\Models\RouteMap\RouteMap; | 22 | use App\Models\RouteMap\RouteMap; |
| @@ -37,15 +41,66 @@ class CNoticeController extends BaseController | @@ -37,15 +41,66 @@ class CNoticeController extends BaseController | ||
| 37 | */ | 41 | */ |
| 38 | public function sendNotify(Request $request) | 42 | public function sendNotify(Request $request) |
| 39 | { | 43 | { |
| 40 | - $url = $this->user['domain'].'api/update_page/'; | 44 | + $project_id = $this->user['project_id']; |
| 45 | + $type = intval($request->input('type', 1)); | ||
| 46 | + $route = intval($request->input('page', 1)); | ||
| 47 | + $url = $request->input('url', []); | ||
| 48 | + $language = $request->input('language', []); | ||
| 49 | + $is_sitemap = intval($request->input('is_sitemap', 0)); | ||
| 50 | + | ||
| 51 | + //获取项目所在服务器 | ||
| 52 | + $project_model = new Project(); | ||
| 53 | + $project_info = $project_model->read(['id'=>$project_id],['serve_id']); | ||
| 54 | + | ||
| 55 | + if($project_info && $project_info['serve_id'] == ServerConfig::SELF_SITE_ID){ | ||
| 56 | + //自建站服务器:如果项目已经上线,不请求C端接口,数据直接入库 | ||
| 57 | + $domain_model = new DomainInfo(); | ||
| 58 | + $domain_info = $domain_model->read(['project_id'=>$this->user['project_id']],['domain']); | ||
| 59 | + if($domain_info){ | ||
| 60 | + //判断是否已有更新进行中 | ||
| 61 | + $notify_model = new Notify(); | ||
| 62 | + $data = [ | ||
| 63 | + 'project_id' => $project_id, | ||
| 64 | + 'type' => $type, | ||
| 65 | + 'route' => $route, | ||
| 66 | + 'server_id' => ServerConfig::SELF_SITE_ID, | ||
| 67 | + 'status' => ['<',Notify::STATUS_FINISH_PAGE] | ||
| 68 | + ]; | ||
| 69 | + $notify = $notify_model->read($data,['id']); | ||
| 70 | + | ||
| 71 | + if(!$notify){ | ||
| 72 | + $domain = $domain_info['domain']; | ||
| 73 | + if($type == Notify::TYPE_AMP){ | ||
| 74 | + $domain_array = parse_url($domain); | ||
| 75 | + $host = $domain_array['host'] ?? $domain_array['path']; | ||
| 76 | + $host_array = explode('.',$host); | ||
| 77 | + if(count($host_array) <= 2){ | ||
| 78 | + array_unshift($host_array,'m'); | ||
| 79 | + }else{ | ||
| 80 | + $host_array[0] = 'm'; | ||
| 81 | + } | ||
| 82 | + $domain = implode('.',$host_array); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + $data['data'] = Arr::a2s(['domain'=>$domain,'url'=>$url,'language'=>$language]); | ||
| 86 | + $data['status'] = $is_sitemap == 1 ? Notify::STATUS_FINISH_PAGE : Notify::STATUS_INIT; | ||
| 87 | + $notify_model->add($data); | ||
| 88 | + } | ||
| 89 | + } | ||
| 90 | + }else{ | ||
| 91 | + //其他服务器:请求对应C端接口 | ||
| 92 | + $c_url = $this->user['domain'].'api/update_page/'; | ||
| 41 | $param = [ | 93 | $param = [ |
| 42 | 'project_id' => $this->user['project_id'], | 94 | 'project_id' => $this->user['project_id'], |
| 43 | - 'type' => intval($request->input('type', 1)), | ||
| 44 | - 'route' => intval($request->input('page', 1)), | ||
| 45 | - 'url' => $request->input('url', []), | ||
| 46 | - 'language'=> $request->input('language', []), | 95 | + 'type' => $type, |
| 96 | + 'route' => $route, | ||
| 97 | + 'url' => $url, | ||
| 98 | + 'language'=> $language, | ||
| 99 | + 'is_sitemap' => $is_sitemap | ||
| 47 | ]; | 100 | ]; |
| 48 | - http_post($url, json_encode($param)); | 101 | + http_post($c_url, json_encode($param)); |
| 102 | + } | ||
| 103 | + | ||
| 49 | $this->response('更新中请稍后, 更新完成将会发送站内信通知更新结果!'); | 104 | $this->response('更新中请稍后, 更新完成将会发送站内信通知更新结果!'); |
| 50 | } | 105 | } |
| 51 | 106 |
| @@ -266,6 +266,9 @@ class DomainInfoLogic extends BaseLogic | @@ -266,6 +266,9 @@ class DomainInfoLogic extends BaseLogic | ||
| 266 | if($project_info['serve_id'] == 9){ | 266 | if($project_info['serve_id'] == 9){ |
| 267 | $this->fail('请切换服务器,生成站点不能使用测试服务器'); | 267 | $this->fail('请切换服务器,生成站点不能使用测试服务器'); |
| 268 | } | 268 | } |
| 269 | + if($project_info['serve_id'] == ServerConfig::SELF_SITE_ID){ | ||
| 270 | + $this->fail('自建站服务器无法生成站点'); | ||
| 271 | + } | ||
| 269 | //域名是否都已经解析 | 272 | //域名是否都已经解析 |
| 270 | if(!empty($info['domain']) && !$this->check_cname($info['domain'], $server_info)){ | 273 | if(!empty($info['domain']) && !$this->check_cname($info['domain'], $server_info)){ |
| 271 | $this->fail('域名' . $info['domain'] . '未解析至目标服务器'); | 274 | $this->fail('域名' . $info['domain'] . '未解析至目标服务器'); |
| @@ -7,6 +7,7 @@ use App\Enums\Common\Common; | @@ -7,6 +7,7 @@ use App\Enums\Common\Common; | ||
| 7 | use App\Exceptions\BsideGlobalException; | 7 | use App\Exceptions\BsideGlobalException; |
| 8 | use App\Http\Logic\Logic; | 8 | use App\Http\Logic\Logic; |
| 9 | use App\Models\Com\UpdateNotify; | 9 | use App\Models\Com\UpdateNotify; |
| 10 | +use App\Models\Devops\ServerConfig; | ||
| 10 | use App\Models\Project\Project; | 11 | use App\Models\Project\Project; |
| 11 | use App\Models\RouteMap\RouteDelete; | 12 | use App\Models\RouteMap\RouteDelete; |
| 12 | use App\Models\Service\Service; | 13 | use App\Models\Service\Service; |
| @@ -174,6 +175,10 @@ class BaseLogic extends Logic | @@ -174,6 +175,10 @@ class BaseLogic extends Logic | ||
| 174 | $data['project_id'] = $this->user['project_id']; | 175 | $data['project_id'] = $this->user['project_id']; |
| 175 | $str = http_build_query($data); | 176 | $str = http_build_query($data); |
| 176 | $url = $this->user['domain'].'api/delHtml/?'.$str; | 177 | $url = $this->user['domain'].'api/delHtml/?'.$str; |
| 178 | + if(isset($this->project['serve_id']) && ($this->project['serve_id'] == ServerConfig::SELF_SITE_ID)){ | ||
| 179 | + //自建站服务器直接返回 | ||
| 180 | + return $this->success(); | ||
| 181 | + } | ||
| 177 | if(isset($this->project['serve_id']) && ($this->project['serve_id'] != 1)){//TODO::当前项目通知不过 ,跳过自动更新 | 182 | if(isset($this->project['serve_id']) && ($this->project['serve_id'] != 1)){//TODO::当前项目通知不过 ,跳过自动更新 |
| 178 | exec('curl -k "'.$url.'" > /dev/null 2>&1 &'); | 183 | exec('curl -k "'.$url.'" > /dev/null 2>&1 &'); |
| 179 | }else{ | 184 | }else{ |
| @@ -15,10 +15,11 @@ class Notify extends Base | @@ -15,10 +15,11 @@ class Notify extends Base | ||
| 15 | const STATUS_FINISH_PAGE = 2; | 15 | const STATUS_FINISH_PAGE = 2; |
| 16 | 16 | ||
| 17 | /** | 17 | /** |
| 18 | - * 类型 1:主站, 2:小语种 | 18 | + * 类型 1:主站, 2:小语种, 3:amp |
| 19 | */ | 19 | */ |
| 20 | const TYPE_MASTER = 1; | 20 | const TYPE_MASTER = 1; |
| 21 | const TYPE_MINOR = 2; | 21 | const TYPE_MINOR = 2; |
| 22 | + const TYPE_AMP = 3; | ||
| 22 | 23 | ||
| 23 | /** | 24 | /** |
| 24 | * 路由 | 25 | * 路由 |
| @@ -34,6 +34,8 @@ class ServerConfig extends Base | @@ -34,6 +34,8 @@ class ServerConfig extends Base | ||
| 34 | 34 | ||
| 35 | const STATUS_ONE = 1; | 35 | const STATUS_ONE = 1; |
| 36 | 36 | ||
| 37 | + const SELF_SITE_ID = 8;//自建站服务器ID | ||
| 38 | + | ||
| 37 | /** | 39 | /** |
| 38 | * @remark :获取数据用户名解密 | 40 | * @remark :获取数据用户名解密 |
| 39 | * @name :getUserAttribute | 41 | * @name :getUserAttribute |
-
请 注册 或 登录 后发表评论