Commit c23ea67b authored by yogesh.m's avatar yogesh.m

Revert "code cleanup"

This reverts commit c2573302.
parent bb3b182c
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class SecurityManagementOfflineConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "security_management_offline"
This diff is collapsed.
No preview for this file type
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<title>Security Management</title>
<meta content="" name="description">
<meta content="" name="keywords">
{% load static %}
<!-- Favicons -->
<link href="{% static 'assets2/img/favicon.png' %}" rel="icon">
<link href="{% static 'assets2/img/apple-touch-icon.png' %}" rel="apple-touch-icon">
<!-- Google Fonts -->
<link href="https://fonts.gstatic.com" rel="preconnect">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">
<!-- Vendor CSS Files -->
<link href="{% static 'assets/vendor/bootstrap/css/bootstrap.min.css' %}" rel="stylesheet">
<link href="{% static 'assets/vendor/bootstrap-icons/bootstrap-icons.css' %}" rel="stylesheet">
<link href="{% static 'assets/vendor/boxicons/css/boxicons.min.css' %}" rel="stylesheet">
<link href="{% static 'assets/vendor/quill/quill.snow.css' %}" rel="stylesheet">
<link href="{% static 'assets/vendor/quill/quill.bubble.css' %}" rel="stylesheet">
<link href="{% static 'assets/vendor/remixicon/remixicon.css' %}" rel="stylesheet">
<link href="{% static 'assets/vendor/simple-datatables/style.css' %}" rel="stylesheet">
<!-- Template Main CSS File -->
<link href="{% static 'assets/css/style.css' %}" rel="stylesheet">
<style>
body{
}
.btn_width{
width: 100px;
}
</style>
</head>
<body>
<!-- ======= Header ======= -->
<header id="header" class="header fixed-top d-flex align-items-center">
<div class="d-flex align-items-center justify-content-between">
<a href="index" class="logo d-flex align-items-center">
<img src="{static 'assets/img/UT_384.png' }" alt="">
<span class="d-none d-lg-block">UnifyTwin</span>
</a>
</div><!-- End Logo -->
<nav class="header-nav ms-auto">
<ul class="d-flex align-items-center">
<li class="nav-item dropdown pe-3">
<a class="nav-link nav-profile d-flex align-items-center pe-0" href="#" data-bs-toggle="dropdown">
<span class="d-none d-md-block dropdown-toggle ps-2">{{ user_details }}</span>
</a><!-- End Profile Iamge Icon -->
<ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow profile">
<li class="dropdown-header">
<h6>{{ user_details }}</h6>
</li>
<li>
<hr class="dropdown-divider">
</li>
<li>
<a class="dropdown-item d-flex align-items-center" href="sign_out">
<i class="bi bi-box-arrow-right"></i>
<span>Sign Out</span>
</a>
</li>
</ul><!-- End Profile Dropdown Items -->
</li><!-- End Profile Nav -->
</ul>
</nav><!-- End Icons Navigation -->
</header><!-- End Header -->
<main id="main" class="main" style="scale:90%;">
<div class="pagetitle" style="margin-top:-2.5%">
<h1>Assets Discovery</h1>
</div><!-- End Page Title -->
<section class="section" style="font-size:16px;">
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body" style="box-shadow: 0 4px 3px -3px #ddd; margin-bottom:10px;">
<form action="start_sniff" name="start_sniff" method="POST">
{% csrf_token %}
<div style="padding-top: 20px;">
<div class="row mb-3">
<label class="col-sm-2 col-form-label" style="font-weight: bold;">Choose an Interface</label>
<div class="col-sm-10">
<select name="interface" class="form-select" aria-label="Default select example">
{% for interface in interface_list %}
<option value="{{ interface }}">{{ interface }}</option>
{% endfor %}
</select>
</div>
</div>
<input class="btn btn-primary rounded-pill btn_width" type="submit" value="Start">
<a href = "stop_sniff"><button type="button" class="btn btn-primary rounded-pill btn_width">Stop</button></a>
<a href = "refresh"><button type="button" class="btn btn-primary rounded-pill btn_width">Refresh</button></a>
<label style="float: right; margin-right:20px;font-weight: bold;">Status : {{ status }}</label>
</div>
</form>
</div>
<div class="card-body" style="scale:95%;">
<!-- Table with stripped rows -->
<table class="table datatable">
<thead>
<tr>
<th scope="col">No.</th>
{% for field_name in heading %}
<th scope="col">{{ field_name }}</th>
{% endfor %}
<th scope="col">Status</th>
</tr>
</thead>
<tbody>
{% for field in data %}
<tr>
<th scope="row">{{ field.0 }}</th>
<td>{{ field.1 }}</td>
<td>{{ field.2 }}</td>
<td>{{ field.3 }}</td>
<td>{{ field.4 }}</td>
<td>{{ field.5 }}</td>
<td>{{ field.6 }}</td>
<td>{{ field.7 }}</td>
<td>{{ field.8 }}</td>
<td>
{% if field.9 == "Active" %}
<button type="button" class="btn btn-success rounded-pill" style="scale:75%">
<span class="action mat-icon material-icons" style="margin-top:5px;">wifi</span>
</button>
{% else %}
<button type="button" class="btn btn-danger rounded-pill" style="scale:75%">
<span class="action mat-icon material-icons" style="margin-top:5px;">wifi_off</span>
</button>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<!-- End Table with stripped rows -->
</div>
</div>
</div>
</div>
</section>
</main><!-- End #main -->
<a href="#" class="back-to-top d-flex align-items-center justify-content-center"><i class="bi bi-arrow-up-short"></i></a>
<!-- Vendor JS Files -->
<script src="{% static 'assets/vendor/apexcharts/apexcharts.min.js' %}"></script>
<script src="{% static 'assets/vendor/bootstrap/js/bootstrap.bundle.min.js' %}"></script>
<script src="{% static 'assets/vendor/chart.js/chart.umd.js' %}"></script>
<script src="{% static 'assets/vendor/echarts/echarts.min.js' %}"></script>
<script src="{% static 'assets/vendor/quill/quill.min.js' %}"></script>
<script src="{% static 'assets/vendor/simple-datatables/simple-datatables.js' %}"></script>
<script src="{% static 'assets/vendor/tinymce/tinymce.min.js' %}"></script>
<script src="{% static 'assets/vendor/php-email-form/validate.js' %}"></script>
<!-- Template Main JS File -->
<script src="{% static 'assets/js/main.js' %}"></script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<title>Assets Discovery | Login</title>
<meta content="" name="description">
<meta content="" name="keywords">
{% load static %}
<!-- Google Fonts -->
<link href="https://fonts.gstatic.com" rel="preconnect">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">
<!-- Vendor CSS Files -->
<link href="{% static 'assets/vendor/bootstrap/css/bootstrap.min.css' %}" rel="stylesheet">
<link href="{% static 'assets/vendor/bootstrap-icons/bootstrap-icons.css' %}" rel="stylesheet">
<link href="{% static 'assets/vendor/boxicons/css/boxicons.min.css' %}" rel="stylesheet">
<link href="{% static 'assets/vendor/quill/quill.snow.css' %}" rel="stylesheet">
<link href="{% static 'assets/vendor/quill/quill.bubble.css' %}" rel="stylesheet">
<link href="{% static 'assets/vendor/remixicon/remixicon.css' %}" rel="stylesheet">
<link href="{% static 'assets/vendor/simple-datatables/style.css' %}" rel="stylesheet">
<!-- Template Main CSS File -->
<link href="{% static 'assets/css/style.css' %}" rel="stylesheet">
<!-- =======================================================
* Template Name: NiceAdmin
* Updated: Jul 27 2023 with Bootstrap v5.3.1
* Template URL: https://bootstrapmade.com/nice-admin-bootstrap-admin-html-template/
* Author: BootstrapMade.com
* License: https://bootstrapmade.com/license/
======================================================== -->
</head>
<body>
<main>
<div class="container">
<section class="section register min-vh-100 d-flex flex-column align-items-center justify-content-center py-4">
<div class="container" style="margin-top:-10%">
<div class="row justify-content-center">
<div class="col-lg-4 col-md-6 d-flex flex-column align-items-center justify-content-center">
<div class="d-flex justify-content-center py-4">
<a href="login" class="logo d-flex align-items-center w-auto">
<img src="assets/img/logo.png" alt="">
<span class="d-none d-lg-block">Assets Discovery</span>
</a>
</div><!-- End Logo -->
<div class="card mb-3">
<div class="card-body">
<div class="pt-4 pb-2">
<h5 class="card-title text-center pb-0 fs-4">Login to Your Account</h5>
</div>
<form method="post" action="validate_user" class="row g-3 needs-validation" novalidate>
{% csrf_token %}
<div class="col-12">
<label for="yourUsername" class="form-label">Username</label>
<div class="input-group has-validation">
<input type="text" name="username" class="form-control" id="yourUsername" required>
<div class="invalid-feedback">Please enter your username.</div>
</div>
</div>
<div class="col-12">
<label for="yourPassword" class="form-label">Password</label>
<input type="password" name="password" class="form-control" id="yourPassword" required>
<div class="invalid-feedback">Please enter your password!</div>
</div>
<div class="col-12">
<button class="btn btn-primary w-100" type="submit">Login</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
</main><!-- End #main -->
<a href="#" class="back-to-top d-flex align-items-center justify-content-center"><i class="bi bi-arrow-up-short"></i></a>
<!-- Vendor JS Files -->
<script src="{% static 'assets/vendor/apexcharts/apexcharts.min.js' %}"></script>
<script src="{% static 'assets/vendor/bootstrap/js/bootstrap.bundle.min.js' %}"></script>
<script src="{% static 'assets/vendor/chart.js/chart.umd.js' %}"></script>
<script src="{% static 'assets/vendor/echarts/echarts.min.js' %}"></script>
<script src="{% static 'assets/vendor/quill/quill.min.js' %}"></script>
<script src="{% static 'assets/vendor/simple-datatables/simple-datatables.js' %}"></script>
<script src="{% static 'assets/vendor/tinymce/tinymce.min.js' %}"></script>
<script src="{% static 'assets/vendor/php-email-form/validate.js' %}"></script>
<!-- Template Main JS File -->
<script src="{% static 'assets/js/main.js' %}"></script>
</body>
</html>
\ No newline at end of file
from django.db import models
# Create your models here.
......@@ -120,7 +120,7 @@ def stop_sniff(request):
global status
if process:
if process.is_alive():
process.terminate()
process.kill()
status = "Offline"
return security_management_offline(request)
......
......@@ -46,7 +46,7 @@
<div class="d-flex align-items-center justify-content-between">
<a href="index" class="logo d-flex align-items-center">
<img src="{% static 'assets/img/UT_384.png' %}" alt="">
<img src="{static 'assets/img/UT_384.png' }" alt="">
<span class="d-none d-lg-block">UnifyTwin</span>
</a>
</div><!-- End Logo -->
......
......@@ -48,7 +48,7 @@
<div class="d-flex justify-content-center py-4">
<a href="login" class="logo d-flex align-items-center w-auto">
<img src="{% static 'assets/img/UT_384.png' %}" alt="">
<img src="assets/img/logo.png" alt="">
<span class="d-none d-lg-block">Assets Discovery</span>
</a>
</div><!-- End Logo -->
......
from django.urls import path, re_path
from . import views
urlpatterns = [
path('', views.login, name='login'),
path('login', views.login, name='login'),
path('sign_out', views.sign_out, name='sign out'),
path('validate_user', views.validate_user, name='validating user'),
path('index', views.security_management_offline, name='index'),
path('start_sniff', views.start_sniff, name='start sniffing'),
path('stop_sniff', views.stop_sniff, name='stop sniffing'),
path('refresh', views.refresh, name='refresh'),
]
\ No newline at end of file
import json
import sniff
import multiprocessing
from security_management.settings import CREDENTIALS
from utilities.list_interfaces import get_interfaces
from datetime import datetime, timedelta
from django.http import HttpResponse
from django.template import loader
from django.shortcuts import redirect
status = "Offline"
transfer_status = "not transmitting"
process = None
periodic_transfer = None
def check_session(request):
if 'user' in request.session:
return True
else:
return False
def login(request):
template = loader.get_template('login.html')
return HttpResponse(template.render({}, request))
def sign_out(request):
if 'user' in request.session:
request.session.flush()
return redirect('login')
def validate_user(request):
user_name = request.POST['username']
password = request.POST['password']
if user_name == CREDENTIALS.get("username") and password == CREDENTIALS.get("password"):
request.session['user'] = user_name
return redirect('index')
else:
return HttpResponse("<script>alert('Invalid Login Credentials!'); window.history.back();</script>")
def check_status(timestamp):
current_time = datetime.now()
given_time = datetime.strptime(timestamp, "%d-%m-%y %H:%M:%S")
time_difference = current_time - given_time
five_minutes = timedelta(minutes=5)
status = "Active"
if time_difference > five_minutes:
status = "Inactive"
return status
def security_management_offline(request):
if check_session(request):
global status
global transfer_status
headings = [
"Name", "Last Activity", "Type", "Protocols", "MAC Address",
"Vendor", "Firmware Version", "Model"
]
try:
with open("assets.json") as json_file:
data = json.load(json_file)
except:
data = {}
data_list = []
count = 0
for data_item in data:
count += 1
data_list.append(
[
count,
data_item,
data[data_item]["last_activity"],
data[data_item]["dev_type"],
data[data_item]["protocols"],
data[data_item]["mac"],
data[data_item]["vendor"],
data[data_item]["firmware"],
data[data_item]["model"],
check_status(data[data_item]["last_activity"])
]
)
template = loader.get_template('index.html')
user_name = request.session['user']
context = {
'interface_list': [interface for interface in get_interfaces() if interface != ""],
'data': data_list,
'heading': headings,
'status': status,
'user_details': user_name.title()
}
return HttpResponse(template.render(context, request))
else:
return redirect('login')
def start_sniff(request):
interface = request.POST['interface']
global process
global status
process = multiprocessing.Process(target=sniff.start_sniff, args=(interface,))
if process.is_alive():
process.kill()
process.start()
else:
process.start()
status = "Listening on " + interface + ""
return security_management_offline(request)
def stop_sniff(request):
global process
global status
if process:
if process.is_alive():
process.kill()
status = "Offline"
return security_management_offline(request)
def refresh(request):
return redirect('index')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment