/* ***********************IMPORTANT *********************************************
 *  Copyright (C) 2004-2007 Thierry Lagarde <tlagarde@users.sourceforge.net>
 *  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.
 *
 *
 *                      ********************
 *
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *
 *                      ********************
 *
 *
 * You are highly encouraged to send your changes to <tlagarde@users.sourceforge.net>
 * for possible incorporation into the main distribution.
 * By sending these changes to <tlagarde@users.sourceforge.net>,
 * it is assumed that you are offering <tlagarde@users.sourceforge.net>
 * the unlimited, non-exclusive right to reuse, modify, and relicense the code.
 *
 *
 *                      ********************
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **************************************************************************************/
#ifndef         __EQUIPEMENT
#define         __EQUIPEMENT

#include <gtk/gtk.h>
#include <errno.h>
#include <time.h>
#include "Reseau.h"
#include "crypt-md5.h"
#include "Declaration_Constante.h"

#define NB_SCAN_OS 15
#define NUM_MAX_REGISTRATION 25
#define IP_ADDR_LEN	4
#define MAC_ADDR_LEN 6
#define REGISTRATION_GROUP 1
#define REGISTRATION_UNIQUE 2
#define PORT_TELNET 23
#define PORT_SSL 22
#define PORT_SAMBA 139

GList    *GList_Equipement_Cours_Affichage; 

enum enum_Nessus {
	INFO_NIVEAU_NESSUS = 0,
	NOTE_NIVEAU_NESSUS,
	HOLE_NIVEAU_NESSUS
};
enum enum_ID_Snmp_Liste {
	SNMP_SYSTEM_LOGICAL_STORAGE = 0,
	SNMP_SOFTWARE,
	SNMP_NETWORK_TCPIP_TCP_CONNECTIONS,
	SNMP_NETWORK_ROUTES,
	SNMP_NETWORK_ARP,
	SNMP_SYSTEM_DEVICE,
	SNMP_SYSTEM_SERVICE,
	SNMP_NETWORK_INTERFACES_BASIC,
	SNMP_NETWORK_TCPIP_UDP_SERVICES,
	SNMP_BRIDGE_FORWARDING_DATABASE,
	SNMP_BRIDGE_STATIC_DATABASE,
	NB_ID_SNMP_LISTE
};


struct Struct_Nessus {
	gint      Niveau_Nessus;
	gchar    *Info;
	gchar    *Texte;
};

struct struct_Reponse {
	unsigned char TaillePacketReponse;
	
	unsigned char HeaderLengthIP;
	unsigned char DSF;
	unsigned short TailleTotal;
	unsigned char Id;
	unsigned short Flags_IP_Offset;
	unsigned char TTL;
	
	unsigned char NumSeq;
	unsigned char HeaderLengthTCP;
	unsigned char Flags_TCP;
	unsigned short WindowSize;
};


struct struct_Reponse_debug{
	 
	gint      Num_Port_Utiliser;  
	time_t64  Time_Debut;  
	time_t64  Time_Fin;  
	gint  Temps_Reponse; 
};

struct Struct_Liste_Port_UDP {
	gint      Id_Port_UDP;
	gint 	  Num_Port_UDP;	
};


enum enum_Port_UDP {
	DHCPC = 0,
	SVRLOC,
	LISTENER,
	UPNP,
	SIP,
	ZEROCONF,
	NB_PORT_UDP
};


struct struct_Smb_Registration {
	unsigned char Type;
	unsigned char Name[16 + 1];
	unsigned char Numero;
};

struct struct_Smb {
	unsigned char HostName[16 + 1];
	unsigned char DomainName[16 + 1];
	unsigned char Utilisateur[16 + 1];
	struct struct_Smb_Registration Smb_Registration[NUM_MAX_REGISTRATION];
};

#define CHAINE_NORMALE 100
#define CHAINE_MAX 255
#define CHAINE_MINI 30
struct Struct_Snmp {

	gchar     System_Name[CHAINE_NORMALE];
	gchar     Description[CHAINE_MAX];
	gchar     Contact[CHAINE_NORMALE];
	gchar     Location[CHAINE_NORMALE];
	gchar     Uptime[CHAINE_NORMALE];
	gint      Ram;

