CODE
----------------------------------------------------------------------------------------------------------
-- Name: SymantecAVDefs.lua
-- Author: Intellipool AB
-- Required INM version: 3.0.5
-- Version: 1.0
-- Date: 2006-03-06
-- Description: Checks if Symantec AV definition files is uptodate
-- Arguments:
-- Name and path to ini file
-- Max age in days
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
-- Creates a table of all lines ending with CR in the text file
function MakeTable(s)
local sInData = s;
iLastPos = 0;
t = {};
max = string.len(sInData);
for count = 0, max do
cCharacter = string.byte(sInData,count);
if cCharacter == 10 then
local sTemp = string.sub(sInData,iLastPos,count-1);
table.insert(t,sTemp);
iLastPos = count+1;
end
end
return t;
end
----------------------------------------------------------------------------------------------------------
-- Start
sFileName = GetArgument(0);
iMaxDaysOld = tonumber(GetArgument(1));
File = TLuaFile:new();
iLength = File:GetFileSize(sFileName);
if File:Open(sFileName) == 0 then
SetExitStatus("Cant open AV definition file",false);
File:Close();
return;
end
Data = "";
Data,iLength = File:Read(iLength);
if iLength==0 then
SetExitStatus("AV definition file is empty",false);
File:Close();
return;
end
File:Close();
StringTable = MakeTable(Data);
----------------------------------------------------------------------------------------------------------
-- Find the line with "CurDefs"
nTableMax = table.getn(StringTable);
if nTableMax == 0 then
SetExitStatus("Failed to parse AV file",false);
return;
end
-- Parse table
for count=1, nTableMax do
sTemp = StringTable[count];
if string.find(sTemp,"DefDates]") ~= nil then
sCurDefs = StringTable[count+1];
sCurDefs = string.sub(sCurDefs,-13);
sCurDefs = string.sub(sCurDefs,1,8);
sYear = string.sub(sCurDefs,1,4);
sMonth = string.sub(sCurDefs,5,6);
sDay = string.sub(sCurDefs,7,8);
-- Got a date
DateInFile = TLuaDateTime:new();
DateInFile:Create(tonumber(sYear),tonumber(sMonth),tonumber(sDay),0,0,0);
DateSpan = TLuaDateTime:new();
DateSpan:CreateSpan(iMaxDaysOld*24,0,0);
DateInFile:Add(DateSpan);
currentTime = TLuaDateTime:new()
if currentTime:Less(DateInFile) == false then
SetExitStatus("AV definition file is out of date",false);
return;
else
SetExitStatus("AV definition file is up to date",true);
return;
end
end
end
SetExitStatus("CurDefs not found in AV definition file",false);
-- Name: SymantecAVDefs.lua
-- Author: Intellipool AB
-- Required INM version: 3.0.5
-- Version: 1.0
-- Date: 2006-03-06
-- Description: Checks if Symantec AV definition files is uptodate
-- Arguments:
-- Name and path to ini file
-- Max age in days
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
-- Creates a table of all lines ending with CR in the text file
function MakeTable(s)
local sInData = s;
iLastPos = 0;
t = {};
max = string.len(sInData);
for count = 0, max do
cCharacter = string.byte(sInData,count);
if cCharacter == 10 then
local sTemp = string.sub(sInData,iLastPos,count-1);
table.insert(t,sTemp);
iLastPos = count+1;
end
end
return t;
end
----------------------------------------------------------------------------------------------------------
-- Start
sFileName = GetArgument(0);
iMaxDaysOld = tonumber(GetArgument(1));
File = TLuaFile:new();
iLength = File:GetFileSize(sFileName);
if File:Open(sFileName) == 0 then
SetExitStatus("Cant open AV definition file",false);
File:Close();
return;
end
Data = "";
Data,iLength = File:Read(iLength);
if iLength==0 then
SetExitStatus("AV definition file is empty",false);
File:Close();
return;
end
File:Close();
StringTable = MakeTable(Data);
----------------------------------------------------------------------------------------------------------
-- Find the line with "CurDefs"
nTableMax = table.getn(StringTable);
if nTableMax == 0 then
SetExitStatus("Failed to parse AV file",false);
return;
end
-- Parse table
for count=1, nTableMax do
sTemp = StringTable[count];
if string.find(sTemp,"DefDates]") ~= nil then
sCurDefs = StringTable[count+1];
sCurDefs = string.sub(sCurDefs,-13);
sCurDefs = string.sub(sCurDefs,1,8);
sYear = string.sub(sCurDefs,1,4);
sMonth = string.sub(sCurDefs,5,6);
sDay = string.sub(sCurDefs,7,8);
-- Got a date
DateInFile = TLuaDateTime:new();
DateInFile:Create(tonumber(sYear),tonumber(sMonth),tonumber(sDay),0,0,0);
DateSpan = TLuaDateTime:new();
DateSpan:CreateSpan(iMaxDaysOld*24,0,0);
DateInFile:Add(DateSpan);
currentTime = TLuaDateTime:new()
if currentTime:Less(DateInFile) == false then
SetExitStatus("AV definition file is out of date",false);
return;
else
SetExitStatus("AV definition file is up to date",true);
return;
end
end
end
SetExitStatus("CurDefs not found in AV definition file",false);
