no message
This commit is contained in:
parent
2e157ee1a7
commit
d96680db03
@ -17,6 +17,7 @@ class Cmd extends Base {
|
||||
'文章add' => '/Article#Add__name',
|
||||
'文章del' => '/Article#Del__id',
|
||||
'文章set' => '/Article#Set__id__fild set',
|
||||
'添加github的sshhost' => "System#AddSshHostGithub",
|
||||
];
|
||||
|
||||
$this->oTGHttp->sendToTG(json_encode($aCmdList, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||
|
||||
39
app/Services/TG/Hook/System.php
Normal file
39
app/Services/TG/Hook/System.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\TG\Hook;
|
||||
|
||||
class System extends Base {
|
||||
|
||||
public function AddSshHostGithub()
|
||||
{
|
||||
|
||||
// 定义要添加的主机
|
||||
$host = 'github.com';
|
||||
|
||||
// 执行 ssh-keyscan 命令
|
||||
$key = shell_exec("ssh-keyscan -t ed25519 $host");
|
||||
|
||||
// 检查是否成功获取到公钥
|
||||
if ($key) {
|
||||
// 获取 known_hosts 文件的路径
|
||||
$knownHostsFile = getenv('HOME') . '/.ssh/known_hosts';
|
||||
|
||||
// 检查 known_hosts 文件中是否已经存在该主机的公钥
|
||||
if (strpos(file_get_contents($knownHostsFile), $host) === false) {
|
||||
// 将公钥写入 known_hosts 文件
|
||||
file_put_contents($knownHostsFile, $key, FILE_APPEND);
|
||||
$sMsg = "公钥已成功添加到 $knownHostsFile\n";
|
||||
} else {
|
||||
$sMsg = "公钥已存在于 $knownHostsFile\n";
|
||||
}
|
||||
} else {
|
||||
$sMsg = "无法获取 $host 的公钥\n";
|
||||
}
|
||||
|
||||
$this->oTGHttp->sendToTG($sMsg);
|
||||
|
||||
$this->oHttp::response(200, 'ok');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user