作者 lyh

修改脚本设置

... ... @@ -47,36 +47,23 @@ class Demo extends Command
protected $description = 'demo';
public function handle(){
$serverConfigModel = new ServerConfig();
$lists = $serverConfigModel->list(['type'=>1],'id',['*'],'asc');
$serverIpModel = new ServersIp();
$lists = $serverIpModel->list();
foreach ($lists as $v){
echo date('Y-m-d H:i:s') . 'title数据:'.$v['title'] . PHP_EOL;
$encrypt = new EncryptUtils();
$param = [
'server_name'=>$v['title'],
'being_number'=>$v['count'],
'ip_total'=>1,
'account'=>$encrypt->lock_url($v['user']),
'password'=>$encrypt->lock_url($v['password']),
'port'=>$encrypt->lock_url($v['port']),
'bt_account'=>$v['bt_account'],
'bt_password'=>$v['bt_password'],
'service_type'=>$v['service_type'],
'domain'=>'globalso.com',
];
$serverModel = new Servers();
$server_id = $serverModel->addReturnId($param);
echo date('Y-m-d H:i:s') . 'server_id:'.$server_id . PHP_EOL;
$paramsIp = [
'id'=>$v['id'],
'ip'=>$v['host'],
'servers_id'=>$server_id,
'domain'=>$v['init_domain'],
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s')
];
$serverIpModel = new ServersIp();
$serverIpModel->insert($paramsIp);
$num = 0;
$str = '';
$projectModel = new Project();
$project_list = $projectModel->list(['serve_id'=>$v['id']],['id']);
if(!empty($project_list)){
foreach ($project_list as $value){
$str .= $value['id'].',';
$num++;
}
if(!empty($str)){
$str = ','.$str;
}
$serverIpModel->edit(['total'=>$num,'project_arr'=>$str],['id'=>$v['id']]);
}
}
return true;
}
... ...
... ... @@ -53,109 +53,6 @@ class Temp extends Command
$this->output('end');
}
// public function handle()
// {
// $domain_model = new DomainInfo();
// $notify_model = new Notify();
// $project_model = new Project();
//
// $domain_list = $domain_model->list(['amp_status' => 1]);
// foreach ($domain_list as $info) {
// if ($info['project_id'] > 0) {
// $notify_info = $notify_model->read(['project_id' => $info['project_id'], 'type' => 3]);
// if (!$notify_info) {
//
// $domain_array = parse_url($info['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' => $info['project_id']]);
//
// $notify_model->add([
// 'project_id' => $info['project_id'],
// 'type' => 3,
// 'data' => json_encode(['domain' => $amp_domain, 'url' => [], 'language' => []]),
// 'server_id' => $project_info['serve_id'],
// ]);
// }
// }
// }
// }
// public function handle()
// {
// $domain_model = new DomainInfo();
// $server_model = new ServerConfig();
// $project_model = new Project();
//
// $domain_list = $domain_model->list(['domain' => ['like', 'www.%']], 'id', ['id', 'domain', 'project_id'], 'asc');
// foreach ($domain_list as $info) {
// $this->output('domain:' . $info['domain'] . ',开始');
//
// $project_info = $project_model->read(['id' => $info['project_id']], 'serve_id');
// if ($project_info === false) {
// $this->output('获取项目数据失败');
// continue;
// }
//
// $server_info = $server_model->read(['id' => $project_info['serve_id']], ['init_domain', 'host']);
// if ($server_info === false) {
// $this->output('获取服务器数据失败');
// continue;
// }
//
// $domain_array = parse_url($info['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);
// if (!$this->check_cname($amp_domain, $server_info)) {
// $this->output('AMP站点域名' . $amp_domain . '未解析至目标服务器');
// continue;
// }
//
// $api_url = 'http://' . $server_info['init_domain'] . '/api/createSiteAmp';
// $api_param = [
// 'domain' => $info['domain'],
// 'private_key' => '',
// 'cert' => ''
// ];
//
// try {
// $rs = HttpUtils::get($api_url, $api_param);
// $rs = json_decode($rs, true);
// if (isset($rs['status']) && $rs['status'] == 200) {
// $this->output('创建AMP站点成功');
// } else {
// $this->output($rs['message'] ?? '');
// continue;
// }
// } catch (\Exception | GuzzleException $e) {
// errorLog('创建AMP站点', $api_param, $e);
// $this->output('创建AMP站点失败');
// continue;
// }
//
// $data = [
// 'amp_status' => 1,
// 'amp_type' => 1,
// ];
// $domain_model->edit($data, ['id' => $info['id']]);
// }
//
// echo '成功' . PHP_EOL;
// }
public function check_cname($domain, $server_info)
{
$checkA = false;
... ... @@ -166,7 +63,7 @@ class Temp extends Command
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line) {
if ($line) {
$checkA = strpos($line, $server_info['host']) !== false;
$checkA = strpos($line, $server_info['ip']) !== false;
if ($checkA) {
return $domain;
}
... ... @@ -179,7 +76,7 @@ class Temp extends Command
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line) {
if ($line) {
$checkCname = (strpos($line, $server_info['init_domain']) !== false);
$checkCname = (strpos($line, $server_info['domain']) !== false);
if ($checkCname) {
return $domain;
}
... ...
... ... @@ -68,14 +68,13 @@ class ServersIpController extends BaseController
* @method :post
* @time :2024/6/25 14:52
*/
public function info(){
public function info(ServersIpLogic $serversIpLogic){
$this->request->validate([
'id'=>'required'
],[
'id.required' => 'id不能为空'
]);
$serversIpModel = new ServersIpModel();
$data = $serversIpModel->read(['id'=>$this->param['id']]);
$data = $serversIpLogic->infoServersIp();
$this->response('success',Code::SUCCESS,$data);
}
... ...
... ... @@ -602,19 +602,6 @@ class ProjectController extends BaseController
}
/**
* @remark :获取项目服务器与数据库列表
* @name :getServiceConfig
* @author :lyh
* @method :post
* @time :2023/8/14 10:23 todo::后面删除
*/
public function getServiceConfig(){
$serviceConfigModel = new ServerConfig();
$list = $serviceConfigModel->list($this->param,'id',['id','type','title','count','init_domain','service_type']);
$this->response('success',Code::SUCCESS,$list);
}
/**
* @remark :获取域名列表
* @name :getDomain
* @author :lyh
... ...
... ... @@ -225,9 +225,12 @@ class CNoticeController extends BaseController
$ids = explode(',',$info['country_lists']);
}
$languageModel = new WebLanguage();
if(empty($ids)){
array_push($ids,1);
}
//根据排序查询选中的小语种
$lists = $languageModel->whereIn('id', $ids)->orderByRaw(DB::raw("FIND_IN_SET(id,'" . implode(',', $ids) . "'" . ')'))->get()->toArray();
// $lists = $languageModel->list(['id'=>['in',$ids]]);
$this->response('success',Code::SUCCESS,$lists);
}
... ...
... ... @@ -12,6 +12,7 @@ namespace App\Http\Logic\Aside\Devops;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Devops\Servers;
use App\Models\Devops\ServersIp;
use App\Models\Project\Project;
class ServersIpLogic extends BaseLogic
{
... ... @@ -26,6 +27,20 @@ class ServersIpLogic extends BaseLogic
}
/**
* @remark :获取数据详情
* @name :infoServersIp
* @author :lyh
* @method :post
* @time :2024/6/27 15:52
*/
public function infoServersIp(){
$info = $this->model->read(['id'=>$this->param['id']]);
$projectModel = new Project();
$info['project_title'] = $projectModel->formatQuery(['serve_id'=>$info['id']])->pluck('title')->toArray();
return $this->success($info);
}
/**
* @remark :保存数据
* @name :saveServersIp
* @author :lyh
... ... @@ -88,7 +103,7 @@ class ServersIpLogic extends BaseLogic
if($info['total'] != 0){
continue;
}
$this->model->del(['id'=>$v]);
$this->model->edit(['status'=>1],['id'=>$v]);
}
return $this->success();
}
... ...
... ... @@ -8,6 +8,7 @@ use App\Jobs\EditAmpDomainBt;
use App\Jobs\EditCustomDomainBt;
use App\Jobs\EditDomainBt;
use App\Models\Devops\ServerConfig;
use App\Models\Devops\ServersIp;
use App\Models\Domain\DomainInfo;
use App\Models\Project\CountryCustom;
use App\Models\Project\DeployOptimize;
... ... @@ -258,8 +259,8 @@ class DomainInfoLogic extends BaseLogic
if($project_info === false){
$this->fail('获取项目数据失败');
}
$server_model = new ServerConfig();
$server_info = $server_model->read(['id'=>$project_info['serve_id']],['init_domain', 'host']);
$serverIpModel = new ServersIp();
$server_info = $serverIpModel->read(['id'=>$project_info['serve_id']],['domain', 'ip']);
if($server_info === false){
$this->fail('获取服务器数据失败');
}
... ... @@ -312,11 +313,9 @@ class DomainInfoLogic extends BaseLogic
$this->model->edit($data,['id'=>$this->param['id']]);
//主站生成证书
EditDomainBt::dispatch($this->param['id']);
// $this->setDomainSsl($server_info['init_domain'],$info['domain'],$this->param['extend_config'] ?? [],$this->param['other_domain'] ?? [],$this->param['is_https'] ?? 0);
//amp站生成证书
if($data['amp_status']){
EditAmpDomainBt::dispatch($this->param['id']);
// $this->setAmpDomainSsl($server_info['init_domain'],$info['domain']);
}
return $this->success();
}
... ... @@ -339,7 +338,7 @@ class DomainInfoLogic extends BaseLogic
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line){
if($line){
$checkA = strpos($line, $server_info['host']) !== false;
$checkA = strpos($line, $server_info['ip']) !== false;
if($checkA){
return $domain;
}
... ... @@ -352,7 +351,7 @@ class DomainInfoLogic extends BaseLogic
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line){
if($line){
$checkCname = (strpos($line, $server_info['init_domain']) !== false);
$checkCname = (strpos($line, $server_info['domain']) !== false);
if($checkCname){
return $domain;
}
... ... @@ -378,8 +377,8 @@ class DomainInfoLogic extends BaseLogic
$custom_model = new CountryCustom();
if($this->param['is_create']){
//需要创建站点
$server_model = new ServerConfig();
$server_info = $server_model->read(['id'=>$project_info['serve_id']],['init_domain', 'host']);
$serverIpModel = new ServersIp();
$server_info = $serverIpModel->read(['id'=>$project_info['serve_id']],['domain', 'ip']);
if($server_info === false){
$this->fail('获取服务器数据失败');
}
... ... @@ -419,9 +418,6 @@ class DomainInfoLogic extends BaseLogic
if($this->param['is_create']){
//创建站点,设置证书
EditCustomDomainBt::dispatch($id);
// $this->param['key'] = $this->param['private_key'] ?? '';
// $this->param['cert'] = $this->param['private_cert'] ?? '';
// $this->setDomainSsl($server_info['init_domain'],$this->param['custom_domain'],[],[],1);
}
return $this->success();
... ...
... ... @@ -10,7 +10,6 @@ use App\Helper\Arr;
use App\Helper\Common;
use App\Helper\FormGlobalsoApi;
use App\Http\Logic\Aside\BaseLogic;
use App\Http\Logic\Aside\Domain\DomainInfoLogic;
use App\Jobs\CopyImageFileJob;
use App\Jobs\CopyProjectJob;
use App\Models\Channel\Channel;
... ... @@ -18,7 +17,6 @@ use App\Models\Channel\User;
use App\Models\Channel\Zone;
use App\Models\Com\NoticeLog;
use App\Models\Com\UpdateLog;
use App\Models\Devops\ServerConfig;
use App\Models\Devops\Servers;
use App\Models\Devops\ServersIp;
use App\Models\Domain\DomainInfo;
... ... @@ -40,18 +38,14 @@ use App\Models\RankData\RankData;
use App\Models\RankData\RankWeek;
use App\Models\RankData\RecommDomain;
use App\Models\RankData\Speed;
use App\Models\RouteMap\RouteMap;
use App\Models\User\ProjectMenu;
use App\Models\User\ProjectRole;
use App\Models\User\User as UserModel;
use App\Models\WebSetting\WebLanguage;
use App\Services\ProjectServer;
use App\Services\SyncService;
use App\Utils\HttpUtils;
use App\Utils\LogUtils;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
/**
... ... @@ -130,10 +124,10 @@ class ProjectLogic extends BaseLogic
public function getInitDomain($serve_id = ''){
$domain = '';
if(!empty($serve_id)){
$serveModel = new ServerConfig();
$info = $serveModel->read(['id'=>$serve_id]);
$serverIpModel = new ServersIp();
$info = $serverIpModel->read(['id'=>$serve_id]);
if($info !== false){
$domain = $info['init_domain'];
$domain = $info['domain'];
}
}
return $this->success(['domain'=>$domain]);
... ... @@ -709,37 +703,6 @@ class ProjectLogic extends BaseLogic
}
/**
* 创建站点
* @param $param
* @throws AsideGlobalException
* @author Akun
* @date 2023/10/17 10:04
*/
public function createSite($param){
if(isset($param['serve_id']) && $param['serve_id'] && isset($param['deploy_optimize']['domain']) && $param['deploy_optimize']['domain']){
$server_model = new ServerConfig();
$server_info = $server_model->read(['id'=>$param['serve_id']],['init_domain','host']);
$domain_model = new DomainInfo();
$domain_info = $domain_model->read(['id'=>$param['deploy_optimize']['domain']],'domain');
if($server_info && $domain_info){
//验证解析
if (!empty($domain_info['domain']) && !DomainInfoLogic::instance()->check_cname($domain_info['domain'], $server_info)) {
throw new AsideGlobalException(Code::SYSTEM_ERROR,'域名' . $domain_info['domain'] . '未解析至目标服务器');
}
$api_url = 'http://'.$server_info['init_domain'].'/api/createSite';
$api_param = ['domain'=>$domain_info['domain']];
try {
HttpUtils::get($api_url, $api_param);
} catch (\Exception | GuzzleException $e) {
errorLog('创建站点', $api_param, $e);
}
}
}
}
/**
* @remark :复制项目
* @name :copyProject
* @author :lyh
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Jobs;
use App\Models\Devops\ServerConfig;
use App\Models\Devops\ServersIp;
use App\Models\Domain\DomainInfo;
use App\Models\Project\Project;
use App\Utils\HttpUtils;
... ... @@ -51,16 +52,14 @@ class EditAmpDomainBt implements ShouldQueue
if ($project_info === false) {
return $this->output($domain_info['domain'] . ':获取项目数据失败');
}
//获取服务器数据
$server_model = new ServerConfig();
$server_info = $server_model->read(['id' => $project_info['serve_id']], ['init_domain', 'host']);
$serverIpModel = new ServersIp();
$server_info = $serverIpModel->read(['id'=>$project_info['serve_id']],['domain', 'ip']);
if ($server_info === false) {
return $this->output($domain_info['domain'] . ':获取服务器数据失败');
}
//编辑amp站
$api_url_amp = 'http://' . $server_info['init_domain'] . '/api/createSiteAmp';
$api_url_amp = 'http://' . $server_info['domain'] . '/api/createSiteAmp';
$api_param_amp = [
'domain' => $domain_info['domain'],
];
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Jobs;
use App\Models\Devops\ServerConfig;
use App\Models\Devops\ServersIp;
use App\Models\Project\CountryCustom;
use App\Models\Project\Project;
use App\Utils\HttpUtils;
... ... @@ -51,14 +52,14 @@ class EditCustomDomainBt implements ShouldQueue
return $this->output($domain_info['custom_domain'] . ':获取项目数据失败');
}
//获取服务器数据
$server_model = new ServerConfig();
$server_info = $server_model->read(['id' => $project_info['serve_id']], ['init_domain', 'host']);
$serverIpModel = new ServersIp();
$server_info = $serverIpModel->read(['id'=>$project_info['serve_id']],['domain', 'ip']);
if ($server_info === false) {
return $this->output($domain_info['custom_domain'] . ':获取服务器数据失败');
}
//编辑站点
if ($domain_info['type'] == 2) {
$api_url = 'http://' . $server_info['init_domain'] . '/api/setSsl';
$api_url = 'http://' . $server_info['domain'] . '/api/setSsl';
$api_param = [
'domain' => $domain_info['custom_domain'],
'private_key' => $domain_info['private_key'],
... ... @@ -68,7 +69,7 @@ class EditCustomDomainBt implements ShouldQueue
'is_https' => 1
];
} else {
$api_url = 'http://' . $server_info['init_domain'] . '/api/applySsl';
$api_url = 'http://' . $server_info['domain'] . '/api/applySsl';
$api_param = [
'domain' => $domain_info['custom_domain'],
'rewrite' => [],
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Jobs;
use App\Models\Devops\ServerConfig;
use App\Models\Devops\ServersIp;
use App\Models\Domain\DomainInfo;
use App\Models\Project\Project;
use App\Utils\HttpUtils;
... ... @@ -53,15 +54,15 @@ class EditDomainBt implements ShouldQueue
}
//获取服务器数据
$server_model = new ServerConfig();
$server_info = $server_model->read(['id' => $project_info['serve_id']], ['init_domain', 'host']);
$serverIpModel = new ServersIp();
$server_info = $serverIpModel->read(['id'=>$project_info['serve_id']],['domain', 'ip']);
if ($server_info === false) {
return $this->output($domain_info['domain'] . ':获取服务器数据失败');
}
//编辑主站
if ($domain_info['type'] == 2) {
$api_url = 'http://' . $server_info['init_domain'] . '/api/setSsl';
$api_url = 'http://' . $server_info['domain'] . '/api/setSsl';
$api_param = [
'domain' => $domain_info['domain'],
'private_key' => $domain_info['private_key'],
... ... @@ -71,7 +72,7 @@ class EditDomainBt implements ShouldQueue
'is_https' => $domain_info['is_https']
];
} else {
$api_url = 'http://' . $server_info['init_domain'] . '/api/applySsl';
$api_url = 'http://' . $server_info['domain'] . '/api/applySsl';
$api_param = [
'domain' => $domain_info['domain'],
'rewrite' => $domain_info['extend_config'],
... ...