better handling of different options in 'base_url' ad 'base_cgi'

This commit is contained in:
Jordi Sanfeliu 2013-02-11 15:28:20 +01:00
parent 052e8f352e
commit 4088a61216
2 changed files with 18 additions and 10 deletions

View File

@ -70,6 +70,7 @@ sub handle_request {
my $port = $main::config{httpd_builtin}->{port};
my $mimetype;
my $target;
my $target_cgi;
my @data;
return if fork(); # parent returns
@ -85,21 +86,24 @@ sub handle_request {
$target =~ s/\/$//;
last unless $cur ne length $target;
}
$target = "/$target";
$target = $target_cgi = "/$target";
$target =~ s/^$base_url//; # removes the 'base_url' part
$target =~ s/^$base_cgi//; # removes the 'base_cgi' part
$target =~ s/^\///; # removes leading slash
$target = "index.html" unless $target;
$target_cgi =~ s/^$base_cgi//; # removes the 'base_cgi' part
if(!$target || $target eq $base_url) {
$target = "index.html" unless $target;
}
($mimetype) = ($target =~ m/.*\.(html|cgi|png)$/);
if($target eq "monitorix.cgi") {
$target =~ s/^\///; # removes leading slash
$target_cgi =~ s/^\///; # removes leading slash
if($target_cgi eq "monitorix.cgi") {
# chdir("cgi");
chdir("/home/jordi/github/Monitorix/"); # XXX
open(EXEC, "./$target |");
open(EXEC, "./$target_cgi |");
@data = <EXEC>;
close(EXEC);
} else {
} elsif($target) {
if(open(IN, $target)) {
@data = <IN>;
close(IN);

View File

@ -163,6 +163,10 @@ sub create_index {
my $title_back_color;
my $title_fore_color;
# force to only one trailing slash
(my $base_url = $config{base_url}) =~ s/\/*$/\//;
(my $base_cgi = $config{base_cgi}) =~ s/\/*$/\//;
if($theme eq "black") {
$bgcolor = $config{$theme}->{main_bg};
$table_back_color = $config{$theme}->{graph_bg};
@ -185,7 +189,7 @@ sub create_index {
<html>
<head>
<title>$config{title}</title>
<link rel="shortcut icon" href="$config{base_url}/$config{favicon}">
<link rel="shortcut icon" href="$base_url$config{favicon}">
</head>
<body bgcolor="$bgcolor" text="#888888" vlink="#888888" link="#888888">
<center>
@ -195,7 +199,7 @@ sub create_index {
<table>
<tr>
<td>
<a href="http://www.monitorix.org/"><img src="$config{base_url}/$config{logo_top}" border="0"></a>
<a href="http://www.monitorix.org/"><img src="$base_url$config{logo_top}" border="0"></a>
</td>
</tr>
<tr>
@ -205,7 +209,7 @@ sub create_index {
</tr>
</table>
<p>
<form action="$config{base_cgi}/monitorix.cgi" method="get">
<form action="${base_cgi}monitorix.cgi" method="get">
<table cellspacing="5" cellpadding="0" bgcolor="$table_back_color" border="1">
<tr>
<td bgcolor="$title_back_color">