作者 赵彬吉
  1 +<?php
  2 +
  3 +namespace App\Console\Commands\Domain;
  4 +
  5 +use App\Models\Project\Project;
  6 +use App\Models\Project\ProjectServerBackup;
  7 +use Illuminate\Console\Command;
  8 +
  9 +class EmergencyRelieve extends Command
  10 +{
  11 + protected $signature = 'emergency_relieve';
  12 + protected $description = '危机解除,恢复项目服务器';
  13 +
  14 + public function handle()
  15 + {
  16 + $backup_list = ProjectServerBackup::where('status', ProjectServerBackup::STATUS_NO)->get();
  17 +
  18 + $project_model = new Project();
  19 + if ($backup_list->count() > 0) {
  20 + foreach ($backup_list as $item) {
  21 + $project_model->edit(['serve_id' => $item->serve_id], ['id' => $item->project_id]);
  22 + $item->status = ProjectServerBackup::STATUS_YES;
  23 + $item->save();
  24 +
  25 + $this->output('项目ID:' . $item->project_id . ',恢复成功');
  26 + }
  27 + }
  28 + }
  29 +
  30 + /**
  31 + * 输出处理日志
  32 + * @param $message
  33 + */
  34 + public function output($message)
  35 + {
  36 + echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
  37 + }
  38 +}
  1 +<?php
  2 +
  3 +namespace App\Console\Commands\Domain;
  4 +
  5 +use App\Models\Com\Notify;
  6 +use App\Models\Devops\ServersIp;
  7 +use App\Models\Domain\DomainCreateTask;
  8 +use App\Models\Project\Project;
  9 +use App\Models\Project\ProjectServerBackup;
  10 +use App\Models\Domain\DomainInfo;
  11 +use Illuminate\Console\Command;
  12 +use Symfony\Component\Process\Process;
  13 +
  14 +class EmergencyRenewSite extends Command
  15 +{
  16 + protected $signature = 'emergency_renew_site';
  17 + protected $description = '紧急重建站点';
  18 +
  19 + public function handle()
  20 + {
  21 + //目标服务器
  22 + $target_server_id = 1;
  23 + $target_server = ServersIp::select(['id', 'ip', 'domain'])->where('servers_id', $target_server_id)->first()->toArray();
  24 +
  25 + //受灾服务器
  26 + $server_ids = [9, 13];
  27 + $server_ip_ids = ServersIp::whereIn('servers_id', $server_ids)->get()->pluck('id')->toArray();
  28 +
  29 + //获取所有受灾项目
  30 + $project_list = Project::select(['id', 'serve_id', 'title'])->whereIn('serve_id', $server_ip_ids)->get();
  31 + $domain_model = new DomainInfo();
  32 + $create_model = new DomainCreateTask();
  33 + $notify_model = new Notify();
  34 + $backup_model = new ProjectServerBackup();
  35 + foreach ($project_list as $value) {
  36 + $domain_info = $domain_model->read(['project_id' => $value->id, 'status' => 1], ['id', 'domain']);
  37 + if (!$domain_info) {
  38 + //过滤未绑定正式域名的项目
  39 + continue;
  40 + }
  41 +
  42 + //判断域名是否已经解析到目标服务器
  43 + if (!$this->check_cname($domain_info['domain'], $target_server)) {
  44 + $this->output($domain_info['domain'] . ' | 未解析到目标服务器');
  45 + }
  46 +
  47 + //获取站点其他域名
  48 + $other_domain = [];
  49 + if (strpos($domain_info['domain'], 'www.') === 0) {
  50 + $other_domain[] = str_replace('www', '*', $domain_info['domain']);
  51 +
  52 + $top_domain = str_replace('www.', '', $domain_info['domain']);
  53 + if ($this->check_cname($top_domain, $target_server)) {
  54 + $other_domain[] = $top_domain;
  55 + }
  56 + }
  57 +
  58 + //创建目标服务器建站任务
  59 + $map_create = [
  60 + 'type' => DomainCreateTask::TYPE_MAIN,
  61 + 'server_id' => $target_server_id,
  62 + 'project_id' => $value->id,
  63 + 'domain_id' => $domain_info['id'],
  64 + 'status' => DomainCreateTask::STATUS_UN,
  65 + ];
  66 + $task_info = $create_model->read($map_create, ['id']);
  67 + if (!$task_info) {
  68 + $map_create['other_domain'] = json_encode($other_domain);
  69 + $create_model->add($map_create);
  70 + }
  71 +
  72 + //创建目标服务器站点页面生成任务
  73 + $map_notify = [
  74 + 'type' => Notify::TYPE_MASTER,
  75 + 'server_id' => $target_server_id,
  76 + 'project_id' => $value->id,
  77 + 'status' => Notify::STATUS_INIT,
  78 + 'route' => Notify::ROUTE_ALL,
  79 + ];
  80 + $notify_info = $notify_model->read($map_notify);
  81 + if (!$notify_info) {
  82 + $map_notify['data'] = json_encode(['domain' => $domain_info['domain'], 'url' => [], 'language' => []]);
  83 + $map_notify['sort'] = 9;
  84 + $notify_model->add($map_notify);
  85 + }
  86 +
  87 + //备份项目原始服务器
  88 + $backup_info = $backup_model->read(['project_id' => $value->id, 'status' => ProjectServerBackup::STATUS_NO], ['id']);
  89 + if ($backup_info) {
  90 + $backup_model->edit(['serve_id' => $value->serve_id], ['id' => $backup_info['id']]);
  91 + } else {
  92 + $backup_model->add(['project_id' => $value->id, 'serve_id' => $value->serve_id]);
  93 + }
  94 +
  95 + //更改项目服务器
  96 + $value->serve_id = $target_server_id;
  97 + $value->save();
  98 +
  99 + $this->output($domain_info['domain'] . ' | success');
  100 + }
  101 + }
  102 +
  103 + /**
  104 + * 验证是否cname或者A记录解析到目标服务器
  105 + * @param $domain
  106 + * @param $server_info
  107 + * @return mixed
  108 + * @author zbj
  109 + * @date 2023/11/13
  110 + */
  111 + public function check_cname($domain, $server_info)
  112 + {
  113 + $process = new Process(['nslookup', '-qt=a', $domain]);
  114 + $process->run();
  115 + $output = explode(PHP_EOL, $process->getOutput());
  116 + foreach ($output as $line) {
  117 + if ($line) {
  118 + $checkA = strpos($line, $server_info['ip']) !== false;
  119 + if ($checkA) {
  120 + return $domain;
  121 + }
  122 + }
  123 + }
  124 +
  125 + //是否cname
  126 + $process = new Process(['nslookup', '-qt=cname', $domain]);
  127 + $process->run();
  128 + $output = explode(PHP_EOL, $process->getOutput());
  129 + foreach ($output as $line) {
  130 + if ($line) {
  131 + $checkCname = (strpos($line, $server_info['domain']) !== false);
  132 + if ($checkCname) {
  133 + return $domain;
  134 + }
  135 + }
  136 + }
  137 + return false;
  138 + }
  139 +
  140 + /**
  141 + * 输出处理日志
  142 + * @param $message
  143 + */
  144 + public function output($message)
  145 + {
  146 + echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
  147 + }
  148 +}
