diff --git a/tunnel/link.cgi b/tunnel/link.cgi index 6e89467f2..42cb7912a 100755 --- a/tunnel/link.cgi +++ b/tunnel/link.cgi @@ -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 - if ( m/\<(a|link).*href=(?!#|javascript:|https:|http:|\/|'|").*[ >]/gi ) { - s/href=([^ "'>]*)/href=$linkurl$baseurl\/$1/gi; - } - - # fix href like - if ( m/\<(a|link).*href="(?!#|javascript:|https:|http:|\/).*"[ >]/gi ) { - s/href="([^"]*)"/href="$linkurl$baseurl\/$1"/gi; - } - - # fix href like - if ( m/\<(a|link).*href='(?!#|javascript:|https:|http:|\/).*'[ >]/gi ) { - s/href='([^']*)'/href='$linkurl$baseurl\/$1'/gi; - } - - # fix src like - if ( m/\<(img|script).*src=(?!https:|http:|\/|'|").*[ >]/gi ) { - s/src=([^ "'>]*)/src=$linkurl$baseurl\/$1/gi; - } - - # fix src like - if ( m/\<(img|script).*src="(?!https:|http:|\/).*"[ >]/gi ) { - s/src="([^"]*)"/src="$linkurl$baseurl\/$1"/gi; - } - - # fix href like - 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; diff --git a/tunnel/tunnel-lib.pl b/tunnel/tunnel-lib.pl index f56e71b33..6bc2b31a2 100755 --- a/tunnel/tunnel-lib.pl +++ b/tunnel/tunnel-lib.pl @@ -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;