作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

@@ -40,6 +40,12 @@ class DomainInfo extends Command @@ -40,6 +40,12 @@ class DomainInfo extends Command
40 $map = ['status'=>['!=',2]]; 40 $map = ['status'=>['!=',2]];
41 $list = $domainModel->list($map); 41 $list = $domainModel->list($map);
42 foreach ($list as $v){ 42 foreach ($list as $v){
  43 + if(empty($v['private_key']) || empty($v['private_cert'])){
  44 + //域名结束时间<2天时,重新生成
  45 + if(!empty($v['certificate_end_time']) && ($v['certificate_end_time'] > date('Y-m-d H:i:s',time() + 24*3600))){
  46 + $this->updatePrivate($v);
  47 + }
  48 + }
43 $ssl = $this->updateDomainSsl($v['domain']); 49 $ssl = $this->updateDomainSsl($v['domain']);
44 $time = $this->updateDomain($v['domain']); 50 $time = $this->updateDomain($v['domain']);
45 $data = [ 51 $data = [
@@ -48,12 +54,94 @@ class DomainInfo extends Command @@ -48,12 +54,94 @@ class DomainInfo extends Command
48 'domain_start_time'=>$time['start'], 54 'domain_start_time'=>$time['start'],
49 'domain_end_time'=>$time['end'] 55 'domain_end_time'=>$time['end']
50 ]; 56 ];
  57 +
51 $domainModel->edit($data,['id'=>$v['id']]); 58 $domainModel->edit($data,['id'=>$v['id']]);
52 } 59 }
53 return 1; 60 return 1;
54 } 61 }
55 62
56 /** 63 /**
  64 + * @remark :更新正式
  65 + * @name :updatePrivate
  66 + * @author :lyh
  67 + * @method :post
  68 + * @time :2023/12/8 16:16
  69 + */
  70 + public function updatePrivate($param)
  71 + {
  72 + $url = 'https://' . $param['domain']. '/api/applySsl/';
  73 + $extend_config = json_decode($param['extend_config'], true);
  74 + $top_domain = $this->getTopDomain($param['domain']);
  75 + if ((empty($extend_config) || empty($extend_config[0]['origin'])) && $param['id'] != 3) {
  76 + $extend_config = [
  77 + ['origin' => $top_domain, 'target' => $param['domain']]
  78 + ];
  79 + }
  80 + $param = [
  81 + 'project_id' => $param['project_id'],
  82 + 'type' => 1,
  83 + 'route' => 1,
  84 + "domain" =>$param['domain'],
  85 + "rewrite"=> $extend_config,
  86 + 'other_domain' => [$top_domain, '*.' . $top_domain],
  87 + 'private_key' => '',
  88 + 'cert' => ''
  89 + ];
  90 + $result = $this->curlRequest($url, $param);
  91 + Log::info('domain id: ' . $param['id'] . ', domain: ' . $param['domain'] . ', result: ' . var_export($result, true));
  92 + }
  93 +
  94 + public static function getTopDomain ($url) {
  95 + $url = strtolower($url); //首先转成小写
  96 + $url = mb_ereg_replace('^( | )+', '', trim($url));
  97 + $url = mb_ereg_replace('( | )+$', '', $url);
  98 + if (!preg_match('/^(http:\/\/|https)/', $url)) {
  99 + $url = "https://".$url;
  100 + }
  101 + $hosts = parse_url($url);
  102 + $host = $hosts['host'] ?? '';
  103 + //查看是几级域名
  104 + $data = explode('.', $host);
  105 + $n = count($data);
  106 + if ($n < 2) {
  107 + return $host;
  108 + }
  109 + //判断是否是双后缀
  110 + $preg = '/[\w].+\.(com|net|org|gov|edu|co|ne)\.[\w]/';
  111 + if (($n > 2) && preg_match($preg, $host)) {
  112 + //双后缀取后3位
  113 + $host = $data[$n - 3].'.'.$data[$n - 2].'.'.$data[$n - 1];
  114 + } else {
  115 + //非双后缀取后两位
  116 + $host = $data[$n - 2].'.'.$data[$n - 1];
  117 + }
  118 + return $host;
  119 + }
  120 +
  121 + public function curlRequest($url, $data, $method = 'POST', $header = [], $time_out = 60)
  122 + {
  123 + $ch = curl_init();
  124 + curl_setopt($ch, CURLOPT_TIMEOUT, $time_out);
  125 + curl_setopt($ch, CURLOPT_URL, $url);
  126 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  127 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  128 + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  129 + if ($data)
  130 + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  131 + curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge([
  132 + 'Expect:',
  133 + 'Content-type: application/json',
  134 + 'Accept: application/json',
  135 + ], $header)
  136 + );
  137 + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
  138 + $response = curl_exec($ch);
  139 + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  140 + curl_close($ch);
  141 + return [$code, $response];
  142 + }
  143 +
  144 + /**
57 * @remark :更新域名证书 145 * @remark :更新域名证书
58 * @name :updateDomainSsl 146 * @name :updateDomainSsl
59 * @author :lyh 147 * @author :lyh
@@ -31,10 +31,30 @@ class CustomModuleContentController extends BaseController @@ -31,10 +31,30 @@ class CustomModuleContentController extends BaseController
31 ]); 31 ]);
32 $this->map['project_id'] = $this->user['project_id']; 32 $this->map['project_id'] = $this->user['project_id'];
33 $lists = $customModuleContent->lists($this->map,$this->page,$this->row,$this->order); 33 $lists = $customModuleContent->lists($this->map,$this->page,$this->row,$this->order);
  34 + foreach ($lists as $v){
  35 + //获取分类名称
  36 + }
34 $this->response('success',Code::SUCCESS,$lists); 37 $this->response('success',Code::SUCCESS,$lists);
35 } 38 }
36 39
37 /** 40 /**
  41 + * @remark :获取所有分类名称
  42 + * @name :getAllCategoryName
  43 + * @author :lyh
  44 + * @method :post
  45 + * @time :2023/12/8 15:47
  46 + */
  47 + public function getAllCategoryName(){
  48 + $categoryModel = new CustomModuleCategory();
  49 + $list = $categoryModel->list(['status'=>0],'id',['id','name']);
  50 + $data = [];
  51 + foreach ($list as $v){
  52 + $data[$v['id']] = $v['name'];
  53 + }
  54 + return $this->success($data);
  55 + }
  56 +
  57 + /**
38 * @remark :添加/编辑内容时获取分类 58 * @remark :添加/编辑内容时获取分类
39 * @name :getCategoryList 59 * @name :getCategoryList
40 * @author :lyh 60 * @author :lyh
@@ -353,7 +353,7 @@ class BTemplateLogic extends BaseLogic @@ -353,7 +353,7 @@ class BTemplateLogic extends BaseLogic
353 public function homeOrProduct($source,$source_id = ''){ 353 public function homeOrProduct($source,$source_id = ''){
354 if($source == BTemplate::SOURCE_HOME){ 354 if($source == BTemplate::SOURCE_HOME){
355 $type = 'index'; 355 $type = 'index';
356 - $route = ''; 356 + $route = 'index';
357 //路由映射 357 //路由映射
358 RouteMap::setRoute('index', RouteMap::SOURCE_PAGE, 0, $this->user['project_id']); 358 RouteMap::setRoute('index', RouteMap::SOURCE_PAGE, 0, $this->user['project_id']);
359 }else{ 359 }else{
@@ -299,9 +299,9 @@ class CustomModuleCategoryLogic extends BaseLogic @@ -299,9 +299,9 @@ class CustomModuleCategoryLogic extends BaseLogic
299 */ 299 */
300 public function delRoute($id) 300 public function delRoute($id)
301 { 301 {
302 - RouteMap::delRoute(RouteMap::SOURCE_MODULE_CATE.$this->param['module_id'], $id, $this->user['project_id']); 302 + $info = $this->model->read(['id' => $id], ['id', 'route','module_id']);
  303 + RouteMap::delRoute(RouteMap::SOURCE_MODULE_CATE.$info['module_id'], $id, $this->user['project_id']);
303 //通知 304 //通知
304 - $info = $this->model->read(['id' => $id], ['id', 'route']);  
305 $this->curlDelRoute(['route'=>$info['route']]); 305 $this->curlDelRoute(['route'=>$info['route']]);
306 return $this->success(); 306 return $this->success();
307 } 307 }