-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_proxy.php
More file actions
50 lines (50 loc) · 1.62 KB
/
get_proxy.php
File metadata and controls
50 lines (50 loc) · 1.62 KB
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
<?php
function getResponseHeaders($response, $header_size) {
$header_str = substr($response, 0, $header_size);
$headers = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $header_str));
return $headers;
}
// function proxies an asynchronous request to the API
// via the curl library
function proxyRequest($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
curl_close($ch);
$headers = getResponseHeaders($response, $header_size);
$body = substr($response, $header_size);
foreach($headers as $hdr){
if (strpos($hdr, "Set-Cookie") === 0){
continue;
}
else {
header($hdr);
}
}
echo $body;
}
//Script body
if ($_GET['command']){
$qs = $_SERVER['QUERY_STRING'];
$api_url = "https://api.expensify.com?";
if ($_GET['command'] == "Authenticate"){
$partnerName = "applicant";
$partnerPassword = "d7c3119c6cdab02d68d9";
$useExpensifyLogin = "false";
$qs = $qs . "&partnerName=" . $partnerName . "&partnerPassword=" . $partnerPassword;
$qs = $qs . "&useExpensifyLogin=" . $useExpensifyLogin;
$api_url = $api_url . $qs;
proxyRequest($api_url);
}
else if ($_COOKIE['authToken']){
$authToken = $_COOKIE['authToken'];
$qs = $qs . "&authToken=" . $authToken;
$api_url = $api_url . $qs;
proxyRequest($api_url);
}
}
?>