Public feed #893512

Untitled

public text v1 · immutable
Raw Edit
·published 2008-02-06 04:43 UTC
rendered paste body
#include<guiconstants.au3>
#include <File.au3>
#include <Array.au3>
opt("GUIOnEventMode",1)
Opt("OnExitFunc","onautoitexit")


;~ If ProcessExists(@ScriptName) then processclose(@ScriptName)
HotKeySet("{ESC}","escape")

$sFlagString	=	"status"															;Flag string to look for in sourcefile
$sBinPath 		=	iniread(StringTrimRight(@ScriptName,3)&"ini","PATH","BIN","")		;Path to the Modacl, Reacl and Pracl executables.
$sSourceDir 	=	iniread(StringTrimRight(@ScriptName,3)&"ini","PATH","SOURCE","")	;Path to the RVI Logs to be Parsed
$sTargetDir 	=	iniread(StringTrimRight(@ScriptName,3)&"ini","PATH","TARGET","")	;Path to the folders to be modded
$sIndexDir  	=	iniread(StringTrimRight(@ScriptName,3)&"ini","PATH","INDEX","")		;Path to the index folder (for use of this script only).
$Logfilepath	=	iniread(StringTrimRight(@ScriptName,3)&"ini","PATH","LOG","")

$sSourcefile	=	iniread(StringTrimRight(@ScriptName,3)&"ini","FILES","SOURCEFILE","")
$Logfilename	=	iniread(StringTrimRight(@ScriptName,3)&"ini","FILES","LOGFILE","")
$sNameConvFile 	=	iniread(StringTrimRight(@ScriptName,3)&"ini","FILES","NAMES","")		;Path to the ID to Name convertion file.
$sEmailTarget   = 	iniread(StringTrimRight(@ScriptName,3)&"ini","EMAIL","TO","")

$sBinPath		= 	_checkpath($sBinPath)
$sSourceDir 	= 	_checkpath($sSourceDir)
$sTargetDir 	= 	_checkpath($sTargetDir)
$sIndexDir  	=	_checkpath($sIndexDir)
$sNameConvFile 	= 	_checkpath($sNameConvFile)
$Logfilepath	=	_checkpath($Logfilepath)
$lines = 0
dim $aHasFile[1], $atest[1],$aOFOID2NAmes
_FileReadToArray($sNameConvFile,$aOFOID2NAmes)
logmessage("********************")
logmessage("Starting RVI Service"& _NowDate() & " " & _NowTime())
logmessage("********************")
;~ $edit = GUIMake("test")
;~ 	global $main = GUICreate("test", 400,300,default,default)
;~ 	$edit = GUICtrlCreateEdit("",0,0,300,250,$WS_DISABLED)
;~ 	GUISetState(@sw_show)
while 1
	$afolderList = _scanFolder($sSourceDir)
	For $x  = 1 to UBound($afolderList)-1
		$sfilecontents 	= 	''
		$atest			= 	''
		$statusflag		=	''
		if _ArraySearch($aHasFile,$afolderList[$x]) = -1 Then										; If the current folder (OFOID) is not in the $aHasFileArray
				if FileExists($sSourcedir &'\'& $afolderList[$x] & '\' & $sSourcefile) then 			; If the $sSourcefile exists then 
					_ArrayAdd($aHasFile,$afolderList[$x])													;	add the current userlog directory to the $ahasafile Array 
					logmessage("added " & $afolderList[$x] & " to list @" & _nowdate() & " " & _nowtime() &@crlf)	;	Send String to Logmessage Function
					$sfilecontents = FileRead($sSourcedir &'\'& $afolderList[$x] & '\' & $sSourcefile)		; 	Read contents for current sourcefile to file contents
					if StringInStr($sfilecontents,$sFlagString&"=",0) then 	
						$atest = StringRegExp($sfilecontents,'(?i)'&$sFlagString&'\=[a-z]*',1)
						$statusflag = StringLower(StringTrimLeft($atest[ubound($atest)-1],7))
						logmessage("User " & $afolderList[$x]& " is status " &$statusflag& @crLF)
						_processflag($statusFlag, $afolderList[$x])
						
					EndIf
				EndIf	
			EndIf
	Next
sleep(200)
WEnd

Func _checkpath($sX)
	If $sX <> "" then 
		Select 
			Case stringleft($sX,2) = "\\" 
				Return $sX
			Case StringMid($sX, 2, 2)= ":\" 			
				Return $sX
			Case Else
				Return FileGetLongName(@scriptdir & "\" & $sX)
		EndSelect
	Else
		MsgBox(0,"Error","String is Empty")
	EndIf
EndFunc

Func _scanFolder($sFolder)
	return _FileListToArray($sFolder, '*', 2)
EndFunc

Func _processflag($sFlag, $userid)
	select 
		case $sFlag = "success"
			enableTR($userid)
		case $sFlag = "failed"
			
		case Else
			
	EndSelect
EndFunc

Func enableTR($userid)
	
	if StringIsInt(GetName($userid))=0 Then
		if fileexists($sTargetDir&"\"&GetName($userid)) then
			if fileexists($sTargetDir&"\"&GetName($userid)&"\"&"rvi.txt") Then
				$ret = filedelete($sTargetDir&"\"&GetName($userid)&"\"&"rvi.txt")
				if $ret <> 1 then 
					$string = "could not delete rvi.txt file for " 
				Else
					$string = "rvi.txt file has been deleted for" 
				EndIf
			Else
				$string = "rvi.txt not present for : "
			EndIf
		else
			$string = "Target folder not present for : "
		EndIf
	Elseif StringIsInt(GetName($userid)) then
		$String= "User not in database, please assist."
	EndIf
	$string = $string & $userid & " " & GetName($userid)
	logmessage($string)
	email($userid,$string,"RVI Completed")
EndFunc

func logmessage($sString)
	$fFile = $Logfilepath & '\' & $Logfilename
	filewriteline($fFile,$sString)
EndFunc

;~ Title:			GetName
;~ Description:		Returns the Target Folder name given an OFOID.
Func GetName($ID)
	$aIndex = _ArraySearch($aOFOID2NAmes,$ID,1,0,0,1)
	if $aIndex <> -1 Then
		$iStringPos = StringInStr($aOFOID2NAmes[$aIndex],"=")
		Return StringMid($aOFOID2NAmes[$aIndex],$iStringPos+1)
	EndIf
EndFunc

Func email($ID, $body, $subject )
	$name=GetName($id)
	RunWait(@ComSpec & ' /c ' &'blat -body "'&$body&'" -attach '&$sSourceDir&"\"&$id&"\"&$sSourcefile &' -s "User '&$ID& "/"&$name&' '&$subject&'" -bcc "'& $sEmailTarget &'" -server 146.142.32.37 -f RVI_Service ',$sBinPath,@SW_HIDE)
EndFunc

Func _NowTime()
	return @HOUR &":"& @MIN &":"& @SEC
EndFunc

Func _nowdate()
	return @MON & '/' & @MDAY & '/' &@YEAR
EndFunc

Func escape()
	Exit
endFunc

Func onautoitexit()
	logmessage("Stoping RVI Service" & _NowDate() & " " & _NowTime())
	logmessage("********************")
endFunc