home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2007 April / PCpro_2007_04.ISO / files / dsl / NVinst.exe / Scripts / Scripter / Searcher_PHP_Base.nvs < prev    next >
Encoding:
Text File  |  2007-02-10  |  5.7 KB  |  194 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. {
  16. WebCenter NetSearch helper script
  17. }
  18.  
  19. const LOW_PRIORITY=true; //Set to true to prevent script from consuming much
  20.                           //CPU while processing filelists
  21.  
  22.  
  23. function CreateMutex(notused:Longint; bInitialOwner:Longint; lpName: PChar): Longint; external 'CreateMutexA@kernel32.dll stdcall';
  24. function WaitForSingleObject(hHandle :Longint; dwMilliseconds:Longint): Longint; external 'WaitForSingleObject@kernel32.dll stdcall';
  25. function ReleaseMutex (hObject :Longint): Longint; external 'ReleaseMutex@kernel32.dll stdcall';
  26. function CloseHandle(hObject :Longint): Longint; external 'CloseHandle@kernel32.dll stdcall';
  27. function SetThreadPriority(hThread:Longint;nPriority:integer): Longint; external 'SetThreadPriority@kernel32.dll stdcall';
  28. function GetCurrentThread: Longint; external 'GetCurrentThread@kernel32.dll stdcall';
  29.  
  30. procedure WorkFileList(FileListName:string;var OnlineHosts,OfflineHosts:TStringList);
  31. var mtxname,s,s1,s2,s3,host,fname:string;
  32.     mtx:longint;
  33.     f1,f2,f3, x,j:integer;
  34.     ison:boolean;
  35.     hst:TNVHost;
  36. begin
  37. mtxname:='SearcherFileMutex_'+FileListName;
  38. mtx:=CreateMutex(0,1,pchar(mtxname));
  39. WaitForSingleObject(mtx,-1);
  40. f1:=OpenFile(FileListName,1);
  41. f2:=OpenFile('Online.'+FileListName+'.tmp',1+2+4+8);
  42. f3:=OpenFile('All.'+FileListName+'.tmp',1+2+4+8);
  43. if f1<>0 then
  44.  begin
  45.  SetLength(s,0);
  46.  while ReadFile(f1,32768,s1)<>0 do
  47.   begin
  48.   s:=s+s1;
  49.   x:=pos(#13#10,s);
  50.   while x<>0 do
  51.    begin
  52.    s2:=copy(s,1,x-1);delete(s,1,x+1);
  53.    x:=pos('|',s2);
  54.    if x<>0 then
  55.     begin
  56.     s1:=copy(s2,1,x-1);delete(s2,1,x);
  57.     host:=s1;
  58.     j:=length(s1);
  59.     if host[1]='\' then
  60.      begin
  61.      while(j>1)and(s1[j]<>'\')do j:=j-1;
  62.      fname:=copy(s1,j+1,length(s1)-j);
  63.      delete(s1,j+1,length(s1)-j);
  64.      delete(host,1,2);
  65.      x:=pos('\',host);
  66.      end else
  67.      begin
  68.      while(j>1)and(s1[j]<>'/')do j:=j-1;
  69.      fname:=copy(s1,j+1,length(s1)-j);
  70.      delete(s1,j+1,length(s1)-j);
  71.      delete(host,1,6);
  72.      x:=pos('/',host);
  73.      end;
  74.     if x<>0 then delete(host,x,length(host)-x+1);
  75.  
  76.     if OnlineHosts.Find(LowerCase(host),j) then
  77.      begin
  78.      hst:=TNVHost(OnlineHosts.Objects[j]);
  79.      ison:=true;
  80.      end else if OfflineHosts.Find(LowerCase(host),j) then
  81.      begin
  82.      hst:=TNVHost(OfflineHosts.Objects[j]);
  83.      ison:=false;
  84.      end else
  85.      begin
  86.      hst:=nil;
  87.      ison:=false;
  88.      end;
  89.     if hst<>nil then s3:=hst.hip+'|'+hst.hname+'|'+s1+'|'+fname+'|'+s2+#13#10
  90.                 else s3:='|'+host+'|'+s1+'|'+fname+'|'+s2+#13#10;
  91.     if ison then writefile(f2,s3);
  92.     writefile(f3,s3);
  93.     end;
  94.    x:=pos(#13#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. procedure InitHosts(var OnlineHosts,OfflineHosts,AllHosts:TStringList);
  110. var hst:TNVHost;
  111.     nextId:integer;
  112. begin
  113. nextId:=0;
  114. repeat
  115.  hst:=TNVHost.Create;
  116.  hst.gethost(nextId,0);
  117.  if hst.id<>0 then
  118.   begin
  119.   nextId:=hst.nextId;
  120.   if hst.GetMetaVar('ison')<>'off' then
  121.    begin
  122.    OnlineHosts.AddObject(LowerCase(hst.hname),hst);
  123.    if length(hst.hip)<>0 then OnlineHosts.AddObject(hst.hip,hst);
  124.    end else
  125.    begin
  126.    OfflineHosts.AddObject(LowerCase(hst.hname),hst);
  127.    if length(hst.hip)<>0 then OfflineHosts.AddObject(hst.hip,hst);
  128.    end;
  129.   AllHosts.AddObject('',hst);
  130.   end else
  131.   begin
  132.   hst.Free;
  133.   nextId:=hst.nextId;
  134.   end;
  135.  until nextId=0;
  136. end;
  137.  
  138. procedure ClearHosts(var OnlineHosts,OfflineHosts,AllHosts:TStringList);
  139. var i:integer;
  140. begin
  141. if AllHosts.Count>0 then
  142.  begin
  143.  for i:=0 to AllHosts.Count-1 do
  144.   TNVHost(AllHosts.Objects[i]).Free;
  145.  AllHosts.Clear;
  146.  OnlineHosts.Clear;
  147.  OfflineHosts.Clear;
  148.  end;
  149. end;
  150.  
  151. var OnlineHosts,OfflineHosts,AllHosts,ProcessedFiles:TStringList;
  152.     e,i1,i2:integer;
  153.     sr:TSearchRec;
  154. begin
  155. ProcessedFiles:=TStringList.Create;
  156. OnlineHosts:=TStringList.Create;
  157. OfflineHosts:=TStringList.Create;
  158. AllHosts:=TStringList.Create;
  159. OnlineHosts.Sorted:=true;
  160. OfflineHosts.Sorted:=true;
  161. ProcessedFiles.Sorted:=true;
  162. ProcessedFiles.CaseSensitive:=false;
  163.  
  164. if LOW_PRIORITY then SetThreadPriority(GetCurrentThread,-2);
  165.  
  166. SetStatus('Idle');
  167.  
  168. repeat
  169.  e:=waitevent(i1,i2);
  170.  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
  171.   begin
  172.   if FindFirst('*.FileList',sr)=0 then
  173.    begin
  174.    InitHosts(OnlineHosts,OfflineHosts,AllHosts);
  175.    repeat
  176.     SetStatus(sr.Name);
  177.     WorkFileList(sr.Name,OnlineHosts,OfflineHosts);
  178.     ProcessedFiles.Add(sr.Name);
  179.     until FindNext(sr)<>0;
  180.    ClearHosts(OnlineHosts,OfflineHosts,AllHosts);
  181.    FindClose(sr);
  182.    SetStatus('Idle');
  183.    end;
  184.   ProcessedFiles.SaveToFile(nv_directory+'Scripts\SearcherProcessedFiles.lst');
  185.   ProcessedFiles.Clear;
  186.   end;
  187.  until e=0;
  188.  
  189. OnlineHosts.Free;
  190. OfflineHosts.Free;
  191. AllHosts.Free;
  192. ProcessedFiles.Free;
  193. end.
  194.