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

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

GUI-Tools: EVFSGUI Version 2.0 beta3 level code

File size: 11.9 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 otherwise do
139 say "Workgroup: "smbtreeline.sl
140 if pos("RECEIVING",translate(smbtreeline.sl)) > 0 then do
141 Msg.Type = "W"
142 Msg.Text = smbtreeline.sl
143 call _ShowMsg
144 end
145 else do
146 if VRGet("CN_smbtree","View") = "IconTree" then do
147 smbtree.!workgroup = VRMethod( "CN_smbtree", "AddRecord",,, smbtreeline.sl,"#62:PMWP.DLL")
148 ok = VRMethod( "CN_smbtree", "SetFieldData", smbtree.!workgroup, WorkGroupFH, smbtreeline.sl)
149 ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!workgroup, "Collapsed", 0)
150 ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!workgroup, "ReadOnly", 1)
151 ok = VRMethod( "CN_smbtree", 'SetRecordAttr', smbtree.!workgroup, "UserData", "WORKGROUP|")
152 end
153 CurWG = smbtreeline.sl
154 end
155 end
156 end
157 end
158
159 ok = VRSet( "CN_smbtree", "Painting", 1 )
160
161/* ok = VRSet("Main", 'Pointer', '<default>' ) */
162 ok = VRSet("CN_smbtree","Enabled", 1)
163 ok = VRSet("TM_Throbber","Enabled", 0)
164 ok = VRSet("Pict_Throbber","Visible", 0)
165return
166
167/*:VRX _RefreshShares
168*/
169_RefreshShares:
170 say "_RefreshShares() started"
171 RefreshID = RANDOM()
172 smbshares = TempDir||"smbshares."||machine
173
174 say 'detach 'samba.!smbclientexe' -L "'strip(machine)'" 'UserCred' 'debuglevel' 1>'smbshares' 2>NUL'
175 address cmd 'detach 'samba.!smbclientexe' -L "'strip(machine)'" 'UserCred' 'debuglevel' 1>'smbshares' 2>NUL'
176
177 RefreshMode = "SHARE"
178
179 ok = VRSet("CN_smbtree","Enabled", 0)
180 ok = VRset("TM_RefreshTreeDisplay","Enabled",1)
181return
182
183/*:VRX _AddSharesDisplay
184*/
185_AddSharesDisplay: /* New get shares code - uses smbclient output and is much faster */
186 say "_AddSharesDisplay() started"
187
188 ok = SysFileTree(Tempdir||'smbshares.*',smbshare.,'FO')
189
190 if smbshare.0 = 0 then do /* we are done, no more files around, cleanup, disable Timer and exit */
191 RefreshMode = ""
192 ok = VRSet("CN_smbtree","Enabled", 1)
193 ok = VRset("TM_RefreshTreeDisplay","Enabled",0)
194 say "_AddSharesDisplay() completed"
195 return /* exit here */
196 end
197
198 if UserCred = 'USERCRED' | UserCred = '' | UserCred = '--user=%' then do
199 UserCred = '-N'
200 end
201
202 if ShowHidden = 'SHOWHIDDEN' | ShowHidden = '' then ShowHidden = 0
203
204 do I = 1 to smbshare.0
205 stat = stream(smbshare.I,'c','open read')
206 if stat = "READY:" then do /* we found a readable output file */
207 Machine = VRParseFilename(smbshare.I,'E')
208 smbtree.!machine = _GetMachinehandle(Machine)
209
210 line = linein(smbshare.I)
211 say line
212 ok = VRMethod('CN_smbtree', 'SetRecordAttr', smbtree.!machine, 'UserData', "SERVER|"||strip(line))
213
214 if left(line, 20) = "session setup failed" then do /* we see an error message */
215 say left(line, 20)
216 signal sharecleanup
217 end
218
219 retries = 0
220 do while(left(line,1) <> '09'x)
221 line = linein(smbshare.I)
222 retries = retries + 1
223 say 'Retry 'retries
224 if retries >=10 then do /* No valid output - error */
225 signal sharecleanup
226 end
227 end
228
229 /* Skip header */
230 line = linein(smbshare.I)
231 line = linein(smbshare.I)
232
233 if left(line,5) = "Error" then ok = VRMethod('CN_smbtree', 'SetRecordAttr', smbtree.!machine, 'UserData', "SERVER|"||strip(line))
234
235 do while(left(line,1) = '09'x)
236 parse var line '09'x share type comment
237 type = translate(strip(type))
238 comment = strip(comment)
239
240 select
241 when type = "DISK" then res = '#34:PMWP.DLL'
242 when type = "PRINTER" then res = '#65:PMWP.DLL'
243 when type = "IPC" then res = '#59:PMWP.DLL'
244 when type = "DEVICE" then res = '#84:PMWP.DLL' /* There might be better ones around */
245 otherwise res = ''
246 end
247
248 /* Now the machine receives the wakeup icon */
249 ok = VRMethod('CN_smbtree', 'SetRecordAttr', smbtree.!machine, 'Icon', "#35:PMWP.DLL")
250 parent = smbtree.!machine
251 smbtree.!share = VRMethod( "CN_smbtree", "AddRecord",parent,, share||'0D0A'x||comment, res)
252 ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!share, "ReadOnly", 1, 'UserData', type"|")
253 if pos("$", share) > 0 then ok = VRMethod( "CN_smbtree", "SetRecordAttr", smbtree.!share, "Visible", ShowHidden)
254
255 /* get next share */
256 line = linein(smbshare.I)
257 end
258sharecleanup:
259 say "_AddSharesDisplay() cleanup"
260 ok = stream(smbshare.I,'c','close')
261 ok = SysFileDelete(smbshare.I)
262 if ok <> 0 then say 'Failure 'ok' deleting "'smbshare.I'"!'
263 end
264 end
265 say "_AddSharesDisplay() loop finished"
266return
267
268/*:VRX _GetMachinehandle
269*/
270
271_GetMachinehandle: procedure
272 Machine = arg(1)
273 ok = VRMethod("CN_smbtree", "GetRecordList", "All", rh.)
274
275 do I = 1 to rh.0
276
277 ResName = VRMethod("CN_smbtree","GetRecordAttr",rh.I,"Caption")
278
279 parse var ResName ResName '0D0A'x .
280 ResName = strip(ResName)
281
282 if Machine = ResName then leave /* we got a matching name */
283 end
284return rh.I
Note: See TracBrowser for help on using the repository browser.