home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 April / CHIP_CD_2005-04.iso / software / netv / NVinst.exe / $INSTDIR / Scripts / Scripter / Searcher_PHP_Base.nvs < prev    next >
Encoding:
Text File  |  2005-02-22  |  5.1 KB  |  141 lines

  1. program Searcher_PHP_Base;
  2. {
  3. This program searchers *.FileList files created by NetSearcher.nvs script
  4. after every global hostlist recheck. It creates Online.*.txt and All.*.txt
  5. files in wich filelist information about only online and all hosts is placed
  6. in the following form:
  7. IPAddress1|Hostname1|FilePath1|FileName1|FileSize1|Flags1|FindTime1|SeenTime1
  8. IPAddress2|Hostname2|FilePath2|FileName2|FileSize2|Flags2|FindTime2|SeenTime2
  9. IPAddress3|Hostname3|FilePath3|FileName3|FileSize3|Flags3|FindTime3|SeenTime3
  10.  
  11. This files then can be used with PHP search engine and can be found in
  12. NetView\Scripts\ folder.
  13. Sample PHP search script can be found in NetView\searcher_php.zip file
  14. }
  15. function CreateMutex(notused:Longint; bInitialOwner:Longint; lpName: PChar): Longint; external 'CreateMutexA@kernel32.dll stdcall';
  16. function WaitForSingleObject(hHandle :Longint; dwMilliseconds:Longint): Longint; external 'WaitForSingleObject@kernel32.dll stdcall';
  17. function ReleaseMutex (hObject :Longint): Longint; external 'ReleaseMutex@kernel32.dll stdcall';
  18. function CloseHandle(hObject :Longint): Longint; external 'CloseHandle@kernel32.dll stdcall';
  19.  
  20. var mtx:longint;
  21.     hind,e,x,i1,i2,f1,f2,f3,j:integer;
  22.     s,s1,s2,s3,hname,fname:string;
  23.     hnames,lstips,lstnames,lstison:TStringList;
  24.     hst:TNVHost;
  25.     sr:TSearchRec;
  26.  
  27. procedure WorkFileList(FileListName:string);
  28. var mtxname:string;
  29. begin
  30. mtxname:='SearcherFileMutex_'+FileListName;
  31. mtx:=CreateMutex(0,1,pchar(mtxname));
  32. WaitForSingleObject(mtx,-1);
  33. f1:=OpenFile(FileListName,1);
  34. f2:=OpenFile('Online.'+FileListName+'.tmp',1+2+4+8);
  35. f3:=OpenFile('All.'+FileListName+'.tmp',1+2+4+8);
  36. if f1<>0 then
  37.     begin
  38.     s:='';
  39.     while(ReadFile(f1,1024,s1)<>0)do
  40.         begin
  41.         s:=s+s1;
  42.         x:=pos(chr(13)+chr(10),s);
  43.         while x<>0 do
  44.             begin
  45.             s2:=copy(s,1,x-1);delete(s,1,x+1);
  46.             x:=pos('|',s2);
  47.             if x<>0 then
  48.                 begin
  49.                 s1:=copy(s2,1,x-1);delete(s2,1,x);
  50.                 hname:=s1;
  51.                 if hname[1]='\' then
  52.                     begin
  53.                     j:=length(s1);
  54.                     while(j>1)and(s1[j]<>'\')do j:=j-1;
  55.                     fname:=copy(s1,j+1,length(s1)-j);
  56.                     delete(s1,j+1,length(s1)-j);
  57.                     delete(hname,1,2);
  58.                     x:=pos('\',hname);if x<>0 then delete(hname,x,length(hname)-x+1);
  59.                     end else
  60.                     begin
  61.                     j:=length(s1);
  62.                     while(j>1)and(s1[j]<>'/')do j:=j-1;
  63.                     fname:=copy(s1,j+1,length(s1)-j);
  64.                     delete(s1,j+1,length(s1)-j);
  65.                     delete(hname,1,6);
  66.                     x:=pos('/',hname);
  67.                     if x<>0 then delete(hname,x,length(hname)-x+1);
  68.                     end;
  69.  
  70.                 hind:=hnames.IndexOf(hname);
  71.                 if hind=-1 then
  72.                     begin
  73.                     hst.GetByText(hname,0);
  74.                     hnames.Add(hname);
  75.                     hind:=hnames.Count-1;
  76.                     if hst.id<>0 then
  77.                         begin
  78.                         lstnames.Add(hst.hname);
  79.                         lstips.Add(hst.hip);
  80.                         if hst.GetMetaVar('ison')='off' then lstison.Add('-')
  81.                                                         else lstison.Add('+');
  82.                         end else
  83.                         begin
  84.                         lstnames.Add(hname);
  85.                         lstips.Add('');
  86.                         lstison.Add('+');
  87.                         end;
  88.                     end;
  89.  
  90.                 s3:=lstips.Strings[hind]+'|'+lstnames.Strings[hind]+'|'+s1+'|'+fname+'|'+s2+chr(13)+chr(10);
  91.                 if lstison.Strings[hind]='+' then writefile(f2,s3);
  92.                 writefile(f3,s3);
  93.             end;
  94.         x:=pos(chr(13)+chr(10),s);
  95.         end;
  96.     end;
  97. end;
  98. CloseFile(f1);CloseFile(f2);CloseFile(f3);
  99.  
  100. DeleteFile('All.'+FileListName+'.txt');
  101. MoveFile('All.'+FileListName+'.tmp','All.'+FileListName+'.txt');
  102. DeleteFile('Online.'+FileListName+'.txt');
  103. MoveFile('Online.'+FileListName+'.tmp','Online.'+FileListName+'.txt');
  104.  
  105. ReleaseMutex(mtx);
  106. CloseHandle(mtx);
  107. end;
  108.  
  109. begin
  110. hnames:=TStringList.Create;
  111. lstips:=TStringList.Create;
  112. lstnames:=TStringList.Create;
  113. lstison:=TStringList.Create;
  114. hst:=TNVHost.Create;
  115. SetStatus('Idle');
  116.     repeat
  117.     e:=waitevent(i1,i2);
  118.         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
  119.         begin
  120.         if FindFirst('*.FileList',sr)=0 then
  121.             begin
  122.             hnames.Clear;
  123.             lstips.Clear;
  124.             lstnames.Clear;
  125.             lstison.Clear;
  126.                 repeat
  127.                 SetStatus(sr.Name);
  128.                 WorkFileList(sr.Name);
  129.                 until FindNext(sr)<>0;
  130.             FindClose(sr);
  131.             SetStatus('Idle');
  132.             end;
  133.         end;
  134.     until e=0;
  135. hnames.Free;
  136. lstips.Free;
  137. lstnames.Free;
  138. lstison.Free;
  139. hst.Free;
  140. end.
  141.