-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitlab_webhooks.php
66 lines (59 loc) · 1.72 KB
/
gitlab_webhooks.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
<?php
$url='';
function array2string($data){
$log_a = "";
foreach ($data as $key => $value) {
if(is_array($value)) {
if(strpos($key,'_link')===false){
$log_a .= "[b]".$key."[/b]"."\n". array2string($value). "\n";
}
} else {
if(strpos($key,'url')===false && strpos($key,'vatar')===false && $value!=''){
$log_a .= "[b]".$key."[/b]=".$value."\n";
} else if($key=='web_url' && $url==''){
$url = $value;
}
}
}
return $log_a;
}
if(isset($_GET['k'])){
$private_key = filter_input(INPUT_GET, 'k', FILTER_SANITIZE_STRING);
$icon = filter_input(INPUT_GET, 'i', FILTER_SANITIZE_STRING);
$sound = filter_input(INPUT_GET, 's', FILTER_SANITIZE_STRING);
$vibration = filter_input(INPUT_GET, 'v', FILTER_SANITIZE_STRING);
$time2live = filter_input(INPUT_GET, 'l', FILTER_SANITIZE_STRING);
foreach (getallheaders() as $name => $value) {
if($name=='X-Gitlab-Event'){
$title = 'Gitlab-Event: '.str_replace('_',' ',$value);
$url_title = 'Open '.str_replace('_',' ',$value);
}
}
$message = array2string(json_decode(file_get_contents('php://input'),true));
if($title=='') { $title = 'Gitlab Notification';}
if($message=='') { $message = 'no content ';}
$pushurl = 'https://www.pushsafer.com/api';
$data = array(
'k' => $private_key,
'm' => $message,
't' => $title,
'i' => $icon,
's' => $sound,
'v' => $vibration,
'l' => $time2live,
'u' => $url,
'ut' => $url_title
);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($pushurl, false, $context);
echo $result;
}
exit();
?>