	gchar     Ip_Forwarding[CHAINE_MINI];
	gint      Default_TTL;
	gint      Reassembly_Timeout;
	gint      Need_To_Be_Reassembled;
	gint      Reassembled;
	gint      Reassembly_Failures;
	gint      Successfully_Fragmented;
	gint      Fragmentation_Failures;
	gint      Created_Fragments;
	gint      Discarded_Routing_Entries;

	gint      All;
	gint      Forwarded;
	gint      Delivered;
	gint      Header_Errors;
	gint      Address_Errors;
	gint      Unknown_Protocol;
	gint      Input_Buffer_Errors;

	gint      Requested;
	gint      Output_Buffer_Errors;
	gint      Not_Routed;

	gint	  Mem_Total_Swap;
	gint	  Mem_Available_Swap;
	gint	  Mem_Total_Real;
	gint	  Mem_Available_Real;
	gint	  Mem_Total_Free;
	gint	  Mem_Shared;
	gint	  Mem_Buffer;
	gint	  Mem_Cached;
	gint	  Mem_Swap_Error;
	gchar	  Mem_Swap_Error_Message[CHAINE_NORMALE];

	gint	  Cpu_Raw_User;
	gint	  Cpu_Raw_Nice;
	gint	  Cpu_Raw_System;
	gint	  Cpu_Raw_Idle;
	gint	  Cpu_Raw_Wait;
	gint	  Cpu_Raw_Kernel;
	gint	  Cpu_Raw_Interrupt;
};

#define NB_MAX_LIGNE_LISTE_SNMP 30
#define ERROR_FTP "Error%20FTP%3A%20Connection%20refused"
#define ERROR_HTTP "Error%20HTTP%3A%20Connection%20refused"
#define ERROR_HTTPS "Error%20HTTPS%3A%20Connection%20refused"
#define ERROR_IMAP "Error%20IMAP%3A%20Connection%20refused"
#define ERROR_SMTP "Error%20SMTP%3A%20Connection%20refused"
#define ERROR_SSH "Error%20SSH%3A%20Connection%20refused"
#define ERROR_TELNET "Error%20TELNET%3A%20Connection%20refused"	

struct struct_Info_Liste_Snmp {
	gint      Colonne;
	gint      Ligne;
	gchar     Info[CHAINE_NORMALE];
};

struct Struct_Equipement {

	struct Struct_Modele_Objet *Objet_Liste_Par_Type; 
	struct Struct_Modele_Objet *Objet_Liste_Par_Ip; 
	unsigned char ID_Equipement[MAC_ADDR_LEN + IP_ADDR_LEN + 1];
	unsigned char Adresse_Ip_Char[15 + 1];
	unsigned char Adresse_MAC_Char[17 + 1];
	gboolean  Agent_AutoScan;
	gboolean  Equipement_Allumer;
	gboolean  Equipement_Erase;
	time_t64  Derniere_Modification_Etat_Equipement;
	gboolean  Notification_En_Cours;
	gboolean  Scan_Nessus_En_Cours;
	gboolean  Rafraichir_Equipement;
	GList    *GList_Port;
	GList    *GList_Port_Fermer;
	GList    *GList_Port_Firewall;
	gint	  Liste_Etat_Udp[NB_PORT_UDP]; 
	gint  	   Temps_Scan_Complet; 
	gint  	   Temps_Resolv_DNS;
	gint  Temps_Samba;
	int       Nb_Port_Total_Scanner;
	int       Nb_Port_Ouvert;
	int       Nb_Port_Fermer;
	int       Nb_Port_Firewaller;
	gint  Temps_Scan_Port;
	gint  Temps_Scan_Port_Udp;
	struct struct_Reponse Reponse_Signature[NB_SCAN_OS];
	struct struct_Reponse Reponse_Signature_W[NB_SCAN_OS];
	struct struct_Reponse_debug Reponse_Signature_Debug[NB_SCAN_OS];
	gchar    *Debug_Signature;
	char     *Entete_FTP;
	gint  		 Temps_Scan_Service_Ftp;
	char     *Entete_HTTP;
	gint  		 Temps_Scan_Service_Http;
	char     *Entete_HTTPS;
	gint  		 Temps_Scan_Service_Https;
	char     *Entete_IMAP;
	gint  		 Temps_Scan_Service_Imap;
	char     *Entete_SMTP;
	gint  		 Temps_Scan_Service_Smtp;
	char     *Entete_SSH;
	gint  		 Temps_Scan_Service_Ssh;	
	char     *Entete_TELNET;
	gint  		 Temps_Scan_Service_Telnet; 
	gchar     Md5_Signature[32 + 1];
	gchar     Md5_Signature_W[32 + 1];
	gchar	  *Fournisseur; 
	struct Struct_Signature *Signature;
	gint  Temps_Scan_Signature;
	struct struct_Smb Smb;
	gchar    *Alias;
	gchar    *Ping_Time;
	gchar    *Nom_DNS_Complet;
	gchar    *Nom_DNS;
	gchar    *User_Smb;
	gchar    *Password_Smb;
	gchar    *Partage_En_Cours;
	gchar    *Chemin_Samba_En_Cours;
	gchar    *Contact_Admin;
	gchar    *Localisation;
	gchar    *Num_Serie;
	gchar    *Num_Serie_Ecran;
	gchar    *Num_Serie_Imprimante;
	gchar    *Num_Serie_OS;
	gchar    *Num_Serie_Office_Suite;
	gchar    *Processeur;
	gchar    *Memoire;
	gchar    *Disque;
	gchar    *Contact;
	gchar    *Tel_Contact;
	gchar    *Notes;
	GList    *GList_Nessus;
	struct Struct_Nessus *Nessus_En_Cours;
	GList    *GList_Historique;
	gboolean  Snmp_Ouvert;
	struct Struct_Snmp Snmp;
	gchar	*Snmp_Info_Device;
	gint  Temps_Scan_Snmp;
	GList    *Glist_Snmp[NB_ID_SNMP_LISTE];
	gchar	 *Snmp_Device;
	gchar	 *PortUdpListe;
	gchar	 *PortOuvertListe;
	gchar	 *PortFermerListe;
	gchar	 *PortFirewallerListe;
	gboolean  Intrus;
	gboolean  Alert_Notification_En_Cours;
	gboolean  GateWay;
	gboolean  Routage;
	gboolean  Deplier;
};


