作者 刘锟

update

... ... @@ -8,7 +8,6 @@ use App\Models\Devops\ServerConfig;
use App\Models\Devops\ServersIp;
use App\Models\Domain\DomainInfo;
use App\Models\Project\Project;
use App\Models\Project\ProjectServerBackup;
use App\Services\BatchExportService;
use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
... ... @@ -29,13 +28,58 @@ class Temp extends Command
*/
protected $description = '临时脚本';
/**
* 获取指定服务器所有项目
* @author Akun
* @date 2024/09/30 17:01
*/
public function handle()
{
$server_id = 1;
$server_ip_model = new ServersIp();
$server_ip_ids = $server_ip_model->where('servers_id', $server_id)->get()->pluck('id')->toArray();
$project_list = Project::select(['id', 'serve_id', 'title'])->whereIn('serve_id', $server_ip_ids)->get();
$domain_model = new DomainInfo();
$data = [];
foreach ($project_list as $value) {
$domain_info = $domain_model->read(['project_id' => $value->id, 'status' => 1], ['id', 'domain']);
if (!$domain_info) {
//过滤未绑定正式域名的项目
continue;
}
$domain = $domain_info['domain'];
$data[] = [
$value->id,
$value->title,
$domain
];
}
$map = ['项目id', '名称', '域名'];
if ($data) {
$table = new BatchExportService("240云服务器项目");
$file = $table->head($map)->data($data)->save();
if (!$file) {
$this->output('文件生成失败,请重试');
} else {
$this->output('export success');
}
} else {
$this->output('no data');
}
}
/**
* 检查不在所属服务器解析上的域名
* @author Akun
* @date 2024/09/26 10:48
*/
public function handle()
public function handle1()
{
$server_id = 14;
... ... @@ -59,7 +103,7 @@ class Temp extends Command
foreach ($check as $item) {
if (strpos($item, 'Address:') !== false) {
$ip = trim(str_replace('Address:', '', $item));
if (strpos($ip,'#') === false) {
if (strpos($ip, '#') === false) {
$ip_info = $server_ip_model->read(['ip' => $ip]);
if ($ip_info === false || $ip_info['servers_id'] != $server_id) {
$data[] = [
... ... @@ -80,10 +124,10 @@ class Temp extends Command
$file = $table->head($map)->data($data)->save();
if (!$file) {
$this->output('文件生成失败,请重试');
}else{
} else {
$this->output('export success');
}
}else{
} else {
$this->output('no data');
}
}
... ...