码迷,mamicode.com
首页 > Web开发 > 详细

gitlab+webhook

时间:2019-03-13 12:40:45      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:nbsp   div   ===   fopen   白名单   web   file   erro   project   

<?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);

 

gitlab+webhook

标签:nbsp   div   ===   fopen   白名单   web   file   erro   project   

原文地址:https://www.cnblogs.com/GreenForestQuan/p/10522206.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!