Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into develop
正在显示
6 个修改的文件
包含
143 行增加
和
30 行删除
| @@ -38,14 +38,13 @@ class HtmlCollect extends Command | @@ -38,14 +38,13 @@ class HtmlCollect extends Command | ||
| 38 | public function handle() | 38 | public function handle() |
| 39 | { | 39 | { |
| 40 | // while (true) { | 40 | // while (true) { |
| 41 | - $this->start_update(); | 41 | + $this->start_collect(); |
| 42 | // } | 42 | // } |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | - protected function start_update() | 45 | + protected function start_collect() |
| 46 | { | 46 | { |
| 47 | -// $task_id = $this->get_task(); | ||
| 48 | - $task_id = '298_1'; | 47 | + $task_id = $this->get_task(); |
| 49 | if ($task_id === false) { | 48 | if ($task_id === false) { |
| 50 | //所有项目采集完成 | 49 | //所有项目采集完成 |
| 51 | sleep(60); | 50 | sleep(60); |
| @@ -70,7 +69,7 @@ class HtmlCollect extends Command | @@ -70,7 +69,7 @@ class HtmlCollect extends Command | ||
| 70 | return true; | 69 | return true; |
| 71 | } | 70 | } |
| 72 | 71 | ||
| 73 | - echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', task_type: ' . $collect_id . ', collect start' . PHP_EOL; | 72 | + echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', collect start' . PHP_EOL; |
| 74 | 73 | ||
| 75 | $collect_info->status = CollectTask::STATUS_ING; | 74 | $collect_info->status = CollectTask::STATUS_ING; |
| 76 | $collect_info->save(); | 75 | $collect_info->save(); |
| @@ -84,7 +83,7 @@ class HtmlCollect extends Command | @@ -84,7 +83,7 @@ class HtmlCollect extends Command | ||
| 84 | $html = $this->upload_source($html, $source_list, $project_id); | 83 | $html = $this->upload_source($html, $source_list, $project_id); |
| 85 | } | 84 | } |
| 86 | } catch (\Exception $e) { | 85 | } catch (\Exception $e) { |
| 87 | - echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', task_type: ' . $collect_id . ', error: ' . $e->getMessage() . PHP_EOL; | 86 | + echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: ' . $e->getMessage() . PHP_EOL; |
| 88 | return true; | 87 | return true; |
| 89 | } | 88 | } |
| 90 | 89 | ||
| @@ -92,7 +91,7 @@ class HtmlCollect extends Command | @@ -92,7 +91,7 @@ class HtmlCollect extends Command | ||
| 92 | $collect_info->status = CollectTask::STATUS_COM; | 91 | $collect_info->status = CollectTask::STATUS_COM; |
| 93 | $collect_info->save(); | 92 | $collect_info->save(); |
| 94 | 93 | ||
| 95 | - echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', task_type: ' . $collect_id . ', collect end' . PHP_EOL; | 94 | + echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', collect end' . PHP_EOL; |
| 96 | } | 95 | } |
| 97 | //关闭数据库 | 96 | //关闭数据库 |
| 98 | DB::disconnect('custom_mysql'); | 97 | DB::disconnect('custom_mysql'); |
| @@ -150,7 +149,7 @@ class HtmlCollect extends Command | @@ -150,7 +149,7 @@ class HtmlCollect extends Command | ||
| 150 | return $source; | 149 | return $source; |
| 151 | } | 150 | } |
| 152 | 151 | ||
| 153 | - //图片 | 152 | + //image |
| 154 | preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_img); | 153 | preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_img); |
| 155 | $img = $result_img[2] ?? []; | 154 | $img = $result_img[2] ?? []; |
| 156 | foreach ($img as $vi) { | 155 | foreach ($img as $vi) { |
| @@ -182,6 +181,15 @@ class HtmlCollect extends Command | @@ -182,6 +181,15 @@ class HtmlCollect extends Command | ||
| 182 | $check_vc && $source[] = $check_vc; | 181 | $check_vc && $source[] = $check_vc; |
| 183 | } | 182 | } |
| 184 | 183 | ||
| 184 | + //css background | ||
| 185 | + preg_match_all("/url\(['\"]?(\s*[^>]+?)['\"]?\)/i", $html, $result_css_b); | ||
| 186 | + $css_b = $result_css_b[1] ?? []; | ||
| 187 | + foreach ($css_b as $vc_b) { | ||
| 188 | + $check_vc_b = $this->url_check($vc_b, $project_id, $domain); | ||
| 189 | + $check_vc_b && $source[] = $check_vc_b; | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + | ||
| 185 | return $source; | 193 | return $source; |
| 186 | } | 194 | } |
| 187 | 195 | ||
| @@ -194,9 +202,11 @@ class HtmlCollect extends Command | @@ -194,9 +202,11 @@ class HtmlCollect extends Command | ||
| 194 | $host = $arr['host'] ?? ''; | 202 | $host = $arr['host'] ?? ''; |
| 195 | $path = $arr['path'] ?? ''; | 203 | $path = $arr['path'] ?? ''; |
| 196 | 204 | ||
| 197 | - if ((strpos($host, '.globalso.') === false) | ||
| 198 | - && (strpos($host, '.goodao.') === false) | ||
| 199 | - && $path && (strpos($path, '.') !== false)) { | 205 | + if ( |
| 206 | + (strpos($host, '.globalso.') === false) && | ||
| 207 | + (strpos($host, '.goodao.') === false) && | ||
| 208 | + $path && (strpos($path, '.') !== false) | ||
| 209 | + ) { | ||
| 200 | 210 | ||
| 201 | $source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first(); | 211 | $source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first(); |
| 202 | if (!$source) { | 212 | if (!$source) { |
| @@ -236,6 +246,50 @@ class HtmlCollect extends Command | @@ -236,6 +246,50 @@ class HtmlCollect extends Command | ||
| 236 | 'updated_at' => date('Y-m-d H:i:s'), | 246 | 'updated_at' => date('Y-m-d H:i:s'), |
| 237 | ]); | 247 | ]); |
| 238 | $html = str_replace($vs['url'], getImageUrl($new_source), $html); | 248 | $html = str_replace($vs['url'], getImageUrl($new_source), $html); |
| 249 | + | ||
| 250 | + if (substr($new_source, -3, 3) == 'css') { | ||
| 251 | + // 下载css文件中的资源 | ||
| 252 | + $css_html = file_get_contents($vs['url_complete']); | ||
| 253 | + preg_match_all("/url\(['\"](\s*[^>]+?)['\"]\)/i", $css_html, $result_css_source); | ||
| 254 | + $css_source = $result_css_source[1] ?? []; | ||
| 255 | + | ||
| 256 | + $url_arr = explode('/', $vs['url_complete']); | ||
| 257 | + $target_arr = explode('/', $new_source); | ||
| 258 | + foreach ($css_source as $vcs) { | ||
| 259 | + $vcs_arr = parse_url($vcs); | ||
| 260 | + if (isset($vcs_arr['domain'])) { | ||
| 261 | + //不是相对路径,不下载 | ||
| 262 | + continue; | ||
| 263 | + } | ||
| 264 | + | ||
| 265 | + $vcs = $vcs_arr['path'] ?? ''; | ||
| 266 | + if (!$vcs) { | ||
| 267 | + continue; | ||
| 268 | + } | ||
| 269 | + | ||
| 270 | + $source_info = CollectSource::where('project_id', $project_id)->where('origin', $vcs)->first(); | ||
| 271 | + if ($source_info) { | ||
| 272 | + //已存在,不下载 | ||
| 273 | + continue; | ||
| 274 | + } | ||
| 275 | + | ||
| 276 | + $url_arr[count($url_arr) - 1] = $vcs; | ||
| 277 | + $url_css_complete = implode('/', $url_arr); | ||
| 278 | + $target_arr[count($target_arr) - 1] = $vcs; | ||
| 279 | + $path = implode('/', $target_arr); | ||
| 280 | + | ||
| 281 | + $new_source_css = CosService::uploadRemote($project_id, 'source', $url_css_complete, $path); | ||
| 282 | + if ($new_source_css) { | ||
| 283 | + CollectSource::insert([ | ||
| 284 | + 'project_id' => $project_id, | ||
| 285 | + 'origin' => $vcs, | ||
| 286 | + 'target' => $new_source_css, | ||
| 287 | + 'created_at' => date('Y-m-d H:i:s'), | ||
| 288 | + 'updated_at' => date('Y-m-d H:i:s'), | ||
| 289 | + ]); | ||
| 290 | + } | ||
| 291 | + } | ||
| 292 | + } | ||
| 239 | } | 293 | } |
| 240 | } else { | 294 | } else { |
| 241 | $html = str_replace($vs['url'], getImageUrl($vs['url_complete']), $html); | 295 | $html = str_replace($vs['url'], getImageUrl($vs['url_complete']), $html); |
| @@ -421,17 +421,19 @@ if (!function_exists('getImageUrl')) { | @@ -421,17 +421,19 @@ if (!function_exists('getImageUrl')) { | ||
| 421 | * @time :2023/7/20 16:46 | 421 | * @time :2023/7/20 16:46 |
| 422 | */ | 422 | */ |
| 423 | function getImageUrl($path,$location = 1){ | 423 | function getImageUrl($path,$location = 1){ |
| 424 | - if(empty($path)){ | ||
| 425 | - return ''; | ||
| 426 | - } | ||
| 427 | - if((strpos($path,'https://')!== false) || (strpos($path,'http://') !== false)){ | ||
| 428 | - return $path; | ||
| 429 | - } | ||
| 430 | if(is_array($path)){ | 424 | if(is_array($path)){ |
| 425 | + $url =[]; | ||
| 431 | foreach ($path as $v){ | 426 | foreach ($path as $v){ |
| 432 | $url[] = getImageUrl($v); | 427 | $url[] = getImageUrl($v); |
| 433 | } | 428 | } |
| 429 | + $url = array_filter($url); | ||
| 434 | }else{ | 430 | }else{ |
| 431 | + if(empty($path)){ | ||
| 432 | + return ''; | ||
| 433 | + } | ||
| 434 | + if((strpos($path,'https://')!== false) || (strpos($path,'http://') !== false)){ | ||
| 435 | + return $path; | ||
| 436 | + } | ||
| 435 | if($location == 1){ | 437 | if($location == 1){ |
| 436 | $cos = config('filesystems.disks.cos'); | 438 | $cos = config('filesystems.disks.cos'); |
| 437 | $cosCdn = $cos['cdn']; | 439 | $cosCdn = $cos['cdn']; |
| @@ -92,9 +92,9 @@ class CollectLogic extends Logic | @@ -92,9 +92,9 @@ class CollectLogic extends Logic | ||
| 92 | 'title' => $item['title'], | 92 | 'title' => $item['title'], |
| 93 | 'url' => $this->domain . $item['route'], | 93 | 'url' => $this->domain . $item['route'], |
| 94 | 'keywords' => $keyword, | 94 | 'keywords' => $keyword, |
| 95 | - 'description' => strip_tags($item['intro']?:''), | 95 | + 'desc' => strip_tags($item['intro']?:''), |
| 96 | 'content' => strip_tags($item['content'] ?: ''), | 96 | 'content' => strip_tags($item['content'] ?: ''), |
| 97 | - 'img' => array_column($item['gallery'] ?: [], 'url') | 97 | + 'images' => getImageUrl(array_column($item['gallery'] ?: [], 'url')) |
| 98 | ]; | 98 | ]; |
| 99 | } | 99 | } |
| 100 | $list['list'] = $data; | 100 | $list['list'] = $data; |
| @@ -114,9 +114,9 @@ class CollectLogic extends Logic | @@ -114,9 +114,9 @@ class CollectLogic extends Logic | ||
| 114 | 'title' => $item['name'], | 114 | 'title' => $item['name'], |
| 115 | 'url' => $this->domain . $item['url'], | 115 | 'url' => $this->domain . $item['url'], |
| 116 | 'keywords' => $item['seo_keywords'], | 116 | 'keywords' => $item['seo_keywords'], |
| 117 | - 'description' => strip_tags($item['remark']?:''), | 117 | + 'desc' => strip_tags($item['remark']?:''), |
| 118 | 'content' => strip_tags($item['text'] ?: ''), | 118 | 'content' => strip_tags($item['text'] ?: ''), |
| 119 | - 'img' => $item['image'] ?:'' | 119 | + 'images' => getImageUrl([$item['image']] ?:[]) |
| 120 | ]; | 120 | ]; |
| 121 | } | 121 | } |
| 122 | $list['list'] = $data; | 122 | $list['list'] = $data; |
| @@ -136,9 +136,9 @@ class CollectLogic extends Logic | @@ -136,9 +136,9 @@ class CollectLogic extends Logic | ||
| 136 | 'title' => $item['name'], | 136 | 'title' => $item['name'], |
| 137 | 'url' => $this->domain . $item['url'], | 137 | 'url' => $this->domain . $item['url'], |
| 138 | 'keywords' => $item['seo_keywords'], | 138 | 'keywords' => $item['seo_keywords'], |
| 139 | - 'description' => strip_tags($item['remark']?:''), | 139 | + 'desc' => strip_tags($item['remark']?:''), |
| 140 | 'content' => strip_tags($item['text'] ?: ''), | 140 | 'content' => strip_tags($item['text'] ?: ''), |
| 141 | - 'img' => $item['image'] ?:'' | 141 | + 'images' => getImageUrl([$item['image']] ?:[]) |
| 142 | ]; | 142 | ]; |
| 143 | } | 143 | } |
| 144 | $list['list'] = $data; | 144 | $list['list'] = $data; |
| @@ -12,6 +12,7 @@ use App\Utils\HttpUtils; | @@ -12,6 +12,7 @@ use App\Utils\HttpUtils; | ||
| 12 | use GuzzleHttp\Client; | 12 | use GuzzleHttp\Client; |
| 13 | use GuzzleHttp\Exception\GuzzleException; | 13 | use GuzzleHttp\Exception\GuzzleException; |
| 14 | use Illuminate\Support\Carbon; | 14 | use Illuminate\Support\Carbon; |
| 15 | +use Symfony\Component\Process\Process; | ||
| 15 | 16 | ||
| 16 | class DomainInfoLogic extends BaseLogic | 17 | class DomainInfoLogic extends BaseLogic |
| 17 | { | 18 | { |
| @@ -226,4 +227,44 @@ class DomainInfoLogic extends BaseLogic | @@ -226,4 +227,44 @@ class DomainInfoLogic extends BaseLogic | ||
| 226 | return $this->success(); | 227 | return $this->success(); |
| 227 | } | 228 | } |
| 228 | 229 | ||
| 230 | + | ||
| 231 | + /** | ||
| 232 | + * 验证是否cname或者A记录解析到目标服务器 | ||
| 233 | + * @param $domain | ||
| 234 | + * @param $server_info | ||
| 235 | + * @return mixed | ||
| 236 | + * @author zbj | ||
| 237 | + * @date 2023/11/13 | ||
| 238 | + */ | ||
| 239 | + public function check_cname($domain, $server_info){ | ||
| 240 | + $checkA = false; | ||
| 241 | + $checkCname = false; | ||
| 242 | + | ||
| 243 | + $process = new Process(['nslookup', '-qt=a', $domain]); | ||
| 244 | + $process->run(); | ||
| 245 | + $output = explode(PHP_EOL, $process->getOutput()); | ||
| 246 | + foreach ($output as $line){ | ||
| 247 | + if($line){ | ||
| 248 | + $checkA = strpos($line, $server_info['host']) !== false; | ||
| 249 | + } | ||
| 250 | + } | ||
| 251 | + if($checkA){ | ||
| 252 | + return $domain; | ||
| 253 | + } | ||
| 254 | + | ||
| 255 | + //是否cname | ||
| 256 | + $process = new Process(['nslookup', '-qt=cname', $domain]); | ||
| 257 | + $process->run(); | ||
| 258 | + $output = explode(PHP_EOL, $process->getOutput()); | ||
| 259 | + foreach ($output as $line){ | ||
| 260 | + if($line){ | ||
| 261 | + $checkCname = (strpos($line, $server_info['init_domain']) !== false); | ||
| 262 | + } | ||
| 263 | + } | ||
| 264 | + if($checkCname){ | ||
| 265 | + return $domain; | ||
| 266 | + | ||
| 267 | + } | ||
| 268 | + return false; | ||
| 269 | + } | ||
| 229 | } | 270 | } |
| @@ -2,6 +2,8 @@ | @@ -2,6 +2,8 @@ | ||
| 2 | 2 | ||
| 3 | namespace App\Http\Logic\Aside\Project; | 3 | namespace App\Http\Logic\Aside\Project; |
| 4 | 4 | ||
| 5 | +use App\Enums\Common\Code; | ||
| 6 | +use App\Exceptions\AsideGlobalException; | ||
| 5 | use App\Models\Com\NoticeLog; | 7 | use App\Models\Com\NoticeLog; |
| 6 | use App\Models\Devops\ServerConfig; | 8 | use App\Models\Devops\ServerConfig; |
| 7 | use App\Models\Project\ProjectRenew; | 9 | use App\Models\Project\ProjectRenew; |
| @@ -36,6 +38,7 @@ use Illuminate\Support\Facades\DB; | @@ -36,6 +38,7 @@ use Illuminate\Support\Facades\DB; | ||
| 36 | use Illuminate\Support\Facades\Log; | 38 | use Illuminate\Support\Facades\Log; |
| 37 | use Illuminate\Support\Facades\Schema; | 39 | use Illuminate\Support\Facades\Schema; |
| 38 | use Illuminate\Support\Str; | 40 | use Illuminate\Support\Str; |
| 41 | +use App\Http\Logic\Aside\Domain\DomainInfoLogic; | ||
| 39 | 42 | ||
| 40 | /** | 43 | /** |
| 41 | * Class ProjectLogic | 44 | * Class ProjectLogic |
| @@ -130,6 +133,9 @@ class ProjectLogic extends BaseLogic | @@ -130,6 +133,9 @@ class ProjectLogic extends BaseLogic | ||
| 130 | $this->createSite($this->param); | 133 | $this->createSite($this->param); |
| 131 | } | 134 | } |
| 132 | DB::commit(); | 135 | DB::commit(); |
| 136 | + }catch (AsideGlobalException $e){ | ||
| 137 | + DB::rollBack(); | ||
| 138 | + $this->fail($e->getMessage()); | ||
| 133 | }catch (\Exception $e){ | 139 | }catch (\Exception $e){ |
| 134 | DB::rollBack(); | 140 | DB::rollBack(); |
| 135 | $this->fail('请填写完整后再提交'); | 141 | $this->fail('请填写完整后再提交'); |
| @@ -505,18 +511,24 @@ class ProjectLogic extends BaseLogic | @@ -505,18 +511,24 @@ class ProjectLogic extends BaseLogic | ||
| 505 | /** | 511 | /** |
| 506 | * 创建站点 | 512 | * 创建站点 |
| 507 | * @param $param | 513 | * @param $param |
| 514 | + * @throws AsideGlobalException | ||
| 508 | * @author Akun | 515 | * @author Akun |
| 509 | * @date 2023/10/17 10:04 | 516 | * @date 2023/10/17 10:04 |
| 510 | */ | 517 | */ |
| 511 | public function createSite($param){ | 518 | public function createSite($param){ |
| 512 | if(isset($param['serve_id']) && $param['serve_id'] && isset($param['deploy_optimize']['domain']) && $param['deploy_optimize']['domain']){ | 519 | if(isset($param['serve_id']) && $param['serve_id'] && isset($param['deploy_optimize']['domain']) && $param['deploy_optimize']['domain']){ |
| 513 | $server_model = new ServerConfig(); | 520 | $server_model = new ServerConfig(); |
| 514 | - $server_info = $server_model->read(['id'=>$param['serve_id']],'init_domain'); | 521 | + $server_info = $server_model->read(['id'=>$param['serve_id']],['init_domain','host']); |
| 515 | 522 | ||
| 516 | $domain_model = new DomainInfo(); | 523 | $domain_model = new DomainInfo(); |
| 517 | $domain_info = $domain_model->read(['id'=>$param['deploy_optimize']['domain']],'domain'); | 524 | $domain_info = $domain_model->read(['id'=>$param['deploy_optimize']['domain']],'domain'); |
| 518 | 525 | ||
| 519 | if($server_info && $domain_info){ | 526 | if($server_info && $domain_info){ |
| 527 | + | ||
| 528 | + //验证解析 | ||
| 529 | + if (!DomainInfoLogic::instance()->check_cname($domain_info['domain'], $server_info)) { | ||
| 530 | + throw new AsideGlobalException(Code::SYSTEM_ERROR,'域名' . $domain_info['domain'] . '未解析至目标服务器'); | ||
| 531 | + } | ||
| 520 | $api_url = 'http://'.$server_info['init_domain'].'/api/createSite'; | 532 | $api_url = 'http://'.$server_info['init_domain'].'/api/createSite'; |
| 521 | $api_param = ['domain'=>$domain_info['domain']]; | 533 | $api_param = ['domain'=>$domain_info['domain']]; |
| 522 | try { | 534 | try { |
| @@ -68,18 +68,23 @@ class CosService | @@ -68,18 +68,23 @@ class CosService | ||
| 68 | * @param $project_id | 68 | * @param $project_id |
| 69 | * @param $image_type | 69 | * @param $image_type |
| 70 | * @param $file_url | 70 | * @param $file_url |
| 71 | + * @param $key | ||
| 71 | * @return string | 72 | * @return string |
| 72 | * @author Akun | 73 | * @author Akun |
| 73 | * @date 2023/09/21 9:39 | 74 | * @date 2023/09/21 9:39 |
| 74 | */ | 75 | */ |
| 75 | - public static function uploadRemote($project_id,$image_type,$file_url) | 76 | + public static function uploadRemote($project_id,$image_type,$file_url,$key='') |
| 76 | { | 77 | { |
| 77 | - $ext = explode('.',$file_url); | 78 | + if(!$key){ |
| 79 | + $ext = explode('.',$file_url); | ||
| 78 | 80 | ||
| 79 | - $filename = uniqid().rand(10000,99999).'.'.end($ext); | 81 | + $filename = uniqid().rand(10000,99999).'.'.end($ext); |
| 82 | + | ||
| 83 | + $uploads = config('upload.default_file'); | ||
| 84 | + $path = $uploads['path_b'].'/'.$project_id.'/'.$image_type.'/'.date('Y-m'); | ||
| 85 | + $key = $path.'/'.$filename; | ||
| 86 | + } | ||
| 80 | 87 | ||
| 81 | - $uploads = config('upload.default_file'); | ||
| 82 | - $path = $uploads['path_b'].'/'.$project_id.'/'.$image_type.'/'.date('Y-m'); | ||
| 83 | $cos = config('filesystems.disks.cos'); | 88 | $cos = config('filesystems.disks.cos'); |
| 84 | $cosClient = new Client([ | 89 | $cosClient = new Client([ |
| 85 | 'region' => $cos['region'], | 90 | 'region' => $cos['region'], |
| @@ -88,7 +93,6 @@ class CosService | @@ -88,7 +93,6 @@ class CosService | ||
| 88 | 'secretKey' => $cos['credentials']['secretKey'], | 93 | 'secretKey' => $cos['credentials']['secretKey'], |
| 89 | ], | 94 | ], |
| 90 | ]); | 95 | ]); |
| 91 | - $key = $path.'/'.$filename; | ||
| 92 | try { | 96 | try { |
| 93 | $cosClient->putObject([ | 97 | $cosClient->putObject([ |
| 94 | 'Bucket' => $cos['bucket'], | 98 | 'Bucket' => $cos['bucket'], |
-
请 注册 或 登录 后发表评论