Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.88 KB | None | 0 0
  1. //#region Global Variables
  2. const readln = process.stdout;
  3. const { promisify } = require('util');
  4. const fs = require('fs');
  5. const readFile = promisify(fs.readFile);
  6. const open = promisify(fs.open);
  7. const stat = promisify(fs.stat);
  8. const mkdir = promisify(fs.mkdir);
  9. const path = require('path');
  10. const { XMLHttpRequest } = require('xmlhttprequest');
  11. const puppeteer = require('puppeteer');
  12. const devices = require('puppeteer/DeviceDescriptors');
  13. const iPhonex = devices['iPhone X'];
  14. const isPkg = typeof process.pkg !== 'undefined';
  15.  
  16. let chromiumPath = (isPkg ?
  17. puppeteer.executablePath().replace(
  18. process.platform!='win32' ? /^.*?\/node_modules\/puppeteer\/\.local-chromium/ : /^.*?\\node_modules\\puppeteer\\\.local-chromium/,
  19. path.join(path.dirname(process.execPath), 'chromium')
  20. ) :
  21. puppeteer.executablePath()
  22. );
  23.  
  24. const siteData = {
  25. appName: 'dofus',
  26. app: 'https://www.dofus.com/fr/mmorpg/jouer',
  27. appHome: 'https://www.dofus.com/fr',
  28. appLogout: 'https://account.ankama.com/sso?action=logout&from=https%3A%2F%2Fwww.dofus.com%2Ffr',
  29. username: '#userlogin',
  30. password: '#user_password',
  31. verify_pass: '#user_password_confirm',
  32. email: '#user_mail',
  33. birthDay: '#ak_field_1',
  34. birthMonth: '#ak_field_2',
  35. birthYear: '#ak_field_3',
  36. newletterCheck: 'body > div.ak-mobile-menu-scroller > div.container.ak-main-container > div > div:nth-child(1) > div > div > div > div.ak-inner-block > div > div.col-md-8 > div > form > fieldset > div > div > div > div:nth-child(8) > div > div > label',
  37. submit: '#submit_field',
  38. siteKey: '6LfbFRsUAAAAACrqF5w4oOiGVxOsjSUjIHHvglJx'
  39. };
  40.  
  41. const defaultData = {
  42. inputFileName: 'proxy.txt',
  43. outputFileName: 'accounts.txt',
  44. dirs: {
  45. captureDir: 'capture',
  46. logDir: 'log',
  47. outDir: 'out'
  48. },
  49. proxyAllowedCountries: [
  50. 'BD','BE','BJ','MM','BO','CM','CA','CY','FR','GB','IQ','JP','PG','PY','PR','PE','SV','SD','PS','LK'
  51. ]
  52. };
  53.  
  54. const stdClrs = {
  55. Reset: "\x1b[0m",
  56. Bright: "\x1b[1m",
  57. Dim: "\x1b[2m",
  58. Underscore: "\x1b[4m",
  59. Blink: "\x1b[5m",
  60. Reverse: "\x1b[7m",
  61. Hidden: "\x1b[8m",
  62. FgBlack: "\x1b[30m",
  63. FgRed: "\x1b[31m",
  64. FgGreen: "\x1b[32m",
  65. FgYellow: "\x1b[33m",
  66. FgBlue: "\x1b[34m",
  67. FgMagenta: "\x1b[35m",
  68. FgCyan: "\x1b[36m",
  69. FgWhite: "\x1b[37m",
  70. BgBlack: "\x1b[40m",
  71. BgRed: "\x1b[41m",
  72. BgGreen: "\x1b[42m",
  73. BgYellow: "\x1b[43m",
  74. BgBlue: "\x1b[44m",
  75. BgMagenta: "\x1b[45m",
  76. BgCyan: "\x1b[46m",
  77. BgWhite: "\x1b[47m"
  78. };
  79.  
  80. const ipValidityUrl = 'https://hidemyna.me/api/geoip.php?out=js&htmlentities';
  81. const antiCaptchaKey = 'KEYHERE'; //Anti-captcha key
  82. const createTaskUrl = 'https://api.anti-captcha.com/createTask';
  83. const getTaskResultUrl = 'https://api.anti-captcha.com/getTaskResult';
  84. const mailDomain = '@exemple.com'; //remplacez par votre domaine mail
  85. const getMailListUrl = 'https://mailsac.com/api/addresses/*@exemple.com/messages?_mailsacKey=SITEKEYHERE'; //mettre ici domaine mail & clé api mail
  86.  
  87. // Filtering and detecting arguments
  88. const arguments = process.argv;
  89. let skipNext = false;
  90. let inputFile, outputFile,
  91. useProxy = true,
  92. useEmulation = false;
  93.  
  94. arguments.forEach((arg, key) => {
  95. if(key < 1 || skipNext){
  96. skipNext = false;
  97. return;
  98. }
  99. if(arg[0] === '-'){
  100. skipNext = true;
  101. switch (arg[1]) {
  102. case 'i':
  103. inputFile = arguments[key+1];
  104. break;
  105.  
  106. case 'o':
  107. outputFile = arguments[key+1];
  108. break;
  109.  
  110. case '-':
  111. switch (arg.substring(2)) {
  112. case 'use-proxy':
  113. useProxy = true;
  114. break;
  115.  
  116. case 'no-proxy':
  117. useProxy = false;
  118. break;
  119.  
  120. case 'use-emulation':
  121. useEmulation = true;
  122. break;
  123.  
  124. case 'no-emulation':
  125. useEmulation = false;
  126. break;
  127.  
  128. default:
  129. break;
  130. }
  131. break;
  132.  
  133. default:
  134. skipNext = false;
  135. console.error('Unknown argument Encountered');
  136. break;
  137. }
  138. }
  139. });
  140.  
  141. if(!inputFile) {
  142. inputFile = defaultData.inputFileName;
  143. }
  144. if(!outputFile) {
  145. outputFile = defaultData.dirs.outDir+'/'+defaultData.outputFileName;
  146. }
  147.  
  148. //#endregion
  149.  
  150. //#region Helper Functions
  151.  
  152. const delay = (seconds) => new Promise((resolves) => {
  153. setTimeout(resolves, seconds*1000);
  154. });
  155.  
  156. const tempId = () => {
  157. const getRandomString = () => Math.random().toString(36).substr(2, 9);
  158. let isNumber = (temp, key) => !isNaN(temp.charAt(key));
  159.  
  160. let tempStr = getRandomString();
  161. let firstChar = isNumber(tempStr, 0);
  162. let numCount = 0;
  163. while(firstChar || numCount==0) {
  164. numCount = 0;
  165. tempStr = getRandomString();
  166. firstChar = isNumber(tempStr, 0);
  167. for (let i = 0; i < tempStr.length; i++) {
  168. if(isNumber(tempStr, i)){
  169. numCount++;
  170. }
  171. }
  172. }
  173.  
  174. let firstLtr = tempStr.charAt(0);
  175. return tempStr.replace(firstLtr, firstLtr.toUpperCase());
  176. }
  177.  
  178. const getRnd = function(min, max) {
  179. return Math.floor(Math.random() * (max - min + 1)) + min;
  180. }
  181.  
  182. const getFrenchMonth = function(month) {
  183. const months = {
  184. "1": "Janvier",
  185. "2": "Fevrier",
  186. "3": "Mars",
  187. "4": "Avril",
  188. "5": "Mai",
  189. "6": "Juin",
  190. "7": "Juillet",
  191. "8": "Aout",
  192. "9": "Septembre",
  193. "10": "Octobre",
  194. "11": "Novembre",
  195. "12": "Decembre",
  196. };
  197.  
  198. return months[`${month}`];
  199. }
  200.  
  201. var _loadTick = 0;
  202. var _msg = "";
  203. const waiting = (msg, t) => {
  204. _msg = msg;
  205. return setInterval(() => {
  206. readln.clearLine();
  207. readln.cursorTo(0);
  208. _loadTick = (_loadTick + 1) % 4;
  209.  
  210. var dots = new Array(_loadTick + 1).join(".");
  211. readln.write(msg + dots);
  212. }, t);
  213. }
  214.  
  215. const stopWaiting = (timer, status) => {
  216. clearInterval(timer);
  217. loadTick = 0;
  218. readln.clearLine();
  219. readln.cursorTo(0);
  220. readln.write(_msg + "... "+ status + stdClrs.Reset+ "\n");
  221. }
  222.  
  223. const keypress = async () => {
  224. process.stdin.setRawMode(true)
  225. return new Promise(resolve => process.stdin.once('data', () => {
  226. process.stdin.setRawMode(false)
  227. resolve()
  228. }));
  229. }
  230.  
  231. const getTwoDigitString = (no) => ("0" + no.toString()).slice(-2);
  232.  
  233. var getDateTime = () => {
  234. let date = new Date();
  235. return "["+getTwoDigitString(date.getDate())+"-"+getTwoDigitString(date.getMonth())+"-"+getTwoDigitString(date.getFullYear())+" "+getTwoDigitString(date.getHours())+":"+getTwoDigitString(date.getMinutes())+":"+getTwoDigitString(date.getSeconds())+"]";
  236. }
  237.  
  238. //#endregion
  239.  
  240. //#region Utility Functions
  241. //#region File Control Functions
  242.  
  243. const checkDir = async (dir, callback) => new Promise(async (resolve, reject) => {
  244. await stat(dir, function(err, stats) {
  245. if(!err) return;
  246. if (err && err.errno === -4058) {
  247. mkdir(dir);
  248. } else {
  249. callback(err)
  250. }
  251. });
  252. });
  253.  
  254. const readInputFile = (fileName) => new Promise(async (resolve, reject) => {
  255. console.log('\x1b[36m%s\x1b[0m', 'Createur de compte - Syliaz#1452');
  256. console.log('\x1b[36m%s\x1b[0m', 'Discord : https://discordapp.com/invite/FqwpVQW');
  257.  
  258. try {
  259. readFile(fileName, 'utf-8', (err, content) => {
  260. if(err) {
  261. return reject(err);
  262. }
  263.  
  264. var proxyList = [];
  265. content.split('\n').forEach((line, key) => {
  266. let proxy = line.trim().split(':');
  267.  
  268. if(proxy == '' || proxy[0].split('.').length < 4) {
  269. // console.error('Invalid type of IP address Detected: ', proxy);
  270. return;
  271. }
  272.  
  273. let tempObj = {};
  274. tempObj["_id"] = key;
  275. tempObj["ip"] = proxy[0];
  276. tempObj["port"] = proxy[1];
  277.  
  278. proxyList.push(tempObj);
  279. });
  280.  
  281. if(proxyList.length == 0) {
  282. console.log('No Proxy IPs found in the given file.\nTerminating application...');
  283. return reject({ errorId: 1, msg: 'No IP found' });
  284. }
  285.  
  286. console.log(`${proxyList.length} proxy IPs found`);
  287. return resolve(proxyList);
  288. });
  289. } catch (err) {
  290. console.log(`Error occured when reading \'${fileName}\'': `, err);
  291. return reject({ errorId: -1, error: err });
  292. }
  293. });
  294.  
  295. const writeOutputFile = (fileName, data) => new Promise(async (resolve, reject) => {
  296. open(fileName, 'a', (err, fd) => {
  297. if (err) throw err;
  298. fs.appendFile(fd, data, 'utf8', (err) => {
  299. fs.close(fd, (err) => {
  300. if (err) throw err;
  301. });
  302. if (err) throw err;
  303. resolve({ status: 'success' });
  304. });
  305. });
  306. });
  307.  
  308. const LOG = async (log) => {
  309. // await writeOutputFile('log/LOG.txt', `${getDateTime()} ${log}\n`);
  310. }
  311.  
  312. //#endregion
  313. //#region Browser Control functions
  314.  
  315. // Initialize browser window for proxy details
  316. const initBrowser = (proxy) => new Promise(async (resolve, reject) => {
  317. try {
  318. let browser = await puppeteer.launch({
  319. executablePath: chromiumPath,
  320. // headless: false,
  321. // slowMo: 100,
  322. args: (useProxy)?[ `--proxy-server=${proxy.ip}:${proxy.port}` ]:[]
  323. });
  324.  
  325. resolve(browser);
  326. } catch (error) {
  327. console.log('Error in initBrowser: ', error);
  328. // reject(error);
  329. }
  330. });
  331.  
  332. // Close pre-opened browser window
  333. const closeBrowser = (browser) => new Promise(async (resolve, reject) => {
  334. try {
  335. await browser.close();
  336. return resolve({ status: 'success' });
  337. } catch (error) {
  338. console.log('Error in closeBrowser: ', error);
  339. reject(error);
  340. }
  341. });
  342.  
  343. //#endregion
  344. //#region Network Requests
  345.  
  346. const creatAntiCaptchaTask = () => new Promise(async (resolve, reject) => {
  347. let http = new XMLHttpRequest();
  348.  
  349. http.onload = function(e) {
  350. if(http.readyState === 4) {
  351. let taskData = JSON.parse(http.responseText);
  352. if(taskData.errorId !== 0)
  353. reject(taskData);
  354. resolve(taskData);
  355. } else console.log('Error in response Data \'anti-captcha task creation\'');
  356. }
  357.  
  358. try {
  359. http.open("POST", createTaskUrl, true);
  360. http.responseType = "json";
  361. http.send(JSON.stringify({
  362. "clientKey": `${antiCaptchaKey}`,
  363. "task":
  364. {
  365. "type":"NoCaptchaTaskProxyless",
  366. "websiteURL":"https:\/\/www.dofus.com\/fr\/mmorpg\/jouer",
  367. "websiteKey": `${siteData.siteKey}`
  368. },
  369. "softId":0,
  370. "languagePool":"en"
  371. }));
  372. } catch(err) {
  373. console.log('Error in anti-captcha request', err);
  374. reject(err);
  375. }
  376. });
  377.  
  378. const getAntiCaptchaResponseKey = (taskId) => new Promise(async (resolve, reject) => {
  379. let http = new XMLHttpRequest();
  380.  
  381. http.onload = async function(e) {
  382. let response = JSON.parse(http.responseText);
  383.  
  384. if(response.status === "processing") {
  385. setTimeout(() => {
  386. return resolve(getAntiCaptchaResponseKey(taskId));
  387. }, 2000);
  388. } else {
  389. if(response.errorId !== 0) return reject(response);
  390. return resolve(response);
  391. }
  392. }
  393.  
  394. try {
  395. http.open("POST", getTaskResultUrl, true);
  396. http.responseType = "json";
  397. http.send(JSON.stringify({
  398. clientKey: `${antiCaptchaKey}`,
  399. taskId: `${taskId}`
  400. }));
  401. } catch (error) {
  402. console.log('Error in anti-captcha responseKey request', error);
  403. return reject(error);
  404. }
  405. });
  406.  
  407. const getValidationLink = (username) => new Promise(async (resolve, reject) => {
  408. let http = new XMLHttpRequest();
  409.  
  410. http.onload = function(e) {
  411. let mails = JSON.parse(http.responseText);
  412.  
  413. let mailCount = 0;
  414. mails.forEach((mail) => {
  415. if(mail.originalInbox == username + mailDomain){
  416. mailCount++;
  417. mail.links.forEach((link) => {
  418. if(link.substr(8,13) == 'www.dofus.com'){
  419. return resolve(link);
  420. }
  421. });
  422. }
  423. });
  424.  
  425. if(mailCount == 0){
  426. setTimeout(() => {
  427. return resolve(getValidationLink(username));
  428. }, 2000);
  429. }
  430. }
  431.  
  432. http.open("GET", getMailListUrl, true);
  433. http.responseType = "json";
  434. http.send();
  435. });
  436.  
  437. const getAllMails = () => new Promise(async (resolve, reject) => {
  438. let http = new XMLHttpRequest();
  439. let mailList = [];
  440.  
  441. http.onload = () => {
  442. let mails = JSON.parse(http.responseText);
  443.  
  444. mails.forEach((mail) => {
  445. mailList.push(mail);
  446. })
  447.  
  448. return resolve(mailList);
  449. }
  450. http.open("GET", getMailListUrl, true);
  451. http.responseType = "json";
  452. http.send();
  453. });
  454.  
  455. const getMail = (mailId) => new Promise(async (resolve) => {
  456. let http = new XMLHttpRequest();
  457.  
  458. http.onload = () => {
  459. if(http.readyState === 4){
  460. let msg = JSON.parse(http.responseText);
  461. // console.log(mailId, msg);
  462. return resolve(msg);
  463. }
  464. }
  465. http.open("GET", `https://mailsac.com/api/addresses/*@exemple.com/messages/${mailId}/?_mailsacKey=SITEKEYHERE`);//mettre domaine mail & clé api mail
  466. http.send();
  467. });
  468.  
  469. const deleteMail = (mailId) => new Promise(async (resolve) => {
  470. let http = new XMLHttpRequest();
  471.  
  472. http.onload = () => {
  473. if(http.readyState === 4){
  474. let msg = JSON.parse(http.responseText);
  475. // console.log(mailId, msg);
  476. return resolve(msg);
  477. }
  478. }
  479. http.open("DELETE", `https://mailsac.com/api/addresses/*@gmail.msdc.co/messages/${mailId}/?_mailsacKey=SITEKEYHERE`);//mettre domaine mail & clé api mail
  480. http.send();
  481. })
  482.  
  483. //#endregion
  484. //#endregion
  485.  
  486. //#region Task Handling Functions
  487.  
  488. const handleProxyFile = async () => {
  489. // TODO
  490. }
  491.  
  492. const handleAntiCaptcha = async () => {
  493. await LOG('Creating Anti-Captcha Task');
  494. let task;
  495. try {
  496. task = await creatAntiCaptchaTask();
  497. await LOG(`Anti-Captcha Task created: ${JSON.stringify(task)}`);
  498. } catch (error) {
  499. await LOG(`An error occured: ${error}`);
  500. return false;
  501. }
  502.  
  503. await LOG('Requesting Anti-Captcha response key')
  504. let response = null;
  505. try {
  506. response = await getAntiCaptchaResponseKey(task.taskId);
  507. await LOG(`Anti-Captcha response key recieved: ${JSON.stringify(response)}`);
  508.  
  509. response = response.solution.gRecaptchaResponse;
  510. } catch (error) {
  511. await LOG(`An error occured: ${error}`);
  512. return false;
  513. }
  514.  
  515. return response;
  516. }
  517.  
  518. const handleFormSubmission = async (dataIn) => {
  519. let browser, status;
  520. if(useProxy) {
  521. await LOG('Using Proxy for browser');
  522. console.log(`Using proxy ${dataIn.proxy.ip}:${dataIn.proxy.port}`);
  523.  
  524. browser = await initBrowser(dataIn.proxy);
  525. await LOG('Initializing Browser');
  526.  
  527. let page = await browser.newPage();
  528.  
  529. //#region Proxy Validity Check
  530.  
  531. let proxyValidity = waiting("Checking proxy Validity", 800);
  532. try {
  533. await LOG('Trying to validate IP using an API');
  534. await page.goto(ipValidityUrl, { waitUntil: "load" });
  535. } catch (err) {
  536. await LOG('Error occured during loading IP validation API');
  537. await page.close();
  538. await closeBrowser(browser);
  539. stopWaiting(proxyValidity, (stdClrs.FgRed + "ERROR"));
  540.  
  541. return {
  542. errorId: 3,
  543. msg: 'Unknown Proxy Error',
  544. error: err
  545. };
  546. }
  547. await LOG('IP validation URL loaded');
  548.  
  549. let proxyInfo = await page.evaluate(() => {
  550. let div = document.querySelector('body > pre'),
  551. jsonObject = JSON.parse(div.innerText),
  552. key = Object.keys(jsonObject);
  553.  
  554. return jsonObject[key];
  555. })
  556. await LOG(`Proxy infomarmation recorded: ${proxyInfo}`);
  557.  
  558. await LOG('Checking for validity of IP');
  559. let isValid = defaultData.proxyAllowedCountries.find((element) => {
  560. return (proxyInfo[0] == element)
  561. }) == proxyInfo[0];
  562.  
  563. if(!isValid) {
  564. await LOG('IP is not from a valid country');
  565. await page.close();
  566. await closeBrowser(browser);
  567. stopWaiting(proxyValidity, (proxyInfo[0]+stdClrs.FgMagenta + " INVALID"));
  568.  
  569. return {
  570. errorId: 2,
  571. msg: 'Proxy IP location is not valid'
  572. }
  573. }
  574. stopWaiting(proxyValidity, (stdClrs.FgGreen + " VALID"));
  575. await LOG('IP is from a valid country');
  576.  
  577. //#endregion
  578.  
  579. await page.close();
  580. } else {
  581. await LOG('Initializing Browser');
  582. console.log('Account Creation Started');
  583. browser = await initBrowser();
  584. }
  585. await LOG('Account Creation Started');
  586.  
  587. let noOfPages = dataIn.cycles;
  588. for (let page = 0; page < noOfPages; page++) {
  589. await LOG(`Starting ${page+1} of ${dataIn.cycles} form submission`);
  590. let webPage = await browser.newPage();
  591.  
  592. if(useEmulation) await webPage.emulate(iPhonex);
  593.  
  594. let msgStart = stdClrs.FgYellow + `[${page+1}] ` + stdClrs.Reset;
  595.  
  596. //#region Loading Signup Page
  597.  
  598. let pageLoading = waiting(msgStart + "Page Loading", 800);
  599. try {
  600. await webPage.goto(siteData.app, { waitUntil: "load" });
  601. } catch (err) {
  602. if(noOfPages < 5) noOfPages++;
  603. stopWaiting(pageLoading, (stdClrs.FgRed + "ERROR"));
  604. await LOG(`Error occured while loading: ${siteData.app} ${err}`);
  605. await webPage.close();
  606.  
  607. continue;
  608. }
  609. await LOG(`${siteData.app} URL loaded`);
  610. stopWaiting(pageLoading, (stdClrs.FgGreen + "DONE"));
  611.  
  612. //#endregion
  613.  
  614. //#region Anti-Captcha handling
  615.  
  616. await LOG('Handling Anti-captcha');
  617. let responseKeyHandle = waiting(msgStart + "Handling Anti-captcha", 500);
  618.  
  619. let antiCaptchaKey = await handleAntiCaptcha();
  620. if(antiCaptchaKey == false) {
  621. stopWaiting(responseKeyHandle, (stdClrs.FgRed + "ERROR"));
  622. status = {
  623. errorId: 4,
  624. msg: 'Error in Anticaptcha Key'
  625. }
  626. break;
  627. }
  628.  
  629. await LOG('Anti-captcha response key recieved successfully');
  630. stopWaiting(responseKeyHandle, (stdClrs.FgGreen + "DONE"))
  631.  
  632. //#endregion
  633.  
  634. //#region Page Processing
  635. // process html and inject response key
  636. let injectLoading = waiting(msgStart + "Page Injection", 400);
  637. await LOG('Page Alteration Started');
  638. let alteration = await webPage.evaluate((key) => {
  639. let divs = document.querySelectorAll("body > div"),
  640. iframe = document.querySelector('body > iframe'),
  641. keyArea = document.querySelector('#g-recaptcha-response'),
  642. form = document.querySelector('body > div.ak-mobile-menu-scroller > div.container.ak-main-container > div > div:nth-child(1) > div > div > div > div.ak-inner-block > div > div.col-md-8 > div > form'),
  643. btn = document.createElement('input');
  644.  
  645. if(iframe == null) return {
  646. errorId: 5,
  647. error: 'Iframe not found',
  648. content: iframe
  649. };
  650. iframe.parentNode.removeChild(iframe);
  651.  
  652. if(divs == null) return {
  653. errorId: 6,
  654. error: 'Div not found',
  655. content: div
  656. };
  657. divs.forEach((div) => {
  658. let top = div.style.top;
  659. if(top!==''){
  660. div.parentNode.removeChild(div);
  661. }
  662. });
  663.  
  664. try {
  665. keyArea.style.display = "block";
  666. keyArea.innerHTML = key;
  667.  
  668. btn.setAttribute('id', 'submit_field');
  669. btn.setAttribute('type', 'submit');
  670. form.append(btn);
  671. } catch (error) {
  672. return {
  673. errorId: 7,
  674. msg: 'Error on alteration',
  675. error: error
  676. };
  677. }
  678.  
  679. return {
  680. errorId: 0
  681. };
  682. }, antiCaptchaKey );
  683.  
  684. if(alteration.errorId != 0) {
  685. await LOG(`Error in page injection: ${JSON.stringify(alteration)}`)
  686. stopWaiting(injectLoading, (stdClrs.FgRed + "ERROR"));
  687. await webPage.close();
  688.  
  689. continue;
  690. }
  691. await LOG('Page Alteration Done');
  692. stopWaiting(injectLoading, (stdClrs.FgGreen + "DONE"));
  693.  
  694. // #endregion
  695.  
  696. //#region Form Submission
  697.  
  698. let formFilling = waiting(msgStart + "Form Filling", 500);
  699. await LOG('Starting Form auto filling');
  700. let userName = tempId(),
  701. password = tempId(),
  702. email = "eMail nta3k",
  703. bDay = ("0" + getRnd(1,10).toString()).slice(-2),
  704. bMonth = getFrenchMonth(getRnd(1, 12)).toString().substr(0,2),
  705. bYear = getRnd(1987, 1998).toString();
  706.  
  707. let formData = {
  708. username: userName,
  709. password: password,
  710. email: email,
  711. birth: {
  712. day: bDay,
  713. month: bMonth,
  714. year: bYear
  715. }
  716. };
  717. await LOG(`Form filling started using random data ${JSON.stringify(formData)}`);
  718.  
  719. try {
  720. await Promise.all([
  721. await webPage.focus(siteData.username),
  722. await webPage.keyboard.type(userName),
  723. await webPage.keyboard.press('Tab'),
  724.  
  725. await webPage.focus(siteData.password),
  726. await webPage.keyboard.type(password),
  727. await webPage.keyboard.press('Tab'),
  728.  
  729. await webPage.focus(siteData.verify_pass),
  730. await webPage.keyboard.type(password),
  731. await webPage.keyboard.press('Tab'),
  732.  
  733. await webPage.focus(siteData.email),
  734. await webPage.keyboard.type(email),
  735. await webPage.keyboard.press('Tab'),
  736.  
  737. await webPage.focus(siteData.birthDay),
  738. await webPage.keyboard.type(bDay),
  739.  
  740. await webPage.focus(siteData.birthMonth),
  741. await webPage.keyboard.type(bMonth),
  742.  
  743. await webPage.focus(siteData.birthYear),
  744. await webPage.keyboard.type(bYear)
  745. ]);
  746. await LOG('Form filling finished');
  747. } catch (error) {
  748. await LOG(`Error on form fill: ${error}`);
  749. stopWaiting(formFilling, (stdClrs.FgRed + "ERROR"));
  750. await webPage.close();
  751.  
  752. status = {
  753. errorId: 10,
  754. msg: 'Error on form filling',
  755. error: error
  756. }
  757.  
  758. break;
  759. }
  760.  
  761. await webPage.screenshot({ path: `./capture/${Date.now()}_${formData.username}_${formData.password}_beforeSubmission.png`, fullPage: true });
  762. await LOG('Submitting filled signup form');
  763. await webPage.click(siteData.submit);
  764. await webPage.waitFor(2*1000);
  765.  
  766. stopWaiting(formFilling, (stdClrs.FgGreen + "DONE"));
  767.  
  768. //#endregion
  769.  
  770. //#region Checking Submission State
  771.  
  772. let checkingSubmission = waiting(msgStart + "Checking Submission State", 500);
  773.  
  774. await LOG('Searching for submit state in DOM');
  775. let submitState = await webPage.evaluate(() => {
  776. let okDiv = document.querySelectorAll('.ak-register-email-validate'),
  777. problemDiv = document.querySelectorAll('.ak-register-error');
  778.  
  779. if(okDiv.length >= 1){
  780. return {
  781. state: 'OK'
  782. };
  783. } else if(problemDiv.length >= 1) {
  784. return {
  785. state: 'ERROR'
  786. };
  787. } else {
  788. return {
  789. state: 'UNKNOWN'
  790. };
  791. }
  792. });
  793.  
  794. if(submitState.state != 'OK') {
  795. await LOG('Form was not submitted successfully: ' + JSON.stringify(submitState));
  796. stopWaiting(checkingSubmission, (stdClrs.FgRed + "ERROR"));
  797.  
  798. await webPage.screenshot({ path: `./capture/${Date.now()}_error_${formData.username}_${formData.password}.png`, fullPage: true });
  799. await webPage.close();
  800.  
  801. status = {
  802. errorId: 5,
  803. msg: 'Submission Error'
  804. };
  805. break;
  806. }
  807. await LOG('Form submitted successfully');
  808. await webPage.screenshot({ path: `./capture/${Date.now()}_${formData.username}_${formData.password}_submitted.png`, fullPage: true });
  809. await LOG('Submitted form page Captured');
  810. stopWaiting(checkingSubmission, (stdClrs.FgGreen + "DONE"));
  811.  
  812. //#endregion
  813.  
  814. //#region Form Validation & Logging Out
  815. /*
  816. let checkingEmail = waiting(msgStart + "Checking Validation Email", 500);
  817. await LOG('Searching for validation Email')
  818. let validationLink = await getValidationLink(formData.username.toLowerCase());
  819. await LOG('Got the validation link: '+ validationLink);
  820. stopWaiting(checkingEmail, (stdClrs.FgGreen + "DONE"));
  821.  
  822. let validateAccount = waiting(msgStart + "Validating Account", 500);
  823. try {
  824. await webPage.goto(validationLink, { waitUntil: 'load' });
  825. await LOG('Account validated');
  826. await webPage.screenshot({ path: `./capture/${Date.now()}_${formData.username}_${formData.password}_validated.png`, fullPage: true });
  827. await writeOutputFile(outputFile, `${formData.username}:${formData.password}\n`);
  828. } catch (error) {
  829. stopWaiting(validateAccount, (stdClrs.FgRed + "ERROR"));
  830. await LOG('Error on Account validation: '+error);
  831. await webPage.screenshot({ path: `./capture/${Date.now()}_${formData.username}_${formData.password}_errorvalidated.png`, fullPage: true });
  832. await webPage.close();
  833.  
  834. status = {
  835. errorId: 6,
  836. msg: 'Error on validation',
  837. error: error
  838. };
  839. break;
  840. }
  841. stopWaiting(validateAccount, (stdClrs.FgGreen + "DONE"));
  842.  
  843. */
  844. let loggingOut = waiting(msgStart + "Logging Out", 500);
  845. await LOG('Logging out of the account');
  846. await webPage.goto(siteData.appHome, { waitUntil: 'load' });
  847. if(webPage.url() != siteData.appHome) {
  848. // console.log('Cloudfare detected', webPage.url());
  849. await LOG('Logging out not succeeded');
  850. await webPage.screenshot({ path: `./capture/${Date.now()}_${formData.username}_${formData.password}_errorAfterValidation.png`, fullPage: true });
  851. await webPage.close();
  852.  
  853. stopWaiting(loggingOut, (stdClrs.FgRed + "ERROR"));
  854. break;
  855. }
  856. await webPage.screenshot({ path: `./capture/${Date.now()}_${formData.username}_${formData.password}_homeAfterValidation.png`, fullPage: true });
  857.  
  858. await webPage.goto(siteData.appLogout, { waitUntil: 'load' });
  859. await webPage.screenshot({ path: `./capture/${Date.now()}_${formData.username}_${formData.password}_logoutAfterValidation.png`, fullPage: true });
  860. await LOG('Logged out successfully');
  861. stopWaiting(loggingOut, (stdClrs.FgGreen + "DONE"));
  862.  
  863. let deleteMails = waiting(msgStart + "Deleting Validation Email", 500);
  864. await LOG('Deleting validation mail');
  865. let mailList = await getAllMails();
  866. let unsubscribeUrl = null;
  867. if(mailList.length < 1) {
  868. console.log('No Mails in inbox');
  869. await LOG('No mails found for delete');
  870. stopWaiting(deleteMails, (stdClrs.FgMagenta + "NO MAILS"));
  871. }else {
  872. let isDone = false;
  873. for (let i = 0; i < mailList.length; i++) {
  874. const element = mailList[i];
  875. if(element.originalInbox.split('@')[0] == formData.username) {
  876. await deleteMail(element._id).then(async (conf) => {
  877. await LOG(`Validation Mail deleted: ${conf}`);
  878. });
  879. isDone = true;
  880.  
  881. element.links.forEach((link) => {
  882. if(link.split(formData.username).length > 1) {
  883. unsubscribeUrl = link;
  884. }
  885. });
  886. await LOG(`Unsubscription link was ${unsubscribeUrl?'':'not'} found: ${unsubscribeUrl}`);
  887. }
  888. }
  889. stopWaiting(deleteMails, isDone?(stdClrs.FgGreen + "DONE"):(stdClrs.FgRed + "ERROR"));
  890. }
  891.  
  892.  
  893. //#endregion
  894.  
  895. await LOG(`Account ${page+1} of 3, Created Successfully`);
  896. console.log(`Account ${page+1} of 3, Created Successfully`);
  897. await webPage.close();
  898. }
  899. await closeBrowser(browser);
  900.  
  901. if(status){
  902. return status;
  903. }
  904. return { errorId: 0, msg: 'successfull' };
  905. }
  906.  
  907. const handleTasks = async () => {
  908. console.clear();
  909. let proxyList = [
  910.  
  911. ];
  912. if(useProxy) {
  913. proxyList = await readInputFile(inputFile)
  914. .catch((err) => {
  915. console.log(err);
  916. process.exit(0);
  917. });
  918. }
  919.  
  920. let length = proxyList.length;
  921. length = (length > 0)?length:1;
  922. for (let i = 0; i < length; i++) {
  923. let status = await handleFormSubmission(useProxy?{
  924. proxy: {
  925. ip: proxyList[i].ip,
  926. port: proxyList[i].port
  927. },
  928. cycles: 3,
  929. entryNo: i
  930. } : {
  931. cycles: 3,
  932. entryNo: i
  933. });
  934. }
  935.  
  936. return;
  937. }
  938.  
  939. //#endregion
  940.  
  941. (async function() {
  942. var dirs = Object.values(defaultData.dirs);
  943. for (const dir in defaultData.dirs) {
  944. if (defaultData.dirs.hasOwnProperty(dir)) {
  945. const element = defaultData.dirs[dir];
  946.  
  947. checkDir(element, (err) => {
  948. console.log('Error Occured', err);
  949. });
  950. }
  951. }
  952. await delay(2);
  953. await handleTasks();
  954.  
  955. process.exit();
  956. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement