Skip to content

Commit

Permalink
Merge pull request #48 from cisagov/feature/add-bootstrap
Browse files Browse the repository at this point in the history
feature: add bootstrap
  • Loading branch information
Dbones202 authored Sep 11, 2023
2 parents 13831bb + a348ffe commit 1fd26ca
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/navv/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from navv.bll import get_inventory_report_df, get_snmp_df, get_zeek_df

# cisagov Libraries
from navv.gui import app
from navv.gui.app import app
from navv.message_handler import success_msg, warning_msg
from navv.spreadsheet_tools import (
auto_adjust_width,
Expand Down
11 changes: 0 additions & 11 deletions src/navv/gui.py

This file was deleted.

Empty file added src/navv/gui/__init__.py
Empty file.
39 changes: 39 additions & 0 deletions src/navv/gui/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import logging
import os

from flask import Flask, render_template, send_from_directory

from navv.gui.utils import get_pcap_file


logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
app = Flask(__name__)


@app.route("/")
def index():
pcap_file, pcap_msg, pcap_msg_color = get_pcap_file()

return render_template(
"index.html",
pcap_file=pcap_file,
pcap_msg=pcap_msg,
pcap_msg_color=pcap_msg_color,
)


@app.route("/download")
def download():
"""Download the network analysis excel file."""
filename = "test-customer_network_analysis.xlsx"
current_path = os.getcwd()

if not os.path.isfile(os.path.join(current_path, filename)):
logger.error(f"File {filename} not found in {current_path}")

return send_from_directory(
current_path,
filename,
as_attachment=True,
)
7 changes: 7 additions & 0 deletions src/navv/gui/static/css/bootstrap.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/navv/gui/static/css/bootstrap.min.css.map

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/navv/gui/static/css/bootstrap.rtl.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/navv/gui/static/css/bootstrap.rtl.min.css.map

Large diffs are not rendered by default.

Binary file added src/navv/gui/static/img/navv-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/navv/gui/static/js/bootstrap.bundle.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/navv/gui/static/js/bootstrap.bundle.min.js.map

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/navv/gui/static/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@media (min-width: 992px) {
.rounded-lg-3 {
border-radius: .3rem;
}
}

.alert {
width: 40%;
font-size: .5rem;
}
78 changes: 78 additions & 0 deletions src/navv/gui/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="Idaho National Laboratory">
<meta name="generator" content="Hugo 0.84.0">
<title>NAVV</title>

<link rel="canonical" href="https://pypi.org/project/navv/">



<!-- Bootstrap core CSS -->
<link href="../static/css/bootstrap.min.css" rel="stylesheet">

<style>
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}

@media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
</style>

<!-- Custom styles for this template -->
<link href="../static/styles.css" rel="stylesheet">
</head>

<body>

<main>
<h1 class="visually-hidden">NAVV</h1>

<div class="px-4 py-5 my-5 text-center">
<img class="d-block mx-auto mb-4" src="../static/img/navv-logo.png" alt="" width="100" height="100">
<h1 class="display-5 fw-bold">NAVV</h1>
<div class="col-lg-6 mx-auto">
<h3 class="lead mb-3">Network Architecture Verification and Validation</h3>
<p class="mb-3">Generate a spreadsheet for network traffic analysis. You can optionally upload a PCAP file to
analyze network traffic.
</p>
<div class="d-grid gap-2 d-sm-flex justify-content-sm-center">
<button type="file" class="btn btn-primary btn-sm px-4 gap-3 {% if pcap_file %}disabled{% endif %}">Upload
PCAP</button>
<a class="btn btn-outline-secondary btn-sm px-4" href="{{ url_for('download') }}">Download Excel</a>
</div>
</div>
<div class="alert alert-{{ pcap_msg_color }} mx-auto mt-3" role="alert">{{ pcap_msg }}</div>
</div>

<div class="bg-dark text-secondary px-2 py-3 text-center">
<div class="py-3">
<div class="col-lg-6 mx-auto">
<p class="fs-5 mb-3">This project uses <a class="link-offset-2 link-underline link-underline-opacity-0"
href="https://zeek.org">Zeek</a>, a network security monitoring tool.
</p>
</div>
</div>
</div>
</main>


<script src="../static/dist/js/bootstrap.bundle.min.js"></script>


</body>

</html>
30 changes: 30 additions & 0 deletions src/navv/gui/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import logging

logger = logging.getLogger(__name__)


def get_pcap_file() -> tuple[str, str, str]:
"""Get the pcap file from the current working directory."""
pcap_files = set()
for file in os.listdir(os.getcwd()):
if file.endswith(".pcap"):
logger.info(f"Found pcap file: {file} in {os.getcwd()}")
pcap_files.add(file)

# No PCAP file found
if len(pcap_files) == 0:
logger.error(f"Could not find a pcap file in {os.getcwd()}")
return (
"",
"Could not find a pcap file in the current directory. Please upload.",
"warning",
)

# Multiple PCAP files found
if len(pcap_files) > 1:
logger.error(f"Found multiple pcap files, please remove all but one.")
return "", "Found multiple pcap files. Please remove all but one.", "danger"

filename = pcap_files.pop()
return filename, f"{filename} detected and uploaded successfully.", "success"

0 comments on commit 1fd26ca

Please sign in to comment.