Fix if url was set

This commit is contained in:
nawawi
2013-11-23 03:03:53 +08:00
parent 2a675929e8
commit db600751bd
5 changed files with 24 additions and 18 deletions

View File

@@ -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 {

View File

@@ -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;
}
}

View File

@@ -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'}");

View File

@@ -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'}");

View File

@@ -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;