From db600751bddfe0be1cd5f4a31c7ad61dc44767a3 Mon Sep 17 00:00:00 2001 From: nawawi Date: Sat, 23 Nov 2013 03:03:53 +0800 Subject: [PATCH] Fix if url was set --- tunnel/index.cgi | 1 + tunnel/link.cgi | 3 ++- tunnel/login.cgi | 1 + tunnel/seturl.cgi | 18 +----------------- tunnel/tunnel-lib.pl | 19 +++++++++++++++++++ 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/tunnel/index.cgi b/tunnel/index.cgi index 2bac1a67c..02d1329e4 100755 --- a/tunnel/index.cgi +++ b/tunnel/index.cgi @@ -3,6 +3,7 @@ require './tunnel-lib.pl'; if ($config{'url'}) { + $config{'url'} = &fix_end_url($config{'url'}) || &error($text{'seturl_eurl'}); &redirect("link.cgi/$config{'url'}"); } else { diff --git a/tunnel/link.cgi b/tunnel/link.cgi index 42cb7912a..1f202b004 100755 --- a/tunnel/link.cgi +++ b/tunnel/link.cgi @@ -25,6 +25,7 @@ $url = $gconfig{'webprefix'}."/$module_name/link.cgi/$openurl"; $| = 1; $meth = $ENV{'REQUEST_METHOD'}; if ($config{'url'}) { + $config{'url'} = &fix_end_url($config{'url'}) || &error($text{'seturl_eurl'}); $openurl =~ /^\Q$config{'url'}\E/ || &error(&text('link_ebadurl', $openurl)); } @@ -190,7 +191,7 @@ if ($header{'content-type'} =~ /text\/html/ && !$header{'x-no-links'}) { } } else { - while($buf = &read_http_connection($con, 1024)) { + while($buf = &read_http_connection($con,1024)) { print $buf; } } diff --git a/tunnel/login.cgi b/tunnel/login.cgi index a3170fe47..d90377d8e 100755 --- a/tunnel/login.cgi +++ b/tunnel/login.cgi @@ -11,5 +11,6 @@ if (uc($ENV{'HTTPS'}) eq 'ON') { print "; secure"; } print "\n"; +$in{'url'} = &fix_end_url($in{'url'}) || &error($text{'seturl_eurl'}); &redirect("link.cgi/$in{'url'}"); diff --git a/tunnel/seturl.cgi b/tunnel/seturl.cgi index 386bec638..b1906a57d 100755 --- a/tunnel/seturl.cgi +++ b/tunnel/seturl.cgi @@ -5,23 +5,7 @@ require './tunnel-lib.pl'; &ReadParse(); &error_setup($text{'seturl_err'}); -if ( $in{'url'} =~ m/^(http|https):\/\/(\S+)$/ ) { - $schema = $1."://"; - $host = $2; - $url = $2; - - # check: http://aa.com - # check: http://aa.com/bb.html - # check: http://aa.com/bb/cc.html - $url =~ s/\/?[^\/]*\/*$//; - - # empty? append / at the end - if ( $url eq '' ) { - $in{'url'} = "$schema$host/"; - } -} else { - &error($text{'seturl_eurl'}); -} +$in{'url'} = &fix_end_url($in{'url'}) || &error($text{'seturl_eurl'}); #$in{'url'} =~ /^(http|https):\/\/(\S+)$/ || &error($text{'seturl_eurl'}); &redirect("link.cgi/$in{'url'}"); diff --git a/tunnel/tunnel-lib.pl b/tunnel/tunnel-lib.pl index 6bc2b31a2..30cf8c1d1 100755 --- a/tunnel/tunnel-lib.pl +++ b/tunnel/tunnel-lib.pl @@ -5,5 +5,24 @@ BEGIN { push(@INC, ".."); }; use WebminCore; &init_config(); +sub fix_end_url { + my($url) = @_; + if ( $url =~ m/^(http|https):\/\/(\S+)$/ ) { + $schema = $1."://"; + $host = $2; + + # check: http://aa.com + # check: http://aa.com/bb.html + # check: http://aa.com/bb/cc.html + $host_test = $2; + $host_test =~ s/\/?[^\/]*\/*$//; + if ( $host_test eq '' ) { + $url = "$schema$host/"; + } + return $url; + } + return 0; +} + 1;