/
pin.php
88 lines (72 loc) · 2.81 KB
/
pin.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
<?php
//echo 'hello!';
function submitHTTPpost($cookie_file, $url, $isPOSTsubmission, $params)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
// set submission to POST if needed
if ($isPOSTsubmission == true)
{
curl_setopt($ch, CURLOPT_POST, true);
}
// set parameters for HTTP body, if any
if ($params != "")
{
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
$response = (curl_exec($ch));
curl_close($ch);
return $response;
}
// create cookie jar and direct to Harvard pin authentication site
$cookie_file = tempnam(sys_get_temp_dir(), '');
//$responseArr = array();
// direct to Harvard pin authentication site using GET submission
$response = submitHTTPpost($cookie_file, "https://www.pin1.harvard.edu/pin/authenticate?__authen_application=VPA_HUDS_MYHUDS", false, "");
// submit HUID & PIN for authentication & remember cookies via POST submission
$response = submitHTTPpost($cookie_file, "https://www.pin1.harvard.edu/pin/submit-login", true, "__authen_application=VPA_HUDS_MYHUDS&__authen_login_type=PIN&__authen_id=".$_POST['huid']."&__authen_password=".$_POST['password']);
// check if there's a page that's being the PIN site is trying to redirect
preg_match('/<meta http-equiv="Refresh" content="3; URL=([\w\:\/\.\?=\%\&\+]+)/', $response, $matches);
// if there's a match to the reg ex above, redirect to the appropriate link
if (count($matches) > 1)
{
$response = submitHTTPpost($cookie_file, $matches[1], false, "");
}
// check whether the the scrip should submit an order
/*if (empty($_POST["order"]))
{
return;
}*/
//echo "right before third submission";
// submit order via GET submission
$response = submitHTTPpost($cookie_file,$_POST['url'] ,false, "");
//echo "third submission done";
//$response = submitHTTPpost($cookie_file,"http://www.dining.harvard.edu/myhuds/students/breakfast/?action=submit&pickup=2012-01-16&order%5Blocation_id%5D=FD&order%5Bdelivery_time%5D=07%3A00&pickup_list=0&items%5B8%20oz%20Cottage%20Cheese%5D=on",false, "");
header("HTTP/1.1 200 OK");
//echo $response;
$str = (file_get_contents($cookie_file));
// use a reg ex to check whether the login cookie has been activated
preg_match('/\.www\.dining\.harvard\.edu([\s]+)TRUE/',$str, $matches);
if (count($matches) > 1)
{
// echo 'it worked!';
$arr = array('didWork'=>'yes');
echo json_encode($arr);
//header("HTTP/1.1 200 OK");
//return $response;
}
else
{
$arr = array('didWork'=>'no');
//echo 'it failed =(';
echo json_encode($arr);
//header("HTTP/1.1 200 OK");
//return $response;
}
?>