Advertisement
Guest User

Untitled

a guest
Aug 10th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.28 KB | None | 0 0
  1. // Requires
  2. var Nightmare = require('nightmare');
  3. var nicknames = require('./nicknames.json');
  4. var fs = require('fs');
  5.  
  6. // Settings
  7. var debug = false;
  8. var showWindow = false;
  9.  
  10. var start = 0; // Start from x (NAMEx, EMAIL+x@domain.com)
  11. var end = 10;
  12.  
  13. var useNicknamesFile = false; // Use nicknames file, or just append numbers to username?
  14. var useRandomPassword = true; // Generate a random password?
  15. var screenshotResult = true; // Saves a screenshot per account creation if set to true
  16. var screenshotOnFailure = true; // Saves a screenshot even if registration failed
  17.  
  18. var outputFile = "PogoPlayer/accounts.csv"; // File which will contain the generated "username password" combinations.
  19. var outputFormat = "ptc,%NICK%,%PASS%,%LAT%,%LON%,%UN%\r\n"; // Format used to save the account data in outputFile. Supports %NICK%, %PASS%.
  20. var screenshotFolder = "output/screenshots/";
  21.  
  22. var country = "US"; // Country code (e.g. BE, FR, US, CA)
  23. var dob = "1990-01-01"; // Date of birth, yyyy-mm-dd
  24. var username = "CHANGEME"; // User- & display name. Make sure any "(username + number)@domain.com" is 100% unique, and is 6 characters minimum, but under 14 characters after the numbers are applied.
  25. var password = "CHANGEME"; // Static password for all accounts. Ignored if useRandomPassword is true.
  26. var email_user = "username"; // If your email is email@domain.com, enter "email"
  27. var email_domain = "domain.com"; // Domain of e-mail host
  28. var lat = "LATITUDE" // Location Latitude for initial login
  29. var lon = "LONGITUDE" // Location Longitude for initial login
  30.  
  31. // App data
  32. var url_ptc = "https://club.pokemon.com/us/pokemon-trainer-club/sign-up/";
  33. var useragent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36";
  34. var nightmare_opts = {
  35. show: showWindow,
  36. waitTimeout: 10000,
  37. gotoTimeout: 5000,
  38. loadTimeout: 5000
  39. };
  40.  
  41. // Settings check
  42. if (!useNicknamesFile && (username + end).length > 16) {
  43. console.log("Error: length of username + number can't be longer than 16 characters.");
  44. console.log("Please use a shorter nickname.");
  45. process.exit();
  46. }
  47.  
  48. if ((email_user + '+' + username + end + '@' + email_domain).length > 75) {
  49. console.log("Error: length of e-mail address including the + trick can't be longer than 75 characters.");
  50. console.log("Please use a shorter e-mail address and/or nickname.");
  51. process.exit();
  52. }
  53.  
  54. if (!useRandomPassword && password.length > 15) {
  55. console.log("Error: length of password can't be longer than 15 characters.");
  56. console.log("Please use a shorter password.");
  57. process.exit();
  58. }
  59.  
  60. // LETSAHGO
  61. var nightmare = Nightmare(nightmare_opts);
  62. nightmare.useragent(useragent);
  63.  
  64. createAccount(start);
  65.  
  66. // Helpers
  67.  
  68. function handleError(err) {
  69. if(debug) {
  70. console.log("[DEBUG] Error:" + JSON.stringify(err));
  71. }
  72.  
  73. return err;
  74. }
  75.  
  76. function randomPassword() {
  77. return Math.random().toString(36).substr(2, 8);
  78. }
  79.  
  80. function prepareNightmare(nightmare) {
  81. nightmare.useragent(useragent);
  82. }
  83.  
  84. function randomPassword() {
  85. return Math.random().toString(36).substr(2, 8);
  86. }
  87.  
  88. // Pages
  89. function createAccount(ctr) {
  90. console.log("Creating account " + ctr + " of " + end);
  91.  
  92. // Launch instance
  93. handleFirstPage(ctr);
  94. }
  95.  
  96. // First page
  97. function handleFirstPage(ctr) {
  98. if(debug) {
  99. console.log("[DEBUG] Handle first page #" + ctr);
  100. }
  101.  
  102. nightmare.goto(url_ptc)
  103. .evaluate(evaluateDobPage)
  104. .then(function(validated) {
  105. if(!validated) {
  106. // Missing form data, loop over itself
  107. console.log("[" + ctr + "] Servers are acting up... Trying again.");
  108. return function() { nightmare.wait(500).refresh().wait(); handleFirstPage(ctr); };
  109. } else {
  110. return function() { fillFirstPage(ctr); };
  111. }
  112. })
  113. .then(function(next) {
  114. // Handle next step: either a loop to first page in case of error, or form fill on success
  115. return next();
  116. })
  117. .catch(handleError)
  118. .then(function(err) {
  119. if (typeof err !== "undefined") {
  120. return handleFirstPage(ctr);
  121. }
  122. });
  123. }
  124.  
  125. function fillFirstPage(ctr) {
  126. if(debug) {
  127. console.log("[DEBUG] Fill first page #" + ctr);
  128. }
  129.  
  130. nightmare.evaluate(function(data) {
  131. document.getElementById("id_dob").value = data.dob;
  132.  
  133. var els = document.getElementsByName("id_country");
  134. for(var i = 0; i < els.length; i++) {
  135. els[i].value = data.country;
  136. }
  137.  
  138. return document.getElementById("id_dob").value;
  139. }, { dob: dob, country: country })
  140. .click("form[name='verify-age'] [type=submit]")
  141. .wait("#id_username")
  142. .then(function() {
  143. handleSignupPage(ctr);
  144. })
  145. .catch(handleError)
  146. .then(function(err) {
  147. if (typeof err !== "undefined") {
  148. return handleFirstPage(ctr);
  149. }
  150. });
  151. }
  152.  
  153. // Signup page
  154. function handleSignupPage(ctr) {
  155. if(debug) {
  156. console.log("[DEBUG] Handle second page #" + ctr);
  157. }
  158.  
  159. nightmare.evaluate(evaluateSignupPage)
  160. .then(function(validated) {
  161. if(!validated) {
  162. // Missing form data, loop over itself
  163. console.log("[" + ctr + "] Servers are acting up... Trying again.");
  164. return function() { nightmare.wait(500).refresh().wait(); handleFirstPage(ctr); };
  165. } else {
  166. return function() { fillSignupPage(ctr); };
  167. }
  168. }).then(function(next) {
  169. // Handle next step: either a loop to first page in case of error, or form fill on success
  170. return next();
  171. })
  172. .catch(handleError)
  173. .then(function(err) {
  174. if (typeof err !== "undefined") {
  175. return handleSignupPage(ctr);
  176. }
  177. });
  178. }
  179.  
  180. function fillSignupPage(ctr) {
  181. if(debug) {
  182. console.log("[DEBUG] Fill signup page #" + ctr);
  183. }
  184.  
  185. var _pass = password;
  186. var _nick = username + ctr;
  187.  
  188. if(useRandomPassword) {
  189. _pass = randomPassword();
  190. }
  191.  
  192. // Use nicknames list, or (username + number) combo?
  193. if(useNicknamesFile) {
  194. // Make sure we have a nickname left
  195. if(nicknames.length < 1) {
  196. throw Error("We're out of nicknames to use!");
  197. }
  198.  
  199. // Get the first nickname off the list & use it
  200. _nick = nicknames.shift();
  201. }
  202.  
  203. // Fill it all in
  204. nightmare.evaluate(function(data) {
  205. document.getElementById("id_password").value = data.pass;
  206. document.getElementById("id_confirm_password").value = data.pass;
  207. document.getElementById("id_email").value = data.email_user + "+" + data.nick + "@" + data.email_domain;
  208. document.getElementById("id_confirm_email").value = data.email_user + "+" + data.nick + "@" + data.email_domain;
  209. document.getElementById("id_screen_name").value = data.nick;
  210. document.getElementById("id_username").value = data.nick;
  211. }, { "pass": _pass, "nick": _nick, "email_user": email_user, "email_domain": email_domain })
  212. .check("#id_terms")
  213. .click("form[name='create-account'] [type=submit]")
  214. .wait(function() {
  215. return (document.getElementById("signup-signin") !== null || document.getElementById("btn-reset") !== null || document.body.textContent.indexOf("That username already exists") > -1);
  216. })
  217. .evaluate(function() {
  218. return (document.body.textContent.indexOf("Hello! Thank you for creating an account!") > -1);
  219. })
  220. .then(function(success) {
  221. if(success) {
  222. // Log it in the file of used nicknames
  223. var content = outputFormat.replace('%NICK%', _nick).replace('%PASS%', _pass).replace('%LAT%', lat).replace('%LON%', lon).replace('%UN%', _nick);
  224. fs.appendFile(outputFile, content, function(err) {
  225. //
  226. });
  227. }
  228.  
  229. if((success && screenshotResult) || screenshotOnFailure) {
  230. // Screenshot
  231. nightmare.screenshot(screenshotFolder + _nick + ".png");
  232. }
  233.  
  234. // Next one, or stop
  235. if(ctr < end) {
  236. return function() { createAccount(ctr + 1); };
  237. } else {
  238. return nightmare.end();
  239. }
  240. }).then(function(next) {
  241. return next();
  242. }).catch(handleError)
  243. .then(function(err) {
  244. if (typeof err !== "undefined") {
  245. return handleSignupPage(ctr);
  246. }
  247. });
  248. }
  249.  
  250. // Evaluations
  251. function evaluateDobPage() {
  252. var dob_value = document.getElementById("id_dob");
  253. return ((document.title === "The Official Pokémon Website | Pokemon.com") && (dob_value !== null));
  254. }
  255.  
  256. function evaluateSignupPage() {
  257. var username_field = document.getElementById("id_username");
  258. return ((document.title === "The Official Pokémon Website | Pokemon.com") && (username_field !== null));
  259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement