Commit | Line | Data |
---|---|---|
183344e4 | 1 | <?PHP |
ca451761 | 2 | /* |
e20f7315 PM |
3 | ini_set('display_errors', 1); |
4 | ini_set('display_startup_errors', 1); | |
5 | error_reporting(E_ALL); | |
ca451761 PM |
6 | */ |
7 | include_once('/var/www/secure.php'); //outside webserver | |
8 | ||
9f5b3b38 | 9 | |
9f5b3b38 PM |
10 | function cut_part_out($start,$end,$whole){ |
11 | $parts = explode($start,$whole); | |
12 | $subparts = explode($end,$parts[1]); | |
13 | $out = $subparts[0]; | |
14 | return $out; | |
15 | } | |
16 | ||
6a816a4b | 17 | function MVgetPage($url,$cookie,$post){ |
9f5b3b38 PM |
18 | $url = str_replace('[month]',date('F'),$url); // replace month January through December |
19 | $url = str_replace('[day]',date('j'),$url); // replace day 1 to 31 | |
20 | $url = str_replace('[yesterday]',date('j',strtotime('yesterday')),$url); // replace day 1 to 31 | |
21 | $url = str_replace('[year]',date('Y'),$url); // replace year Examples: 1999 or 2003 | |
22 | $curl = curl_init(); | |
23 | curl_setopt ($curl, CURLOPT_URL, $url); | |
24 | curl_setopt ($curl, CURLOPT_USERAGENT, sprintf("McGuire MEPS https://www.md-petition.com/ /%d.0",rand(4,50))); | |
25 | curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1); | |
26 | curl_setopt ($curl, CURLOPT_HEADER, 1); | |
27 | curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0); | |
28 | curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, true); | |
29 | if ($cookie != ''){ | |
30 | curl_setopt ($curl, CURLOPT_HTTPHEADER, array("Cookie: ASP.NET_SessionId=$cookie")); // use cookies | |
31 | } | |
32 | /* | |
33 | $postfields = array( | |
34 | 'upload_file' => '@file_to_upload.png', | |
35 | 'upload_text' => '@text_to_upload' | |
36 | ); | |
37 | */ | |
38 | if ($post != ''){ | |
39 | curl_setopt ($curl, CURLOPT_POSTFIELDS, $post); | |
40 | } | |
41 | $html = curl_exec ($curl); | |
42 | curl_close ($curl); | |
43 | return $html; | |
44 | } | |
45 | ||
79ab6eac | 46 | function md_voter_lookup($SearchFirstName,$SearchLastName,$DOBMonth,$DOBDay,$DOBYear,$SearchZipCode,$SearchHouseNumber,$SearchMiddleInitial){ |
ca451761 | 47 | global $petition; |
79ab6eac PM |
48 | $post['ctl00$MainContent$btnSearch'] = "Search"; |
49 | $post['btnSearch'] = "Search"; | |
50 | $post['ctl00$MainContent$listLanguages'] = "en"; | |
51 | $post['listLanguages'] = "en"; | |
52 | $post['ctl00$MainContent$txtSearchFirstName'] = $SearchFirstName; | |
8eeb49e5 | 53 | $post['txtSearchFirstName'] = $SearchFirstName; |
79ab6eac PM |
54 | $post['ctl00$MainContent$txtSearchLastName'] = $SearchLastName; |
55 | $post['txtSearchLastName'] = $SearchLastName; | |
56 | $post['ctl00$MainContent$txtDOBMonth'] = $DOBMonth; | |
57 | $post['txtDOBMonth'] = $DOBMonth; | |
58 | $post['ctl00$MainContent$txtDOBDay'] = $DOBDay; | |
59 | $post['txtDOBDay'] = $DOBDay; | |
60 | $post['ctl00$MainContent$txtDOBYear'] = $DOBYear; | |
61 | $post['txtDOBYear'] = $DOBYear; | |
62 | $post['ctl00$MainContent$txtSearchZipCode'] = $SearchZipCode; | |
63 | $post['txtSearchZipCode'] = $SearchZipCode; | |
64 | $post['ctl00$MainContent$txtSearchHouseNumber'] = $SearchHouseNumber; | |
65 | $post['txtSearchHouseNumber'] = $SearchHouseNumber; | |
66 | $post['ctl00$MainContent$txtSearchMiddleInitial'] = $SearchMiddleInitial; | |
67 | $post['txtSearchMiddleInitial'] = $SearchMiddleInitial; | |
68 | // start a session to get a cookie | |
69 | $form['url'] = 'https://voterservices.elections.maryland.gov/VoterSearch'; | |
6a816a4b | 70 | $form['html'] = MVgetPage($form['url'],'',''); |
79ab6eac PM |
71 | // extract the cookie from the header (see CURLOPT_HEADER) |
72 | $cookie = cut_part_out('ASP.NET_SessionId=',';',$form['html']); | |
73 | // extract the form elements we will need to post with our data | |
74 | $post['__VIEWSTATE'] = cut_part_out('id="__VIEWSTATE" value="','"',$form['html']); | |
75 | $post['__VIEWSTATEGENERATOR'] = cut_part_out('id="__VIEWSTATEGENERATOR" value="','"',$form['html']); | |
76 | $post['__VIEWSTATEENCRYPTED'] = cut_part_out('id="__VIEWSTATEENCRYPTED" value="','"',$form['html']); | |
77 | $post['__EVENTVALIDATION'] = cut_part_out('id="__EVENTVALIDATION" value="','"',$form['html']); | |
6a816a4b | 78 | $result['html'] = MVgetPage($form['url'],$cookie,$post); |
79ab6eac PM |
79 | //echo "<h1>STEP 2: SBE RESULTS</h1>"; |
80 | $return['debug'] = htmlspecialchars($result['html']); | |
81 | $return['html'] = $result['html']; | |
29c736a0 | 82 | $html = $petition->real_escape_string($result['html']); |
ca451761 PM |
83 | $petition->query("INSERT INTO `RemoteVoterList` (`date_validated`, `txtSearchFirstName`, `txtSearchLastName`, `txtDOBMonth`, `txtDOBDay`, `txtDOBYear`, `txtSearchZipCode`, `txtSearchHouseNumber`, `txtSearchMiddleInitial`, `sbe_response`) |
84 | VALUES (now(), '$SearchFirstName', '$SearchLastName', '$DOBMonth', '$DOBDay', '$DOBYear', '$SearchZipCode', '$SearchHouseNumber', '$SearchMiddleInitial', '$html')"); | |
5b251e46 | 85 | return $result['html']; |
79ab6eac | 86 | } |
6a816a4b | 87 | /* |
79ab6eac | 88 | if (isset($_POST['SearchFirstName'])){ |
5738f45e | 89 | $voter = md_voter_lookup($_POST['SearchFirstName'],$_POST['SearchLastName'],$_POST['DOBMonth'],$_POST['DOBDay'],$_POST['DOBYear'],$_POST['SearchZipCode'],$_POST['SearchHouseNumber'],$_POST['SearchMiddleInitial']); |
79ab6eac | 90 | echo $voter['html']; |
6a5ac174 PM |
91 | } |
92 | ?> | |
79ab6eac PM |
93 | <form method='POST'> |
94 | <table> | |
95 | <tr> | |
96 | <td>SearchFirstName</td><td><input name='SearchFirstName'></td> | |
97 | </tr> | |
98 | <tr> | |
99 | <td>SearchLastName</td><td><input name='SearchLastName'></td> | |
100 | </tr> | |
101 | <tr> | |
102 | <td>DOBMonth</td><td><input name='DOBMonth'></td> | |
103 | </tr> | |
104 | <tr> | |
105 | <td>DOBDay</td><td><input name='DOBDay'></td> | |
106 | </tr> | |
107 | <tr> | |
108 | <td>DOBYear</td><td><input name='DOBYear'></td> | |
109 | </tr> | |
110 | <tr> | |
111 | <td>SearchZipCode</td><td><input name='SearchZipCode'></td> | |
112 | </tr> | |
113 | <tr> | |
114 | <td>SearchHouseNumber*</td><td><input name='SearchHouseNumber'></td> | |
115 | </tr> | |
116 | <tr> | |
117 | <td>SearchMiddleInitial*</td><td><input name='SearchMiddleInitial'></td> | |
118 | </tr> | |
119 | <tr> | |
120 | <td>*Optional</td><td><input type='submit'></td> | |
121 | </tr> | |
122 | </table> | |
123 | </form> | |
6a816a4b PM |
124 | */ |
125 |