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

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

GUI-Tools: EVFSGUI 2.5 final stuff (including helpfiles EN and DE)

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 parse var line '09'x share type comment
283 type = translate(strip(type))
284 comment = strip(comment)
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 parent = smbtree.!machine
297 smbtree.!share = VRMethod( "CN_smbtree", "AddRecord",parent,, share||'0D0A'x||comment, res)
298 ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!share, "ReadOnly", 1, 'UserData', type"|")
299 if pos("$", share) > 0 then ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!share, "Visible", ShowHidden)
300
301 /* get next share */
302 line = linein(smbmachine.I)
303 end /* Share loop */
304
305 do until left(line,10) = '09'x||'Workgroup' | lines(smbmachine.I) = 0
306 line = linein(smbmachine.I)
307 end
308 line = linein(smbmachine.I) /* this should be the -------- string */
309 /* Reading FIRST workgroup and master - eventually both empty */
310 line = linein(smbmachine.I)
311
312 /* Multiple workgroups? */
313 if lines(smbmachine.I) = 0 then OneWorkGroupOnly = 1
314 else OneWorkGroupOnly = 0
315 say " OneWorkGroupOnly = "OneWorkGroupOnly
316
317 parse var line '09'x workgroup master
318 master = strip(master)
319
320 /* we use this to set the workgroup for manually added servers - if there is ONLY ONE workgroup */
321 if workgroup <> "" & OneWorkGroupOnly = 1 then do
322 wgh = _GetMachinehandle(workgroup)
323 if wgh = "" then do /* The machine appears to be in a new workgroup - add it as well */
324 /* NOTE: This should be obsolete now because the list of available */
325 /* workgroups should always have been updated before we get here */
326 wgh = _AddWorkGroup(workgroup)
327 end
328 /* we only do this for machines with empty parent (=workgroup) handle */
329 /* IF there is only one workgroup */
330 if wgh <> "" & VRMethod('CN_smbtree', 'GetRecordAttr', smbtree.!machine, 'Parent') = "" then do
331 ok = VRMethod('CN_smbtree', 'SetRecordAttr', smbtree.!machine, 'Parent', wgh)
332 end
333 end
334 else do
335 if workgroup <> "" then do
336 /* There are multiple workgroups, we need additional */
337 /* measures to find out which is our workgroup */
338 if infoline <> "" then do
339 say ' 'samba.!smbclientexe' -L "'Machine'" -N 'debuglevel' 2>'samba.!msg' 1>NUL'
340 address cmd samba.!smbclientexe' -L "'Machine'" -N 'debuglevel' 2>'samba.!msg' 1>NUL'
341 infoline = linein(samba.!msg)
342
343 if word(infoline,1) = "creating" then do /* upcase tables are missing */
344 say "Missing upcase tables detected!"
345 infoline = linein(samba.!msg)
346 infoline = linein(samba.!msg)
347 end
348 IF options.!debug == 1 THEN say ' Response = "'Infoline'"'
349 ok = stream(samba.!msg,'c','close')
350 ok = SysFileDelete(samba.!msg)
351 end
352
353 parse var infoline "Domain=["WorkGroup"] OS=["OS"] Server=["Server"]"Rest
354
355 wgh = _GetMachinehandle(workgroup)
356 if wgh <> "" & VRMethod('CN_smbtree', 'GetRecordAttr', smbtree.!machine, 'Parent') = "" then do
357 ok = VRMethod('CN_smbtree', 'SetRecordAttr', smbtree.!machine, 'Parent', wgh)
358 end
359 end
360 else do
361 /* The machine does not allow browsing and does not report a workgroup here */
362 say ' "'Machine'" does not allow browsing.'
363 end
364 end
365
366 ok = VRSet("Main", 'Pointer', 'Wait' )
367
368 /* Get NMBLookup Status for machine */
369 NMBStatus = _GetMachineNMBSTatus(machine)
370 parse var NMBStatus IPStr'|'MAC '|' Roles; drop NMBStatus
371 if pos("PDC",Roles) > 0 then ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!machine, "Icon","#63:PMWP.DLL")
372 ok = VRMethod( "CN_smbtree", "SetFieldData", smbtree.!machine, IPFH, IPStr,MBFH, Roles, MacFH,MAC)
373
374 ok = VRSet("Main", 'Pointer', '<default>' )
375
376 say time()' _AddSharesDisplay() success and cleanup'
377 ok = stream(smbmachine.I,'c','close')
378 ok = SysFileDelete(smbmachine.I)
379 if ok <> 0 then say ' Failure 'ok' deleting "'smbmachine.I'"!'
380 end
381 end
382
383 if UserCred = '-N' then UserCred = ''
384
385 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption", "Ready.")
386 say time()' _AddSharesDisplay() loop end'
387return
388
389/*:VRX _GetMachinehandle
390*/
391
392_GetMachinehandle: procedure /* get recordhandle by machine name (also works for workgroups) */
393 Machine = translate(arg(1))
394 say ' _GetMachineHandle("'Machine'") started.'
395 ok = VRMethod("CN_smbtree", "GetRecordList", "All", rh.)
396 match = 0
397
398 do I = 1 to rh.0
399 ResName = translate(VRMethod("CN_smbtree","GetRecordAttr",rh.I,"Caption"))
400
401 parse var ResName ResName '0D0A'x .
402 ResName = strip(ResName)
403
404 if Machine = ResName then do /* we got a matching name */
405 match = 1
406 leave
407 end
408 end
409 if match = 0 then rh.I = "" /* return an empty handle, if there was no match */
410 say ' _GetMachineHandle("'Machine'") done, handle = "'rh.I'"'
411return rh.I
412
413/*:VRX _RefreshWorkgroups
414*/
415_RefreshWorkgroups:
416 say time()' _RefreshWorkgroups() started'
417 if UserCred = 'USERCRED' | UserCred = '' | UserCred = '--user=%' then UserCred = '-N'
418 if BroadCast = 1 then BroadCast = '-b'; else BroadCast = ''
419
420 call VRSet VRWindow(), 'Pointer', 'Wait'
421 say ' detach 'samba.!smbtreeexe' 'BroadCast' -D 'debuglevel' 'UserCred' >'samba.!msg
422 address cmd 'detach 'samba.!smbtreeexe' 'BroadCast' -D 'debuglevel' 'UserCred' >'samba.!msg
423
424 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption","Enumerating workgroups")
425 do while stream(samba.!msg,'c','open read') <> "READY:"
426 ok = SysSleep(1)
427 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption", VRGet("DT_STATUSBAR","Caption")||'.')
428 end
429 call VRSet VRWindow(), 'Pointer', '<default>'
430
431 if BroadCast = '-b' then BroadCast = 1; else BroadCast = 0
432 if UserCred = '-N' then UserCred = ''
433
434 ok = File2Stem(samba.!msg,"workgroups.")
435 do I = 1 to workgroups.0
436 workgroup = translate(workgroups.I)
437 if pos("RECEIVING",workgroup) > 0 | pos("TDB(",workgroup) > 0 then iterate /* We ignore errors here */
438 wgh = _GetMachinehandle(workgroup)
439 if wgh = "" then wgh = _AddWorkGroup(workgroup) /* A new workgroup was found -- add it */
440 end
441 say time()' _RefreshWorkgroups() done'
442return
443
444/*:VRX _AddWorkgroup
445*/
446_AddWorkGroup: procedure expose WorkGroupFH
447 workgroup = arg(1)
448 say ' _AddWorkGroup("'workgroup'") started.'
449 wgh= VRMethod( "CN_smbtree", "AddRecord",,, workgroup,"#62:PMWP.DLL")
450 ok = VRMethod( "CN_smbtree", "SetFieldData", wgh, WorkGroupFH, workgroup)
451 ok = VRMethod( "CN_smbtree", "SetRecordAttr", wgh, "Collapsed", 0)
452 ok = VRMethod( "CN_smbtree", "SetRecordAttr", wgh, "ReadOnly", 1)
453 ok = VRMethod( "CN_smbtree", 'SetRecordAttr', wgh, "UserData", "WORKGROUP|")
454 say ' _AddWorkGroup("'workgroup'") done.'
455return wgh
456
457/*:VRX _AddSleepingMachine
458*/
459_AddSleepingMachine: procedure expose WorkGroupFH NBFH CommentFH
460 machine = arg(1)
461 comment = arg(2)
462 parent = arg(3)
463 mh = VRMethod( "CN_smbtree", "AddRecord",parent,, machine||'0D0A'x||comment)
464 ok = VRMethod( "CN_smbtree", "SetFieldData", mh, NBFH, machine, CommentFH, comment)
465 ok = VRMethod( "CN_smbtree", "SetRecordAttr", mh, "Icon","#61:PMWP.DLL")
466 ok = VRMethod( "CN_smbtree", "SetRecordAttr", mh, "ReadOnly", 1)
467 ok = VRMethod( "CN_smbtree", "SetRecordAttr", mh, "Collapsed", 1)
468 ok = VRMethod( "CN_smbtree", 'SetRecordAttr', mh, "UserData", "SERVER|")
469 if parent <> "" then do
470 WGName = translate(VRMethod("CN_smbtree","GetRecordAttr",parent,"Caption"))
471 parse var WGName WGName '0D0A'x .
472 ok = VRMethod( "CN_smbtree", "SetFieldData", mh, WorkgroupFH, strip(WGName))
473 end
474return mh
475
476/*:VRX _GetMachineIP
477*/
478_GetMachineIP: procedure expose debuglevel samba.
479 say time()' _GetMachineIP() started'
480 /* Get all IP addresses of the machine */
481 machine = arg(1)
482 call VRSet VRWindow(), 'Pointer', 'Wait'
483 say ' detach 'samba.!nmblookupexe' 'machine' 'debuglevel' >'samba.!msg
484 address cmd 'detach 'samba.!nmblookupexe' 'machine' 'debuglevel' >'samba.!msg
485
486 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption","Obtaining IP from "machine)
487 do while stream(samba.!msg,'c','open read') <> "READY:"
488 ok = SysSleep(0.33)
489 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption", VRGet("DT_STATUSBAR","Caption")||'.')
490 end
491 call VRSet VRWindow(), 'Pointer', '<default>'
492
493 ok = file2stem(samba.!msg,"nmblookup.")
494 ipstr = ""; ip = ""
495 do i = 1 to nmblookup.0
496 if pos(strip(machine)'<',nmblookup.i) = 0 then iterate
497 parse var nmblookup.i ip .
498 if pos(strip(ip), ipstr) = 0 then ipstr = ipstr||ip','
499 end
500 ipstr = strip(ipstr,,',')
501 say time()' _GetMachineIP() done'
502return IpStr
503
504/*:VRX _GetMachineRole
505*/
506_GetMachineMACRoles: procedure expose debuglevel samba.
507 say time()' _GetMachineMACRoles() started'
508 machine = arg(1) /* May be name or IP */
509 call VRSet VRWindow(), 'Pointer', 'Wait'
510 say ' detach 'samba.!nmblookupexe' -A 'machine' 'debuglevel' >'samba.!msg
511 address cmd 'detach 'samba.!nmblookupexe' -A 'machine' 'debuglevel' >'samba.!msg
512
513 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption","Obtaining capabilities from "machine)
514 do while stream(samba.!msg,'c','open read') <> "READY:"
515 ok = SysSleep(0.33)
516 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption", VRGet("DT_STATUSBAR","Caption")||'.')
517 end
518 call VRSet VRWindow(), 'Pointer', '<default>'
519 ok = file2stem(samba.!msg,"nmblookup.")
520 Roles = ""
521 MAC = 'xx-xx-xx-xx-xx-xx'
522 do I = 1 to nmblookup.0
523 select
524 when pos('<1c>', nmblookup.I) > 0 then Roles = Roles||"PDC," /* # */
525 when pos('<1b>', nmblookup.I) > 0 then Roles = Roles||"LMB," /* + */
526 when pos('<1d>', nmblookup.I) > 0 then Roles = Roles||"DMB," /* * */
527 when pos('MAC', nmblookup.I) > 0 then do
528 parse var nmblookup.I . '=' MAC
529 MAC = strip(MAC)
530 end
531 otherwise nop
532 end
533 end
534 Roles = strip(Roles,,',')
535 if Roles = "" then Roles = "Workstation"
536 say time()' _GetMachineMACRoles() done'
537return MAC'|'Roles
538
539/*:VRX _GetMachineNMBStatus
540*/
541_GetMachineNMBStatus: procedure expose debuglevel samba.
542 say time()' _GetMachineNMBStatus() started'
543 machine = arg(1) /* name only allowed */
544 call VRSet VRWindow(), 'Pointer', 'Wait'
545 say ' detach 'samba.!nmblookupexe' -S 'machine' 'debuglevel' >'samba.!msg
546 address cmd 'detach 'samba.!nmblookupexe' -S 'machine' 'debuglevel' >'samba.!msg
547
548 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption","Querying "machine" for roles")
549 do while stream(samba.!msg,'c','open read') <> "READY:"
550 ok = SysSleep(0.33)
551 if VRIsValidObject("DT_STATUSBAR") then ok = VRSet("DT_STATUSBAR","Caption", VRGet("DT_STATUSBAR","Caption")||'.')
552 end
553 call VRSet VRWindow(), 'Pointer', '<default>'
554
555 ok = file2stem(samba.!msg,"nmblookup.")
556 IPStr = ""
557 Roles = ""
558 MAC = 'xx-xx-xx-xx-xx-xx'
559 do I = 1 to nmblookup.0
560 select
561 when pos(machine'<',nmblookup.I) > 0 then do
562 parse var nmblookup.i ip .
563 ip = strip(ip)
564 if pos(ip, ipstr) = 0 then ipstr = ipstr||ip','
565 end
566 when pos('<1c>', nmblookup.I) > 0 then Roles = Roles||"PDC," /* # */
567 when pos('<1b>', nmblookup.I) > 0 then Roles = Roles||"LMB," /* + */
568 when pos('<1d>', nmblookup.I) > 0 then Roles = Roles||"DMB," /* * */
569 when pos('MAC', nmblookup.I) > 0 then do
570 parse var nmblookup.I . '=' MAC
571 MAC = strip(MAC)
572 end
573 otherwise nop
574 end
575 end
576 Roles = strip(Roles,,',')
577 if Roles = "" then Roles = "Workstation"
578 ipstr = strip(ipstr,,',')
579 say time()' _GetMachineNMBStatus() done'
580return IPStr'|'MAC'|'Roles
581
582
583
584/*:VRX file2stem
585*/
586file2stem:
587 say time()' file2stem() started'
588 msgfile = arg(1)
589 msgstem = arg(2)
590 delmsgfile = translate(arg(3))
591 if right(msgstem,1) <> '.' then msgstem = msgstem'.'
592 say ' file2stem("'msgfile'","'msgstem'")'
593 dyn = 'drop 'msgstem
594 interpret dyn
595 stemcount = 0
596 do while lines(msgfile) > 0
597 stemcount = stemcount + 1
598 inline = linein(msgfile)
599 if pos('creating lame',inline) > 0 then do
600 stemcount = stemcount - 1
601 iterate
602 end
603 dyn = msgstem||stemcount' = inline'
604 interpret dyn
605 end
606 dyn = msgstem||"0 = "stemcount
607 interpret dyn
608 ok = stream(msgfile,'c','close')
609 if delMsgFile <> "NODEL" then ok = SysFileDelete(msgfile)
610 drop msgfile msgstem
611 say time()' file2stem() done'
612return stemcount
Note: See TracBrowser for help on using the repository browser.