-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
125 lines (102 loc) · 3.21 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$AEweb = false;
$AEdidRun = array([true, "init", ""]);
include 'config.php';
if (!isset($settings)) {
exit("I cannot continue without settings, please see config.sample.php for an example.");
}
// General regular expressions:
$expressions = [
'assign' => '/(@' . $settings['username'] . ')?( )?(please)?( )?assign( )?me/',
'unassign' => '/(@' . $settings['username'] . ')?( )?(please)?( )?unassign( )?me/'
];
include 'discord.php';
function api($url, $postData = null, $extra = "PATCH")
{
global $settings;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $extra);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
curl_setopt(
$curl,
CURLOPT_HTTPHEADER,
array(
"User-Agent: Aurora Editor Bot",
"Accept: application/vnd.github+json",
"Authorization: Bearer {$settings['github_token']}",
"X-GitHub-Api-Version: 2022-11-28"
)
);
$result = curl_exec($curl);
if (curl_errno($curl)) {
discord('Error:' . curl_error($curl));
}
curl_close($curl);
return $result;
}
if (PHP_SAPI === 'cli') {
if (!isset($argv[1])) {
echo "Please use php {$argv[0]} payload.json";
exit(2);
} else {
$file = "payload/" . $argv[1];
if (file_exists($file) && !preg_match("/\.\./", $file)) {
echo "Overwrite payload with test data from payload/{$argv[1]}.\r\n";
$_POST['payload'] = file_get_contents($file);
} else {
echo file_exists($file) ? "File contains invalid characters" : "File {$file} not found";
exit(3);
}
}
}
if (isset($_POST['payload'])) {
if (PHP_SAPI !== 'cli') {
// Comply with GitHub's webhook secret
http_response_code(200);
}
// Save payload log for traceability
file_put_contents(
$fileName = "gh-action/" . time() . ".json",
$_POST['payload']
);
// The log URL.
$logURL = $settings['serverURL'] . $fileName;
// discord("Log: {$logURL}");
// delete old logs
foreach ($file = glob("gh-action/*.json") as $filename) {
// Disable error reporting
error_reporting(0);
// Check if file exists
if (file_exists($filename)) {
// If older than 24hours, then delete
if (time() - filemtime($filename) > ((60 * 60) * 24)) {
// Delete
unlink($filename);
}
}
// Enable error reporting
error_reporting(E_ALL);
}
if (!isset($_POST['payload'])) {
discord("No payload found.\r\nLog: {$logURL}");
exit();
}
// Create $payload
$payload = json_decode($_POST['payload'], true);
if (!isset($payload['action'])) {
// discord("No action found.\r\nLog: {$logURL}");
exit();
}
foreach ($file = glob("action/*.php") as $filename) {
include $filename;
}
} else {
if (!headers_sent()) {
header("location: https://github.com/AuroraEditor/");
}
}