revert to previous commit, tunnel work with end url /

This commit is contained in:
nawawi
2013-11-21 14:49:54 +08:00
parent ab9ce8c70d
commit 43bc397ffd
2 changed files with 1 additions and 101 deletions

View File

@@ -186,57 +186,9 @@ if ($header{'content-type'} =~ /text\/html/ && !$header{'x-no-links'}) {
#s/\.location\s*=\s*"$page([^']*)"/.location="$url\/$1"/gi;
#s/window.open\("$page([^"]*)"/window.open\("$url\/$1"/gi;
#s/name=return\s+value="$page([^"]*)"/name=return value="$url\/$1"/gi;
# fix href like <a href=aa.html>
if ( m/\<(a|link).*href=(?!#|javascript:|https:|http:|\/|'|").*[ >]/gi ) {
s/href=([^ "'>]*)/href=$linkurl$baseurl\/$1/gi;
}
# fix href like <a href="aa.html">
if ( m/\<(a|link).*href="(?!#|javascript:|https:|http:|\/).*"[ >]/gi ) {
s/href="([^"]*)"/href="$linkurl$baseurl\/$1"/gi;
}
# fix href like <a href='aa.html'>
if ( m/\<(a|link).*href='(?!#|javascript:|https:|http:|\/).*'[ >]/gi ) {
s/href='([^']*)'/href='$linkurl$baseurl\/$1'/gi;
}
# fix src like <img src=aa.html>
if ( m/\<(img|script).*src=(?!https:|http:|\/|'|").*[ >]/gi ) {
s/src=([^ "'>]*)/src=$linkurl$baseurl\/$1/gi;
}
# fix src like <img src="aa.html">
if ( m/\<(img|script).*src="(?!https:|http:|\/).*"[ >]/gi ) {
s/src="([^"]*)"/src="$linkurl$baseurl\/$1"/gi;
}
# fix href like <img src='aa.html'>
if ( m/\<(img|script).*src='(?!https:|http:|\/).*'[ >]/gi ) {
s/src='([^']*)'/src='$linkurl$baseurl\/$1'/gi;
}
print;
}
}
} elsif ($header{'content-type'} =~ /text\/css/) {
my $s;
my $pathinfo = $ENV{'PATH_INFO'};
while($_ = &read_http_connection($con)) {
if ( m/url\("(.*?)"\)/i ) {
$s = &resolv_path($pathinfo, $1);
s/url\("$1"\)/url\("$linkurl$s"\)/gi;
} elsif ( m/url\('(.*?)'\)/i ) {
$s = &resolv_path($pathinfo, $1);
s/url\('$1'\)/url\('$linkurl$s'\)/gi;
} elsif ( m/url\((.*?)\)/i ) {
$s = &resolv_path($pathinfo, $1);
s/url\($1\)/url\($linkurl$s\)/gi;
}
print;
}
}
else {
while($buf = &read_http_connection($con, 1024)) {
print $buf;

View File

@@ -5,57 +5,5 @@ BEGIN { push(@INC, ".."); };
use WebminCore;
&init_config();
sub get_path {
my ($file) = @_;
$file =~ s!/?[^/]*/*$!!;
return $file;
}
sub pop_path {
my ($dir, $stack) = @_;
return get_path($dir) if ( $stack eq 0 );
$ret = $dir;
for($x=0; $x <= $stack; $x++) {
$ret = get_path($ret);
}
return $ret;
}
# $ENV{'PATH_INFO'}: /http:/rutweb.com/wp-content/themes/olympus/style.css
# content: url(css/bootstrap.css)
# path: css/bootstrap.css
# translate to: http://rutweb.com/wp-content/themes/olympus/css/bootstrap.css
# content: url(../css/bootstrap.css)
# path: ../css/bootstrap.css
# translate to: http://rutweb.com/wp-content/themes/css/bootstrap.css
# base on simplify_path
sub resolv_path {
my ($pathinfo, $path) = @_;
# fix schema
$pathinfo =~ s/^\///g;
$pathinfo =~ s/^(http:\/|https:\/)(?!\/.*)/$1\/$2/gi;
$path =~ s/^\/+//g;
$path =~ s/\/+$//g;
my @bits = split(/\/+/, $path);
my @fixedbits = ();
my $cnt = 0;
foreach my $b (@bits) {
if ($b eq ".") {
# do nothing
} elsif ($b eq "..") {
$cnt++;
pop(@fixedbits);
} else {
# Add dir to list
push(@fixedbits, $b);
}
}
$fpath = pop_path($pathinfo, $cnt);
return "$fpath/".join('/', @fixedbits);
}
1;