作者 赵彬吉
... ... @@ -9,7 +9,9 @@
namespace App\Console\Commands\Domain;
use App\Models\Devops\ServerConfig;
use App\Models\Project\CountryCustom;
use App\Models\Project\Project;
use Illuminate\Console\Command;
use App\Models\Domain\DomainInfo as DomainInfoModel;
... ... @@ -83,6 +85,7 @@ class DomainInfo extends Command
public function startUpdateCert()
{
$domainModel = new DomainInfoModel();
$projectModel = new Project();
$end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期
$list = $domainModel->where('status', '!=', 2)->where(function ($query) use ($end_day) {
$query->whereNull('certificate_end_time')->orWhere('certificate_end_time', '<', $end_day);
... ... @@ -95,8 +98,9 @@ class DomainInfo extends Command
$ssl['from'] && $data['certificate_start_time'] = $ssl['from'];
$ssl['to'] && $data['certificate_end_time'] = $ssl['to'];
if ($v['type'] == 1 && $ssl['to'] < $end_day) {
//申请免费证书
$project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']);
if ($v['type'] == 1 && $ssl['to'] < $end_day && $project_info['serve_id'] != ServerConfig::SELF_SITE_ID) {
//非自建站项目,申请免费证书
$this->updatePrivate($v);
$ssl_new = $this->updateDomainSsl($v['domain']);
... ... @@ -116,6 +120,7 @@ class DomainInfo extends Command
public function startUpdateAmpCert()
{
$domainModel = new DomainInfoModel();
$projectModel = new Project();
$end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期
$list = $domainModel->where('status', '!=', 2)->where('amp_status', 1)->where(function ($query) use ($end_day) {
$query->whereNull('amp_certificate_end_time')->orWhere('amp_certificate_end_time', '<', $end_day);
... ... @@ -137,8 +142,9 @@ class DomainInfo extends Command
$ssl['from'] && $data['amp_certificate_start_time'] = $ssl['from'];
$ssl['to'] && $data['amp_certificate_end_time'] = $ssl['to'];
if ($v['amp_type'] == 1 && $ssl['to'] < $end_day) {
//申请免费证书
$project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']);
if ($v['amp_type'] == 1 && $ssl['to'] < $end_day && $project_info['serve_id'] != ServerConfig::SELF_SITE_ID) {
//非自建站项目,申请免费证书
$this->updateAmpPrivate($v['domain']);
$ssl_new = $this->updateDomainSsl($v['domain']);
... ... @@ -283,9 +289,9 @@ class DomainInfo extends Command
],
]);
$stream = stream_socket_client('ssl://' . $domain . ':443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
if($stream){
if ($stream) {
$remote_cert = stream_context_get_params($stream)['options']['ssl']['peer_certificate'];
if($remote_cert){
if ($remote_cert) {
$valid_from = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validFrom_time_t']);
$valid_to = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validTo_time_t']);
}
... ...
... ... @@ -10,9 +10,13 @@
namespace App\Http\Controllers\Bside\BCom;
use App\Enums\Common\Code;
use App\Helper\Arr;
use App\Http\Controllers\Bside\BaseController;
use App\Models\Com\Notify;
use App\Models\Com\UpdateNotify;
use App\Models\Com\UpdateProgress;
use App\Models\Devops\ServerConfig;
use App\Models\Domain\DomainInfo;
use App\Models\Project\Country as CountryModel;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
... ... @@ -37,15 +41,66 @@ class CNoticeController extends BaseController
*/
public function sendNotify(Request $request)
{
$url = $this->user['domain'].'api/update_page/';
$param = [
'project_id' => $this->user['project_id'],
'type' => intval($request->input('type', 1)),
'route' => intval($request->input('page', 1)),
'url' => $request->input('url', []),
'language'=> $request->input('language', []),
];
http_post($url, json_encode($param));
$project_id = $this->user['project_id'];
$type = intval($request->input('type', 1));
$route = intval($request->input('page', 1));
$url = $request->input('url', []);
$language = $request->input('language', []);
$is_sitemap = intval($request->input('is_sitemap', 0));
//获取项目所在服务器
$project_model = new Project();
$project_info = $project_model->read(['id'=>$project_id],['serve_id']);
if($project_info && $project_info['serve_id'] == ServerConfig::SELF_SITE_ID){
//自建站服务器:如果项目已经上线,不请求C端接口,数据直接入库
$domain_model = new DomainInfo();
$domain_info = $domain_model->read(['project_id'=>$this->user['project_id']],['domain']);
if($domain_info){
//判断是否已有更新进行中
$notify_model = new Notify();
$data = [
'project_id' => $project_id,
'type' => $type,
'route' => $route,
'server_id' => ServerConfig::SELF_SITE_ID,
'status' => ['<',Notify::STATUS_FINISH_PAGE]
];
$notify = $notify_model->read($data,['id']);
if(!$notify){
$domain = $domain_info['domain'];
if($type == Notify::TYPE_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';
}
$domain = implode('.',$host_array);
}
$data['data'] = Arr::a2s(['domain'=>$domain,'url'=>$url,'language'=>$language]);
$data['status'] = $is_sitemap == 1 ? Notify::STATUS_FINISH_PAGE : Notify::STATUS_INIT;
$notify_model->add($data);
}
}
}else{
//其他服务器:请求对应C端接口
$c_url = $this->user['domain'].'api/update_page/';
$param = [
'project_id' => $this->user['project_id'],
'type' => $type,
'route' => $route,
'url' => $url,
'language'=> $language,
'is_sitemap' => $is_sitemap
];
http_post($c_url, json_encode($param));
}
$this->response('更新中请稍后, 更新完成将会发送站内信通知更新结果!');
}
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Http\Controllers\File;
use App\Enums\Common\Code;
use App\Helper\Translate;
use App\Jobs\SyncImageFileJob;
use App\Models\File\ErrorFile;
use App\Models\File\File;
use App\Models\File\Image as ImageModel;
... ... @@ -146,13 +147,7 @@ class FileController
*/
public function synchronizationFile($fileName){
//同步到大文件
$file_path = config('filesystems.disks.cos')['cdn1'].$this->path.'/'.$fileName;
$cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$this->path.'" https://v6-file.globalso.com/upload.php';
$code = shell_exec($cmd);
if(200 != (int)$code){
$errorFileModel = new ErrorFile();
$errorFileModel->add(['path'=>$this->path.'/'.$fileName]);
}
SyncImageFileJob::dispatch(['path'=>$this->path,'name'=>$fileName]);
return true;
}
... ...
... ... @@ -204,6 +204,7 @@ class ImageController extends Controller
$this->response('不支持当前格式',Code::SYSTEM_ERROR);
}
$fileName = $this->getOnlyFilename($name,$param['project_id'] ?? 0);
//上传到cos
if($this->upload_location == 0){
$cosService = new CosService();
... ... @@ -265,13 +266,6 @@ class ImageController extends Controller
*/
public function synchronizationImage($fileName){
SyncImageFileJob::dispatch(['path'=>$this->path,'name'=>$fileName]);
// $file_path = getImageUrl($this->path.'/'.$fileName,$this->cache['storage_type'] ?? 0);
// $cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$this->path.'" https://v6-file.globalso.com/upload.php';
// $code = shell_exec($cmd);
// if(200 != (int)$code){
// $errorFileModel = new ErrorFile();
// $errorFileModel->add(['path'=>$this->path.'/'.$fileName]);
// }
return true;
}
... ...
... ... @@ -266,6 +266,9 @@ class DomainInfoLogic extends BaseLogic
if($project_info['serve_id'] == 9){
$this->fail('请切换服务器,生成站点不能使用测试服务器');
}
if($project_info['serve_id'] == ServerConfig::SELF_SITE_ID){
$this->fail('自建站服务器无法生成站点');
}
//域名是否都已经解析
if(!empty($info['domain']) && !$this->check_cname($info['domain'], $server_info)){
$this->fail('域名' . $info['domain'] . '未解析至目标服务器');
... ...
... ... @@ -7,6 +7,7 @@ use App\Enums\Common\Common;
use App\Exceptions\BsideGlobalException;
use App\Http\Logic\Logic;
use App\Models\Com\UpdateNotify;
use App\Models\Devops\ServerConfig;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteDelete;
use App\Models\Service\Service;
... ... @@ -174,6 +175,10 @@ class BaseLogic extends Logic
$data['project_id'] = $this->user['project_id'];
$str = http_build_query($data);
$url = $this->user['domain'].'api/delHtml/?'.$str;
if(isset($this->project['serve_id']) && ($this->project['serve_id'] == ServerConfig::SELF_SITE_ID)){
//自建站服务器直接返回
return $this->success();
}
if(isset($this->project['serve_id']) && ($this->project['serve_id'] != 1)){//TODO::当前项目通知不过 ,跳过自动更新
exec('curl -k "'.$url.'" > /dev/null 2>&1 &');
}else{
... ...
... ... @@ -11,6 +11,7 @@ namespace App\Http\Logic\Bside\Setting;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Com\UpdateLog;
use App\Models\RouteMap\RouteMap;
use App\Models\User\UserLog;
use App\Models\WebSetting\Translate as TranslateModel;
use App\Models\WebSetting\WebLanguage;
... ... @@ -284,6 +285,37 @@ class TranslateLogic extends BaseLogic
}
/**
* @remark :根据路由获取source+source_id
* @name :getRouteSource
* @author :lyh
* @method :post
* @time :2024/5/17 15:11
*/
public function getRouteSource($route){
$data = ['source'=>0,'source_id'=>0,'is_list'=>0,'is_custom'=>0];
if(strtolower($route) == 'all'){
return $this->success($data);
}
if($route == '/'){
$data['source'] = 1;
return $this->success($data);
}
$route = basename($route);
$routeModel = new RouteMap();
$routeInfo = $routeModel->read(['route'=>$route]);
if($routeInfo['source'] == RouteMap::SOURCE_PAGE){
if($routeInfo['source_id']){
$data = ['source'=>9,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>0];
}
}
if($routeInfo['source'] == RouteMap::SOURCE_PAGE){
if($routeInfo['source_id']){
$data = ['source'=>9,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>0];
}
}
}
/**
* @remark :处理路由
* @name :handleRoute
* @author :lyh
... ...
... ... @@ -15,10 +15,11 @@ class Notify extends Base
const STATUS_FINISH_PAGE = 2;
/**
* 类型 1:主站, 2:小语种
* 类型 1:主站, 2:小语种, 3:amp
*/
const TYPE_MASTER = 1;
const TYPE_MINOR = 2;
const TYPE_AMP = 3;
/**
* 路由
... ...
... ... @@ -34,6 +34,8 @@ class ServerConfig extends Base
const STATUS_ONE = 1;
const SELF_SITE_ID = 8;//自建站服务器ID
/**
* @remark :获取数据用户名解密
* @name :getUserAttribute
... ...