'<%
'*****************************************************************************************
'***** Script uses DUMPEL.EXE and converts its Date and Time format
'*****  Autore: Stefano Fronte
'*****  Data: 28.03.2007
'*****
'*****  Descrizione attivitą:
'*****  Lo script effettua il backup del file di log security di sistema archiviati da windows 
'*****  trasformandolo nel formato richiesto da LogCollector e riposizionandoli nella cartella definita.
'*****
'*****************************************************************************************

'***** Inizio Script
option Explicit

'***** Definizione Costanti
Const ForReading = 1							'***** Parametro apertura File in Lettura
Const ForWriting = 2							'***** Parametro apertura File in Scrittura
Const ForAppend = 8								'***** Parametro apertura File in Accodamento
Const PathDest = "C:\LogLCI\"					'***** Dati importati per lettura path 
Const Piattaforma = "COP."
Const LogConstDest = ".ACCESSLOG."
Const FineDest = ".Log"

'***** Definizione Variabili
dim Path										'***** Path Script
dim test, a, c									'***** Variabili per le subroutine
dim FileDest							'***** Contiene il nome completo del file (con il path)
dim WshShell, WshNetwork	'***** Variabili per la gestione dei file
dim cmd											'***** Variabile comando dos
dim hostname

'***** Corpo Script


'***** Inizializzazione Metodi
set WshShell = Wscript.CreateObject("Wscript.shell")
set WshNetwork = Wscript.CreateObject("Wscript.Network")

'***** Inizializzazione Variabili
Path = ScriptPath
test=0
Hostname = WshNetwork.computername 


FileDest = PathDest	& Piattaforma & Hostname & LogConstDest & FormatoData(6) & "_" & FormatoOra(1) & FineDest '***** Costruzione del nome del file destinazione

cmd= pathdest & "dumpel -f " & FileDest & "  -l security -d 1"
WshShell.Run "%comspec% /c " & cmd, 0, True



'***** Funzioni
Function ScriptPath  ' La funzione restituisce il percorso da cui si esegue lo script
	Dim PathScript
	PathScript = Wscript.ScriptFullName
	ScriptPath = Left (PathScript, InStrRev(PathScript, "\"))
End Function

Function FormatoData (a) ' La funzione restituisce la data di oggi nel formato richiesto
dim anno, mese, giorno
	anno = right (Year(date), 2)
	IF Month(Date) < 10 then
		mese = "0" & Month(Date)
		else 
		mese = Month(Date)
	End If
	If Day(Date-1) < 10 then 
		giorno = "0" & Day(Date)
		else 
		giorno = Day(Date)
	End If
	IF a >=1 and a <=9 then
		Select Case a 
			Case 1
				FormatoData= anno & mese & giorno
		    Case 2
			    FormatoData= anno & "-" & mese & "-" & giorno
			Case 3
				FormatoData= giorno & mese & anno
			Case 4
				FormatoData= giorno & "-" & mese & "-" & anno
			Case 5
				FormatoData= Year(date) & mese & giorno
			Case 6
				FormatoData= Year(date) & "-" & mese & "-" & giorno
			Case 7
				FormatoData= giorno & mese & Year(date)
			Case 8
				FormatoData= giorno & "-" & mese & "-" & Year(date)
			Case 9
				FormatoData= ""
			Case Else
				FormatoData= "ERRORE DI CONVERSIONE DATA"
		End Select
	Else
		FormatoData= "ERRORE DI CONVERSIONE DATA"
	End If
	anno=""
	mese=""
	giorno=""
End Function

Function FormatoOra (c) ' La funzione restituisce la data di oggi nel formato richiesto
dim ora, minuti, secondi
	IF Hour(Time) < 10 then
		ora = "0" & Hour(Time)
		else 
		ora = Hour(Time)
	End If
	IF minute(Time) < 10 then
		minuti = "0" & minute(Time)
		else 
		minuti = minute(Time)
	End If
	IF second(Time) < 10 then
		secondi = "0" & second(Time)
		else 
		secondi = second(Time)
	End If
	IF c >=1 and c <=1 then
		Select Case c 
			Case 1
				FormatoOra= ora & "-" & minuti & "-" & secondi
			Case Else
				FormatoOra= "ERRORE DI CONVERSIONE ora"
		End Select
	Else
		FormatoOra= "ERRORE DI CONVERSIONE ORA"
	End If
	ora=""
	minuti=""
	secondi=""
End Function
'***** Fine funzioni
'***** Fine script