Advertisement
mikeymop

Untitled

Sep 21st, 2019
272
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 'url' \
  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/~/mid.php';
  20. $headers = [
  21. 'Content-Type: application/json; charset=utf-8'
  22. //'Host: web.njit.edu',
  23. //'Referer: https://web.njit.edu~/login.php', //Your referrer address
  24. ];
  25.  
  26. // echo json_encode($login);
  27. $ch = curl_init($Mid_url); //Init curl
  28. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  29. curl_setopt($ch, CURLOPT_POST, true);
  30. // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirect to new housing page
  31. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($login)); // concat ucid/pass
  32. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return results to stdout instead of echo
  33. $result = curl_exec($ch); // send the curl, return result (actually html page after redir)
  34. echo "curl errors?:\n";
  35. echo curl_error($ch);
  36. curl_close($ch);
  37. return $result;
  38. }
  39.  
  40. /* get data from index.thml */
  41. // $data = json_decode($HTTP_RAW_POST_DATA);
  42. $ucid_POST = 'bob123';//$data->ucid;
  43. $pass_POST = 'password123';//$data->pass;
  44.  
  45. /* get response from mid */
  46. $result = toMid($ucid_POST, $pass_POST);
  47. echo $result;
  48.  
  49. json_decode($result);
  50. $data = $result->response;
  51. echo "decoded data\n";
  52. echo $data;
  53. // echo json_decode($result);
  54. // $ucid_Response = $result->njitucid;
  55. // $njit_Response = $result->njitsuccess;
  56.  
  57. /* send this to index.html */
  58. $to_frt = array(
  59. 'response' => array(
  60. // 'njitucid' => $ucid_Response,
  61. // 'njitsuccess' => $njit_Response,
  62. 'dbucid' => $ucid_POST,
  63. 'dbsuccess' => '0',
  64. 'debug' => $result
  65. )
  66. );
  67.  
  68. // header('Content-Type: application/json;charset=utf-8');
  69. // echo json_encode($to_frt);
  70. echo "SUCCESS";
  71. http_response_code(200);
  72. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement