Advertisement
mikeymop

Untitled

Sep 21st, 2019
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. <?php
  2. function toMid($user, $pass) {
  3. /* Takes a ucid and password as args
  4. Builds a curl req to the middle-end
  5. Returns the response
  6.  
  7. Making:
  8. curl -L 'https://aevitepr2.njit.edu/MyHousing/login.cfm' \
  9. -H 'Content-Type: application/x-www-form-urlencoded' \
  10. -H 'Upgrade-Insecure-Requests: 1'\
  11. --data 'ucid=[ucid]&pass=[pass]'
  12. */
  13.  
  14. $login = array(
  15. "ucid" => $user,
  16. "pass" => $pass
  17. );
  18.  
  19. $Mid_url = 'https://web.njit.edu/~md537/mid.php';
  20. $headers = [
  21. 'Content-Type: application/json; charset=utf-8'
  22. //'Host: web.njit.edu',
  23. ];
  24.  
  25. // echo json_encode($login);
  26. $ch = curl_init($Mid_url); //Init curl
  27. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  28. curl_setopt($ch, CURLOPT_POST, true);
  29. // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirect to new housing page
  30. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($login)); // concat ucid/pass
  31. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return results to stdout instead of echo
  32. $result = curl_exec($ch); // send the curl, return result (actually html page after redir)
  33. echo "curl errors?:\n";
  34. echo curl_error($ch);
  35. curl_close($ch);
  36. return $result;
  37. }
  38.  
  39. /* get data from index.thml */
  40. // $data = json_decode($HTTP_RAW_POST_DATA);
  41. $ucid_POST = 'useranme';//$data->ucid;
  42. $pass_POST = 'password';//$data->pass;
  43.  
  44. /* get response from mid */
  45. $result = toMid($ucid_POST, $pass_POST);
  46. echo $result;
  47.  
  48. // $result = json_decode($result, 1);
  49. echo "decoded data\n";
  50. var_dump((json_decode($result))); // this is null
  51. // echo json_decode($result);
  52. // $ucid_Response = $result->njitucid;
  53. // $njit_Response = $result->njitsuccess;
  54.  
  55. /* send this to index.html */
  56. $to_frt = array(
  57. 'response' => array(
  58. // 'njitucid' => $ucid_Response,
  59. // 'njitsuccess' => $njit_Response,
  60. 'dbucid' => $ucid_POST,
  61. 'dbsuccess' => '0',
  62. 'debug' => $result
  63. )
  64. );
  65.  
  66. // header('Content-Type: application/json;charset=utf-8');
  67. // echo json_encode($to_frt);
  68. echo "SUCCESS";
  69. http_response_code(200);
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement