home *** CD-ROM | disk | FTP | other *** search
- program Searcher_PHP_Base;
- {
- This program searchers *.FileList files created by NetSearcher.nvs script
- after every global hostlist recheck. It creates Online.*.txt and All.*.txt
- files in wich filelist information about only online and all hosts is placed
- in the following form:
- IPAddress1|Hostname1|FilePath1|FileName1|FileSize1|Flags1|FindTime1|SeenTime1
- IPAddress2|Hostname2|FilePath2|FileName2|FileSize2|Flags2|FindTime2|SeenTime2
- IPAddress3|Hostname3|FilePath3|FileName3|FileSize3|Flags3|FindTime3|SeenTime3
-
- This files then can be used with PHP search engine and can be found in
- NetView\Scripts\ folder.
- Sample PHP search script can be found in NetView\searcher_php.zip file
- }
- function CreateMutex(notused:Longint; bInitialOwner:Longint; lpName: PChar): Longint; external 'CreateMutexA@kernel32.dll stdcall';
- function WaitForSingleObject(hHandle :Longint; dwMilliseconds:Longint): Longint; external 'WaitForSingleObject@kernel32.dll stdcall';
- function ReleaseMutex (hObject :Longint): Longint; external 'ReleaseMutex@kernel32.dll stdcall';
- function CloseHandle(hObject :Longint): Longint; external 'CloseHandle@kernel32.dll stdcall';
-
- var mtx:longint;
- hind,e,x,i1,i2,f1,f2,f3,j:integer;
- s,s1,s2,s3,hname,fname:string;
- hnames,lstips,lstnames,lstison:TStringList;
- hst:TNVHost;
- sr:TSearchRec;
-
- procedure WorkFileList(FileListName:string);
- var mtxname:string;
- begin
- mtxname:='SearcherFileMutex_'+FileListName;
- mtx:=CreateMutex(0,1,pchar(mtxname));
- WaitForSingleObject(mtx,-1);
- f1:=OpenFile(FileListName,1);
- f2:=OpenFile('Online.'+FileListName+'.tmp',1+2+4+8);
- f3:=OpenFile('All.'+FileListName+'.tmp',1+2+4+8);
- if f1<>0 then
- begin
- s:='';
- while(ReadFile(f1,1024,s1)<>0)do
- begin
- s:=s+s1;
- x:=pos(chr(13)+chr(10),s);
- while x<>0 do
- begin
- s2:=copy(s,1,x-1);delete(s,1,x+1);
- x:=pos('|',s2);
- if x<>0 then
- begin
- s1:=copy(s2,1,x-1);delete(s2,1,x);
- hname:=s1;
- if hname[1]='\' then
- begin
- j:=length(s1);
- while(j>1)and(s1[j]<>'\')do j:=j-1;
- fname:=copy(s1,j+1,length(s1)-j);
- delete(s1,j+1,length(s1)-j);
- delete(hname,1,2);
- x:=pos('\',hname);if x<>0 then delete(hname,x,length(hname)-x+1);
- end else
- begin
- j:=length(s1);
- while(j>1)and(s1[j]<>'/')do j:=j-1;
- fname:=copy(s1,j+1,length(s1)-j);
- delete(s1,j+1,length(s1)-j);
- delete(hname,1,6);
- x:=pos('/',hname);
- if x<>0 then delete(hname,x,length(hname)-x+1);
- end;
-
- hind:=hnames.IndexOf(hname);
- if hind=-1 then
- begin
- hst.GetByText(hname,0);
- hnames.Add(hname);
- hind:=hnames.Count-1;
- if hst.id<>0 then
- begin
- lstnames.Add(hst.hname);
- lstips.Add(hst.hip);
- if hst.GetMetaVar('ison')='off' then lstison.Add('-')
- else lstison.Add('+');
- end else
- begin
- lstnames.Add(hname);
- lstips.Add('');
- lstison.Add('+');
- end;
- end;
-
- s3:=lstips.Strings[hind]+'|'+lstnames.Strings[hind]+'|'+s1+'|'+fname+'|'+s2+chr(13)+chr(10);
- if lstison.Strings[hind]='+' then writefile(f2,s3);
- writefile(f3,s3);
- end;
- x:=pos(chr(13)+chr(10),s);
- end;
- end;
- end;
- CloseFile(f1);CloseFile(f2);CloseFile(f3);
-
- DeleteFile('All.'+FileListName+'.txt');
- MoveFile('All.'+FileListName+'.tmp','All.'+FileListName+'.txt');
- DeleteFile('Online.'+FileListName+'.txt');
- MoveFile('Online.'+FileListName+'.tmp','Online.'+FileListName+'.txt');
-
- ReleaseMutex(mtx);
- CloseHandle(mtx);
- end;
-
- begin
- hnames:=TStringList.Create;
- lstips:=TStringList.Create;
- lstnames:=TStringList.Create;
- lstison:=TStringList.Create;
- hst:=TNVHost.Create;
- SetStatus('Idle');
- repeat
- e:=waitevent(i1,i2);
- if((e=NMNP_ACTION)and((i1 and NVACTION_RECHECK)<>0)and((i1 and NVACTION_LIST)<>0))or((e=NMNP_ALERT)and(i1=NVALERT_NETSEARCHER))then
- begin
- if FindFirst('*.FileList',sr)=0 then
- begin
- hnames.Clear;
- lstips.Clear;
- lstnames.Clear;
- lstison.Clear;
- repeat
- SetStatus(sr.Name);
- WorkFileList(sr.Name);
- until FindNext(sr)<>0;
- FindClose(sr);
- SetStatus('Idle');
- end;
- end;
- until e=0;
- hnames.Free;
- lstips.Free;
- lstnames.Free;
- lstison.Free;
- hst.Free;
- end.
-