| blib/lib/CGI/Bus.pm | |||
|---|---|---|---|
| Criterion | Covered | Total | % |
| statement | 27 | 794 | 3.4 |
| branch | 0 | 616 | 0.0 |
| condition | 0 | 400 | 0.0 |
| subroutine | 9 | 121 | 7.4 |
| pod | 83 | 93 | 89.2 |
| total | 119 | 2024 | 5.8 |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | #!perl -w | ||||||
| 2 | # | ||||||
| 3 | # CGI::Bus - CGI Application Object Model | ||||||
| 4 | # | ||||||
| 5 | # admiral | ||||||
| 6 | # | ||||||
| 7 | |||||||
| 8 | |||||||
| 9 | package CGI::Bus; | ||||||
| 10 | require 5.000; | ||||||
| 11 | 1 | 1 | 774 | use strict; | |||
| 1 | 1 | ||||||
| 1 | 30 | ||||||
| 12 | 1 | 1 | 690 | use CGI::Carp qw(fatalsToBrowser warningsToBrowser); | |||
| 1 | 4179 | ||||||
| 1 | 6 | ||||||
| 13 | |||||||
| 14 | |||||||
| 15 | 1 | 1 | 116 | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $AUTOLOAD); | |||
| 1 | 2 | ||||||
| 1 | 77 | ||||||
| 16 | $VERSION = '0.62'; | ||||||
| 17 | |||||||
| 18 | 1 | 1 | 5 | use vars qw($SELF); | |||
| 1 | 2 | ||||||
| 1 | 379 | ||||||
| 19 | |||||||
| 20 | $SELF =undef; | ||||||
| 21 | |||||||
| 22 | if ($ENV{MOD_PERL}) { # $ENV{GATEWAY_INTERFACE} && $ENV{GATEWAY_INTERFACE} =~/^CGI-Perl\// | ||||||
| 23 | eval('use Apache qw(exit);'); | ||||||
| 24 | # *exit =\&Apache::exit; | ||||||
| 25 | } | ||||||
| 26 | |||||||
| 27 | 1; | ||||||
| 28 | |||||||
| 29 | |||||||
| 30 | ####################### | ||||||
| 31 | |||||||
| 32 | sub new { | ||||||
| 33 | 0 | 0 | 1 | my $c=shift; | |||
| 34 | 0 | my $s ={}; | |||||
| 35 | 0 | bless $s,$c; | |||||
| 36 | 0 | $s =$s->initialize(@_); | |||||
| 37 | } | ||||||
| 38 | |||||||
| 39 | |||||||
| 40 | sub fcgicount { | ||||||
| 41 | 0 | 0 | 1 | my $s =shift; | |||
| 42 | 0 | 0 | if (!ref($s)) {$s =CGI::Bus->new(@_)} # while (fcgicount) {} | ||||
| 0 | 0 | ||||||
| 0 | |||||||
| 43 | elsif (scalar(@_)) {$s =CGI::Bus->new(@_)} # while (fcgicount) {} | ||||||
| 44 | else {} # while(1) {new ;,,, last if !fcgicount} | ||||||
| 45 | 0 | 0 | return(undef) if !$s->{-cgi}; | ||||
| 46 | 0 | 0 | $s->{-fcgicount} =($s->{-fcgicount} ||0) +1; | ||||
| 47 | 0 | 0 | 0 | return(undef) if $s->{-fcgicount} >($s->{-fcgimax}||0); | |||
| 48 | 0 | $s; | |||||
| 49 | } | ||||||
| 50 | |||||||
| 51 | |||||||
| 52 | sub initialize { | ||||||
| 53 | 0 | 0 | 0 | my $s =shift; | |||
| 54 | 0 | local $SELF =$s; | |||||
| 55 | 0 | 0 | 0 | if (ref($_[0]) && eval{$_[0]->isa('CGI::Bus')}) { # reuse | |||
| 0 | |||||||
| 56 | 0 | my $r =shift; # reuse object | |||||
| 57 | 0 | $r->reset($s->{-reset}); | |||||
| 58 | 0 | $s =$r; # in doubt | |||||
| 59 | 0 | $s->{-cache} ={}; # -> reset? | |||||
| 60 | 0 | foreach my $k (qw(-cgi -qpath -qurl)) { | |||||
| 61 | 0 | $s->{$k} =undef; | |||||
| 62 | } | ||||||
| 63 | } | ||||||
| 64 | else { | ||||||
| 65 | 0 | 0 | shift if !defined($_[0]); | ||||
| 66 | 0 | %$s =( | |||||
| 67 | -classes =>{} # Classes to autocreate Objects | ||||||
| 68 | #,-import =>{} # add Classes or Methods & Packages | ||||||
| 69 | ,-reset =>{} # Slotes to destroy on reuse | ||||||
| 70 | ,-endh =>{} # End handlers, used in 'reset' | ||||||
| 71 | #,-reimport =>{} # add Classes {} or Slotes [] to reset | ||||||
| 72 | ,-debug =>0 # Debug Mode | ||||||
| 73 | ,-problem =>undef # Current problem set by problem() | ||||||
| 74 | ,-cache =>{ # Data cache | ||||||
| 75 | #,-lngbase =>undef # Language messages base | ||||||
| 76 | #,-pushmsg =>undef # Messages to accumulate and display | ||||||
| 77 | #,-qrun =>undef # Query to run | ||||||
| 78 | #,-user =>undef # Current user name | ||||||
| 79 | #,-usdomain =>undef # Server's User Domain | ||||||
| 80 | #,-unames =>undef # User names list | ||||||
| 81 | #,-ugroups =>undef # User groups list | ||||||
| 82 | #,-ugnames =>undef # User and groups names list | ||||||
| 83 | #,-httpheader=>undef # HTTP header output from print->httpheader() | ||||||
| 84 | #,-htmlstart =>undef # HTML start output from print->htmlstart() | ||||||
| 85 | #,-htpgstart =>undef # HTML page begin output from print->htpgstart() | ||||||
| 86 | } | ||||||
| 87 | ,-lngname =>undef # Name and charset of the language to use | ||||||
| 88 | ,-pushlog =>undef # Log file name | ||||||
| 89 | |||||||
| 90 | ,-cgi =>undef # CGI predefined object | ||||||
| 91 | #,-fcgimax =>undef # CGI::Fast requests max | ||||||
| 92 | #,-fcgicount =>undef # CGI::Fast requests counter | ||||||
| 93 | ,-dbi =>undef # DBI predefined object | ||||||
| 94 | |||||||
| 95 | #,-qpath =>undef # Query (script) Path | ||||||
| 96 | #,-qurl =>undef # Query (script) URL | ||||||
| 97 | #,-spath =>undef # Site Path | ||||||
| 98 | #,-surl =>undef # Site URL | ||||||
| 99 | #,-bpath =>undef # Binary Path | ||||||
| 100 | #,-burl =>undef # Binary URL | ||||||
| 101 | #,-dpath =>undef # Data Path | ||||||
| 102 | #,-tpath =>undef # Temporary Files Path | ||||||
| 103 | #,-ppath =>undef # Publish Path | ||||||
| 104 | #,-purl =>undef # Publish URL | ||||||
| 105 | #,-fpath =>undef # Files Store Path | ||||||
| 106 | #,-furf =>undef # Files Store file URL | ||||||
| 107 | #,-furl =>undef # Files Store URL | ||||||
| 108 | #,-hpath =>undef # Homes Store Path | ||||||
| 109 | #,-hurf =>undef # Homes Store file URL | ||||||
| 110 | #,-hurl =>undef # Homes Store URL | ||||||
| 111 | #,-urfcnd =>undef # URFs condition sub{} | ||||||
| 112 | #,-iurl =>undef # Apaceh Images URL '/images' | ||||||
| 113 | |||||||
| 114 | #,-user =>undef # User name get optional sub | ||||||
| 115 | #,-usdomain =>undef # Server's User Domain optional sub | ||||||
| 116 | #,-ugroups =>undef # User groups list optional sub | ||||||
| 117 | #,-usercnv =>undef # User/Group names convertor optional sub | ||||||
| 118 | #,-ugrpcnv =>undef # User/Group names convertor optional sub | ||||||
| 119 | #,-userauth =>undef # User authentication optional sub | ||||||
| 120 | #,-uadmins =>undef # Administrators list | ||||||
| 121 | #,-w32IISdpsn =>($ENV{SERVER_SOFTWARE}||'') =~/IIS/ ? 2 : 0 # MsIIS deimpersonation | ||||||
| 122 | |||||||
| 123 | #,-httpheader =>undef # HTTP header hash ref, for httpheader() | ||||||
| 124 | #,-htmlstart =>undef # HTML start hash ref, for htmlstart() | ||||||
| 125 | #,-htpnstart =>undef # Navigator pane HTML start | ||||||
| 126 | #,-htpgstart =>undef # HTML page HTML start | ||||||
| 127 | #,-htpfstart =>undef # HTML form HTML start | ||||||
| 128 | #,-htpgtop =>undef # HTML page begin, for htpgstart() | ||||||
| 129 | #,-htpgend =>undef # HTML page end, for htpgend() | ||||||
| 130 | ); | ||||||
| 131 | } | ||||||
| 132 | 0 | $s->set(@_); | |||||
| 133 | 0 | 0 | if ($ENV{MOD_PERL}) { | ||||
| 134 | 0 | Apache->push_handlers("PerlCleanupHandler" | |||||
| 135 | 0 | 0 | ,sub{eval{$s->reset}; eval('Apache::DECLINED;')}); # or '$s->reset' at the bottom of scripts | ||||
| 0 | |||||||
| 0 | |||||||
| 136 | } | ||||||
| 137 | 0 | 0 | if (!$s->{-cgi}) { | ||||
| 138 | 0 | 0 | eval('use CGI::Fast') if $s->{-fcgimax}; | ||||
| 139 | 0 | eval('use CGI qw(-no_xhtml);'); | |||||
| 140 | # $CGI::POST_MAX =-1; # default in CGI.pm | ||||||
| 141 | # $MultipartBuffer::INITIAL_FILLUNIT =1024*4; # default in CGI.pm | ||||||
| 142 | 0 | 0 | 0 | local $ENV{CONTENT_TYPE} ='multipart/form-data' # !!! fix CGI.pm: $boundary = "--$boundary" unless CGI::user_agent('MSIE\s+3\.0[12];\s*Mac') | |||
| 0 | |||||||
| 143 | if ($ENV{CONTENT_TYPE}||'') =~m|^multipart/form-data| | ||||||
| 144 | && !$ENV{MOD_PERL}; # !!! beter to read boundary from input, but CGI.pm BUG: This won't work correctly under mod_perl | ||||||
| 145 | # $s->pushmsg($ENV{CONTENT_TYPE}); | ||||||
| 146 | 1 | 1 | 4 | no warnings; | |||
| 1 | 6 | ||||||
| 1 | 8507 | ||||||
| 147 | 0 | 0 | $s->{-cgi} =(!$s->{-fcgimax} ? eval('CGI->new') : eval('CGI::Fast->new')) | ||||
| 148 | ||CGI::Carp::croak("'CGI->new' failure: $@\n"); | ||||||
| 149 | 0 | $CGI::Q =$s->{-cgi}; | |||||
| 150 | 0 | $CGI::XHTML =0; | |||||
| 151 | 0 | 0 | 0 | if ((($ENV{SERVER_SOFTWARE}||'') =~/IIS/) | |||
| 0 | |||||||
| 0 | |||||||
| 152 | || ($ENV{MOD_PERL} && !$ENV{PERL_SEND_HEADER})) { | ||||||
| 153 | 0 | $CGI::NPH =1; | |||||
| 154 | } | ||||||
| 155 | #CGI quote: | ||||||
| 156 | #die "Malformed multipart POST: " | ||||||
| 157 | #.'boundary: ' .$self->{BOUNDARY} ."***\n" | ||||||
| 158 | #.'buffer: ' .$self->{BUFFER} ."***\n" | ||||||
| 159 | #." start=$start; selflen=" .$self->{LENGTH} .'; ' | ||||||
| 160 | #.join(',', map {($_=>$ENV{$_}||'')} qw (REQUEST_METHOD REQUEST_URI CONTENT_TYPE CONTENT_LENGTH)) | ||||||
| 161 | #unless ($start >= 0) || ($self->{LENGTH} > 0); | ||||||
| 162 | } | ||||||
| 163 | $s | ||||||
| 164 | 0 | } | |||||
| 165 | |||||||
| 166 | |||||||
| 167 | sub class { | ||||||
| 168 | 0 | 0 | 1 | substr($_[0], 0, index($_[0],'=')) | |||
| 169 | } | ||||||
| 170 | |||||||
| 171 | |||||||
| 172 | sub set { | ||||||
| 173 | 0 | 0 | 0 | 1 | return(keys(%{$_[0]})) if scalar(@_) ==1; | ||
| 0 | |||||||
| 174 | 0 | 0 | return($_[0]->{$_[1]}) if scalar(@_) ==2; | ||||
| 175 | 0 | my ($s, %opt) =@_; | |||||
| 176 | 0 | foreach my $k (keys(%opt)) { | |||||
| 177 | 0 | $s->{$k} =$opt{$k}; | |||||
| 178 | } | ||||||
| 179 | 0 | my $h; | |||||
| 180 | 0 | 0 | if ($h =$opt{-import}) { # Import Classes or Methods and Packages | ||||
| 181 | 0 | delete $s->{-import}; | |||||
| 182 | 0 | foreach my $k (keys %$h) { | |||||
| 183 | 0 | my $l = $h->{$k}; | |||||
| 184 | 0 | 0 | if (ref($l) eq 'HASH') { # 'use...'=>{-method=>call,...},... | ||||
| 0 | |||||||
| 185 | 0 | 0 | my $p =$k =~/^([^\;\s\(]+)/ ? $1 : $k; | ||||
| 186 | 0 | foreach my $c (keys %$l) { | |||||
| 187 | 0 | my $m =$l->{$c}; | |||||
| 188 | 0 | 0 | $s->{$m} = | ||||
| 189 | sub{$s->{$m} =eval("use $k; \\\&$p::$c"); | ||||||
| 190 | 0 | eval("use $k; &$p::$c(\@_)")} | |||||
| 191 | 0 | } | |||||
| 192 | } | ||||||
| 193 | elsif (ref($l) eq 'ARRAY') { # 'use...'=>[method,...],... | ||||||
| 194 | 0 | 0 | my $p =$k =~/^([^\;\s\(]+)/ ? $1 : $k; | ||||
| 195 | 0 | foreach my $m (@$l) { | |||||
| 196 | 0 | 0 | $s->{"-$m"} = | ||||
| 197 | sub{$s->{"-$m"} =eval("use $k; \\\&$p::$m"); | ||||||
| 198 | 0 | eval("use $k; &$p::$m(\@_)")} | |||||
| 199 | 0 | } | |||||
| 200 | } | ||||||
| 201 | else { # -key=>class,.... | ||||||
| 202 | 0 | $s->{-classes}->{$k} =$h->{$k} | |||||
| 203 | } | ||||||
| 204 | } | ||||||
| 205 | } | ||||||
| 206 | 0 | 0 | if ($h =$opt{-reimport}) { # Reset or Load Classes | ||||
| 207 | 0 | delete $s->{-reimport}; | |||||
| 208 | 0 | 0 | if (ref($h) eq 'HASH') { # {-key=>class,...} | ||||
| 0 | |||||||
| 209 | 0 | foreach my $k (keys %$h) { | |||||
| 210 | 0 | $s->{-classes}->{$k} =$h->{$k}; | |||||
| 211 | 0 | $s->{-reset}->{$k} =1 | |||||
| 212 | } | ||||||
| 213 | } | ||||||
| 214 | elsif (ref($h) eq 'ARRAY') { # [-key,...] | ||||||
| 215 | 0 | foreach my $k (@$h) {$s->{-reset}->{$k} =1} | |||||
| 0 | |||||||
| 216 | } | ||||||
| 217 | else { # -key | ||||||
| 218 | 0 | $s->{-reset}->{$h} =1; | |||||
| 219 | } | ||||||
| 220 | } | ||||||
| 221 | 0 | 0 | if ($opt{-debug}) { | ||||
| 222 | 0 | 0 | 0 | $SIG{__WARN__} =sub{return if $^S; | |||
| 223 | 0 | 0 | eval{$s->pushmsg('WARN: ' .($_[0] =~/(.+)[\n\r]+$/ ? $1 : $_[0]))}}; | ||||
| 0 | |||||||
| 0 | |||||||
| 224 | } | ||||||
| 225 | 0 | 0 | 0 | $TempFile::TMPDIRECTORY =$opt{-tpath} # use CGI | |||
| 0 | |||||||
| 226 | if $opt{-tpath} | ||||||
| 227 | && ((-d $opt{-tpath}) ||$s->fut->mkdir($opt{-tpath})); | ||||||
| 228 | 0 | $s | |||||
| 229 | } | ||||||
| 230 | |||||||
| 231 | |||||||
| 232 | sub reset { | ||||||
| 233 | 0 | 0 | 1 | my $s =shift; | |||
| 234 | 0 | local $SELF =$s; | |||||
| 235 | 0 | my $v =!scalar(@_) | |||||
| 236 | ? $s->{-reset} | ||||||
| 237 | :ref($_[0]) eq 'ARRAY' | ||||||
| 238 | 0 | 0 | ? {map {$_=>1} @{$_[0]}} | ||||
| 0 | 0 | ||||||
| 239 | :$_[0]; | ||||||
| 240 | 0 | foreach my $k (sort keys %{$s->{-endh}}) { | |||||
| 0 | |||||||
| 241 | 0 | eval{&{$s->{-endh}->{$k}}($s)} | |||||
| 0 | |||||||
| 0 | |||||||
| 242 | } | ||||||
| 243 | 0 | $s->{-endh} ={}; | |||||
| 244 | 0 | foreach my $k (keys %$v) { | |||||
| 245 | 0 | my $o =$s->{$k}; | |||||
| 246 | 0 | my $t =ref($o); | |||||
| 247 | 0 | 0 | 0 | next if !$t || $t eq 'HASH' || $t eq 'ARRAY'; | |||
| 0 | |||||||
| 248 | 0 | delete $s->{$k}; | |||||
| 249 | 0 | eval {$o->DESTROY()}; | |||||
| 0 | |||||||
| 250 | 0 | 0 | 0 | eval {delete $o->{'CGI::Bus'} if ref($o) && $o->isa('HASH')}; | |||
| 0 | |||||||
| 251 | } | ||||||
| 252 | 0 | $SELF =undef; | |||||
| 253 | 0 | 0 | 0 | if (!scalar(@_) && $ENV{MOD_PERL}) { | |||
| 254 | 0 | delete $ENV{REMOTE_USER}; | |||||
| 255 | } | ||||||
| 256 | $s | ||||||
| 257 | 0 | } | |||||
| 258 | |||||||
| 259 | |||||||
| 260 | sub DESTROY { | ||||||
| 261 | 0 | 0 | my $s =shift; | ||||
| 262 | 0 | $s->reset($s); | |||||
| 263 | 0 | $s | |||||
| 264 | } | ||||||
| 265 | |||||||
| 266 | |||||||
| 267 | sub evalsub { | ||||||
| 268 | 0 | 0 | 1 | my ($s, $c) =(shift, shift); | |||
| 269 | 0 | local $SELF =$s; | |||||
| 270 | 0 | 0 | ref($c) ? &$c(@_) : eval $c | ||||
| 271 | } | ||||||
| 272 | |||||||
| 273 | |||||||
| 274 | sub AUTOLOAD {# Objects & Methods Loader | ||||||
| 275 | 0 | 0 | 0 | my $s =shift; confess("!object($s) in AUTOLOAD") if !ref($s); | |||
| 0 | |||||||
| 276 | 0 | my $m =substr($AUTOLOAD, rindex($AUTOLOAD, '::')+2); | |||||
| 277 | 0 | my $k ='-' .$m; | |||||
| 278 | 0 | 0 | 0 | if (ref($s->{$k}) eq 'CODE') {$s->evalsub($s->{$k},@_)} | |||
| 0 | 0 | ||||||
| 0 | 0 | ||||||
| 279 | elsif (!scalar(@_) && ref($s->{$k})) {$s->{$k}} | ||||||
| 280 | elsif ($s->{-classes}->{$k}) { | ||||||
| 281 | 0 | local $SELF =$s; | |||||
| 282 | 0 | my $c =$s->{-classes}->{$k}; | |||||
| 283 | 0 | 0 | my $o =ref($c) ? &$c(@_) : eval("use $c; $c->new(\@_)"); | ||||
| 284 | 0 | 0 | $s->die($@) if $@; | ||||
| 285 | 0 | 0 | eval {$o->{'CGI::Bus'}=$s if $o->isa('HASH')}; | ||||
| 0 | |||||||
| 286 | 0 | $s->{$k} =$o; # cycle ref! | |||||
| 287 | } | ||||||
| 288 | #elsif (grep {$m eq $_} qw(select tr link delete accept sub vars)) | ||||||
| 289 | # {$m =ucfirst($m); $s->{-cgi}->$m(@_)} | ||||||
| 290 | #else {$s->{-cgi}->$m(@_)} | ||||||
| 291 | #else {eval {$s->{-cgi}->$m(@_)}; $s->_selfload(@_) if $@} | ||||||
| 292 | else { | ||||||
| 293 | 0 | my @r; | |||||
| 294 | 0 | 0 | wantarray ? eval{@r =$s->{-cgi}->$m(@_)} : eval{$r[0] =$s->{-cgi}->$m(@_)}; | ||||
| 0 | |||||||
| 0 | |||||||
| 295 | 0 | 0 | if ($@) { | ||||
| 296 | 0 | 0 | if (grep {$m eq $_} qw(select tr link delete accept sub vars)) { | ||||
| 0 | |||||||
| 297 | 0 | $m =ucfirst($m); | |||||
| 298 | 0 | 0 | wantarray ? eval{@r =$s->{-cgi}->$m(@_)} : eval{$r[0] =$s->{-cgi}->$m(@_)}; | ||||
| 0 | |||||||
| 0 | |||||||
| 299 | } | ||||||
| 300 | 0 | 0 | $r[0] =$s->_selfload(@_) if $@; | ||||
| 301 | } | ||||||
| 302 | 0 | 0 | wantarray ? @r : $r[0] | ||||
| 303 | } | ||||||
| 304 | } | ||||||
| 305 | |||||||
| 306 | |||||||
| 307 | sub launch { # Objects Factory | ||||||
| 308 | 0 | 0 | 1 | my ($s,$m) =(shift, shift); | |||
| 309 | 0 | 0 | return CGI::BusLauncher->new($s) if !defined($m); | ||||
| 310 | 0 | my $k ='-' .$m; | |||||
| 311 | 0 | local $SELF =$s; | |||||
| 312 | 0 | local $s->{$k}; | |||||
| 313 | 0 | my $o; | |||||
| 314 | 0 | 0 | if ($s->{-classes}->{$k}) { | ||||
| 315 | 0 | my $c =$s->{-classes}->{$k}; | |||||
| 316 | 0 | 0 | $o =ref($c) ? &$c(@_) : eval("use $c; $c->new(\@_)"); | ||||
| 317 | } | ||||||
| 318 | else { | ||||||
| 319 | 0 | $o =eval "use CGI::Bus::$m; CGI::Bus::$m->new (\@_)"; | |||||
| 320 | } | ||||||
| 321 | 0 | 0 | $s->die($@) if $@; | ||||
| 322 | 0 | 0 | $s->die("Object not created '$m'") if !defined($o); | ||||
| 323 | 0 | 0 | eval {$o->{'CGI::Bus'}=$s if $o->isa('HASH')}; | ||||
| 0 | |||||||
| 324 | 0 | $o | |||||
| 325 | } | ||||||
| 326 | |||||||
| 327 | |||||||
| 328 | sub _selfload{# Self SubObject Loader | ||||||
| 329 | 0 | 0 | my $s =shift; | ||||
| 330 | 0 | local $SELF =$s; | |||||
| 331 | 0 | my $e =$@; chomp($e); | |||||
| 0 | |||||||
| 332 | 0 | my $o; | |||||
| 333 | 0 | $o =eval "use $AUTOLOAD; $AUTOLOAD->new(\@_)"; | |||||
| 334 | 0 | 0 | if (defined($o)) { | ||||
| 335 | 0 | $s->{'-' .substr($AUTOLOAD, rindex($AUTOLOAD, '::')+2)} =$o; | |||||
| 336 | 0 | 0 | eval {$o->{'CGI::Bus'}=$s if $o->isa('HASH')}; | ||||
| 0 | |||||||
| 337 | 0 | $o | |||||
| 338 | } | ||||||
| 339 | else { | ||||||
| 340 | 0 | $s->die("$e. $@") | |||||
| 341 | } | ||||||
| 342 | } | ||||||
| 343 | |||||||
| 344 | |||||||
| 345 | sub microtest{# Microtest of the Object | ||||||
| 346 | 0 | 0 | 1 | my $s =shift; | |||
| 347 | 0 | 0 | $s->{-debug} ? $s->print->hr : $s->print->htpgstart; | ||||
| 348 | #local $s->{-debug} =0; | ||||||
| 349 | 0 | 0 | 0 | if (($s->{-debug}||0) >4) { | |||
| 350 | 0 | $s->print->h2('Methods'); | |||||
| 351 | 0 | foreach my $k (qw(class request qpath qurl qrun spath surl bpath burl dpath ppath purl furl user usdomain useron usersn usercn userfn userds unames ugroups ugnames)) { | |||||
| 352 | 0 | $s->print->text("$k = " ._stringify($s->$k()))->br; | |||||
| 353 | } | ||||||
| 354 | } | ||||||
| 355 | 0 | $s->print->h2('Slotes'); | |||||
| 356 | 0 | foreach my $k (sort keys %$s) { | |||||
| 357 | 0 | $s->print->text("$k = " ._stringify($s->{$k}))->br; | |||||
| 358 | } | ||||||
| 359 | 0 | $s->print->h2('Environment Variables'); | |||||
| 360 | 0 | foreach my $k (sort keys %ENV) { | |||||
| 361 | 0 | $s->print->text($s->htmlescape("$k = '" .$ENV{$k} ."'"))->br; | |||||
| 362 | } | ||||||
| 363 | 0 | 0 | $s->print->text($s->htmlescape( "login = '" .(eval{$^O eq 'MSWin32' ? Win32::LoginName() : getlogin()} ||'') ."'"))->br; | ||||
| 364 | 0 | $s->print->text($s->htmlescape("\$0 = '$0'"))->br; | |||||
| 365 | 0 | $s->print->text($s->htmlescape("\$^V = '$^V'"))->br; | |||||
| 366 | 0 | 0 | $s->print->text($s->htmlescape("\$^X = '$^X'"))->br if $^X; | ||||
| 367 | 0 | local $s->{-debug} =0; | |||||
| 368 | 0 | $s->print->htpgend(); | |||||
| 369 | } | ||||||
| 370 | |||||||
| 371 | |||||||
| 372 | sub microenv {# Microenv text of the Object | ||||||
| 373 | 0 | 0 | 0 | my $s =shift; | |||
| 374 | 0 | 0 | join(', ',('LOGIN=' .(eval{$^O eq 'MSWin32' ? Win32::LoginName() : getlogin()} ||'')) | ||||
| 375 | 0 | 0 | ,map {$_ .'=' .($ENV{$_}||'')} qw(REMOTE_USER REMOTE_ADDR REMOTE_PORT HTTP_USER_AGENT REQUEST_METHOD REQUEST_URI CONTENT_TYPE CONTENT_LENGTH HTTP_COOKIE GATEWAY_INTERFACE)) | ||||
| 376 | } | ||||||
| 377 | |||||||
| 378 | |||||||
| 379 | sub _stringify { | ||||||
| 380 | 0 | 0 | my $v =$_[0]; | ||||
| 381 | 0 | my $p =''; | |||||
| 382 | 0 | 0 | 0 | if (!defined($v)) {$p ='null'} | |||
| 0 | 0 | ||||||
| 0 | |||||||
| 383 | elsif (UNIVERSAL::isa($v,'ARRAY')) { | ||||||
| 384 | 0 | $p =$v .'['; | |||||
| 385 | 0 | foreach my $e (@$v) {$p .=_stringify($e) .','} | |||||
| 0 | |||||||
| 386 | 0 | 0 | chop($p) if scalar(@$v); | ||||
| 387 | 0 | $p .=']'; | |||||
| 388 | } | ||||||
| 389 | elsif (UNIVERSAL::isa($v,'HASH') && !UNIVERSAL::isa($v,'CGI::Bus')) { | ||||||
| 390 | 0 | $p =$v .'{'; | |||||
| 391 | 0 | foreach my $e (sort keys %$v) {$p .=$e .'=>' ._stringify($v->{$e}) .','} | |||||
| 0 | |||||||
| 392 | 0 | 0 | chop($p) if scalar(%$v); | ||||
| 393 | 0 | $p .='}'; | |||||
| 394 | } | ||||||
| 395 | else { | ||||||
| 396 | # if (ref($CGI::Bus::USED{$v})) { $p ="''" ._stringify($CGI::Bus::USED{$v})} | ||||||
| 397 | # else {$p ="'" .$v ."'"} | ||||||
| 398 | 0 | $p ="'" .$v ."'" | |||||
| 399 | } | ||||||
| 400 | 0 | $p | |||||
| 401 | } | ||||||
| 402 | |||||||
| 403 | |||||||
| 404 | ####################### | ||||||
| 405 | |||||||
| 406 | sub lngname { # language name | ||||||
| 407 | 0 | 0 | 0 | 0 | 1 | if (!$_[0]->{-lngname} || $_[1]) { | |
| 408 | 0 | 0 | if (defined($_[1])) { | ||||
| 409 | 0 | $_[0]->{-lngname} =$_[1] | |||||
| 410 | } | ||||||
| 411 | else { | ||||||
| 412 | 0 | 0 | $_[0]->{-lngname} =$_[0]->{-cgi}->http('Accept_language')||''; | ||||
| 413 | # .($_[0]->{-cgi}->http('Accept_charset') ||'') | ||||||
| 414 | 0 | 0 | $_[0]->{-lngname} =$_[0]->{-lngname} =~/^([^ ;,]+)/ ? $1 : $_[0]->{-lngname}; | ||||
| 415 | } | ||||||
| 416 | } | ||||||
| 417 | 0 | $_[0]->{-lngname} | |||||
| 418 | } | ||||||
| 419 | |||||||
| 420 | |||||||
| 421 | sub lngload { # language load | ||||||
| 422 | 0 | 0 | 1 | my ($s, $c, $l) =@_; | |||
| 423 | 0 | 0 | $c =$s->class if !$c; | ||||
| 424 | 0 | 0 | $l =$s->lngname if !$l; | ||||
| 425 | 0 | my $r; | |||||
| 426 | 0 | foreach my $m ($c .'_' .$l, $c) { | |||||
| 427 | 0 | $m =~s/::/_/g; | |||||
| 428 | 0 | $m =~s/[ -]/_/g; | |||||
| 429 | 0 | eval("use CGI::Bus::lngbase::${m}; \$r ={CGI::Bus::lngbase::${m}::lngbase}"); | |||||
| 430 | 0 | 0 | last if $r; | ||||
| 431 | } | ||||||
| 432 | 0 | return $r | |||||
| 433 | } | ||||||
| 434 | |||||||
| 435 | |||||||
| 436 | sub lng { # language string | ||||||
| 437 | 0 | 0 | 0 | 1 | $_[0]->{-cache}->{-lngbase} =$_[0]->lngload($_[0]->class) if !$_[0]->{-cache}->{-lngbase}; | ||
| 438 | 0 | my $r =$_[0]->{-cache}->{-lngbase}; | |||||
| 439 | 0 | 0 | 0 | $r = !defined($_[2]) ? $r->{$_[1]} | |||
| 0 | |||||||
| 440 | :!defined($r->{$_[2]}) ||!defined($r->{$_[2]}->[$_[1]]) ? $_[2] | ||||||
| 441 | :$r->{$_[2]}->[$_[1]]; | ||||||
| 442 | 0 | foreach my $e (@_[3..$#_]) { | |||||
| 443 | 0 | $r =~s/\$_/$e/e; | |||||
| 0 | |||||||
| 444 | } | ||||||
| 445 | $r | ||||||
| 446 | 0 | } | |||||
| 447 | |||||||
| 448 | |||||||
| 449 | sub pushmsg { # messages to accumulate and display | ||||||
| 450 | 0 | 0 | 1 | my $s =shift; | |||
| 451 | 0 | 0 | $s->{-cache}->{-pushmsg} =[] if !$s->{-cache}->{-pushmsg}; | ||||
| 452 | 0 | 0 | push @{$s->{-cache}->{-pushmsg}}, @_ if scalar(@_); | ||||
| 0 | |||||||
| 453 | 0 | $s->{-cache}->{-pushmsg} | |||||
| 454 | } | ||||||
| 455 | |||||||
| 456 | |||||||
| 457 | sub pushlog { # push messages to log file | ||||||
| 458 | 0 | 0 | 1 | my $s =shift; | |||
| 459 | 0 | 0 | return @_ if !$s->{-pushlog}; | ||||
| 460 | 0 | my $b ="[" .$0 ."\t" .$s->user ."\t" .$s->strtime() ."]\t"; | |||||
| 461 | 0 | 0 | $s->fut->fstore('-', '>' .$s->{-pushlog}, map {$b .(defined($_) ?$_ :'')} @_); | ||||
| 0 | |||||||
| 462 | @_ | ||||||
| 463 | 0 | } | |||||
| 464 | |||||||
| 465 | |||||||
| 466 | sub problem { # problem flag | ||||||
| 467 | 0 | 0 | 0 | 1 | $_[0]->pushmsg($_[0]->{-problem} =$_[1] || $@ || $!); | ||
| 468 | } | ||||||
| 469 | |||||||
| 470 | |||||||
| 471 | sub warn { # warning | ||||||
| 472 | 0 | 0 | 1 | problem(@_); | |||
| 473 | 0 | 0 | my $m =$_[1] || $@ || $!; | ||||
| 474 | 0 | 0 | if ($m !~/\n/) { | ||||
| 475 | 0 | CGI::Carp::cluck($m) # carp cluck | |||||
| 476 | } | ||||||
| 477 | else { | ||||||
| 478 | 0 | eval {$_[0]->pushlog('Warning $m')}; | |||||
| 0 | |||||||
| 479 | 0 | $m=$_[0]->htmlescape($m); | |||||
| 480 | 0 | 0 | 0 | if (!$_[0] ||!$_[0]->{-cache} ||!$_[0]->{-cache}->{-httpheader}) { | |||
| 0 | |||||||
| 481 | 0 | print STDOUT "Content-type: text/html\n\n"; | |||||
| 482 | } | ||||||
| 483 | 0 | print STDOUT '' .$_[0]->lng(0,'Warning') ."\n"; |
|||||
| 484 | 0 | print STDOUT "$m \n"; |
|||||
| 485 | } | ||||||
| 486 | } | ||||||
| 487 | |||||||
| 488 | |||||||
| 489 | sub die { # stop error | ||||||
| 490 | 0 | 0 | 0 | 1 | my $m =$_[1] || $@ || $!; | ||
| 491 | 0 | 0 | if (!CGI::Carp::ineval) { #!$^S | ||||
| 492 | 0 | eval {$_[0]->pushlog('Error $m', @{$_[0]->pushmsg} ,'<---Error')}; | |||||
| 0 | |||||||
| 0 | |||||||
| 493 | 0 | 0 | 0 | if ($m !~/\n/ || !$_[0]->{-cgi}) { | |||
| 494 | 0 | eval{$_[0]->reset}; # for mod_perl | |||||
| 0 | |||||||
| 495 | 0 | CGI::Carp::confess($m) # croak confess | |||||
| 496 | } | ||||||
| 497 | 0 | $m=$_[0]->htmlescape($m); | |||||
| 498 | 0 | 0 | 0 | if (!$_[0] ||!$_[0]->{-cache} ||!$_[0]->{-cache}->{-httpheader}) { | |||
| 0 | |||||||
| 499 | 0 | print STDOUT "Content-type: text/html\n\n"; | |||||
| 500 | } | ||||||
| 501 | 0 | print STDOUT '' .$_[0]->lng(0,'Error') ."\n"; |
|||||
| 502 | 0 | print STDOUT "$m \n"; |
|||||
| 503 | 0 | print STDOUT '' | |||||
| 504 | 0 | , join('; ', map {$_[0]->htmlescape($_)} @{$_[0]->pushmsg}) |
|||||
| 0 | |||||||
| 505 | , ''; | ||||||
| 506 | 0 | print STDOUT " \n"; |
|||||
| 507 | 0 | eval{$_[0]->reset}; # for mod_perl | |||||
| 0 | |||||||
| 508 | 0 | exit; | |||||
| 509 | } | ||||||
| 510 | 0 | 0 | $m !~/\n/ ? CGI::Carp::confess($m) : CORE::die($m); # croak confess | ||||
| 511 | } | ||||||
| 512 | |||||||
| 513 | |||||||
| 514 | ####################### | ||||||
| 515 | |||||||
| 516 | |||||||
| 517 | sub cgi { # CGI object | ||||||
| 518 | 0 | 0 | 1 | $_[0]->{-cgi} | |||
| 519 | } | ||||||
| 520 | |||||||
| 521 | |||||||
| 522 | sub request { # Web server request object | ||||||
| 523 | 0 | 0 | 0 | 1 | $ENV{MOD_PERL} ? Apache->request | ||
| 524 | : $_[0]->{-cgi} | ||||||
| 525 | } | ||||||
| 526 | |||||||
| 527 | |||||||
| 528 | sub dbi { # DBI object | ||||||
| 529 | 0 | 0 | 0 | 0 | 1 | if (scalar(@_) >1) { | |
| 0 | |||||||
| 530 | 0 | my $s =shift; | |||||
| 531 | 0 | 0 | $s->{-dbi} =eval('use DBI; DBI->connect(@_)') ||$s->die("Cannot connect to database\n") | ||||
| 532 | } | ||||||
| 533 | elsif (!$_[0]->{-dbi} && $_[0]->{-classes}->{-dbi}) { | ||||||
| 534 | 0 | my $s =shift; | |||||
| 535 | # $s->pushmsg('DBI connect'); | ||||||
| 536 | 0 | my $v =$s->{-classes}->{-dbi}; | |||||
| 537 | 0 | 0 | $s->{-dbi} =ref($v) eq 'CODE' ? &$v($s) : $s->dbi(@$v); | ||||
| 538 | } | ||||||
| 539 | else { | ||||||
| 540 | 0 | $_[0]->{-dbi} | |||||
| 541 | } | ||||||
| 542 | } | ||||||
| 543 | |||||||
| 544 | |||||||
| 545 | sub dbquote { | ||||||
| 546 | 0 | $_[0]->{-dbi} ||$_[0]->{-classes}->{-dbi} | |||||
| 547 | ? $_[0]->dbi->quote(@_[1..$#_]) | ||||||
| 548 | 0 | 0 | 0 | 0 | 1 | : ('"' .join('', map {my $v=$_; $v=~s/([\\"])/\\$1/g; $v} @_[1..$#_]) .'"') | |
| 0 | |||||||
| 0 | |||||||
| 549 | } | ||||||
| 550 | |||||||
| 551 | |||||||
| 552 | sub dblikesc { | ||||||
| 553 | 0 | 0 | 1 | join('', map {my $v =$_; $v =~s/([\\%_])/\\$1/g; $v} @_[1..$#_]) | |||
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 554 | } | ||||||
| 555 | |||||||
| 556 | |||||||
| 557 | ####################### | ||||||
| 558 | |||||||
| 559 | |||||||
| 560 | |||||||
| 561 | sub url { # CGI script URL | ||||||
| 562 | 0 | 0 | 0 | 0 | if ($#_ >0) { | ||
| 563 | 0 | local $^W =0; | |||||
| 564 | 0 | 0 | my $v =($_[0]->{-cgi}||$_[0]->cgi)->url(@_[1..$#_]); | ||||
| 565 | 0 | 0 | 0 | if ($v) {} | |||
| 0 | 0 | ||||||
| 0 | 0 | ||||||
| 0 | |||||||
| 0 | |||||||
| 566 | elsif (!($ENV{PERLXS} ||(($ENV{GATEWAY_INTERFACE}||'') =~/PerlEx/))) {} | ||||||
| 567 | elsif (($#_ >2) ||(($#_ ==2) && !$_[2])) {} | ||||||
| 568 | elsif ($_[1] eq '-relative') { | ||||||
| 569 | 0 | $v =$ENV{SCRIPT_NAME}; | |||||
| 570 | 0 | 0 | $v =$1 if $v =~/[\\\/]([^\\\/]+)$/; | ||||
| 571 | } | ||||||
| 572 | elsif ($_[1] eq '-absolute') { | ||||||
| 573 | 0 | $v =$ENV{SCRIPT_NAME} | |||||
| 574 | } | ||||||
| 575 | 0 | return($v) | |||||
| 576 | } | ||||||
| 577 | 0 | 0 | return($_[0]->{-cache}->{-url}) | ||||
| 578 | if $_[0]->{-cache}->{-url}; | ||||||
| 579 | 0 | local $^W =0; | |||||
| 580 | 0 | $_[0]->{-cache}->{-url} =$_[0]->cgi->url(); | |||||
| 581 | 0 | 0 | 0 | if ($ENV{PERLXS} ||(($ENV{GATEWAY_INTERFACE}||'') =~/PerlEx/)) { | |||
| 0 | |||||||
| 582 | 0 | 0 | 0 | $_[0]->{-cache}->{-url} .= | |||
| 0 | 0 | ||||||
| 583 | (($_[0]->{-cache}->{-url} =~/\/$/) ||($ENV{SCRIPT_NAME} =~/^\//) ? '' : '/') | ||||||
| 584 | .$ENV{SCRIPT_NAME} | ||||||
| 585 | if ($_[0]->{-cache}->{-url} !~/\w\/\w/) && $ENV{SCRIPT_NAME}; | ||||||
| 586 | } | ||||||
| 587 | 0 | $_[0]->{-cache}->{-url} | |||||
| 588 | } | ||||||
| 589 | |||||||
| 590 | |||||||
| 591 | sub url_form { # form url for start_form | ||||||
| 592 | 0 | 0 | 0 | $_[0]->url | |||
| 593 | # $_[0]->url(-absolute=>1,-path=>1) | ||||||
| 594 | # $_[0]->cgi->self_url() | ||||||
| 595 | } | ||||||
| 596 | |||||||
| 597 | |||||||
| 598 | sub qpath { # Query (script) path | ||||||
| 599 | 0 | 0 | 0 | 0 | 1 | defined($_[0]->{-qpath}) ||($_[0]->{-qpath} =$ENV{SCRIPT_FILENAME} ||$ENV{PATH_TRANSLATED}); | |
| 600 | 0 | 0 | (!defined($_[1]) ? $_[0]->{-qpath} : $_[0]->{-qpath} .'/' .$_[1]) | ||||
| 601 | } | ||||||
| 602 | |||||||
| 603 | |||||||
| 604 | sub qurl { # Query (script) URL | ||||||
| 605 | 0 | 0 | 0 | 1 | defined($_[0]->{-qurl}) ||($_[0]->{-qurl} =$_[0]->url); | ||
| 606 | 0 | 0 | 0 | (!defined($_[1]) || $_[1] eq '' ? $_[0]->{-qurl} : ($_[0]->{-qurl} .'/')) | |||
| 0 | |||||||
| 607 | .(scalar(@_) >1 ? $_[0]->htmlurl(@_[1..$#_]) :'') | ||||||
| 608 | } | ||||||
| 609 | |||||||
| 610 | |||||||
| 611 | sub qparam { # Query param(s) set or get | ||||||
| 612 | 0 | 0 | 1 | my $s =shift; | |||
| 613 | 0 | 0 | if (!ref($_[0])) { # CGI param call | ||||
| 0 | |||||||
| 0 | |||||||
| 614 | 0 | $s->{-cgi}->param(@_) | |||||
| 615 | } | ||||||
| 616 | elsif (ref($_[0]) eq 'ARRAY') { | ||||||
| 617 | 0 | 0 | if (!defined($_[1])) { # qparam([names]) -> [values] | ||||
| 618 | 0 | my $r =[]; | |||||
| 619 | 0 | for (my $i =0; $i <=$#{$_[0]}; $i++) {push @$r, $s->{-cgi}->param($_[0]->[$i])} | |||||
| 0 | |||||||
| 0 | |||||||
| 620 | 0 | $r | |||||
| 621 | } | ||||||
| 622 | else { # qparam([names]=>[values]) -> [values] | ||||||
| 623 | 0 | for (my $i =0; $i <=$#{$_[0]}; $i++) {$s->{-cgi}->param($_[0]->[$i], $_[1]->[$i])} | |||||
| 0 | |||||||
| 0 | |||||||
| 624 | 0 | $_[1] | |||||
| 625 | } | ||||||
| 626 | } | ||||||
| 627 | elsif (ref($_[0]) eq 'HASH') { # qparam({name=>value,...}) -> {name=>value,...} | ||||||
| 628 | 0 | foreach my $k (keys(%{$_[0]})) {$s->{-cgi}->param($k,$_[0]->{$k})} | |||||
| 0 | |||||||
| 0 | |||||||
| 629 | 0 | $_[0] | |||||
| 630 | } | ||||||
| 631 | else { # CGI param call | ||||||
| 632 | 0 | $s->{-cgi}->param(@_) | |||||
| 633 | } | ||||||
| 634 | } | ||||||
| 635 | |||||||
| 636 | |||||||
| 637 | sub param { # CGI param call | ||||||
| 638 | 0 | 0 | 1 | shift->{-cgi}->param(@_) | |||
| 639 | } | ||||||
| 640 | |||||||
| 641 | |||||||
| 642 | sub qparamh { # Query params get as hash ref | ||||||
| 643 | 0 | 0 | 1 | my $s =shift; | |||
| 644 | 0 | 0 | 0 | return $s->qparam(@_) if ref($_[0]) ne 'ARRAY' || defined($_[1]); | |||
| 645 | 0 | my $r ={}; | |||||
| 646 | 0 | for (my $i =0; $i <=$#{$_[0]}; $i++) {$r->{$_[0]->[$i]} =$s->{-cgi}->param($_[0]->[$i])} | |||||
| 0 | |||||||
| 0 | |||||||
| 647 | 0 | $r | |||||
| 648 | } | ||||||
| 649 | |||||||
| 650 | |||||||
| 651 | sub qrun { # Query 'run' param - Script to run | ||||||
| 652 | 0 | 0 | 0 | 0 | 1 | $_[0]->{-cache}->{-qrun} =$_[1] | |
| 0 | |||||||
| 653 | ## || $ENV{REQUEST_URI} ? substr($ENV{REQUEST_URI}, length($ENV{SCRIPT_NAME})+1) :'' | ||||||
| 654 | || $_[0]->{-cgi}->param('_run') | ||||||
| 655 | || $_[0]->{-cgi}->url_param('') | ||||||
| 656 | || $_[0]->{-cgi}->url_param('run') | ||||||
| 657 | if !$_[0]->{-cache}->{-qrun} || $_[1]; | ||||||
| 658 | 0 | $_[0]->{-cache}->{-qrun} | |||||
| 659 | } | ||||||
| 660 | |||||||
| 661 | |||||||
| 662 | ####################### | ||||||
| 663 | |||||||
| 664 | |||||||
| 665 | sub spath { # Site Path | ||||||
| 666 | 0 | 0 | 0 | 1 | if (!defined($_[0]->{-spath})) { | ||
| 667 | 0 | 0 | $_[0]->{-spath} =substr($ENV{SCRIPT_FILENAME} ||$ENV{PATH_TRANSLATED} | ||||
| 0 | |||||||
| 668 | , 0 | ||||||
| 669 | , -length($ENV{SCRIPT_NAME} ||$ENV{PATH_INFO})); | ||||||
| 670 | } | ||||||
| 671 | 0 | 0 | !defined($_[1]) ? $_[0]->{-spath} : $_[0]->{-spath} .'/' .$_[1] | ||||
| 672 | } | ||||||
| 673 | |||||||
| 674 | |||||||
| 675 | sub surl { # Site URL | ||||||
| 676 | 0 | 0 | 0 | 0 | 1 | ($_[0]->{-surl} | |
| 0 | 0 | ||||||
| 677 | || ($_[0]->{-surl} = | ||||||
| 678 | $_[0]->url() =~/^([^\/]+:\/\/[^\/]+)/ ? $1 : $_[0]->url())) | ||||||
| 679 | . ((!defined($_[1]) || $_[1] eq '' ? '' : '/') | ||||||
| 680 | . (scalar(@_) >1 ? $_[0]->htmlurl(@_[1..$#_]) :'')); | ||||||
| 681 | } | ||||||
| 682 | |||||||
| 683 | |||||||
| 684 | sub bpath { # Binary Path | ||||||
| 685 | 0 | 0 | 0 | 1 | if (!defined($_[0]->{-bpath})) { | ||
| 686 | 0 | 0 | 0 | $_[0]->{-bpath} =(($ENV{SCRIPT_FILENAME} ||$ENV{PATH_TRANSLATED} ||$0) =~/^(.+?)[\\\/][^\\\/]+$/ ? $1 : ''); | |||
| 687 | } | ||||||
| 688 | 0 | 0 | !defined($_[1]) ? $_[0]->{-bpath} : $_[0]->{-bpath} .'/' .$_[1] | ||||
| 689 | } | ||||||
| 690 | |||||||
| 691 | |||||||
| 692 | sub burl { # Binary URL | ||||||
| 693 | 0 | 0 | 0 | 1 | if (!defined($_[0]->{-burl})) { | ||
| 694 | 0 | 0 | 0 | my $pv =(($ENV{SCRIPT_NAME} ||$ENV{PATH_INFO} ||$0) =~/^[\\\/]*(.+?)[\\\/]+[^\\\/]+$/ ? $1 : ''); | |||
| 695 | 0 | 0 | $_[0]->{-burl} =$_[0]->surl .($pv ? '/' .$pv :''); | ||||
| 696 | } | ||||||
| 697 | 0 | 0 | 0 | (!defined($_[1]) || $_[1] eq '' ? $_[0]->{-burl} : ($_[0]->{-burl} .'/')) | |||
| 0 | |||||||
| 698 | .(scalar(@_) >1 ? $_[0]->htmlurl(@_[1..$#_]) : '') | ||||||
| 699 | } | ||||||
| 700 | |||||||
| 701 | |||||||
| 702 | sub dpath { # Data Path | ||||||
| 703 | 0 | 0 | 0 | 1 | if (!defined($_[0]->{-dpath})) { | ||
| 704 | 0 | $_[0]->{-dpath} =$_[0]->tpath; | |||||
| 705 | } | ||||||
| 706 | 0 | 0 | !defined($_[1]) ? $_[0]->{-dpath} : $_[0]->{-dpath} .'/' .$_[1] | ||||
| 707 | } | ||||||
| 708 | |||||||
| 709 | |||||||
| 710 | sub tpath { # Temporary files Path | ||||||
| 711 | 0 | 0 | 0 | 1 | if (!defined($_[0]->{-tpath})) { | ||
| 712 | 0 | 0 | $_[0]->{-tpath} =$TempFile::TMPDIRECTORY # use CGI | ||||
| 713 | ||$ENV{TMP} ||$ENV{TEMP} | ||||||
| 714 | ||$_[0]->orarg('-d' | ||||||
| 715 | ,$^O eq 'MSWin32' | ||||||
| 716 | ?('c:/tmp','c:/temp') | ||||||
| 717 | :('/tmp','/temp')); | ||||||
| 718 | 0 | 0 | $_[0]->{-tpath} = ($_[0]->{-tpath} ||'') .'/cgi-bus' | ||||
| 719 | } | ||||||
| 720 | 0 | 0 | !defined($_[1]) ? $_[0]->{-tpath} : $_[0]->{-tpath} .'/' .$_[1] | ||||
| 721 | } | ||||||
| 722 | |||||||
| 723 | |||||||
| 724 | sub ppath { # Publish Path | ||||||
| 725 | 0 | 0 | 0 | 1 | if (!defined($_[0]->{-ppath})) { | ||
| 726 | 0 | 0 | $_[0]->{-ppath} =$ENV{DOCUMENT_ROOT} ||$ENV{PATH_TRANSLATED} ||'.'; | ||||
| 727 | } | ||||||
| 728 | 0 | 0 | !defined($_[1]) ? $_[0]->{-ppath} : $_[0]->{-ppath} .'/' .$_[1] | ||||
| 729 | } | ||||||
| 730 | |||||||
| 731 | |||||||
| 732 | sub purl { # Publish URL | ||||||
| 733 | 0 | 0 | 0 | 1 | if (!defined($_[0]->{-purl})) { | ||
| 734 | 0 | $_[0]->{-purl} =$_[0]->surl; | |||||
| 735 | } | ||||||
| 736 | 0 | 0 | 0 | (!defined($_[1]) || $_[1] eq '' ? $_[0]->{-purl} : ($_[0]->{-purl} .'/')) | |||
| 0 | |||||||
| 737 | .(scalar(@_) >1 ? $_[0]->htmlurl(@_[1..$#_]) : '') | ||||||
| 738 | } | ||||||
| 739 | |||||||
| 740 | |||||||
| 741 | sub fpath { # File Store Path | ||||||
| 742 | 0 | 0 | 0 | 1 | $_[0]->{-fpath} =$_[0]->ppath if !defined($_[0]->{-fpath}); | ||
| 743 | 0 | 0 | !defined($_[1]) ? $_[0]->{-fpath} : $_[0]->{-fpath} .'/' .$_[1] | ||||
| 744 | } | ||||||
| 745 | |||||||
| 746 | |||||||
| 747 | sub furl { # File Store URL | ||||||
| 748 | 0 | 0 | 0 | 1 | $_[0]->{-furl} =$_[0]->purl if !defined($_[0]->{-furl}); | ||
| 749 | 0 | 0 | 0 | (!defined($_[1]) || $_[1] eq '' ? $_[0]->{-furl} : ($_[0]->{-furl} .'/')) | |||
| 0 | |||||||
| 750 | .(scalar(@_) >1 ? $_[0]->htmlurl(@_[1..$#_]) : '') | ||||||
| 751 | } | ||||||
| 752 | |||||||
| 753 | |||||||
| 754 | sub furf { # File Store file URL | ||||||
| 755 | 0 | 0 | 0 | 1 | $_[0]->{-furf} ='file://' .$_[0]->fpath if !defined($_[0]->{-furf}); | ||
| 756 | 0 | 0 | 0 | (!defined($_[1]) || $_[1] eq '' ? $_[0]->{-furf} : ($_[0]->{-furf} .'/')) | |||
| 0 | |||||||
| 757 | .(scalar(@_) >1 ? $_[0]->htmlurl(@_[1..$#_]) : '') | ||||||
| 758 | } | ||||||
| 759 | |||||||
| 760 | |||||||
| 761 | sub hpath { # Homes Store Path | ||||||
| 762 | 0 | 0 | 0 | 1 | $_[0]->{-hpath} =$_[0]->ppath if !defined($_[0]->{-hpath}); | ||
| 763 | 0 | 0 | !defined($_[1]) ? $_[0]->{-hpath} : $_[0]->{-hpath} .'/' .$_[1] | ||||
| 764 | } | ||||||
| 765 | |||||||
| 766 | |||||||
| 767 | sub hurl { # Homes Store URL | ||||||
| 768 | 0 | 0 | 0 | 1 | $_[0]->{-hurl} =$_[0]->purl if !defined($_[0]->{-hurl}); | ||
| 769 | 0 | 0 | 0 | (!defined($_[1]) || $_[1] eq '' ? $_[0]->{-hurl} : ($_[0]->{-hurl} .'/')) | |||
| 0 | |||||||
| 770 | .(scalar(@_) >1 ? $_[0]->htmlurl(@_[1..$#_]) : '') | ||||||
| 771 | } | ||||||
| 772 | |||||||
| 773 | |||||||
| 774 | sub hurf { # Homes Store file URL | ||||||
| 775 | 0 | 0 | 0 | 1 | $_[0]->{-hurf} ='file://' .$_[0]->hpath if !defined($_[0]->{-hurf}); | ||
| 776 | 0 | 0 | 0 | (!defined($_[1]) || $_[1] eq '' ? $_[0]->{-hurf} : ($_[0]->{-hurf} .'/')) | |||
| 0 | |||||||
| 777 | .(scalar(@_) >1 ? $_[0]->htmlurl(@_[1..$#_]) : '') | ||||||
| 778 | } | ||||||
| 779 | |||||||
| 780 | |||||||
| 781 | sub urfcnd { # Use URFs? | ||||||
| 782 | 0 | 0 | 1 | my $s =shift; | |||
| 783 | 0 | ($s->{-cgi}->user_agent||'') =~/MSIE|StarOffice/ | |||||
| 784 | 0 | 0 | 0 | && ( ref($s->{-urfcnd}) eq 'CODE' ? &{$s->{-urfcnd}}(@_) | |||
| 0 | |||||||
| 0 | |||||||
| 785 | : exists $s->{-urfcnd} ? $s->{-urfcnd} | ||||||
| 786 | : 1 # $ENV{REMOTE_ADDR} | ||||||
| 787 | ) | ||||||
| 788 | } | ||||||
| 789 | |||||||
| 790 | |||||||
| 791 | ####################### | ||||||
| 792 | |||||||
| 793 | |||||||
| 794 | sub hmerge { # merge hash ref with data given | ||||||
| 795 | 0 | 0 | 0 | my ($s, $h) =(shift, shift); | |||
| 796 | 0 | 0 | my $r =$h ? {%$h} : {}; | ||||
| 797 | 0 | my %h =@_; | |||||
| 798 | 0 | 0 | foreach my $k (keys %h) {$r->{$k} =$h{$k} if !exists($r->{$k})} | ||||
| 0 | |||||||
| 799 | $r | ||||||
| 800 | 0 | } | |||||
| 801 | |||||||
| 802 | |||||||
| 803 | sub max { # maximal number | ||||||
| 804 | 0 | 0 | 0 | 0 | 0 | (($_[1]||0) >($_[2]||0) ? $_[1] : $_[2])||0 | |
| 0 | 0 | ||||||
| 805 | } | ||||||
| 806 | |||||||
| 807 | |||||||
| 808 | sub min { # minimal number | ||||||
| 809 | 0 | 0 | 0 | 0 | 0 | (($_[1]||0) >($_[2]||0) ? $_[2] : $_[1])||0 | |
| 0 | 0 | ||||||
| 810 | } | ||||||
| 811 | |||||||
| 812 | |||||||
| 813 | sub orarg { # argument of true result | ||||||
| 814 | 0 | 0 | 1 | shift(@_); | |||
| 815 | 0 | 0 | my $s =ref($_[0]) ? shift | ||||
| 0 | |||||||
| 816 | :index($_[0], '-') ==0 ? eval('sub{' .shift(@_) .' $_}') | ||||||
| 817 | :eval('sub{' .shift(@_) .'($_)}'); | ||||||
| 818 | 0 | local $_; | |||||
| 819 | 0 | 0 | foreach (@_) {return $_ if &$s($_)}; | ||||
| 0 | |||||||
| 820 | undef | ||||||
| 821 | 0 | } | |||||
| 822 | |||||||
| 823 | |||||||
| 824 | sub strtime { # Stringify Time | ||||||
| 825 | 0 | 0 | 1 | my $s =shift; | |||
| 826 | 0 | 0 | 0 | my $msk =@_ ==0 || $_[0] =~/^\d+$/i ? 'yyyy-mm-dd hh:mm:ss' : shift; | |||
| 827 | 0 | 0 | my @tme =@_ ==0 ? localtime(time) : @_ ==1 ? localtime($_[0]) : @_; | ||||
| 0 | |||||||
| 828 | 0 | $msk =~s/yyyy/%Y/; | |||||
| 829 | 0 | $msk =~s/yy/%y/; | |||||
| 830 | 0 | $msk =~s/mm/%m/; | |||||
| 831 | 0 | $msk =~s/mm/%M/i; | |||||
| 832 | 0 | $msk =~s/dd/%d/; | |||||
| 833 | 0 | $msk =~s/hh/%H/; | |||||
| 834 | 0 | $msk =~s/hh/%h/i; | |||||
| 835 | 0 | $msk =~s/ss/%S/; | |||||
| 836 | 0 | eval('use POSIX'); | |||||
| 837 | 0 | POSIX::strftime($msk, @tme) | |||||
| 838 | } | ||||||
| 839 | |||||||
| 840 | |||||||
| 841 | sub timestr { # Time from String | ||||||
| 842 | 0 | 0 | 1 | my $s =shift; | |||
| 843 | 0 | 0 | 0 | my $msk =@_ <2 || !$_[1] ? 'yyyy-mm-dd hh:mm:ss' : shift; | |||
| 844 | 0 | my $ts =shift; | |||||
| 845 | 0 | my %th; | |||||
| 846 | 0 | while ($msk =~/(yyyy|yy|mm|dd|hh|MM|ss)/) { | |||||
| 847 | 0 | my $m=$1; $msk =$'; | |||||
| 0 | |||||||
| 848 | 0 | 0 | last if !($ts =~/(\d+)/); | ||||
| 849 | 0 | my $d =$1; $ts =$'; | |||||
| 0 | |||||||
| 850 | 0 | 0 | 0 | $d -=1900 if $m eq 'yyyy' ||$m eq '%Y'; | |||
| 851 | 0 | $m =chop($m); | |||||
| 852 | 0 | 0 | 0 | $m ='M' if $m eq 'm' && $th{$m}; | |||
| 853 | 0 | 0 | $m =lc($m) if $m ne 'M'; | ||||
| 854 | 0 | $th{$m}=$d; | |||||
| 855 | } | ||||||
| 856 | 0 | eval('use POSIX'); | |||||
| 857 | 0 | 0 | POSIX::mktime($th{'s'}||0,$th{'M'}||0,$th{'h'}||0,$th{'d'}||0,($th{'m'}||1)-1,$th{'y'}||0) | ||||
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 858 | } | ||||||
| 859 | |||||||
| 860 | |||||||
| 861 | sub timeadd { # Adjust time to years, months, days,... | ||||||
| 862 | 0 | 0 | 1 | my $s =shift; | |||
| 863 | 0 | my @t =localtime(shift); | |||||
| 864 | 0 | my $i =5; | |||||
| 865 | 0 | 0 | foreach my $a (@_) {$t[$i] += ($a||0); $i--} | ||||
| 0 | |||||||
| 0 | |||||||
| 866 | 0 | eval('use POSIX'); | |||||
| 867 | 0 | POSIX::mktime(@t[0..5]) | |||||
| 868 | } | ||||||
| 869 | |||||||
| 870 | |||||||
| 871 | sub cptran { # Translate strings between codepages | ||||||
| 872 | 0 | 0 | 1 | my ($s,$f,$t,@s) =@_; | |||
| 873 | 0 | foreach my $v ($f, $t) { | |||||
| 874 | 0 | 0 | if ($v =~/oem|866/i) {$v ='€‚ƒ„…ð†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™œ›šžŸ ¡¢£¤¥ñ¦§¨©ª«¬®¯àáâãäåæçèéìëêíîï'} | ||||
| 0 | 0 | ||||||
| 0 | 0 | ||||||
| 0 | |||||||
| 875 | 0 | elsif ($v =~/ansi|1251/i) {$v ='ÀÁÂÃÄŨÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÜÛÚÝÞßàáâãä叿çèéêëìíîïðñòóôõö÷øùüûúýþÿ'} | |||||
| 876 | 0 | elsif ($v =~/koi/i) {$v ='áâ÷çäå³öúéêëìíîïðòóôõæèãþûýøùÿüàñÁÂ×ÇÄÅ£ÖÚÉÊËÌÍÎÏÐÒÓÔÕÆÈÃÞÛÝØÙßÜÀÑ'} | |||||
| 877 | elsif ($v =~/8859-5/i) {$v ='°±²³´µ¡¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÌËÊÍÎÏÐÑÒÓÔÕñÖרÙÚÛÜÝÞßàáâãäåæçèéìëêíîï'} | ||||||
| 878 | } | ||||||
| 879 | 0 | map {eval("~tr/$f/$t/")} @s; | |||||
| 0 | |||||||
| 880 | 0 | 0 | @s >1 ? @s : $s[0]; | ||||
| 881 | } | ||||||
| 882 | |||||||
| 883 | |||||||
| 884 | sub dumpout { # Data dump out | ||||||
| 885 | 0 | 0 | 1 | my ($s, $d) =@_; | |||
| 886 | 0 | eval('use Data::Dumper'); | |||||
| 887 | 0 | my $o =Data::Dumper->new([$d]); | |||||
| 888 | 0 | $o->Indent(1); | |||||
| 889 | 0 | $o->Dump(); | |||||
| 890 | } | ||||||
| 891 | |||||||
| 892 | |||||||
| 893 | sub dumpin { # Data dump in | ||||||
| 894 | 0 | 0 | 1 | my ($s, $d) =@_; | |||
| 895 | 0 | 0 | my $e; for(my $i=0; !$e && $i<10; $i++) {$e =eval('use Safe; Safe->new()')}; | ||||
| 0 | |||||||
| 0 | |||||||
| 896 | 0 | 0 | defined($e) && $e->reval($d) | ||||
| 897 | } | ||||||
| 898 | |||||||
| 899 | |||||||
| 900 | sub ishtml { # Is html code? | ||||||
| 901 | 0 | 0 | 0 | 1 | ($_[1] ||'') =~m/^<(?:(?:B|BIG|BLOCKQUOTE|CENTER|CITE|CODE|DFN|DIV|EM|I|KBD|P|SAMP|SMALL|SPAN|STRIKE|STRONG|STYLE|SUB|SUP|TT|U|VAR)\s*>|(?:BR|HR)\s*\/{0,1}>|(?:A|BASE|BASEFONT|DIR|DIV|DL|!DOCTYPE|FONT|H\d|HEAD|HTML|IMG|IFRAME|MAP|MENU|OL|P|PRE|TABLE|UL)\b)/i | ||
| 902 | } | ||||||
| 903 | |||||||
| 904 | |||||||
| 905 | |||||||
| 906 | ####################### | ||||||
| 907 | |||||||
| 908 | |||||||
| 909 | |||||||
| 910 | sub user { # User name | ||||||
| 911 | 0 | 0 | 0 | 0 | 1 | if (!$_[0]->{-cache}->{-user} ||$_[1]) { | |
| 912 | 0 | $_[0]->{-cache}->{-user} =$_[0]->{-cache}->{-useron} = | |||||
| 913 | $_[1] ? $_[1] : | ||||||
| 914 | 0 | 0 | ref($_[0]->{-user}) eq 'CODE' ? &{$_[0]->{-user}}(@_) | ||||
| 0 | |||||||
| 915 | : $_[0]->uauth->user(@_[1..$#_]); | ||||||
| 916 | 0 | 0 | if ($_[0]->{-usercnv}) { | ||||
| 917 | 0 | local $_ =$_[0]->{-cache}->{-user}; | |||||
| 918 | 0 | $_[0]->{-cache}->{-user} =&{$_[0]->{-usercnv}}(@_) | |||||
| 0 | |||||||
| 919 | } | ||||||
| 920 | } | ||||||
| 921 | 0 | $_[0]->{-cache}->{-user} | |||||
| 922 | } | ||||||
| 923 | |||||||
| 924 | |||||||
| 925 | sub useron { # User original name | ||||||
| 926 | 0 | 0 | 0 | 1 | $_[0]->user if !$_[0]->{-cache}->{-useron}; | ||
| 927 | 0 | $_[0]->{-cache}->{-useron} | |||||
| 928 | } | ||||||
| 929 | |||||||
| 930 | |||||||
| 931 | sub uadmin { # Is admin? | ||||||
| 932 | 0 | 0 | 1 | my $s =shift; | |||
| 933 | 0 | my $u =$s->user; | |||||
| 934 | 0 | 0 | if (scalar(@_)) { | ||||
| 935 | 0 | 0 | return $u if $_[0] eq $u; | ||||
| 936 | 0 | 0 | 0 | return $s->uadmin ? $s->uglist | |||
| 0 | |||||||
| 937 | : ($s->udata->paramj('uauth_managed') ||[]) | ||||||
| 938 | if ref($_[0]); | ||||||
| 939 | 0 | 0 | my $l =$s->udata->paramj('uauth_managed') ||[]; | ||||
| 940 | 0 | foreach my $n (@$l) { | |||||
| 941 | 0 | 0 | return $n if $n eq $_[0] | ||||
| 942 | } | ||||||
| 943 | } | ||||||
| 944 | 0 | 0 | if (!defined($s->{-uadmins})) {} | ||||
| 0 | 0 | ||||||
| 0 | |||||||
| 945 | 0 | elsif (ref($s->{-uadmins}) eq 'CODE') {return &{$s->{-uadmins}}($s)} | |||||
| 946 | 0 | 0 | elsif (ref($s->{-uadmins}) eq 'ARRAY') { | ||||
| 947 | 0 | foreach my $n (@{$s->ugnames}) { | |||||
| 0 | |||||||
| 948 | 0 | 0 | next if !defined($n); | ||||
| 949 | 0 | 0 | return $n if grep {$_ eq $n} @{$s->{-uadmins}} | ||||
| 0 | |||||||
| 0 | |||||||
| 950 | } | ||||||
| 951 | } | ||||||
| 952 | else {return $u if $u eq $s->{-uadmins}} | ||||||
| 953 | 0 | return ''; | |||||
| 954 | } | ||||||
| 955 | |||||||
| 956 | |||||||
| 957 | sub uguest { # Is guest? | ||||||
| 958 | 0 | 0 | 0 | 1 | ($_[1] ||$_[0]->user ||'') eq $_[0]->uauth->guest | ||
| 959 | } | ||||||
| 960 | |||||||
| 961 | |||||||
| 962 | sub usercn { # User name CN | ||||||
| 963 | 0 | 0 | 0 | 1 | my $v =scalar(@_) >1 ? $_[1] : $_[0]->user; | ||
| 964 | 0 | 0 | 0 | return($v) if !defined($v) || $v eq ''; | |||
| 965 | 0 | 0 | $v =~/CN=([^=,]+)/i ? $1 | ||||
| 0 | |||||||
| 0 | |||||||
| 966 | : $v =~/^([^\@])\@/i ? $1 | ||||||
| 967 | : $v =~/\\([^\\]+)$/ ? $1 | ||||||
| 968 | : $v | ||||||
| 969 | } | ||||||
| 970 | |||||||
| 971 | |||||||
| 972 | sub usersn { # User Shorten Name, remove domain if default | ||||||
| 973 | 0 | 0 | 0 | 1 | my $v =scalar(@_) >1 ? $_[1] : $_[0]->user; | ||
| 974 | 0 | 0 | 0 | return($v) if !defined($v) || $v eq ''; | |||
| 975 | 0 | my $d =$_[0]->usdomain; | |||||
| 976 | 0 | 0 | if ($v =~m/^(.*?)[\/@]\Q$d\E$/i) {$1} | ||||
| 0 | 0 | ||||||
| 0 | |||||||
| 977 | 0 | elsif ($v =~m/^\Q$d\E[\\](.*)$/i) {$1} | |||||
| 978 | else {$v} | ||||||
| 979 | } | ||||||
| 980 | |||||||
| 981 | |||||||
| 982 | sub userfn { # User name translated to filename | ||||||
| 983 | 0 | 0 | 0 | 1 | my $v =scalar(@_) >1 ? $_[1] : $_[0]->user; | ||
| 984 | 0 | 0 | 0 | return($v) if !defined($v) || $v eq ''; | |||
| 985 | 0 | $v =~ s/[\\\/|\+\:\*\?\[\]\(\) &,]/-/g; | |||||
| 986 | 0 | $v | |||||
| 987 | } | ||||||
| 988 | |||||||
| 989 | |||||||
| 990 | sub userds { # User name as dir structure | ||||||
| 991 | 0 | 0 | 0 | 1 | my $u =scalar(@_) >1 ? $_[1] : $_[0]->user; | ||
| 992 | 0 | 0 | 0 | return($u) if !defined($u) || $u eq ''; | |||
| 993 | 0 | my $p =$_[0]->userfn($_[0]->usercn($u)); | |||||
| 994 | 0 | $p =substr($p,0,1) .'/' .substr($p,0,2) .'/' .$_[0]->userfn($u); | |||||
| 995 | } | ||||||
| 996 | |||||||
| 997 | |||||||
| 998 | sub unames { # User Names | ||||||
| 999 | 0 | 0 | 0 | 1 | if (!defined($_[0]->{-cache}->{-unames})) { | ||
| 1000 | 0 | my $s =$_[0]; | |||||
| 1001 | 0 | 0 | return('') if !defined($s->user); | ||||
| 1002 | 0 | $s->{-cache}->{-unames} =[]; | |||||
| 1003 | 0 | local $_; | |||||
| 1004 | 0 | 0 | foreach my $v ($_ =$s->user, $s->useron | ||||
| 0 | 0 | ||||||
| 0 | |||||||
| 0 | |||||||
| 1005 | # , lc($s->user), $s->usercn, lc($s->usercn) | ||||||
| 1006 | #, $s->user =~/^([^\\]+)\\(.+)$/ ? lc("$2\@$1") : () | ||||||
| 1007 | #, $s->useron =~/^([^\\]+)\\(.+)$/ ? lc("$2\@$1") : () | ||||||
| 1008 | , $s->user =~/^([^@]+)\@(.+)$/ ? lc("$2\\$1") : () | ||||||
| 1009 | , $s->useron =~/^([^@]+)\@(.+)$/ ? lc("$2\\$1") : () | ||||||
| 1010 | , ref($s->{-unmsadd}) eq 'ARRAY' | ||||||
| 1011 | 0 | ? map {&$_($s)} @{$s->{-unmsadd}} | |||||
| 0 | |||||||
| 1012 | : ref($s->{-unmsadd}) | ||||||
| 1013 | ? &{$s->{-unmsadd}}($s) | ||||||
| 1014 | : () | ||||||
| 1015 | ) { | ||||||
| 1016 | 0 | push @{$s->{-cache}->{-unames}}, $v | |||||
| 0 | |||||||
| 1017 | 0 | 0 | if !grep /^\Q$v\E$/, @{$s->{-cache}->{-unames}}; | ||||
| 1018 | } | ||||||
| 1019 | } | ||||||
| 1020 | 0 | $_[0]->{-cache}->{-unames} | |||||
| 1021 | } | ||||||
| 1022 | |||||||
| 1023 | |||||||
| 1024 | sub usdomain {# User names Server Domain | ||||||
| 1025 | 0 | 0 | 0 | 0 | 1 | if (!$_[0]->{-cache}->{-usdomain} ||$_[1]) { | |
| 1026 | $_[0]->{-cache}->{-usdomain} =$_[1] | ||||||
| 1027 | || (ref($_[0]->{-usdomain}) eq 'CODE' | ||||||
| 1028 | 0 | 0 | ? &{$_[0]->{-usdomain}}(@_) | ||||
| 1029 | : $_[0]->uauth->usdomain(@_[1..$#_])); | ||||||
| 1030 | } | ||||||
| 1031 | 0 | $_[0]->{-cache}->{-usdomain} | |||||
| 1032 | } | ||||||
| 1033 | |||||||
| 1034 | |||||||
| 1035 | sub userver { # User names Server | ||||||
| 1036 | 0 | 0 | 0 | 0 | 1 | if (!$_[0]->{-cache}->{-userver} ||$_[1]) { | |
| 1037 | $_[0]->{-cache}->{-userver} =$_[1] | ||||||
| 1038 | ||(ref($_[0]->{-userver}) eq 'CODE' | ||||||
| 1039 | 0 | 0 | ? &{$_[0]->{-userver}}(@_) | ||||
| 1040 | : $_[0]->uauth->userver(@_[1..$#_])); | ||||||
| 1041 | } | ||||||
| 1042 | 0 | $_[0]->{-cache}->{-userver} | |||||
| 1043 | } | ||||||
| 1044 | |||||||
| 1045 | |||||||
| 1046 | sub ugroups { # User groups [user name] | ||||||
| 1047 | 0 | 0 | 0 | 0 | 1 | if (!defined($_[0]->{-cache}->{-ugroups}) | |
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 1048 | || ($_[1] && (lc($_[0]->useron ||'') ne lc($_[1])) | ||||||
| 1049 | && (lc($_[0]->user ||'') ne lc($_[1])))) { | ||||||
| 1050 | 0 | my $s =$_[0]; | |||||
| 1051 | 0 | my $r =[]; | |||||
| 1052 | 0 | 0 | 0 | return($r) if !defined($s->user) && !$_[1]; | |||
| 1053 | 0 | $r = ref($s->{-ugroups}) eq 'CODE' | |||||
| 1054 | 0 | 0 | ? &{$s->{-ugroups}}(@_) | ||||
| 1055 | : $_[0]->uauth->ugroups(@_[1..$#_]); | ||||||
| 1056 | 0 | 0 | if ($_[0]->{-ugrpcnv}) { | ||||
| 1057 | 0 | my $ga =[]; | |||||
| 1058 | 0 | local $_; | |||||
| 1059 | 0 | foreach $_ (@$r) { | |||||
| 1060 | 0 | $_ =&{$_[0]->{-ugrpcnv}}(@_); | |||||
| 0 | |||||||
| 1061 | 0 | 0 | 0 | push(@$ga, $_) if defined($_) && $_ ne ''; | |||
| 1062 | } | ||||||
| 1063 | 0 | $r =$ga; | |||||
| 1064 | } | ||||||
| 1065 | 0 | 0 | if ($_[0]->{-ugrpadd}) { | ||||
| 1066 | 0 | local $_ =$r; | |||||
| 1067 | 0 | 0 | my $ugadd=ref($s->{-ugrpadd}) eq 'CODE' ? &{$s->{-ugrpadd}}(@_) : $s->{-ugrpadd}; | ||||
| 0 | |||||||
| 1068 | 0 | 0 | foreach my $e ( ref($ugadd) eq 'ARRAY' | ||||
| 0 | 0 | ||||||
| 1069 | ? @{$ugadd} | ||||||
| 1070 | : ref($ugadd) eq 'HASH' | ||||||
| 1071 | ? keys(%$ugadd) | ||||||
| 1072 | : $ugadd){ | ||||||
| 1073 | 0 | 0 | push @$r, $e if !grep /^\Q$e\E$/i, @$r | ||||
| 1074 | } | ||||||
| 1075 | } | ||||||
| 1076 | 1 | 1 | 965 | { use locale; | |||
| 1 | 274 | ||||||
| 1 | 6 | ||||||
| 0 | |||||||
| 1077 | 0 | $r =[sort {lc($a) cmp lc($b)} @$r]; | |||||
| 0 | |||||||
| 1078 | } | ||||||
| 1079 | 0 | 0 | 0 | $s->{-cache}->{-ugroups} =$r | |||
| 0 | |||||||
| 1080 | if !$_[1] | ||||||
| 1081 | || (lc($_[0]->useron) eq lc($_[1])) | ||||||
| 1082 | || (lc($_[0]->user) eq lc($_[1])); | ||||||
| 1083 | 0 | return($r) | |||||
| 1084 | } | ||||||
| 1085 | 0 | $_[0]->{-cache}->{-ugroups} | |||||
| 1086 | } | ||||||
| 1087 | |||||||
| 1088 | |||||||
| 1089 | sub ugnames { # User & Group Names | ||||||
| 1090 | 0 | 0 | 0 | 1 | if (!defined($_[0]->{-cache}->{-ugnames})) { | ||
| 1091 | 0 | my $s =$_[0]; | |||||
| 1092 | 0 | 0 | return('') if !defined($s->user); | ||||
| 1093 | 0 | $s->{-cache}->{-ugnames} =[]; | |||||
| 1094 | 0 | push @{$s->{-cache}->{-ugnames}}, @{$s->unames}; | |||||
| 0 | |||||||
| 0 | |||||||
| 1095 | 0 | push @{$s->{-cache}->{-ugnames}}, @{$s->ugroups}; | |||||
| 0 | |||||||
| 0 | |||||||
| 1096 | } | ||||||
| 1097 | 0 | $_[0]->{-cache}->{-ugnames} | |||||
| 1098 | } | ||||||
| 1099 | |||||||
| 1100 | |||||||
| 1101 | sub uglist { # User & Group List | ||||||
| 1102 | 0 | 0 | 1 | my $s =shift; | |||
| 1103 | 0 | 0 | 0 | my $o =defined($_[0]) && substr($_[0],0,1) eq '-' ? shift : '-ug'; | |||
| 1104 | 0 | my $r = | |||||
| 1105 | 0 | 0 | ref($s->{-uglist}) eq 'CODE' ? &{$s->{-uglist}}($s,$o,@_) | ||||
| 1106 | : $s->uauth->uglist($o,@_); | ||||||
| 1107 | 0 | 0 | if ($s->{-ugrpadd}) { | ||||
| 1108 | 0 | local $_ =$r; | |||||
| 1109 | 0 | 0 | my $ugadd=ref($s->{-ugrpadd}) eq 'CODE' ? &{$s->{-ugrpadd}}(@_) : $s->{-ugrpadd}; | ||||
| 0 | |||||||
| 1110 | 0 | 0 | 0 | if ((ref($r) eq 'HASH') | |||
| 1111 | && (ref($ugadd) eq 'HASH')) { | ||||||
| 1112 | 0 | foreach my $e (keys(%$ugadd)) { | |||||
| 1113 | 0 | 0 | $r->{$e} =$ugadd->{$e} if !$r->{$e} | ||||
| 1114 | } | ||||||
| 1115 | } | ||||||
| 1116 | else { | ||||||
| 1117 | 0 | 0 | foreach my $e ( ref($ugadd) eq 'ARRAY' | ||||
| 0 | 0 | ||||||
| 1118 | ? @{$ugadd} | ||||||
| 1119 | : ref($ugadd) eq 'HASH' | ||||||
| 1120 | ? keys(%$ugadd) | ||||||
| 1121 | : $ugadd){ | ||||||
| 1122 | 0 | 0 | if (ref($r) eq 'HASH') { | ||||
| 1123 | 0 | 0 | $r->{$e} =$e if !$r->{$e} | ||||
| 1124 | } | ||||||
| 1125 | else { | ||||||
| 1126 | 0 | 0 | push @$r, $e if !grep /^\Q$e\E$/i, @$r | ||||
| 1127 | } | ||||||
| 1128 | } | ||||||
| 1129 | } | ||||||
| 1130 | } | ||||||
| 1131 | 1 | 0 | 1 | 472 | $r =do{use locale; [sort {lc($a) cmp lc($b)} @$r]} if ref($r) eq 'ARRAY'; | ||
| 1 | 3 | ||||||
| 1 | 4 | ||||||
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 1132 | |||||||
| 1133 | 0 | 0 | if ($s->{-ugrpcnv}) { | ||||
| 1134 | 0 | local $_; | |||||
| 1135 | 0 | 0 | if (ref($r) eq 'ARRAY') { | ||||
| 1136 | 0 | my @g; | |||||
| 1137 | 0 | foreach $_ (@$r) { | |||||
| 1138 | 0 | $_ =&{$s->{-ugrpcnv}}($s,$o); | |||||
| 0 | |||||||
| 1139 | 0 | 0 | 0 | push(@g, $_) if defined($_) && $_ ne ''; | |||
| 1140 | } | ||||||
| 1141 | 0 | $r =[sort {lc($a) cmp lc($b)} @g]; | |||||
| 0 | |||||||
| 1142 | } | ||||||
| 1143 | else { | ||||||
| 1144 | 0 | my $w =$_[1]; # width of label | |||||
| 1145 | 0 | foreach my $k (keys %$r) { | |||||
| 1146 | 0 | $_ =$k; | |||||
| 1147 | 0 | $_ =&{$s->{-ugrpcnv}}($s,$o); | |||||
| 0 | |||||||
| 1148 | 0 | 0 | 0 | if (defined($_) && $_ ne '') { | |||
| 0 | 0 | ||||||
| 0 | |||||||
| 1149 | 0 | $r->{$_} =$r->{$k}; | |||||
| 1150 | 0 | 0 | $r->{$_} =substr($r->{$_},0,$w) if $w; | ||||
| 1151 | } | ||||||
| 1152 | elsif (!defined($_) || $_ eq '' || $_ ne $k) { | ||||||
| 1153 | 0 | delete $r->{$k} | |||||
| 1154 | } | ||||||
| 1155 | } | ||||||
| 1156 | } | ||||||
| 1157 | } | ||||||
| 1158 | $r | ||||||
| 1159 | 0 | } | |||||
| 1160 | |||||||
| 1161 | |||||||
| 1162 | sub unamesun {# User Names Unique list | ||||||
| 1163 | 0 | 0 | 1 | my $s =shift; | |||
| 1164 | 0 | my $r =[]; | |||||
| 1165 | 0 | 0 | foreach my $n (ref($_[0]) ? @{$_[0]} : @_) { | ||||
| 0 | |||||||
| 1166 | 0 | 0 | next if grep {lc($n) eq lc($_) | ||||
| 0 | 0 | ||||||
| 1167 | || lc($s->usercn($n)) eq lc($s->usercn($_))} @$r; | ||||||
| 1168 | 0 | push @$r, $n; | |||||
| 1169 | } | ||||||
| 1170 | $r | ||||||
| 1171 | 0 | } | |||||
| 1172 | |||||||
| 1173 | |||||||
| 1174 | sub userauth {# User Authenticate | ||||||
| 1175 | 0 | 0 | 1 | my $s =shift; | |||
| 1176 | 0 | 0 | 0 | $s->{-w32IISdpsn} =($ENV{SERVER_SOFTWARE}||'') !~/IIS/ | |||
| 0 | 0 | ||||||
| 0 | |||||||
| 1177 | ? 0 | ||||||
| 1178 | : ($s->{-login}||'') =~/\/$/i | ||||||
| 1179 | ? 2 | ||||||
| 1180 | : 0 | ||||||
| 1181 | if !defined($s->{-w32IISdpsn}); | ||||||
| 1182 | 0 | 0 | ref($s->{-userauth}) eq 'CODE' ? &{$s->{-userauth}}($s,@_) | ||||
| 0 | 0 | ||||||
| 0 | |||||||
| 1183 | : ref($s->{-userauth}) eq 'ARRAY' ? $s->uauth->auth($s->{-userauth},@_) | ||||||
| 1184 | : $s->{-userauth} ? $s->uauth->auth([$s->{-userauth}],@_) | ||||||
| 1185 | : $s->uauth->auth(@_); | ||||||
| 1186 | 0 | $s->{-cache}->{-userauth} =$s->user | |||||
| 1187 | } | ||||||
| 1188 | |||||||
| 1189 | |||||||
| 1190 | |||||||
| 1191 | sub userauthopt { # User Authenticate optional | ||||||
| 1192 | 0 | 0 | 1 | my $s =shift; | |||
| 1193 | 0 | 0 | 0 | if ($s->{-cache}->{-userauth}) { | |||
| 0 | 0 | ||||||
| 0 | 0 | ||||||
| 0 | |||||||
| 1194 | } | ||||||
| 1195 | elsif ($s->uguest() | ||||||
| 1196 | &&(defined($s->{-cgi}->param('_auth')) | ||||||
| 1197 | || defined($s->{-cgi}->param('_login')))) { | ||||||
| 1198 | 0 | $s->userauth(@_) | |||||
| 1199 | } | ||||||
| 1200 | elsif ((($ENV{SERVER_SOFTWARE}||'') =~/IIS/) | ||||||
| 1201 | &&($s->url() =~/\/_*(login|auth|a|ntlm|search|guest)\//i)) { # !!! IIS impersonation avoid | ||||||
| 1202 | 0 | my $url =$s->url(); | |||||
| 1203 | 0 | 0 | 0 | $s->userauth(@_) if $url !~/\/_*(search|guest)\//i | |||
| 0 | 0 | ||||||
| 0 | |||||||
| 0 | |||||||
| 1204 | ## && !$s->{-cache}->{-RevertToSelf} # -w32IISdpsn | ||||||
| 1205 | && (!$s->{-cache}->{-RevertToSelf} && (!defined($s->{-w32IISdpsn}) ? ($s->{-login}||'') =~/\/$/i : $s->{-w32IISdpsn} >1)) | ||||||
| 1206 | && !$s->uauth()->signget(); # $s->uguest | ||||||
| 1207 | 0 | 0 | 0 | if ((($s->qparam('_run')||'') ne 'SEARCH') | |||
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 1208 | && !$s->{-cache}->{-RevertToSelf} | ||||||
| 1209 | && (!defined($s->{-w32IISdpsn}) || ($s->{-w32IISdpsn} >1)) | ||||||
| 1210 | ) { # see 'search' in 'upws' | ||||||
| 1211 | 0 | $url =~s/\/_*(login|auth|a|ntlm|search|guest)\//\//i; | |||||
| 1212 | 0 | 0 | $url .=($ENV{QUERY_STRING} ? ('?' .$ENV{QUERY_STRING}) :''); | ||||
| 1213 | 0 | $s->print()->redirect(-uri=>$url, -nph=>1); | |||||
| 1214 | 0 | eval{$s->reset()}; | |||||
| 0 | |||||||
| 1215 | 0 | exit; | |||||
| 1216 | } | ||||||
| 1217 | } | ||||||
| 1218 | $s->user | ||||||
| 1219 | 0 | } | |||||
| 1220 | |||||||
| 1221 | |||||||
| 1222 | |||||||
| 1223 | sub w32IISdpsn {# deimpersonate Microsoft IIS impersonated process | ||||||
| 1224 | # 'Win32::API' used. | ||||||
| 1225 | # Set 'IIS / Home Directory / Application Protection' = 'Low (IIS Process)' | ||||||
| 1226 | # or see 'Administrative Tools / Component Services'. | ||||||
| 1227 | # Do not use quering to 'Index Server'. | ||||||
| 1228 | 0 | 0 | 0 | 0 | 0 | return(undef) if (defined($_[0]->{-w32IISdpsn}) && !$_[0]->{-w32IISdpsn}) | |
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 1229 | || $_[0]->{-cache}->{-RevertToSelf} | ||||||
| 1230 | || ($^O ne 'MSWin32') | ||||||
| 1231 | || !(($ENV{SERVER_SOFTWARE}||'') =~/IIS/) | ||||||
| 1232 | || $ENV{'FCGI_SERVER_VERSION'}; | ||||||
| 1233 | 0 | $_[0]->user(); | |||||
| 1234 | 0 | my $o =eval('use Win32::API; new Win32::API("advapi32.dll","RevertToSelf",[],"N")'); | |||||
| 1235 | 0 | 0 | my $l =eval{Win32::LoginName()}||''; | ||||
| 1236 | 0 | 0 | 0 | if ($o && $o->Call() && ($l ne (eval{Win32::LoginName()} ||''))) { | |||
| 0 | |||||||
| 0 | |||||||
| 1237 | 0 | 0 | $_[0]->{-cache}->{-RevertToSelf} =(Win32::LoginName()||'?'); | ||||
| 1238 | 0 | 0 | 0 | $_[1] && $_[0]->{-debug} | |||
| 0 | |||||||
| 0 | |||||||
| 1239 | && $_[0]->pushmsg('w32IISdpsn(' .(defined($_[0]->{-w32IISdpsn}) ? $_[0]->{-w32IISdpsn} : 'undef') .')' .($_[0]->{-debug} >2 ? ' '. $_[0]->{-cache}->{-RevertToSelf} : '')) | ||||||
| 1240 | } | ||||||
| 1241 | else { | ||||||
| 1242 | 0 | 0 | return $_[0]->die($_[0]->lng(0, 'w32IISdpsn') .": Win32::API('RevertToSelf') -> " .join('; ', map {$_ ? $_ : ()} $@,$!,$^E)) | ||||
| 0 | |||||||
| 1243 | } | ||||||
| 1244 | 0 | 1 | |||||
| 1245 | } | ||||||
| 1246 | |||||||
| 1247 | |||||||
| 1248 | ####################### | ||||||
| 1249 | |||||||
| 1250 | |||||||
| 1251 | sub oscmd { # OS Command with logging | ||||||
| 1252 | 0 | 0 | 1 | my $s =shift; | |||
| 1253 | 0 | 0 | my $opt = substr($_[0],0,1) eq '-' ? shift : ''; # 'h'ide, 'i'gnore | ||||
| 1254 | 0 | 0 | my $sub =ref($_[$#_]) eq 'CODE' ? pop : undef; | ||||
| 1255 | 0 | my $r; | |||||
| 1256 | my $o; | ||||||
| 1257 | 0 | 0 | $s->pushmsg(join(' ',@_)) if $opt !~/h/; | ||||
| 1258 | 0 | local(*RDRFH, *WTRFH); | |||||
| 1259 | 0 | 0 | if ($^X =~/(?:perlis|perlex)\d*\.dll$/i) { # !!! ISAPI IIS problem | ||||
| 1260 | 0 | 0 | if ($sub) { | ||||
| 1261 | 0 | 0 | 0 | open(WTRFH, '|' .join(' ',@_)) && defined(*WTRFH) || $s->die(join(' ',@_) .' -> ' .$!); | |||
| 1262 | # open(WTRFH, '|' ,@_) && defined(*WTRFH) || $s->die(join(' ',@_) .' -> ' .$!); | ||||||
| 1263 | 0 | my $ls =select(); select(WTRFH); $| =1; | |||||
| 0 | |||||||
| 0 | |||||||
| 1264 | 0 | &$sub($s); | |||||
| 1265 | 0 | select($ls); | |||||
| 1266 | 0 | eval{close(WTRFH)}; | |||||
| 0 | |||||||
| 1267 | } | ||||||
| 1268 | else { | ||||||
| 1269 | 0 | 0 | 0 | if ($opt !~/h/ && $_[0] =~/cacls/) { # !!! IIS/cacls behaviour debug | |||
| 1270 | 0 | $r =join(' ',@_,'2>&1'); | |||||
| 1271 | 0 | @$o =`$r`; | |||||
| 1272 | # push @$o, Win32::LoginName, `logname`; # 'SYSTEM'/'IUSR_' || 'IUSR_'/'IWAM' | ||||||
| 1273 | } | ||||||
| 1274 | else { | ||||||
| 1275 | 0 | system(@_) | |||||
| 1276 | } | ||||||
| 1277 | } | ||||||
| 1278 | } | ||||||
| 1279 | else { | ||||||
| 1280 | 0 | eval('use IPC::Open2'); | |||||
| 1281 | 0 | my $pid = IPC::Open2::open2(\*RDRFH, \*WTRFH, @_); | |||||
| 1282 | 0 | 0 | if ($pid) { | ||||
| 1283 | 0 | 0 | if ($sub) { | ||||
| 1284 | 0 | my $select =select(); | |||||
| 1285 | 0 | select(WTRFH); | |||||
| 1286 | 0 | $| =1; | |||||
| 1287 | 0 | &$sub($s); | |||||
| 1288 | 0 | select($select); | |||||
| 1289 | } | ||||||
| 1290 | 0 | @$o = |
|||||
| 1291 | 0 | waitpid($pid,0); | |||||
| 1292 | } | ||||||
| 1293 | } | ||||||
| 1294 | 0 | $r =$?>>8; | |||||
| 1295 | 0 | 0 | 0 | $s->pushmsg(@$o) if $o && $opt !~/h/; | |||
| 1296 | 0 | 0 | 0 | $s->die(join(' ',@_) .($opt !~/h/ ? '' : ' -> ' .join('',@{$o||[]})) ." -> $r\n") if $r && $opt !~/i/; | |||
| 0 | 0 | ||||||
| 0 | |||||||
| 1297 | 0 | !$r | |||||
| 1298 | } | ||||||
| 1299 | |||||||
| 1300 | |||||||
| 1301 | |||||||
| 1302 | ####################### | ||||||
| 1303 | |||||||
| 1304 | |||||||
| 1305 | sub httpheader { | ||||||
| 1306 | 0 | 0 | 1 | my $s =shift; | |||
| 1307 | 0 | 0 | 0 | my %p =!defined($_[0]) ? () : @_==1 && ref($_[0]) ? %{$_[0]} : @_; | |||
| 0 | 0 | ||||||
| 1308 | 0 | 0 | if (ref($s->{-httpheader})) { | ||||
| 1309 | 0 | foreach my $k (keys(%{$s->{-httpheader}})) { | |||||
| 0 | |||||||
| 1310 | 0 | 0 | if (!exists($p{$k})) {$p{$k} =$s->{-httpheader}->{$k}} | ||||
| 0 | |||||||
| 1311 | } | ||||||
| 1312 | } | ||||||
| 1313 | 0 | $s->{-cgi}->header(%p) | |||||
| 1314 | } | ||||||
| 1315 | |||||||
| 1316 | |||||||
| 1317 | sub htmlstart { | ||||||
| 1318 | 0 | 0 | 1 | my $s =shift; | |||
| 1319 | 0 | 0 | 0 | my %p =!defined($_[0]) ? () : @_==1 && ref($_[0]) ? %{$_[0]} : @_; | |||
| 0 | 0 | ||||||
| 1320 | 0 | 0 | if (ref($s->{-htmlstart})) { | ||||
| 1321 | 0 | foreach my $k (keys(%{$s->{-htmlstart}})) { | |||||
| 0 | |||||||
| 1322 | 0 | 0 | if (!exists($p{$k})) {$p{$k} =$s->{-htmlstart}->{$k}} | ||||
| 0 | |||||||
| 1323 | } | ||||||
| 1324 | } | ||||||
| 1325 | 0 | 0 | $p{-style} ={code=> | ||||
| 1326 | ".Form, .List, .Help, .MenuArea, .FooterArea {margin-top:0px; font-size: 8pt; font-family: Verdana, Helvetica, Arial, sans-serif; }\n" | ||||||
| 1327 | #."a:link.ListTable {font-weight: bold}\n" | ||||||
| 1328 | .".MenuButton {background-color: buttonface; color: black; text-decoration: none; font-size: 7pt;}\n" | ||||||
| 1329 | #."td.MenuButton {background-color: activeborder;}\n" | ||||||
| 1330 | #.".MenuArea {background-color: blue; color: white;}" | ||||||
| 1331 | #.".MenuButton {background-color: blue; color: white; text-decoration: none; font-size: 7pt;}\n" | ||||||
| 1332 | .".PaneLeft, .PaneForm, .PaneList {margin-top:0px; font-size: 8pt; font-family: Verdana, Helvetica, Arial, sans-serif; }\n" | ||||||
| 1333 | ."td.ListTable {border-style: inset; border-bottom-width: 1px; border-top-width: 0px; border-left-width: 0px; border-right-width: 0px; padding-top: 0;}\n" | ||||||
| 1334 | ."th.ListTable {border-style: inset; border-bottom-width: 1px; border-top-width: 0px; border-left-width: 0px; border-right-width: 0px;}\n" | ||||||
| 1335 | } if !exists($p{-style}); | ||||||
| 1336 | 0 | 0 | 0 | $s->{-debug} && $s->{-debug} >2 | |||
| 1337 | ? $s->{-cgi}->start_html(%p) | ||||||
| 1338 | .("\n\n") | ||||||
| 1339 | : $s->{-cgi}->start_html(%p) | ||||||
| 1340 | } | ||||||
| 1341 | |||||||
| 1342 | |||||||
| 1343 | sub htmlend { | ||||||
| 1344 | 0 | 0 | 0 | 0 | 0 | $_[0]->microtest if $_[0]->{-debug} && $_[0]->{-debug} >3; | |
| 1345 | 0 | $_[0]->{-cgi}->end_html | |||||
| 1346 | } | ||||||
| 1347 | |||||||
| 1348 | |||||||
| 1349 | sub htpgstart { | ||||||
| 1350 | 0 | 0 | 0 | 1 | $_[0]->httpheader($_[1]) | ||
| 1351 | .$_[0]->htmlstart($_[2]) | ||||||
| 1352 | .($_[0]->{-htpgtop}||'') | ||||||
| 1353 | } | ||||||
| 1354 | |||||||
| 1355 | |||||||
| 1356 | sub htpgend { | ||||||
| 1357 | 0 | 0 | 0 | 1 | ($_[0]->{-htpgbot}||'') | ||
| 1358 | .$_[0]->htmlend | ||||||
| 1359 | } | ||||||
| 1360 | |||||||
| 1361 | |||||||
| 1362 | sub htpfstart { | ||||||
| 1363 | 0 | 0 | 1 | my $s =shift; | |||
| 1364 | 0 | $s->htpgstart($_[0],$_[1]) ."\n" | |||||
| 1365 | .((($ENV{HTTP_USER_AGENT} ||'') =~m{^[^/]+/(\d)} ? $1 >=3 : 0) | ||||||
| 1366 | ? $s->{-cgi}->start_multipart_form({-action=>$s->url_form() | ||||||
| 1367 | , -acceptcharset=>$s->{-httpheader} ?$s->{-httpheader}->{-charset} :undef | ||||||
| 1368 | 0 | , $_[2] ? %{$_[2]} : () | |||||
| 1369 | }) | ||||||
| 1370 | : $s->{-cgi}->start_form({-action=>$s->url_form() | ||||||
| 1371 | , -acceptcharset=>$s->{-httpheader} ?$s->{-httpheader}->{-charset} :undef} | ||||||
| 1372 | 0 | 0 | 0 | , $_[2] ? %{$_[2]} : () | |||
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 1373 | ) | ||||||
| 1374 | ) ."\n" | ||||||
| 1375 | } | ||||||
| 1376 | |||||||
| 1377 | |||||||
| 1378 | sub htpfend { | ||||||
| 1379 | 0 | 0 | 1 | "\n\n" .$_[0]->htpgend(@_) | |||
| 1380 | } | ||||||
| 1381 | |||||||
| 1382 | |||||||
| 1383 | sub htmlescape { | ||||||
| 1384 | 0 | 0 | 0 | 1 | !defined($_[1]) ? '' : shift->{-cgi}->escapeHTML(@_) | ||
| 1385 | } | ||||||
| 1386 | |||||||
| 1387 | |||||||
| 1388 | sub htmlescapetext { | ||||||
| 1389 | 0 | 0 | 1 | my $s =shift; | |||
| 1390 | 0 | my $r =join("\n",@_); | |||||
| 1391 | 0 | my $g =$s->cgi; | |||||
| 1392 | 0 | my ($e, $m, $l) =(''); | |||||
| 1393 | 0 | while ($r =~/\b(\w{3,5}:\/\/[^\s\t,()<>\[\]"']+[^\s\t.,;()<>\[\]"'])/) { | |||||
| 1394 | 0 | $m =$1; $r =$'; | |||||
| 0 | |||||||
| 1395 | 0 | $l =$g->escapeHTML($`); $l =~s/( {2,})/' ' x length($1)/ge; $l =~s/\n/ \n/g; $l =~s/\r//g; |
|||||
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 1396 | 0 | $e .=$l; | |||||
| 1397 | 0 | $m =~s/^(host|urlh):\/\//\//; | |||||
| 1398 | 0 | $m =~s/^(url|urlr):\/\//$s->url(-relative=>1)/e; | |||||
| 0 | |||||||
| 1399 | 0 | $e .=$g->a({-href=>$m, -target=>'_blank'}, $g->escapeHTML($m)); | |||||
| 1400 | } | ||||||
| 1401 | 0 | $r =$g->escapeHTML($r); $r =~s/( {2,})/' ' x length($1)/ge; $r =~s/\n/ \n/g; $r =~s/\r//g; |
|||||
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 1402 | 0 | $e .=$r; | |||||
| 1403 | 0 | 0 | $e ="$e" if $e =~/ /;
|
||||
| 1404 | 0 | $e | |||||
| 1405 | } | ||||||
| 1406 | |||||||
| 1407 | |||||||
| 1408 | sub urlescape { | ||||||
| 1409 | 0 | 0 | 0 | 1 | !defined($_[1]) ? '' : shift->{-cgi}->escape(@_) | ||
| 1410 | } | ||||||
| 1411 | |||||||
| 1412 | |||||||
| 1413 | sub htmlurl { # Create URL from call string and parameters | ||||||
| 1414 | 0 | 0 | 0 | 0 | return($_[0]->url .($ENV{QUERY_STRING} ? '?' .$ENV{QUERY_STRING} : '')) if scalar(@_) <2; | ||
| 0 | |||||||
| 1415 | 0 | my $rsp = $_[1]; # do not escape at all?!!! | |||||
| 1416 | 0 | 0 | $rsp ='' if !defined($rsp); | ||||
| 1417 | 0 | 0 | 0 | chop $rsp if $rsp ne '' && substr($rsp, length($rsp) -1, 0) eq '/'; | |||
| 1418 | 0 | $rsp =~s/([^a-zA-Z0-9_\.\-\/\?\=\&;:%])/uc sprintf("%%%02x",ord($1))/eg; # see cgi->escape | |||||
| 0 | |||||||
| 1419 | 0 | 0 | $rsp .=($rsp =~/\?/ ? '&' : '?'); | ||||
| 1420 | 0 | for (my $i =2; $i <$#_; $i +=2) { # see cgi->escape | |||||
| 1421 | 0 | my @a =($_[$i], $_[$i+1]); | |||||
| 1422 | 0 | 0 | map {!defined($_) ? ($_ ='') | ||||
| 0 | |||||||
| 1423 | 0 | : ~s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg} @a; | |||||
| 1424 | 0 | $rsp .=$a[0] .'=' .$a[1] .'&'; | |||||
| 1425 | } | ||||||
| 1426 | 0 | chop($rsp); | |||||
| 1427 | 0 | $rsp; | |||||
| 1428 | } | ||||||
| 1429 | |||||||
| 1430 | |||||||
| 1431 | sub htmlddlb { # HTML Drop-Down List Box - Input helper | ||||||
| 1432 | 0 | 0 | 1 | shift->wg->ddlb(@_); | |||
| 1433 | } | ||||||
| 1434 | |||||||
| 1435 | sub htmltextfield { # HTML Text filed with autosizing | ||||||
| 1436 | 0 | 0 | 1 | shift->wg->textfield(@_); | |||
| 1437 | } | ||||||
| 1438 | |||||||
| 1439 | |||||||
| 1440 | sub htmltextarea { # HTML Text area with autorowing and hrefs | ||||||
| 1441 | 0 | 0 | 1 | shift->wg->textarea(@_); | |||
| 1442 | } | ||||||
| 1443 | |||||||
| 1444 | |||||||
| 1445 | sub htmlfsdir { # HTML Filesystem dir field | ||||||
| 1446 | 0 | 0 | 1 | shift->wg->fsdir(@_); | |||
| 1447 | } | ||||||
| 1448 | |||||||
| 1449 | |||||||
| 1450 | ####################### | ||||||
| 1451 | |||||||
| 1452 | |||||||
| 1453 | sub print { # print and CGI::BusCgiPrint object | ||||||
| 1454 | 0 | 0 | 1 | my $s =shift; | |||
| 1455 | #return(undef) if scalar(@_) && !CORE::print @_; | ||||||
| 1456 | 0 | CORE::print @_; | |||||
| 1457 | 0 | CGI::BusCgiPrint->new($s); | |||||
| 1458 | } | ||||||
| 1459 | |||||||
| 1460 | |||||||
| 1461 | sub text { # Retransalte text for print->text() | ||||||
| 1462 | 0 | 0 | 1 | shift; join('',@_) | |||
| 0 | |||||||
| 1463 | } | ||||||
| 1464 | |||||||
| 1465 | |||||||
| 1466 | |||||||
| 1467 | ####################### | ||||||
| 1468 | |||||||
| 1469 | # Autoload Launcher Object | ||||||
| 1470 | package CGI::BusLauncher; # Used with 'launch' | ||||||
| 1471 | 1 | 1 | 3208 | use vars qw($AUTOLOAD); | |||
| 1 | 2 | ||||||
| 1 | 183 | ||||||
| 1472 | 1; | ||||||
| 1473 | |||||||
| 1474 | sub new { | ||||||
| 1475 | 0 | 0 | my $c=shift; | ||||
| 1476 | 0 | my $s =[$_[0]]; | |||||
| 1477 | 0 | bless $s,$c; | |||||
| 1478 | } | ||||||
| 1479 | |||||||
| 1480 | sub DESTROY { | ||||||
| 1481 | 0 | 0 | eval {$_[0]->[0] =undef} | ||||
| 0 | |||||||
| 1482 | } | ||||||
| 1483 | |||||||
| 1484 | sub AUTOLOAD { | ||||||
| 1485 | 0 | 0 | shift->[0]->launch(substr($AUTOLOAD, rindex($AUTOLOAD, '::')+2), @_) | ||||
| 1486 | } | ||||||
| 1487 | |||||||
| 1488 | |||||||
| 1489 | |||||||
| 1490 | ####################### | ||||||
| 1491 | |||||||
| 1492 | # Autoload CGI method, print it result, return self | ||||||
| 1493 | package CGI::BusCgiPrint; # Used with 'print' | ||||||
| 1494 | 1 | 1 | 5 | use vars qw($AUTOLOAD); | |||
| 1 | 1 | ||||||
| 1 | 571 | ||||||
| 1495 | 1; | ||||||
| 1496 | |||||||
| 1497 | sub new { | ||||||
| 1498 | 0 | 0 | my $c=shift; | ||||
| 1499 | 0 | my $s =[$_[0]]; | |||||
| 1500 | 0 | bless $s,$c; | |||||
| 1501 | } | ||||||
| 1502 | |||||||
| 1503 | sub DESTROY { | ||||||
| 1504 | 0 | 0 | eval {$_[0]->[0] =undef} | ||||
| 0 | |||||||
| 1505 | } | ||||||
| 1506 | |||||||
| 1507 | |||||||
| 1508 | sub httpheader { | ||||||
| 1509 | 0 | 0 | my $s =shift; | ||||
| 1510 | 0 | 0 | $s->[0]->print($s->[0]->{-cache}->{-httpheader} ? '' | ||||
| 1511 | :($s->[0]->{-cache}->{-httpheader} =$s->[0]->httpheader(@_))); | ||||||
| 1512 | } | ||||||
| 1513 | |||||||
| 1514 | |||||||
| 1515 | sub htmlstart { | ||||||
| 1516 | 0 | 0 | my $s =shift; | ||||
| 1517 | 0 | 0 | $s->[0]->print($s->[0]->{-cache}->{-htmlstart} ? '' | ||||
| 1518 | :($s->[0]->{-cache}->{-htmlstart} =$s->[0]->htmlstart(@_))); | ||||||
| 1519 | } | ||||||
| 1520 | |||||||
| 1521 | |||||||
| 1522 | sub htpgstart { | ||||||
| 1523 | 0 | 0 | $_[0]->httpheader($_[1]); | ||||
| 1524 | 0 | $_[0]->htmlstart ($_[2]); | |||||
| 1525 | 0 | 0 | 0 | $_[0]->[0]->print($_[0]->[0]->{-cache}->{-htpgstart} ? '' | |||
| 1526 | :($_[0]->[0]->{-cache}->{-htpgstart} =$_[0]->[0]->{-htpgtop}||'')) | ||||||
| 1527 | } | ||||||
| 1528 | |||||||
| 1529 | |||||||
| 1530 | sub htpfstart { | ||||||
| 1531 | 0 | 0 | $_[0]->htpgstart($_[1],$_[2]); | ||||
| 1532 | 0 | $_[0]->[0]->print("\n" | |||||
| 1533 | .((($ENV{HTTP_USER_AGENT} ||'') =~m{^[^/]+/(\d)} ? $1 >=3 : 0) | ||||||
| 1534 | ? $_[0]->[0]->{-cgi}->start_multipart_form({-action=>$_[0]->[0]->url_form() | ||||||
| 1535 | , -acceptcharset=>$_[0]->[0]->{-httpheader} ?$_[0]->[0]->{-httpheader}->{-charset} :undef | ||||||
| 1536 | 0 | , $_[3] ? %{$_[3]} : ()}) | |||||
| 1537 | : $_[0]->[0]->{-cgi}->start_form({-action=>$_[0]->[0]->url_form() | ||||||
| 1538 | ,-acceptcharset=>$_[0]->[0]->{-httpheader} ?$_[0]->[0]->{-httpheader}->{-charset} :undef | ||||||
| 1539 | 0 | 0 | 0 | , $_[3] ? %{$_[3]} : ()}) | |||
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 0 | |||||||
| 1540 | ) ."\n") | ||||||
| 1541 | } | ||||||
| 1542 | |||||||
| 1543 | |||||||
| 1544 | sub br { | ||||||
| 1545 | 0 | 0 | $_[0]->[0]->print(' ') |
||||
| 1546 | } | ||||||
| 1547 | |||||||
| 1548 | |||||||
| 1549 | sub AUTOLOAD { | ||||||
| 1550 | 0 | 0 | my $s =shift; | ||||
| 1551 | 0 | my $m =substr($AUTOLOAD, rindex($AUTOLOAD, '::')+2); | |||||
| 1552 | 0 | $s->[0]->print($s->[0]->$m(@_)); | |||||
| 1553 | } | ||||||
| 1554 | |||||||
| 1555 |