| 1 | package GetWeb::File; | ||
| 2 | |||
| 3 | use URI::URL::file; | ||
| 4 | use MailBot::Config; | ||
| 5 | |||
| 6 | @ISA = qw( URI::URL::file ); | ||
| 7 | use strict; | ||
| 8 | |||
| 9 | sub newlocal { | ||
| 10 | my($class, $path) = @_; | ||
| 11 | |||
| 12 | # untaint path | ||
| 13 | |||
| 14 | # jf fix canonical url mismatch | ||
| 15 | |||
| 16 | ($path =~ /\.\./) | ||
| 17 | and die "cannot go below public dir"; | ||
| 18 | $path = "./".$path unless | ||
| 19 | $path =~ /^\.\//; | ||
| 20 | |||
| 21 | $path =~ m!^([_a-zA-Z0-9/.?%+-]+)$! or die "unsafe filename: $path\n"; | ||
| 22 | $path = $1; | ||
| 23 | |||
| 24 | # Carp::Croak("Only implemented for Unix file systems") | ||
| 25 | # unless $ostype eq "unix"; | ||
| 26 | # XXX: Should implement the same thing for other systems | ||
| 27 | |||
| 28 | my $url = new URI::URL "file:"; | ||
| 29 | $url->path($path); | ||
| 30 | $url; | ||
| 31 | } | ||
| 32 | |||
| 33 | sub local_path | ||
| 34 | { | ||
| 35 | my $path = URI::URL::file::local_path(@_); | ||
| 36 | |||
| 37 | # require Cwd; | ||
| 38 | # my $cwd = Cwd::fastcwd(); | ||
| 39 | my $config = MailBot::Config::current; | ||
| 40 | my $cwd = $config -> getPubDir(); | ||
| 41 | # die "cwd is $cwd"; | ||
| 42 | $cwd =~ s:/?$:/:; # force trailing slash on dir | ||
| 43 | $path = (defined $path) ? $cwd . $path : $cwd; | ||
| 44 | $path; | ||
| 45 | } |