Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 19th, 2012  |  syntax: PHP  |  size: 2.79 KB  |  views: 166  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. /*
  4.         param2str: Turns named-key parameter array into POST/GET string
  5. */
  6.  
  7. function param2str($paramArray)
  8. {
  9.         if( count($paramArray) < 1 ){
  10.                 return '';
  11.         }
  12.         $retVal = '';
  13.         $vals = array();
  14.                
  15.         // Blank string first, now we build like this
  16.         // key=value&key=value&key=value
  17.         foreach($paramArray as $key=>$val)
  18.         {
  19.                 $vals []= "$key=$val";
  20.         }
  21.        
  22.         $retVal = implode('&', $vals);
  23.        
  24.         return $retVal;
  25. }
  26.  
  27. /*
  28.  
  29.         COMMAND LINE JUNK
  30.        
  31. */
  32.  
  33. if($argc < 2){
  34.         die("This command must be run with a service tag as the first argument.\n");
  35. }
  36.  
  37. if(strlen($argv[1]) != 7){
  38.         die("Service tags must be 7 characters in length.\n");
  39. }
  40.  
  41. if(preg_match('/[^a-z^A-Z^0-9]/', $argv[1])){
  42.         die("Invalid character detected in service tag. Service tags can only be alphanumerics.\n");
  43. }
  44.  
  45. $service_tag = $argv[1];
  46.  
  47.  
  48. /*
  49.  
  50.         Original URL is http://www.dell.com/support/troubleshooting/us/en/555/ProductSelector
  51.  
  52.         Initial search POST hits http://www.dell.com/support/productselector/us/en/555/Select/SetSVCTag
  53.  
  54. */
  55.  
  56. // Service Tag Search POST
  57. // This just sorta sets up our cookie jar with the service tag embedded
  58.  
  59. $tag_post_url = "http://www.dell.com/support/productselector/us/en/555/Select/SetSVCTag";
  60. $tag_search_referer = "http://www.dell.com/support/productselector/us/en/555/Select/ProductSelectorHome?SelectMode=FullMode";
  61.  
  62. $search_post_parms = array(
  63.         "ServiceTagCode"        =>      $service_tag
  64. );
  65.  
  66.  
  67. // Build cURL request
  68. $curl_tag_search = curl_init($tag_post_url);
  69. $curl_tag_opts = curl_setopt_array( $curl_tag_search,
  70. array(
  71.  
  72.      CURLOPT_COOKIESESSION   =>      true,
  73.         CURLOPT_USERAGENT               =>      "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13",
  74.      CURLOPT_COOKIEFILE              =>      "cookies.txt",
  75.      CURLOPT_COOKIEJAR               =>      "cookies.txt",
  76.      CURLOPT_POST                    =>      true,
  77.      CURLOPT_POSTFIELDS              =>      param2str($search_post_parms),
  78. ));
  79.  
  80. $output = curl_exec($curl_tag_search);
  81. curl_close($curl_tag_search);
  82.  
  83. // Pull drivers page now
  84.  
  85. $drivers_url = "http://www.dell.com/support/drivers/us/en/555";
  86. //$drivers_referer ="http://www.dell.com/support/troubleshooting/us/en/555/Index";
  87.  
  88. $curl_drivers = curl_init($drivers_url);
  89. $curl_drivers_opts = curl_setopt_array( $curl_drivers,
  90. array (
  91.      CURLOPT_COOKIESESSION   =>      true,
  92.         CURLOPT_USERAGENT               =>      "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13",
  93.      CURLOPT_COOKIEFILE              =>      "cookies.txt",
  94.      CURLOPT_COOKIEJAR               =>      "cookies.txt",
  95.      CURLOPT_RETURNTRANSFER  =>      true,
  96. ));
  97.  
  98. $output = curl_exec($curl_drivers);
  99. curl_close($curl_drivers);
  100.  
  101. // Now search $output for download URLs and whatnot.
  102.  
  103.  
  104.  
  105. ?>