HEX
Server: nginx/1.28.3
System: Linux ip-172-31-12-242 6.17.0-1007-aws #7~24.04.1-Ubuntu SMP Thu Jan 22 21:04:49 UTC 2026 x86_64
User: root (0)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: //proc/660477/root/www/wwwroot/nasuhang.com/webhook_pull.php
<?php
/**
 * Git Webhook 自动拉取脚本
 * 支持Gitee/GitHub/GitLab等平台的Webhook触发自动拉取最新代码
 */

// 配置项 - 请根据实际情况修改
$config = [
    // 安全秘钥:Webhook请求时需要携带此参数验证身份,防止恶意触发
    'secret' => 'c8cbe9b5d41cde0cf5c9cc16f5f6d401',
    // 本地仓库绝对路径(已修正为服务器实际站点路径)
    'repo_path' => '/www/wwwroot/hst.aizyu.cn',
    // 拉取的分支名
    'branch' => 'master',
    // 日志文件路径(修改为站点目录下,避免权限问题)
    'log_file' => '/www/wwwroot/hst.aizyu.cn/webhook_pull.log',
    // 是否开启调试模式(开启会输出详细执行信息)
    'debug' => true
];

// 日志记录函数
function writeLog($message, $level = 'INFO') {
    global $config;
    $logDir = dirname($config['log_file']);
    if (!is_dir($logDir)) {
        mkdir($logDir, 0755, true);
    }
    $logMsg = sprintf("[%s] [%s] %s\n", date('Y-m-d H:i:s'), $level, $message);
    file_put_contents($config['log_file'], $logMsg, FILE_APPEND | LOCK_EX);
    
    if ($config['debug']) {
        echo $logMsg . "<br>";
    }
}

// 1. 安全验证
$requestToken = $_GET['token'] ?? ($_POST['token'] ?? '');
if (empty($requestToken) || $requestToken !== $config['secret']) {
    writeLog('非法请求:Token验证失败', 'ERROR');
    http_response_code(403);
    exit('Access Denied: Invalid Token');
}

// 2. 验证仓库目录存在
if (!is_dir($config['repo_path']) || !is_dir($config['repo_path'] . '/.git')) {
    writeLog('错误:仓库目录不存在或不是有效的Git仓库,当前路径:' . $config['repo_path'], 'ERROR');
    http_response_code(500);
    exit('Error: Invalid Git Repository Path');
}

// 3. 执行Git拉取命令
writeLog('开始执行自动拉取操作,分支:' . $config['branch']);
$command = sprintf('cd %s && git pull origin %s 2>&1', escapeshellarg($config['repo_path']), escapeshellarg($config['branch']));

// 执行命令并获取输出
$output = [];
$exitCode = 0;
exec($command, $output, $exitCode);

// 记录执行结果
$outputStr = implode("\n", $output);
writeLog('命令执行输出:' . $outputStr);

if ($exitCode === 0) {
    writeLog('✅ 代码拉取成功', 'SUCCESS');
    exit('OK: Pull completed successfully');
} else {
    writeLog('❌ 代码拉取失败,退出码:' . $exitCode, 'ERROR');
    http_response_code(500);
    exit('Error: Pull failed, check log for details');
}
?>