2016-10-17 10:24:39 +02:00
|
|
|
//Terminal
|
2016-12-21 19:36:42 +01:00
|
|
|
|
|
|
|
/* Write text to terminal */
|
2016-10-17 10:24:39 +02:00
|
|
|
var post = function(input) {
|
2016-11-01 06:30:59 +01:00
|
|
|
$("#terminal-input").before('<tr class="posted"><td style="color: #66ff33;">' + input.replace( / /g, " " ) + '</td></tr>');
|
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
|
|
|
|
var hackProgressBarPost = function(input) {
|
|
|
|
$("#terminal-input").before('<tr class="posted"><td id="hack-progress-bar" style="color: #66ff33;">' + input + '</td></tr>');
|
2016-12-21 19:36:42 +01:00
|
|
|
updateTerminalScroll();
|
2016-10-27 05:34:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var hackProgressPost = function(input) {
|
|
|
|
$("#terminal-input").before('<tr class="posted"><td id="hack-progress" style="color: #66ff33;">' + input + '</td></tr>');
|
2016-12-21 19:36:42 +01:00
|
|
|
updateTerminalScroll();
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateTerminalScroll() {
|
|
|
|
var element = document.getElementById("terminal-container");
|
|
|
|
element.scrollTop = element.scrollHeight;
|
2016-10-27 05:34:18 +02:00
|
|
|
}
|
|
|
|
|
2016-10-20 23:11:01 +02:00
|
|
|
var postNetburnerText = function() {
|
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
|
2016-10-17 10:24:39 +02:00
|
|
|
$(document).keyup(function(event) {
|
2016-11-24 23:30:33 +01:00
|
|
|
//Terminal
|
|
|
|
if (Engine.currentPage == Engine.Page.Terminal) {
|
2016-12-21 17:33:00 +01:00
|
|
|
//Enter
|
2016-11-24 23:30:33 +01:00
|
|
|
if (event.keyCode == 13) {
|
|
|
|
var command = $('input[class=terminal-input]').val();
|
|
|
|
if (command.length > 0) {
|
|
|
|
post("> " + command);
|
|
|
|
|
|
|
|
//TODO Do i have to switch the order of these two?
|
|
|
|
Terminal.executeCommand(command);
|
|
|
|
$('input[class=terminal-input]').val("");
|
|
|
|
}
|
2016-10-17 10:24:39 +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);
|
|
|
|
}
|
2016-10-17 10:24:39 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-11-24 23:30:33 +01:00
|
|
|
//Keep terminal in focus
|
2016-12-19 21:59:13 +01:00
|
|
|
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 {
|
|
|
|
$('.terminal-input').focus();
|
|
|
|
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
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2016-10-20 20:26:38 +02:00
|
|
|
var Terminal = {
|
2016-11-01 06:30:59 +01:00
|
|
|
//Flags to determine whether the player is currently running a hack or an analyze
|
|
|
|
hackFlag: false,
|
|
|
|
analyzeFlag: false,
|
|
|
|
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
//Complete the hack/analyze command
|
2016-12-21 17:33:00 +01:00
|
|
|
finishHack: function(cancelled = false) {
|
|
|
|
if (cancelled == false) {
|
|
|
|
console.log("Hack done. Determining success/failure of hack. Re-enabling terminal and changing the id of the hack progress bar");
|
2016-12-14 21:29:40 +01: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();
|
|
|
|
var expGainedOnFailure = Math.round(expGainedOnSuccess / 4);
|
|
|
|
if (rand < hackChance) { //Success!
|
|
|
|
var moneyGained = Player.calculatePercentMoneyHacked();
|
|
|
|
moneyGained = Math.floor(Player.getCurrentServer().moneyAvailable * moneyGained);
|
|
|
|
|
|
|
|
//Safety check
|
|
|
|
if (moneyGained <= 0) {moneyGained = 0;}
|
|
|
|
|
|
|
|
Player.getCurrentServer().moneyAvailable -= moneyGained;
|
|
|
|
Player.gainMoney(moneyGained);
|
|
|
|
|
2017-04-18 06:32:17 +02:00
|
|
|
Player.gainHackingExp(expGainedOnSuccess)
|
2016-12-21 17:33:00 +01:00
|
|
|
|
|
|
|
post("Hack successful! Gained $" + moneyGained + " and " + expGainedOnSuccess + " hacking EXP");
|
|
|
|
} 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)
|
2016-12-21 17:33:00 +01:00
|
|
|
post("Failed to hack " + Player.getCurrentServer().hostname + ". Gained " + expGainedOnFailure + " hacking EXP");
|
|
|
|
}
|
|
|
|
}
|
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");
|
|
|
|
document.getElementById("terminal-input-td").innerHTML = '$ <input type="text" class="terminal-input"/>';
|
|
|
|
$('input[class=terminal-input]').prop('disabled', false);
|
|
|
|
|
|
|
|
Terminal.hackFlag = false;
|
2016-10-27 20:26:00 +02:00
|
|
|
},
|
2016-11-01 06:30:59 +01:00
|
|
|
|
2016-12-21 17:33:00 +01:00
|
|
|
finishAnalyze: function(cancelled = false) {
|
|
|
|
if (cancelled == false) {
|
|
|
|
post(Player.getCurrentServer().hostname + ": ");
|
|
|
|
post("Required hacking skill: " + Player.getCurrentServer().requiredHackingSkill);
|
|
|
|
//TODO Make these actual estimates by adding a random offset to result?
|
|
|
|
//TODO Change the text to sound better
|
|
|
|
post("Estimated chance to hack: " + Math.round(Player.calculateHackingChance() * 100) + "%");
|
|
|
|
post("Estimated time to hack: " + Math.round(Player.calculateHackingTime()) + " seconds");
|
|
|
|
post("Estimed total money available on server: $" + Player.getCurrentServer().moneyAvailable);
|
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")
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Player.getCurrentServer().ftpPortOpen) {
|
|
|
|
post("FTP port: Open")
|
|
|
|
} else {
|
|
|
|
post("FTP port: Closed")
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Player.getCurrentServer().smtpPortOpen) {
|
|
|
|
post("SMTP port: Open")
|
|
|
|
} else {
|
|
|
|
post("SMTP port: Closed")
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Player.getCurrentServer().httpPortOpen) {
|
|
|
|
post("HTTP port: Open")
|
|
|
|
} else {
|
|
|
|
post("HTTP port: Closed")
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Player.getCurrentServer().sqlPortOpen) {
|
|
|
|
post("SQL port: Open")
|
|
|
|
} else {
|
|
|
|
post("SQL port: Closed")
|
|
|
|
}
|
|
|
|
}
|
2016-11-01 06:30:59 +01:00
|
|
|
Terminal.analyzeFlag = false;
|
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");
|
|
|
|
document.getElementById("terminal-input-td").innerHTML = '$ <input type="text" class="terminal-input"/>';
|
|
|
|
$('input[class=terminal-input]').prop('disabled', false);
|
2016-11-01 06:30:59 +01:00
|
|
|
},
|
2016-10-27 20:26:00 +02:00
|
|
|
|
2016-10-20 20:26:38 +02:00
|
|
|
executeCommand: function(command) {
|
2016-10-24 09:18:01 +02:00
|
|
|
var commandArray = command.split(" ");
|
2016-10-20 20:26:38 +02:00
|
|
|
|
|
|
|
if (commandArray.length == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (commandArray[0]) {
|
|
|
|
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();
|
|
|
|
|
|
|
|
//Disable terminal
|
|
|
|
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 "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();
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
|
|
|
case "connect":
|
2016-10-24 08:34:04 +02:00
|
|
|
case "telnet":
|
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) {
|
2016-10-24 23:16:51 +02:00
|
|
|
post("Incorrect usage of connect/telnet command. Usage: connect/telnet [ip/hostname]");
|
2016-10-24 08:34:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var ip = commandArray[1];
|
|
|
|
|
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) {
|
|
|
|
Player.getCurrentServer().isConnectedTo = false;
|
|
|
|
Player.currentServer = Player.getCurrentServer().getServerOnNetwork(i).ip;
|
2017-02-03 23:05:59 +01:00
|
|
|
Player.getCurrentServer().isConnectedTo = true;
|
2016-10-24 09:18:01 +02:00
|
|
|
post("Connected to " + ip);
|
2016-10-24 08:34:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-24 09:18:01 +02:00
|
|
|
post("Host not found");
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
2016-12-01 23:18:18 +01:00
|
|
|
case "free":
|
2016-11-24 23:30:33 +01:00
|
|
|
if (commandArray.length != 1) {
|
2016-12-05 23:31:46 +01:00
|
|
|
post("Incorrect usage of free command. Usage: free"); return;
|
2016-11-24 23:30:33 +01:00
|
|
|
}
|
2016-12-01 23:18:18 +01:00
|
|
|
post("Total: " + Player.getCurrentServer().maxRam.toString() + " GB");
|
|
|
|
post("Used: " + Player.getCurrentServer().ramUsed.toString() + " GB");
|
|
|
|
post("Available: " + (Player.getCurrentServer().maxRam - Player.getCurrentServer().ramUsed).toString() + " GB");
|
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();
|
2016-10-27 20:26:00 +02:00
|
|
|
|
|
|
|
//Disable terminal
|
|
|
|
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":
|
2016-12-15 18:51:23 +01:00
|
|
|
if (commandArray.length != 1) {
|
|
|
|
post("Incorrect usage of help command. Usage: help"); return;
|
|
|
|
}
|
|
|
|
|
|
|
|
post(CONSTANTS.HelpText);
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
2016-12-14 00:52:32 +01:00
|
|
|
case "home":
|
|
|
|
//TODO return to home computer
|
|
|
|
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":
|
2016-12-06 19:09:23 +01:00
|
|
|
if (commandArray.length != 2) {
|
|
|
|
post("Incorrect usage of kill command. Usage: kill [scriptname]"); return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var scriptName = commandArray[1];
|
|
|
|
for (var i = 0; i < Player.getCurrentServer().runningScripts.length; i++) {
|
2016-12-14 00:52:32 +01:00
|
|
|
if (Player.getCurrentServer().runningScripts[i] == scriptName) {
|
2016-12-06 19:09:23 +01:00
|
|
|
killWorkerScript(scriptName, Player.getCurrentServer().ip);
|
2017-04-27 22:02:58 +02:00
|
|
|
post("Killing " + scriptName + ". May take up to a few minutes for the scripts to die...");
|
2016-12-14 00:52:32 +01:00
|
|
|
return;
|
2016-12-06 19:09:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
post("No such script is running. Nothing to kill");
|
2016-10-20 20:26:38 +02:00
|
|
|
break;
|
|
|
|
case "ls":
|
2016-11-24 23:30:33 +01:00
|
|
|
if (commandArray.length != 1) {
|
|
|
|
post("Incorrect usage of ls command. Usage: ls"); return;
|
|
|
|
}
|
|
|
|
|
2016-10-27 20:26:00 +02:00
|
|
|
//Display all programs and scripts
|
|
|
|
var allFiles = [];
|
|
|
|
|
|
|
|
//Get all of the programs and scripts on the machine into one temporary array
|
2016-12-01 23:18:18 +01:00
|
|
|
for (var i = 0; i < Player.getCurrentServer().programs.length; i++) {
|
|
|
|
allFiles.push(Player.getCurrentServer().programs[i]);
|
2016-10-27 20:26:00 +02:00
|
|
|
}
|
2016-12-01 23:18:18 +01:00
|
|
|
for (var i = 0; i < Player.getCurrentServer().scripts.length; i++) {
|
|
|
|
allFiles.push(Player.getCurrentServer().scripts[i].filename);
|
2016-10-27 20:26:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Sort the files alphabetically then print each
|
|
|
|
allFiles.sort();
|
|
|
|
|
|
|
|
for (var i = 0; i < allFiles.length; i++) {
|
|
|
|
post(allFiles[i]);
|
|
|
|
}
|
2016-10-20 20:26:38 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
var filename = commandArray[1];
|
|
|
|
|
|
|
|
//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
|
|
|
}
|
|
|
|
|
|
|
|
//Script name is the filename without the .script at the end
|
|
|
|
var scriptname = filename.substr(0, filename.indexOf(".script"));
|
|
|
|
|
|
|
|
//Cannot edit scripts that are currently running
|
2016-12-01 23:18:18 +01:00
|
|
|
for (var i = 0; i < Player.getCurrentServer().runningScripts.length; i++) {
|
2017-04-20 10:29:07 +02:00
|
|
|
if (filename == Player.getCurrentServer().runningScripts[i]) {
|
2016-11-24 23:30:33 +01:00
|
|
|
post("Cannot open/edit scripts that are currently running!"); return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//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 "netstat":
|
|
|
|
case "scan":
|
2016-10-24 08:34:04 +02:00
|
|
|
if (commandArray.length != 1) {
|
2016-11-24 23:30:33 +01:00
|
|
|
post("Incorrect usage of netstat/scan command. Usage: netstat/scan"); return;
|
2016-10-24 08:34:04 +02:00
|
|
|
}
|
|
|
|
//Displays available network connections using TCP
|
2016-11-01 06:30:59 +01:00
|
|
|
post("Hostname IP Root Access");
|
2016-12-01 23:18:18 +01:00
|
|
|
for (var i = 0; i < Player.getCurrentServer().serversOnNetwork.length; i++) {
|
2016-11-01 06:30:59 +01:00
|
|
|
//Add hostname
|
2016-12-01 23:18:18 +01:00
|
|
|
var entry = Player.getCurrentServer().getServerOnNetwork(i).hostname;
|
2016-11-01 06:30:59 +01:00
|
|
|
|
|
|
|
//Calculate padding and add IP
|
|
|
|
var numSpaces = 21 - entry.length;
|
|
|
|
var spaces = Array(numSpaces+1).join(" ");
|
|
|
|
entry += spaces;
|
2016-12-01 23:18:18 +01:00
|
|
|
entry += Player.getCurrentServer().getServerOnNetwork(i).ip;
|
2016-11-01 06:30:59 +01:00
|
|
|
|
|
|
|
//Calculate padding and add root access info
|
|
|
|
var hasRoot;
|
2016-12-01 23:18:18 +01:00
|
|
|
if (Player.getCurrentServer().getServerOnNetwork(i).hasAdminRights) {
|
2016-11-01 06:30:59 +01:00
|
|
|
hasRoot = 'Y';
|
|
|
|
} else {
|
|
|
|
hasRoot = 'N';
|
|
|
|
}
|
2016-12-01 23:18:18 +01:00
|
|
|
numSpaces = 21 - Player.getCurrentServer().getServerOnNetwork(i).ip.length;
|
2016-11-01 06:30:59 +01:00
|
|
|
spaces = Array(numSpaces+1).join(" ");
|
|
|
|
entry += spaces;
|
|
|
|
entry += hasRoot;
|
|
|
|
post(entry);
|
2016-10-24 08:34:04 +02:00
|
|
|
}
|
2016-11-24 23:30:33 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
for (var i = 0; i < Player.getCurrentServer().runningScripts.length; i++) {
|
|
|
|
post(Player.getCurrentServer().runningScripts[i]);
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check programs
|
|
|
|
var delTarget = commandArray[1];
|
|
|
|
var s = Player.getCurrentServer();
|
|
|
|
for (var i = 0; i < s.programs.length; ++i) {
|
|
|
|
if (s.programs[i] == delTarget) {
|
|
|
|
s.programs.splice(i, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check scripts
|
|
|
|
for (var i = 0; i < s.scripts.length; ++i) {
|
|
|
|
if (s.scripts[i].filename == delTarget) {
|
|
|
|
//Check that the script isnt currently running
|
|
|
|
if (s.runningScripts.indexOf(delTarget) > -1) {
|
|
|
|
post("Cannot delete a script that is currently running!");
|
|
|
|
} else {
|
|
|
|
s.scripts.splice(i, 1);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
post("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) {
|
|
|
|
post("Incorrect number of arguments. Usage: run [program/script]");
|
2016-10-24 23:16:51 +02:00
|
|
|
} else {
|
|
|
|
var executableName = commandArray[1];
|
|
|
|
//Check if its a script or just a program/executable
|
|
|
|
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;
|
|
|
|
case "scp":
|
|
|
|
//TODO
|
|
|
|
break;
|
2016-12-02 22:57:20 +01:00
|
|
|
case "tail":
|
2017-04-13 19:33:34 +02:00
|
|
|
if (commandArray.length != 2) {
|
2017-03-31 23:47:06 +02:00
|
|
|
post("Incorrect number of arguments. Usage: tail [script]");
|
|
|
|
} else {
|
2017-04-13 19:33:34 +02:00
|
|
|
var scriptName = commandArray[1];
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check that the script exists on this machine
|
|
|
|
var currScripts = Player.getCurrentServer().scripts;
|
|
|
|
for (var i = 0; i < currScripts.length; ++i) {
|
2017-04-13 19:33:34 +02:00
|
|
|
if (scriptName == currScripts[i].filename) {
|
2017-03-31 23:47:06 +02:00
|
|
|
currScripts[i].displayLog();
|
2017-04-13 19:33:34 +02:00
|
|
|
return;
|
2017-03-31 23:47:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
post("Error: No such script exists");
|
|
|
|
}
|
2016-12-02 22:57:20 +01:00
|
|
|
break;
|
2016-12-01 23:18:18 +01:00
|
|
|
case "top":
|
|
|
|
//TODO List each's script RAM usage
|
2016-11-17 23:25:40 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
},
|
2016-10-17 23:23:23 +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
|
2016-12-01 23:18:18 +01:00
|
|
|
for (var i = 0; i < Player.getHomeComputer().programs.length; i++) {
|
|
|
|
if (Player.getHomeComputer().programs[i] == programName) {
|
2016-10-27 20:26:00 +02:00
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
//Contains the implementations of all possible programs
|
|
|
|
executeProgram: function(programName) {
|
2017-04-19 23:40:26 +02:00
|
|
|
var s = Player.getCurrentServer();
|
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;
|
|
|
|
}
|
|
|
|
break;
|
2016-10-24 23:16:51 +02:00
|
|
|
default:
|
|
|
|
post("Executable not found");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
},
|
2016-10-20 20:26:38 +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();
|
2016-11-28 23:02:06 +01:00
|
|
|
//Check if this script is already running
|
2016-12-14 21:29:40 +01:00
|
|
|
for (var i = 0; i < server.runningScripts.length; i++) {
|
|
|
|
if (server.runningScripts[i] == scriptName) {
|
2016-11-28 23:02:06 +01:00
|
|
|
post("ERROR: This script is already running. Cannot run multiple instances");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//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
|
|
|
|
var ramUsage = server.scripts[i].ramUsage;
|
|
|
|
var ramAvailable = server.maxRam - server.ramUsed;
|
|
|
|
|
|
|
|
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){
|
|
|
|
post("This machine does not have enough RAM to run this script. Script requires " + ramUsage + "GB of RAM");
|
|
|
|
return;
|
|
|
|
}else {
|
|
|
|
//Able to run script
|
2016-12-19 19:20:19 +01:00
|
|
|
post("Running script. May take a few seconds to start up the process...");
|
2016-12-14 21:29:40 +01:00
|
|
|
var script = server.scripts[i];
|
2016-12-15 18:51:23 +01:00
|
|
|
server.runningScripts.push(script.filename); //Push onto runningScripts
|
2016-12-14 21:29:40 +01:00
|
|
|
addWorkerScript(script, server);
|
2016-11-29 23:56:05 +01:00
|
|
|
return;
|
2016-11-28 23:02:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-24 23:16:51 +02:00
|
|
|
|
2016-11-28 23:02:06 +01:00
|
|
|
post("ERROR: No such script");
|
2016-10-20 20:26:38 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|