作者 赵彬吉
... ... @@ -16,6 +16,7 @@ use App\Models\Project\CountryCustom;
use App\Models\Project\Project;
use Illuminate\Console\Command;
use App\Models\Domain\DomainInfo as DomainInfoModel;
use Illuminate\Support\Facades\Log;
use Symfony\Component\Process\Process;
class DomainInfo extends Command
... ... @@ -43,6 +44,9 @@ class DomainInfo extends Command
*/
public function handle()
{
//先更新所有域名证书有效期
$this->startUpdateSslTime();
//主站证书到期更新
$this->startUpdateCert();
... ... @@ -56,6 +60,47 @@ class DomainInfo extends Command
}
/**
* 更新域名证书有效期
* @author Akun
* @date 2024/09/06 11:16
*/
public function startUpdateSslTime()
{
$domainModel = new DomainInfoModel();
$projectModel = new Project();
$serverIpModel = new ServersIp();
$list = $domainModel->where('status', '=', 1)->get();
foreach ($list as $v) {
$project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']);
if (!$project_info) {
continue;
}
$servers_ip_info = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id', 'ip', 'domain']);
if (!$servers_ip_info) {
continue;
}
//除自建站项目外,记录已解析到别的ip的域名
if ($servers_ip_info['servers_id'] != ServerConfig::SELF_SITE_ID) {
//过滤已解析到别的ip的域名
if (!$this->check_cname($v['domain'], $servers_ip_info)) {
Log::channel('analyze_other')->error('域名 [' . $v['domain'] . '] 已解析到别的IP');
continue;
}
}
//获取证书有效期并更新
$ssl_time = $this->getDomainSslTime($v['domain']);
if ($ssl_time['from'] && $ssl_time['to']) {
$v->certificate_start_time = $ssl_time['from'];
$v->certificate_end_time = $ssl_time['to'];
$v->save();
}
}
}
/**
* 主站证书到期更新
* @author Akun
* @date 2024/02/26 10:26
... ... @@ -190,6 +235,7 @@ class DomainInfo extends Command
//过滤已解析到别的ip的域名
if (!$this->check_cname($v['custom_domain'], $servers_ip_info)) {
Log::channel('analyze_other')->error('自定义跳转域名 [' . $v['custom_domain'] . '] 已解析到别的IP');
continue;
}
... ... @@ -207,6 +253,42 @@ class DomainInfo extends Command
}
/**
* 获取域名证书有效时间
* @param $domain
* @return string[]
* @author Akun
* @date 2024/08/29 9:59
*/
public function getDomainSslTime($domain)
{
$valid_from = '';
$valid_to = '';
try {
$context = stream_context_create([
'ssl' => [
'capture_peer_cert' => true,
'capture_peer_cert_chain' => false,
'verify_peer' => false,
'verify_peer_name' => false
],
]);
$stream = stream_socket_client('ssl://' . $domain . ':443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
if ($stream) {
$remote_cert = stream_context_get_params($stream)['options']['ssl']['peer_certificate'];
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']);
}
}
fclose($stream);
} catch (\Exception $e) {
$valid_from = '';
$valid_to = '';
}
return ['from' => $valid_from, 'to' => $valid_to];
}
/**
* 验证是否cname或者A记录解析到目标服务器
* @param $domain
* @param $server_info
... ...
... ... @@ -10,10 +10,8 @@
namespace App\Console\Commands\Update;
use App\Models\Log\OperationHeartbeat;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class UpdateHeartbeat extends Command
{
... ... @@ -40,9 +38,10 @@ class UpdateHeartbeat extends Command
* @time :2024/8/28 15:25
*/
public function handle(){
$date = date('Y-m-d H:i:s',time() - 30 * 60);
$date = date('Y-m-d H:i:s',time() - 10 * 60);
$operationHeartbeatModel = new OperationHeartbeat();
$operationHeartbeatModel->edit(['status'=>0],['updated_at'=>['<=',$date]]);
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
return true;
}
}
... ...
... ... @@ -40,13 +40,13 @@ class OperationHeartbeatController extends BaseController
'is_list'=>$this->param['is_list'],'is_custom'=>$this->param['is_custom'],'is_template'=>$this->param['is_template']];
$operationHeartbeatModel = new OperationHeartbeat();
$info = $operationHeartbeatModel->read($condition,['id','status']);
$condition['status'] = $condition['status'] ?? 0;
$condition['status'] = $this->param['status'] ?? 0;
if($info === false){
$condition['operator_id'] = $this->user['id'];
$condition['project_id'] = $this->user['project_id'];
$operationHeartbeatModel->addReturnId($condition);
}else{
$operationHeartbeatModel->edit(['status'=>1],['id'=>$info['id']]);
$operationHeartbeatModel->edit(['status'=>$condition['status'] ?? 0],['id'=>$info['id']]);
}
$this->response('success');
}
... ... @@ -76,6 +76,9 @@ class OperationHeartbeatController extends BaseController
'is_list'=>$this->param['is_list'],'is_custom'=>$this->param['is_custom'],'is_template'=>$this->param['is_template']];
$operationHeartbeatModel = new OperationHeartbeat();
$info = $operationHeartbeatModel->read($condition,['id','status']);
if($info === false){
$info = [];
}
$this->response('success',Code::SUCCESS,$info);
}
}
... ...
... ... @@ -210,6 +210,9 @@ class ExtensionModuleController extends BaseController
$status_data[$value] = $number;
$number++;
}
if(($status_data[$info['value']] + 1) != $status_data[$v['value']]){
$this->fail('流程控制不能跳流程选择');
}
if($status_data[$info['value']] > $status_data[$v['value']]){
$this->fail('流程控制不能回滚');
}
... ...
... ... @@ -794,7 +794,6 @@ class RankDataLogic extends BaseLogic
if (!$rank_week) {
$rank_week = new RankWeekModel();
}
$rank_week->project_id = $project_id;
$rank_week->data = $res['data'][$api_no] ?? [];
$rank_week->date = $res['date'];
... ...
... ... @@ -101,6 +101,12 @@ return [
'via' => \App\Factory\LogFormatterFactory::class,
'prefix' => 'wechatside',
],
//域名解析别处记录日志
'analyze_other' => [
'driver' => 'custom',
'via' => \App\Factory\LogFormatterFactory::class,
'prefix' => 'analyze_other',
],
'stack' => [
'driver' => 'stack',
'channels' => ['single'],
... ...