-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.js
executable file
·258 lines (239 loc) · 6.74 KB
/
upload.js
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/usr/bin/env node
"use strict";
console.debug = console.log;
require("colors");
const fs = require("fs");
const path = require("path");
const ini = require("ini");
const minimist = require("minimist");
const log = require("loglevel");
const glob = require("glob");
require("./lib/wangblows");
const {Room} = require("./lib/room");
const {sort, naturalCaseSort} = require("./lib/sorting");
const {shuffle, filesize, Rate} = require("./lib/util");
const BLACKED = /^thumbs.*\.db$|^\.ds_store$/i;
const normalize = (function() {
if (process.platform === "win32") {
return file => file.replace(/\\/g, "/");
}
return file => file;
})();
class UsageError extends Error {}
function *collect_files(inputFiles, recursive) {
for (let file of inputFiles) {
file = normalize(file);
try {
const {base} = path.parse(file);
if (BLACKED.test(base)) {
log.warn("Ignored", `${file.yellow}:`, "You must be a roboCOP".bold);
continue;
}
const stat = fs.statSync(file);
if (recursive && stat.isDirectory()) {
yield *collect_files(
fs.readdirSync(file).map(e => path.resolve(file, e)),
recursive);
continue;
}
if (!stat.isFile()) {
log.warn("Ignored", `${file.yellow}:`, "Not a file".bold);
continue;
}
yield file;
}
catch (ex) {
try {
const found = glob.sync(file);
if (!found.length) {
throw new UsageError("No files matched");
}
yield *collect_files(found, recursive);
}
catch (ex) {
log.warn("Ignored", `${file.yellow}:`, ex.message || ex);
}
}
}
}
function printUsage() {
const {base: exe} = path.parse(process.argv[1]);
log.info(exe.bold.green,
"--room".yellow, "BEEPi".cyan,
"--user".yellow, "volaupload".cyan,
"[FILES]".bold.yellow);
const options = {
"-r, --room": "Room(s) to which to upload files",
"-t, --attempts": "Number of upload attempts per file",
"-a, --roompasswd": "Room password",
"-u, --user": "User name to use",
"-p, --passwd": "Login to vola for some sweet stats",
"-s, --sort": "Method by which file to order before uploading " +
"[filename*, path, size, none]",
"-R, --retarddir": "Specify directories and upload all files within",
"-c, --check": "Check files were uploaded correctly",
"--delete-after": "Remove file after uploading",
"--version": "Print version and exit",
"--prefix": "Add a prefix to all uploads",
"--spam": "Spam using these greek names",
"-h, --help": "Take a wild guess",
};
const args = Object.keys(options);
const sk = k => k.replace(/-/g, "");
sort(args, sk, naturalCaseSort);
const max = args.reduce((p, c) => Math.max(c.length, p), 0);
log.info("");
for (const a of args) {
log.info(" ", a.yellow, " ".repeat(max - a.length + 2), options[a].bold);
}
log.info("");
log.info("Additionally, ~/.vola.conf will be considered".magenta.bold);
}
function sort_filename(file) {
const {base, dir} = path.parse(file);
return [base, dir];
}
function sort_path(file) {
const {base, dir} = path.parse(file);
return [dir, base];
}
function sort_size(file) {
return [fs.statSync(file).size, sort_filename(file)];
}
const SORTS = Object.freeze(new Map([
["filename", sort_filename],
["path", sort_path],
["size", sort_size],
]));
async function main(args) {
const home = process.env[
(process.platform === "win32") ? "USERPROFILE" : "HOME"];
const iniPath = path.resolve(home, ".vola.conf");
let config = {};
try {
config = ini.parse(fs.readFileSync(iniPath, {encoding: "utf-8"}));
}
catch (ex) {
log.warn("Make a", ".vola.conf".yellow, "already, pls");
}
const {vola = {}, aliases = {}, roompasswords = {}} = config;
args = minimist(args, {
boolean: ["help", "h", "v", "delete-after", "retarddir", "check"],
alias: {
a: "roompasswd",
c: "check",
h: "help",
p: "passwd",
r: "room",
R: "retarddir",
s: "sort",
t: "attempts",
u: "user",
},
default: {
sort: "filename",
attempts: 5,
}
});
if (args.help) {
printUsage();
return;
}
if (args.version) {
log.info(require("./package.json").version);
process.exit(0);
}
let {_: files} = args;
delete args._;
let {room: roomids} = args;
if ("user" in args && args.user) {
delete vola.passwd;
}
if (!roomids) {
throw new UsageError("No room specified");
}
if (!Array.isArray(roomids)) {
roomids = [roomids];
}
delete args.room;
config = Object.assign({}, vola, args);
files = Array.from(collect_files(files, config.retarddir));
if (!files.length) {
throw new UsageError("No files specified");
}
if (config.sort === "rnd") {
files = shuffle(files);
}
else if (config.sort !== "none") {
const sort_fn = SORTS.get(config.sort);
if (!sort_fn) {
throw new UsageError("Invalid --sort");
}
files = sort(files.map(f => path.resolve(f)), sort_fn, naturalCaseSort);
}
if (!isFinite(config.attempts) || config.attempts < 0) {
throw new UsageError("Invalid number of attempts");
}
let lastRoom = null;
const rate = new Rate();
const t_len = files.length === 1 ? "one" : files.length.toString();
log.info(
"Deploying".bold,
t_len.bold.green,
`botnet payload${t_len === "one" ? "" : "s"}`.bold.yellow,
"to", roomids.length.toString().bold.magenta, "rooms");
let canceled = false;
const cancel = () => {
if (canceled) {
return;
}
log.warn("\r\nCancel requested".bold.yellow);
canceled = true;
lastRoom.close();
};
process.on("SIGINT", cancel);
process.on("SIGTERM", cancel);
process.on("SIGQUIT", cancel);
for (;;) {
let room_id = roomids.shift();
if (!room_id || canceled) {
break;
}
if (room_id.toLowerCase() in aliases) {
room_id = aliases[room_id] || room_id;
}
const this_config = Object.assign({}, config);
if (roomids.length) {
this_config["delete-after"] = false;
}
const room = new Room(room_id, this_config, lastRoom);
if (config.roompasswd) {
room.password = config.roompasswd;
}
else if (room.id in roompasswords) {
room.password = roompasswords[room.id];
}
if (!lastRoom) {
await room.login();
}
lastRoom = room;
await room.upload(files, rate);
}
log.info(
"All done in",
`${rate.elapsed.toFixed(1)}s`.bold,
`(${`${filesize(rate.rate)}/s`.cyan.blue})`);
}
if (require.main === module) {
log.setDefaultLevel(log.levels.INFO);
main(process.argv.slice(2)).catch(ex => {
log.error("Error".red, ex.message || ex);
if (ex instanceof UsageError) {
log.info("");
printUsage();
}
process.exit(1);
}).then(rv => {
process.exit(rv || 0);
});
}