Skip to content

Commit

Permalink
adding client and env vars for backend comms.
Browse files Browse the repository at this point in the history
  • Loading branch information
royrusso committed Nov 27, 2024
1 parent 65dc139 commit 09d113d
Show file tree
Hide file tree
Showing 15 changed files with 197 additions and 90 deletions.
9 changes: 8 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@
"console": "integratedTerminal"
},
{
"name": "Python Debugger: FastAPI",
"name": "Python Debugger: Uvicorn",
"type": "debugpy",
"request": "launch",
"module": "uvicorn",
"args": ["backend.main:app", "--reload"],
"jinja": true
},
{
"name": "FastAPI",
"type": "debugpy",
"request": "launch",
"module": "fastapi",
"args": ["dev", "backend/main.py", "--reload"]
}
]
}
5 changes: 0 additions & 5 deletions backend/api/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,3 @@
@router.get("/", tags=["default"])
def read_root():
return {"Net Pretzel says": "Hello World"}


@router.get("/health", tags=["default"])
def read_health():
return {"status": "OK"}
9 changes: 7 additions & 2 deletions backend/api/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
router = APIRouter()


@router.get("/ipinfo", tags=["info"])
@router.get("/info/ip", tags=["info"])
def get_ip_info():
"""
Returns information about the IP address of the server.
"""
return {"internet_connected": ip.internet(), "internal_ip": ip.internal(), "external_ip": ip.external()}


@router.get("/is_root", tags=["info"])
@router.get("/info/is_root", tags=["info"])
def is_root():
"""
Returns whether the user is root or not.
Expand All @@ -23,3 +23,8 @@ def is_root():
logger.error("You need to have root privileges. Some functionality may not work as expected.")
return {"is_root": False}
return {"is_root": True}


@router.get("/info/health", tags=["info"])
def read_health():
return {"status": "OK"}
16 changes: 10 additions & 6 deletions backend/api/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
router = APIRouter()


@router.get("/scan_detailed/{ip_address:path}", tags=["scan"])
@router.get("/scan/detailed/{ip_address:path}", tags=["scan"])
async def scan_detailed(ip_address: str):
"""
Detailed scan of the target IP address, including port scan.
Expand All @@ -16,7 +16,7 @@ async def scan_detailed(ip_address: str):
return {"result": result}


@router.get("/scan_ping/{ip_address:path}", tags=["scan"])
@router.get("/scan/ping/{ip_address:path}", tags=["scan"])
async def scan_basic(ip_address: str):
"""
First pass at a scan. Just pings the target and conducts a traceroute. No port scan.
Expand All @@ -28,7 +28,7 @@ async def scan_basic(ip_address: str):
return {"result": result}


@router.get("/scan_os/{ip_address:path}", tags=["scan"])
@router.get("/scan/os/{ip_address:path}", tags=["scan"])
async def scan_os(ip_address: str):
"""
Scan the target IP address for OS detection.
Expand All @@ -40,7 +40,7 @@ async def scan_os(ip_address: str):
return {"result": result}


