All pastes #1410906 Raw Edit

Anonymous

public php v1 · immutable
#1410906 ·published 2009-05-03 04:04 UTC
rendered paste body
   1.      <?php   2.          3.          /*****************************   4.           * Neopets Restock Alerter   *   5.           * Author: Neon           *   6.           * Start Date: 05/01/2009    *   7.           * Last Update: 05/02/2009   *   8.           *****************************/   9.             10.           set_time_limit(0);  11.             12.           // START PHP WRAPPER  13.             14.           class httpwrapper {  15.              private $cookies;  16.              private $lastpage;  17.              private $html;  18.              private $headers;  19.         20.              function __construct() {  21.                  $this->useproxy = false;  22.                  $this->cookies = array();  23.                  $this->lastpage = NULL;  24.              }  25.         26.              public function getLastPage() {  27.                  return $this->lastpage;  28.              }  29.         30.              public function clearCookies() {  31.                  $this->cookies = array();  32.              }  33.         34.              public function req($type, $url, $postdata = NULL, $referer = NULL, $follow_location = true, $return_headers = false) {  35.                  if($referer == NULL) {  36.                      if($this->lastpage != NULL)  37.                          $r = "Referer: " . $this->lastpage . "\r\n";  38.                  } else  39.                      $r = "Referer: $referer\r\n";  40.         41.                  $url = str_replace("http://", "", $url);  42.                  $host = $this->getHost($url);  43.                  $path = $this->getPath($url);  44.         45.                  $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8";  46.         47.                  $type = strtoupper($type);  48.                  if(!in_array($type,array("GET","POST"))) $type="GET";  49.         50.                  $f = fsockopen($host . ":80");  51.                  if($f) {  52.                      $h = "$type $path HTTP/1.1\r\n";  53.                      $h .= "HOST: $host\r\n";  54.                      $h .= "User-Agent: $agent\r\n";  55.                      $h .= $this->cookieString();  56.                      $h .= $r;  57.                      if($type == "POST") {  58.                          $length = strlen($postdata);  59.                          $h .= "Content-Type: application/x-www-form-urlencoded\r\n";  60.                          $h .= "Content-Length: $length\r\n";  61.                      }  62.                      $h .= "Connection: close\r\n\r\n";  63.         64.                      if($type == "POST")  65.                          $h .= $postdata;  66.         67.                      fwrite($f,$h);  68.                      while(!feof($f))  69.                          $data.=fgets($f,256);  70.                      list($headers,$html) = explode("\r\n\r\n", $data, 2);  71.                      //list($rand,$html) = explode("\r\n", $html, 2);  72.                      $this->html = $html;  73.                      $this->lastpage = "http://".$url;  74.                      $this->process_headers($headers,$url,$follow_location,$return_headers);  75.                      return ($return_headers) ? $this->headers : $this->html;  76.                  }  77.              }  78.         79.              private function getHost($url) {  80.                  if(strpos($url,"/") === FALSE)  81.                      return $url;  82.                  else  83.                      return $this->gsb("<".$url,"<","/");  84.              }  85.         86.              private function getPath($url) {  87.                  if(strpos($url,"/") === FALSE)  88.                      return "/";  89.                  else  90.                      return "/".$this->gsb($url.">","/",">");  91.              }  92.         93.              private function process_headers($headers,$url,$follow,$return) {  94.                  $this->headers = $headers;  95.                  $lines = explode("\n", $headers);  96.                  foreach($lines AS $line) {  97.                      if(substr($line,0,10) == "Set-Cookie") {  98.                          $cookie = $this->gsb($line, "Set-Cookie: ", ";");  99.                          list($key,$val) = explode("=", $cookie, 2); 100.                          $this->cookies[$key] = $val; 101.                      } else if(substr($line,0,8) == "Location" && $follow == true) { 102.                          $location = $this->gsb($line.">>", "Location: ", ">>"); 103.                          $this->req("GET", "http://".$this->getHost($url).$location, null, null, true, $return); 104.                      } 105.                  } 106.              } 107.        108.              private function cookieString() { 109.                  if(count($this->cookies) > 0) { 110.                      $string = "Cookie:"; 111.                      foreach($this->cookies AS $k=>$v) 112.                          $string .= " $k=$v;"; 113.                      return $string."\r\n"; 114.                  } 115.              } 116.        117.              private function gsb($search, $start, $end) { 118.                  list($a,$b) = explode($start, $search, 2); 119.                  list($a,$b) = explode($end, $b, 2); 120.                  return $a; 121.              } 122.          } 123.          124.          // END PHP WRAPPER 125.          126.              $form = <<<FRM 127.              <html> 128.              <h2>Neopets Restock Alerter</h2> 129.              <form method="POST"> 130.              Neopets Username: <input type="text" name="user" /><br /> 131.              Neopets Password: <input type="text" name="pass" /><br /><br /><br /> 132.              <h4>Restock Alerter Settings</h4> 133.          Refresh Time: <input type="text" name="min" size="2" /> - <input type="text" name="max" size="2" /><br /><br /> 134.          Shop ID: <input type="text" maxlength="3" name="shopid" size="2" /><br /><br /> 135.              Check for Restock Ban?: <input type="checkbox" name="restockban" /> <br /> 136.              ------ Restock Ban Refresher (In Minutes) 137.              <input type="text" name="rmin" size="2" /> - <input type="text" name="rmax" size="2" /><br /><br /> 138.              <input type="checkbox" name="pausetime" /> Pause every <input type="text" name="pminevery" size="2" /> - <input type="text" name="pmaxevery" size="2" /> minutes for <input type="text" name="pminfor" size="2" /> - <input type="text" name="pmaxfor" size="2" /> minutes.<br /><br /> 139.              List Input 140.              <textarea name="itemlist"></textarea><br /> 141.              <input type="submit" name="Submit" value="Submit" /> 142.              </form> 143.              </html> 144.      FRM; 145.        146.              $banned = <<<FRM 147.              <script>alert('You have been restock banned! :(');</script> 148.      FRM; 149.        150.          if(!$_POST["user"] || !$_POST["pass"] || !$_POST['min'] || !$_POST['max'] || !$_POST['shopid'] || !$_POST['itemlist']) 151.              die($form); 152.          153.        154.              $user = $_POST['user']; 155.              $pass = $_POST['pass']; 156.              $refreshTimeMin = $_POST['min']; 157.              $refreshTimeMax = $_POST['max']; 158.              $shop = $_POST['shopid']; 159.              $restockBanCheck = $_POST['restockban']; 160.              $restockBanMin = $_POST['rmin'] * 60; 161.              $restockBanMax = $_POST['rmax'] * 60; 162.              $pauseTimeCheck = $_POST['pausetime']; 163.              $pauseEveryMin = $_POST['pminevery'] * 60; 164.              $pauseEveryMax = $_POST['pmaxevery'] * 60; 165.              $pauseForMin = $_POST['pminfor'] * 60; 166.              $pauseForMax = $_POST['pmaxfor'] * 60; 167.              $itemList = $_POST['itemlist']; 168.              $items = explode("\r\n", $itemList); 169.              $soldOut = "Sorry, we are sold out of everything! We get restocked every eight minutes or so, so please come back soon."; 170.              $restock = <<<FRM 171.              <script type="text/javascript"> 172.              var win = window.open().document; 173.              win.location = "http://www.neopets.com/objects.phtml?type=shop&obj_type=$shop"; 174.              </script> 175.      FRM; 176.        177.              $w = new httpwrapper(); 178.              $login = $w->req("POST", "http://www.neopets.com/login.phtml", "username=$user&password=$pass&destination=%2Findex.phtml&x=".rand(0,100)."&y=".rand(0,30), "http://www.neopets.com/hi.phtml", false, true); 179.        180.              if(strpos($login, "badpassword.phtml") !== FALSE) 181.                      die("Bad Password!"); 182.              elseif(strpos($login, "failed_bday") !== FALSE) 183.                      die("Birthday Needed!"); 184.              elseif(strpos($w->req("GET", "http://www.neopets.com/"), "Welcome, <a") === FALSE) 185.                      die("Reason for error is unknown. You could possibly be frozen! ;-;"); 186.                      187.              $time = time(); $time2 = $time; 188.              while(true) { 189.                      $rsWait = rand($restockBanMin, $restockBanMax); 190.                      $pauseWait = rand($pauseEveryMin, $pauseEveryMax); 191.                      $pBetween = (time() - $time) / 60; 192.                      $rBetween = (time() - $time2) / 60; 193.        194.                      if($pBetween >= $pauseWait) { 195.                              sleep(rand($pauseForMin, $pauseForMax)); 196.                              $time = time(); 197.                      } 198.        199.                      $shophtml = $w->req("GET", "http://www.neopets.com/objects.phtml?type=shop&obj_type=$shop"); 200.        201.                      if(strpos($shophtml, $soldOut) !== FALSE && $rBetween >= $rsWait) { 202.                              $restockBanHTML = $w->req("GET", "http://www.neopets.com/objects.phtml?type=shop&obj_type=21"); 203.                              if(strpos($restockBanHTML, $soldOut) !== FALSE); 204.                                      die($banned); 205.                              $time2 = time(); 206.                      } 207.                      foreach($items AS $item) { 208.                              if(strpos($shophtml, $item) !== FALSE) { 209.                                      die($restock); 210.                              } 211.                      } 212.              } 213.      ?>