Guest User

Untitled

a guest
May 24th, 2018
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 KB | None | 0 0
  1. #!/usr/local/bin/perl -w
  2.  
  3. use LWP;
  4. use HTTP::Cookies;
  5. use HTML::LinkExtor;
  6. use HTML::Entities;
  7.  
  8. $argc = $#ARGV +1;
  9. if ($argc < 1)
  10. {
  11. die "URL needed";
  12. }
  13. else
  14. {
  15. $url = $ARGV[0];
  16. }
  17.  
  18. #######################
  19. $browser = LWP::UserAgent->new;
  20. $browser->agent("Mozilla/5.0");
  21. $cooooooookie = HTTP::Cookies->new(
  22. file => 'delicious.file.is.a.cookie',
  23. # where to read/write cookies
  24. autosave => 1,
  25. ignore_discard => 1,
  26. # save it to disk when done
  27. );
  28. $browser->cookie_jar($cooooooookie);
  29.  
  30. push @{ $browser->requests_redirectable }, 'POST';
  31.  
  32. $response=$browser->get($url);
  33.  
  34. #
  35. if ($url =~ m/^http:\/\/([a-z]+)\.?([a-zA-Z0-9]+)\.[a-z]+\/([a-zA-Z0-9~]+)/)
  36. {
  37. $file = "$1.inf";
  38. }
  39. else
  40. {
  41. die "Error";
  42. }
  43. if (-e $file)
  44. {
  45. #login($url);
  46. ;
  47. }
  48. else
  49. {
  50. open INF, ">$file" or die $!;
  51. createUser($url);
  52. print INF 'test11212@mail.com=guen1013';
  53. close INF;
  54. }
  55.  
  56. #get all links on site
  57. my ($pageParser) = HTML::LinkExtor->new(undef, $url);
  58. $pageParser->parse($response->content())->eof;
  59. @links = $pageParser->links;
  60.  
  61. #find all products on site
  62. @products = ();
  63. foreach $link(@links)
  64. {
  65. #check if link is a product
  66. if("$$link[2]" =~ /products_id/)
  67. {
  68. #add link to product array
  69. push(@products,$link);
  70. }
  71. }
  72.  
  73. #choose a random product to buy
  74. $numberOfLinks = @products;
  75. $ranNum = RandomNum($numberOfLinks);
  76. $purProduct = $products[$ranNum];
  77. $productUrl = "$$purProduct[2]";
  78.  
  79. print "This is my product $productUrl\n";
  80.  
  81. # buy the product
  82. buy($productUrl);
  83.  
  84.  
  85.  
  86.  
  87.  
  88. ###########################
  89. # Random number generator
  90. ###########################
  91. sub RandomNum
  92. {
  93. $range = $numberOfLinks-1; #number of products
  94. $randomNumber = int(rand($range));
  95. return $randomNumber;
  96. }
  97.  
  98.  
  99. ###########################
  100. # Create user account
  101. ###########################
  102. sub createUser
  103. {
  104. #$pageUrl = $ARGV[0];
  105. $response = $browser->get($url . '/index.php?main_page=login');
  106. print "login/checkout = ".$response->status_line."\n";
  107.  
  108. $response=$browser->post($url . '/index.php?main_page=create_account',
  109. [
  110. 'action' => 'process',
  111. "gender" => "f",
  112. "zone_country_id" => "223",
  113. "firstname" => "My",
  114. "street_address" => "1234 My Street",
  115. "city" => "Mycity",
  116. "state" => "CA",
  117. "postcode" => "55555",
  118. "password" => "guen1013",
  119. "telephone" => "5555555555",
  120. "dob" => "01/20/1909",
  121. "lastname" => "Test",
  122. "email_address" => 'test11212@mail.com',
  123. "confirmation" => "guen1013",
  124. ]
  125. );
  126. print $response->status_line."\n";
  127. #print $response->content."\n";
  128. }
  129.  
  130.  
  131.  
  132. ###########################
  133. # Login
  134. ###########################
  135. sub login
  136. {
  137. #login
  138. $page = $browser->get($url .'/index.php?main_page=login');
  139. $securityToken = 0;
  140. if($page->content =~ /securityToken" value="([a-z0-9]+)/)
  141. {
  142. $securityToken = $1;
  143. }
  144. print "This is the token $securityToken\n";
  145. $page = $browser->post($url .'/index.php?main_page=login&action=process&zenid='. $securityToken,
  146. [
  147. 'email_address' => 'test11212@mail.com',
  148. 'password' => 'guen1013',
  149. 'securityToken' => "$securityToken",
  150. ]
  151. );
  152. print $page->content;
  153. }
  154.  
  155.  
  156. ###########################
  157. # Buy product
  158. ###########################
  159. sub buy
  160. {
  161. $url = $ARGV[0];
  162. #get product information
  163. $response = $browser->get($productUrl);
  164. #$contents = $response->content();
  165.  
  166. #get product ID
  167. if($productUrl =~ m/products_id=([0-9]+)/)
  168. {
  169. $prodID = $1;
  170. # $prodID = 117;
  171. }
  172. print "This is the ID $prodID\n";
  173.  
  174. #get product price
  175. $price = 0.00;
  176. if( $response->content() =~ m/<title>(.*?)</)
  177. {
  178. $tempPrice = $1;
  179. }
  180. if($tempPrice =~ m/\$([0-9\.]+)/)
  181. {
  182. $price = $1;
  183. }
  184. print "The price is $price\n";
  185.  
  186. #add product to cart
  187. #$response = $browser->get($url . '/index.php?main_page=product_info&cPath=22&products_id=' . "$prodID" . '&number_of_uploads=2&action=add_product');
  188. $response = $browser->post($url . '/index.php?main_page=product_info&cPath=22&products_id=' . "$prodID" . '&number_of_uploads=2&action=add_product',
  189. [
  190. 'cart_quantity' => '1',
  191. 'products_id' => "$prodID",
  192. ]
  193. );
  194. login;
  195.  
  196. #$response = $browser->get($url . '/index.php?main_page=shopping_cart');
  197. #$response = $browser->post($url . '/index.php?main_page=shopping_cart',[]);
  198. #print $response->status_line."\n";
  199.  
  200. #finish check out
  201.  
  202. #check out step 1
  203. #$page = $browser->get($url . '/index.php?main_page=checkout_shipping');
  204. $page = $browser->post($url . '/index.php?main_page=checkout_shipping',
  205. [
  206. "shipping" => "storepickup_storepickup",
  207. "action" => "process"
  208. ]
  209. );
  210.  
  211. #check out step 2
  212. $page = $browser->post($url . '/index.php?main_page=checkout_payment',
  213. [
  214. "payment" => "cod",
  215. ]
  216. );
  217.  
  218. #check out step 3
  219. $page = $browser->post($url . '/index.php?main_page=checkout_confirmation', []);
  220. #print $page->status_line . "\n";
  221. # print $page->content;
  222.  
  223. }
Add Comment
Please, Sign In to add comment