Proyecto

General

Perfil

' Gambas class file

' This program IS free software; you can redistribute it AND/OR
' modify it under the terms of the GNU General PUBLIC License AS
' published by the Free Software Foundation; either version 2 of the
' License, OR (at your option) any later version.
'
' This program IS distributed IN the hope that it will be useful, but
' IS provided AS IS, WITHOUT ANY WARRANTY; without even the implied
' warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
' NON-INFRINGEMENT. See the GNU General PUBLIC License FOR more details.
'
' You should READ the GNU General PUBLIC License
' IF you have non, WRITE TO the Free Software
' Foundation, INC., 59 Temple Place - Suite 330, Boston,
' # MA 02111-1307, USA.
' ----------------------------------------------------------------------------
' ################################################
' # file name : frmnmap.class
' # created in project : scanies
' # created by : Francisco Paniagua Sánchez
' # mail : adminies.franciscodeorellana@edu.juntaextremadura.net
' # created at : 12/11/2006
' # last test with : gambas-2.7-1
' ################################################

PRIVATE indice AS Integer
PUBLIC pasarnombre AS String
PRIVATE hset AS Settings


PUBLIC SUB iniciar_formulario()
DIM fichero AS String
btnsalir.picture = Stock["16/quit"]
lista.Columns.Count = 2
lista.Columns[0].Width = 125
lista.Columns[1].Width = 200
lista.Columns[0].Text = "Dirección IP"
lista.Columns[1].text = "Dispositivo"
fichero = User.home & "/.scanies-nmap"
IF NOT Exist(fichero) THEN SHELL "touch " & fichero WAIT
hset = NEW Settings(fichero)
END


PUBLIC SUB Form_Open()

ME.Center
iniciar_formulario()
cargar_datos()
END

PRIVATE FUNCTION obtener_nombre(dato AS String) AS String
RETURN hset[dato]
END



PRIVATE SUB cargar_datos()
DIM fichero AS String
DIM fdispositivos AS File
DIM linea AS String
DIM contador AS Integer
DIM ip AS String
DIM nombre AS String


IF (lista.Exist(0)) THEN lista.Clear

fichero = "/tmp/encendidos-nmap"
contador = 0
TRY SHELL "nmap -n -sP " & fprincipal.rango & " | grep appears | cut -f2 -d\" \" > " & fichero WAIT
TRY OPEN fichero FOR READ AS #fdispositivos
WHILE NOT Eof(fdispositivos)
LINE INPUT #fdispositivos, linea
nombre = obtener_nombre(linea)
IF (nombre = "") THEN nombre = "Dispositivo"
lista.Add(contador, linea)
lista[contador][1] = nombre
contador = contador + 1
WEND
CLOSE #fdispositivos
CATCH
Message.Info("Existe algún problema por el cual no se puede ejecutar la aplicación, revisa la configuración")
END

PUBLIC SUB lista_Click()
indice = lista.Current.Key
END



PUBLIC SUB lista_Menu()
'DIM tocado AS Boolean

' TRY tocado = LAST.current.selected
' IF NOT ERROR THEN
mnupopup.Popup
' indice = LAST.item.key
' ENDIF

END



PUBLIC SUB mnunombre_Click()

pasarnombre = lista[indice][1]
frmnombre.pasardireccion = lista[indice][0]
frmnombre.ShowModal
lista[indice][1] = pasarnombre
hset[lista[indice][0]] = pasarnombre
hset.Save
END

PUBLIC SUB mnunavegador_Click()
SHELL "firefox " & lista[indice][0] WAIT
END

PUBLIC SUB mnupdf_Click()
DIM fecha AS String
DIM fichero AS String
DIM ficheropdf AS String
DIM x AS Integer
DIM y AS Integer
DIM yinc1 AS Integer
DIM yinc2 AS Integer
DIM xinc1 AS Integer
DIM xinc2 AS Integer
DIM i AS Integer
DIM snombre AS String
DIM sdireccionip AS String
DIM smac AS String
DIM npagina AS Integer

'generar un fichero con los datos de los equipos

fecha = Now() 'Format(Now, "dd-mm-yyyy")
fichero = "/tmp/redscanies-report.ps"
ficheropdf = User.home & "/Desktop/redscanies-report.pdf"
npagina = 1
Printer.copies = 1
Printer.name = ""
Printer.size = "A4"
Printer.file = fichero
Draw.Begin(printer)
Draw.Font.name = "FreeSans"
'cabecera *****************************************************************
x = 250
y = 200
Draw.Font.size = 6
Draw.Text("Documento generado: " & fecha & " --- Página " & npagina, x + 3250, y - 100)
Draw.Font.size = 24
Draw.Font.Bold = TRUE
Draw.Text("*** Elementos de Red - ScanIES ***", x + 600, y)
Draw.Font.size = 10
yinc1 = 200
xinc1 = 1800
xinc2 = 3700
y = y + yinc1 + yinc1
Draw.Font.size = 16
Draw.Text("Nombre", x, y)
Draw.Text("Dirección IP", x + xinc2, y)
'cuerpo *************************************************************
y = y + yinc1
yinc2 = 100
Draw.Font.size = 10
Draw.Font.bold = FALSE
FOR i = 0 TO lista.Count
IF (lista.Exist(i)) THEN
snombre = lista[i][1]
sdireccionip = lista[i][0]
Draw.Text(snombre, x, y)
Draw.Text(sdireccionip, x + xinc2, y)
y = y + yinc2
IF (y > 6400) THEN 'debemos comenzar una nueva página *******************************
'incluimos la cabecera y modificamos el valor de y **********************************
printer.NewPage
npagina = npagina + 1
Draw.Font.size = 6
Draw.Text("Documento generado: " & fecha & " --- Página " & npagina, x + 3250, 100)
y = 400
Draw.Font.size = 16
Draw.Font.Bold = TRUE
Draw.Text("Nombre", x, y)
Draw.Text("Dirección IP", x + xinc2, y)
Draw.Font.size = 10
Draw.Font.bold = FALSE
y = y + yinc1
ENDIF
ENDIF
NEXT
Draw.End
'convertimos el fichero ps a pdf
SHELL "ps2pdf " & fichero & " " & ficheropdf WAIT
Message.Info("Fichero generado en el escritorio")
END

PUBLIC SUB btnsalir_Click()

ME.Close

END

(13-13/18)