From 762fce8c01a2dece3d4781921b4849fb5657ce89 Mon Sep 17 00:00:00 2001 From: hellcat <> Date: Thu, 17 Apr 2025 19:56:29 +0800 Subject: [PATCH] no message --- app/Http/Controllers/CronController.php | 41 ++++++++++++++++++++-- app/Http/Controllers/TestsController.php | 35 +++++++++++++++++- app/Services/Github/Mod/JichangTuijian.php | 4 --- 3 files changed, 73 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/CronController.php b/app/Http/Controllers/CronController.php index 1b391e4..a53d972 100755 --- a/app/Http/Controllers/CronController.php +++ b/app/Http/Controllers/CronController.php @@ -11,6 +11,7 @@ class CronController private $sUserName; private $sProjectName; + private $sHostName; private $sProjectPath; private $sProjectUrl; @@ -85,8 +86,9 @@ class CronController foreach ($aArticle as $row) { $this->sUserName = $row["user_name"]; $this->sProjectName = $row["project_name"]; - $this->sProjectPath = env("BASE_DIR")."github/".$this->sUserName."-".$this->sProjectName; - $this->sProjectUrl = env("github_url_base").":".$this->sUserName."/".$this->sProjectName.".git"; + $this->sHostName = $row['host_name']; + $this->sProjectPath = env("BASE_DIR")."github/".$this->sHostName."-".$this->sProjectName; + $this->sProjectUrl = env("github_url_base").":".$this->sHostName."/".$this->sProjectName.".git"; $this->aArticle = $row; list($sClass, $sFunc) = explode('#', $row['mod']); @@ -113,6 +115,8 @@ class CronController $this->gitInit(); + $this->sshConfigAdd(); + } // 写入内容 @@ -128,6 +132,39 @@ class CronController } } + private function sshConfigAdd() + { + + // 定义要添加的配置 + $host = $this->sHostName; + $hostname = "github.com"; + $user = "git"; + $identityFile = env("path_ssh")."/id_rsa_".$sHostName; + + // 构建配置字符串 + $config = "\nHost ".$host.".com\n"; + $config .= "\tHostName $hostname\n"; + $config .= "\tUser $user\n"; + $config .= "\tIdentityFile $identityFile\n"; + + // 指定 SSH 配置文件路径 + $sshConfigFile = env("path_ssh")."/config"; + + // 检查文件是否存在,如果不存在则创建 + if (!file_exists($sshConfigFile)) { + touch($sshConfigFile); + } + + // 追加配置到文件 + file_put_contents($sshConfigFile, $config, FILE_APPEND | LOCK_EX); + + // 设置文件权限 + chmod($sshConfigFile, 0600); + + echo "SSH config updated successfully."; + + } + private function formatstr($str) { $str = substr($str, 1, -1); diff --git a/app/Http/Controllers/TestsController.php b/app/Http/Controllers/TestsController.php index 199df4e..8ee8db0 100755 --- a/app/Http/Controllers/TestsController.php +++ b/app/Http/Controllers/TestsController.php @@ -10,8 +10,41 @@ use App\Services\TomTool\Http; class TestsController { - public function hook() + public function hook($sHostName = 'ssssss') { + + // 定义要添加的配置 + $host = $sHostName; + $hostname = "github.com"; + $user = "git"; + $identityFile = env("path_ssh")."/id_rsa_".$sHostName; + + // 构建配置字符串 + $config = "\nHost ".$host.".com\n"; + $config .= "\tHostName $hostname\n"; + $config .= "\tUser $user\n"; + $config .= "\tIdentityFile $identityFile\n"; + + // 指定 SSH 配置文件路径 + $sshConfigFile = env("path_ssh")."/config"; + + // 检查文件是否存在,如果不存在则创建 + if (!file_exists($sshConfigFile)) { + touch($sshConfigFile); + } + + // 追加配置到文件 + file_put_contents($sshConfigFile, $config, FILE_APPEND | LOCK_EX); + + // 设置文件权限 + chmod($sshConfigFile, 0600); + + echo "SSH config updated successfully."; + + + + + exit; // $t = []; // $a = $t['zz']["cc"] += 10; // $a = $t['zz']["cc"] += 10; diff --git a/app/Services/Github/Mod/JichangTuijian.php b/app/Services/Github/Mod/JichangTuijian.php index 5aa06c2..dc99b2e 100755 --- a/app/Services/Github/Mod/JichangTuijian.php +++ b/app/Services/Github/Mod/JichangTuijian.php @@ -4,10 +4,6 @@ use App\Services\TomTool\Http; class JichangTuijian { - public $sTitle; // 必须 - public $sContent; // 必须 - public $sSubTitle; // 非必须 - public function A($aArticle) {