Spaces:
Build error
Build error
File size: 8,415 Bytes
0489775 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | #### BIBLIOTECAS ####
import streamlit as st
import docx2txt
#import pdfplumber
from datetime import datetime, date
#UTILS
import base64
import time
timestr = time.strftime("%Y%m%d")
import pandas as pd
class FileDownloader(object):
def __init__(self, data,filename='JUNOS_CRQ',file_ext='txt'):
super(FileDownloader, self).__init__()
self.data = data
self.filename = filename
self.file_ext = file_ext
def download(self):
b64 = base64.b64encode(self.data.encode()).decode()
new_filename = "{}_{}_.{}".format(self.filename,timestr,self.file_ext)
st.markdown("#### Download File ###")
href = f'<a href="data:file/{self.file_ext};base64,{b64}" download="{new_filename}">Click Here!!</a>'
st.markdown(href,unsafe_allow_html=True)
def mainJunos():
#st.title("Pasos a Producci贸n")
### INFORMACION LADO IZQUIERDO ###
#st.sidebar.image('proconty.jpg', width=300)
### ESTRUCTURA PRINCIPAL ###
st.title('IPs MALICIOSAS - JUNOS')
menu = ['Archivo CSV - JUNOS', 'Comparaci贸n de IPs - JUNOS']
choice = st.sidebar.selectbox('Menu - JUNOS', menu)
#st.sidebar.markdown('[MENU PRINCIPAL](https://proconty-pap.herokuapp.com/)')
if choice == 'Archivo CSV - JUNOS':
st.write('Indicaciones de uso:')
st.write("Cargar el archivo (.txt), ingresar el n煤mero de CRQ y verificar que la fecha este correcta.")
st.write("Al presionar el boton GENERAR se creara un archivo con el formato para JUNOS.")
st.write("En la opcion Menu seleccionar el tipo de archivo que desea descargar (.txt o .csv)")
st.warning("Al abrirse la opcion de descargar colocar el n煤mero de CRQ")
### CARGAR Y VISUALIZAR ARCHIVO ###
docx_file = st.file_uploader('Cargar archivo .txt', type=['pdf','docx','txt'])
if docx_file is not None:
if docx_file.type == "text/plain":
# Read as string (decode bytes to string)
raw_text = str(docx_file.read(),"utf-8")
st.text(raw_text)
else:
raw_text = docx2txt.process(docx_file)
st.write(raw_text)
### INGRESAR CRQ Y FECHA ###
crq_num = st.text_input('Ingrese el n煤mero de la CRQ: ')
st.write("CRQ_"+crq_num)
day = date.today().strftime("%A")
day = day[0:3]
fecha = datetime.now().strftime("%d-%b-%Y %H:%M:%S")
st.write(day+', '+fecha)
##### GENERAR ARCHIVO TXT #####
def Convert(string):
li = list(string.split('\n'))
return li
if st.button('GENERAR'):
bandera = Convert(raw_text)
documento = 'prueba.txt'
with open(documento, 'w') as f:
f.write("#Rows which start with '#' are treated as a commented row \n")
f.write("# \n")
f.write('\n')
fechaCreacion = str('#Created time:,'+'"{}'.format(day)+", {}".format(fecha)+'"\n')
f.write(''.join(fechaCreacion))
f.write('#Version -11.4 \n')
f.write('\n')
f.write("# \n")
f.write("# \n")
f.write("# \n")
f.write('\n')
f.write('#Start - Please do not modify or change this line \n')
f.write('\n')
f.write('#Section Start - Network Address - Please do not modify or change this line \n')
f.write('#Explanation for the Column Names \n')
f.write('# \n')
f.write('#Name - Name of the Address \n')
f.write('#Domain - Domains for the Address to be created \n')
f.write('#Description - Description for Address \n')
f.write('#Type - Type of the Address. Values can be Network, IPRange or Host \n')
f.write("#IP Address - Ip Address(IPv4/IPv6) of the individual host. This field with 'Type' as Host or Network. It can be wildcard ip as well \n")
f.write('#Subnet Mask/Prefix - Subnet mask/prefix provided for the IP Address((IPv4/IPv6)) provided in previous column when Type is selected as Network \n')
f.write('#IP Range Min - Minimum IP(IPv4) Range in case range is provided. This should be provided when Type is Range \n')
f.write('#IP Range Max - Maximum IP(IPv4) Range in case range is provided. This should be provided when Type is Range \n')
f.write('#Host - Host Name of the host address. This should be provided when Type is Host. This field will be ignored if IP Address is provided \n')
f.write('#Wildcard Mask - Wildcard mask IP address (IPV4/IPV6) \n')
f.write('#Address Groups - Provide the Address Groups for the Address to be created. \n')
f.write('# If Address Group is not present it would be created. \n')
f.write("# More than one Address Groups should be seperated by '|' \n")
f.write('#Metadata - Add metadata with Logical Operatos to your Address. \n')
f.write('#DnsAddressType - Type of the DNS Address. Values can be ipv4-only or ipv6only \n')
f.write('# \n')
f.write('#Name, Description, Type, IP Address, Subnet Mask/Prefix, IP Range Min, IP Range Max, Host, Wildcard Mask, Address Groups, Metadata, DnsAddressType, Domain \n')
ipsMali = []
count = 0
for line in bandera:
if count != len(bandera):
ipsMali = str("Host_{}".format(line.strip())+',"CRQ{}",'.format(crq_num)+'Host,'+'{}'.format(line.strip())+',,,,,,,,,,'+'Global/FW_ATLAS')
f.write(''.join(ipsMali))
f.write('\n')
print(ipsMali)
else:
break
count =+ 1
f.write('\n')
f.write('#Section End - Network Address - Please do not modify or change this line \n')
f.write('#End - Please do not modify or change this line')
#### DESCARGAR #####
menu = ['Text', 'CSV']
choice = st.selectbox('Menu', menu)
if choice == 'Text':
if st.button('Guardar TXT'):
with open('prueba.txt', 'r') as file:
dataIPS = file.read()
download = FileDownloader(dataIPS).download()
if choice == 'CSV':
if st.button('Guardar CSV'):
with open('prueba.txt', 'r') as file:
dataIPScsv = file.read()
download = FileDownloader(dataIPScsv, file_ext='csv').download()
#st.write('All rights reserved. Developed by David Minango')
if choice == 'Comparaci贸n de IPs - JUNOS':
st.write('Indicaciones de uso:')
st.write("Cargar los dos archivos en (.txt), el archivo 1 debe ser la base de datos de JUNOS, el archivo 2 debe ser el enviado por Ingenieria.")
st.write("Al presionar el boton COMPARAR se generara una tabla con las ips no encontradas en la base de datos de JUNOS.")
### CARGAR Y VISUALIZAR ARCHIVO BASE DE DATOS###
upload_baseDatos = st.file_uploader('Base de Datos')
upload_ingenieria = st.file_uploader('Ingenieria')
if upload_baseDatos:
df1 = pd.read_table(upload_baseDatos, delimiter=" ", header=None)
df1 = pd.DataFrame(df1.values, columns=['BaseDatos'])
#st.write(df1)
if upload_ingenieria:
df2 = pd.read_table(upload_ingenieria, header=None)
df2 = pd.DataFrame(df2.values, columns=['BaseIngenieria'])
df2 = df2.drop_duplicates()
unir = st.checkbox('Unir archivos')
if unir:
unionDataFrames = pd.concat([df1,df2], axis=1)
st.write(unionDataFrames)
if st.button('Comparar'):
df_1notin2 = df2[~(df2['BaseIngenieria'].isin(df1['BaseDatos']) )].reset_index(drop=True)
st.write(df_1notin2)
#st.write('All rights reserved. Developed by David Minango')
|