作者 赵彬吉
@@ -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/';  
41 - $param = [  
42 - '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', []),  
47 - ];  
48 - http_post($url, json_encode($param)); 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/';
  93 + $param = [
  94 + 'project_id' => $this->user['project_id'],
  95 + 'type' => $type,
  96 + 'route' => $route,
  97 + 'url' => $url,
  98 + 'language'=> $language,
  99 + 'is_sitemap' => $is_sitemap
  100 + ];
  101 + http_post($c_url, json_encode($param));
  102 + }
  103 +
49 $this->response('更新中请稍后, 更新完成将会发送站内信通知更新结果!'); 104 $this->response('更新中请稍后, 更新完成将会发送站内信通知更新结果!');
50 } 105 }
51 106
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\File; @@ -4,6 +4,7 @@ namespace App\Http\Controllers\File;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
6 use App\Helper\Translate; 6 use App\Helper\Translate;
  7 +use App\Jobs\SyncImageFileJob;
7 use App\Models\File\ErrorFile; 8 use App\Models\File\ErrorFile;
8 use App\Models\File\File; 9 use App\Models\File\File;
9 use App\Models\File\Image as ImageModel; 10 use App\Models\File\Image as ImageModel;
@@ -146,13 +147,7 @@ class FileController @@ -146,13 +147,7 @@ class FileController
146 */ 147 */
147 public function synchronizationFile($fileName){ 148 public function synchronizationFile($fileName){
148 //同步到大文件 149 //同步到大文件
149 - $file_path = config('filesystems.disks.cos')['cdn1'].$this->path.'/'.$fileName;  
150 - $cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$this->path.'" https://v6-file.globalso.com/upload.php';  
151 - $code = shell_exec($cmd);  
152 - if(200 != (int)$code){  
153 - $errorFileModel = new ErrorFile();  
154 - $errorFileModel->add(['path'=>$this->path.'/'.$fileName]);  
155 - } 150 + SyncImageFileJob::dispatch(['path'=>$this->path,'name'=>$fileName]);
156 return true; 151 return true;
157 } 152 }
158 153
@@ -204,6 +204,7 @@ class ImageController extends Controller @@ -204,6 +204,7 @@ class ImageController extends Controller
204 $this->response('不支持当前格式',Code::SYSTEM_ERROR); 204 $this->response('不支持当前格式',Code::SYSTEM_ERROR);
205 } 205 }
206 $fileName = $this->getOnlyFilename($name,$param['project_id'] ?? 0); 206 $fileName = $this->getOnlyFilename($name,$param['project_id'] ?? 0);
  207 +
207 //上传到cos 208 //上传到cos
208 if($this->upload_location == 0){ 209 if($this->upload_location == 0){
209 $cosService = new CosService(); 210 $cosService = new CosService();
@@ -265,13 +266,6 @@ class ImageController extends Controller @@ -265,13 +266,6 @@ class ImageController extends Controller
265 */ 266 */
266 public function synchronizationImage($fileName){ 267 public function synchronizationImage($fileName){
267 SyncImageFileJob::dispatch(['path'=>$this->path,'name'=>$fileName]); 268 SyncImageFileJob::dispatch(['path'=>$this->path,'name'=>$fileName]);
268 -// $file_path = getImageUrl($this->path.'/'.$fileName,$this->cache['storage_type'] ?? 0);  
269 -// $cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$this->path.'" https://v6-file.globalso.com/upload.php';  
270 -// $code = shell_exec($cmd);  
271 -// if(200 != (int)$code){  
272 -// $errorFileModel = new ErrorFile();  
273 -// $errorFileModel->add(['path'=>$this->path.'/'.$fileName]);  
274 -// }  
275 return true; 269 return true;
276 } 270 }
277 271
@@ -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{
@@ -11,6 +11,7 @@ namespace App\Http\Logic\Bside\Setting; @@ -11,6 +11,7 @@ namespace App\Http\Logic\Bside\Setting;
11 11
12 use App\Http\Logic\Bside\BaseLogic; 12 use App\Http\Logic\Bside\BaseLogic;
13 use App\Models\Com\UpdateLog; 13 use App\Models\Com\UpdateLog;
  14 +use App\Models\RouteMap\RouteMap;
14 use App\Models\User\UserLog; 15 use App\Models\User\UserLog;
15 use App\Models\WebSetting\Translate as TranslateModel; 16 use App\Models\WebSetting\Translate as TranslateModel;
16 use App\Models\WebSetting\WebLanguage; 17 use App\Models\WebSetting\WebLanguage;
@@ -284,6 +285,37 @@ class TranslateLogic extends BaseLogic @@ -284,6 +285,37 @@ class TranslateLogic extends BaseLogic
284 } 285 }
285 286
286 /** 287 /**
  288 + * @remark :根据路由获取source+source_id
  289 + * @name :getRouteSource
  290 + * @author :lyh
  291 + * @method :post
  292 + * @time :2024/5/17 15:11
  293 + */
  294 + public function getRouteSource($route){
  295 + $data = ['source'=>0,'source_id'=>0,'is_list'=>0,'is_custom'=>0];
  296 + if(strtolower($route) == 'all'){
  297 + return $this->success($data);
  298 + }
  299 + if($route == '/'){
  300 + $data['source'] = 1;
  301 + return $this->success($data);
  302 + }
  303 + $route = basename($route);
  304 + $routeModel = new RouteMap();
  305 + $routeInfo = $routeModel->read(['route'=>$route]);
  306 + if($routeInfo['source'] == RouteMap::SOURCE_PAGE){
  307 + if($routeInfo['source_id']){
  308 + $data = ['source'=>9,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>0];
  309 + }
  310 + }
  311 + if($routeInfo['source'] == RouteMap::SOURCE_PAGE){
  312 + if($routeInfo['source_id']){
  313 + $data = ['source'=>9,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>0];
  314 + }
  315 + }
  316 + }
  317 +
  318 + /**
287 * @remark :处理路由 319 * @remark :处理路由
288 * @name :handleRoute 320 * @name :handleRoute
289 * @author :lyh 321 * @author :lyh
@@ -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