Guest User

Untitled

a guest
Feb 9th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. function logintorouter(){
  2. $.ajax({
  3. type: 'GET',
  4. dataType:"text",
  5. url: 'login.php'
  6. }).done(function(data){
  7. if(data.includes('WiFi')){
  8. setWiFichannel(); /*Wait for this function to finish before closing cURL connection */
  9. }else{
  10. alert('something went wrong, try again later!');
  11. }
  12. }).fail(function(data){
  13. alert('can not connect to router');
  14. });
  15. }
  16.  
  17. <?php
  18. function openRouter(){
  19. $username = 'admin';
  20. $password = 'pass';
  21.  
  22. $url="http://10.1.10.1/login/Auth";
  23. $postinfo = "username=".$username."&password=".$password;
  24.  
  25. $cookie_file_path = "cookie.txt";
  26.  
  27. $ch = curl_init();
  28. curl_setopt($ch, CURLOPT_HEADER, false);
  29. curl_setopt($ch, CURLOPT_NOBODY, false);
  30. curl_setopt($ch, CURLOPT_URL, $url);
  31. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  32.  
  33. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
  34. curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
  35. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:56.0) Gecko/20100101 Firefox/56.0");
  36. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  37. curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
  38. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  39. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
  40.  
  41. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  42. curl_setopt($ch, CURLOPT_POST, 1);
  43. curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
  44. curl_exec($ch);
  45.  
  46. curl_setopt($ch, CURLOPT_URL, "http://10.1.10.1/main.html#WiFi");
  47. $mainPage = curl_exec($ch);
  48.  
  49. curl_close($ch);
  50. /*As you can see I close the connection here so the setWiFichannel() will fail
  51. but I don't want to keep the connection alive forever*/
  52. return $mainPage;
  53. }
  54.  
  55. echo openRouter();
  56. ?>
Add Comment
Please, Sign In to add comment