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