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

Last change on this file since 766 was 766, checked in by Herwig Bauernfeind, 12 years ago

GUI-Tools: EVFSGUI 2.5, SMBMON 2.5 yet another place to fix Ticket #202

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