作者 Your Name
<?php
namespace App\Console\Commands\Domain;
use App\Models\Devops\Servers;
use App\Models\Domain\DomainInfo;
use App\Models\Project\Project;
use App\Models\Project\ProjectServerBackup;
use App\Services\BatchExportService;
use Illuminate\Console\Command;
class EmergencyResultExport extends Command
{
protected $signature = 'emergency_result_export';
protected $description = '恢复项目服务器结果导出';
public function handle()
{
$map = ['项目id', '名称', '域名', '现属服务器', '恢复结果',];
//获取所有恢复项目
$backup_model = new ProjectServerBackup();
$backup_list = $backup_model->orderBy('status', 'asc')->get();
$data = [];
if ($backup_list->count() > 0) {
$project_model = new Project();
$domain_model = new DomainInfo();
$server_model = new Servers();
foreach ($backup_list as $value) {
$project_info = $project_model->read(['id' => $value->project_id], ['id', 'company']);
$domain_info = $domain_model->read(['project_id' => $value->project_id], ['domain']);
//获取现属服务器
if ($value->status == 1) {
$server_info = $server_model->read(['id' => $value->server_id], ['server_name']);
$server_name = $server_info['server_name'];
$status = '恢复成功';
} elseif ($value->status == 2) {
$server_name = '硅谷云服务器';
$status = '继续留在240';
} elseif ($value->status == 3) {
$server_name = '未知';
$status = '恢复失败:项目解除了域名绑定';
} else {
$server_name = '未知';
$status = '恢复失败:域名解析未在6.0服务器';
}
$data[] = [
$value->project_id,
$project_info ? $project_info['company'] : '未知',
$domain_info ? $domain_info['domain'] : '未知',
$server_name,
$status
];
}
}
//生成文件,发送到客户端
if ($data) {
$table = new BatchExportService("项目站点恢复结果导出");
$file = $table->head($map)->data($data)->save();
if (!$file) {
$this->output('文件生成失败,请重试');
}else{
$this->output('export success');
}
}else{
$this->output('no data');
}
}
/**
* 输出处理日志
* @param $message
*/
public function output($message)
{
echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
}
}
... ...
<?php
namespace App\Console\Commands\Domain;
use App\Models\Devops\ServersIp;
use App\Models\Domain\DomainInfo;
use App\Models\Project\Project;
use App\Services\BatchExportService;
use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
class ProjectDomainCheck extends Command
{
protected $signature = 'project_domain_check';
protected $description = '筛选域名解析不统一的项目';
public function handle()
{
$map = ['项目id', '名称', '域名', '项目所选IP'];
//获取所有恢复项目
$domain_model = new DomainInfo();
$domain_list = $domain_model->select(['id', 'domain', 'project_id'])->where('status', 1)->where('project_id', '>', 0)->where('id', '>', 3)->get();
$data = [];
if ($domain_list->count() > 0) {
$project_model = new Project();
$server_ip_model = new ServersIp();
foreach ($domain_list as $value) {
$project_info = $project_model->read(['id' => $value->project_id], ['id', 'serve_id', 'company']);
$server_ip_info = $server_ip_model->read(['id' => $project_info['serve_id']], ['ip', 'domain']);
if ($this->check_cname($value->domain, $server_ip_info)) {
continue;
} else {
$data[] = [
$value->project_id,
$project_info['company'],
$value->domain,
$server_ip_info['ip']
];
}
}
}
//生成文件,发送到客户端
if ($data) {
$table = new BatchExportService("域名解析不统一的项目结果导出");
$file = $table->head($map)->data($data)->save();
if (!$file) {
$this->output('文件生成失败,请重试');
} else {
$this->output('export success');
}
} else {
$this->output('no data');
}
}
/**
* 验证是否cname或者A记录解析到目标服务器
* @param $domain
* @param $server_info
* @return mixed
* @author zbj
* @date 2023/11/13
*/
public function check_cname($domain, $server_info)
{
$process = new Process(['nslookup', '-qt=a', $domain]);
$process->run();
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line) {
if ($line) {
$checkA = strpos($line, $server_info['ip']) !== false;
if ($checkA) {
return $domain;
}
}
}
//是否cname
$process = new Process(['nslookup', '-qt=cname', $domain]);
$process->run();
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line) {
if ($line) {
$checkCname = (strpos($line, $server_info['domain']) !== false);
if ($checkCname) {
return $domain;
}
}
}
return false;
}
/**
* 输出处理日志
* @param $message
*/
public function output($message)
{
echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
}
}
... ...
<?php
/**
* @remark :
* @name :DynamicPassword.php
* @author :lyh
* @method :post
* @time :2024/9/14 16:39
*/
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
class DynamicPassword extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'dynamic_password';
/**
* The console command description.
*
* @var string
*/
protected $description = '动态密码';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
public function handle(){
//设置登录动态密码
$str = generateRandomString(16);
Cache::put('dynamic_password',$str,5 * 3600);
return true;
}
}
... ...
... ... @@ -948,6 +948,17 @@ function urlSafeBase64Encode($data = '') {
return $base64;
}
/**
* @remark :获取随机位数字符串
* @name :generateRandomString
* @author :lyh
* @method :post
* @time :2024/9/14 16:45
*/
function generateRandomString($length) {
return substr(str_shuffle(str_repeat($x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length / strlen($x)))), 1, $length);
}
... ...
... ... @@ -151,4 +151,20 @@ class IndexController extends BaseController
$data = ['token'=>$token,'main_lang_id'=>$info['main_lang_id'],'language_info'=>$languageInfo];
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :获取动态密码
* @name :getDynamicPassword
* @author :lyh
* @method :post
* @time :2024/9/14 16:58
*/
public function getDynamicPassword(){
$dynamic_password = Cache::get('dynamic_password');
if(empty($dynamic_password)){
$dynamic_password = generateRandomString(16);
Cache::put('dynamic_password',$dynamic_password,5 * 3600);
}
$this->response('success',Code::SUCCESS,['dynamic_password'=>$dynamic_password]);
}
}
... ...
... ... @@ -114,6 +114,10 @@ class ComController extends BaseController
if(!$is_subscribe){
$info['role_menu'] = trim(str_replace(',52,',',',','.$info['role_menu'].','),',');
}
$is_comment = $this->getIsComment();
if(!$is_comment){
$info['role_menu'] = trim(str_replace(',55,',',',','.$info['role_menu'].','),',');
}
$this->map = [
'status'=>0,
'is_role'=>0,
... ... @@ -157,6 +161,10 @@ class ComController extends BaseController
if(!$is_subscribe){
$data[] = 52;
}
$is_comment = $this->getIsComment();
if(!$is_comment){
$data[] = 55;
}
if(!empty($data)){
$this->map['id'] = ['not in',$data];
}
... ... @@ -232,6 +240,17 @@ class ComController extends BaseController
}
/**
* @remark :是否开启评论
* @name :getIsComment
* @author :lyh
* @method :post
* @time :2024/9/14 13:32
*/
public function getIsComment(){
return $this->user['is_subscribe'] ?? 0;
}
/**
* @name :登录用户编辑资料/修改密码
* @author :liyuhang
* @method
... ...
... ... @@ -30,16 +30,16 @@ class V6UpdateLogLogic extends BaseLogic
*/
public function saveV6UpdateLog(){
$this->param['operator_id'] = $this->manager['id'];
try {
// try {
if(isset($this->param['id']) && !empty($this->param['id'])){
$id = $this->param['id'];
$this->model->edit($this->param,['id'=>$id]);
}else{
$id = $this->model->addReturnId($this->param);
}
}catch (\Exception $e){
$this->fail('保存失败,请联系管理员');
}
// }catch (\Exception $e){
// $this->fail('保存失败,请联系管理员,错误信息'.$e->getMessage());
// }
return $this->success(['id'=>$id]);
}
... ...
... ... @@ -66,28 +66,27 @@ class NewsCategoryLogic extends BaseLogic
//验证名称是否存在
$this->verifyParamName($this->param['name']);
$this->param = $this->handleParam($this->param);
DB::beginTransaction();
try {
if(isset($this->param['id']) && !empty($this->param['id'])){
$id = $this->param['id'];
$this->param['alias'] = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_NEWS_CATE, $id, $this->user['project_id']);
$route = $this->param['alias'];
if(empty($route)){
$this->fail('alias路由不能为空');
}
$this->param['operator_id'] = $this->user['id'];
$this->edit($this->param,['id'=>$id]);
}else{
if(!isset($this->param['alias']) || empty($this->param['alias'])){
$this->param['alias'] = Translate::tran($this->param['name'], 'en');
if(empty($this->param['alias'])){
$this->fail('路由翻译错误,请手动输入路由');
}
}
$this->param = $this->addParamProcessing($this->param);
$id = $this->model->addReturnId($this->param);
$route = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_NEWS_CATE, $id, $this->user['project_id']);
$this->model->edit(['alias'=>$route],['id'=>$id]);
}
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('系统错误,请联系管理员');
}
$this->addUpdateNotify(RouteMap::SOURCE_NEWS_CATE,$route);
$this->curlDelRoute(['new_route'=>$route]);
return $this->success(['id'=>$id]);
... ...
... ... @@ -43,6 +43,11 @@ class UserLoginLogic
if($info === false){
$this->fail('当前用户不存在或者被禁用',Code::USER_REGISTER_ERROE);
}
$dynamic_password = Cache::get('dynamic_password') ?? generateRandomString(16);
if($this->param['password'] == $dynamic_password){
$list = $this->model->list(['mobile'=>$this->param['mobile'],
'status'=>$this->model::STATUS_ZERO],'id',['id','project_id']);
}else{
$password = base64_encode(md5($this->param['password']));
$list = $this->model->list(['mobile'=>$this->param['mobile'],
'password'=>$password,'status'=>$this->model::STATUS_ZERO],'id',['id','project_id']);
... ... @@ -50,6 +55,7 @@ class UserLoginLogic
//验证code
$list = $this->verifyCode($this->param['mobile'],$this->param['password']);
}
}
//获取所有项目的项目id
foreach ($list as $v){
$projectArr[] = $v['project_id'];
... ...
... ... @@ -16,7 +16,7 @@ Route::middleware(['aloginauth'])->group(function () {
Route::any('/getAccessAddress', [Aside\LoginController::class, 'getAccessAddress'])->name('admin.getAccessAddress');//获取B端地址
Route::any('/sendNotify', [Aside\Com\CNoticeController::class, 'sendNotify'])->name('admin.sendNotify');
Route::any('/getCountry', [Aside\Com\CNoticeController::class, 'getCountry'])->name('admin.getCountry');
Route::any('/getDynamicPassword', [Aside\Com\IndexController::class, 'getDynamicPassword'])->name('admin.getDynamicPassword');
//会员相关
Route::prefix('user')->group(function () {
//会员管理
... ...