@@ -13,6 +13,7 @@ use App\Helper\Arr; @@ -13,6 +13,7 @@ use App\Helper\Arr;
13 use App\Helper\Translate; 13 use App\Helper\Translate;
14 use App\Models\Blog\Blog; 14 use App\Models\Blog\Blog;
15 use App\Models\CustomModule\CustomModuleCategory; 15 use App\Models\CustomModule\CustomModuleCategory;
  16 +use App\Models\CustomModule\CustomModuleContent;
16 use App\Models\Product\CategoryRelated; 17 use App\Models\Product\CategoryRelated;
17 use App\Models\Product\Keyword; 18 use App\Models\Product\Keyword;
18 use App\Models\Product\Product; 19 use App\Models\Product\Product;
@@ -55,33 +56,35 @@ class UpdateRoute extends Command @@ -55,33 +56,35 @@ class UpdateRoute extends Command
55 */ 56 */
56 public function handle(){ 57 public function handle(){
57 $projectModel = new Project(); 58 $projectModel = new Project();
58 - $list = $projectModel->list(['id'=>['in',[1659]]]); 59 + $list = $projectModel->list(['id'=>['in',[2321]]]);
59 $data = []; 60 $data = [];
60 foreach ($list as $v){ 61 foreach ($list as $v){
61 echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL; 62 echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
62 ProjectServer::useProject($v['id']); 63 ProjectServer::useProject($v['id']);
63 - $this->getProduct(); 64 +// $this->getProduct();
64 // $this->setProductKeyword(); 65 // $this->setProductKeyword();
65 // $this->getBlog(); 66 // $this->getBlog();
  67 + $this->setCustomRoute($v['id']);
66 DB::disconnect('custom_mysql'); 68 DB::disconnect('custom_mysql');
67 } 69 }
68 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL; 70 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
69 } 71 }
70 72
71 public function setCustomRoute($project_id){ 73 public function setCustomRoute($project_id){
72 -// $customModel = new CustomModuleContent();  
73 -// $list = $customModel->list();  
74 -// foreach ($list as $v){  
75 -// $route = RouteMap::setRoute($v['name'], RouteMap::SOURCE_MODULE, $v['id'], $project_id);  
76 -// $customModel->edit(['route'=>$route],['id'=>$v['id']]);  
77 -// }  
78 - $cateModel = new CustomModuleCategory();  
79 - $lists = $cateModel->list();  
80 - foreach ($lists as $v1){  
81 - $route = RouteMap::setRoute($v1['name'], RouteMap::SOURCE_MODULE_CATE, $v1['id'], $project_id);  
82 - $cateModel->edit(['route'=>$route],['id'=>$v1['id']]);  
83 - 74 + $customModel = new CustomModuleContent();
  75 + $list = $customModel->list();
  76 + foreach ($list as $v){
  77 + echo date('Y-m-d H:i:s') . '扩展模块id:'.$v['id'] . PHP_EOL;
  78 + $route = RouteMap::setRoute($v['name'], RouteMap::SOURCE_MODULE, $v['id'], $project_id);
  79 + $customModel->edit(['route'=>$route],['id'=>$v['id']]);
84 } 80 }
  81 +// $cateModel = new CustomModuleCategory();
  82 +// $lists = $cateModel->list();
  83 +// foreach ($lists as $v1){
  84 +// $route = RouteMap::setRoute($v1['name'], RouteMap::SOURCE_MODULE_CATE, $v1['id'], $project_id);
  85 +// $cateModel->edit(['route'=>$route],['id'=>$v1['id']]);
  86 +//
  87 +// }
85 } 88 }
86 89
87 public function delProductKeyword(){ 90 public function delProductKeyword(){
@@ -189,6 +189,7 @@ class UserLoginLogic @@ -189,6 +189,7 @@ class UserLoginLogic
189 if($info['is_customized'] == 1){ 189 if($info['is_customized'] == 1){
190 $info['is_visualization'] = json_decode($project['is_visualization']); 190 $info['is_visualization'] = json_decode($project['is_visualization']);
191 } 191 }
  192 + $info['is_comment'] = $project['deploy_build']['is_comment'] ?? 0;
192 $info['is_visualization_authority'] = $project['deploy_build']['is_visualization_authority']; 193 $info['is_visualization_authority'] = $project['deploy_build']['is_visualization_authority'];
193 $info['is_inquiry_country'] = $project['is_inquiry_country']; 194 $info['is_inquiry_country'] = $project['is_inquiry_country'];
194 $info['is_subscribe'] = $project['is_subscribe']; 195 $info['is_subscribe'] = $project['is_subscribe'];
@@ -294,6 +295,7 @@ class UserLoginLogic @@ -294,6 +295,7 @@ class UserLoginLogic
294 $info['project_location'] = $project['project_location']; 295 $info['project_location'] = $project['project_location'];
295 $info['file_cdn'] = $project['deploy_build']['file_cdn']; 296 $info['file_cdn'] = $project['deploy_build']['file_cdn'];
296 $info['service_duration'] = $project['deploy_build']['service_duration'] ?? 0; 297 $info['service_duration'] = $project['deploy_build']['service_duration'] ?? 0;
  298 + $info['is_comment'] = $project['deploy_build']['is_comment'] ?? 0;
297 $info['remain_day'] = $project['remain_day'] ?? 0; 299 $info['remain_day'] = $project['remain_day'] ?? 0;
298 if($info['is_customized'] == 1){ 300 if($info['is_customized'] == 1){
299 $info['is_visualization'] = json_decode($project['is_visualization']); 301 $info['is_visualization'] = json_decode($project['is_visualization']);
@@ -308,7 +310,6 @@ class UserLoginLogic @@ -308,7 +310,6 @@ class UserLoginLogic
308 $is_amp = $amp_info ? $amp_info['amp_status'] : 0; 310 $is_amp = $amp_info ? $amp_info['amp_status'] : 0;
309 } 311 }
310 $info['is_amp'] = $is_amp; 312 $info['is_amp'] = $is_amp;
311 -  
312 //保存项目缓存 313 //保存项目缓存
313 Cache::put('user-'.$info['project_id'],$project,12 * 3600); 314 Cache::put('user-'.$info['project_id'],$project,12 * 3600);
314 return $this->success($info); 315 return $this->success($info);
  1 +<?php
  2 +namespace App\Models\Project;
  3 +
  4 +use App\Models\Base;
  5 +
  6 +class ProjectServerBackup extends Base
  7 +{
  8 + protected $table = 'gl_project_server_backup';
  9 +
  10 + const STATUS_NO = 0;
  11 + const STATUS_YES = 1;
  12 +}
@@ -621,6 +621,13 @@ Route::middleware(['bloginauth'])->group(function () { @@ -621,6 +621,13 @@ Route::middleware(['bloginauth'])->group(function () {
621 Route::any('/set_smtp', [\App\Http\Controllers\Bside\Subscribe\EmailController::class, 'set_smtp'])->name('subscribe_email_set_smtp'); 621 Route::any('/set_smtp', [\App\Http\Controllers\Bside\Subscribe\EmailController::class, 'set_smtp'])->name('subscribe_email_set_smtp');
622 Route::any('/group_send', [\App\Http\Controllers\Bside\Subscribe\EmailController::class, 'group_send'])->name('subscribe_email_group_send'); 622 Route::any('/group_send', [\App\Http\Controllers\Bside\Subscribe\EmailController::class, 'group_send'])->name('subscribe_email_group_send');
623 }); 623 });
  624 +
  625 + //网站评论
  626 + Route::prefix('comment')->group(function () {
  627 + Route::any('/', [\App\Http\Controllers\Bside\Comment\CommentController::class, 'lists'])->name('comment_lists');
  628 + Route::any('/info', [\App\Http\Controllers\Bside\Comment\CommentController::class, 'info'])->name('comment_info');
  629 + Route::any('/status', [\App\Http\Controllers\Bside\Comment\CommentController::class, 'status'])->name('comment_status');
  630 + });
624 }); 631 });
625 //无需登录验证的路由组 632 //无需登录验证的路由组
626 Route::group([], function () { 633 Route::group([], function () {