@router.get("/scan_vuln/{ip_address:path}", tags=["scan"])
@router.get("/scan/vuln/{ip_address:path}", tags=["scan"])
async def scan_vuln(ip_address: str):
"""
Scan the target IP address for OS detection and vulnerabilities.
Expand All @@ -52,11 +52,15 @@ async def scan_vuln(ip_address: str):
return {"result": result}


@router.get("/scan_list/{ip_address:path}", tags=["scan"])
@router.get("/scan/list/{ip_address:path}", tags=["scan"])
async def scan_list(ip_address: str):
"""
Returns a list of IP addresses to scan. This call does NOT perform scan, ping, traceroute, etc. and simply returns
a list of IP addresses with hostnames, if found.
"""
nmap_scanner = NmapScanner()
return nmap_scanner.list_scan(ip_address)
try:
response = nmap_scanner.list_scan(ip_address)
except Exception as e:
response = str(e)
return {"result": response}
2 changes: 0 additions & 2 deletions backend/scan/nmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,9 @@ def get_scan_command(self):
): # No port scan. Yes traceroute sudo nmap -sn --traceroute -T4 -oX - -v 192.168.1.196
flags = [
"-sn",
"--traceroute",
"-T4",
"-oX",
"-",
"-v",
]
case ScanTypesEnum.DETAILED: # TCP SYN scan
flags = ["-sS", "--min-rate", "2000", "-oX", "-"]
Expand Down
3 changes: 2 additions & 1 deletion backend/scan/nmap_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def wrapper(*args, **kwargs):
logger.error(
"You need to have root privileges to run this script.\nPlease try again, this time using 'sudo'. Exiting."
)
exit()
return {"error": True, "message": "You need to have root privileges to run this script."}
# exit()
return func(*args, **kwargs)

return wrapper
4 changes: 2 additions & 2 deletions backend/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
def test_read_default():
response = client.get("/")
assert response.status_code == 200
assert response.json() == {"Net Pretzel says": "Hello World"}
assert response.json() == {"Minerva says": "Hello World"}


def test_health_check():
response = client.get("/health")
response = client.get("/info/health")
assert response.status_code == 200
assert response.json() == {"status": "OK"}
2 changes: 2 additions & 0 deletions frontend/.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

VITE_API_URL=http://localhost:8000
1 change: 1 addition & 0 deletions frontend/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_API_URL=http://localhost:8000
4 changes: 2 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Route, Routes } from "react-router-dom";
import Home from "./components/home";
import Header from "./layouts/header";
import Header from "./components/header";
import Home from "./routes/home";
//
const App = () => {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Container from "react-bootstrap/Container";
import Nav from "react-bootstrap/Nav";
import Navbar from "react-bootstrap/Navbar";
import NavDropdown from "react-bootstrap/NavDropdown";
import { IconContext } from "react-icons";
import { FaGithub } from "react-icons/fa";

const Header = () => {
return (
Expand All @@ -15,10 +17,12 @@ const Header = () => {
<Container>
<Navbar.Brand href="#home">Minerva</Navbar.Brand>
<Navbar.Toggle aria-controls="basic-navbar-nav" />
<Navbar.Collapse id="basic-navbar-nav">
<Nav className="me-auto">
<Nav.Link href="#home">Home</Nav.Link>
<Nav.Link href="#link">Link</Nav.Link>
<Navbar.Collapse
id="basic-navbar-nav"
className="justify-content-end"
>
<Nav className="justify-content-end">
<Nav.Link href="#home">Settings</Nav.Link>
<NavDropdown title="Dropdown" id="basic-nav-dropdown">
<NavDropdown.Item href="#action/3.1">Action</NavDropdown.Item>
<NavDropdown.Item href="#action/3.2">
Expand All @@ -32,6 +36,16 @@ const Header = () => {
Separated link
</NavDropdown.Item>
</NavDropdown>
<Nav.Link
href="https://github.com/royrusso/minerva"
target="_blank"
>
<IconContext.Provider
value={{ size: "1.5em", className: "react-icon-button" }}
>
<FaGithub />
</IconContext.Provider>
</Nav.Link>
</Nav>
</Navbar.Collapse>
</Container>
Expand Down
61 changes: 0 additions & 61 deletions frontend/src/components/home.tsx

This file was deleted.

11 changes: 7 additions & 4 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
* Custom class for the react-icons that are wrapped by a provider
*/
.react-icon-button {
/* display: inline-block; */
/* margin: 0 0.5em; */
font-size: 1.5em !important;
margin: 0 0.1em;
display: inline-block;
font-size: 1em;

/* Center the icon */
display: flex;
justify-content: center;
align-items: center;
}
Loading

0 comments on commit 09d113d

Please sign in to comment.