From 8d0dce126730faedb2c15bcfbad6a3dc8e7b4d52 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 9 Nov 2023 11:11:19 +0000 Subject: [PATCH] adding export --- app.py | 33 ++++++++++++++++++++------------- static/style.css | 14 +++++++------- templates/index.html | 16 +++++++++++++++- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/app.py b/app.py index 42d4f12..6f16c95 100644 --- a/app.py +++ b/app.py @@ -4,7 +4,6 @@ import sys import time import socket import iperf3 -import logging import requests import subprocess import scapy.all as scapy @@ -14,12 +13,6 @@ from flask_navigation import Navigation from flask_socketio import SocketIO, emit from flask import Flask, render_template, Response, request, redirect, url_for, session, escape -#Global config -__version__ = "1.0.0" -path = os.path.dirname(__file__) -logging.basicConfig(filename=path+'/log/Pyng.log', level=logging.DEBUG, format=f'%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s') -logging.info('PROGRAM START') - #Init app = Flask(__name__) app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT' @@ -30,6 +23,7 @@ nav = Navigation(app) #Variable uphost=0 +export_list=[] #Menu nav.Bar('top', [ nav.Item('Network', 'index'), @@ -100,6 +94,7 @@ def bg_scan_port(target): #Background network scan def bg_scan_network(subnet): + global export_list global uphost uphost=0 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -109,18 +104,18 @@ def bg_scan_network(subnet): broadcast.dst = 'ff:ff:ff:ff:ff:ff' request_broadcast = broadcast / request clients = scapy.srp(request_broadcast, timeout = 1)[0] + export_list=['IP,MAC,VENDOR,DNS'] for element in clients: uphost=uphost+1 macdet=get_mac_details(element[1].hwsrc) dns=dns_resolv(element[1].psrc) + export_list.append(element[1].psrc+','+element[1].hwsrc+','+macdet.replace(",", " ")+','+dns) socketio.emit('net_response',{'ip': element[1].psrc,'mac': element[1].hwsrc,'vendor':macdet,'dns':dns}) sock.close() #Main route to index. @app.route("/") def index(): - app.logger.info('Info level log') - app.logger.warning('Warning level log') if 'username' in session: return render_template('index.html') return render_template('login.html',title="Welcome") @@ -156,11 +151,24 @@ def connect(data): @socketio.on('net_port') def connect(data): global uphost + global export_list emit('net_response', {'ip':'IP','mac':'Mac address','vendor':'Vendor resolution','dns':'Local DNS'}) socketio.start_background_task(bg_scan_network(data)) downhost=256-uphost - emit('net_response', {'ip':' ','mac':'Up:'+str(uphost),'vendor': 'Down:'+str(downhost),'dns':' '}) - + print(export_list) + emit('net_response', {'ip':' ','mac':'Up:'+str(uphost),'vendor': 'Down:'+str(downhost),'dns':''}) +#Export +@app.route("/export", methods=['GET', 'POST']) +def export_file(): + global export_list + csv="" + for line in export_list: + csv = csv+'\n'+line + return Response( + csv, + mimetype="text/csv", + headers={"Content-disposition": + "attachment; filename=CMDB.csv"}) ##Login @app.route("/login", methods=['GET', 'POST']) def login(): @@ -169,7 +177,6 @@ def login(): password = request.form['password'] if authenticate(str(username), str(password)): session['username'] = request.form['username'] - logging.info('AUTH LOG - New auth from '+username+' !') return redirect(url_for('index')) else: resultats='

Invalid Username/Password !

' @@ -182,4 +189,4 @@ def logout(): ##Start if __name__ == '__main__': - socketio.run(app, host='0.0.0.0', port='5005', allow_unsafe_werkzeug=True) + socketio.run(app, host='0.0.0.0', port='5005') diff --git a/static/style.css b/static/style.css index adf8e43..b659350 100644 --- a/static/style.css +++ b/static/style.css @@ -4,8 +4,8 @@ body { font-family: helvetica, arial, verdana, sans-serif; text-align:center; min-height: 100% !important; - background: #333; - color: white; + background: white; + color: black; } ::placeholder { @@ -87,7 +87,7 @@ span { background-color: #BB8FCE; } #output { - border-radius: 15px; +// border-radius: 15px; box-shadow: 0px 0px 9px 0px rgba(0,0,0,0.1); width: fit-content; background-color:white; @@ -110,13 +110,13 @@ tr:not(:first-child):hover { background-color: rgba(114, 114, 113, 0.2); } input { - padding: 6px; + padding: 15px; font-size: 14px; border-width: 0px; border-color: #CCCCCC; background-color: #FFFFFF; - color: #000000; + color: #333; border-style: solid; - border-radius: 9px; - box-shadow: 0px 0px 5px rgba(66,66,66,.75); + border-radius: 5px; + box-shadow: 0px 0px 2px rgba(66,66,66,.75); } diff --git a/templates/index.html b/templates/index.html index 48baff7..4e253b2 100644 --- a/templates/index.html +++ b/templates/index.html @@ -32,6 +32,19 @@ return false; }); + const outputDiv = document.querySelector('#output'); + const autreDiv = document.querySelector('#export_list'); + if (outputDiv.innerHTML.trim() === '') { + autreDiv.style.display = 'none'; + } + outputDiv.addEventListener('DOMSubtreeModified', function () { + if (outputDiv.innerHTML.trim() === '') { + autreDiv.style.display = 'none'; + } else { + autreDiv.style.display = 'block'; + } + }); + }); @@ -58,7 +71,8 @@
-

+

+