Compare commits
No commits in common. "01ea52d4d70b538bbd2df880490b82d016cd96a0" and "8733556ac2e0c90a955fb81cb57c7dc90b6a9674" have entirely different histories.
01ea52d4d7
...
8733556ac2
9
servers/home/no-ports/root.js
Normal file
9
servers/home/no-ports/root.js
Normal file
@ -0,0 +1,9 @@
|
||||
/** @param {NS} ns */
|
||||
export async function main(ns) {
|
||||
let server = ns.args[0]
|
||||
if (ns.getServerNumPortsRequired(server) <= 2) {
|
||||
ns.brutessh(server)
|
||||
ns.ftpcrack(server)
|
||||
ns.nuke(server)
|
||||
}
|
||||
}
|
19
servers/home/remove-files-from-servers.ts
Normal file
19
servers/home/remove-files-from-servers.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import {NS} from "NetscriptDefinitions";
|
||||
import {recursiveScan} from "./utils";
|
||||
|
||||
export async function main(ns: NS, servers: string[]) {
|
||||
let hosts = recursiveScan(ns);
|
||||
|
||||
let folderPrefix = "no-ports/";
|
||||
let files = ns.ls("home", folderPrefix).map((file) => {
|
||||
return file.substring(folderPrefix.length, file.length);
|
||||
});
|
||||
|
||||
ns.tprint("Files to be removed: ", JSON.stringify(files));
|
||||
|
||||
for(const host of hosts) {
|
||||
for (const file of files) {
|
||||
ns.rm(file, host)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,7 @@
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
|
||||
import {NS} from "NetscriptDefinitions";
|
||||
|
||||
/**
|
||||
* Recursively scans all servers connected to the current server, excluding home
|
||||
* @param ns global NS object
|
||||
* @returns A list of all servers connected to the current server
|
||||
*/
|
||||
export function recursiveScan(ns: NS) {
|
||||
// Starting case
|
||||
let servers = ns.scan("home");
|
||||
let servers = ns.scan(ns.getHostname());
|
||||
// Add all servers to the list
|
||||
let allServers: string[] = [];
|
||||
while (servers.length > 0) {
|
||||
@ -25,87 +17,7 @@ export function recursiveScan(ns: NS) {
|
||||
}
|
||||
}
|
||||
// Remove the current server
|
||||
allServers.splice(allServers.indexOf("home"), 1);
|
||||
allServers.splice(allServers.indexOf(ns.getHostname()), 1);
|
||||
// Print all servers
|
||||
return allServers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes files passed in from all servers
|
||||
* @param ns Global NS object
|
||||
* @param files The files to remove
|
||||
* @returns void
|
||||
* @example Removes all files from the folder "no-ports" from all servers.
|
||||
* removeFilesOnAllServers(ns, ns.ls("home", "no-ports"));
|
||||
* @note ns.ls() returns the full path of every file, so if the file is not in the same place in every server,
|
||||
* you will need to modify each file path to match the server you are removing it from.
|
||||
*/
|
||||
export function removeFilesOnAllServers(ns: NS, files: string[]) {
|
||||
let hosts = recursiveScan(ns);
|
||||
for(const host of hosts) {
|
||||
for (const file of files) {
|
||||
ns.rm(file, host)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to gain root access to a server
|
||||
* @param ns Global NS object
|
||||
* @param server The server to gain root access to
|
||||
* @returns The number of programs used to gain root access
|
||||
*/
|
||||
export function rootServer(ns: NS, server: string) {
|
||||
let counter = 0;
|
||||
if (ns.fileExists("BruteSSH.exe", "home")) {
|
||||
ns.brutessh(server);
|
||||
counter++;
|
||||
}
|
||||
if (ns.fileExists("FTPCrack.exe", "home")) {
|
||||
ns.ftpcrack(server);
|
||||
counter++;
|
||||
}
|
||||
if (ns.fileExists("SMTPCrack.exe", "home")) {
|
||||
ns.relaysmtp(server);
|
||||
counter++;
|
||||
}
|
||||
if (ns.fileExists("HTTPWorm.exe", "home")) {
|
||||
ns.httpworm(server);
|
||||
counter++;
|
||||
}
|
||||
if (ns.fileExists("SQLInject.exe", "home")) {
|
||||
ns.sqlinject(server);
|
||||
counter++;
|
||||
}
|
||||
ns.nuke(server)
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a function on a server if the player is capable of doing so, otherwise returns false
|
||||
* @param ns Global NS object
|
||||
* @param server The server to perform the function on
|
||||
* @param func The function to perform
|
||||
* @param args The arguments to pass to the function
|
||||
* @returns The result of the function if it is performed or true if the function does not return anything, otherwise false
|
||||
*/
|
||||
export function performFunctionIfCapable(ns: NS, server: string, func: CallableFunction, args: any[]) {
|
||||
if (ns.getHackingLevel() < ns.getServerRequiredHackingLevel(server)) {
|
||||
return false;
|
||||
}
|
||||
if (ns.getServerNumPortsRequired(server) < ns.getServer(server).openPortCount) {
|
||||
if (rootServer(ns, server) < ns.getServerNumPortsRequired(server)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!ns.hasRootAccess(server)) {
|
||||
return false;
|
||||
|
||||
}
|
||||
let result = func(...args);
|
||||
if (result === undefined) {
|
||||
return true;
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user