source: branches/guitools-2.0/shared/smbtree.vrs@ 347

Last change on this file since 347 was 347, checked in by Herwig Bauernfeind, 16 years ago

GUI-Tools: EVFSGUI Version 2.0 beta5 level code

File size: 14.4 KB
Line 
1/* Routines to handle smbtree output */
2
3/*:VRX */
4_RefreshTree:
5 say "_RefreshTree() started"
6 FirstRun = 0
7
8 ok = SysFileDelete(samba.!msg)
9
10 if UserCred = 'USERCRED' | UserCred = '' | UserCred = '--user=%' then do
11 UserCred = '-N'
12 end
13
14 if ShowHidden = 'SHOWHIDDEN' | ShowHidden = '' then ShowHidden = 0
15
16 say 'detach 'samba.!smbtreeexe' -S 'debuglevel' 'UserCred' >'samba.!msg
17 address cmd 'detach 'samba.!smbtreeexe' -S 'debuglevel' 'UserCred' >'samba.!msg
18
19 if UserCred = '-N' then UserCred = ''
20
21 ok = VRMethod("CN_smbtree", "RemoveRecord", "ALL")
22
23 RefreshMode = "TREE"
24 ok = VRSet("CN_smbtree","Enabled", 0)
25 ok = VRset("TM_RefreshTreeDisplay","Enabled",1)
26
27 say "_RefreshTree() done"
28return
29
30/*:VRX */
31_RefreshTreeDisplay:
32 stat = stream(samba.!msg,'c','open read')
33 if stat <> "READY:" then return
34
35 if UserCred = 'USERCRED' | UserCred = '' | UserCred = '--user=%' then do
36 UserCred = '-N'
37 end
38
39 if ShowHidden = 'SHOWHIDDEN' | ShowHidden = '' then ShowHidden = 0
40
41 ok = VRset("TM_RefreshTreeDisplay","Enabled",0)
42/* ok = VRSet("Main", "StatusText", NLVGetMessage(50)) */
43 ok = VRSet("CN_smbtree", 'Enabled', 0 )
44/* ok = VRSet("Main", 'Pointer', 'Wait' ) */
45
46 ok = VRSet( "CN_smbtree", "Painting", 0 )
47 ok = VRMethod("CN_smbtree", "RemoveRecord", "ALL")
48
49 drop smbtree.
50 drop smbtreeline.
51
52 sl = 0
53
54 do until lines(samba.!msg) = 0
55 sl = sl + 1
56 smbtreeline.sl = linein(samba.!msg)
57 end
58 smbtreeline.0 = sl
59 ok = stream(samba.!msg,'c','close')
60 ok = SysFileDelete(samba.!msg)
61
62 do sl = 1 to smbtreeline.0
63 Header = c2x(left(smbtreeline.sl,3))
64 select
65 when Header = "09095C" then do /* share - obsolete, we do that differently now see below! */
66 smbtreeline.sl = strip(smbtreeline.sl,,'09'x)
67 parse var smbtreeline.sl '\\'machine'\'share '09'x comment
68 machine = strip(machine)
69 share = left(strip(share),10)
70 comment = strip(comment)
71 text = translate(share' 'comment)
72 res = _GuessIcon(text)
73 if VRGet("CN_smbtree","View") = "IconTree" then do
74 parent = smbtree.!machine
75 smbtree.!share = VRMethod( "CN_smbtree", "AddRecord",parent,, share||'0D0A'x||comment, res)
76 ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!share, "ReadOnly", 1)
77 if pos("$", share) > 0 then ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!share, "Visible", ShowHidden)
78 end
79 end /* end of obsolete share code */
80 when Header = "095C5C" then do /* Machine */
81 smbtreeline.sl = strip(smbtreeline.sl,,'09'x)
82 parse var smbtreeline.sl '\\'machine '0909'x comment
83 machine = left(strip(machine),13)
84 comment = strip(comment)
85 if VRGet("CN_smbtree","View") = "IconTree" then parent = smbtree.!workgroup; else parent = ""
86 ok = VRSet( "CN_smbtree", "Painting", 1 )
87 smbtree.!machine = VRMethod( "CN_smbtree", "AddRecord",parent,, machine||'0D0A'x||comment)
88 /* We make any machine as sleeping initially */
89 ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!machine, "Icon","#61:PMWP.DLL")
90 ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!machine, "ReadOnly", 1)
91 ok = VRMethod( "CN_smbtree", "SetFieldData", smbtree.!machine, NBFH, machine, CommentFH, Comment, WorkGroupFH, CurWG)
92 ok = VRSet( "CN_smbtree", "Painting", 0 )
93 if VRGet("CN_smbtree","View") = "Detail" then do
94 address cmd samba.!nmblookupexe' 'machine' 'debuglevel' -N >'samba.!msg
95 ipstr = ""
96 ip = ""
97 do until lines(samba.!msg) = 0
98 nmblookupline = linein(samba.!msg)
99 if pos(strip(machine)'<',nmblookupline) > 0 then do
100 parse var nmblookupline ip .
101 if pos(strip(ip), ipstr) = 0 then do
102 ipstr = ipstr||ip','
103 end
104 end
105 end
106 ok = SysFileDelete(samba.!msg)
107 ipstr = strip(ipstr,,',')
108 ok = VRMethod( "CN_smbtree", "SetFieldData", smbtree.!machine, IPFH, IPStr)
109 ok = stream(samba.!msg,'c','close')
110 if ip <> "" then do
111 address cmd samba.!smbclientexe' -L "'strip(machine)'" -I "'ip'" -N 'debuglevel' 2>'samba.!msg' 1>NUL'
112 smbline = linein(samba.!msg)
113 ok = stream(samba.!msg,'c','close')
114 parse var smbline "Domain=["WorkGroup"] OS=["OS"] Server=["Server"]"Rest
115 ok = VRMethod( "CN_smbtree", "SetFieldData", smbtree.!machine, OSFH, OS)
116 /* WorkGroupFH, Workgroup */
117 address cmd samba.!nmblookupexe' -A 'machine' 'debuglevel' -N >'samba.!msg
118 Master = ""
119 do until lines(samba.!msg) = 0
120 nmblookupline = linein(samba.!msg)
121 if pos('<1b>', nmblookupline) > 0 then Master = Master||"LMB," /* + */
122 if pos('<1d>', nmblookupline) > 0 then Master = Master||"DMB," /* * */
123 if pos('MAC',nmblookupline) > 0 then do
124 parse var nmblookupline . '=' MAC
125 MAC = strip(MAC)
126 end
127 end
128 Master= strip(Master,,',')
129 ok = stream(samba.!msg,'c','close')
130 ok = SysFileDelete(samba.!msg)
131 ok = VRMethod( "CN_smbtree", "SetFieldData", smbtree.!machine, MBFH, Master,MacFH,MAC)
132 end
133 end
134 else do
135 call _RefreshShares
136 end
137 end
138 when smbtreeline.sl = "" then nop
139 otherwise do
140 say 'Workgroup: "'smbtreeline.sl'"'
141 if pos("RECEIVING",translate(smbtreeline.sl)) > 0 then do
142 Msg.Type = "W"
143 Msg.Text = smbtreeline.sl
144 call _ShowMsg
145 end
146 else do
147 if VRGet("CN_smbtree","View") = "IconTree" then do
148 smbtree.!workgroup = VRMethod( "CN_smbtree", "AddRecord",,, smbtreeline.sl,"#62:PMWP.DLL")
149 ok = VRMethod( "CN_smbtree", "SetFieldData", smbtree.!workgroup, WorkGroupFH, smbtreeline.sl)
150 ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!workgroup, "Collapsed", 0)
151 ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!workgroup, "ReadOnly", 1)
152 ok = VRMethod( "CN_smbtree", 'SetRecordAttr', smbtree.!workgroup, "UserData", "WORKGROUP|")
153 end
154 CurWG = smbtreeline.sl
155 end
156 end
157 end
158 end
159
160 ok = VRSet( "CN_smbtree", "Painting", 1 )
161
162/* ok = VRSet("Main", 'Pointer', '<default>' ) */
163 ok = VRSet("CN_smbtree","Enabled", 1)
164 ok = VRSet("TM_Throbber","Enabled", 0)
165 ok = VRSet("Pict_Throbber","Visible", 0)
166return
167
168/*:VRX _RefreshShares
169*/
170_RefreshShares:
171 say "_RefreshShares() started"
172 RefreshID = RANDOM()
173 smbmachine = TempDir||"smbmachine."||machine
174
175 say 'detach 'samba.!smbclientexe' -L "'strip(machine)'" 'UserCred' 'debuglevel' 1>'smbmachine' 2>NUL'
176 address cmd 'detach 'samba.!smbclientexe' -L "'strip(machine)'" 'UserCred' 'debuglevel' 1>'smbmachine' 2>NUL'
177
178 RefreshMode = "SHARE"
179
180 ok = VRSet("CN_smbtree","Enabled", 0)
181 ok = VRset("TM_RefreshTreeDisplay","Enabled",1)
182return
183
184/*:VRX _AddSharesDisplay
185*/
186_AddSharesDisplay: /* New get shares code - uses smbclient output and is much faster */
187 say "_AddSharesDisplay() started"
188
189 ok = SysFileTree(Tempdir||'smbmachine.*',smbmachine.,'FO')
190 say ' 'smbmachine.0' file(s) to process.'
191
192 if smbmachine.0 = 0 then do /* we are done, no more files around, cleanup, disable Timer and exit */
193 RefreshMode = ""
194 ok = VRSet("CN_smbtree","Enabled", 1)
195 ok = VRset("TM_RefreshTreeDisplay","Enabled",0)
196 say "_AddSharesDisplay() completed"
197 return /* exit here */
198 end
199
200 if UserCred = 'USERCRED' | UserCred = '' | UserCred = '--user=%' then do
201 UserCred = '-N'
202 end
203
204 if ShowHidden = 'SHOWHIDDEN' | ShowHidden = '' then ShowHidden = 0
205
206 do I = 1 to smbmachine.0
207 say ' Going for "'smbmachine.I'"'
208 stat = stream(smbmachine.I,'c','open read')
209 if stat = "READY:" then do /* we found a readable output file */
210 /* Machine = VRParseFilename(smbmachine.I,'E') */
211 Machine = substr(smbmachine.I,pos('.',smbmachine.I)+1)
212
213 smbtree.!machine = _GetMachinehandle(Machine)
214 say ' Machine (handle) = "'machine'" ('smbtree.!machine')'
215
216 if smbtree.!machine = "" then do /* invalid (old) file */
217 say "_AddSharesDisplay() exit with Invalid file found (no corresponding machine)"
218 ok = stream(smbmachine.I,'c','close')
219 ok = SysFileDelete(smbmachine.I)
220 iterate
221 end
222 line = linein(smbmachine.I)
223 say ' Answer "'line'"'
224 ok = VRMethod('CN_smbtree', 'SetRecordAttr', smbtree.!machine, 'UserData', "SERVER|"||strip(line))
225
226 if pos("FAIL", translate(line)) > 0 then do /* we see an error message - the term "FAIL" seems to be common to all */
227 say '_AddSharesDisplay() exit with "'line'"'
228 ok = stream(smbmachine.I,'c','close')
229 ok = SysFileDelete(smbmachine.I)
230 iterate
231 end
232
233 retries = 0
234 do while(left(line,1) <> '09'x)
235 line = linein(smbmachine.I)
236 retries = retries + 1
237 say ' Skip 'retries' "'line'"'
238 if retries >=10 then do /* No valid output - error */
239 say "_AddSharesDisplay() exit with invalid output error"
240 ok = stream(smbmachine.I,'c','close')
241 ok = SysFileDelete(smbmachine.I)
242 leave
243 end
244 end
245 if retries >=10 then iterate
246
247 /* Skip header */
248 line = linein(smbmachine.I)
249 line = linein(smbmachine.I)
250
251 if left(line,5) = "Error" then ok = VRMethod('CN_smbtree', 'SetRecordAttr', smbtree.!machine, 'UserData', "SERVER|"||strip(line))
252
253 do while(left(line,1) = '09'x)
254 parse var line '09'x share type comment
255 type = translate(strip(type))
256 comment = strip(comment)
257
258 select
259 when type = "DISK" then res = '#34:PMWP.DLL'
260 when type = "PRINTER" then res = '#65:PMWP.DLL'
261 when type = "IPC" then res = '#59:PMWP.DLL'
262 when type = "DEVICE" then res = '#84:PMWP.DLL' /* There might be better ones around */
263 otherwise res = ''
264 end
265
266 /* Now the machine receives the wakeup icon */
267 ok = VRMethod('CN_smbtree', 'SetRecordAttr', smbtree.!machine, 'Icon', "#35:PMWP.DLL")
268 parent = smbtree.!machine
269 smbtree.!share = VRMethod( "CN_smbtree", "AddRecord",parent,, share||'0D0A'x||comment, res)
270 ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!share, "ReadOnly", 1, 'UserData', type"|")
271 if pos("$", share) > 0 then ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!share, "Visible", ShowHidden)
272
273 /* get next share */
274 line = linein(smbmachine.I)
275 end
276
277 do until left(line,10) = '09'x||'Workgroup'
278 line = linein(smbmachine.I)
279 end
280 line = linein(smbmachine.I)
281 /* Reading workgroup and master - eventually both empty */
282 line = linein(smbmachine.I)
283 parse var line '09'x workgroup master
284 master = strip(master)
285
286 /* we use this to set the workgroup for manually added servers */
287 if workgroup <> "" then do
288 wgh = _GetMachinehandle(workgroup)
289 if wgh = "" then do /* This machine is in a new workgroup - add it as well */
290 wgh = VRMethod( "CN_smbtree", "AddRecord",,, workgroup,"#62:PMWP.DLL")
291 ok = VRMethod( "CN_smbtree", "SetFieldData", wgh, WorkGroupFH, workgroup)
292 ok = VRMethod( "CN_smbtree", "SetRecordAttr", wgh, "Collapsed", 0)
293 ok = VRMethod( "CN_smbtree", "SetRecordAttr", wgh, "ReadOnly", 1)
294 ok = VRMethod( "CN_smbtree", 'SetRecordAttr', wgh, "UserData", "WORKGROUP|")
295 end
296 if wgh <> "" then ok = VRMethod('CN_smbtree', 'SetRecordAttr', smbtree.!machine, 'Parent', wgh)
297 end
298
299 say "_AddSharesDisplay() success and cleanup"
300 ok = stream(smbmachine.I,'c','close')
301 ok = SysFileDelete(smbmachine.I)
302 if ok <> 0 then say 'Failure 'ok' deleting "'smbmachine.I'"!'
303 end
304 else say ' Got "'stat'" for "'smbmachine.I'"'
305 end
306 say "_AddSharesDisplay() loop end"
307return
308
309/*:VRX _GetMachinehandle
310*/
311
312_GetMachinehandle: procedure /* get recordhandle by machine name (also works for workgroups) */
313 Machine = translate(arg(1))
314
315 ok = VRMethod("CN_smbtree", "GetRecordList", "All", rh.)
316 match = 0
317
318 do I = 1 to rh.0
319 ResName = translate(VRMethod("CN_smbtree","GetRecordAttr",rh.I,"Caption"))
320
321 parse var ResName ResName '0D0A'x .
322 ResName = strip(ResName)
323
324 if Machine = ResName then do /* we got a matching name */
325 match = 1
326 leave
327 end
328 end
329 if match = 0 then rh.I = "" /* return an empty handle, if there was no match */
330return rh.I
Note: See TracBrowser for help on using the repository browser.