Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
cb117273a7 | |||
3bda688b1e | |||
446b1aa9db |
28
index.html
28
index.html
@ -6,31 +6,11 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import {ArgParser} from './dist/index.mjs';
|
import {PES, PathEvent} from './dist/index.mjs';
|
||||||
|
const perm = PES`storage/test/john-flag.png:r`;
|
||||||
|
const perms = [ 'logs/Momentum:c', 'storage/test:r', 'data/Repos:r', 'email:c' ];
|
||||||
|
|
||||||
const hostname = 'test';
|
console.log(PathEvent.filter(perms, perm));
|
||||||
const argParser = new ArgParser('botnet-manager.js', 'Connect & manage a network of servers to launch distributed attacks.', [
|
|
||||||
new ArgParser('copy', 'Copy file & dependencies to botnet', [
|
|
||||||
{name: 'file', desc: 'File to copy', default: false},
|
|
||||||
{name: 'control', desc: 'Copy to master server', flags: ['-c', '--control'], default: false},
|
|
||||||
{name: 'noDeps', desc: 'Skip copying dependencies', flags: ['-d', '--no-deps'], default: false},
|
|
||||||
{name: 'slave', desc: 'Copy to slave servers', flags: ['-s', '--slave'], default: false},
|
|
||||||
]),
|
|
||||||
new ArgParser('join', 'Connect server as a botnet slave', [
|
|
||||||
{name: 'device', desc: 'Device to connect, defaults to the current machine', optional: true, default: hostname}
|
|
||||||
]),
|
|
||||||
new ArgParser('kill', 'Kill any scripts running on the botnet'),
|
|
||||||
new ArgParser('leave', 'Disconnect worker node from swarm', [
|
|
||||||
{name: 'device', desc: 'Device to disconnect, defaults to the current machine', optional: true, default: hostname}
|
|
||||||
]),
|
|
||||||
new ArgParser('run', 'Copy & run script on the botnet', [
|
|
||||||
{name: 'script', desc: 'Script to copy & execute', type: 'string'},
|
|
||||||
{name: 'args', desc: 'Arguments for script. Forward the current target with: {{TARGET}}', optional: true, extras: true},
|
|
||||||
]),
|
|
||||||
new ArgParser('start', 'Start this server as the botnet manager'),
|
|
||||||
{name: 'silent', desc: 'Suppress program output', flags: ['-s', '--silent'], default: false},
|
|
||||||
]);
|
|
||||||
console.log(argParser.help({}));
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/utils",
|
"name": "@ztimson/utils",
|
||||||
"version": "0.23.4",
|
"version": "0.23.7",
|
||||||
"description": "Utility library",
|
"description": "Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -14,8 +14,6 @@ export type Arg<T = any> = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ArgParser {
|
export class ArgParser {
|
||||||
static readonly helpArg: Arg = {name: 'help', desc: 'Display command\'s help message', flags: ['-h', '--help'], default: false};
|
|
||||||
|
|
||||||
commands: ArgParser[] = [];
|
commands: ArgParser[] = [];
|
||||||
args: Arg[] = [];
|
args: Arg[] = [];
|
||||||
flags: Arg[] = [];
|
flags: Arg[] = [];
|
||||||
@ -37,7 +35,8 @@ export class ArgParser {
|
|||||||
// Arguments
|
// Arguments
|
||||||
this.commands = argList.filter(arg => arg instanceof ArgParser);
|
this.commands = argList.filter(arg => arg instanceof ArgParser);
|
||||||
this.args = <Arg[]>argList.filter(arg => !(arg instanceof ArgParser) && !arg.flags?.length);
|
this.args = <Arg[]>argList.filter(arg => !(arg instanceof ArgParser) && !arg.flags?.length);
|
||||||
this.flags = <Arg[]>[...argList.filter(arg => !(arg instanceof ArgParser) && arg.flags && arg.flags.length), ...this.flags];
|
this.flags = <Arg[]>[...argList.filter(arg => !(arg instanceof ArgParser) && arg.flags && arg.flags.length),
|
||||||
|
{name: 'help', desc: 'Display command\'s help message', flags: ['-h', '--help'], default: false}];
|
||||||
this.defaults = argList.reduce((acc, arg: any) => ({...acc, [arg.name]: arg['extras'] ? [] : (arg.default ?? null)}), {});
|
this.defaults = argList.reduce((acc, arg: any) => ({...acc, [arg.name]: arg['extras'] ? [] : (arg.default ?? null)}), {});
|
||||||
|
|
||||||
// Examples
|
// Examples
|
||||||
@ -125,18 +124,18 @@ export class ArgParser {
|
|||||||
// Description
|
// Description
|
||||||
let msg = `\n\n${opts.message || this.desc}`;
|
let msg = `\n\n${opts.message || this.desc}`;
|
||||||
// Examples
|
// Examples
|
||||||
msg += '\n\nUsage:\t' + this.examples.map(ex => `run ${this.name} ${ex}`).join('\n\t\t');
|
msg += '\n\nUsage:\t' + this.examples.map(ex => `${this.name} ${ex}`).join('\n\t');
|
||||||
// Arguments
|
// Arguments
|
||||||
if(this.args.length) msg += '\n\n\t\t' + this.args.map(arg =>
|
if(this.args.length) msg += '\n\n\t' + this.args.map(arg =>
|
||||||
`${arg.name.toUpperCase()}${spacer(arg.name)}${arg.desc}`).join('\n\t\t');
|
`${arg.name.toUpperCase()}${spacer(arg.name)}${arg.desc}`).join('\n\t');
|
||||||
// Flags
|
// Flags
|
||||||
msg += '\n\nOptions:\n\t\t' + this.flags.map(flag => {
|
msg += '\n\nOptions:\n\t' + this.flags.map(flag => {
|
||||||
const flags = flag.flags?.join(', ') || '';
|
const flags = flag.flags?.join(', ') || '';
|
||||||
return `${flags}${spacer(flags)}${flag.desc}`;
|
return `${flags}${spacer(flags)}${flag.desc}`;
|
||||||
}).join('\n\t\t');
|
}).join('\n\t');
|
||||||
// Commands
|
// Commands
|
||||||
if(this.commands.length) msg += '\n\nCommands:\n\t\t' + this.commands.map(command =>
|
if(this.commands.length) msg += '\n\nCommands:\n\t' + this.commands.map(command =>
|
||||||
`${command.name}${spacer(command.name)}${command.desc}`).join('\n\t\t');
|
`${command.name}${spacer(command.name)}${command.desc}`).join('\n\t');
|
||||||
return `${msg}\n\n`;
|
return `${msg}\n\n`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
src/color.ts
Normal file
12
src/color.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* Determine if either black or white provides more contrast to the provided color
|
||||||
|
* @param {string} background Color to compare against
|
||||||
|
* @return {"white" | "black"} Color with the most contrast
|
||||||
|
*/
|
||||||
|
export function blackOrWhite(background: string): 'white' | 'black' {
|
||||||
|
const exploded = background.match(background.length >= 6 ? /\w\w/g : /\w/g);
|
||||||
|
if(!exploded) return 'black';
|
||||||
|
const [r, g, b] = exploded.map(hex => parseInt(hex, 16));
|
||||||
|
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
||||||
|
return luminance > 0.5 ? 'black' : 'white';
|
||||||
|
}
|
@ -2,6 +2,7 @@ export * from './arg-parser';
|
|||||||
export * from './array';
|
export * from './array';
|
||||||
export * from './aset';
|
export * from './aset';
|
||||||
export * from './cache';
|
export * from './cache';
|
||||||
|
export * from './color';
|
||||||
export * from './csv';
|
export * from './csv';
|
||||||
export * from './files';
|
export * from './files';
|
||||||
export * from './emitter';
|
export * from './emitter';
|
||||||
|
@ -142,7 +142,7 @@ export class PathEvent {
|
|||||||
const parsedFind = makeArray(filter).map(pe => new PathEvent(pe));
|
const parsedFind = makeArray(filter).map(pe => new PathEvent(pe));
|
||||||
return parsedTarget.filter(t => {
|
return parsedTarget.filter(t => {
|
||||||
if(!t.fullPath && t.all) return true;
|
if(!t.fullPath && t.all) return true;
|
||||||
return !!parsedFind.find(f => t.fullPath.startsWith(f.fullPath)
|
return !!parsedFind.find(f => f.fullPath.startsWith(t.fullPath)
|
||||||
&& (f.all || t.all || t.methods.intersection(f.methods).length));
|
&& (f.all || t.all || t.methods.intersection(f.methods).length));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user