2017-08-30 19:44:29 +02:00
|
|
|
import {substituteAliases, printAliases,
|
|
|
|
parseAliasDeclaration,
|
|
|
|
removeAlias, GlobalAliases,
|
|
|
|
Aliases} from "./Alias.js";
|
|
|
|
import {CONSTANTS} from "./Constants.js";
|
|
|
|
import {Programs} from "./CreateProgram.js";
|
|
|
|
import {executeDarkwebTerminalCommand,
|
|
|
|
checkIfConnectedToDarkweb} from "./DarkWeb.js";
|
|
|
|
import {Engine} from "./engine.js";
|
|
|
|
import {TerminalHelpText, HelpTexts} from "./HelpText.js";
|
|
|
|
import {iTutorialNextStep, iTutorialSteps,
|
|
|
|
iTutorialIsRunning,
|
|
|
|
currITutorialStep} from "./InteractiveTutorial.js";
|
|
|
|
import {showLiterature} from "./Literature.js";
|
|
|
|
import {showMessage, Message} from "./Message.js";
|
2017-09-19 20:38:03 +02:00
|
|
|
import {scriptCalculateHackingTime,
|
|
|
|
scriptCalculateGrowTime,
|
|
|
|
scriptCalculateWeakenTime} from "./NetscriptEvaluator.js";
|
2017-08-30 19:44:29 +02:00
|
|
|
import {killWorkerScript, addWorkerScript} from "./NetscriptWorker.js";
|
|
|
|
import {Player} from "./Player.js";
|
|
|
|
import {hackWorldDaemon} from "./RedPill.js";
|
|
|
|
import {findRunningScript, RunningScript,
|
2017-08-31 19:19:28 +02:00
|
|
|
AllServersMap, Script} from "./Script.js";
|
2017-08-30 19:44:29 +02:00
|
|
|
import {AllServers, GetServerByHostname,
|
|
|
|
getServer, Server} from "./Server.js";
|
|
|
|
import {SpecialServerIps,
|
|
|
|
SpecialServerNames} from "./SpecialServerIps.js";
|
2017-10-12 04:00:22 +02:00
|
|
|
import {TextFile, getTextFile,
|
|
|
|
createTextFile} from "./TextFile.js";
|
2017-08-30 19:44:29 +02:00
|
|
|
|
|
|
|
import {containsAllStrings, longestCommonStart,
|
2017-09-12 01:14:51 +02:00
|
|
|
formatNumber, isString} from "../utils/StringHelperFunctions.js";
|
2017-08-30 19:44:29 +02:00
|
|
|
import {addOffset, printArray} from "../utils/HelperFunctions.js";
|
|
|
|
import {logBoxCreate} from "../utils/LogBox.js";
|
2016-12-21 19:36:42 +01:00
|
|
|
|
|
|
|
/* Write text to terminal */
|
2017-09-15 16:06:59 +02:00
|
|
|
//If replace is true then spaces are replaced with " "
|
2017-08-30 19:44:29 +02:00
|
|
|
function post(input, replace=true) {
|
2017-06-23 16:23:35 +02:00
|
|
|
if (replace) {
|
2017-07-22 00:54:55 +02:00
|
|
|
$("#terminal-input").before('<tr class="posted"><td class="terminal-line" style="color: var(--my-font-color); background-color: var(--my-background-color);">' + input.replace( / /g, " " ) + '</td></tr>');
|
2017-06-23 16:23:35 +02:00
|
|
|
} else {
|
2017-07-22 00:54:55 +02:00
|
|
|
$("#terminal-input").before('<tr class="posted"><td class="terminal-line" style="color: var(--my-font-color); background-color: var(--my-background-color);">' + input + '</td></tr>');
|
2017-06-23 16:23:35 +02:00
|
|
|
}
|
2016-12-21 19:36:42 +01:00
|
|
|
updateTerminalScroll();
|
2016-10-17 10:24:39 +02:00
|
|
|
}
|
|
|
|
|
2016-10-27 05:34:18 +02:00
|
|
|
//Same thing as post but the td cells have ids so they can be animated for the hack progress bar
|
2017-08-30 19:44:29 +02:00
|
|
|
function hackProgressBarPost(input) {
|
2017-06-07 03:23:51 +02:00
|
|
|
$("#terminal-input").before('<tr class="posted"><td id="hack-progress-bar" style="color: var(--my-font-color); background-color: var(--my-background-color);">' + input + '</td></tr>');
|
2016-12-21 19:36:42 +01:00
|
|
|
updateTerminalScroll();
|
2016-10-27 05:34:18 +02:00
|
|
|
}
|
|
|
|
|
2017-08-30 19:44:29 +02:00
|
|
|
function hackProgressPost(input) {
|
2017-06-07 03:23:51 +02:00
|
|
|
$("#terminal-input").before('<tr class="posted"><td id="hack-progress" style="color: var(--my-font-color); background-color: var(--my-background-color);">' + input + '</td></tr>');
|
2017-07-25 03:06:40 +02:00
|
|
|
updateTerminalScroll();
|
2016-12-21 19:36:42 +01:00
|
|
|
}
|
|
|
|
|
2017-05-01 19:23:20 +02:00
|
|
|
//Scroll to the bottom of the terminal's 'text area'
|
2016-12-21 19:36:42 +01:00
|
|
|
function updateTerminalScroll() {
|
|
|
|
var element = document.getElementById("terminal-container");
|
|
|
|
element.scrollTop = element.scrollHeight;
|
2016-10-27 05:34:18 +02:00
|
|
|
}
|
|
|
|
|
2017-08-30 19:44:29 +02:00
|
|
|
function postNetburnerText() {
|
2017-04-24 21:10:35 +02:00
|
|
|
post("Bitburner v" + CONSTANTS.Version);
|
2016-10-20 23:11:01 +02:00
|
|
|
}
|
|
|
|
|
2016-12-21 17:33:00 +01:00
|
|
|
//Defines key commands in terminal
|
2017-05-01 23:38:49 +02:00
|
|
|
$(document).keydown(function(event) {
|
2016-11-24 23:30:33 +01:00
|
|
|
//Terminal
|
|
|
|
if (Engine.currentPage == Engine.Page.Terminal) {
|
2017-05-02 18:28:54 +02:00
|
|
|
var terminalInput = document.getElementById("terminal-input-text-box");
|
2017-05-04 09:05:43 +02:00
|
|
|
if (terminalInput != null && !event.ctrlKey && !event.shiftKey) {terminalInput.focus();}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-12-21 17:33:00 +01:00
|
|
|
//Enter
|
2016-11-24 23:30:33 +01:00
|
|
|
if (event.keyCode == 13) {
|
2017-05-16 06:37:14 +02:00
|
|
|
event.preventDefault(); //Prevent newline from being entered in Script Editor
|
2016-11-24 23:30:33 +01:00
|
|
|
var command = $('input[class=terminal-input]').val();
|
|
|
|
if (command.length > 0) {
|
2017-09-13 16:22:22 +02:00
|
|
|
post("[" + Player.getCurrentServer().hostname + " ~]> " + command);
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-09-13 16:22:22 +02:00
|
|
|
Terminal.resetTerminalInput(); //Clear input first
|
2016-11-24 23:30:33 +01:00
|
|
|
Terminal.executeCommand(command);
|
|
|
|
}
|
2016-10-17 10:24:39 +02:00
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-12-21 17:33:00 +01:00
|
|
|
//Ctrl + c when an "Action" is in progress
|
|
|
|
if (event.keyCode == 67 && event.ctrlKey && Engine._actionInProgress) {
|
|
|
|
post("Cancelling...");
|
|
|
|
Engine._actionInProgress = false;
|
|
|
|
Terminal.finishAction(true);
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-01 19:23:20 +02:00
|
|
|
//Up key to cycle through past commands
|
|
|
|
if (event.keyCode == 38) {
|
2017-05-03 06:38:58 +02:00
|
|
|
if (terminalInput == null) {return;}
|
2017-05-02 05:05:26 +02:00
|
|
|
var i = Terminal.commandHistoryIndex;
|
|
|
|
var len = Terminal.commandHistory.length;
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-02 05:05:26 +02:00
|
|
|
if (len == 0) {return;}
|
|
|
|
if (i < 0 || i > len) {
|
|
|
|
Terminal.commandHistoryIndex = len;
|
2017-07-25 03:06:40 +02:00
|
|
|
}
|
|
|
|
|
2017-05-02 05:05:26 +02:00
|
|
|
if (i != 0) {
|
|
|
|
--Terminal.commandHistoryIndex;
|
|
|
|
}
|
2017-05-01 19:23:20 +02:00
|
|
|
var prevCommand = Terminal.commandHistory[Terminal.commandHistoryIndex];
|
2017-05-02 18:28:54 +02:00
|
|
|
terminalInput.value = prevCommand;
|
|
|
|
setTimeout(function(){terminalInput.selectionStart = terminalInput.selectionEnd = 10000; }, 0);
|
2017-05-02 05:05:26 +02:00
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-02 05:05:26 +02:00
|
|
|
//Down key
|
|
|
|
if (event.keyCode == 40) {
|
2017-05-03 06:38:58 +02:00
|
|
|
if (terminalInput == null) {return;}
|
2017-05-02 05:05:26 +02:00
|
|
|
var i = Terminal.commandHistoryIndex;
|
|
|
|
var len = Terminal.commandHistory.length;
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-02 05:05:26 +02:00
|
|
|
if (len == 0) {return;}
|
|
|
|
if (i < 0 || i > len) {
|
|
|
|
Terminal.commandHistoryIndex = len;
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-02 05:05:26 +02:00
|
|
|
//Latest command, put nothing
|
|
|
|
if (i == len || i == len-1) {
|
|
|
|
Terminal.commandHistoryIndex = len;
|
2017-05-02 18:28:54 +02:00
|
|
|
terminalInput.value = "";
|
2017-05-02 05:05:26 +02:00
|
|
|
} else {
|
|
|
|
++Terminal.commandHistoryIndex;
|
|
|
|
var prevCommand = Terminal.commandHistory[Terminal.commandHistoryIndex];
|
2017-05-02 18:28:54 +02:00
|
|
|
terminalInput.value = prevCommand;
|
2017-05-02 05:05:26 +02:00
|
|
|
}
|
2017-05-01 19:23:20 +02:00
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-01 23:38:49 +02:00
|
|
|
//Tab (autocomplete)
|
|
|
|
if (event.keyCode == 9) {
|
2017-05-03 06:38:58 +02:00
|
|
|
if (terminalInput == null) {return;}
|
2017-05-02 18:28:54 +02:00
|
|
|
var input = terminalInput.value;
|
2017-05-01 23:38:49 +02:00
|
|
|
if (input == "") {return;}
|
2017-05-02 05:05:26 +02:00
|
|
|
input = input.trim();
|
2017-05-01 23:38:49 +02:00
|
|
|
input = input.replace(/\s\s+/g, ' ');
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-30 04:02:41 +02:00
|
|
|
var commandArray = input.split(" ");
|
|
|
|
var index = commandArray.length - 2;
|
2017-06-03 03:26:17 +02:00
|
|
|
if (index < -1) {index = 0;}
|
2017-05-30 04:02:41 +02:00
|
|
|
var allPos = determineAllPossibilitiesForTabCompletion(input, index);
|
2017-05-01 23:38:49 +02:00
|
|
|
if (allPos.length == 0) {return;}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-01 23:38:49 +02:00
|
|
|
var arg = "";
|
2017-05-30 04:02:41 +02:00
|
|
|
var command = "";
|
2017-05-01 23:38:49 +02:00
|
|
|
if (commandArray.length == 0) {return;}
|
2017-07-25 03:06:40 +02:00
|
|
|
if (commandArray.length == 1) {command = commandArray[0];}
|
2017-05-30 04:02:41 +02:00
|
|
|
else if (commandArray.length == 2) {
|
|
|
|
command = commandArray[0];
|
2017-05-01 23:38:49 +02:00
|
|
|
arg = commandArray[1];
|
2017-05-30 04:02:41 +02:00
|
|
|
} else if (commandArray.length == 3) {
|
|
|
|
command = commandArray[0] + " " + commandArray[1];
|
|
|
|
arg = commandArray[2];
|
|
|
|
} else {
|
2017-07-25 03:06:40 +02:00
|
|
|
arg = commandArray.pop();
|
|
|
|
command = commandArray.join(" ");
|
2017-05-01 23:38:49 +02:00
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-30 04:02:41 +02:00
|
|
|
tabCompletion(command, arg, allPos);
|
2017-05-01 23:38:49 +02:00
|
|
|
}
|
2016-10-17 10:24:39 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-11-24 23:30:33 +01:00
|
|
|
//Keep terminal in focus
|
2017-08-30 19:44:29 +02:00
|
|
|
let terminalCtrlPressed = false;
|
2016-11-24 23:30:33 +01:00
|
|
|
$(document).ready(function() {
|
|
|
|
if (Engine.currentPage == Engine.Page.Terminal) {
|
|
|
|
$('.terminal-input').focus();
|
|
|
|
}
|
|
|
|
});
|
2016-12-19 21:59:13 +01:00
|
|
|
$(document).keydown(function(e) {
|
2016-11-24 23:30:33 +01:00
|
|
|
if (Engine.currentPage == Engine.Page.Terminal) {
|
2016-12-19 21:59:13 +01:00
|
|
|
if (e.which == 17) {
|
|
|
|
terminalCtrlPressed = true;
|
|
|
|
} else if (terminalCtrlPressed == true) {
|
|
|
|
//Don't focus
|
|
|
|
} else {
|
2017-05-03 06:38:58 +02:00
|
|
|
var inputTextBox = document.getElementById("terminal-input-text-box");
|
|
|
|
if (inputTextBox != null) {
|
|
|
|
inputTextBox.focus();
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-12-19 21:59:13 +01:00
|
|
|
terminalCtrlPressed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
$(document).keyup(function(e) {
|
|
|
|
if (Engine.currentPage == Engine.Page.Terminal) {
|
|
|
|
if (e.which == 17) {
|
|
|
|
terminalCtrlPressed = false;
|
|
|
|
}
|
2016-11-24 23:30:33 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-05-01 23:38:49 +02:00
|
|
|
//Implements a tab completion feature for terminal
|
2017-05-02 05:05:26 +02:00
|
|
|
// command - Command (first arg only)
|
|
|
|
// arg - Incomplete argument string that the function will try to complete, or will display
|
2017-05-01 23:38:49 +02:00
|
|
|
// a series of possible options for
|
|
|
|
// allPossibilities - Array of strings containing all possibilities that the
|
|
|
|
// string can complete to
|
2017-05-30 04:02:41 +02:00
|
|
|
// index - index of argument that is being "tab completed". By default is 0, the first argument
|
|
|
|
function tabCompletion(command, arg, allPossibilities, index=0) {
|
2017-05-01 23:38:49 +02:00
|
|
|
if (!(allPossibilities.constructor === Array)) {return;}
|
|
|
|
if (!containsAllStrings(allPossibilities)) {return;}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-07-27 04:56:14 +02:00
|
|
|
if (!command.startsWith("./")) {
|
|
|
|
command = command.toLowerCase();
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-07-22 00:54:55 +02:00
|
|
|
//Remove all options in allPossibilities that do not match the current string
|
|
|
|
//that we are attempting to autocomplete
|
2017-06-03 03:26:17 +02:00
|
|
|
if (arg == "") {
|
|
|
|
for (var i = allPossibilities.length-1; i >= 0; --i) {
|
2017-09-12 01:14:51 +02:00
|
|
|
if (!allPossibilities[i].toLowerCase().startsWith(command.toLowerCase())) {
|
2017-06-03 03:26:17 +02:00
|
|
|
allPossibilities.splice(i, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (var i = allPossibilities.length-1; i >= 0; --i) {
|
2017-09-12 01:14:51 +02:00
|
|
|
if (!allPossibilities[i].toLowerCase().startsWith(arg.toLowerCase())) {
|
2017-06-03 03:26:17 +02:00
|
|
|
allPossibilities.splice(i, 1);
|
|
|
|
}
|
2017-05-01 23:38:49 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-06-03 03:26:17 +02:00
|
|
|
var val = "";
|
2017-05-02 18:28:54 +02:00
|
|
|
if (allPossibilities.length == 0) {
|
|
|
|
return;
|
2017-07-25 03:06:40 +02:00
|
|
|
} else if (allPossibilities.length == 1) {
|
2017-06-03 03:26:17 +02:00
|
|
|
if (arg == "") {
|
|
|
|
//Autocomplete command
|
2017-06-03 03:46:43 +02:00
|
|
|
val = allPossibilities[0] + " ";
|
2017-06-03 03:26:17 +02:00
|
|
|
} else {
|
|
|
|
val = command + " " + allPossibilities[0];
|
|
|
|
}
|
|
|
|
document.getElementById("terminal-input-text-box").value = val;
|
2017-05-02 05:05:26 +02:00
|
|
|
document.getElementById("terminal-input-text-box").focus();
|
2017-05-01 23:38:49 +02:00
|
|
|
} else {
|
|
|
|
var longestStartSubstr = longestCommonStart(allPossibilities);
|
|
|
|
//If the longest common starting substring of remaining possibilities is the same
|
|
|
|
//as whatevers already in terminal, just list all possible options. Otherwise,
|
|
|
|
//change the input in the terminal to the longest common starting substr
|
2017-06-03 03:26:17 +02:00
|
|
|
var allOptionsStr = "";
|
|
|
|
for (var i = 0; i < allPossibilities.length; ++i) {
|
|
|
|
allOptionsStr += allPossibilities[i];
|
|
|
|
allOptionsStr += " ";
|
|
|
|
}
|
|
|
|
if (arg == "") {
|
|
|
|
if (longestStartSubstr == command) {
|
|
|
|
post("> " + command);
|
|
|
|
post(allOptionsStr);
|
|
|
|
} else {
|
|
|
|
document.getElementById("terminal-input-text-box").value = longestStartSubstr;
|
|
|
|
document.getElementById("terminal-input-text-box").focus();
|
2017-05-01 23:38:49 +02:00
|
|
|
}
|
|
|
|
} else {
|
2017-06-03 03:26:17 +02:00
|
|
|
if (longestStartSubstr == arg) {
|
|
|
|
//List all possible options
|
|
|
|
post("> " + command + " " + arg);
|
|
|
|
post(allOptionsStr);
|
|
|
|
} else {
|
|
|
|
document.getElementById("terminal-input-text-box").value = command + " " + longestStartSubstr;
|
|
|
|
document.getElementById("terminal-input-text-box").focus();
|
|
|
|
}
|
2017-05-01 23:38:49 +02:00
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-01 23:38:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-30 04:02:41 +02:00
|
|
|
function determineAllPossibilitiesForTabCompletion(input, index=0) {
|
2017-05-01 23:38:49 +02:00
|
|
|
var allPos = [];
|
2017-07-25 03:06:40 +02:00
|
|
|
allPos = allPos.concat(Object.keys(GlobalAliases));
|
2017-05-01 23:38:49 +02:00
|
|
|
var currServ = Player.getCurrentServer();
|
2017-06-03 03:26:17 +02:00
|
|
|
input = input.toLowerCase();
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-07-27 04:56:14 +02:00
|
|
|
//If the command starts with './' and the index == -1, then the user
|
|
|
|
//has input ./partialexecutablename so autocomplete the script or program
|
|
|
|
//Put './' in front of each script/executable
|
|
|
|
if (input.startsWith("./") && index == -1) {
|
|
|
|
//All programs and scripts
|
|
|
|
for (var i = 0; i < currServ.scripts.length; ++i) {
|
|
|
|
allPos.push("./" + currServ.scripts[i].filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Programs are on home computer
|
|
|
|
var homeComputer = Player.getHomeComputer();
|
|
|
|
for(var i = 0; i < homeComputer.programs.length; ++i) {
|
|
|
|
allPos.push("./" + homeComputer.programs[i]);
|
|
|
|
}
|
|
|
|
return allPos;
|
|
|
|
}
|
|
|
|
|
2017-06-03 03:26:17 +02:00
|
|
|
//Autocomplete the command
|
|
|
|
if (index == -1) {
|
2017-10-12 04:00:22 +02:00
|
|
|
return ["alias", "analyze", "cat", "check", "clear", "cls", "connect", "download", "free",
|
2017-06-05 19:59:30 +02:00
|
|
|
"hack", "help", "home", "hostname", "ifconfig", "kill", "killall",
|
2017-10-10 06:56:48 +02:00
|
|
|
"ls", "lscpu", "mem", "nano", "ps", "rm", "run", "scan", "scan-analyze",
|
2017-06-30 18:44:03 +02:00
|
|
|
"scp", "sudov", "tail", "theme", "top"].concat(Object.keys(Aliases)).concat(Object.keys(GlobalAliases));
|
2017-06-03 03:26:17 +02:00
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-06-15 03:27:22 +02:00
|
|
|
if (input.startsWith ("buy ")) {
|
|
|
|
return [Programs.BruteSSHProgram, Programs.FTPCrackProgram, Programs.RelaySMTPProgram,
|
|
|
|
Programs.HTTPWormProgram, Programs.SQLInjectProgram, Programs.DeepscanV1,
|
2017-07-25 03:06:40 +02:00
|
|
|
Programs.DeepscanV2].concat(Object.keys(GlobalAliases));
|
2017-06-15 03:27:22 +02:00
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-30 04:02:41 +02:00
|
|
|
if (input.startsWith("scp ") && index == 1) {
|
|
|
|
for (var iphostname in AllServers) {
|
|
|
|
if (AllServers.hasOwnProperty(iphostname)) {
|
|
|
|
allPos.push(AllServers[iphostname].ip);
|
|
|
|
allPos.push(AllServers[iphostname].hostname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-08-18 19:20:51 +02:00
|
|
|
if (input.startsWith("scp ") && index == 0) {
|
|
|
|
//All Scripts and lit files
|
|
|
|
for (var i = 0; i < currServ.scripts.length; ++i) {
|
|
|
|
allPos.push(currServ.scripts[i].filename);
|
|
|
|
}
|
|
|
|
for (var i = 0; i < currServ.messages.length; ++i) {
|
|
|
|
if (!(currServ.messages[i] instanceof Message)) {
|
|
|
|
allPos.push(currServ.messages[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-01 23:38:49 +02:00
|
|
|
if (input.startsWith("connect ") || input.startsWith("telnet ")) {
|
|
|
|
//All network connections
|
|
|
|
for (var i = 0; i < currServ.serversOnNetwork.length; ++i) {
|
|
|
|
var serv = AllServers[currServ.serversOnNetwork[i]];
|
|
|
|
if (serv == null) {continue;}
|
|
|
|
allPos.push(serv.ip); //IP
|
|
|
|
allPos.push(serv.hostname); //Hostname
|
|
|
|
}
|
|
|
|
return allPos;
|
2017-07-25 03:06:40 +02:00
|
|
|
}
|
|
|
|
|
2017-05-01 23:38:49 +02:00
|
|
|
if (input.startsWith("kill ") || input.startsWith("nano ") ||
|
2017-09-12 01:14:51 +02:00
|
|
|
input.startsWith("tail ") ||
|
2017-08-18 19:20:51 +02:00
|
|
|
input.startsWith("mem ") || input.startsWith("check ")) {
|
2017-05-01 23:38:49 +02:00
|
|
|
//All Scripts
|
|
|
|
for (var i = 0; i < currServ.scripts.length; ++i) {
|
|
|
|
allPos.push(currServ.scripts[i].filename);
|
|
|
|
}
|
|
|
|
return allPos;
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-09-12 01:14:51 +02:00
|
|
|
if (input.startsWith("rm ")) {
|
|
|
|
for (var i = 0; i < currServ.scripts.length; ++i) {
|
|
|
|
allPos.push(currServ.scripts[i].filename);
|
|
|
|
}
|
|
|
|
for (var i = 0; i < currServ.programs.length; ++i) {
|
|
|
|
allPos.push(currServ.programs[i]);
|
|
|
|
}
|
|
|
|
for (var i = 0; i < currServ.messages.length; ++i) {
|
|
|
|
if (!(currServ.messages[i] instanceof Message) && isString(currServ.messages[i]) &&
|
|
|
|
currServ.messages[i].endsWith(".lit")) {
|
|
|
|
allPos.push(currServ.messages[i]);
|
|
|
|
}
|
|
|
|
}
|
2017-10-12 04:00:22 +02:00
|
|
|
for (var i = 0; i < currServ.textFiles.length; ++i) {
|
|
|
|
allPos.push(currServ.textFiles[i].fn);
|
|
|
|
}
|
2017-09-12 01:14:51 +02:00
|
|
|
return allPos;
|
|
|
|
}
|
|
|
|
|
2017-05-01 23:38:49 +02:00
|
|
|
if (input.startsWith("run ")) {
|
|
|
|
//All programs and scripts
|
|
|
|
for (var i = 0; i < currServ.scripts.length; ++i) {
|
|
|
|
allPos.push(currServ.scripts[i].filename);
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-01 23:38:49 +02:00
|
|
|
//Programs are on home computer
|
|
|
|
var homeComputer = Player.getHomeComputer();
|
|
|
|
for(var i = 0; i < homeComputer.programs.length; ++i) {
|
|
|
|
allPos.push(homeComputer.programs[i]);
|
|
|
|
}
|
|
|
|
return allPos;
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-06-02 06:15:45 +02:00
|
|
|
if (input.startsWith("cat ")) {
|
|
|
|
for (var i = 0; i < currServ.messages.length; ++i) {
|
2017-08-18 19:20:51 +02:00
|
|
|
if (currServ.messages[i] instanceof Message) {
|
|
|
|
allPos.push(currServ.messages[i].filename);
|
|
|
|
} else {
|
|
|
|
allPos.push(currServ.messages[i]);
|
|
|
|
}
|
2017-10-12 04:00:22 +02:00
|
|
|
}
|
|
|
|
for (var i = 0; i < currServ.textFiles.length; ++i) {
|
|
|
|
allPos.push(currServ.textFiles[i].fn);
|
2017-06-02 06:15:45 +02:00
|
|
|
}
|
|
|
|
return allPos;
|
|
|
|
}
|
2017-10-12 04:00:22 +02:00
|
|
|
|
|
|
|
if (input.startsWith("download ")) {
|
|
|
|
for (var i = 0; i < currServ.textFiles.length; ++i) {
|
|
|
|
allPos.push(currServ.textFiles[i].fn);
|
|
|
|
}
|
|
|
|
}
|
2017-05-01 23:38:49 +02:00
|
|
|
return allPos;
|
|
|
|
}
|
|
|
|
|
2017-08-30 19:44:29 +02:00
|
|
|
let Terminal = {
|
2016-11-01 06:30:59 +01:00
|
|
|
//Flags to determine whether the player is currently running a hack or an analyze
|
2017-07-25 03:06:40 +02:00
|
|
|
hackFlag: false,
|
|
|
|
analyzeFlag: false,
|
|
|
|
|
2017-05-01 19:23:20 +02:00
|
|
|
commandHistory: [],
|
|
|
|
commandHistoryIndex: 0,
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-12-21 17:33:00 +01:00
|
|
|
finishAction: function(cancelled = false) {
|
2016-11-01 06:30:59 +01:00
|
|
|
if (Terminal.hackFlag) {
|
2016-12-21 17:33:00 +01:00
|
|
|
Terminal.finishHack(cancelled);
|
2016-11-01 06:30:59 +01:00
|
|
|
} else if (Terminal.analyzeFlag) {
|
2016-12-21 17:33:00 +01:00
|
|
|
Terminal.finishAnalyze(cancelled);
|
2016-11-01 06:30:59 +01:00
|
|
|
}
|
|
|
|
},
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-09-13 16:22:22 +02:00
|
|
|
resetTerminalInput: function() {
|
|
|
|
document.getElementById("terminal-input-td").innerHTML =
|
|
|
|
"<div id='terminal-input-header'>[" + Player.getCurrentServer().hostname + " ~]" + "$ </div>" +
|
|
|
|
'<input type="text" id="terminal-input-text-box" class="terminal-input" tabindex="1"/>';
|
|
|
|
var hdr = document.getElementById("terminal-input-header");
|
|
|
|
hdr.style.display = "inline";
|
|
|
|
var lineWidth = document.getElementById("terminal-input-td").offsetWidth;
|
|
|
|
var width = lineWidth - hdr.offsetWidth - 10;
|
|
|
|
document.getElementById("terminal-input-text-box").style.width = width + "px";
|
|
|
|
},
|
|
|
|
|
2016-11-01 06:30:59 +01:00
|
|
|
//Complete the hack/analyze command
|
2016-12-21 17:33:00 +01:00
|
|
|
finishHack: function(cancelled = false) {
|
|
|
|
if (cancelled == false) {
|
2017-06-02 06:15:45 +02:00
|
|
|
var server = Player.getCurrentServer();
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-12-21 17:33:00 +01:00
|
|
|
//Calculate whether hack was successful
|
|
|
|
var hackChance = Player.calculateHackingChance();
|
|
|
|
var rand = Math.random();
|
|
|
|
console.log("Hack success chance: " + hackChance + ", rand: " + rand);
|
|
|
|
var expGainedOnSuccess = Player.calculateExpGain();
|
2017-05-05 17:50:55 +02:00
|
|
|
var expGainedOnFailure = (expGainedOnSuccess / 4);
|
2016-12-21 17:33:00 +01:00
|
|
|
if (rand < hackChance) { //Success!
|
2017-07-22 00:54:55 +02:00
|
|
|
if (SpecialServerIps[SpecialServerNames.WorldDaemon] &&
|
|
|
|
SpecialServerIps[SpecialServerNames.WorldDaemon] == server.ip) {
|
2017-08-13 07:01:33 +02:00
|
|
|
if (Player.bitNodeN == null) {
|
|
|
|
Player.bitNodeN = 1;
|
|
|
|
}
|
|
|
|
hackWorldDaemon(Player.bitNodeN);
|
2017-07-22 00:54:55 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-06-02 16:45:33 +02:00
|
|
|
server.manuallyHacked = true;
|
2016-12-21 17:33:00 +01:00
|
|
|
var moneyGained = Player.calculatePercentMoneyHacked();
|
2017-06-02 06:15:45 +02:00
|
|
|
moneyGained = Math.floor(server.moneyAvailable * moneyGained);
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-09-15 16:06:59 +02:00
|
|
|
if (moneyGained <= 0) {moneyGained = 0;} //Safety check
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-06-02 06:15:45 +02:00
|
|
|
server.moneyAvailable -= moneyGained;
|
2016-12-21 17:33:00 +01:00
|
|
|
Player.gainMoney(moneyGained);
|
2017-04-18 06:32:17 +02:00
|
|
|
Player.gainHackingExp(expGainedOnSuccess)
|
2017-09-15 16:06:59 +02:00
|
|
|
Player.gainIntelligenceExp(expGainedOnSuccess / CONSTANTS.IntelligenceTerminalHackBaseExpGain);
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-06-02 06:15:45 +02:00
|
|
|
server.fortify(CONSTANTS.ServerFortifyAmount);
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-05 17:50:55 +02:00
|
|
|
post("Hack successful! Gained $" + formatNumber(moneyGained, 2) + " and " + formatNumber(expGainedOnSuccess, 4) + " hacking EXP");
|
2016-12-21 17:33:00 +01:00
|
|
|
} else { //Failure
|
|
|
|
//Player only gains 25% exp for failure? TODO Can change this later to balance
|
2017-04-18 06:32:17 +02:00
|
|
|
Player.gainHackingExp(expGainedOnFailure)
|
2017-06-02 06:15:45 +02:00
|
|
|
post("Failed to hack " + server.hostname + ". Gained " + formatNumber(expGainedOnFailure, 4) + " hacking EXP");
|
2016-12-21 17:33:00 +01:00
|
|
|
}
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-11-01 06:30:59 +01:00
|
|
|
//Rename the progress bar so that the next hacks dont trigger it. Re-enable terminal
|
|
|
|
$("#hack-progress-bar").attr('id', "old-hack-progress-bar");
|
|
|
|
$("#hack-progress").attr('id', "old-hack-progress");
|
2017-09-13 16:22:22 +02:00
|
|
|
Terminal.resetTerminalInput();
|
|
|
|
//document.getElementById("terminal-input-td").innerHTML = '$ <input type="text" id="terminal-input-text-box" class="terminal-input" tabindex="1"/>';
|
2017-07-25 03:06:40 +02:00
|
|
|
$('input[class=terminal-input]').prop('disabled', false);
|
2016-11-01 06:30:59 +01:00
|
|
|
|
|
|
|
Terminal.hackFlag = false;
|
2016-10-27 20:26:00 +02:00
|
|
|
},
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-12-21 17:33:00 +01:00
|
|
|
finishAnalyze: function(cancelled = false) {
|
|
|
|
if (cancelled == false) {
|
|
|
|
post(Player.getCurrentServer().hostname + ": ");
|
2017-06-03 22:51:18 +02:00
|
|
|
post("Organization name: " + Player.getCurrentServer().organizationName);
|
2017-05-06 08:24:01 +02:00
|
|
|
var rootAccess = "";
|
|
|
|
if (Player.getCurrentServer().hasAdminRights) {rootAccess = "YES";}
|
|
|
|
else {rootAccess = "NO";}
|
|
|
|
post("Root Access: " + rootAccess);
|
2016-12-21 17:33:00 +01:00
|
|
|
post("Required hacking skill: " + Player.getCurrentServer().requiredHackingSkill);
|
2017-11-02 22:47:09 +01:00
|
|
|
post("Estimated server security level: " + formatNumber(addOffset(Player.getCurrentServer().hackDifficulty, 5), 3));
|
2017-05-06 08:24:01 +02:00
|
|
|
post("Estimated chance to hack: " + formatNumber(addOffset(Player.calculateHackingChance() * 100, 5), 2) + "%");
|
|
|
|
post("Estimated time to hack: " + formatNumber(addOffset(Player.calculateHackingTime(), 5), 3) + " seconds");
|
|
|
|
post("Estimated total money available on server: $" + formatNumber(addOffset(Player.getCurrentServer().moneyAvailable, 5), 2));
|
2017-04-13 19:33:34 +02:00
|
|
|
post("Required number of open ports for NUKE: " + Player.getCurrentServer().numOpenPortsRequired);
|
|
|
|
if (Player.getCurrentServer().sshPortOpen) {
|
2016-12-21 17:33:00 +01:00
|
|
|
post("SSH port: Open")
|
|
|
|
} else {
|
|
|
|
post("SSH port: Closed")
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-12-21 17:33:00 +01:00
|
|
|
if (Player.getCurrentServer().ftpPortOpen) {
|
|
|
|
post("FTP port: Open")
|
|
|
|
} else {
|
|
|
|
post("FTP port: Closed")
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-12-21 17:33:00 +01:00
|
|
|
if (Player.getCurrentServer().smtpPortOpen) {
|
|
|
|
post("SMTP port: Open")
|
|
|
|
} else {
|
|
|
|
post("SMTP port: Closed")
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-12-21 17:33:00 +01:00
|
|
|
if (Player.getCurrentServer().httpPortOpen) {
|
|
|
|
post("HTTP port: Open")
|
|
|
|
} else {
|
|
|
|
post("HTTP port: Closed")
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-12-21 17:33:00 +01:00
|
|
|
if (Player.getCurrentServer().sqlPortOpen) {
|
|
|
|
post("SQL port: Open")
|
|
|
|
} else {
|
|
|
|
post("SQL port: Closed")
|
|
|
|
}
|
|
|
|
}
|
2016-11-01 06:30:59 +01:00
|
|
|
Terminal.analyzeFlag = false;
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-11-21 07:11:14 +01:00
|
|
|
//Rename the progress bar so that the next hacks dont trigger it. Re-enable terminal
|
|
|
|
$("#hack-progress-bar").attr('id', "old-hack-progress-bar");
|
|
|
|
$("#hack-progress").attr('id', "old-hack-progress");
|
2017-09-13 16:22:22 +02:00
|
|
|
Terminal.resetTerminalInput();
|
|
|
|
//document.getElementById("terminal-input-td").innerHTML = '$ <input type="text" id="terminal-input-text-box" class="terminal-input" tabindex="1"/>';
|
2017-07-25 03:06:40 +02:00
|
|
|
$('input[class=terminal-input]').prop('disabled', false);
|
|
|
|
},
|
|
|
|
|
2016-10-20 20:26:38 +02:00
|
|
|
executeCommand: function(command) {
|
2017-05-02 05:05:26 +02:00
|
|
|
command = command.trim();
|
2017-05-01 23:38:49 +02:00
|
|
|
//Replace all extra whitespace in command with a single space
|
|
|
|
command = command.replace(/\s\s+/g, ' ');
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-06-06 23:22:57 +02:00
|
|
|
//Terminal history
|
2017-06-06 03:34:00 +02:00
|
|
|
if (Terminal.commandHistory[Terminal.commandHistory.length-1] != command) {
|
|
|
|
Terminal.commandHistory.push(command);
|
|
|
|
if (Terminal.commandHistory.length > 50) {
|
|
|
|
Terminal.commandHistory.splice(0, 1);
|
|
|
|
}
|
2017-05-01 19:23:20 +02:00
|
|
|
}
|
2017-06-06 23:22:57 +02:00
|
|
|
Terminal.commandHistoryIndex = Terminal.commandHistory.length;
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-23 17:12:09 +02:00
|
|
|
//Process any aliases
|
|
|
|
command = substituteAliases(command);
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-07-22 00:54:55 +02:00
|
|
|
//Allow usage of ./
|
|
|
|
if (command.startsWith("./")) {
|
2017-07-27 04:56:14 +02:00
|
|
|
command = "run " + command.slice(2);
|
2017-07-22 00:54:55 +02:00
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-23 05:50:06 +02:00
|
|
|
//Only split the first space
|
2016-10-24 09:18:01 +02:00
|
|
|
var commandArray = command.split(" ");
|
2017-05-23 05:50:06 +02:00
|
|
|
if (commandArray.length > 1) {
|
|
|
|
commandArray = [commandArray.shift(), commandArray.join(" ")];
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-05 17:50:55 +02:00
|
|
|
if (commandArray.length == 0) {return;}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
/****************** Interactive Tutorial Terminal Commands ******************/
|
|
|
|
if (iTutorialIsRunning) {
|
|
|
|
var foodnstuffServ = GetServerByHostname("foodnstuff");
|
|
|
|
if (foodnstuffServ == null) {throw new Error("Could not get foodnstuff server"); return;}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
switch(currITutorialStep) {
|
|
|
|
case iTutorialSteps.TerminalHelp:
|
|
|
|
if (commandArray[0] == "help") {
|
2017-07-22 00:54:55 +02:00
|
|
|
post(TerminalHelpText);
|
2017-05-06 08:24:01 +02:00
|
|
|
iTutorialNextStep();
|
2017-05-16 05:31:05 +02:00
|
|
|
} else {post("Bad command. Please follow the tutorial");}
|
2017-05-06 08:24:01 +02:00
|
|
|
break;
|
|
|
|
case iTutorialSteps.TerminalLs:
|
|
|
|
if (commandArray[0] == "ls") {
|
|
|
|
Terminal.executeListCommand(commandArray);
|
|
|
|
iTutorialNextStep();
|
2017-05-16 05:31:05 +02:00
|
|
|
} else {post("Bad command. Please follow the tutorial");}
|
2017-05-06 08:24:01 +02:00
|
|
|
break;
|
|
|
|
case iTutorialSteps.TerminalScan:
|
|
|
|
if (commandArray[0] == "scan") {
|
|
|
|
Terminal.executeScanCommand(commandArray);
|
|
|
|
iTutorialNextStep();
|
2017-05-16 05:31:05 +02:00
|
|
|
} else {post("Bad command. Please follow the tutorial");}
|
2017-05-06 08:24:01 +02:00
|
|
|
break;
|
2017-05-25 01:23:28 +02:00
|
|
|
case iTutorialSteps.TerminalScanAnalyze1:
|
|
|
|
if (commandArray.length == 1 && commandArray[0] == "scan-analyze") {
|
|
|
|
Terminal.executeScanAnalyzeCommand(1);
|
|
|
|
iTutorialNextStep();
|
|
|
|
} else {post("Bad command. Please follow the tutorial");}
|
|
|
|
break;
|
|
|
|
case iTutorialSteps.TerminalScanAnalyze2:
|
|
|
|
if (commandArray.length == 2 && commandArray[0] == "scan-analyze" &&
|
|
|
|
commandArray[1] == "2") {
|
|
|
|
Terminal.executeScanAnalyzeCommand(2);
|
|
|
|
iTutorialNextStep();
|
|
|
|
} else {post("Bad command. Please follow the tutorial");}
|
|
|
|
break;
|
|
|
|
break;
|
2017-05-06 08:24:01 +02:00
|
|
|
case iTutorialSteps.TerminalConnect:
|
|
|
|
if (commandArray.length == 2) {
|
2017-05-25 01:23:28 +02:00
|
|
|
if ((commandArray[0] == "connect") &&
|
2017-05-06 08:24:01 +02:00
|
|
|
(commandArray[1] == "foodnstuff" || commandArray[1] == foodnstuffServ.ip)) {
|
|
|
|
Player.getCurrentServer().isConnectedTo = false;
|
|
|
|
Player.currentServer = foodnstuffServ.ip;
|
|
|
|
Player.getCurrentServer().isConnectedTo = true;
|
|
|
|
post("Connected to foodnstuff");
|
|
|
|
iTutorialNextStep();
|
|
|
|
} else {post("Wrong command! Try again!"); return;}
|
2017-05-16 05:31:05 +02:00
|
|
|
} else {post("Bad command. Please follow the tutorial");}
|
2017-05-06 08:24:01 +02:00
|
|
|
break;
|
|
|
|
case iTutorialSteps.TerminalAnalyze:
|
2017-07-25 03:06:40 +02:00
|
|
|
if (commandArray[0] == "analyze") {
|
2017-05-06 08:24:01 +02:00
|
|
|
if (commandArray.length != 1) {
|
|
|
|
post("Incorrect usage of analyze command. Usage: analyze"); return;
|
|
|
|
}
|
|
|
|
//Analyze the current server for information
|
|
|
|
Terminal.analyzeFlag = true;
|
|
|
|
post("Analyzing system...");
|
|
|
|
hackProgressPost("Time left:");
|
|
|
|
hackProgressBarPost("[");
|
|
|
|
Player.analyze();
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
//Disable terminal
|
2017-09-13 16:22:22 +02:00
|
|
|
//Terminal.resetTerminalInput();
|
2017-05-06 08:24:01 +02:00
|
|
|
document.getElementById("terminal-input-td").innerHTML = '<input type="text" class="terminal-input"/>';
|
|
|
|
$('input[class=terminal-input]').prop('disabled', true);
|
|
|
|
iTutorialNextStep();
|
|
|
|
} else {
|
2017-05-16 05:31:05 +02:00
|
|
|
post("Bad command. Please follow the tutorial");
|
2017-05-06 08:24:01 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case iTutorialSteps.TerminalNuke:
|
2017-07-25 03:06:40 +02:00
|
|
|
if (commandArray.length == 2 &&
|
2017-05-06 08:24:01 +02:00
|
|
|
commandArray[0] == "run" && commandArray[1] == "NUKE.exe") {
|
|
|
|
foodnstuffServ.hasAdminRights = true;
|
|
|
|
post("NUKE successful! Gained root access to foodnstuff");
|
|
|
|
iTutorialNextStep();
|
2017-05-16 05:31:05 +02:00
|
|
|
} else {post("Bad command. Please follow the tutorial");}
|
2017-05-06 08:24:01 +02:00
|
|
|
break;
|
|
|
|
case iTutorialSteps.TerminalManualHack:
|
|
|
|
if (commandArray.length == 1 && commandArray[0] == "hack") {
|
|
|
|
Terminal.hackFlag = true;
|
|
|
|
hackProgressPost("Time left:");
|
|
|
|
hackProgressBarPost("[");
|
|
|
|
Player.hack();
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
//Disable terminal
|
2017-09-13 16:22:22 +02:00
|
|
|
//Terminal.resetTerminalInput();
|
2017-05-06 08:24:01 +02:00
|
|
|
document.getElementById("terminal-input-td").innerHTML = '<input type="text" class="terminal-input"/>';
|
|
|
|
$('input[class=terminal-input]').prop('disabled', true);
|
|
|
|
iTutorialNextStep();
|
2017-05-16 05:31:05 +02:00
|
|
|
} else {post("Bad command. Please follow the tutorial");}
|
2017-05-06 08:24:01 +02:00
|
|
|
break;
|
|
|
|
case iTutorialSteps.TerminalCreateScript:
|
2017-07-25 03:06:40 +02:00
|
|
|
if (commandArray.length == 2 &&
|
2017-05-06 08:24:01 +02:00
|
|
|
commandArray[0] == "nano" && commandArray[1] == "foodnstuff.script") {
|
|
|
|
Engine.loadScriptEditorContent("foodnstuff", "");
|
|
|
|
iTutorialNextStep();
|
2017-05-16 05:31:05 +02:00
|
|
|
} else {post("Bad command. Please follow the tutorial");}
|
2017-05-06 08:24:01 +02:00
|
|
|
case iTutorialSteps.TerminalFree:
|
|
|
|
if (commandArray.length == 1 && commandArray[0] == "free") {
|
|
|
|
Terminal.executeFreeCommand(commandArray);
|
|
|
|
iTutorialNextStep();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case iTutorialSteps.TerminalRunScript:
|
2017-07-25 03:06:40 +02:00
|
|
|
if (commandArray.length == 2 &&
|
2017-05-06 08:24:01 +02:00
|
|
|
commandArray[0] == "run" && commandArray[1] == "foodnstuff.script") {
|
|
|
|
Terminal.runScript("foodnstuff.script");
|
|
|
|
iTutorialNextStep();
|
2017-05-16 05:31:05 +02:00
|
|
|
} else {post("Bad command. Please follow the tutorial");}
|
2017-05-06 08:24:01 +02:00
|
|
|
break;
|
|
|
|
case iTutorialSteps.ActiveScriptsToTerminal:
|
|
|
|
if (commandArray.length == 2 &&
|
|
|
|
commandArray[0] == "tail" && commandArray[1] == "foodnstuff.script") {
|
2017-06-18 23:01:23 +02:00
|
|
|
//Check that the script exists on this machine
|
|
|
|
var runningScript = findRunningScript("foodnstuff.script", [], Player.getCurrentServer());
|
|
|
|
if (runningScript == null) {
|
|
|
|
post("Error: No such script exists");
|
|
|
|
return;
|
2017-05-06 08:24:01 +02:00
|
|
|
}
|
2017-06-18 23:01:23 +02:00
|
|
|
logBoxCreate(runningScript);
|
2017-05-06 08:24:01 +02:00
|
|
|
iTutorialNextStep();
|
2017-05-16 05:31:05 +02:00
|
|
|
} else {post("Bad command. Please follow the tutorial");}
|
2017-05-06 08:24:01 +02:00
|
|
|
break;
|
2017-07-25 03:06:40 +02:00
|
|
|
default:
|
2017-05-06 08:24:01 +02:00
|
|
|
post("Please follow the tutorial, or click 'Exit Tutorial' if you'd like to skip it");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
/****************** END INTERACTIVE TUTORIAL ******************/
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
/* Command parser */
|
2017-06-17 04:53:57 +02:00
|
|
|
var s = Player.getCurrentServer();
|
2017-06-03 02:41:46 +02:00
|
|
|
switch (commandArray[0].toLowerCase()) {
|
2017-05-23 05:50:06 +02:00
|
|
|
case "alias":
|
|
|
|
if (commandArray.length == 1) {
|
|
|
|
printAliases();
|
2017-06-30 18:44:03 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-07-05 19:53:51 +02:00
|
|
|
if (commandArray.length == 2) {
|
|
|
|
if (commandArray[1].startsWith("-g ")) {
|
|
|
|
var alias = commandArray[1].substring(3);
|
|
|
|
if (parseAliasDeclaration(alias, true)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (parseAliasDeclaration(commandArray[1])) {
|
|
|
|
return;
|
|
|
|
}
|
2017-05-23 15:49:20 +02:00
|
|
|
}
|
2017-05-23 05:50:06 +02:00
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
post('Incorrect usage of alias command. Usage: alias [-g] [aliasname="value"]');
|
2017-05-23 05:50:06 +02:00
|
|
|
break;
|
2016-10-20 20:26:38 +02:00
|
|
|
case "analyze":
|
2016-11-24 23:30:33 +01:00
|
|
|
if (commandArray.length != 1) {
|
|
|
|
post("Incorrect usage of analyze command. Usage: analyze"); return;
|
|
|
|
}
|
2016-11-01 06:30:59 +01:00
|
|
|
//Analyze the current server for information
|
|
|
|
Terminal.analyzeFlag = true;
|
|
|
|
post("Analyzing system...");
|
|
|
|
hackProgressPost("Time left:");
|
|
|
|
hackProgressBarPost("[");
|
|
|
|
Player.analyze();
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-11-01 06:30:59 +01:00
|
|
|
//Disable terminal
|
2017-09-13 16:22:22 +02:00
|
|
|
//Terminal.resetTerminalInput();
|
2016-11-01 06:30:59 +01:00
|
|
|
document.getElementById("terminal-input-td").innerHTML = '<input type="text" class="terminal-input"/>';
|
|
|
|
$('input[class=terminal-input]').prop('disabled', true);
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
2017-05-05 17:50:55 +02:00
|
|
|
case "buy":
|
2017-06-14 03:07:02 +02:00
|
|
|
if (SpecialServerIps.hasOwnProperty("Darkweb Server")) {
|
|
|
|
executeDarkwebTerminalCommand(commandArray);
|
2017-06-15 03:27:22 +02:00
|
|
|
} else {
|
|
|
|
post("You need to be connected to the Dark Web to use the buy command");
|
2017-06-14 03:07:02 +02:00
|
|
|
}
|
2017-06-02 06:15:45 +02:00
|
|
|
break;
|
|
|
|
case "cat":
|
|
|
|
if (commandArray.length != 2) {
|
2017-08-18 19:20:51 +02:00
|
|
|
post("Incorrect usage of cat command. Usage: cat [file]"); return;
|
2017-06-02 06:15:45 +02:00
|
|
|
}
|
|
|
|
var filename = commandArray[1];
|
2017-10-12 04:00:22 +02:00
|
|
|
if (!filename.endsWith(".msg") && !filename.endsWith(".lit") && !filename.endsWith(".txt")) {
|
|
|
|
post("Error: Only .msg, .txt, and .lit files are viewable with cat (filename must end with .msg, .txt, or .lit)"); return;
|
2017-06-02 06:15:45 +02:00
|
|
|
}
|
|
|
|
for (var i = 0; i < s.messages.length; ++i) {
|
2017-08-18 19:20:51 +02:00
|
|
|
if (filename.endsWith(".lit") && s.messages[i] == filename) {
|
|
|
|
showLiterature(s.messages[i]);
|
|
|
|
return;
|
|
|
|
} else if (filename.endsWith(".msg") && s.messages[i].filename == filename) {
|
2017-06-02 06:15:45 +02:00
|
|
|
showMessage(s.messages[i]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-10-12 04:00:22 +02:00
|
|
|
for (var i = 0; i < s.textFiles.length; ++i) {
|
|
|
|
if (s.textFiles[i].fn === filename) {
|
|
|
|
s.textFiles[i].show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-06-02 06:15:45 +02:00
|
|
|
post("Error: No such file " + filename);
|
2017-06-15 03:19:52 +02:00
|
|
|
break;
|
|
|
|
case "check":
|
2017-06-17 04:53:57 +02:00
|
|
|
if (commandArray.length < 2) {
|
|
|
|
post("Incorrect number of arguments. Usage: check [script] [arg1] [arg2]...");
|
2017-06-15 03:19:52 +02:00
|
|
|
} else {
|
2017-06-17 04:53:57 +02:00
|
|
|
var results = commandArray[1].split(" ");
|
|
|
|
var scriptName = results[0];
|
|
|
|
var args = [];
|
|
|
|
for (var i = 1; i < results.length; ++i) {
|
|
|
|
args.push(results[i]);
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-06-17 04:53:57 +02:00
|
|
|
//Can only tail script files
|
2017-06-15 03:19:52 +02:00
|
|
|
if (scriptName.endsWith(".script") == false) {
|
2017-06-17 04:53:57 +02:00
|
|
|
post("Error: tail can only be called on .script files (filename must end with .script)"); return;
|
2017-06-15 03:19:52 +02:00
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-06-15 03:19:52 +02:00
|
|
|
//Check that the script exists on this machine
|
2017-06-17 04:53:57 +02:00
|
|
|
var runningScript = findRunningScript(scriptName, args, s);
|
|
|
|
if (runningScript == null) {
|
|
|
|
post("Error: No such script exists");
|
|
|
|
return;
|
2017-06-15 03:19:52 +02:00
|
|
|
}
|
2017-06-19 16:54:11 +02:00
|
|
|
runningScript.displayLog();
|
2017-06-15 03:19:52 +02:00
|
|
|
}
|
2017-05-05 17:50:55 +02:00
|
|
|
break;
|
2016-10-20 20:26:38 +02:00
|
|
|
case "clear":
|
|
|
|
case "cls":
|
2016-11-24 23:30:33 +01:00
|
|
|
if (commandArray.length != 1) {
|
|
|
|
post("Incorrect usage of clear/cls command. Usage: clear/cls"); return;
|
|
|
|
}
|
2016-10-20 23:11:01 +02:00
|
|
|
$("#terminal tr:not(:last)").remove();
|
|
|
|
postNetburnerText();
|
2017-07-25 03:06:40 +02:00
|
|
|
break;
|
2016-10-20 20:26:38 +02:00
|
|
|
case "connect":
|
2016-10-27 20:26:00 +02:00
|
|
|
//Disconnect from current server in terminal and connect to new one
|
2016-10-24 08:34:04 +02:00
|
|
|
if (commandArray.length != 2) {
|
2017-05-30 00:37:38 +02:00
|
|
|
post("Incorrect usage of connect command. Usage: connect [ip/hostname]");
|
2016-10-24 08:34:04 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-10-24 08:34:04 +02:00
|
|
|
var ip = commandArray[1];
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-12-01 23:18:18 +01:00
|
|
|
for (var i = 0; i < Player.getCurrentServer().serversOnNetwork.length; i++) {
|
|
|
|
if (Player.getCurrentServer().getServerOnNetwork(i).ip == ip || Player.getCurrentServer().getServerOnNetwork(i).hostname == ip) {
|
2017-06-23 16:23:35 +02:00
|
|
|
Terminal.connectToServer(ip);
|
2016-10-24 08:34:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
|
|
|
post("Host not found");
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
2017-10-12 04:00:22 +02:00
|
|
|
case "download":
|
|
|
|
if (commandArray.length != 2) {
|
|
|
|
post("Incorrect usage of download command. Usage: download [text file]");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var fn = commandArray[1];
|
|
|
|
var txtFile = getTextFile(fn, s);
|
|
|
|
if (txtFile !== null) {
|
|
|
|
txtFile.download();
|
|
|
|
} else {
|
|
|
|
post("Error: " + fn + " does not exist");
|
|
|
|
}
|
|
|
|
break;
|
2016-12-01 23:18:18 +01:00
|
|
|
case "free":
|
2017-05-06 21:12:45 +02:00
|
|
|
Terminal.executeFreeCommand(commandArray);
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
|
|
|
case "hack":
|
2016-11-24 23:30:33 +01:00
|
|
|
if (commandArray.length != 1) {
|
|
|
|
post("Incorrect usage of hack command. Usage: hack"); return;
|
|
|
|
}
|
2016-10-27 20:26:00 +02:00
|
|
|
//Hack the current PC (usually for money)
|
2016-10-20 20:26:38 +02:00
|
|
|
//You can't hack your home pc or servers you purchased
|
2016-12-01 23:18:18 +01:00
|
|
|
if (Player.getCurrentServer().purchasedByPlayer) {
|
2016-10-20 20:26:38 +02:00
|
|
|
post("Cannot hack your own machines! You are currently connected to your home PC or one of your purchased servers");
|
2016-12-01 23:18:18 +01:00
|
|
|
} else if (Player.getCurrentServer().hasAdminRights == false ) {
|
2016-10-20 23:34:21 +02:00
|
|
|
post("You do not have admin rights for this machine! Cannot hack");
|
2016-12-01 23:18:18 +01:00
|
|
|
} else if (Player.getCurrentServer().requiredHackingSkill > Player.hacking_skill) {
|
2016-10-24 23:16:51 +02:00
|
|
|
post("Your hacking skill is not high enough to attempt hacking this machine. Try analyzing the machine to determine the required hacking skill");
|
2016-10-20 20:26:38 +02:00
|
|
|
} else {
|
2016-11-01 06:30:59 +01:00
|
|
|
Terminal.hackFlag = true;
|
2016-10-27 05:34:18 +02:00
|
|
|
hackProgressPost("Time left:");
|
|
|
|
hackProgressBarPost("[");
|
2016-11-01 06:30:59 +01:00
|
|
|
Player.hack();
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-10-27 20:26:00 +02:00
|
|
|
//Disable terminal
|
2017-09-13 16:22:22 +02:00
|
|
|
//Terminal.resetTerminalInput();
|
2016-10-27 20:26:00 +02:00
|
|
|
document.getElementById("terminal-input-td").innerHTML = '<input type="text" class="terminal-input"/>';
|
|
|
|
$('input[class=terminal-input]').prop('disabled', true);
|
2016-10-20 20:26:38 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "help":
|
2017-07-22 00:54:55 +02:00
|
|
|
if (commandArray.length != 1 && commandArray.length != 2) {
|
2016-12-15 18:51:23 +01:00
|
|
|
post("Incorrect usage of help command. Usage: help"); return;
|
|
|
|
}
|
2017-07-22 00:54:55 +02:00
|
|
|
if (commandArray.length == 1) {
|
|
|
|
post(TerminalHelpText);
|
|
|
|
} else {
|
|
|
|
var cmd = commandArray[1];
|
|
|
|
var txt = HelpTexts[cmd];
|
|
|
|
if (txt == null) {
|
|
|
|
post("Error: No help topics match '" + cmd + "'");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
post(txt);
|
|
|
|
}
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
2016-12-14 00:52:32 +01:00
|
|
|
case "home":
|
2017-05-05 03:08:44 +02:00
|
|
|
if (commandArray.length != 1) {
|
|
|
|
post("Incorrect usage of home command. Usage: home"); return;
|
|
|
|
}
|
|
|
|
Player.getCurrentServer().isConnectedTo = false;
|
|
|
|
Player.currentServer = Player.getHomeComputer().ip;
|
|
|
|
Player.getCurrentServer().isConnectedTo = true;
|
|
|
|
post("Connected to home");
|
2017-09-13 16:22:22 +02:00
|
|
|
Terminal.resetTerminalInput();
|
2016-12-14 00:52:32 +01:00
|
|
|
break;
|
2016-10-20 20:26:38 +02:00
|
|
|
case "hostname":
|
2016-11-24 23:30:33 +01:00
|
|
|
if (commandArray.length != 1) {
|
|
|
|
post("Incorrect usage of hostname command. Usage: hostname"); return;
|
|
|
|
}
|
2016-10-20 20:26:38 +02:00
|
|
|
//Print the hostname of current system
|
2016-12-01 23:18:18 +01:00
|
|
|
post(Player.getCurrentServer().hostname);
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
|
|
|
case "ifconfig":
|
2016-11-24 23:30:33 +01:00
|
|
|
if (commandArray.length != 1) {
|
|
|
|
post("Incorrect usage of ifconfig command. Usage: ifconfig"); return;
|
|
|
|
}
|
2016-10-20 20:26:38 +02:00
|
|
|
//Print the IP address of the current system
|
2016-12-01 23:18:18 +01:00
|
|
|
post(Player.getCurrentServer().ip);
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
|
|
|
case "kill":
|
2017-06-17 04:53:57 +02:00
|
|
|
if (commandArray.length < 2) {
|
|
|
|
post("Incorrect usage of kill command. Usage: kill [scriptname] [arg1] [arg2]..."); return;
|
2016-12-06 19:09:23 +01:00
|
|
|
}
|
2017-06-17 04:53:57 +02:00
|
|
|
var results = commandArray[1].split(" ");
|
|
|
|
var scriptName = results[0];
|
|
|
|
var args = [];
|
|
|
|
for (var i = 1; i < results.length; ++i) {
|
|
|
|
args.push(results[i]);
|
|
|
|
}
|
|
|
|
var runningScript = findRunningScript(scriptName, args, s);
|
|
|
|
if (runningScript == null) {
|
|
|
|
post("No such script is running. Nothing to kill");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
killWorkerScript(runningScript, s.ip);
|
|
|
|
post("Killing " + scriptName + ". May take up to a few minutes for the scripts to die...");
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
2017-06-05 19:59:30 +02:00
|
|
|
case "killall":
|
2017-06-17 04:53:57 +02:00
|
|
|
for (var i = s.runningScripts.length-1; i >= 0; --i) {
|
2017-06-05 19:59:30 +02:00
|
|
|
killWorkerScript(s.runningScripts[i], s.ip);
|
|
|
|
}
|
|
|
|
post("Killing all running scripts. May take up to a few minutes for the scripts to die...");
|
|
|
|
break;
|
2016-10-20 20:26:38 +02:00
|
|
|
case "ls":
|
2017-05-06 08:24:01 +02:00
|
|
|
Terminal.executeListCommand(commandArray);
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
2017-10-10 06:56:48 +02:00
|
|
|
case "lscpu":
|
|
|
|
post(Player.getCurrentServer().cpuCores + " Core(s)");
|
|
|
|
break;
|
2017-05-15 04:46:52 +02:00
|
|
|
case "mem":
|
|
|
|
if (commandArray.length != 2) {
|
2017-06-11 22:28:20 +02:00
|
|
|
post("Incorrect usage of mem command. usage: mem [scriptname] [-t] [number threads]"); return;
|
2017-05-15 04:46:52 +02:00
|
|
|
}
|
|
|
|
var scriptName = commandArray[1];
|
2017-06-11 03:46:02 +02:00
|
|
|
var numThreads = 1;
|
|
|
|
if (scriptName.indexOf(" -t ") != -1) {
|
|
|
|
var results = scriptName.split(" ");
|
|
|
|
if (results.length != 3) {
|
|
|
|
post("Invalid use of run command. Usage: mem [script] [-t] [number threads]");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
numThreads = Math.round(Number(results[2]));
|
|
|
|
if (isNaN(numThreads) || numThreads < 1) {
|
|
|
|
post("Invalid number of threads specified. Number of threads must be greater than 1");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
scriptName = results[0];
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-15 04:46:52 +02:00
|
|
|
var currServ = Player.getCurrentServer();
|
|
|
|
for (var i = 0; i < currServ.scripts.length; ++i) {
|
|
|
|
if (scriptName == currServ.scripts[i].filename) {
|
2017-06-11 03:46:02 +02:00
|
|
|
var scriptBaseRamUsage = currServ.scripts[i].ramUsage;
|
2017-06-20 18:11:33 +02:00
|
|
|
var ramUsage = scriptBaseRamUsage * numThreads * Math.pow(CONSTANTS.MultithreadingRAMCost, numThreads-1);
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-06-11 03:46:02 +02:00
|
|
|
post("This script requires " + formatNumber(ramUsage, 2) + "GB of RAM to run for " + numThreads + " thread(s)");
|
2017-05-15 04:46:52 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
post("ERR: No such script exists!");
|
|
|
|
break;
|
2016-11-24 23:30:33 +01:00
|
|
|
case "nano":
|
|
|
|
if (commandArray.length != 2) {
|
|
|
|
post("Incorrect usage of nano command. Usage: nano [scriptname]"); return;
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-11-24 23:30:33 +01:00
|
|
|
var filename = commandArray[1];
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-11-24 23:30:33 +01:00
|
|
|
//Can only edit script files
|
|
|
|
if (filename.endsWith(".script") == false) {
|
2017-02-16 19:52:11 +01:00
|
|
|
post("Error: Only .script files are editable with nano (filename must end with .script)"); return;
|
2016-11-24 23:30:33 +01:00
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-11-24 23:30:33 +01:00
|
|
|
//Script name is the filename without the .script at the end
|
|
|
|
var scriptname = filename.substr(0, filename.indexOf(".script"));
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-11-24 23:30:33 +01:00
|
|
|
//Check if the script already exists
|
2016-12-01 23:18:18 +01:00
|
|
|
for (var i = 0; i < Player.getCurrentServer().scripts.length; i++) {
|
|
|
|
if (filename == Player.getCurrentServer().scripts[i].filename) {
|
|
|
|
Engine.loadScriptEditorContent(scriptname, Player.getCurrentServer().scripts[i].code);
|
2016-11-24 23:30:33 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Engine.loadScriptEditorContent(scriptname, "");
|
|
|
|
break;
|
2016-10-20 20:26:38 +02:00
|
|
|
case "ps":
|
2016-12-05 23:31:46 +01:00
|
|
|
if (commandArray.length != 1) {
|
2017-04-13 21:36:03 +02:00
|
|
|
post("Incorrect usage of ps command. Usage: ps"); return;
|
2016-12-05 23:31:46 +01:00
|
|
|
}
|
2017-06-17 04:53:57 +02:00
|
|
|
for (var i = 0; i < s.runningScripts.length; i++) {
|
|
|
|
var rsObj = s.runningScripts[i];
|
|
|
|
var res = rsObj.filename;
|
|
|
|
for (var j = 0; j < rsObj.args.length; ++j) {
|
|
|
|
res += (" " + rsObj.args[j].toString());
|
|
|
|
}
|
|
|
|
post(res);
|
2016-12-05 23:31:46 +01:00
|
|
|
}
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
|
|
|
case "rm":
|
2017-04-13 21:36:03 +02:00
|
|
|
if (commandArray.length != 2) {
|
|
|
|
post("Incorrect number of arguments. Usage: rm [program/script]"); return;
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-04-13 21:36:03 +02:00
|
|
|
//Check programs
|
|
|
|
var delTarget = commandArray[1];
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-10-12 04:00:22 +02:00
|
|
|
if (delTarget.endsWith(".exe")) {
|
|
|
|
for (var i = 0; i < s.programs.length; ++i) {
|
|
|
|
if (s.programs[i] == delTarget) {
|
|
|
|
s.programs.splice(i, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (delTarget.endsWith(".script")) {
|
|
|
|
for (var i = 0; i < s.scripts.length; ++i) {
|
|
|
|
if (s.scripts[i].filename == delTarget) {
|
|
|
|
//Check that the script isnt currently running
|
|
|
|
for (var j = 0; j < s.runningScripts.length; ++j) {
|
|
|
|
if (s.runningScripts[j].filename == delTarget) {
|
|
|
|
post("Cannot delete a script that is currently running!");
|
|
|
|
return;
|
|
|
|
}
|
2017-06-17 04:53:57 +02:00
|
|
|
}
|
2017-10-12 04:00:22 +02:00
|
|
|
s.scripts.splice(i, 1);
|
|
|
|
return;
|
2017-04-13 21:36:03 +02:00
|
|
|
}
|
|
|
|
}
|
2017-10-12 04:00:22 +02:00
|
|
|
} else if (delTarget.endsWith(".lit")) {
|
|
|
|
for (var i = 0; i < s.messages.length; ++i) {
|
|
|
|
var f = s.messages[i];
|
|
|
|
if (!(f instanceof Message) && isString(f) && f === delTarget) {
|
|
|
|
s.messages.splice(i, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (delTarget.endsWith(".txt")) {
|
|
|
|
for (var i = 0; i < s.textFiles.length; ++i) {
|
|
|
|
if (s.textFiles[i].fn === delTarget) {
|
|
|
|
s.textFiles.splice(i, 1);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-12 01:14:51 +02:00
|
|
|
}
|
|
|
|
}
|
2017-10-12 04:00:22 +02:00
|
|
|
post("Error: No such file exists");
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
|
|
|
case "run":
|
2016-10-24 23:16:51 +02:00
|
|
|
//Run a program or a script
|
2017-03-31 23:47:06 +02:00
|
|
|
if (commandArray.length != 2) {
|
2017-06-17 04:53:57 +02:00
|
|
|
post("Incorrect number of arguments. Usage: run [program/script] [-t] [num threads] [arg1] [arg2]...");
|
2016-10-24 23:16:51 +02:00
|
|
|
} else {
|
|
|
|
var executableName = commandArray[1];
|
2017-07-25 03:06:40 +02:00
|
|
|
//Check if its a script or just a program/executable
|
2016-10-24 23:16:51 +02:00
|
|
|
if (executableName.indexOf(".script") == -1) {
|
|
|
|
//Not a script
|
|
|
|
Terminal.runProgram(executableName);
|
|
|
|
} else {
|
|
|
|
//Script
|
|
|
|
Terminal.runScript(executableName);
|
|
|
|
}
|
|
|
|
}
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
2017-05-23 19:36:35 +02:00
|
|
|
case "scan":
|
|
|
|
Terminal.executeScanCommand(commandArray);
|
|
|
|
break;
|
2017-05-23 18:15:17 +02:00
|
|
|
case "scan-analyze":
|
2017-05-24 19:07:33 +02:00
|
|
|
if (commandArray.length == 1) {
|
|
|
|
Terminal.executeScanAnalyzeCommand(1);
|
|
|
|
} else if (commandArray.length == 2) {
|
2017-09-19 20:38:03 +02:00
|
|
|
var all = false;
|
|
|
|
if (commandArray[1].endsWith("-a")) {
|
|
|
|
all = true;
|
|
|
|
commandArray[1] = commandArray[1].replace("-a", "");
|
|
|
|
}
|
|
|
|
var depth;
|
|
|
|
if (commandArray[1].length === 0) {
|
|
|
|
depth = 1;
|
|
|
|
} else {
|
|
|
|
depth = Number(commandArray[1]);
|
|
|
|
}
|
2017-05-24 23:35:24 +02:00
|
|
|
if (isNaN(depth) || depth < 0) {
|
|
|
|
post("Incorrect usage of scan-analyze command. depth argument must be positive numeric");
|
|
|
|
return;
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
if (depth > 3 && !Player.hasProgram(Programs.DeepscanV1) &&
|
2017-05-24 23:35:24 +02:00
|
|
|
!Player.hasProgram(Programs.DeepscanV2)) {
|
|
|
|
post("You cannot scan-analyze with that high of a depth. Maximum depth is 3");
|
|
|
|
return;
|
|
|
|
} else if (depth > 5 && !Player.hasProgram(Programs.DeepscanV2)) {
|
|
|
|
post("You cannot scan-analyze with that high of a depth. Maximum depth is 5");
|
|
|
|
return;
|
|
|
|
} else if (depth > 10) {
|
|
|
|
post("You cannot scan-analyze with that high of a depth. Maximum depth is 10");
|
2017-05-24 19:07:33 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-09-19 20:38:03 +02:00
|
|
|
Terminal.executeScanAnalyzeCommand(depth, all);
|
2017-05-24 19:07:33 +02:00
|
|
|
} else {
|
|
|
|
post("Incorrect usage of scan-analyze command. usage: scan-analyze [depth]");
|
2017-07-25 03:06:40 +02:00
|
|
|
}
|
2017-05-23 18:15:17 +02:00
|
|
|
break;
|
2016-10-20 20:26:38 +02:00
|
|
|
case "scp":
|
2017-05-30 02:18:48 +02:00
|
|
|
if (commandArray.length != 2) {
|
2017-08-18 19:20:51 +02:00
|
|
|
post("Incorrect usage of scp command. Usage: scp [file] [destination hostname/ip]");
|
2017-05-30 02:18:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var args = commandArray[1].split(" ");
|
|
|
|
if (args.length != 2) {
|
2017-08-18 19:20:51 +02:00
|
|
|
post("Incorrect usage of scp command. Usage: scp [file] [destination hostname/ip]");
|
2017-05-30 02:18:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var scriptname = args[0];
|
2017-08-18 19:20:51 +02:00
|
|
|
if (!scriptname.endsWith(".lit") && !scriptname.endsWith(".script")){
|
|
|
|
post("Error: scp only works for .script and .lit files");
|
|
|
|
return;
|
|
|
|
}
|
2017-05-30 02:18:48 +02:00
|
|
|
var server = getServer(args[1]);
|
|
|
|
if (server == null) {
|
|
|
|
post("Invalid destination. " + args[1] + " not found");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var ip = server.ip;
|
2017-06-02 21:54:36 +02:00
|
|
|
var currServ = Player.getCurrentServer();
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-08-18 19:20:51 +02:00
|
|
|
//Scp for lit files
|
|
|
|
if (scriptname.endsWith(".lit")) {
|
|
|
|
var found = false;
|
|
|
|
for (var i = 0; i < currServ.messages.length; ++i) {
|
|
|
|
if (!(currServ.messages[i] instanceof Message) && currServ.messages[i] == scriptname) {
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
post("Error: no such file exists!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < server.messages.length; ++i) {
|
|
|
|
if (server.messages[i] === scriptname) {
|
|
|
|
post(scriptname + " copied over to " + server.hostname);
|
|
|
|
return; //Already exists
|
|
|
|
}
|
|
|
|
}
|
|
|
|
server.messages.push(scriptname);
|
|
|
|
post(scriptname + " copied over to " + server.hostname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-02 21:54:36 +02:00
|
|
|
//Get the current script
|
|
|
|
var sourceScript = null;
|
|
|
|
for (var i = 0; i < currServ.scripts.length; ++i) {
|
|
|
|
if (scriptname == currServ.scripts[i].filename) {
|
|
|
|
sourceScript = currServ.scripts[i];
|
|
|
|
break;
|
2017-05-30 02:18:48 +02:00
|
|
|
}
|
|
|
|
}
|
2017-06-02 21:54:36 +02:00
|
|
|
if (sourceScript == null) {
|
|
|
|
post("ERROR: scp() failed. No such script exists");
|
|
|
|
return;
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-06-02 21:54:36 +02:00
|
|
|
//Overwrite script if it exists
|
|
|
|
for (var i = 0; i < server.scripts.length; ++i) {
|
|
|
|
if (scriptname == server.scripts[i].filename) {
|
|
|
|
post("WARNING: " + scriptname + " already exists on " + server.hostname + " and will be overwritten");
|
|
|
|
var oldScript = server.scripts[i];
|
|
|
|
oldScript.code = sourceScript.code;
|
|
|
|
oldScript.ramUsage = sourceScript.ramUsage;
|
|
|
|
post(scriptname + " overwriten on " + server.hostname);
|
2017-05-30 02:18:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-06-02 21:54:36 +02:00
|
|
|
var newScript = new Script();
|
|
|
|
newScript.filename = scriptname;
|
|
|
|
newScript.code = sourceScript.code;
|
|
|
|
newScript.ramUsage = sourceScript.ramUsage;
|
|
|
|
newScript.server = ip;
|
|
|
|
server.scripts.push(newScript);
|
2017-07-25 03:06:40 +02:00
|
|
|
post(scriptname + " copied over to " + server.hostname);
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
2017-05-06 08:24:01 +02:00
|
|
|
case "sudov":
|
|
|
|
if (commandArray.length != 1) {
|
|
|
|
post("Incorrect number of arguments. Usage: sudov"); return;
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
if (Player.getCurrentServer().hasAdminRights) {
|
|
|
|
post("You have ROOT access to this machine");
|
|
|
|
} else {
|
|
|
|
post("You do NOT have root access to this machine");
|
|
|
|
}
|
|
|
|
break;
|
2016-12-02 22:57:20 +01:00
|
|
|
case "tail":
|
2017-06-17 04:53:57 +02:00
|
|
|
if (commandArray.length < 2) {
|
|
|
|
post("Incorrect number of arguments. Usage: tail [script] [arg1] [arg2]...");
|
2017-03-31 23:47:06 +02:00
|
|
|
} else {
|
2017-06-17 04:53:57 +02:00
|
|
|
var results = commandArray[1].split(" ");
|
|
|
|
var scriptName = results[0];
|
|
|
|
var args = [];
|
|
|
|
for (var i = 1; i < results.length; ++i) {
|
|
|
|
args.push(results[i]);
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-03-31 23:47:06 +02:00
|
|
|
//Can only tail script files
|
|
|
|
if (scriptName.endsWith(".script") == false) {
|
|
|
|
post("Error: tail can only be called on .script files (filename must end with .script)"); return;
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-03-31 23:47:06 +02:00
|
|
|
//Check that the script exists on this machine
|
2017-06-17 04:53:57 +02:00
|
|
|
var runningScript = findRunningScript(scriptName, args, s);
|
|
|
|
if (runningScript == null) {
|
|
|
|
post("Error: No such script exists");
|
|
|
|
return;
|
2017-03-31 23:47:06 +02:00
|
|
|
}
|
2017-06-17 04:53:57 +02:00
|
|
|
logBoxCreate(runningScript);
|
2017-03-31 23:47:06 +02:00
|
|
|
}
|
2016-12-02 22:57:20 +01:00
|
|
|
break;
|
2017-06-07 03:23:51 +02:00
|
|
|
case "theme":
|
2017-07-25 03:06:40 +02:00
|
|
|
//todo support theme saving
|
2017-06-07 03:23:51 +02:00
|
|
|
var args = commandArray[1] ? commandArray[1].split(" ") : [];
|
|
|
|
if(args.length != 1 && args.length != 3) {
|
2017-06-15 03:19:52 +02:00
|
|
|
post("Incorrect number of arguments.");
|
2017-06-17 09:21:42 +02:00
|
|
|
post("Usage: theme [default|muted|solarized] | #[background color hex] #[text color hex] #[highlight color hex]");
|
2017-06-07 03:23:51 +02:00
|
|
|
}else if(args.length == 1){
|
|
|
|
var themeName = args[0];
|
|
|
|
if(themeName == "default"){
|
|
|
|
document.body.style.setProperty('--my-highlight-color',"#ffffff");
|
|
|
|
document.body.style.setProperty('--my-font-color',"#66ff33");
|
|
|
|
document.body.style.setProperty('--my-background-color',"#000000");
|
|
|
|
}else if(themeName == "muted"){
|
|
|
|
document.body.style.setProperty('--my-highlight-color',"#ffffff");
|
|
|
|
document.body.style.setProperty('--my-font-color',"#66ff33");
|
|
|
|
document.body.style.setProperty('--my-background-color',"#252527");
|
|
|
|
}else if(themeName == "solarized"){
|
|
|
|
document.body.style.setProperty('--my-highlight-color',"#6c71c4");
|
|
|
|
document.body.style.setProperty('--my-font-color',"#839496");
|
|
|
|
document.body.style.setProperty('--my-background-color',"#002b36");
|
|
|
|
}else{
|
|
|
|
post("Theme not found");
|
2017-07-25 03:06:40 +02:00
|
|
|
}
|
2017-06-07 03:23:51 +02:00
|
|
|
}else{
|
|
|
|
inputBackgroundHex = args[0];
|
|
|
|
inputTextHex = args[1];
|
|
|
|
inputHighlightHex = args[2];
|
|
|
|
if(/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(inputBackgroundHex) &&
|
|
|
|
/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(inputTextHex) &&
|
|
|
|
/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(inputHighlightHex)){
|
|
|
|
document.body.style.setProperty('--my-highlight-color',inputHighlightHex);
|
|
|
|
document.body.style.setProperty('--my-font-color',inputTextHex);
|
|
|
|
document.body.style.setProperty('--my-background-color',inputBackgroundHex);
|
|
|
|
}else{
|
|
|
|
post("Invalid Hex Input for theme");
|
2017-07-25 03:06:40 +02:00
|
|
|
}
|
2017-06-07 03:23:51 +02:00
|
|
|
}
|
|
|
|
break;
|
2016-12-01 23:18:18 +01:00
|
|
|
case "top":
|
2017-06-16 20:17:40 +02:00
|
|
|
if(commandArray.length != 1) {
|
|
|
|
post("Incorrect usage of top command. Usage: top"); return;
|
|
|
|
}
|
2017-06-16 19:23:42 +02:00
|
|
|
|
2017-07-05 19:53:51 +02:00
|
|
|
post("Script Threads RAM Usage");
|
2017-06-16 19:23:42 +02:00
|
|
|
|
2017-06-16 20:17:40 +02:00
|
|
|
var currRunningScripts = Player.getCurrentServer().runningScripts;
|
|
|
|
//Iterate through scripts on current server
|
2017-07-04 17:42:47 +02:00
|
|
|
for(var i = 0; i < currRunningScripts.length; i++) {
|
|
|
|
var script = currRunningScripts[i];
|
2017-06-16 16:57:03 +02:00
|
|
|
|
2017-06-16 20:17:40 +02:00
|
|
|
//Calculate name padding
|
2017-07-05 19:53:51 +02:00
|
|
|
var numSpacesScript = 32 - script.filename.length; //26 -> width of name column
|
|
|
|
if (numSpacesScript < 0) {numSpacesScript = 0;}
|
2017-06-16 20:17:40 +02:00
|
|
|
var spacesScript = Array(numSpacesScript+1).join(" ");
|
2017-06-16 16:57:03 +02:00
|
|
|
|
2017-06-16 20:17:40 +02:00
|
|
|
//Calculate thread padding
|
|
|
|
var numSpacesThread = 16 - (script.threads + "").length; //16 -> width of thread column
|
|
|
|
var spacesThread = Array(numSpacesThread+1).join(" ");
|
2017-06-16 16:57:03 +02:00
|
|
|
|
2017-06-16 20:17:40 +02:00
|
|
|
//Calculate and transform RAM usage
|
2017-07-05 19:53:51 +02:00
|
|
|
ramUsage = formatNumber(script.scriptRef.ramUsage * script.threads, 2).toString() + "GB";
|
2017-06-16 16:57:03 +02:00
|
|
|
|
2017-06-16 20:17:40 +02:00
|
|
|
var entry = [script.filename, spacesScript, script.threads, spacesThread, ramUsage];
|
|
|
|
post(entry.join(""));
|
|
|
|
}
|
2016-11-17 23:25:40 +01:00
|
|
|
break;
|
2017-06-21 19:12:08 +02:00
|
|
|
case "unalias":
|
|
|
|
if (commandArray.length != 2) {
|
|
|
|
post('Incorrect usage of unalias name. Usage: unalias "[alias]"');
|
|
|
|
return;
|
|
|
|
} else if (!(commandArray[1].startsWith('"') && commandArray[1].endsWith('"'))) {
|
|
|
|
post('Incorrect usage of unalias name. Usage: unalias "[alias]"');
|
|
|
|
} else {
|
|
|
|
var alias = commandArray[1].slice(1, -1);
|
|
|
|
if (removeAlias(alias)) {
|
|
|
|
post("Removed alias " + alias);
|
|
|
|
} else {
|
|
|
|
post("No such alias exists");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2016-10-20 20:26:38 +02:00
|
|
|
default:
|
2016-10-24 08:34:04 +02:00
|
|
|
post("Command not found");
|
2016-10-20 20:26:38 +02:00
|
|
|
}
|
|
|
|
},
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-06-23 16:23:35 +02:00
|
|
|
connectToServer: function(ip) {
|
|
|
|
console.log("Connect to server called");
|
|
|
|
var serv = getServer(ip);
|
|
|
|
if (serv == null) {
|
|
|
|
post("Invalid server. Connection failed.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Player.getCurrentServer().isConnectedTo = false;
|
|
|
|
Player.currentServer = serv.ip;
|
|
|
|
Player.getCurrentServer().isConnectedTo = true;
|
|
|
|
post("Connected to " + serv.hostname);
|
|
|
|
if (Player.getCurrentServer().hostname == "darkweb") {
|
|
|
|
checkIfConnectedToDarkweb(); //Posts a 'help' message if connecting to dark web
|
|
|
|
}
|
2017-09-13 16:22:22 +02:00
|
|
|
Terminal.resetTerminalInput();
|
2017-06-23 16:23:35 +02:00
|
|
|
},
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
executeListCommand: function(commandArray) {
|
2017-08-15 22:22:46 +02:00
|
|
|
if (commandArray.length != 1 && commandArray.length != 2) {
|
|
|
|
post("Incorrect usage of ls command. Usage: ls [| grep pattern]"); return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//grep
|
|
|
|
var filter = null;
|
|
|
|
if (commandArray.length == 2) {
|
|
|
|
if (commandArray[1].startsWith("| grep ")) {
|
|
|
|
var pattern = commandArray[1].replace("| grep ", "");
|
|
|
|
if (pattern != " ") {
|
|
|
|
filter = pattern;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
post("Incorrect usage of ls command. Usage: ls [| grep pattern]"); return;
|
|
|
|
}
|
2017-05-06 08:24:01 +02:00
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
//Display all programs and scripts
|
2017-07-25 03:06:40 +02:00
|
|
|
var allFiles = [];
|
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
//Get all of the programs and scripts on the machine into one temporary array
|
2017-06-02 06:15:45 +02:00
|
|
|
var s = Player.getCurrentServer();
|
|
|
|
for (var i = 0; i < s.programs.length; i++) {
|
2017-08-15 22:22:46 +02:00
|
|
|
if (filter) {
|
|
|
|
if (s.programs[i].includes(filter)) {
|
|
|
|
allFiles.push(s.programs[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
allFiles.push(s.programs[i]);
|
|
|
|
}
|
2017-06-02 06:15:45 +02:00
|
|
|
}
|
|
|
|
for (var i = 0; i < s.scripts.length; i++) {
|
2017-08-15 22:22:46 +02:00
|
|
|
if (filter) {
|
|
|
|
if (s.scripts[i].filename.includes(filter)) {
|
|
|
|
allFiles.push(s.scripts[i].filename);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
allFiles.push(s.scripts[i].filename);
|
|
|
|
}
|
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
}
|
2017-06-02 06:15:45 +02:00
|
|
|
for (var i = 0; i < s.messages.length; i++) {
|
2017-08-15 22:22:46 +02:00
|
|
|
if (filter) {
|
2017-08-18 19:20:51 +02:00
|
|
|
if (s.messages[i] instanceof Message) {
|
|
|
|
if (s.messages[i].filename.includes(filter)) {
|
|
|
|
allFiles.push(s.messages[i].filename);
|
|
|
|
}
|
|
|
|
} else if (s.messages[i].includes(filter)) {
|
|
|
|
allFiles.push(s.messages[i]);
|
2017-08-15 22:22:46 +02:00
|
|
|
}
|
|
|
|
} else {
|
2017-08-18 19:20:51 +02:00
|
|
|
if (s.messages[i] instanceof Message) {
|
|
|
|
allFiles.push(s.messages[i].filename);
|
|
|
|
} else {
|
|
|
|
allFiles.push(s.messages[i]);
|
|
|
|
}
|
2017-08-15 22:22:46 +02:00
|
|
|
}
|
2017-05-06 08:24:01 +02:00
|
|
|
}
|
2017-10-12 04:00:22 +02:00
|
|
|
for (var i = 0; i < s.textFiles.length; ++i) {
|
|
|
|
if (filter) {
|
|
|
|
if (s.textFiles[i].fn.includes(filter)) {
|
|
|
|
allFiles.push(s.textFiles[i].fn);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
allFiles.push(s.textFiles[i].fn);
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
//Sort the files alphabetically then print each
|
|
|
|
allFiles.sort();
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
for (var i = 0; i < allFiles.length; i++) {
|
|
|
|
post(allFiles[i]);
|
|
|
|
}
|
|
|
|
},
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
executeScanCommand: function(commandArray) {
|
|
|
|
if (commandArray.length != 1) {
|
|
|
|
post("Incorrect usage of netstat/scan command. Usage: netstat/scan"); return;
|
|
|
|
}
|
|
|
|
//Displays available network connections using TCP
|
|
|
|
post("Hostname IP Root Access");
|
|
|
|
for (var i = 0; i < Player.getCurrentServer().serversOnNetwork.length; i++) {
|
|
|
|
//Add hostname
|
2017-05-08 18:00:34 +02:00
|
|
|
var entry = Player.getCurrentServer().getServerOnNetwork(i);
|
|
|
|
if (entry == null) {continue;}
|
|
|
|
entry = entry.hostname;
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
//Calculate padding and add IP
|
|
|
|
var numSpaces = 21 - entry.length;
|
|
|
|
var spaces = Array(numSpaces+1).join(" ");
|
|
|
|
entry += spaces;
|
|
|
|
entry += Player.getCurrentServer().getServerOnNetwork(i).ip;
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
//Calculate padding and add root access info
|
|
|
|
var hasRoot;
|
|
|
|
if (Player.getCurrentServer().getServerOnNetwork(i).hasAdminRights) {
|
|
|
|
hasRoot = 'Y';
|
|
|
|
} else {
|
|
|
|
hasRoot = 'N';
|
|
|
|
}
|
|
|
|
numSpaces = 21 - Player.getCurrentServer().getServerOnNetwork(i).ip.length;
|
|
|
|
spaces = Array(numSpaces+1).join(" ");
|
|
|
|
entry += spaces;
|
|
|
|
entry += hasRoot;
|
|
|
|
post(entry);
|
|
|
|
}
|
|
|
|
},
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-09-19 20:38:03 +02:00
|
|
|
executeScanAnalyzeCommand: function(depth=1, all=false) {
|
2017-06-01 03:57:49 +02:00
|
|
|
//We'll use the AllServersMap as a visited() array
|
2017-05-24 19:07:33 +02:00
|
|
|
//TODO Using array as stack for now, can make more efficient
|
2017-05-24 23:35:24 +02:00
|
|
|
post("~~~~~~~~~~ Beginning scan-analyze ~~~~~~~~~~");
|
|
|
|
post(" ");
|
2017-06-01 03:57:49 +02:00
|
|
|
var visited = new AllServersMap();
|
2017-09-19 20:38:03 +02:00
|
|
|
|
2017-05-24 19:07:33 +02:00
|
|
|
var stack = [];
|
|
|
|
var depthQueue = [0];
|
|
|
|
var currServ = Player.getCurrentServer();
|
|
|
|
stack.push(currServ);
|
|
|
|
while(stack.length != 0) {
|
|
|
|
var s = stack.pop();
|
|
|
|
var d = depthQueue.pop();
|
2017-09-19 20:38:03 +02:00
|
|
|
if (!all && s.purchasedByPlayer && s.hostname != "home") {
|
|
|
|
continue; //Purchased server
|
|
|
|
} else if (visited[s.ip] || d > depth) {
|
|
|
|
continue; //Already visited or out-of-depth
|
2017-05-24 19:07:33 +02:00
|
|
|
} else {
|
|
|
|
visited[s.ip] = 1;
|
|
|
|
}
|
|
|
|
for (var i = s.serversOnNetwork.length-1; i >= 0; --i) {
|
|
|
|
stack.push(s.getServerOnNetwork(i));
|
|
|
|
depthQueue.push(d+1);
|
|
|
|
}
|
|
|
|
if (d == 0) {continue;} //Don't print current server
|
2017-05-24 23:35:24 +02:00
|
|
|
var titleDashes = Array((d-1) * 4 + 1).join("-");
|
2017-06-23 16:23:35 +02:00
|
|
|
if (Player.hasProgram(Programs.AutoLink)) {
|
|
|
|
post("<strong>" + titleDashes + "> <a class='scan-analyze-link'>" + s.hostname + "</a></strong>", false);
|
|
|
|
} else {
|
|
|
|
post("<strong>" + titleDashes + ">" + s.hostname + "</strong>");
|
|
|
|
}
|
|
|
|
|
2017-05-24 23:35:24 +02:00
|
|
|
var dashes = titleDashes + "--";
|
|
|
|
//var dashes = Array(d * 2 + 1).join("-");
|
|
|
|
var c = "NO";
|
|
|
|
if (s.hasAdminRights) {c = "YES";}
|
|
|
|
post(dashes + "Root Access: " + c + ", Required hacking skill: " + s.requiredHackingSkill);
|
|
|
|
post(dashes + "Number of open ports required to NUKE: " + s.numOpenPortsRequired);
|
|
|
|
post(dashes + "RAM: " + s.maxRam);
|
2017-05-23 19:36:35 +02:00
|
|
|
post(" ");
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-06-23 16:23:35 +02:00
|
|
|
var links = document.getElementsByClassName("scan-analyze-link");
|
|
|
|
for (var i = 0; i < links.length; ++i) {
|
|
|
|
(function() {
|
|
|
|
var hostname = links[i].innerHTML.toString();
|
|
|
|
links[i].onclick = function() {
|
2017-09-15 16:06:59 +02:00
|
|
|
if (Terminal.analyzeFlag || Terminal.hackFlag) {return;}
|
2017-06-23 16:23:35 +02:00
|
|
|
Terminal.connectToServer(hostname);
|
|
|
|
}
|
|
|
|
}());//Immediate invocation
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-23 19:36:35 +02:00
|
|
|
},
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-05-06 08:24:01 +02:00
|
|
|
executeFreeCommand: function(commandArray) {
|
|
|
|
if (commandArray.length != 1) {
|
|
|
|
post("Incorrect usage of free command. Usage: free"); return;
|
|
|
|
}
|
2017-05-10 23:10:06 +02:00
|
|
|
post("Total: " + formatNumber(Player.getCurrentServer().maxRam, 2) + " GB");
|
|
|
|
post("Used: " + formatNumber(Player.getCurrentServer().ramUsed, 2) + " GB");
|
|
|
|
post("Available: " + formatNumber(Player.getCurrentServer().maxRam - Player.getCurrentServer().ramUsed, 2) + " GB");
|
2017-05-06 08:24:01 +02:00
|
|
|
},
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-10-27 20:26:00 +02:00
|
|
|
//First called when the "run [program]" command is called. Checks to see if you
|
|
|
|
//have the executable and, if you do, calls the executeProgram() function
|
2016-10-20 20:26:38 +02:00
|
|
|
runProgram: function(programName) {
|
2016-10-27 20:26:00 +02:00
|
|
|
//Check if you have the program on your computer. If you do, execute it, otherwise
|
|
|
|
//display an error message
|
2017-06-23 16:23:35 +02:00
|
|
|
var splitArgs = programName.split(" ");
|
|
|
|
var name = " ";
|
|
|
|
if (splitArgs.length > 1) {
|
|
|
|
name = splitArgs[0];
|
|
|
|
} else {
|
|
|
|
name = programName;
|
|
|
|
}
|
|
|
|
if (Player.hasProgram(name)) {
|
|
|
|
Terminal.executeProgram(programName);
|
|
|
|
return;
|
|
|
|
}
|
2017-02-16 19:52:11 +01:00
|
|
|
post("ERROR: No such executable on home computer (Only programs that exist on your home computer can be run)");
|
2016-10-27 20:26:00 +02:00
|
|
|
},
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-10-27 20:26:00 +02:00
|
|
|
//Contains the implementations of all possible programs
|
|
|
|
executeProgram: function(programName) {
|
2017-04-19 23:40:26 +02:00
|
|
|
var s = Player.getCurrentServer();
|
2017-06-23 16:23:35 +02:00
|
|
|
var splitArgs = programName.split(" ");
|
|
|
|
if (splitArgs.length > 1) {
|
|
|
|
programName = splitArgs[0];
|
|
|
|
}
|
2016-10-24 23:16:51 +02:00
|
|
|
switch (programName) {
|
2017-04-11 22:42:06 +02:00
|
|
|
case Programs.NukeProgram:
|
2017-04-19 23:39:25 +02:00
|
|
|
if (s.hasAdminRights) {
|
2017-04-05 23:09:37 +02:00
|
|
|
post("You already have root access to this computer. There is no reason to run NUKE.exe");
|
2016-10-24 23:16:51 +02:00
|
|
|
} else {
|
2017-04-19 23:39:25 +02:00
|
|
|
if (s.openPortCount >= Player.getCurrentServer().numOpenPortsRequired) {
|
|
|
|
s.hasAdminRights = true;
|
2017-04-05 23:09:37 +02:00
|
|
|
post("NUKE successful! Gained root access to " + Player.getCurrentServer().hostname);
|
2016-10-27 20:26:00 +02:00
|
|
|
//TODO Make this take time rather than be instant
|
|
|
|
} else {
|
2017-04-05 23:09:37 +02:00
|
|
|
post("NUKE unsuccessful. Not enough ports have been opened");
|
2016-10-27 20:26:00 +02:00
|
|
|
}
|
2016-10-24 23:16:51 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-04-19 23:39:25 +02:00
|
|
|
case Programs.BruteSSHProgram:
|
2017-04-22 00:22:25 +02:00
|
|
|
if (s.sshPortOpen) {
|
2017-04-19 23:39:25 +02:00
|
|
|
post("SSH Port (22) is already open!");
|
|
|
|
} else {
|
|
|
|
s.sshPortOpen = true;
|
|
|
|
post("Opened SSH Port(22)!")
|
|
|
|
++s.openPortCount;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Programs.FTPCrackProgram:
|
2017-04-22 00:22:25 +02:00
|
|
|
if (s.ftpPortOpen) {
|
2017-04-19 23:39:25 +02:00
|
|
|
post("FTP Port (21) is already open!");
|
|
|
|
} else {
|
|
|
|
s.ftpPortOpen = true;
|
|
|
|
post("Opened FTP Port (21)!");
|
|
|
|
++s.openPortCount;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Programs.RelaySMTPProgram:
|
2017-04-22 00:22:25 +02:00
|
|
|
if (s.smtpPortOpen) {
|
2017-04-19 23:39:25 +02:00
|
|
|
post("SMTP Port (25) is already open!");
|
|
|
|
} else {
|
|
|
|
s.smtpPortOpen = true;
|
|
|
|
post("Opened SMTP Port (25)!");
|
|
|
|
++s.openPortCount;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Programs.HTTPWormProgram:
|
2017-04-22 00:22:25 +02:00
|
|
|
if (s.httpPortOpen) {
|
2017-04-19 23:39:25 +02:00
|
|
|
post("HTTP Port (80) is already open!");
|
|
|
|
} else {
|
|
|
|
s.httpPortOpen = true;
|
|
|
|
post("Opened HTTP Port (80)!");
|
|
|
|
++s.openPortCount;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Programs.SQLInjectProgram:
|
2017-04-22 00:22:25 +02:00
|
|
|
if (s.sqlPortOpen) {
|
2017-04-19 23:39:25 +02:00
|
|
|
post("SQL Port (1433) is already open!");
|
|
|
|
} else {
|
|
|
|
s.sqlPortOpen = true;
|
|
|
|
post("Opened SQL Port (1433)!");
|
|
|
|
++s.openPortCount;
|
|
|
|
}
|
2017-06-23 16:23:35 +02:00
|
|
|
break;
|
|
|
|
case Programs.ServerProfiler:
|
|
|
|
if (splitArgs.length != 2) {
|
|
|
|
post("Must pass a server hostname or IP as an argument for ServerProfiler.exe");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var serv = getServer(splitArgs[1]);
|
|
|
|
if (serv == null) {
|
|
|
|
post("Invalid server IP/hostname");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
post(serv.hostname + ":");
|
|
|
|
post("Server base security level: " + serv.baseDifficulty);
|
|
|
|
post("Server current security level: " + serv.hackDifficulty);
|
|
|
|
post("Server growth rate: " + serv.serverGrowth);
|
|
|
|
post("Netscript hack() execution time: " + formatNumber(scriptCalculateHackingTime(serv), 1) + "s");
|
|
|
|
post("Netscript grow() execution time: " + formatNumber(scriptCalculateGrowTime(serv)/1000, 1) + "s");
|
|
|
|
post("Netscript weaken() execution time: " + formatNumber(scriptCalculateWeakenTime(serv)/1000, 1) + "s");
|
2017-07-04 21:34:17 +02:00
|
|
|
break;
|
|
|
|
case Programs.AutoLink:
|
|
|
|
post("This executable cannot be run.");
|
|
|
|
post("AutoLink.exe lets you automatically connect to other servers when using 'scan-analyze'.");
|
|
|
|
post("When using scan-analyze, click on a server's hostname to connect to it.");
|
|
|
|
break;
|
|
|
|
case Programs.DeepscanV1:
|
|
|
|
post("This executable cannot be run.");
|
|
|
|
post("DeepscanV1.exe lets you run 'scan-analyze' with a depth up to 5.");
|
|
|
|
break;
|
|
|
|
case Programs.DeepscanV2:
|
|
|
|
post("This executable cannot be run.");
|
|
|
|
post("DeepscanV2.exe lets you run 'scan-analyze' with a depth up to 10.");
|
2017-07-22 00:54:55 +02:00
|
|
|
break;
|
|
|
|
case Programs.Flight:
|
|
|
|
post("Augmentations: " + Player.augmentations.length + " / 30");
|
2017-07-29 18:25:40 +02:00
|
|
|
post("Money: $" + formatNumber(Player.money.toNumber(), 2) + " / $" + formatNumber(100000000000, 2));
|
2017-07-22 00:54:55 +02:00
|
|
|
post("One path below must be fulfilled...");
|
|
|
|
post("----------HACKING PATH----------");
|
|
|
|
post("Hacking skill: " + Player.hacking_skill + " / 2500");
|
|
|
|
post("----------COMBAT PATH----------");
|
|
|
|
post("Strength: " + Player.strength + " / 1500");
|
|
|
|
post("Defense: " + Player.defense + " / 1500");
|
|
|
|
post("Dexterity: " + Player.dexterity + " / 1500");
|
|
|
|
post("Agility: " + Player.agility + " / 1500");
|
2017-04-19 23:39:25 +02:00
|
|
|
break;
|
2016-10-24 23:16:51 +02:00
|
|
|
default:
|
2017-06-23 16:23:35 +02:00
|
|
|
post("Invalid executable. Cannot be run");
|
2016-10-24 23:16:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
},
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-10-24 23:16:51 +02:00
|
|
|
runScript: function(scriptName) {
|
2016-12-14 21:29:40 +01:00
|
|
|
var server = Player.getCurrentServer();
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-06-11 03:46:02 +02:00
|
|
|
var numThreads = 1;
|
2017-06-17 04:53:57 +02:00
|
|
|
var args = [];
|
|
|
|
var results = scriptName.split(" ");
|
|
|
|
if (results.length <= 0) {
|
|
|
|
post("This is a bug. Please contact developer");
|
2017-06-11 03:46:02 +02:00
|
|
|
}
|
2017-06-17 04:53:57 +02:00
|
|
|
scriptName = results[0];
|
|
|
|
if (results.length > 1) {
|
|
|
|
if (results.length >= 3 && results[1] == "-t") {
|
|
|
|
numThreads = Math.round(Number(results[2]));
|
|
|
|
if (isNaN(numThreads) || numThreads < 1) {
|
|
|
|
post("Invalid number of threads specified. Number of threads must be greater than 0");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (var i = 3; i < results.length; ++i) {
|
|
|
|
var arg = results[i];
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-06-17 04:53:57 +02:00
|
|
|
//Forced string
|
|
|
|
if ((arg.startsWith("'") && arg.endsWith("'")) ||
|
|
|
|
(arg.startsWith('"') && arg.endsWith('"'))) {
|
|
|
|
args.push(arg.slice(1, -1));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//Number
|
|
|
|
var tempNum = Number(arg);
|
|
|
|
if (!isNaN(tempNum)) {
|
|
|
|
args.push(tempNum);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//Otherwise string
|
|
|
|
args.push(arg);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (var i = 1; i < results.length; ++i) {
|
|
|
|
var arg = results[i];
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-06-17 04:53:57 +02:00
|
|
|
//Forced string
|
|
|
|
if ((arg.startsWith("'") && arg.endsWith("'")) ||
|
|
|
|
(arg.startsWith('"') && arg.endsWith('"'))) {
|
|
|
|
args.push(arg.slice(1, -1));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//Number
|
|
|
|
var tempNum = Number(arg);
|
|
|
|
if (!isNaN(tempNum)) {
|
|
|
|
args.push(tempNum);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//Otherwise string
|
|
|
|
args.push(arg);
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-11 22:28:20 +02:00
|
|
|
//Check if this script is already running
|
2017-06-17 04:53:57 +02:00
|
|
|
if (findRunningScript(scriptName, args, server) != null) {
|
|
|
|
post("ERROR: This script is already running. Cannot run multiple instances");
|
|
|
|
return;
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-11-28 23:02:06 +01:00
|
|
|
//Check if the script exists and if it does run it
|
2016-12-14 21:29:40 +01:00
|
|
|
for (var i = 0; i < server.scripts.length; i++) {
|
|
|
|
if (server.scripts[i].filename == scriptName) {
|
|
|
|
//Check for admin rights and that there is enough RAM availble to run
|
2017-06-11 03:46:02 +02:00
|
|
|
var script = server.scripts[i];
|
2017-06-20 18:11:33 +02:00
|
|
|
var ramUsage = script.ramUsage * numThreads * Math.pow(CONSTANTS.MultithreadingRAMCost, numThreads-1);
|
2016-12-14 21:29:40 +01:00
|
|
|
var ramAvailable = server.maxRam - server.ramUsed;
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-12-14 21:29:40 +01:00
|
|
|
if (server.hasAdminRights == false) {
|
2016-11-28 23:02:06 +01:00
|
|
|
post("Need root access to run script");
|
2016-12-14 00:52:32 +01:00
|
|
|
return;
|
2016-12-14 21:29:40 +01:00
|
|
|
} else if (ramUsage > ramAvailable){
|
2017-06-11 03:46:02 +02:00
|
|
|
post("This machine does not have enough RAM to run this script with " +
|
2017-06-17 04:53:57 +02:00
|
|
|
numThreads + " threads. Script requires " + ramUsage + "GB of RAM");
|
2016-12-14 21:29:40 +01:00
|
|
|
return;
|
2017-06-17 04:53:57 +02:00
|
|
|
} else {
|
2016-12-14 21:29:40 +01:00
|
|
|
//Able to run script
|
2017-06-17 04:53:57 +02:00
|
|
|
post("Running script with " + numThreads + " thread(s) and args: " + printArray(args) + ".");
|
|
|
|
post("May take a few seconds to start up the process...");
|
|
|
|
var runningScriptObj = new RunningScript(script, args);
|
|
|
|
runningScriptObj.threads = numThreads;
|
|
|
|
server.runningScripts.push(runningScriptObj);
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2017-06-17 04:53:57 +02:00
|
|
|
addWorkerScript(runningScriptObj, server);
|
2016-11-29 23:56:05 +01:00
|
|
|
return;
|
2016-11-28 23:02:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
|
2016-11-28 23:02:06 +01:00
|
|
|
post("ERROR: No such script");
|
2016-10-20 20:26:38 +02:00
|
|
|
}
|
2017-07-25 03:06:40 +02:00
|
|
|
};
|
2017-08-30 19:44:29 +02:00
|
|
|
|
|
|
|
export {postNetburnerText, post, Terminal};
|