Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const request = require('request');
- const HttpsProxyAgent = require('https-proxy-agent');
- const qs = require('querystring');
- const fs = require('fs');
- var anticaptcha = require('./anticaptcha')('apikey');
- const CARACTERS = 'abcdefghijklmnopqrstuvwxyz';
- const hasLetter = /[^a-z]+/i;
- const hasNumber = /\d+/;
- const HAAPI_SETTINGS = {
- GUEST_CREATION_URI: 'url',
- VALIDATE_GUEST_URI: 'url',
- CREATE_API_URI: 'url',
- GETMAIL: 'mail url',
- ENDGETMAIL: 'mail key end url'
- };
- const ERROR = {
- ACCOUNT_VALIDATION: {
- key: 'account_validation',
- text: 'La validation du compte a échoué.'
- },
- PROXY_DENIED: {
- key: 'proxy_error',
- text: "Le proxy n'a pas pu accéder à la requête."
- }
- };
- var agent = null;
- String.prototype.randomChar = function() {
- return this.charAt(Math.floor(Math.random() * this.length));
- };
- String.prototype.replaceAt = function(index, replacement) {
- return this.substr(0, index) + replacement + this.substr(index + replacement.length);
- };
- Object.prototype.useAgent = function(agent, config) {
- if (agent) {
- this.agent = agent;
- for (let property in config) {
- if (property != 'useAgent') {
- this[property] = config[property];
- }
- }
- }
- return this;
- };
- module.exports = config => {
- return {
- randomString(withNumber = true, prefixedString = "", suffix = "") {
- const caracterList = withNumber ? CARACTERS + '0123456789' : CARACTERS;
- while (prefixedString.length < 8) {
- prefixedString += caracterList.randomChar();
- }
- if (withNumber) {
- if (!hasLetter.test(prefixedString)) {
- let randomChar = prefixedString.randomChar();
- prefixedString = prefixedString.replaceAt(prefixedString.indexOf(randomChar), randomChar);
- }
- if (!hasNumber.test(prefixedString)) {
- let randomChar = '0123456789'.randomChar();
- prefixedString = prefixedString.replaceAt(prefixedString.indexOf(prefixedString.randomChar()), randomChar);
- }
- }
- return prefixedString + suffix;
- },
- validemail(lien) {
- const parse = lien;
- parse = parse.substr(parse.indexOf("id=") + 3, 32 + 3);
- return new Promise((resolve, reject) => {
- request.get({
- url: 'email validation url' + parse
- }.useAgent(agent, config.proxy),
- (err, response) => err ? reject(err) : resolve(response)
- );
- });
- },
- getemail() {
- return new Promise((resolve, reject) => {
- request.get({
- url: HAAPI_SETTINGS.GETMAIL + params.email + ENDGETMAIL
- }.useAgent(agent, config.proxy),
- (error, response, body) => {
- if (error) return reject(error);
- return resolve({
- lien: JSON.parse(body).links,
- response
- });
- }
- );
- });
- },
- validateGuest(guestId) {
- const params = {
- login: this.randomString(),
- password: this.randomString(),
- email: this.randomString() + '@' + config.emailDomain,
- nickname: this.randomString(false),
- guestAccountId: guestId,
- lang: 'fr'
- };
- return new Promise((resolve, reject) => {
- request.get({
- url: HAAPI_SETTINGS.VALIDATE_GUEST_URI + '?' + qs.stringify(params)
- }.useAgent(agent, config.proxy),
- (err, response) => err ? reject(err) : resolve({
- response,
- params
- })
- );
- });
- },
- createGuest() {
- return new Promise((resolve, reject) => {
- anticaptcha.setWebsiteURL("url with captcha");
- anticaptcha.setWebsiteKey("url key");
- //proxy access parameters
- anticaptcha.setProxyType("http");
- anticaptcha.setProxyAddress("54.39.209.38");
- anticaptcha.setProxyPort("3128");
- anticaptcha.setProxyLogin("");
- anticaptcha.setProxyPassword("");
- anticaptcha.setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116");
- anticaptcha.setCookies("anticaptcha=cool; cookies=set");
- // check balance first
- anticaptcha.getBalance(function(err, balance) {
- if (err) {
- console.error(err);
- return;
- }else{console.log('\x1b[42m Balance supérieure à 10 $\x1b[0m`');}
- if (balance > 0) {
- anticaptcha.createTask(function(err, taskId) {
- if (err) {
- console.error(err);
- return;
- }else{console.log('\x1b[42mTask créée :\x1b[0m`');}
- console.log(taskId);
- anticaptcha.getTaskSolution(taskId, function(err, taskSolution) {
- if (err) {
- console.error(err);
- return;
- }else{console.log('\x1b[42mSOLUTION :\x1b[0m`');}
- console.log(taskSolution);
- });
- });
- }
- });
- request.get({
- url: HAAPI_SETTINGS.GUEST_CREATION_URI
- }.useAgent(agent, config.proxy),
- (err, response) => err ? reject(err) : resolve(response)
- );
- });
- },
- create(proxySettings) {
- if (proxySettings) {
- agent = new HttpsProxyAgent(proxySettings);
- console.log(agent.options.Url.hostname);
- }
- return new Promise((resolve, reject) => {
- process.on('uncaughtException', err => reject({
- key: 'EDATALOST',
- err
- }));
- this.createGuest()
- .then(response => {
- if (response.headers['content-type'] == "application/json") {
- let body = JSON.parse(response.body);
- if (response.statusCode == 200) {
- return this.validateGuest(body.id);
- this.getemail()
- .then(response => {
- if (response.headers['content-type'] == "application/json") {
- let body = JSON.parse(response.body);
- if (response.statusCode == 200) {
- return this.validemail(body.links);
- } else {
- reject(body);
- }
- } else {
- reject(ERROR.PROXY_DENIED);
- }
- })
- } else {
- reject(body);
- }
- } else {
- reject(ERROR.PROXY_DENIED);
- }
- })
- .then(data => {
- var body = data.response.body.length ? JSON.parse(data.response.body) : {};
- if (data.response.statusCode == 200) {
- if (!body.key) {
- if (
- config.filteredProxyOutputPath &&
- config.filteredProxyOutputPath !== false
- ) {
- fs.appendFileSync(
- config.filteredProxyOutputPath,
- proxySettings + '\n'
- );
- }
- fs.appendFileSync(
- config.accountOutputPath,
- `${data.params.login}:${data.params.password}\n`
- );
- resolve(data.params);
- } else {
- reject(body);
- }
- } else {
- reject(ERROR.ACCOUNT_VALIDATION);
- }
- })
- .catch(err => reject(err));
- });
- }
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement