-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitpull.php
More file actions
executable file
·42 lines (39 loc) · 1.6 KB
/
Copy pathgitpull.php
File metadata and controls
executable file
·42 lines (39 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
* Created by PhpStorm.
* User: whhong
* Date: 2020-07-24
* Time: 11:02
*/
ini_set('date.timezone', 'Asia/Shanghai');
$target = '/var/www/wechat'; // 生产环境web目录
//密钥
$secret = "123456";
//获取GitHub发送的内容
$json = file_get_contents('php://input');
$content = json_decode($json, true);
//github发送过来的签名
$signature = $_SERVER['HTTP_X_HUB_SIGNATURE'];
if (!$signature) {
return http_response_code(404);
}
list($algo, $hash) = explode('=', $signature, 2);
//计算签名
$payloadHash = hash_hmac($algo, $json, $secret);
// 判断签名是否匹配
if ($hash === $payloadHash) {
$cmd = "cd $target && git pull 2>&1";
$res = shell_exec($cmd);
$res_log = 'Success:' . PHP_EOL;
$res_log .= $cmd . '结果' . $res . PHP_EOL;
$res_log .= $content['head_commit']['author']['name'] . ' 在' . date('Y-m-d H:i:s') . '向' . $content['repository']['name'] . '项目的' . $content['ref'] . '分支push了' . count($content['commits']) . '个commit:' . PHP_EOL;
$res_log .= $res . PHP_EOL;
$res_log .= '=======================================================================' . PHP_EOL;
echo $res_log;
} else {
$res_log = 'Error:' . PHP_EOL;
$res_log .= $content['head_commit']['author']['name'] . ' 在' . date('Y-m-d H:i:s') . '向' . $content['repository']['name'] . '项目的' . $content['ref'] . '分支push了' . count($content['commits']) . '个commit:' . PHP_EOL;
$res_log .= '密钥不正确不能pull' . PHP_EOL;
$res_log .= '=======================================================================' . PHP_EOL;
echo $res_log;
}