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

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

GUITools: EVFSGUI (Ticket #231), SMBMon, shared library updates

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