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
- }
- {
- WebCenter NetSearch helper script
- }
-
- const LOW_PRIORITY=true; //Set to true to prevent script from consuming much
- //CPU while processing filelists
-
-
- 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';
- function SetThreadPriority(hThread:Longint;nPriority:integer): Longint; external 'SetThreadPriority@kernel32.dll stdcall';
- function GetCurrentThread: Longint; external 'GetCurrentThread@kernel32.dll stdcall';
-
- procedure WorkFileList(FileListName:string;var OnlineHosts,OfflineHosts:TStringList);
- var mtxname,s,s1,s2,s3,host,fname:string;
- mtx:longint;
- f1,f2,f3, x,j:integer;
- ison:boolean;
- hst:TNVHost;
- 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
- SetLength(s,0);
- while ReadFile(f1,32768,s1)<>0 do
- begin
- s:=s+s1;
- x:=pos(#13#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);
- host:=s1;
- j:=length(s1);
- if host[1]='\' then
- begin
- 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(host,1,2);
- x:=pos('\',host);
- end else
- begin
- 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(host,1,6);
- x:=pos('/',host);
- end;
- if x<>0 then delete(host,x,length(host)-x+1);
-
- if OnlineHosts.Find(LowerCase(host),j) then
- begin
- hst:=TNVHost(OnlineHosts.Objects[j]);
- ison:=true;
- end else if OfflineHosts.Find(LowerCase(host),j) then
- begin
- hst:=TNVHost(OfflineHosts.Objects[j]);
- ison:=false;
- end else
- begin
- hst:=nil;
- ison:=false;
- end;
- if hst<>nil then s3:=hst.hip+'|'+hst.hname+'|'+s1+'|'+fname+'|'+s2+#13#10
- else s3:='|'+host+'|'+s1+'|'+fname+'|'+s2+#13#10;
- if ison then writefile(f2,s3);
- writefile(f3,s3);
- end;
- x:=pos(#13#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;
-
- procedure InitHosts(var OnlineHosts,OfflineHosts,AllHosts:TStringList);
- var hst:TNVHost;
- nextId:integer;
- begin
- nextId:=0;
- repeat
- hst:=TNVHost.Create;
- hst.gethost(nextId,0);
- if hst.id<>0 then
- begin
- nextId:=hst.nextId;
- if hst.GetMetaVar('ison')<>'off' then
- begin
- OnlineHosts.AddObject(LowerCase(hst.hname),hst);
- if length(hst.hip)<>0 then OnlineHosts.AddObject(hst.hip,hst);
- end else
- begin
- OfflineHosts.AddObject(LowerCase(hst.hname),hst);
- if length(hst.hip)<>0 then OfflineHosts.AddObject(hst.hip,hst);
- end;
- AllHosts.AddObject('',hst);
- end else
- begin
- hst.Free;
- nextId:=hst.nextId;
- end;
- until nextId=0;
- end;
-
- procedure ClearHosts(var OnlineHosts,OfflineHosts,AllHosts:TStringList);
- var i:integer;
- begin
- if AllHosts.Count>0 then
- begin
- for i:=0 to AllHosts.Count-1 do
- TNVHost(AllHosts.Objects[i]).Free;
- AllHosts.Clear;
- OnlineHosts.Clear;
- OfflineHosts.Clear;
- end;
- end;
-
- var OnlineHosts,OfflineHosts,AllHosts,ProcessedFiles:TStringList;
- e,i1,i2:integer;
- sr:TSearchRec;
- begin
- ProcessedFiles:=TStringList.Create;
- OnlineHosts:=TStringList.Create;
- OfflineHosts:=TStringList.Create;
- AllHosts:=TStringList.Create;
- OnlineHosts.Sorted:=true;
- OfflineHosts.Sorted:=true;
- ProcessedFiles.Sorted:=true;
- ProcessedFiles.CaseSensitive:=false;
-
- if LOW_PRIORITY then SetThreadPriority(GetCurrentThread,-2);
-
- 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
- InitHosts(OnlineHosts,OfflineHosts,AllHosts);
- repeat
- SetStatus(sr.Name);
- WorkFileList(sr.Name,OnlineHosts,OfflineHosts);
- ProcessedFiles.Add(sr.Name);
- until FindNext(sr)<>0;
- ClearHosts(OnlineHosts,OfflineHosts,AllHosts);
- FindClose(sr);
- SetStatus('Idle');
- end;
- ProcessedFiles.SaveToFile(nv_directory+'Scripts\SearcherProcessedFiles.lst');
- ProcessedFiles.Clear;
- end;
- until e=0;
-
- OnlineHosts.Free;
- OfflineHosts.Free;
- AllHosts.Free;
- ProcessedFiles.Free;
- end.
-