Temp.php
35.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
<?php
namespace App\Console\Commands\Test;
use App\Helper\Arr;
use App\Http\Logic\Bside\Product\CategoryLogic;
use App\Models\Com\Notify;
use App\Models\Devops\ServerConfig;
use App\Models\Devops\ServersIp;
use App\Models\Domain\DomainCreateTask;
use App\Models\Domain\DomainInfo;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\Project\DeployBuild;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Project;
use App\Models\Template\BCustomTemplate;
use App\Models\WebSetting\WebLanguage;
use App\Services\BatchExportService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class Temp extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'test_temp';
/**
* The console command description.
*
* @var string
*/
protected $description = '临时脚本(akun)';
public function handle()
{
//未被标注 特殊前后缀 && 未达标项目 && 优化开始时间 > 2025-01-01 00:00:00 ,开启自动添加聚合页关键词的前后缀关键词配置
$project_list = DeployOptimize::where('special', 'not like', '%,8,%')->where('start_date', '>', '2025-01-01 00:00:00')->get();
foreach ($project_list as $project) {
$is_remain_today = Project::where('id', $project->project_id)->value('is_remain_today');
if ($is_remain_today) {
continue;
}
$project->is_auto_keywords = 1;
$project->save();
$this->output('ID:' . $project->id . ' | success');
}
}
/**
* 3424项目导入pdf
* @return bool
* @throws \Exception
* @author Akun
* @date 2025/04/01 16:26
*/
public function importPdf()
{
$file_url = 'https://ecdn6.globalso.com/upload/p/3424/file/2025-04/tmp_2.jsonl';
$project_id = 3424;
$line_of_text = [];
try {
$opts = [
'http' => [
'method' => 'GET',
'header' => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246'
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
]
];
$file_handle = fopen($file_url, 'r', null, stream_context_create($opts));
while (!feof($file_handle)) {
$line_of_text[] = fgets($file_handle);
}
fclose($file_handle);
} catch (\Exception $e) {
$this->output($e->getMessage());
return true;
}
if (count($line_of_text) > 1) {
$project = ProjectServer::useProject($project_id);
if ($project) {
$product_model = new Product();
foreach ($line_of_text as $line) {
if (!$line) {
continue;
}
$item = Arr::s2a($line);
if (!$item) {
continue;
}
$title = $item['name'] ?? '';
if (!$title) {
continue;
}
//根据标题查询产品
$product = $product_model->read(['title' => $title], ['id']);
if (!$product) {
continue;
}
//处理分类
$cate = $item['cate'] ?? '';
$category_id = '';
$category_arr = [];
if ($cate) {
$cate_array = explode('/', $cate);
$category = implode($cate_array, '^v6sp$');
//处理分类
$categoryLogic = new CategoryLogic();
$category_info = $categoryLogic->importProductCategory($project_id, $category);
$category_id = $category_info['category_id'];
$category_arr = $category_info['category_arr'];
}
//处理pdf
$pdf = $item['pdf'] ?? '';
$files = null;
if ($pdf) {
$files = Arr::a2s(['url' => $pdf, 'text' => 'Download']);
}
//保存分类及pdf数据
$product_model->edit(['category_id' => $category_id, 'files' => $files], ['id' => $product['id']]);
//关联分类
if ($category_arr) {
CategoryRelated::saveRelated($product['id'], $category_arr);
}
$this->output($title . ' | success');
}
}
//关闭数据库
DB::disconnect('custom_mysql');
}
return true;
}
/*
* 2379项目导入tdk
*/
public function importTdk()
{
$project_id = 2379;
$source = 'page';
$file_url = 'https://ecdn6.globalso.com/upload/p/2379/image_other/2025-04/products.csv';
//判断文件编码格式是否正确
$is_gbk = 0;
$file_code_type = $this->get_code_type($file_url);
if ($file_code_type === false) {
$this->output('文件编码格式错误');
return true;
} elseif ($file_code_type === 'GBK') {
$is_gbk = 1;
setlocale(LC_ALL, 'zh_CN');
}
//读取文件内容
//读取csv文件
$line_of_text = [];
try {
$opts = [
'http' => [
'method' => 'GET',
'header' => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246'
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
]
];
$file_handle = fopen($file_url, 'r', null, stream_context_create($opts));
while (!feof($file_handle)) {
$line_of_text[] = fgetcsv($file_handle, 0, ',');
}
fclose($file_handle);
} catch (\Exception $e) {
$this->output($e->getMessage());
return true;
}
$success_count = 0; //成功导入条数
if (count($line_of_text) > 1) {
//设置数据库
$project = ProjectServer::useProject($project_id);
if ($project) {
foreach ($line_of_text as $k => $v) {
if ($k > 0 && isset($v[0]) && $v[0]) {
if ($is_gbk) {
foreach ($v as $kk => $vv) {
$v[$kk] = mb_convert_encoding($vv, 'utf-8', 'gbk');
}
}
$url = $v[0];
$title = $v[1];
$desc = $v[2];
$keyword = $v[3];
$route = trim(str_replace('https://www.docareco.com/', '', $url), '/');
if ($route) {
if ($source == 'page') {
$model = new BCustomTemplate();
$model->edit([
'title' => $title,
'keywords' => $keyword,
'description' => $desc
], ['url' => $route]);
} elseif ($source == 'product_category') {
$model = new Category();
$model->edit([
'seo_title' => $title,
'seo_keywords' => $keyword,
'seo_des' => $desc
], ['route' => $route]);
} elseif ($source == 'product') {
$model = new Product();
$model->edit(['seo_mate' => Arr::a2s([
'title' => $title,
'keyword' => $keyword,
'description' => $desc
])], ['route' => $route]);
}
$success_count += 1;
}
}
}
}
//关闭数据库
DB::disconnect('custom_mysql');
}
$this->output('导入tdk成功执行' . $success_count . '条');
return true;
}
//判断编码格式
protected function get_code_type($file)
{
$list = array('GBK', 'UTF-8');
$str = curl_c($file, false);
foreach ($list as $item) {
$tmp = mb_convert_encoding($str, $item, $item);
if (md5($tmp) == md5($str)) {
return $item;
}
}
return false;
}
/**
* 小语种为二级目录的项目强制跳转https
* @author Akun
* @date 2025/03/01 10:48
*/
public function domain_rewrite_https()
{
$domainModel = new DomainInfo();
$projectModel = new Project();
$buildModel = new DeployBuild();
$serverIpModel = new ServersIp();
$domainCreateTaskModel = new DomainCreateTask();
$list = $domainModel->select(['id', 'domain', 'project_id'])->where('status', '=', 1)->where('project_id', '>', 0)->where('is_https', 0)->get();
foreach ($list as $v) {
$project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']);
if (!$project_info) {
continue;
}
$build_info = $buildModel->read(['project_id' => $v['project_id']], ['linking_format']);
if (!$build_info) {
continue;
}
if ($build_info['linking_format'] != 1) {
continue;
}
$servers_ip_info = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id', 'ip', 'domain']);
if (!$servers_ip_info) {
continue;
}
//过滤测试项目域名
if ($servers_ip_info['servers_id'] == ServerConfig::SELF_TEST_ID) {
continue;
}
//过滤自建站项目域名
if ($servers_ip_info['servers_id'] == ServerConfig::SELF_SITE_ID) {
continue;
}
//过滤已解析到别的ip的域名
if (!check_domain_record($v['domain'], $servers_ip_info)) {
continue;
}
//强制跳转https
$v->is_https = 1;
$v->save();
//创建更新站点证书任务
$task_info = $domainCreateTaskModel->read(['type' => DomainCreateTask::TYPE_MAIN, 'domain_id' => $v['id'], 'status' => ['<', DomainCreateTask::STATUS_SUC]]);
if (!$task_info) {
$domainCreateTaskModel->add([
'server_id' => $servers_ip_info['servers_id'],
'project_id' => $v['project_id'],
'domain_id' => $v['id'],
'type' => DomainCreateTask::TYPE_MAIN
]);
}
$this->output($v['id'] . ' , success');
}
}
/**
* 240服务器上解析cname的项目迁移
* @author Akun
* @date 2025/02/17 14:21
*/
public function change_cname_projects_240()
{
$server_ip_model = new ServersIp();
$server_ip_ids = $server_ip_model->where('servers_id', 1)->get()->pluck('id')->toArray();
$project_list = Project::select(['id', 'serve_id'])->whereIn('serve_id', $server_ip_ids)->get();
$domain_model = new DomainInfo();
$notify_model = new Notify();
foreach ($project_list as $value) {
$project_id = $value->id;
$domain_info = $domain_model->read(['project_id' => $project_id, 'status' => 1], ['id', 'domain', 'amp_status']);
if (!$domain_info) {
//过滤未绑定正式域名的项目
continue;
}
$domain_id = $domain_info['id'];
$domain = $domain_info['domain'];
//迁移主站
$check = dns_get_record($domain, DNS_A);
$host = $check[0]['host'] ?? '';
if ($host == 'cname.globalso.com') {
//获取主站备份证书
$ssl_info = DB::table('gl_domain_ssl_backup')->select(['private_key', 'private_cert'])->where('domain', $domain)->first();
if (!$ssl_info) {
$this->output('项目id:' . $project_id . ' | 未备份主站证书');
continue;
}
//创建主站建站任务
$task_info = DomainCreateTask::where('type', 1)->where('server_id', 20)->where('project_id', $project_id)->where('status', '!=', DomainCreateTask::STATUS_SUC)->first();
if (!$task_info) {
$task_model = new DomainCreateTask();
$task_model->type = 1;
$task_model->server_id = 20;
$task_model->project_id = $project_id;
$task_model->domain_id = $domain_id;
$task_model->certs = json_encode(['key' => $ssl_info->private_key, 'csr' => $ssl_info->private_cert]);
$task_model->save();
}
//创建主站页面生成任务
$notify_data = [
'project_id' => $project_id,
'type' => 1,
'route' => 1,
'server_id' => 20,
'status' => ['!=', Notify::STATUS_FINISH_SITEMAP]
];
$notify = $notify_model->read($notify_data, ['id']);
if (!$notify) {
$notify_data['data'] = Arr::a2s(['domain' => $domain, 'url' => null, 'language' => []]);
$notify_data['status'] = Notify::STATUS_INIT;
$notify_model->add($notify_data);
}
//创建主站关键词页面生成任务
$notify_keyword_data = [
'project_id' => $project_id,
'type' => 1,
'route' => 4,
'server_id' => 20,
'status' => ['!=', Notify::STATUS_FINISH_SITEMAP]
];
$notify_keyword = $notify_model->read($notify_keyword_data, ['id']);
if (!$notify_keyword) {
$notify_keyword_data['data'] = Arr::a2s(['domain' => $domain, 'url' => null, 'language' => []]);
$notify_keyword_data['status'] = Notify::STATUS_INIT;
$notify_model->add($notify_keyword_data);
}
}
if ($domain_info['amp_status'] == 1) {
//迁移amp站
$domain_array = parse_url($domain);
$host = $domain_array['host'] ?? $domain_array['path'];
$host_array = explode('.', $host);
if (count($host_array) <= 2) {
array_unshift($host_array, 'm');
} else {
$host_array[0] = 'm';
}
$amp_domain = implode('.', $host_array);
$check_amp = dns_get_record($amp_domain, DNS_A);
$host_amp = $check_amp[0]['host'] ?? '';
if ($host_amp == 'cname.globalso.com') {
//获取amp站备份证书
$ssl_info_amp = DB::table('gl_domain_ssl_backup')->select(['private_key', 'private_cert'])->where('domain', $amp_domain)->first();
if (!$ssl_info_amp) {
$this->output('项目id:' . $project_id . ' | 未备份amp站证书');
continue;
}
//创建amp站建站任务
$task_info_amp = DomainCreateTask::where('type', 2)->where('server_id', 20)->where('project_id', $project_id)->where('status', '!=', DomainCreateTask::STATUS_SUC)->first();
if (!$task_info_amp) {
$task_model = new DomainCreateTask();
$task_model->type = 2;
$task_model->server_id = 20;
$task_model->project_id = $project_id;
$task_model->domain_id = $domain_id;
$task_model->certs = json_encode(['key' => $ssl_info_amp->private_key, 'csr' => $ssl_info_amp->private_cert]);
$task_model->save();
}
//创建amp站页面生成任务
$notify_amp_data = [
'project_id' => $project_id,
'type' => 3,
'route' => 1,
'server_id' => 20,
'status' => ['!=', Notify::STATUS_FINISH_SITEMAP]
];
$notify_amp = $notify_model->read($notify_amp_data, ['id']);
if (!$notify_amp) {
$notify_amp_data['data'] = Arr::a2s(['domain' => $amp_domain, 'url' => null, 'language' => []]);
$notify_amp_data['status'] = Notify::STATUS_INIT;
$notify_model->add($notify_amp_data);
}
}
}
}
}
/**
* 创建所有站点建站任务
* @author Akun
* @date 2025/01/27 9:48
*/
public function create_domain_task()
{
$domainModel = new DomainInfo();
$projectModel = new Project();
$serverIpModel = new ServersIp();
$domainCreateTaskModel = new DomainCreateTask();
$list = $domainModel->select(['id', 'domain', 'project_id', 'amp_status'])->where('status', '=', 1)->where('project_id', '>', 0)->get()->toArray();
foreach ($list as $v) {
$project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']);
if (!$project_info) {
continue;
}
$servers_ip_info = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id', 'ip', 'domain']);
if (!$servers_ip_info) {
continue;
}
//过滤测试项目域名
if ($servers_ip_info['servers_id'] == ServerConfig::SELF_TEST_ID) {
continue;
}
//过滤自建站项目域名
if ($servers_ip_info['servers_id'] == ServerConfig::SELF_SITE_ID) {
continue;
}
//过滤已解析到别的ip的域名
if (!check_domain_record($v['domain'], $servers_ip_info)) {
continue;
}
//创建更新站点证书任务
$task_info = $domainCreateTaskModel->read(['type' => DomainCreateTask::TYPE_MAIN, 'domain_id' => $v['id'], 'status' => ['<', DomainCreateTask::STATUS_SUC]]);
if (!$task_info) {
$domainCreateTaskModel->add([
'server_id' => $servers_ip_info['servers_id'],
'project_id' => $v['project_id'],
'domain_id' => $v['id'],
'type' => DomainCreateTask::TYPE_MAIN
]);
}
if ($v['amp_status']) {
$domain_array = parse_url($v['domain']);
$host = $domain_array['host'] ?? $domain_array['path'];
$host_array = explode('.', $host);
if (count($host_array) <= 2) {
array_unshift($host_array, 'm');
} else {
$host_array[0] = 'm';
}
$amp_domain = implode('.', $host_array);
//过滤已解析到别的ip的AMP域名
if (!check_domain_record($amp_domain, $servers_ip_info)) {
continue;
}
//创建更新AMP站点证书任务
$task_info_amp = $domainCreateTaskModel->read(['type' => DomainCreateTask::TYPE_AMP, 'domain_id' => $v['id'], 'status' => ['<', DomainCreateTask::STATUS_SUC]]);
if (!$task_info_amp) {
$domainCreateTaskModel->add([
'server_id' => $servers_ip_info['servers_id'],
'project_id' => $v['project_id'],
'domain_id' => $v['id'],
'type' => DomainCreateTask::TYPE_AMP
]);
}
}
$this->output($v['id'] . ' , success');
}
}
/**
* 判断指定服务器项目小语种是否正常访问
* @author Akun
* @date 2024/12/11 10:15
*/
public function check_server_minor_site()
{
$server_id = 15;
$server_name = '美服1';
$server_ip_model = new ServersIp();
$server_ip_ids = $server_ip_model->where('servers_id', $server_id)->get()->pluck('id')->toArray();
$project_list = Project::select(['id', 'serve_id', 'title'])->whereIn('serve_id', $server_ip_ids)->get();
$domain_model = new DomainInfo();
$data = [];
foreach ($project_list as $value) {
$domain_info = $domain_model->read(['project_id' => $value->id, 'status' => 1], ['id', 'domain']);
if (!$domain_info) {
//过滤未绑定正式域名的项目
continue;
}
$domain = $domain_info['domain'];
//获取项目所在服务器
$serve_ip_info = $server_ip_model->read(['id' => $value->serve_id], ['domain', 'ip']);
if (!$serve_ip_info) {
continue;
}
if (!check_domain_record($domain, $serve_ip_info)) {
continue;
}
//获取最新一条小语种生成任务
$notify = Notify::where(['server_id' => $server_id, 'project_id' => $value->id, 'type' => 2, 'status' => 3, 'route' => 4])->orderBy('id', 'desc')->first();
if (!$notify) {
//过滤未生成过小语种的项目
continue;
}
$notify_data = json_decode($notify->data, true);
$language = array_diff($notify_data['language'], ['1']);
$language_id = current($language);
if (!$language_id) {
continue;
}
$lan_info = WebLanguage::getLangById($language_id);
$short = $lan_info->short;
ProjectServer::useProject($value->id);
$route = Keyword::where('status', 1)->where('is_video_keyword', 0)->value('route');
if (!$route) {
//过滤没有关键词的项目
continue;
}
$url = 'https://' . $domain . '/' . $short . '/' . $route . '/';
$code = check_curl_status($url);
$html = curl_c($url, false);
$is_404 = false;
if (strpos(strtolower($html), 'sorry. the page has either moved or cannot be found.') !== false) {
$is_404 = true;
}
$data[] = [
$value->id,
$value->title,
$url,
$code,
$is_404
];
}
$map = ['项目id', '名称', '访问地址', '访问状态', '是否404'];
if ($data) {
$table = new BatchExportService($server_name . '站点小语种聚合页面访问状态');
$file = $table->head($map)->data($data)->save();
if (!$file) {
$this->output('文件生成失败,请重试');
} else {
$this->output('export success');
}
} else {
$this->output('no data');
}
}
/**
* 判断指定服务器项目是否正常访问
* @author Akun
* @date 2024/12/11 10:15
*/
public function check_server_main_site()
{
$server_id = 20;
$server_name = '硅谷建站服务器';
$server_ip_model = new ServersIp();
$server_ip_ids = $server_ip_model->where('servers_id', $server_id)->get()->pluck('id')->toArray();
$project_list = Project::select(['id', 'serve_id', 'title'])->whereIn('serve_id', $server_ip_ids)->get();
$domain_model = new DomainInfo();
$data = [];
foreach ($project_list as $value) {
$domain_info = $domain_model->read(['project_id' => $value->id, 'status' => 1], ['id', 'domain']);
if (!$domain_info) {
//过滤未绑定正式域名的项目
continue;
}
$domain = $domain_info['domain'];
$check = dns_get_record($domain, DNS_A);
$ip = $check[0]['ip'] ?? '';
$host = $check[0]['host'] ?? '';
$code = check_curl_status('https://' . $domain);
$data[] = [
$value->id,
$value->title,
$domain,
$host,
$ip,
$code
];
}
$map = ['项目id', '名称', '域名', 'CNAME', 'IP', '站点状态'];
if ($data) {
$table = new BatchExportService($server_name . '站点解析情况及访问状态');
$file = $table->head($map)->data($data)->save();
if (!$file) {
$this->output('文件生成失败,请重试');
} else {
$this->output('export success');
}
} else {
$this->output('no data');
}
}
/**
* 获取指定服务器所有项目
* @author Akun
* @date 2024/09/30 17:01
*/
public function get_all_projects_by_server()
{
$server_id = 1;
$server_name = '240云服务器';
$server_ip_model = new ServersIp();
$server_ip_ids = $server_ip_model->where('servers_id', $server_id)->get()->pluck('id')->toArray();
$project_list = Project::select(['id', 'serve_id', 'title'])->whereIn('serve_id', $server_ip_ids)->get();
$domain_model = new DomainInfo();
$data = [];
foreach ($project_list as $value) {
$domain_info = $domain_model->read(['project_id' => $value->id, 'status' => 1], ['id', 'domain']);
if (!$domain_info) {
//过滤未绑定正式域名的项目
continue;
}
$domain = $domain_info['domain'];
$data[] = [
$value->id,
$value->title,
$domain
];
}
$map = ['项目id', '名称', '域名'];
if ($data) {
$table = new BatchExportService($server_name . '项目');
$file = $table->head($map)->data($data)->save();
if (!$file) {
$this->output('文件生成失败,请重试');
} else {
$this->output('export success');
}
} else {
$this->output('no data');
}
}
/**
* 检查服务器上没有解析cname的项目
* @author Akun
* @date 2024/12/11 10:15
*/
public function check_no_cname_projects()
{
$server_id = 1;
$server_name = '硅谷云服务器';
$server_ip_model = new ServersIp();
$server_ip_ids = $server_ip_model->where('servers_id', $server_id)->get()->pluck('id')->toArray();
$project_list = Project::select(['id', 'serve_id', 'title'])->whereIn('serve_id', $server_ip_ids)->get();
$domain_model = new DomainInfo();
$data = [];
foreach ($project_list as $value) {
$domain_info = $domain_model->read(['project_id' => $value->id, 'status' => 1], ['id', 'domain']);
if (!$domain_info) {
//过滤未绑定正式域名的项目
continue;
}
$domain = $domain_info['domain'];
$check = dns_get_record($domain, DNS_A);
$ip = $check[0]['ip'] ?? '';
$host = $check[0]['host'] ?? '';
if (strpos($host, 'globalso.com') === false) {
$data[] = [
$value->id,
$value->title,
$domain,
$ip
];
}
}
$map = ['项目id', '名称', '域名', '解析IP'];
if ($data) {
$table = new BatchExportService($server_name . '没有解析cname的项目');
$file = $table->head($map)->data($data)->save();
if (!$file) {
$this->output('文件生成失败,请重试');
} else {
$this->output('export success');
}
} else {
$this->output('no data');
}
}
/**
* 检查不在所属服务器解析上的域名
* @author Akun
* @date 2024/09/26 10:48
*/
public function check_no_server_projects()
{
$server_id = 15;
$server_name = '美服1';
$server_ip_model = new ServersIp();
$server_ip_ids = $server_ip_model->where('servers_id', $server_id)->get()->pluck('id')->toArray();
$project_list = Project::select(['id', 'serve_id', 'title'])->whereIn('serve_id', $server_ip_ids)->get();
$domain_model = new DomainInfo();
$data = [];
foreach ($project_list as $value) {
$domain_info = $domain_model->read(['project_id' => $value->id, 'status' => 1], ['id', 'domain']);
if (!$domain_info) {
//过滤未绑定正式域名的项目
continue;
}
$domain = $domain_info['domain'];
$check = dns_get_record($domain, DNS_A);
$ip = $check[0]['ip'] ?? '';
$ip_info = $server_ip_model->read(['ip' => $ip]);
if ($ip_info === false || $ip_info['servers_id'] != $server_id) {
$data[] = [
$value->id,
$value->title,
$domain,
$ip,
$ip_info ? $ip_info['servers_id'] : '',
];
}
}
$map = ['项目id', '名称', '域名', 'IP', '服务器ID',];
if ($data) {
$table = new BatchExportService($server_name . '解析未在当前服务器项目');
$file = $table->head($map)->data($data)->save();
if (!$file) {
$this->output('文件生成失败,请重试');
} else {
$this->output('export success');
}
} else {
$this->output('no data');
}
}
/**
* 创建指定服务器所有项目主站生成任务
* @author Akun
* @date 2024/12/19 17:54
*/
public function create_server_update_page()
{
$server_id = 15;
$server_ip_model = new ServersIp();
$server_ip_ids = $server_ip_model->where('servers_id', $server_id)->get()->pluck('id')->toArray();
$project_list = Project::select(['id', 'serve_id'])->whereIn('serve_id', $server_ip_ids)->get();
$domain_model = new DomainInfo();
$notify_model = new Notify();
foreach ($project_list as $value) {
$project_id = $value->id;
$domain_info = $domain_model->read(['project_id' => $project_id, 'status' => 1], ['id', 'domain']);
if (!$domain_info) {
//过滤未绑定正式域名的项目
continue;
}
$domain = $domain_info['domain'];
//获取项目所在服务器
$serve_ip_info = $server_ip_model->read(['id' => $value->serve_id], ['domain', 'ip']);
if (!$serve_ip_info) {
$this->output('项目id:' . $project_id . ' | 未查询到服务器数据');
continue;
}
if (!check_domain_record($domain, $serve_ip_info)) {
$this->output('项目id:' . $project_id . ', domain:' . $domain . ' | 未解析到目标服务器');
continue;
}
$data = [
'project_id' => $project_id,
'type' => 1,
'route' => 1,
'server_id' => $server_id,
'status' => ['!=', Notify::STATUS_FINISH_SITEMAP]
];
$notify = $notify_model->read($data, ['id']);
if (!$notify) {
$data['data'] = Arr::a2s(['domain' => $domain, 'url' => null, 'language' => []]);
$data['status'] = Notify::STATUS_INIT;
$notify_model->add($data);
$this->output('项目id:' . $project_id . ', domain:' . $domain . ' | success');
}
}
}
/**
* 创建所有amp站页面生成任务
* @author Akun
* @date 2024/09/26 10:48
*/
public function create_all_amp_notify()
{
$notify_model = new Notify();
$project_model = new Project();
$serve_ip_model = new ServersIp();
$domain_list = DomainInfo::where('status', 1)->where('amp_status', 1)->get();
foreach ($domain_list as $domain_info) {
$project_id = $domain_info->project_id;
$domain = $domain_info->domain;
$domain_array = parse_url($domain);
$host = $domain_array['host'] ?? $domain_array['path'];
$host_array = explode('.', $host);
if (count($host_array) <= 2) {
array_unshift($host_array, 'm');
} else {
$host_array[0] = 'm';
}
$amp_domain = implode('.', $host_array);
//获取项目所在服务器
$project_info = $project_model->read(['id' => $project_id], ['serve_id']);
if (!$project_info) {
$this->output('项目id:' . $project_id . ' | 未查询到项目数据');
continue;
}
$serve_ip_info = $serve_ip_model->read(['id' => $project_info['serve_id']], ['servers_id', 'domain', 'ip']);
if (!$serve_ip_info) {
$this->output('项目id:' . $project_id . ' | 未查询到服务器数据');
continue;
}
if ($serve_ip_info['servers_id'] != ServerConfig::SELF_SITE_ID) {
if (!check_domain_record($amp_domain, $serve_ip_info)) {
$this->output('项目id:' . $project_id . ', domain:' . $domain . ' | 未解析到目标服务器');
continue;
}
}
//判断是否已有更新进行中
$data = [
'project_id' => $project_id,
'type' => 3,
'route' => 1,
'server_id' => $serve_ip_info['servers_id'],
'status' => ['!=', Notify::STATUS_FINISH_SITEMAP]
];
$notify = $notify_model->read($data, ['id']);
if (!$notify) {
$data['data'] = Arr::a2s(['domain' => $amp_domain, 'url' => [], 'language' => []]);
$data['status'] = Notify::STATUS_INIT;
if ($serve_ip_info['servers_id'] == 2) {
$data['is_pull_html_zip'] = Notify::IS_PULL_HTML_ZIP_TRUE;
}
$notify_model->add($data);
}
$this->output('项目id:' . $project_id . ', domain:' . $domain . ' | success');
}
}
public function output($msg)
{
echo date('Y-m-d H:i:s') . ' | ' . $msg . PHP_EOL;
}
}