diff --git a/.env.sample b/.env.sample index c03f547..92a2a03 100644 --- a/.env.sample +++ b/.env.sample @@ -3,4 +3,5 @@ MAIL_PASSWORD= MAIL_HOST= MAIL_PORT=993 MS_ACCOUNT_COUNT=3 -AWS_ACCOUNT_COUNT=1 \ No newline at end of file +AWS_ACCOUNT_COUNT=1 +AWS_PHONE_NUM=0666666666 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0d42866..7a812c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/ .env -sorted/ -accounts.json \ No newline at end of file +output/ +accounts.json +aws.json \ No newline at end of file diff --git a/main.js b/main.js index cf1e613..a376ac0 100644 --- a/main.js +++ b/main.js @@ -3,6 +3,8 @@ require('dotenv').config(); const { createDriver } = require('./modules/driverManager'); const { createAccount } = require('./modules/microsoftHandler'); const { createAWSAccount } = require('./modules/awsHandler'); +const { sortAccounts } = require('./modules/accountManager'); + const args = process.argv.slice(2); async function microsoft() { @@ -20,6 +22,7 @@ async function microsoft() { } await Promise.all(accountPromises); console.log('All accounts done!'); + return process.exit(0); } async function aws() { @@ -28,10 +31,16 @@ async function aws() { for (let i = 0; i < numAccounts; i++) { const promise = await createAWSAccount(createDriver()); accountPromises.push(promise); - console.log(`Account ${i + 1} done!`); + if (promise) { + console.log('Account failed'); + } + else { + console.log(`Account ${i + 1} done!`); + } } await Promise.all(accountPromises); console.log('All accounts done!'); + return process.exit(0); } for (let i = 0; i < args.length; i++) { @@ -42,5 +51,8 @@ for (let i = 0; i < args.length; i++) { else if (args[i] === '--ms') { microsoft(); } + else if (args[i] === '--sort') { + sortAccounts(); + } } } diff --git a/modules/accountManager.js b/modules/accountManager.js index 95ba8a8..c33cb6b 100644 --- a/modules/accountManager.js +++ b/modules/accountManager.js @@ -1,21 +1,31 @@ const fs = require('fs'); const path = require('path'); +const { faker } = require('@faker-js/faker'); -function batchAccounts(accounts, batchSize) { - const sortedDir = '../accounts/sorted'; - if (!fs.existsSync(path.join(__dirname, sortedDir))) { - fs.mkdirSync(path.join(__dirname, sortedDir)); - } +async function sortAccounts() { + const sortedDir = path.join(__dirname, '../output'); + const accountsFile = path.join(__dirname, '../accounts/accounts.json'); + const accounts = require(accountsFile); - for (let i = 0; i < accounts.length; i += batchSize) { - const batch = accounts.slice(i, i + batchSize); - const batchNumber = Math.ceil((i + 1) / batchSize); - const batchFilename = `${sortedDir}/batch${batchNumber}.json`; - fs.writeFileSync(path.join(__dirname, batchFilename), JSON.stringify(batch, null, 2)); + if (accounts.length < 6) return console.log('Not enough accounts!'); + + if (!fs.existsSync(sortedDir)) fs.mkdirSync(sortedDir, { recursive: true }); + + while (accounts.length >= 6) { + let name = faker.name.firstName(); + let outputFilePath = path.join(sortedDir, `${name}.json`); + + while (fs.existsSync(outputFilePath)) { + name = faker.name.firstName(); + outputFilePath = path.join(sortedDir, `${name}.json`); + } + + const batch = accounts.splice(0, 6); + fs.writeFileSync(outputFilePath, JSON.stringify(batch, null, 2)); + fs.writeFileSync(accountsFile, JSON.stringify(accounts, null, 2)); } + console.log('Accounts Sorted!'); + return process.exit(0); } -const accounts = require(path.join(__dirname, '../accounts/accounts.json')); -batchAccounts(accounts, 6); - -module.exports = { batchAccounts }; \ No newline at end of file +module.exports = { sortAccounts }; \ No newline at end of file diff --git a/modules/awsHandler.js b/modules/awsHandler.js index c2f2fc1..75a567e 100644 --- a/modules/awsHandler.js +++ b/modules/awsHandler.js @@ -1,5 +1,5 @@ -// const fs = require('fs'); -// const path = require('path'); +const fs = require('fs'); +const path = require('path'); const { By, Key, until } = require('selenium-webdriver'); const { createIdentity } = require('./identityHandler'); @@ -46,8 +46,7 @@ async function createAWSAccount(driver) { await driver.findElement(By.id('awsui-select-1-textbox')).click(); await driver.findElement(By.id('awsui-select-1-dropdown-option-74')).click(); - // add a dynamic way to set the phone number - await driver.findElement(By.id('awsui-input-7')).sendKeys('0666666666'); + await driver.findElement(By.id('awsui-input-7')).sendKeys(process.env.AWS_PHONE_NUM); await driver.findElement(By.id('awsui-select-2')).click(); await driver.findElement(By.id('awsui-select-2-dropdown-option-74')).click(); @@ -67,12 +66,113 @@ async function createAWSAccount(driver) { await driver.findElement(By.id('awsui-select-4-dropdown-option-5')).click(); // wait until user finished card verification + await driver.sleep(urlTime + 4000); + await driver.wait(async () => { + const pageSource = await driver.getPageSource(); + return pageSource.includes('Revolut App'); + }, 300000); + await driver.sleep(urlTime + 4000); + await driver.wait(async () => { + const pageSource = await driver.getPageSource(); + return pageSource.includes('you must verify your phone number'); + }, 300000); + await driver.findElement(By.id('awsui-select-3')).click(); + await driver.findElement(By.id('awsui-select-3-dropdown-option-74')).click(); + await driver.findElement(By.id('awsui-input-3')).sendKeys(process.env.AWS_PHONE_NUM); + + await driver.sleep(urlTime); + await driver.wait(async () => { + const pageSource = await driver.getPageSource(); + return pageSource.includes('Verify code'); + }, 300000); + + await driver.sleep(urlTime); + await driver.wait(async () => { + const pageSource = await driver.getPageSource(); + return pageSource.includes('Select a support plan'); + }, 300000); + + await driver.findElement(By.className('awsui-button')).click(); + await driver.sleep(urlTime); + await driver.wait(async () => { + const pageSource = await driver.getPageSource(); + return pageSource.includes('We are activating your account'); + }, 300000); + await driver.findElement(By.className('awsui-button')).click(); + await driver.sleep(urlTime); + + const account = { + 'name': identity.first_name + ' ' + identity.last_name, + 'birthdate': identity.birth_date, + 'email': identity.email, + 'password': identity.password, + 'address': identity.address, + 'phone': process.env.AWS_PHONE_NUM, + }; + + let accounts = []; + if (fs.existsSync(path.join(__dirname, '../accounts/aws.json'))) { + const content = fs.readFileSync(path.join(__dirname, '../accounts/aws.json'), 'utf8'); + accounts = JSON.parse(content); + } + + accounts.push(account); + fs.writeFileSync(path.join(__dirname, '../accounts/aws.json'), JSON.stringify(accounts)); + + await driver.get('https://console.aws.amazon.com/console/home?nc2=h_ct&src=header-signin'); + await driver.sleep(urlTime); + await driver.wait(async () => { + const pageSource = await driver.getPageSource(); + return pageSource.includes('Root user'); + }, 300000); + + await driver.findElement(By.id('resolving_input')).sendKeys(identity.email); + await driver.findElement(By.id('next_button')).click(); + await driver.findElement(By.id('password')).sendKeys(identity.password); + await driver.findElement(By.id('signin_button')).click(); + await driver.sleep(urlTime); + await driver.wait(async () => { + const pageSource = await driver.getPageSource(); + return pageSource.includes('Console Home'); + }, 300000); + + await driver.get('https://eu-west-3.console.aws.amazon.com/console/home?region=eu-west-3'); + await driver.sleep(urlTime); + await driver.wait(async () => { + const pageSource = await driver.getPageSource(); + return pageSource.includes('Console Home'); + }, 300000); + + await driver.get('https://eu-west-3.console.aws.amazon.com/ec2/home?#LaunchInstanceWizard:'); + await driver.sleep(urlTime); + await driver.wait(async () => { + const pageSource = await driver.getPageSource(); + return pageSource.includes('Launch an instance'); + }, 300000); + await driver.findElement(By.css('div[data-testid="getting-started-tile-5"]')).click(); + await driver.findElement(By.css('a[role="button"][tabindex="0"][data-analytics="create-key-pair"][data-analytics-type="eventDetail"]')).click(); + await driver.findElement(By.css('input[placeholder="Enter key pair name"]')).sendKeys(identity.first_name); + await driver.findElement(By.css('button[data-id="key-pair-modal-create"]')).click(); + + const httpsspan = await driver.findElement(By.css('span[data-id="simple-view-https-checkbox"]')); + const httpscheckbox = await httpsspan.findElement(By.css('input[type="checkbox"]')); + const HTTPSisSelected = await httpscheckbox.isSelected(); + if (!HTTPSisSelected) { + await httpscheckbox.click(); + } + + const httpspan = await driver.findElement(By.css('span[data-id="simple-view-http-checkbox"]')); + const httpcheckbox = await httpspan.findElement(By.css('input[type="checkbox"]')); + const HTTPisSelected = await httpcheckbox.isSelected(); + if (!HTTPisSelected) { + await httpcheckbox.click(); + } } finally { // await driver.quit(); } - return; + return 0; } module.exports = { createAWSAccount }; \ No newline at end of file diff --git a/modules/codeHandler.js b/modules/codeHandler.js index 41d6620..21dec66 100644 --- a/modules/codeHandler.js +++ b/modules/codeHandler.js @@ -33,6 +33,9 @@ async function getCodeFromEmail() { imap.addFlags(attributes.uid, '\\Seen', (err) => { if (err) console.log('Error marking email as seen:', err); }); + imap.move(attributes.uid, '\\Trash', (moveErr) => { + if (moveErr) console.log('Error moving email to trash:', moveErr); + }); mailListener.stop(); resolve(match[1]); }