This repository has been archived by the owner on Jun 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
89 lines (73 loc) · 1.96 KB
/
index.php
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
require_once __DIR__ . '/class/loader.php';
$result = new split($_SERVER['REQUEST_URI']);
error_reporting(0);
$signature = $_SERVER['HTTP_X_HUB_SIGNATURE'];
if (empty($result->parameter)) {
http_response_code(404);
exit();
}
if (!empty($projectName = $result->slash['project'])) {
// get Config
$config = new config($projectName);
if ($config->config == false) {
echo 'Project No Found';
http_response_code(404);
exit();
}
// True?
if ($signature) {
$hash = "sha1=" . hash_hmac('sha1', $payload = file_get_contents("php://input"), $config->config['secret']);
if (strcmp($signature, $hash) == 0) {
// Looks fine, init
// get Command
$command = new command(
$config->config['commandPackage'],
$config->config['templateVariable'],
$config->getBasicVariable()
);
// Create log
$time = time();
$log = [];
$logFilePath = $path . '/' . $projectName . '-' . $time . '.log';
// Exec
foreach ($command->commands as $command) {
$log[$command] = shell_exec($command); // Exec
}
if (!empty($path = $config->config['logPath'])) {
file_put_contents($logFilePath, packLog($log)); // Write Log
}
echo json_encode($log);
// Post Command
$postLog = [];
if (!empty($config->config['postCommandPackage'])) {
$postCommand = new command(
$config->config['postCommandPackage'],
$config->config['postCommandVariable'],
$config->getBasicVariable(),
['logFilePath' => $logFilePath],
);
foreach ($command->commands as $command) {
$postLog[$command] = shell_exec($command); // Exec
}
if (!empty($path = $config->config['logPath'])) {
file_put_contents($path . '/' . $projectName . '-postCommand-' . $time . '.log', packLog($log)); // Write Log
}
}
exit();
} else {
http_response_code(403);
exit();
}
} else {
http_response_code(404);
exit();
}
} else {
http_response_code(404);
exit();
}
function packLog($log)
{
return json_encode($log);
}