-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCLI.ts
More file actions
160 lines (141 loc) · 4.99 KB
/
CLI.ts
File metadata and controls
160 lines (141 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env node
import { existsSync, writeFileSync, fstat } from "fs";
import { createInterface } from "readline";
import { green, bold, red, System } from "./System";
const rl = createInterface({ input: process.stdin, output: process.stdout });
const _question = async (text: string): Promise<string> => {
return await new Promise((resolve, reject) => {
rl.question(green("> " + text + " "), answer => resolve(answer));
});
};
const _initConfigFile = async (fileURI: string) => {
console.log("A configuration file will be created.");
console.log(
"\nAll emails should be redirected to a single account. We recommend using a garbage account. Please fill in this account's credentials:"
);
const user = await _question("username: (ex: account@outlook.com)");
const password = await _question("password:");
const host = await _question("host: (ex: outlook.office365.com)");
const port = await _question("port: [993]");
let usingTLS = await _question("using TLS (y/n) [y]");
let tls = false;
if (usingTLS === "" || usingTLS.toLowerCase() === "y") {
tls = true;
}
console.log("\nBBF Account Creator uses 2Captcha to solve the captchas. Please provide your API key.");
const TWO_CAPTCHA_API_KEY = await _question("API Key:");
console.log("\nEmails can be auto-generated with the username if you own a domain name. Fill in your domain name or leave blank.");
const DOMAIN = await _question("Domain name: (ex: google.com):");
writeFileSync("config.json", JSON.stringify({ EMAIL_CREDENTIALS: { user, password, host, port, tls }, TWO_CAPTCHA_API_KEY, DOMAIN }, null, "\t"));
console.log("Config file was successfully created. You can now create an account by using the following command:\n");
console.log(
`${green("bbf")} create --use=${bold("username")} --password=${bold("password")} --email=${bold("abc@xyz.fr")} --birthday=${bold(
"1/1/1992"
)} `
);
await new Promise(resolve => setTimeout(resolve, 2000));
rl.close();
};
const init = async (configFile: string) => {
if (existsSync("config.json")) {
const create = await _question("config.json file already exists. Overwrite? (y/n) [n]");
if (create === "" || create.toLowerCase() === "n") {
console.log("Aborted.");
process.exit();
} else {
_initConfigFile(configFile);
}
} else {
const create = await _question("config.json file not found. Create it? (y/n) [y]");
if (!(create === "" || create.toLowerCase() === "y")) {
console.log("Aborted.");
process.exit();
} else {
_initConfigFile(configFile);
}
}
};
const createAccount = async ({
email,
username,
password,
date
}: {
email?: string;
username: string;
password: string;
date: { day: number; month: number; year: number };
}) => {
if (existsSync("config.json")) {
const system = new System();
await system.launchBrowser();
await system.createAccount({
email: email ? email : "",
username,
password,
date
});
process.exit()
} else {
console.log(
"No config file found. Put your config file in the root directory or create one using one of the following commands:\n\nbbf\nbbf init"
);
process.exit();
}
};
const parseArguments = () => {
if (process.argv.length === 2 || process.argv[2] === "init") {
init("config.json");
} else {
const requiredArguments = ["username", "password", "date"];
const args: { [index in string]: string } = {};
const givenArguments = process.argv
.map(argument => {
if (argument.substring(0, 2) === "--") {
args[argument.substr(2).split("=")[0]] = argument.substr(2).split("=")[1];
return argument.substr(2).split("=")[0];
} else {
return null;
}
})
.filter(arg => arg !== null);
let allRequiredArgumentsPresent = true;
for (const requiredArgument of requiredArguments) {
if (!givenArguments.includes(requiredArgument)) {
allRequiredArgumentsPresent = false;
console.log(red(`Please specify the ${requiredArgument} argument with --${requiredArgument}`));
process.exit();
}
}
let date = {day: 1, month: 1, year: 1996}
if (args["date"].split("/").length !== 3) {
console.log(red("Date needs to be of format dD/mM/YYYY"));
process.exit()
}else{
date.day = parseInt(args["date"].split("/")[0])
date.month = parseInt(args["date"].split("/")[1])
date.year = parseInt(args["date"].split("/")[2])
if(isNaN(date.day) || isNaN(date.month) || isNaN(date.year)){
console.log(red("Date needs to be of format dD/mM/YYYY with numbers. Setting date to 10/10/1980."));
date.year = 1980
date.month = 10
date.day = 10
}
if(date.year < 1920 || date.year > 2000){
console.log(red("Invalid year. Setting year to 1980."))
date.year = 1980
}
if(date.month > 12 || date.month < 1){
console.log(red("Invalid month. Setting month to 10."))
date.month = 10
}
if(date.day > 31 || date.day < 1){
console.log(red("Invalid day. Setting day to 10."))
date.day = 10
}
}
rl.close()
createAccount({email: args["email"], username: args["username"], password: args["password"], date})
}
};
parseArguments();