2021-09-14 02:37:35 +02:00
|
|
|
import React, { useState } from "react";
|
|
|
|
|
2021-09-17 01:23:03 +02:00
|
|
|
import Accordion from "@mui/material/Accordion";
|
|
|
|
import AccordionSummary from "@mui/material/AccordionSummary";
|
|
|
|
import AccordionDetails from "@mui/material/AccordionDetails";
|
|
|
|
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
2021-09-14 02:37:35 +02:00
|
|
|
|
2021-10-01 02:06:40 +02:00
|
|
|
import Typography from "@mui/material/Typography";
|
2021-09-17 01:23:03 +02:00
|
|
|
import Button from "@mui/material/Button";
|
|
|
|
import Select, { SelectChangeEvent } from "@mui/material/Select";
|
2021-10-07 22:04:04 +02:00
|
|
|
import { GetAllServers } from "../../Server/AllServers";
|
|
|
|
import { Server } from "../../Server/Server";
|
2021-09-14 02:37:35 +02:00
|
|
|
import { GetServerByHostname } from "../../Server/ServerHelpers";
|
2021-09-17 01:23:03 +02:00
|
|
|
import MenuItem from "@mui/material/MenuItem";
|
2021-09-14 02:37:35 +02:00
|
|
|
|
2021-09-14 04:27:43 +02:00
|
|
|
export function Servers(): React.ReactElement {
|
2021-09-14 02:37:35 +02:00
|
|
|
const [server, setServer] = useState("home");
|
2021-09-17 01:23:03 +02:00
|
|
|
function setServerDropdown(event: SelectChangeEvent<string>): void {
|
2021-09-14 02:37:35 +02:00
|
|
|
setServer(event.target.value as string);
|
|
|
|
}
|
|
|
|
function rootServer(): void {
|
|
|
|
const s = GetServerByHostname(server);
|
|
|
|
if (s === null) return;
|
2021-10-07 22:04:04 +02:00
|
|
|
if (!(s instanceof Server)) return;
|
2021-09-14 02:37:35 +02:00
|
|
|
s.hasAdminRights = true;
|
|
|
|
s.sshPortOpen = true;
|
|
|
|
s.ftpPortOpen = true;
|
|
|
|
s.smtpPortOpen = true;
|
|
|
|
s.httpPortOpen = true;
|
|
|
|
s.sqlPortOpen = true;
|
|
|
|
s.openPortCount = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
function rootAllServers(): void {
|
2021-10-07 22:04:04 +02:00
|
|
|
for (const s of GetAllServers()) {
|
|
|
|
if (!(s instanceof Server)) return;
|
2021-09-14 02:37:35 +02:00
|
|
|
s.hasAdminRights = true;
|
|
|
|
s.sshPortOpen = true;
|
|
|
|
s.ftpPortOpen = true;
|
|
|
|
s.smtpPortOpen = true;
|
|
|
|
s.httpPortOpen = true;
|
|
|
|
s.sqlPortOpen = true;
|
|
|
|
s.openPortCount = 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function minSecurity(): void {
|
|
|
|
const s = GetServerByHostname(server);
|
|
|
|
if (s === null) return;
|
2021-10-07 22:04:04 +02:00
|
|
|
if (!(s instanceof Server)) return;
|
2021-09-14 02:37:35 +02:00
|
|
|
s.hackDifficulty = s.minDifficulty;
|
|
|
|
}
|
|
|
|
|
|
|
|
function minAllSecurity(): void {
|
2021-10-07 22:04:04 +02:00
|
|
|
for (const s of GetAllServers()) {
|
|
|
|
if (!(s instanceof Server)) return;
|
|
|
|
s.hackDifficulty = s.minDifficulty;
|
2021-09-14 02:37:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function maxMoney(): void {
|
|
|
|
const s = GetServerByHostname(server);
|
|
|
|
if (s === null) return;
|
2021-10-07 22:04:04 +02:00
|
|
|
if (!(s instanceof Server)) return;
|
2021-09-14 02:37:35 +02:00
|
|
|
s.moneyAvailable = s.moneyMax;
|
|
|
|
}
|
|
|
|
|
|
|
|
function maxAllMoney(): void {
|
2021-10-07 22:04:04 +02:00
|
|
|
for (const s of GetAllServers()) {
|
|
|
|
if (!(s instanceof Server)) return;
|
|
|
|
s.moneyAvailable = s.moneyMax;
|
2021-09-14 02:37:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-09-18 03:30:02 +02:00
|
|
|
<Accordion TransitionProps={{ unmountOnExit: true }}>
|
2021-09-14 02:37:35 +02:00
|
|
|
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
2021-10-01 22:22:33 +02:00
|
|
|
<Typography>Servers</Typography>
|
2021-09-14 02:37:35 +02:00
|
|
|
</AccordionSummary>
|
|
|
|
<AccordionDetails>
|
|
|
|
<table>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>
|
2021-10-01 02:06:40 +02:00
|
|
|
<Typography>Server:</Typography>
|
2021-09-14 02:37:35 +02:00
|
|
|
</td>
|
|
|
|
<td colSpan={2}>
|
2021-09-29 07:49:22 +02:00
|
|
|
<Select id="dev-servers-dropdown" onChange={setServerDropdown} value={server}>
|
2021-10-07 22:04:04 +02:00
|
|
|
{GetAllServers().map((server) => (
|
2021-09-14 02:37:35 +02:00
|
|
|
<MenuItem key={server.hostname} value={server.hostname}>
|
|
|
|
{server.hostname}
|
|
|
|
</MenuItem>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
2021-10-01 02:06:40 +02:00
|
|
|
<Typography>Root:</Typography>
|
2021-09-14 02:37:35 +02:00
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<Button onClick={rootServer}>Root one</Button>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<Button onClick={rootAllServers}>Root all</Button>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
2021-10-01 02:06:40 +02:00
|
|
|
<Typography>Security:</Typography>
|
2021-09-14 02:37:35 +02:00
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<Button onClick={minSecurity}>Min one</Button>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<Button onClick={minAllSecurity}>Min all</Button>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
2021-10-01 02:06:40 +02:00
|
|
|
<Typography>Money:</Typography>
|
2021-09-14 02:37:35 +02:00
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<Button onClick={maxMoney}>Max one</Button>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<Button onClick={maxAllMoney}>Max all</Button>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</AccordionDetails>
|
|
|
|
</Accordion>
|
|
|
|
);
|
|
|
|
}
|