source: trunk/guitools/shared/smbtree.vrs@ 703

Last change on this file since 703 was 703, checked in by Herwig Bauernfeind, 13 years ago

GUI-Tools: Updates in EVFSGUI/SMBMON/Shared code

File size: 25.8 KB
Line 
1/* Routines to handle smbtree output */
2
3/*:VRX */
4_RefreshTree:
5 say time()' _RefreshTree() started'
6 FirstRun = 0
7 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption", "Refreshing network")
8 ok = SysFileDelete(samba.!msg)
9
10 if UserCred = 'USERCRED' | UserCred = '' | UserCred = '--user=%' then UserCred = '-N'
11 if ShowHidden = 'SHOWHIDDEN' | ShowHidden = '' then ShowHidden = 0
12 if BroadCast = 1 then BroadCast = '-b'; else BroadCast = ''
13
14 say " UserCred="UserCred
15 samba.!serverlist = TempDir'smbtree.srvlst'
16
17 /* smbtree -S = List workgroups (domains) and servers of tree */
18 say ' detach 'samba.!smbtreeexe' 'BroadCast' -S 'UserCred' 'debuglevel' >'samba.!serverlist
19 address cmd 'detach 'samba.!smbtreeexe' 'BroadCast' -S 'UserCred' 'debuglevel' >'samba.!serverlist
20
21 if UserCred = '-N' then ok = VRSet("CN_SMBTREE","Caption","User context: Guest")
22 else do
23 parse var UserCred '--user='username'%'.
24 ok = VRSet("CN_SMBTREE","Caption","User context: "username)
25 end
26
27 if BroadCast = '-b' then BroadCast = 1; else BroadCast = 0
28 if UserCred = '-N' then UserCred = ''
29
30 ok = VRMethod("CN_smbtree", "RemoveRecord", "ALL")
31
32 RefreshMode = "TREE"
33 ok = VRSet("CN_smbtree","Enabled", 0)
34 ok = VRset("TM_RefreshTreeDisplay","Enabled",1)
35
36 say time()' _RefreshTree() done'
37return
38
39/*:VRX */
40_RefreshTreeDisplay:
41 say time()' _RefreshTreeDisplay() started'
42
43 stat = stream(samba.!serverlist,'c','open read')
44 if stat <> "READY:" then do
45 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption", VRGet("DT_STATUSBAR","Caption")||'.')
46 return
47 end
48
49 if UserCred = 'USERCRED' | UserCred = '' | UserCred = '--user=%' then UserCred = '-N'
50 if ShowHidden = 'SHOWHIDDEN' | ShowHidden = '' then ShowHidden = 0
51 if BroadCast = 1 then BroadCast = '-b'; else BroadCast = ''
52
53 if UserCred = '-N' then ok = VRSet("CN_SMBTREE","Caption","User context: Guest")
54 else do
55 parse var UserCred '--user='username'%'.
56 ok = VRSet("CN_SMBTREE","Caption","User context: "username)
57 end
58
59 ok = VRset("TM_RefreshTreeDisplay","Enabled",0)
60 ok = VRSet("CN_smbtree", 'Enabled', 0 )
61
62 ok = VRSet( "CN_smbtree", "Painting", 0 )
63 ok = VRMethod("CN_smbtree", "RemoveRecord", "ALL")
64
65 drop smbtree.
66
67 ok = file2stem(samba.!serverlist,"smbtreeline.")
68
69 do sl = 1 to smbtreeline.0
70 Header = c2x(left(smbtreeline.sl,3))
71 select
72 when Header = "09095C" then nop /* share - obsolete, we only list domains and servers here */
73 when Header = "095C5C" then do /* machine */
74 smbtreeline.sl = strip(smbtreeline.sl,,'09'x)
75 parse var smbtreeline.sl '\\'machine '0909'x comment
76 machine = strip(machine)
77 comment = strip(comment)
78 if VRGet("CN_smbtree","View") = "IconTree" then parent = smbtree.!workgroup; else parent = ""
79 /* We make any machine as sleeping initially */
80 smbtree.!machine = _AddSleepingMachine(machine,comment,parent)
81
82 ok = VRSet( "CN_smbtree", "Painting", 1 )
83 ok = VRSet( "CN_smbtree", "Painting", 0 )
84
85 if VRGet("CN_smbtree","View") <> "Detail" then do
86 /* Tree view */
87 call _RefreshShares
88 end
89 else do /* Fill records for details view */
90 ok = VRSet("Main", 'Pointer', 'Wait' )
91 /* Get NMBLookup Status for machine */
92 NMBStatus = _GetMachineNMBSTatus(machine)
93 parse var NMBStatus IPStr'|'MAC '|' Roles; drop NMBStatus
94 if pos("PDC",Roles) > 0 then ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!machine, "Icon","#63:PMWP.DLL")
95 ok = VRMethod( "CN_smbtree", "SetFieldData", smbtree.!machine, IPFH, IPStr,MBFH, Roles, MacFH,MAC)
96
97 /* FIXME: Possibly obsolete */
98 parse var IPStr MachineIP ',' .
99 if strip(MachineIP) = "" then MachineIP = machine
100
101 ok = VRSet("Main", 'Pointer', '<default>' )
102
103 /* Find out OS, version */
104 say ' 'samba.!smbclientexe' -L "'machine'" 'UserCred' 'debuglevel' 2>'samba.!msg' 1>NUL'
105 address cmd samba.!smbclientexe' -L "'machine'" 'UserCred' 'debuglevel' 2>'samba.!msg' 1>NUL'
106 smbline = linein(samba.!msg)
107 ok = stream(samba.!msg,'c','close')
108 parse var smbline "Domain=["WorkGroup"] OS=["OS"] Server=["Version"]"Rest
109 ok = VRMethod( "CN_smbtree", "SetFieldData", smbtree.!machine, OSFH, OS, VersionFH, Version, WorkgroupFH, WorkGroup)
110 end
111 end
112 when smbtreeline.sl = "" then nop /* skip empty lines */
113 otherwise do /* possibly a new workgroup */
114 say ' Possible workgroup: "'smbtreeline.sl'"'
115 /* check for eventual error messages */
116 if pos("RECEIVING",translate(smbtreeline.sl)) > 0 | pos("TDB(",translate(smbtreeline.sl)) > 0 then do
117 Msg.Type = "W"
118 Msg.Text = smbtreeline.sl
119 call _ShowMsg
120 end
121 else do /* it is really a new workgroup */
122 if VRGet("CN_smbtree","View") = "IconTree" then do
123 smbtree.!workgroup = _AddWorkGroup(smbtreeline.sl)
124 end
125 CurWG = smbtreeline.sl
126 end
127 end
128 end
129 end
130
131 ok = VRSet( "CN_smbtree", "Painting", 1 )
132
133/* ok = VRSet("Main", 'Pointer', '<default>' ) */
134 ok = VRSet("CN_smbtree","Enabled", 1)
135 ok = VRSet("TM_Throbber","Enabled", 0)
136 ok = VRSet("Pict_Throbber","Visible", 0)
137 say time()' _RefreshTreeDisplay() done'
138return
139
140/*:VRX _RefreshShares */
141_RefreshShares:
142 say time()' _RefreshShares() started'
143
144 smbmachine = TempDir||"smbmachine."||machine
145 MaxSmbClient = 32 /* Do not run more than MaxSmbClient instances of smbclient.exe at the same time */
146
147 Defer = 1
148 do while Defer = 1
149 SmbCltCount = 0
150 ok = PRProcessList(proc)
151
152 do I = 1 to proc.0
153 CurProc = VRParseFileName(proc.i.name,'NE')
154 if CurProc = "SMBCLIENT.EXE" then SmbCltCount = SmbCltCount + 1
155 end
156 say ' 'SmbCltCount' instance(s) of 'samba.!smbclientexe' is/are running.'
157 if SmbCltCount >= MaxSmbClient then do
158 say " Waiting until at least "SmbCltCount-MaxSmbClient+1" instance(s) of smbclient.exe terminate(s)."
159 ok = SysSleep(1)
160 end
161 else Defer = 0
162 end
163
164 if UserCred = 'USERCRED' | UserCred = '' | UserCred = '--user=%' then UserCred = '-N'
165
166 say ' detach 'samba.!smbclientexe' -L "'machine'" 'UserCred' 'debuglevel' 2>'smbmachine' 1>&2'
167 address cmd 'detach 'samba.!smbclientexe' -L "'machine'" 'UserCred' 'debuglevel' 2>'smbmachine' 1>&2'
168
169 if UserCred = '-N' then ok = VRSet("CN_SMBTREE","Caption","User context: Guest")
170 else do
171 parse var UserCred '--user='username'%'.
172 ok = VRSet("CN_SMBTREE","Caption","User context: "username)
173 end
174
175 if UserCred = '-N' then UserCred = ''
176
177 RefreshMode = "SHARE"
178
179 ok = VRSet("CN_smbtree","Enabled", 0)
180 ok = VRset("TM_RefreshTreeDisplay","Enabled",1)
181 say time()' _RefreshShares() done'
182return
183
184/*:VRX _AddSharesDisplay
185*/
186_AddSharesDisplay: /* New get shares code - uses smbclient output and is much faster */
187 say time()' _AddSharesDisplay() started'
188
189 ok = SysFileTree(Tempdir||'smbmachine.*',smbmachine.,'FO')
190 if smbmachine.0 = 0 then do /* we are done, no more files around, cleanup, disable Timer and exit */
191 RefreshMode = ""
192 ok = VRset("TM_RefreshTreeDisplay","Enabled", 0)
193 ok = VRSet("TM_RefreshTreeDisplay","Delay", 1000)
194 ok = VRSet("CN_smbtree","Enabled", 1)
195 if DoLMHosts = 1 then do
196 call _LMHostsRead
197 call _LMHostsUpdate
198 end
199 ok = VRSet("CN_smbtree", "Painting", 0 )
200 ok = VRSet("CN_smbtree", "Painting", 1 )
201 say time()' _AddSharesDisplay() completed'
202 return /* exit here */
203 end
204 else do
205 say ' 'smbmachine.0' file(s) to process.'
206 if smbmachine.0 = 1 then ok = VRSet("TM_RefreshTreeDisplay", "Delay", VRGet("TM_RefreshTreeDisplay", "Delay") * 2)
207 end
208
209 if UserCred = 'USERCRED' | UserCred = '' | UserCred = '--user=%' then UserCred = '-N'
210 if ShowHidden = 'SHOWHIDDEN' | ShowHidden = '' then ShowHidden = 0
211
212 do I = 1 to smbmachine.0
213 call charout , ' Going for "'smbmachine.I'", got '
214 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption", VRGet("DT_STATUSBAR","Caption")||'.')
215 stat = stream(smbmachine.I,'c','open read')
216 say '"'stat'"'
217 if stat = "READY:" & smbmachine.0 = 1 then do /* We just found out we are processing the last machine */
218 ok = VRSet("TM_RefreshTreeDisplay","Delay", 1000)
219 end
220 infoline = ""
221 if stat = "READY:" then do /* we found a readable output file */
222 OneWorkGroupOnly = 0
223
224 Machine = substr(smbmachine.I,pos('.',smbmachine.I)+1)
225
226 smbtree.!machine = _GetMachinehandle(Machine)
227
228 if smbtree.!machine = "" then do /* invalid (old) file */
229 say time()' _AddSharesDisplay() exit with Invalid file found (no corresponding machine)'
230 ok = stream(smbmachine.I,'c','close')
231 ok = SysFileDelete(smbmachine.I)
232 iterate
233 end
234 line = linein(smbmachine.I) /* PID line */
235 line = linein(smbmachine.I)
236 if pos('creating lame', line) > 0 then do
237 line = linein(smbmachine.I)
238 line = linein(smbmachine.I)
239 end
240 if pos('Server=[', line) > 0 then do
241 infoline = linein(smbmachine.I)
242 parse var infoline "Domain=["WorkGroup"] OS=["OS"] Server=["Server"]"Rest
243 ok = VRMethod( "CN_smbtree", "SetFieldData", smbtree.!machine, OSFH, OS, VersionFH, Server)
244 line = linein(smbmachine.I)
245 end
246 say ' Answer "'line'"'
247 ok = VRMethod('CN_smbtree', 'SetRecordAttr', smbtree.!machine, 'UserData', "SERVER|"||strip(line))
248
249 if pos("FAIL", translate(line)) > 0 then do /* we see an error message - the term "FAIL" seems to be common to all */
250 say time()' _AddSharesDisplay() exit with "'line'"'
251 ok = stream(smbmachine.I,'c','close')
252 ok = SysFileDelete(smbmachine.I)
253 iterate
254 end
255
256 retries = 0
257 do while(left(line,1) <> '09'x)
258 line = linein(smbmachine.I)
259 retries = retries + 1
260 say ' Skip 'retries' "'line'"'
261 if retries >=10 then do /* No valid output - error */
262 say time()' _AddSharesDisplay() exit with invalid output error'
263 ok = stream(smbmachine.I,'c','close')
264 ok = SysFileDelete(smbmachine.I)
265 leave
266 end
267 end
268 if retries >=10 then iterate
269
270 /* Skip header */
271 line = linein(smbmachine.I)
272 line = linein(smbmachine.I)
273
274 if translate(left(strip(line),5)) = "ERROR" then ok = VRMethod('CN_smbtree', 'SetRecordAttr', smbtree.!machine, 'UserData', "SERVER|"||strip(line))
275
276 do while(left(line,1) = '09'x) /* Share loop */
277 parse var line '09'x share type comment
278 type = translate(strip(type))
279 comment = strip(comment)
280
281 select
282 when type = "DISK" then res = '#64:PMWP.DLL'
283 when type = "PRINTER" then res = '#65:PMWP.DLL'
284 when type = "IPC" then res = '#59:PMWP.DLL'
285 when type = "DEVICE" then res = '#84:PMWP.DLL' /* There might be better ones around */
286 otherwise res = ''
287 end
288
289 /* Now the machine receives the wakeup icon */
290 ok = VRMethod('CN_smbtree', 'SetRecordAttr', smbtree.!machine, 'Icon', "#35:PMWP.DLL")
291 parent = smbtree.!machine
292 smbtree.!share = VRMethod( "CN_smbtree", "AddRecord",parent,, share||'0D0A'x||comment, res)
293 ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!share, "ReadOnly", 1, 'UserData', type"|")
294 if pos("$", share) > 0 then ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!share, "Visible", ShowHidden)
295
296 /* get next share */
297 line = linein(smbmachine.I)
298 end /* Share loop */
299
300 do until left(line,10) = '09'x||'Workgroup'
301 line = linein(smbmachine.I)
302 end
303 line = linein(smbmachine.I)
304 /* Reading FIRST workgroup and master - eventually both empty */
305 line = linein(smbmachine.I)
306
307 /* Multiple workgroups? */
308 if lines(smbmachine.I) = 0 then OneWorkGroupOnly = 1
309 else OneWorkGroupOnly = 0
310 say " OneWorkGroupOnly = "OneWorkGroupOnly
311
312 parse var line '09'x workgroup master
313 master = strip(master)
314
315 /* we use this to set the workgroup for manually added servers - if there is ONLY ONE workgroup */
316 if workgroup <> "" & OneWorkGroupOnly = 1 then do
317 wgh = _GetMachinehandle(workgroup)
318 if wgh = "" then do /* The machine appears to be in a new workgroup - add it as well */
319 /* NOTE: This should be obsolete now because the list of available */
320 /* workgroups should always have been updated before we get here */
321 wgh = _AddWorkGroup(workgroup)
322 end
323 /* we only do this for machines with empty parent (=workgroup) handle */
324 /* IF there is only one workgroup */
325 if wgh <> "" & VRMethod('CN_smbtree', 'GetRecordAttr', smbtree.!machine, 'Parent') = "" then do
326 ok = VRMethod('CN_smbtree', 'SetRecordAttr', smbtree.!machine, 'Parent', wgh)
327 end
328 end
329 else do
330 if workgroup <> "" then do
331 /* There are multiple workgroups, we need additional */
332 /* measures to find out which is our workgroup */
333 if infoline <> "" then do
334 say ' 'samba.!smbclientexe' -L "'Machine'" -N 'debuglevel' 2>'samba.!msg' 1>NUL'
335 address cmd samba.!smbclientexe' -L "'Machine'" -N 'debuglevel' 2>'samba.!msg' 1>NUL'
336 infoline = linein(samba.!msg)
337
338 if word(infoline,1) = "creating" then do /* upcase tables are missing */
339 say "Missing upcase tables detected!"
340 infoline = linein(samba.!msg)
341 infoline = linein(samba.!msg)
342 end
343 IF options.!debug == 1 THEN say ' Response = "'Infoline'"'
344 ok = stream(samba.!msg,'c','close')
345 ok = SysFileDelete(samba.!msg)
346 end
347
348 parse var infoline "Domain=["WorkGroup"] OS=["OS"] Server=["Server"]"Rest
349
350 wgh = _GetMachinehandle(workgroup)
351 if wgh <> "" & VRMethod('CN_smbtree', 'GetRecordAttr', smbtree.!machine, 'Parent') = "" then do
352 ok = VRMethod('CN_smbtree', 'SetRecordAttr', smbtree.!machine, 'Parent', wgh)
353 end
354 end
355 else do
356 /* The machine does not allow browsing and does not report a workgroup here */
357 say ' "'Machine'" does not allow browsing.'
358 end
359 end
360
361 ok = VRSet("Main", 'Pointer', 'Wait' )
362
363 /* Get NMBLookup Status for machine */
364 NMBStatus = _GetMachineNMBSTatus(machine)
365 parse var NMBStatus IPStr'|'MAC '|' Roles; drop NMBStatus
366 if pos("PDC",Roles) > 0 then ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!machine, "Icon","#63:PMWP.DLL")
367 ok = VRMethod( "CN_smbtree", "SetFieldData", smbtree.!machine, IPFH, IPStr,MBFH, Roles, MacFH,MAC)
368
369 ok = VRSet("Main", 'Pointer', '<default>' )
370
371 say time()' _AddSharesDisplay() success and cleanup'
372 ok = stream(smbmachine.I,'c','close')
373 ok = SysFileDelete(smbmachine.I)
374 if ok <> 0 then say ' Failure 'ok' deleting "'smbmachine.I'"!'
375 end
376 end
377
378 if UserCred = '-N' then UserCred = ''
379
380 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption", "Ready.")
381 say time()' _AddSharesDisplay() loop end'
382return
383
384/*:VRX _GetMachinehandle
385*/
386
387_GetMachinehandle: procedure /* get recordhandle by machine name (also works for workgroups) */
388 Machine = translate(arg(1))
389 say ' _GetMachineHandle("'Machine'") started.'
390 ok = VRMethod("CN_smbtree", "GetRecordList", "All", rh.)
391 match = 0
392
393 do I = 1 to rh.0
394 ResName = translate(VRMethod("CN_smbtree","GetRecordAttr",rh.I,"Caption"))
395
396 parse var ResName ResName '0D0A'x .
397 ResName = strip(ResName)
398
399 if Machine = ResName then do /* we got a matching name */
400 match = 1
401 leave
402 end
403 end
404 if match = 0 then rh.I = "" /* return an empty handle, if there was no match */
405 say ' _GetMachineHandle("'Machine'") done, handle = "'rh.I'"'
406return rh.I
407
408/*:VRX _RefreshWorkgroups
409*/
410_RefreshWorkgroups:
411 say time()' _RefreshWorkgroups() started'
412 if UserCred = 'USERCRED' | UserCred = '' | UserCred = '--user=%' then UserCred = '-N'
413 if BroadCast = 1 then BroadCast = '-b'; else BroadCast = ''
414
415 call VRSet VRWindow(), 'Pointer', 'Wait'
416 say ' detach 'samba.!smbtreeexe' 'BroadCast' -D 'debuglevel' 'UserCred' >'samba.!msg
417 address cmd 'detach 'samba.!smbtreeexe' 'BroadCast' -D 'debuglevel' 'UserCred' >'samba.!msg
418
419 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption","Enumerating workgroups")
420 do while stream(samba.!msg,'c','open read') <> "READY:"
421 ok = SysSleep(1)
422 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption", VRGet("DT_STATUSBAR","Caption")||'.')
423 end
424 call VRSet VRWindow(), 'Pointer', '<default>'
425
426 if BroadCast = '-b' then BroadCast = 1; else BroadCast = 0
427 if UserCred = '-N' then UserCred = ''
428
429 ok = File2Stem(samba.!msg,"workgroups.")
430 do I = 1 to workgroups.0
431 workgroup = translate(workgroups.I)
432 if pos("RECEIVING",workgroup) > 0 | pos("TDB(",workgroup) > 0 then iterate /* We ignore errors here */
433 wgh = _GetMachinehandle(workgroup)
434 if wgh = "" then wgh = _AddWorkGroup(workgroup) /* A new workgroup was found -- add it */
435 end
436 say time()' _RefreshWorkgroups() done'
437return
438
439/*:VRX _AddWorkgroup
440*/
441_AddWorkGroup: procedure expose WorkGroupFH
442 workgroup = arg(1)
443 say ' _AddWorkGroup("'workgroup'") started.'
444 wgh= VRMethod( "CN_smbtree", "AddRecord",,, workgroup,"#62:PMWP.DLL")
445 ok = VRMethod( "CN_smbtree", "SetFieldData", wgh, WorkGroupFH, workgroup)
446 ok = VRMethod( "CN_smbtree", "SetRecordAttr", wgh, "Collapsed", 0)
447 ok = VRMethod( "CN_smbtree", "SetRecordAttr", wgh, "ReadOnly", 1)
448 ok = VRMethod( "CN_smbtree", 'SetRecordAttr', wgh, "UserData", "WORKGROUP|")
449 say ' _AddWorkGroup("'workgroup'") done.'
450return wgh
451
452/*:VRX _AddSleepingMachine
453*/
454_AddSleepingMachine: procedure expose WorkGroupFH NBFH CommentFH
455 machine = arg(1)
456 comment = arg(2)
457 parent = arg(3)
458 mh = VRMethod( "CN_smbtree", "AddRecord",parent,, machine||'0D0A'x||comment)
459 ok = VRMethod( "CN_smbtree", "SetFieldData", mh, NBFH, machine, CommentFH, comment)
460 ok = VRMethod( "CN_smbtree", "SetRecordAttr", mh, "Icon","#61:PMWP.DLL")
461 ok = VRMethod( "CN_smbtree", "SetRecordAttr", mh, "ReadOnly", 1)
462 ok = VRMethod( "CN_smbtree", "SetRecordAttr", mh, "Collapsed", 1)
463 ok = VRMethod( "CN_smbtree", 'SetRecordAttr', mh, "UserData", "SERVER|")
464 if parent <> "" then do
465 WGName = translate(VRMethod("CN_smbtree","GetRecordAttr",parent,"Caption"))
466 parse var WGName WGName '0D0A'x .
467 ok = VRMethod( "CN_smbtree", "SetFieldData", mh, WorkgroupFH, strip(WGName))
468 end
469return mh
470
471/*:VRX _GetMachineIP
472*/
473_GetMachineIP: procedure expose debuglevel samba.
474 /* Get all IP addresses of the machine */
475 machine = arg(1)
476 call VRSet VRWindow(), 'Pointer', 'Wait'
477 say ' detach 'samba.!nmblookupexe' 'machine' 'debuglevel' >'samba.!msg
478 address cmd 'detach 'samba.!nmblookupexe' 'machine' 'debuglevel' >'samba.!msg
479
480 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption","Obtaining IP from "machine)
481 do while stream(samba.!msg,'c','open read') <> "READY:"
482 ok = SysSleep(0.33)
483 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption", VRGet("DT_STATUSBAR","Caption")||'.')
484 end
485 call VRSet VRWindow(), 'Pointer', '<default>'
486
487 ok = file2stem(samba.!msg,"nmblookup.")
488 ipstr = ""; ip = ""
489 do i = 1 to nmblookup.0
490 if pos(strip(machine)'<',nmblookup.i) = 0 then iterate
491 parse var nmblookup.i ip .
492 if pos(strip(ip), ipstr) = 0 then ipstr = ipstr||ip','
493 end
494 ipstr = strip(ipstr,,',')
495return IpStr
496
497/*:VRX _GetMachineRole
498*/
499_GetMachineMACRoles: procedure expose debuglevel samba.
500 machine = arg(1) /* May be name or IP */
501 call VRSet VRWindow(), 'Pointer', 'Wait'
502 say ' detach 'samba.!nmblookupexe' -A 'machine' 'debuglevel' >'samba.!msg
503 address cmd 'detach 'samba.!nmblookupexe' -A 'machine' 'debuglevel' >'samba.!msg
504
505 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption","Obtaining capabilities from "machine)
506 do while stream(samba.!msg,'c','open read') <> "READY:"
507 ok = SysSleep(0.33)
508 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption", VRGet("DT_STATUSBAR","Caption")||'.')
509 end
510 call VRSet VRWindow(), 'Pointer', '<default>'
511 ok = file2stem(samba.!msg,"nmblookup.")
512 Roles = ""
513 MAC = 'xx-xx-xx-xx-xx-xx'
514 do I = 1 to nmblookup.0
515 select
516 when pos('<1c>', nmblookup.I) > 0 then Roles = Roles||"PDC," /* # */
517 when pos('<1b>', nmblookup.I) > 0 then Roles = Roles||"LMB," /* + */
518 when pos('<1d>', nmblookup.I) > 0 then Roles = Roles||"DMB," /* * */
519 when pos('MAC', nmblookup.I) > 0 then do
520 parse var nmblookup.I . '=' MAC
521 MAC = strip(MAC)
522 end
523 otherwise nop
524 end
525 end
526 Roles = strip(Roles,,',')
527 if Roles = "" then Roles = "Workstation"
528return MAC'|'Roles
529
530/*:VRX _GetMachineNMBStatus
531*/
532_GetMachineNMBStatus: procedure expose debuglevel samba.
533 machine = arg(1) /* name only allowed */
534 call VRSet VRWindow(), 'Pointer', 'Wait'
535 say ' detach 'samba.!nmblookupexe' -S 'machine' 'debuglevel' >'samba.!msg
536 address cmd 'detach 'samba.!nmblookupexe' -S 'machine' 'debuglevel' >'samba.!msg
537
538 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption","Querying "machine" for roles")
539 do while stream(samba.!msg,'c','open read') <> "READY:"
540 ok = SysSleep(0.33)
541 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption", VRGet("DT_STATUSBAR","Caption")||'.')
542 end
543 call VRSet VRWindow(), 'Pointer', '<default>'
544
545 ok = file2stem(samba.!msg,"nmblookup.")
546 IPStr = ""
547 Roles = ""
548 MAC = 'xx-xx-xx-xx-xx-xx'
549 do I = 1 to nmblookup.0
550 select
551 when pos(machine'<',nmblookup.I) > 0 then do
552 parse var nmblookup.i ip .
553 ip = strip(ip)
554 if pos(ip, ipstr) = 0 then ipstr = ipstr||ip','
555 end
556 when pos('<1c>', nmblookup.I) > 0 then Roles = Roles||"PDC," /* # */
557 when pos('<1b>', nmblookup.I) > 0 then Roles = Roles||"LMB," /* + */
558 when pos('<1d>', nmblookup.I) > 0 then Roles = Roles||"DMB," /* * */
559 when pos('MAC', nmblookup.I) > 0 then do
560 parse var nmblookup.I . '=' MAC
561 MAC = strip(MAC)
562 end
563 otherwise nop
564 end
565 end
566 Roles = strip(Roles,,',')
567 if Roles = "" then Roles = "Workstation"
568 ipstr = strip(ipstr,,',')
569return IPStr'|'MAC'|'Roles
570
571
572
573/*:VRX file2stem
574*/
575file2stem:
576 msgfile = arg(1)
577 msgstem = arg(2)
578 delmsgfile = translate(arg(3))
579 if right(msgstem,1) <> '.' then msgstem = msgstem'.'
580 say ' file2stem("'msgfile'","'msgstem'")'
581 dyn = 'drop 'msgstem
582 interpret dyn
583 stemcount = 0
584 do while lines(msgfile) > 0
585 stemcount = stemcount + 1
586 inline = linein(msgfile)
587 if pos('creating lame',inline) > 0 then do
588 stemcount = stemcount - 1
589 iterate
590 end
591 dyn = msgstem||stemcount' = inline'
592 interpret dyn
593 end
594 dyn = msgstem||"0 = "stemcount
595 interpret dyn
596 ok = stream(msgfile,'c','close')
597 if delMsgFile <> "NODEL" then ok = SysFileDelete(msgfile)
598 drop msgfile msgstem
599return stemcount
Note: See TracBrowser for help on using the repository browser.