home *** CD-ROM | disk | FTP | other *** search
- program DeleteTooOldHosts;
-
- {
- This script deletes hosts that was not in online state more than
- specified by users cound of days.
- It does it once on start.
- }
-
- var hst:TNVHost;
- lchtm,strMaxDeltaDays:string;
- year,month,day,hour,min,sec:cardinal;
- dtm:TDateTime;
- MaxDeltaDays,NextId:cardinal;
- begin
- strMaxDeltaDays:=ReadIni('DeleteTooOldHosts.nvs','MaxDeltaDays','10');
- if InputQuery('Delete old hosts','Enter max days count of host being offline:',strMaxDeltaDays) then
- begin
- MaxDeltaDays:=StrToIntDef(strMaxDeltaDays,10);
- hst:=TNVHost.create;
- NextId:=0;
- repeat
- hst.GetHost(NextId,0);
- NextId:=hst.nextid;
- if hst.id<>0 then
- begin
- if hst.GetMetaVar('ison')='off' then
- begin
- lchtm:=hst.GetMetaVar('lchtm');
- if length(lchtm)=19 then
- begin
- try
- hour:=StrToInt(copy(lchtm,1,2));
- min:=StrToInt(copy(lchtm,4,2));
- sec:=StrToInt(copy(lchtm,7,2));
- year:=StrToInt(copy(lchtm,10,4));
- month:=StrToInt(copy(lchtm,15,2));
- day:=StrToInt(copy(lchtm,18,2));
- dtm:=EncodeDateTime(year,month,day,hour,min,sec,0);
- if DaysBetween(dtm,Now)>MaxDeltaDays then hst.DelHost;
- except
- end;
- end;
- end;
- end;
- until NextId=0;
- hst.Free;
- WriteIni('DeleteTooOldHosts.nvs','MaxDeltaDays',IntToStr(MaxDeltaDays));
- end;
- end.
-