作者 刘锟

白帽-二级域名绑定改版

... ... @@ -45,11 +45,11 @@ class DomainSettingController extends BaseController
public function save(DomainSettingLogic $logic)
{
$this->request->validate([
'type' => ['required'],
'domain' => ['required'],
'record' => ['required'],
], [
'type.required' => '服务器类型不能为空',
'domain.required' => '主域名不能为空',
'record.required' => '解析记录不能为空',
]);
$logic->saveDomain();
$this->response('success', Code::SUCCESS);
... ...
... ... @@ -9,6 +9,7 @@
namespace App\Http\Logic\Bside\SeoSetting;
use App\Helper\Arr;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Devops\Servers;
use App\Models\Devops\ServersIp;
... ... @@ -37,11 +38,11 @@ class DomainSettingLogic extends BaseLogic
public function infoDomain()
{
$domain_info = $this->model->read(['project_id' => $this->user['project_id']], ['seo_type', 'seo_domain', 'seo_ftp']);
$domain = $domain_info['seo_domain'] ?: '';
$ftp = $domain_info['seo_ftp'] ? json_decode($domain['seo_ftp'], true) : ['url' => '', 'username' => '', 'password' => '', 'port' => ''];
$type = $domain_info['seo_type'] ?: 1;
$record = '';
$type = $domain_info['seo_type'] ?? WebSetting::SEO_TYPE_PUBLIC;
$domain = $domain_info['seo_domain'] ?? '';
$ftp = isset($domain_info['seo_ftp']) && $domain_info['seo_ftp'] ? Arr::s2a($domain_info['seo_ftp']) : ['url' => '', 'username' => '', 'password' => '', 'port' => ''];
$record = '';
if ($type == WebSetting::SEO_TYPE_PUBLIC) {
//公共服务器
if ($domain) {
... ... @@ -65,7 +66,8 @@ class DomainSettingLogic extends BaseLogic
/**
* @remark :保存设置
* @name :saveDomain
* @throws \App\Exceptions\AsideGlobalException
* @throws \App\Exceptions\BsideGlobalException
* @author :lyh
* @method :post
* @time :2025/3/20 16:12
... ... @@ -79,9 +81,16 @@ class DomainSettingLogic extends BaseLogic
$this->fail('主域名填写错误');
}
if ($this->param['type'] = WebSetting::SEO_TYPE_PUBLIC) {
$record = $this->param['record'] ?? '';
if (empty($record)) {
$this->fail('解析记录不能为空');
}
//获取解析服务器详情
$server_ip_model = new ServersIp();
$record_info = $server_ip_model->read(['domain' => $this->param['record']], ['id', 'servers_id', 'ip', 'domain', 'total']);
$record_info = $server_ip_model->read(['domain' => $record], ['id', 'servers_id', 'ip', 'domain', 'total']);
if (!$record_info) {
$this->fail('解析记录不存在');
}
... ... @@ -106,7 +115,7 @@ class DomainSettingLogic extends BaseLogic
//判断blog二级域名是否已经解析
if (!check_domain_record($blog_domain, $record_info)) {
$this->fail($blog_domain . '还未解析cname至' . $this->param['record']);
$this->fail($blog_domain . '还未解析cname至' . $record);
}
DB::beginTransaction();
... ... @@ -114,9 +123,9 @@ class DomainSettingLogic extends BaseLogic
//保存一条主域名记录
$setting_info = $this->model->read(['project_id' => $this->user['project_id']]);
if ($setting_info === false) {
$this->model->add(['seo_domain' => $domain, 'project_id' => $this->user['project_id']]);
$this->model->add(['seo_type' => WebSetting::SEO_TYPE_PUBLIC, 'seo_domain' => $domain, 'project_id' => $this->user['project_id']]);
} else {
$this->model->edit(['seo_domain' => $domain], ['id' => $setting_info['id']]);
$this->model->edit(['seo_type' => WebSetting::SEO_TYPE_PUBLIC, 'seo_domain' => $domain], ['id' => $setting_info['id']]);
}
//添加域名到域名管理
... ... @@ -152,5 +161,22 @@ class DomainSettingLogic extends BaseLogic
DB::rollBack();
$this->fail('保存失败,请联系管理员');
}
} else {
$ftp = $this->param['ftp'] ?? [];
if (empty($ftp) || empty($ftp['url']) || empty($ftp['username']) || empty($ftp['password']) || empty($ftp['port'])) {
$this->fail('ftp信息填写未完整');
}
//保存一条主域名记录
$setting_info = $this->model->read(['project_id' => $this->user['project_id']]);
if ($setting_info === false) {
$this->model->add(['seo_type' => WebSetting::SEO_TYPE_OWN, 'seo_domain' => $domain, 'seo_ftp' => Arr::a2s($ftp), 'project_id' => $this->user['project_id']]);
} else {
$this->model->edit(['seo_type' => WebSetting::SEO_TYPE_OWN, 'seo_domain' => $domain, 'seo_ftp' => Arr::a2s($ftp)], ['id' => $setting_info['id']]);
}
}
}
}
... ...