struct Struct_Equipement *Equipement_Selectionner;

void      Sauve_Etat_Deplier_Objet_Equipement (struct Struct_Liste_Reseau *Reseau);
void      Retour_Modification_Etat_Equipement (gpointer * Donnee);
struct Struct_Modele_Objet *Afficher_Nouveau_Equipement (struct Struct_Equipement *Equipement, gint ID_Reseau);
void      Retour_Info (gpointer * Donnee);
void      Retour_Alerte_Intrusion (gpointer * Donnee);
struct Struct_Modele_Objet *Recherche_Objet_Equipement (unsigned char *ID_Equipement, gint ID_Reseau);
void      Retour_Notification_Equipement (gpointer * Donnee);
void      Debug_ID_Equipement (unsigned char *ID_Equipement);
void      Parcours_Equipement_Inconnu (gchar * Signature);
gchar    *Debug_Signature_Equipement (struct Struct_Equipement *Equipement);
void      Copie_Icone_Equipement (gpointer * pointeur);
char     *url_encode (char *source);
void      Recuperation_Nouveau_Equipement (gpointer * Donnee);
void      Initialisation_Equipement (void);
struct Struct_Modele_Objet *Afficher_Nouveau_Equipement_Liste_Detaille (struct Struct_Equipement *Equipement, gint ID_Reseau);
void      Restore_Different_Etat_Equipement (struct Struct_Equipement *Equipement, struct Struct_Modele_Objet *Objet_Equipement, gint ID_Reseau);
void      Retour_Rafraichir_Equipement (gpointer * Donnee);
void      Deplace_Equipement (struct Struct_Modele_Objet *Objet, struct Struct_Liste_Reseau *Reseau);
void      Equipement_Ip_Retrouver (gpointer * Donnee);
void      Equipement_Ip_Perdu (gpointer * Donnee);
void      Modifie_Coloration_Text_Equipement (struct Struct_Liste_Reseau *Reseau, struct Struct_Equipement *Equipement);
void      Equipement_Ip_Modifier (gpointer * Donnee);
void Retour_Rafraichir_Nom_Utilisateur (gpointer * Donnee);
void Affiche_Nouveau_Equipement (gpointer * Donnee);
void Optimisation_Info_Equipement(struct Struct_Equipement *Equipement);
gchar    *Get_Key_Signature_Equipement (struct Struct_Equipement * Equipement);
gboolean check_entete_valide(struct Struct_Equipement *Equipement);
#endif
