Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const request = require('request');
  2. const HttpsProxyAgent = require('https-proxy-agent');
  3. const qs = require('querystring');
  4. const fs = require('fs');
  5. var anticaptcha = require('./anticaptcha')('apikey');
  6. const CARACTERS = 'abcdefghijklmnopqrstuvwxyz';
  7. const hasLetter = /[^a-z]+/i;
  8. const hasNumber = /\d+/;
  9. const HAAPI_SETTINGS = {
  10.     GUEST_CREATION_URI: 'url',
  11.     VALIDATE_GUEST_URI: 'url',
  12.     CREATE_API_URI: 'url',
  13.     GETMAIL: 'mail url',
  14.     ENDGETMAIL: 'mail key end url'
  15. };
  16. const ERROR = {
  17.     ACCOUNT_VALIDATION: {
  18.         key: 'account_validation',
  19.         text: 'La validation du compte a échoué.'
  20.     },
  21.     PROXY_DENIED: {
  22.         key: 'proxy_error',
  23.         text: "Le proxy n'a pas pu accéder à la requête."
  24.     }
  25. };
  26. var agent = null;
  27. String.prototype.randomChar = function() {
  28.     return this.charAt(Math.floor(Math.random() * this.length));
  29. };
  30. String.prototype.replaceAt = function(index, replacement) {
  31.     return this.substr(0, index) + replacement + this.substr(index + replacement.length);
  32. };
  33. Object.prototype.useAgent = function(agent, config) {
  34.     if (agent) {
  35.         this.agent = agent;
  36.         for (let property in config) {
  37.             if (property != 'useAgent') {
  38.                 this[property] = config[property];
  39.             }
  40.         }
  41.     }
  42.     return this;
  43. };
  44. module.exports = config => {
  45.     return {
  46.         randomString(withNumber = true, prefixedString = "", suffix = "") {
  47.             const caracterList = withNumber ? CARACTERS + '0123456789' : CARACTERS;
  48.  
  49.             while (prefixedString.length < 8) {
  50.                 prefixedString += caracterList.randomChar();
  51.             }
  52.             if (withNumber) {
  53.                 if (!hasLetter.test(prefixedString)) {
  54.                     let randomChar = prefixedString.randomChar();
  55.                     prefixedString = prefixedString.replaceAt(prefixedString.indexOf(randomChar), randomChar);
  56.                 }
  57.                 if (!hasNumber.test(prefixedString)) {
  58.                     let randomChar = '0123456789'.randomChar();
  59.                     prefixedString = prefixedString.replaceAt(prefixedString.indexOf(prefixedString.randomChar()), randomChar);
  60.                 }
  61.             }
  62.             return prefixedString + suffix;
  63.         },
  64.  
  65.         validemail(lien) {
  66.             const parse = lien;
  67.             parse = parse.substr(parse.indexOf("id=") + 3, 32 + 3);
  68.             return new Promise((resolve, reject) => {
  69.                 request.get({
  70.                         url: 'email validation url' + parse
  71.                     }.useAgent(agent, config.proxy),
  72.                     (err, response) => err ? reject(err) : resolve(response)
  73.                 );
  74.             });
  75.         },
  76.         getemail() {
  77.             return new Promise((resolve, reject) => {
  78.                 request.get({
  79.                         url: HAAPI_SETTINGS.GETMAIL + params.email + ENDGETMAIL
  80.                     }.useAgent(agent, config.proxy),
  81.                     (error, response, body) => {
  82.                         if (error) return reject(error);
  83.                         return resolve({
  84.                             lien: JSON.parse(body).links,
  85.                             response
  86.                         });
  87.                     }
  88.                 );
  89.             });
  90.         },
  91.         validateGuest(guestId) {
  92.             const params = {
  93.                 login: this.randomString(),
  94.                 password: this.randomString(),
  95.                 email: this.randomString() + '@' + config.emailDomain,
  96.                 nickname: this.randomString(false),
  97.                 guestAccountId: guestId,
  98.                 lang: 'fr'
  99.             };
  100.             return new Promise((resolve, reject) => {
  101.                 request.get({
  102.                         url: HAAPI_SETTINGS.VALIDATE_GUEST_URI + '?' + qs.stringify(params)
  103.                     }.useAgent(agent, config.proxy),
  104.                     (err, response) => err ? reject(err) : resolve({
  105.                         response,
  106.                         params
  107.                     })
  108.                 );
  109.             });
  110.         },
  111.         createGuest() {
  112.             return new Promise((resolve, reject) => {
  113.  
  114.                 anticaptcha.setWebsiteURL("url with captcha");
  115.                 anticaptcha.setWebsiteKey("url key");
  116.                 //proxy access parameters
  117.                 anticaptcha.setProxyType("http");
  118.                 anticaptcha.setProxyAddress("54.39.209.38");
  119.                 anticaptcha.setProxyPort("3128");
  120.                 anticaptcha.setProxyLogin("");
  121.                 anticaptcha.setProxyPassword("");
  122.                 anticaptcha.setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116");
  123.  
  124.                 anticaptcha.setCookies("anticaptcha=cool; cookies=set");
  125.  
  126.                 // check balance first
  127.                 anticaptcha.getBalance(function(err, balance) {  
  128.                     if (err) {
  129.                         console.error(err);
  130.                         return;
  131.                     }else{console.log('\x1b[42m Balance supérieure à 10 $\x1b[0m`');}
  132.                
  133.  
  134.                     if (balance > 0) {
  135.                         anticaptcha.createTask(function(err, taskId) {
  136.                             if (err) {
  137.                                 console.error(err);
  138.                                 return;
  139.                             }else{console.log('\x1b[42mTask créée :\x1b[0m`');}
  140.  
  141.                             console.log(taskId);
  142.  
  143.                             anticaptcha.getTaskSolution(taskId, function(err, taskSolution) {
  144.                                 if (err) {
  145.                                     console.error(err);
  146.                                     return;
  147.                                 }else{console.log('\x1b[42mSOLUTION :\x1b[0m`');}
  148.  
  149.                                 console.log(taskSolution);
  150.                             });
  151.                         });
  152.                     }
  153.                 });
  154.                 request.get({
  155.                         url: HAAPI_SETTINGS.GUEST_CREATION_URI
  156.                     }.useAgent(agent, config.proxy),
  157.                     (err, response) => err ? reject(err) : resolve(response)
  158.                 );
  159.             });
  160.         },
  161.         create(proxySettings) {
  162.             if (proxySettings) {
  163.                 agent = new HttpsProxyAgent(proxySettings);
  164.                 console.log(agent.options.Url.hostname);
  165.             }
  166.             return new Promise((resolve, reject) => {
  167.                 process.on('uncaughtException', err => reject({
  168.                     key: 'EDATALOST',
  169.                     err
  170.                 }));
  171.  
  172.                 this.createGuest()
  173.                     .then(response => {
  174.                         if (response.headers['content-type'] == "application/json") {
  175.                             let body = JSON.parse(response.body);
  176.  
  177.                             if (response.statusCode == 200) {
  178.                                 return this.validateGuest(body.id);
  179.                                 this.getemail()
  180.                                     .then(response => {
  181.                                         if (response.headers['content-type'] == "application/json") {
  182.                                             let body = JSON.parse(response.body);
  183.  
  184.                                             if (response.statusCode == 200) {
  185.                                                 return this.validemail(body.links);
  186.                                             } else {
  187.                                                 reject(body);
  188.                                             }
  189.                                         } else {
  190.                                             reject(ERROR.PROXY_DENIED);
  191.                                         }
  192.                                     })
  193.                             } else {
  194.                                 reject(body);
  195.                             }
  196.                         } else {
  197.                             reject(ERROR.PROXY_DENIED);
  198.                         }
  199.                     })
  200.  
  201.                     .then(data => {
  202.                         var body = data.response.body.length ? JSON.parse(data.response.body) : {};
  203.  
  204.                         if (data.response.statusCode == 200) {
  205.                             if (!body.key) {
  206.                                 if (
  207.                                     config.filteredProxyOutputPath &&
  208.                                     config.filteredProxyOutputPath !== false
  209.                                 ) {
  210.                                     fs.appendFileSync(
  211.                                         config.filteredProxyOutputPath,
  212.                                         proxySettings + '\n'
  213.                                     );
  214.                                 }
  215.                                 fs.appendFileSync(
  216.                                     config.accountOutputPath,
  217.                                     `${data.params.login}:${data.params.password}\n`
  218.                                 );
  219.                                 resolve(data.params);
  220.                             } else {
  221.                                 reject(body);
  222.                             }
  223.                         } else {
  224.                             reject(ERROR.ACCOUNT_VALIDATION);
  225.                         }
  226.                     })
  227.                     .catch(err => reject(err));
  228.             });
  229.         }
  230.     };
  231. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement