gitlab+webhook

<?php
#项目
$project = trim($_GET['project']); if (empty($project)) { return json_encode(['msg' => "project not exist."]); } #你的项目地址 $wwwFile = '/server/webroot/' . $project . '/';
#钩子日志
$fs = fopen('./hooks.log', 'a'); fwrite($fs, '================ Update Start ===============' . PHP_EOL . PHP_EOL); $accessToken = 'QhNO8YHqym5PHQQsexapF7041xOhzm62DRH';
#白名单服务器执行ip
$accessIp = ['192.168.0.174', '192.168.2.204', '192.168.3.222']; $clientToken = trim($_GET['token']); $clientIp = $_SERVER['REMOTE_ADDR']; fwrite($fs, 'Request on [' . date("Y-m-d H:i:s") . '] from [' . $clientIp . ']' . PHP_EOL); #密匙验证 if ($clientToken !== $accessToken) { fwrite($fs, "Invalid token [{$clientToken}]" . PHP_EOL); return json_encode(['msg' => "error 403"]); } #ip白名单验证 if (!in_array($clientIp, $accessIp)) { fwrite($fs, "Invalid ip [{$clientIp}]" . PHP_EOL); return json_encode(['msg' => "error 503"]); } //命令执行$output = shell_exec("cd {$wwwFile} && git stash && git pull && chown nginx. ./* -R 2>&1");
fwrite($fs, 'Info:' . $output . PHP_EOL); fwrite($fs, PHP_EOL . '================ Update End ===============' . PHP_EOL . PHP_EOL);
$fs and fclose($fs);

猜你喜欢

转载自www.cnblogs.com/GreenForestQuan/p/10522206.html