forked from claudex/olcc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
post.php
69 lines (63 loc) · 2.33 KB
/
post.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
<?php
$VERSION = '1.0.0';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_REQUEST['posturl']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
if (isset($_REQUEST['ua'])) {
$ua = $_REQUEST['ua'];
}
else {
$ua = "olcc-me/" . $VERSION;
}
$message = $_REQUEST['postdata'];
$message = str_replace(array('#{plus}#', '#{amp}#', '#{dcomma}#', '#{percent}#'), array(urlencode('+'), urlencode('&'), '%3B', '%25'), $message);
$referer = $_REQUEST['posturl'];
$referer = substr($referer, 0, strrpos($referer, '/')+1);
curl_setopt($ch, CURLOPT_REFERER, $referer);
$rheaders = array(
'Accept: text/xml',
'Cache-Control: no-cache, must-revalidate' //,
// 'Referer: ' + $referer
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $rheaders);
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
if (get_magic_quotes_gpc()) {
curl_setopt($ch, CURLOPT_POSTFIELDS, stripslashes($message));
}
else {
curl_setopt($ch, CURLOPT_POSTFIELDS, $message);
}
if (isset($_REQUEST['cookie'])) {
curl_setopt($ch, CURLOPT_COOKIE, $_REQUEST['cookie']);
}
$res = curl_exec($ch);
if ($res === false) {
if(curl_errno($ch) == CURLE_OPERATION_TIMEOUTED) {
$http_code = 408;
} else {
$http_code = 500;
}
http_response_code($http_code);
echo( "Erreur ".$http_code." : ". curl_error($ch));
} else {
echo('({');
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = preg_split("\n", substr($res, 0, $header_size));
foreach ($headers as $header) {
if (strpos($header, ':') > 0) {
list($name, $val) = preg_split(":", $header);
$tval = trim($val);
if (!empty($tval)) {
echo("'" . trim(str_replace("-", "", $name)) . "':'" . addslashes($tval) . "',");
}
}
}
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
http_response_code($http_code);
echo("'referer':\"" . $referer . "\",");
echo("'httpcode':" . $http_code . ",");
echo("'result':\"".str_replace("\n","\\n",addslashes(substr($res, $header_size, strlen($res))))."\"");
echo('})');
}