Advertisement
Guest User

Untitled

a guest
Feb 12th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. <form action="sms.php" method="post">
  2. <input type="text" name="uid" value=""/>
  3. <input type="password" name="pwd" value=""/>
  4. <input type="number" name="mobile" value=""/>
  5. <textarea cols="30" rows="10" name="msg"></textarea>
  6. <input type="submit" name="submit" value="Send"/>
  7.  
  8. <?php
  9. class WAY2SMSClient
  10. {
  11. var $curl;
  12. var $timeout = 30;
  13. var $jsToken;
  14. var $way2smsHost;
  15. var $refurl;
  16.  
  17. function login($username, $password)
  18. {
  19. $this->curl = curl_init();
  20. $uid = urlencode($username);
  21. $pwd = urlencode($password);
  22. // Go where the server takes you :P
  23. curl_setopt($this->curl, CURLOPT_URL, "http://way2sms.com");
  24. curl_setopt($this->curl, CURLOPT_HEADER, true);
  25. curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, false);
  26. curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, TRUE);
  27. $a = curl_exec($this->curl);
  28. if (preg_match('#Location: (.*)#', $a, $r))
  29. $this->way2smsHost = trim($r[1]);
  30. // Setup for login
  31. curl_setopt($this->curl, CURLOPT_URL, $this->way2smsHost . "Login1.action");
  32. curl_setopt($this->curl, CURLOPT_POST, 1);
  33. curl_setopt($this->curl, CURLOPT_POSTFIELDS, "username=" . $uid . "&password=" . $pwd . "&button=Login");
  34. curl_setopt($this->curl, CURLOPT_COOKIESESSION, 1);
  35. curl_setopt($this->curl, CURLOPT_COOKIEFILE, "cookie_way2sms");
  36. curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, 1);
  37. curl_setopt($this->curl, CURLOPT_MAXREDIRS, 20);
  38. curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
  39. curl_setopt($this->curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5");
  40. curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, $this->timeout);
  41. curl_setopt($this->curl, CURLOPT_REFERER, $this->way2smsHost);
  42. $text = curl_exec($this->curl);
  43. // Check if any error occured
  44. if (curl_errno($this->curl))
  45. return "access error : " . curl_error($this->curl);
  46. // Check for proper login
  47. $pos = stripos(curl_getinfo($this->curl, CURLINFO_EFFECTIVE_URL), "ebrdg.action");
  48. if ($pos === "FALSE" || $pos == 0 || $pos == "")
  49. return "invalid login";
  50. // Set the home page from where we can send message
  51. $this->refurl = curl_getinfo($this->curl, CURLINFO_EFFECTIVE_URL);
  52. $newurl = str_replace("ebrdg.action?id=", "main.action?section=s&Token=", $this->refurl);
  53. curl_setopt($this->curl, CURLOPT_URL, $newurl);
  54. // Extract the token from the URL
  55. $this->jstoken = substr($newurl, 50, -41);
  56. //Go to the homepage
  57. $text = curl_exec($this->curl);
  58. return true;
  59. }
  60.  
  61. function send($phone, $msg)
  62. {
  63. $result = array();
  64. // Check the message
  65. if (trim($msg) == "" || strlen($msg) == 0)
  66. return "invalid message";
  67. // Take only the first 140 characters of the message
  68. $msg = substr($msg, 0, 140);
  69. // Store the numbers from the string to an array
  70. $pharr = explode(",", $phone);
  71. // Send SMS to each number
  72. foreach ($pharr as $p) {
  73. // Check the mobile number
  74. if (strlen($p) != 10 || !is_numeric($p) || strpos($p, ".") != false) {
  75. $result[] = array('phone' => $p, 'msg' => $msg, 'result' => "invalid number");
  76. continue;
  77. }
  78. // Setup to send SMS
  79. curl_setopt($this->curl, CURLOPT_URL, $this->way2smsHost . 'smstoss.action');
  80. curl_setopt($this->curl, CURLOPT_REFERER, curl_getinfo($this->curl, CURLINFO_EFFECTIVE_URL));
  81. curl_setopt($this->curl, CURLOPT_POST, 1);
  82. curl_setopt($this->curl, CURLOPT_POSTFIELDS, "ssaction=ss&Token=" . $this->jstoken . "&mobile=" . $p . "&message=" . $msg . "&button=Login");
  83. $contents = curl_exec($this->curl);
  84. //Check Message Status
  85. $pos = strpos($contents, 'Message has been submitted successfully');
  86. $res = ($pos !== false) ? true : false;
  87. $result[] = array('phone' => $p, 'msg' => $msg, 'result' => $res);
  88. }
  89. return $result;
  90. }
  91. /**
  92. * logout of current session.
  93. */
  94. function logout()
  95. {
  96. curl_setopt($this->curl, CURLOPT_URL, $this->way2smsHost . "LogOut");
  97. curl_setopt($this->curl, CURLOPT_REFERER, $this->refurl);
  98. $text = curl_exec($this->curl);
  99. curl_close($this->curl);
  100. }
  101. }
  102.  
  103. function sendWay2SMS($uid, $pwd, $phone, $msg)
  104. {
  105. $client = new WAY2SMSClient();
  106. $client->login($uid, $pwd);
  107. $result = $client->send($phone, $msg);
  108. $client->logout();
  109. return $result;
  110. }
  111. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement