forked from andanyoung/githook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull.php
More file actions
33 lines (24 loc) · 868 Bytes
/
pull.php
File metadata and controls
33 lines (24 loc) · 868 Bytes
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
<?php
ini_set('display_errors', 'On');
$log_level = isset($_GET['log_level']) ? $_GET['is_log'] : 0;
$log_level = intval($log_level);
define('LOG_LEVEL', 0);
require_once 'utils/Log.php';
if ($_SERVER['HTTP_CONTENT_TYPE'] === 'application/json') {
$requestBody = file_get_contents("php://input");
$requestBody = json_decode($requestBody, true);
} elseif ($_SERVER['HTTP_CONTENT_TYPE'] === 'application/x-www-form-urlencoded') {
$requestBody = json_decode($_POST['payload'], true);
}
if (!isset($requestBody)) {
exit('没有请求参数');
}
Log::DEBUG($requestBody);
echo 'USER: ';
system('whoami');
$path = isset($_GET['path']) ? urldecode($_GET['path']) : '../' . $requestBody['repository']['name'];
$shell_cmd = "cd {$path} && git pull";
echo $shell_cmd . "\n";
$shell_res = system($shell_cmd);
Log::INFO($shell_cmd);
Log::INFO($shell_res);