Bus/wg.pm untested

filter: Statementstmt 0.0% 0 / 239 Branchbran 0.0% 0 / 230 Conditioncond 0.0% 0 / 148 MC/DCmcdc 0.0% 0 / 86 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 723 CC 116 SCAR 72.7
CC
116
Cov
0%
ddlb
2550.0
fsdir
1406.0
textarea
240.0
CRAP 1435.7
1 #!perl -w
2 #
3 # CGI::Bus::wg - HTML Widgets
4 #
5 # admiral
6 #
7 #
8
9 package CGI::Bus::wg;
10 require 5.000;
11 use strict;
12 use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
13 use CGI::Bus::Base;
14 use vars qw(@ISA $AUTOLOAD);
15 @ISA =qw(CGI::Bus::Base);
16
17
18 1;
19
20
21 #######################
22
23
24 sub ddlb { # Drop-Down List Box - Input helper
25 my ($s,$w,$n,$ds) =(shift
26 #,!$_[0] || $_[0] =~/^(?:<|\$_|\s)/ || $_[0] =~/(?:>|\$_|\s)$/ ? shift : undef
27 ,shift
28 ,shift, shift);
29 my $x; if (ref($n)) {$x =$n; $n =$x->{-name}}
30 my $g =$s->cgi;
31 my $r ='';
32 if ($g->param($n .'_B')) {
33 my $ff =(ref($_[0]) ? $_[0]->[0] : $_[0]);
34 my $fs =sub{
35 '{var k;'
36 ."var l=window.document.forms[0].${n}_L;"
37 .(!$_[0]
38 ? "k=window.document.forms[0].$ff.value +String.fromCharCode(window.event.keyCode);"
39 : $_[0] eq '1'
40 # ? "k=window.document.forms[0].$ff.value +=String.fromCharCode(window.event.keyCode);"
41 # ? "window.document.forms[0].$ff.fireEvent(\"onkeypress\"); k=window.document.forms[0].$ff.value;"
42 ? "window.document.forms[0].$ff.focus(); k=window.document.forms[0].$ff.value =String.fromCharCode(window.event.keyCode); "
43 : $_[0] eq '2'
44 ? "k=prompt('Enter search string',String.fromCharCode(window.event.keyCode));"
45 # $_[0] eq '3'
46 : "k=prompt('Enter search substring',''); ${n}_L.focus();"
47 )
48 .'if(!k){return(false)}; k=k.toLowerCase();'
49 .'for (var i=0; i <l.length; ++i) {'
50 .($g->user_agent('MSIE')
51 ?'if (l.options.item(i).value.toLowerCase().indexOf(k)'
52 .($_[0] eq '3' ?'>=' :'==') .'0 || l.options.item(i).innerText.toLowerCase().indexOf(k)'
53 .($_[0] eq '3' ?'>=' :'==') .'0){'
54 :'if (l.options.item(i).value.toLowerCase().indexOf(k)'
55 .($_[0] eq '3' ?'>=' :'==') .'0){')
56 .'l.selectedIndex =i; break;}}'
57 .($_[0] ? 'return(false);' : '')
58 .'}'};
59 if ($ff !~/^\t/ && $w) {
60 $r .='<script for="' .$ff
61 .'" event="onkeypress()" >' .&$fs(0) .'</script>';
62 }
63 $r .=$w if $w;
64 $r .=$g->submit(($x ? (%$x) : ())
65 ,-name=>($n .'_C')
66 ,-value=>$s->lng(0,'ddlbclose')
67 ,-title=>$s->lng(1,'ddlbclose'));
68 $r .='<br />';
69 $ds = &$ds($s) if ref($ds) eq 'CODE';
70 my $dl;
71 if (ref($ds) eq 'HASH') {
72 $dl =$ds;
73 $ds =do{use locale; [sort {lc($ds->{$a}) cmp lc($ds->{$b})} keys %$ds]};
74 foreach my $k (keys %$dl) {$dl->{$k} =substr($dl->{$k},0,60) .'...' if length($dl->{$k}) >60}
75 }
76 $r .=$g->scrolling_list(($x ? (%$x) : ())
77 ,-name=>($n .'_L')
78 ,-values=>$ds
79 ,-labels=>$dl
80 ,-size=>(scalar(@$ds) <10 ? scalar(@$ds) : 10)
81 ,-onDblClick=>"{${n}_L.nextSibling.nextSibling.click();"
82 .($ff !~/^\t/ && scalar(@_) >1 ? ' submit();' : '')
83 .' return(false)}'
84 ,($ff !~/^\t/ && $w
85 ? (-onKeyPress=>&$fs(1))
86 : ())
87 ,-default=> 0 ? '' : $ff !~/^\t/ ? $g->param($ff) : ''
88 );
89 chomp($r);
90 $r .='<br />';
91 if (scalar(@_) == 1 && $ff !~/^\t/) {
92 $r .=$g->submit(($x ? (%$x) : ())
93 ,-name=>($n .'_S')
94 ,-value=>'<'
95 .(ref($_[0]) ?($_[0]->[1] || $_[0]->[0]) :($_[0] || ''))
96 ,-title=>$s->lng(1,'ddlbsetvalue'));
97 }
98 else {
99 foreach my $ff (@_) {
100 next if !$ff;
101 my ($fn, $l) =ref($ff) ? (@$ff) : ($ff, '');
102 next if !$fn;
103 my $wn =($fn =~/([^\t]+)$/ ? $1 : $fn); # /^\t(.*)/
104 $l =scalar(@_) ==1 ? '' : $wn if !$l ||($l eq $fn);
105 $r .=
106 $g->button(($x ? (%$x) : ())
107 ,-name=>''
108 ,-value=>(($fn !~/^\t/ ? '<' : '<+') .$l)
109 ,-onClick=> "var fs =window.document.forms[0].${n}_L; "
110 ."var ft =window.document.forms[0].$wn; "
111 ."var i =fs.selectedIndex; "
112 .($g->user_agent('MSIE')
113 ?($fn !~/^\t/ ? "ft.value =(fs.options.item(i).value ==\"\" ? fs.options.item(i).text : fs.options.item(i).value); "
114 : "ft.value =(ft.value ==\"\" ? \"\" : (ft.value +\", \")) +(fs.options.item(i).value ==\"\" ? fs.options.item(i).text : fs.options.item(i).value); ")
115 :($fn !~/^\t/ ? "ft.value =fs[i].value; "
116 : "ft.value =(ft.value ==\"\" ? \"\" : (ft.value +\", \")) +fs[i].value; ")
117 )
118 ,-title=>$s->lng(1,'ddlbsetvalue'));
119 }
120 }
121 $r .=$g->button(($x ? (%$x) : ())
122 ,-name=>''
123 ,-value=>$s->lng(0,'ddlbfind')
124 ,-title=>$s->lng(1,'ddlbfind')
125 ,-onClick=>&$fs(3));
126 $r .=$g->submit(($x ? (%$x) : ())
127 ,-name=>($n .'_C')
128 ,-value=>$s->lng(0,'ddlbclose')
129 ,-title=>$s->lng(1,'ddlbclose'));
130 $r .='<script for="window" event="onload">{'
131 # .'window.scrollTo(window.document.forms[0].' .$n .'_L, window.screenTop);'
132 .(0 && $ff !~/^\t/ && $w && defined($g->param($ff)) && ($g->param($ff) ne '')
133 ? "window.document.forms[0].${ff}.select(); window.document.forms[0].${ff}.focus();"
134 : "window.document.forms[0].${n}_L.focus();"
135 ).'}</script>';
136 }
137 else {
138 $g->param(ref($_[0]) ? $_[0]->[0] : $_[0], $g->param($n .'_L'))
139 if scalar(@_) == 1 && $g->param($n .'_S');
140 $r .=$w if $w;
141 my $fn =(ref($_[0]) ?($_[0]->[0] || $_[0]->[1]) :($_[0] || ''));
142 my $wn =($fn =~/([^\t]+)$/ ? $1 : $fn);
143 $r .="<script language=\"jscript\"></script><script language=\"VBScript\">
144 function ${n}_O_O(fldnme)
145 Dim Users1
146 Dim t
147 Dim item
148 Dim field
149 ${n}_O_O =\"\"
150 On Error Resume Next
151 rem EnsureImport()
152 Set field =Document.getElementsByName(fldnme)(0)
153 Set t = CreateObject(\"MsSvAbw.AddrBookWrapper\")
154 if Err <> 0 then
155 Err.Clear
156 set t = CreateObject(\"MsoSvAbw.AddrBookWrapper\")
157 end if
158 if IsObject(t) then
159 t.AddressBook \"Microsoft Address Book\", 1, \"\", \"\", \"\", Users1
160 if Err = 0 or Err <> 0 then
161 For each item in Users1
162 if len(field.value) <> 0 then
163 field.value =field.value & \", \" & item.SMTPAddress
164 else
165 field.value =item.SMTPAddress
166 end if
167 Next
168 rem MsgBox(field.value)
169 ${n}_O_O =\"fldnme\"
170 else
171 MsgBox(\"Error=\" & Err.Description)
172 Err.Clear
173 end if
174 end if
175 End function"
176 ."</script><script language=\"jscript\"></script>"
177 if ($fn =~/msab\t/) && $g->user_agent('MSIE');
178 $r .=$g->submit(($x ? (%$x) : ())
179 ,-name=>($n .'_B')
180 ,-value=>$s->lng(0,'ddlbopen')
181 ,-title=>$s->lng(1,'ddlbopen')
182 ,($fn =~/msab\t/) && $g->user_agent('MSIE')
183 ? (-OnClick=>"if(${n}_O_O('$wn')) {return(false)};")
184 : ()
185 );
186 $r .='<script for="window" event="onload">{'
187 .'window.document.forms[0].' .$n .'_B.focus();}</script>'
188 if ($g->param($n .'_S') ||$g->param($n .'_C'));
189 }
190 $r
191 }
192
193
194 sub textfield {# Text filed with autosizing
195 my $s =shift;
196 my %a =@_;
197 my $v =exists($a{-default}) ? $a{-default} : $s->qparam($a{-name});
198 $v ='' if !defined($v);
199 if ($a{-asize}) {
200 $a{-size} =($a{-asize} >length($v) ? $a{-asize} :length($v));
201 delete $a{-asize};
202 }
203 $s->cgi->textfield(%a)
204 }
205
206
207 sub textarea { # Text Area with autorowing and hrefs
208 my $s =shift;
209 my %a =@_;
210 my $r ='';
211 my $r1='';
212 my $v =exists($a{-default}) ? $a{-default} : $s->qparam($a{-name});
213 $v ='' if !defined($v);
214 if ($a{-htmlopt}) {
215 delete $a{-htmlopt};
216 my $n =$a{-name};
217 # $r1 .="<input type=\"submit\" name=\"${n}__b\" value=\"R\" "
218 # ."title=\"Rich/Text edit: ^Bold, ^Italic, ^Underline, ^Link, Enter/shift-Enter, ^(shift)T ident, ^Z undo, ^Y redo.\nSwitch to 'T'ext before saving!!!\" "
219 # ."style=\"font-style: italic;\" "
220 # # ; font-weight: bold; font-family: fantasy
221 # ."onclick=\"{if(${n}__b.value=='R') {${n}__b.value='T'; ${n}__r.DocumentHTML=$n.value ? $n.value : ''; $n.style.display='none'; ${n}__r.style.display='inline'; ${n}__r.width='100%'; ${n}__r.height=250 }\n"
222 # ."else {var r; ${n}__b.value='R'; r=${n}__r.DocumentHTML.match(/&lt;BODY&gt;[\\s]*([\\s\\S]*)[\\s]*&lt;\\/BODY&gt;/); "
223 # ."$n.value=r ? r[1] : ${n}__r.DocumentHTML; ${n}__r.style.display='none'; $n.style.display='inline';};\n"
224 # ." return(false)}\" />\n"
225 # ."<object classid=\"clsid:2D360201-FFF5-11d1-8D03-00A0C959BC0A\" id=${n}__r height=\"100%\" width=\"250\" style=\"display: none;\" name=\"${n}__r\" title=\"DHTML Editing Component\"></object>\n"
226 # #DHTML Edit Control for IE5, DHTML Editing Component, HTMLRichtextElement:
227 # #http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnaredcom/html/dhtmledit.asp
228 # if $n && ($ENV{HTTP_USER_AGENT}||'') =~/MSIE/;
229 # $r1 .="<input type=\"submit\" name=\"${n}__b\" value=\"R\" "
230 # ."title=\"Rich/Text edit: ^Bold, ^Italic, ^Underline, ^Link, Enter/shift-Enter, ^(shift)T ident, ^Z undo, ^Y redo.\nSwitch to 'T'ext before saving!!!\" "
231 # ."style=\"font-style: italic;\" "
232 # # ; font-weight: bold; font-family: fantasy
233 # ."onclick=\"{if(${n}__b.value=='R') {$n.rows='1'; ${n}__b.value='T'; "
234 # ."\n var r; r =document.createElement('<object classid=&quot;clsid:2D360201-FFF5-11d1-8D03-00A0C959BC0A&quot; id=&quot;${n}__r&quot; height=&quot;250&quot; width=&quot;100%&quot; name=&quot;${n}__r&quot; title=&quot;DHTML Editing Component&quot ></object>'); ${n}__b.parentNode.appendChild(r);\n"
235 # ."r.normalize; r.Refresh; r.DocumentHTML=$n.value ? $n.value : '';}\n"
236 # ."else {var r; ${n}__b.value='R'; r=${n}__r.DocumentHTML.match(/&lt;BODY&gt;[\\s]*([\\s\\S]*)[\\s]*&lt;\\/BODY&gt;/); "
237 # ."$n.value=r ? r[1] : ${n}__r.DocumentHTML; ${n}__r.removeNode(true); $n.rows='6'};\n"
238 # ." return(false)}\" />\n"
239 # #DHTML Edit Control for IE5, DHTML Editing Component, HTMLRichtextElement:
240 # #http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnaredcom/html/dhtmledit.asp
241 # if $n && ($ENV{HTTP_USER_AGENT}||'') =~/MSIE/;
242 $r1 .="<input type=\"submit\" name=\"${n}__b\" value=\"R\" "
243 .($a{-class} ? 'class="' .$a{-class} .'" ' : '')
244 ."title=\"Rich/Text edit: ^Bold, ^Italic, ^Underline, ^hyperlinK, Enter/shift-Enter, ^(shift)T ident, ^Z undo, ^Y redo.\" "
245 ."style=\"font-style: italic;\" "
246 ."onclick=\"{if(${n}__b.value=='R') {${n}__b.value='T'; $n.style.display='none'; "
247 ."\n var r; r =document.createElement('<span contenteditable=true id=&quot;${n}__r&quot; title=&quot;MSHTML Editing Component&quot; ondeactivate=&quot;{$n.value=${n}__r.innerHTML}&quot;></span>'); ${n}__b.parentNode.insertBefore(r,$n);\n"
248 # r.execCommand('Font', 1)
249 ."r.contentEditable='true'; r.style.borderStyle='inset'; r.style.borderWidth='thin'; r.normalize; r.innerHTML =$n.value ? $n.value : ' '; r.focus();}\n"
250 ."else {${n}__b.value='R'; $n.value=${n}__r.innerHTML ? ${n}__r.innerHTML : ''; ${n}__r.removeNode(true); $n.style.display='inline'; $n.focus();};\n"
251 ." return(false)}\" />\n"
252 #MSHTML Edit Control for IE5.5
253 if $n && ($ENV{HTTP_USER_AGENT}||'') =~/MSIE/;
254 }
255 if ($a{-arows}) {
256 my $h =0;
257 $a{-cols} =20 if !$a{-cols};
258 if ($a{-wrap} && lc($a{-wrap}) eq 'off') {
259 my @a =split /\n/, $v;
260 $h =scalar(@a)
261 }
262 else {
263 foreach my $r (split /\n/, $v) {
264 $h +=1 +(length($r) >$a{-cols} ? int(length($r)/$a{-cols}) +1 :0);
265 }
266 }
267 $a{-rows} =($a{-arows} >$h ? $a{-arows} : $h);
268 $a{-rows} =30 if $a{-rows} >30;
269 delete $a{-arows}
270 }
271 if (defined($a{-hrefs})) {
272 my $v =$v;
273 my @h;
274 while ($v =~/\b([\w-]{3,7}:\/\/[^\s\t,()<>\[\]"']+[^\s\t.,;()<>\[\]"'])/) {
275 my $t =$1;
276 $v =$';
277 $t =~s/^(host|urlh):\/\//\//;
278 $t =~s/^(url|urlr):\/\//$s->url(-relative=>1)/e;
279 push @h, $t;
280 }
281 $r .=join(';&nbsp; '
282 ,map {$s->a({-href=>$_, -target=>'_blank', -title=>$_}
283 ,$s->htmlescape(length() >49 ? substr($_,0,47) .'...' : $_))
284 } @h);
285 $r .='<br />' if $r;
286 delete $a{-hrefs};
287 }
288 $r .=$s->cgi->textarea(%a);
289 $r .=$r1;
290 $r
291 }
292
293
294 sub fsdir { # Filesystem dir field
295 # name,edit,path,URL,URF,rows,cols
296 my ($s, $nm, $ed, $ea, $fp, $fu, $fr, $sr, $sc) =@_;
297 my $x; if (ref($nm)) {$x =$nm; $nm =$x->{-name}};
298 my $p =$s->parent;
299 my ($nml, $nma, $nmu, $nmc, $nmo) =("${nm}_l", "${nm}_d", "${nm}_u", "${nm}_c", "${nm}_o");
300 my $r =$p->cgi->a({-href=>$fr||$fu,-target=>'_blank',-title=>$p->htmlescape($s->lng(1,'Files'))}
301 , $p->{-iurl}
302 ? ('<img border="0" src="' .$p->{-iurl} .'/folder.open.gif" />')
303 : ('<strong>' .$p->htmlescape($s->lng(0,'Files')) ."&nbsp;&nbsp;&nbsp;</strong>")
304 ) ."\n";
305 my $fo=undef;
306 $s->_fsclose($fp, [$p->cgi->param($nmc)])
307 if $ed && $p->cgi->param($nmc);
308 $fo = $ed && ($p->cgi->param($nmc)||$p->cgi->param($nmo)) && $s->_fsopens($fp,{});
309 if (1 && $p->urfcnd && $ed && $fr) {
310 $r .=$p->cgi->submit(($x ? (%$x) : ())
311 ,-name=>$nmo
312 ,-value=>$s->lng(0,'fsopens')
313 ,-title=>$s->lng(1,'fsopens')) ."\n"
314 if !$fo && $^O eq 'MSWin32';
315 $r .="<br />"
316 .$p->cgi->scrolling_list(($x ? (%$x) : ())
317 , -name=>$nmc, -override=>1, -multiple=>'true'
318 , -values=> ['---' .$s->lng(0,'fsclose') .'---'
319 ,ref($fo) eq 'HASH' ? sort keys %$fo : @$fo]
320 , ref($fo) eq 'HASH' ? (-labels=>$fo) : ()
321 )
322 .$p->cgi->submit(($x ? (%$x) : ())
323 ,-name=>$nma
324 ,-value=>$s->lng(0,'fsclose')
325 ,-title=>$s->lng(1,'fsclose')) ."\n"
326 if $fo;
327 if ($ed && $fr && $fr =~/^file:(.*)/i) {
328 my $fs =$1; $fs =~s/\//\\/g;
329 $r .='<span style="font-size: smaller;" '
330 #.' onclick="window.event.srcElement.select" '
331 #.' ondblclick="{window.clipboardData.setData(\'Text\',' .$p->htmlescape($fs) .'\'); return(false)}" '
332 # window.event.srcElement
333 # document.selection.empty();
334 .' title="' .$p->htmlescape($s->lng(1,'Files') .' ') .'" '
335 .'><sub>'
336 .$p->htmlescape($fs) ."</sub></span>"
337 }
338 $r .="<br />\n";
339 # !!! filefield may be useful to attach files, but file creation time will not be saved !!!
340 # $r .=$p->cgi->filefield(-name=>$nmu);
341 # $s->_fsdirupload($nmu, $fp) if $ea && $p->cgi->param($nmu);
342 $r .='<iframe scrolling="auto" src="' .$p->htmlescape($fr) .'"';
343 $r .=' application="yes"';
344 $r .=' height="' .$sr .'"' if $sr;
345 $r .=' width="' .$sc .'"' if $sc;
346 $r .='> </iframe>';
347 return $r;
348 }
349 my $fb =$p->urfcnd && $ed ? ($fr ||$fu) : ($fu ||$fr);
350 if (!$ed) {
351 my $fl =join(",\n"
352 , map {$p->cgi->a({-href=>"$fb/$_", -target=>'_blank'
353 }, $p->htmlescape($_))}
354 eval{$p->fut->globn("$fp/*")}
355 );
356 $r .=$fl ."\n" if $fl;
357 my $fd;
358 if ($fd =$p->orarg('-f',"$fp/index.html","$fp/index.htm")) {
359 my $fn =($fd =~/([^\\\/]+)$/ ? $1 : $fd);
360 # $fd ='<embed scr="' ."$fb/$fn" .'" height=100% width=100% />';
361 # $fd ='<iframe scroling="auto" src="' .$p->htmlescape("$fb/$fn") .'" width=100% height=100%></iframe>';
362 $fd =$p->fut->fload('-b',$fd);
363 $fd =$' if $fd =~m/<body\b[^>]*>/i;
364 $fd =$` if $fd =~m/<\/body\b/i;
365 $fd ='<base href="' .($fb =~/:\/\// ? $fb : $p->surl($fb)) .'/" />' .$fd if $fd !~m/<base\b/i; # !!! May be a problem
366 $r .='<hr />' .$fd .'<br />';
367 }
368 }
369 elsif ($ed) {
370 $s->_fsdirupload($nmu, $fp) if $ea && $p->cgi->param($nmu);
371 if ($ea && $p->cgi->param($nma)) {
372 foreach my $fn ($p->cgi->param($nml)) {
373 $p->fut->delete('-r',"$fp/$fn");
374 }
375 }
376 $r .=$p->cgi->filefield(($x ? (%$x) : ()), -name=>$nmu, -title=>$s->lng(1,'fsbrowse'));
377 $r .=$p->cgi->submit(($x ? (%$x) : ()), -name=>$nma, -value=>$s->lng(0,'+|-'), -title=>$s->lng(1,'+|-'));
378 $r .=$p->cgi->submit(($x ? (%$x) : ()), -name=>$nmo, -value=>$s->lng(0,'fsopens'), -title=>$s->lng(1,'fsopens'))
379 if !$fo && $^O eq 'MSWin32';
380 $r .=$p->cgi->scrolling_list(($x ? (%$x) : ())
381 , -name=>$nmc, -override=>1, -multiple=>'true'
382 , -values=> ['---' .$s->lng(0,'fsclose') .'---'
383 ,ref($fo) eq 'HASH' ? sort keys %$fo : @$fo]
384 , ref($fo) eq 'HASH' ? (-labels=>$fo) : ()
385 ) ."\n"
386 if $fo;
387 if ($ed && $fr && $fr =~/^file:(.*)/i) {
388 my $fs =$1; $fs =~s/\//\\/g;
389 $r .='<span style="font-size: smaller;" '
390 .' title="' .$p->htmlescape($s->lng(1,'Files') .' ') .'" '
391 .'><sub>'
392 .$p->htmlescape($fs) ."</sub></span>"
393 }
394 $r .="<br />\n"; # $r .="\n&nbsp;&nbsp;&nbsp;\n";
395
396 foreach my $fn (eval{$p->fut->globn("$fp/*")}) {
397 $r .=$p->cgi->a({-href=>"$fb/$fn", -target=>'_blank'}
398 ,$p->cgi->checkbox(($x ? (%$x) : ()), -name=>$nml, -value=>$fn, -label=>$fn, -title=>$s->lng(1,'fsdelmrk')))
399 ."&nbsp;&nbsp;&nbsp;\n";
400 }
401 }
402 $r
403 }
404
405
406 sub _fsdirupload { # Filesystem dir field file upload
407 my ($s, $nmu, $fp) =@_;
408 my $fa =$s->cgi->param($nmu);
409 if ($fa) {
410 my $fn =$fa =~/[\\\/]([^\\\/]+)$/ ? $1 : $fa;
411 my $fh =$s->cgi->upload($nmu);
412 if ($fh) {
413 $s->pushmsg("upload '$fn' from '$fa'");
414 binmode($fh);
415 eval('use File::Copy');
416 File::Copy::copy($fh, "$fp/$fn")
417 ||$s->die("Upload '$fn' from '$fa': $!\n");
418 close($fh);
419 }
420 else {
421 $s->die("Empty filehandle '$fn' from '$fa': " .($!||$@||'') ."\n");
422 }
423 }
424 }
425
426
427 sub _fsopens { # opened files (`net file`; NetFileEnum; IADsResource, IADsFileServiceOperations)
428 # (mask, ?container)
429 return(undef) if $^O ne 'MSWin32';
430 my $rc =$_[2]||[];
431 my $mask =$_[1]||''; $mask =~s/\//\\/ig;
432 my $o =eval('use Win32::OLE; Win32::OLE->Option("Warn"=>0); Win32::OLE->GetObject("WinNT://'
433 .(eval{Win32::NodeName()}||$ENV{COMPUTERNAME}) .'/lanmanserver")');
434 return(undef) if !$o;
435 if (ref($rc) eq 'HASH') {
436 %$rc =map {(substr($_->{Path}, length($mask)+1), $_->{User} .': ' .substr($_->{Path}, length($mask)+1))
437 } grep {(eval{$_->{Path}}||'') =~/^\Q$mask\E/i
438 } Win32::OLE::in($o->Resources());
439 # %$rc =(1=>'1.1',2=>'2.1',3=>'3.1');
440 $rc =undef if !%$rc
441 }
442 else {
443 @$rc =map {eval{substr($_->{Path}, length($mask)+1)}
444 } grep {(eval{$_->{Path}}||'') =~/^\Q$mask\E/i # $_->GetInfo;
445 } Win32::OLE::in($o->Resources());
446 $rc =undef if !@$rc
447 }
448 $rc
449 }
450
451
452 sub _fsclose { # close opened files (`net file /close`)
453 # (mask, [files])
454 return(0) if $^O ne 'MSWin32';
455 my $mask =$_[1]||''; $mask =~s/\//\\/ig;
456 my $list =$_[2]||[];
457 my $o =eval('use Win32::OLE; Win32::OLE->Option("Warn"=>0); Win32::OLE->GetObject("WinNT://'
458 .(eval{Win32::NodeName()}||$ENV{COMPUTERNAME}) .'/lanmanserver")');
459 return(0) if !$o;
460 foreach my $f (grep {$_ && (eval{$_->{Path}}||'')=~/^\Q$mask\E/i
461 } Win32::OLE::in($o->Resources())) {
462 my $n =eval{$f->{Path} =~/^\Q$mask\E[\\\/]*(.+)/i ? $1 : undef};
463 next if !$n || !grep /^\Q$n\E$/i, @$list;
464 $_[0]->oscmd('net','file',$f->{Name},'/close');
465 }
466 1
467 }
468