Skip to content

Commit

Permalink
Item12180: PATH{URL} checkers
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@16182 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
TimotheLitt authored and TimotheLitt committed Dec 10, 2012
1 parent 172cbe6 commit 71ec9b6
Show file tree
Hide file tree
Showing 14 changed files with 442 additions and 103 deletions.
21 changes: 15 additions & 6 deletions core/lib/Foswiki.spec
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@
# be browseable from the web. If you expose any other directories (such as
# lib or templates) you are opening up routes for possible hacking attempts.</p>

# **URL M**
# **URL CHECK="parts:scheme,authority,path \
# partsreq:scheme,authority \
# schemes:http,https \
# authtype:host" \
# M**
# This is the root of all Foswiki URLs e.g. http://myhost.com:123.
# $Foswiki::cfg{DefaultUrlHost} = 'http://your.domain.com';

Expand All @@ -56,7 +60,7 @@
# to return the <code>DefaultUrlHost</code>.</p>
$Foswiki::cfg{ForceDefaultUrlHost} = $FALSE;

# **URLPATH M**
# **URLPATH CHECK="expand" M**
# This is the 'cgi-bin' part of URLs used to access the Foswiki bin
# directory e.g. <code>/foswiki/bin</code><br />
# Do <b>not</b> include a trailing /.
Expand All @@ -66,7 +70,7 @@ $Foswiki::cfg{ForceDefaultUrlHost} = $FALSE;
# be manually added to <code>lib/LocalSite.cfg</code>
# $Foswiki::cfg{ScriptUrlPath} = '/foswiki/bin';

# **URLPATH M**
# **URLPATH CHECK='expand' M**
# This is the complete path used to access the Foswiki view script including any suffix. Do not include a trailing /.
# (This is an exception override, so the ScriptSuffix is not automatically added.)
# e.g. <code>/foswiki/bin/view.pl</code><br /> Note: The default is acceptable except when shorter URLs are used.
Expand All @@ -87,7 +91,7 @@ $Foswiki::cfg{ScriptUrlPaths}{view} =
# directory.
# $Foswiki::cfg{ScriptDir} = '/home/httpd/foswiki/bin';

# **URLPATH M**
# **URLPATH CHECK='expand' M**
# Attachments URL path e.g. /foswiki/pub
# <p /><b>Security Note:</b> files in this directory are *not*
# protected by Foswiki access controls. If you require access controls, you
Expand Down Expand Up @@ -906,7 +910,12 @@ $Foswiki::cfg{AccessibleENV} =
#---++ Proxies
# Some environments require outbound HTTP traffic to go through a proxy
# server. (e.g. http://proxy.your.company).
# **STRING 30**
# **URL CHECK='parts:scheme,authority,path,user,pass \
# partsreq:scheme,authority \
# schemes:http,https \
# authtype:hostip \
# nullok' \
# 30**
# Hostname or address of the proxy server.
# <b>CAUTION</b> This setting can be overridden by a PROXYHOST setting
# in SitePreferences. Make sure you delete the setting from there if
Expand Down Expand Up @@ -2133,7 +2142,7 @@ $Foswiki::cfg{Plugins}{WebSearchPath} = '$Foswiki::cfg{SystemWebName},TWiki';
# Note: if your Repository uses ApacheAuth, embed the username and password into the listurl as <code>?username=x;password=y</code>
# <p />
# For example,<code>
# twiki.org=(http://twiki.org/cgi-bin/view/Plugins/,http://twiki.org/p/pub/Plugins/); foswiki.org=(http://foswiki.org/Extensions/,http://foswiki.org/pub/Extensions/);</code><p />
# twiki.org=(http://twiki.org/cgi-bin/viewlugins/,http://twiki.org/p/pub/Plugins/); foswiki.org=(http://foswiki.org/Extensions/,http://foswiki.org/pub/Extensions/);</code><p />
# For Extensions with the same name in more than one repository, the <strong>last</strong> matching repository in the list will be chosen, so Foswiki.org should always be last in the list for maximum compatibility.
$Foswiki::cfg{ExtensionsRepositories} =
'Foswiki.org=(http://foswiki.org/Extensions/,http://foswiki.org/pub/Extensions/)';
Expand Down
5 changes: 4 additions & 1 deletion core/lib/Foswiki/Configure/Checker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,17 @@ HERE
---++ ObjectMethod getCfg($name) -> $expanded_val
Get the value of the named configuration var. The name is in the form
getCfg("{Validation}{ExpireKeyOnUse}")
getCfg("{Validation}{ExpireKeyOnUse}"), and defaults to the current
item.
Any embedded references to other Foswiki::cfg vars will be expanded.
=cut

sub getCfg {
my ( $this, $name ) = @_;
$name ||= $this->{item}->getKeys();

my $item = '$Foswiki::cfg' . $name;
Foswiki::Configure::Load::expandValue($item);
return $item;
Expand Down
17 changes: 11 additions & 6 deletions core/lib/Foswiki/Configure/Checkers/DefaultUrlHost.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ package Foswiki::Configure::Checkers::DefaultUrlHost;
use strict;
use warnings;

use Foswiki::Configure::Checker ();
our @ISA = ('Foswiki::Configure::Checker');
require Foswiki::Configure::Checkers::URL;
our @ISA = ('Foswiki::Configure::Checkers::URL');

sub check {
my ( $this, $keys ) = @_;
my $this = shift;
my ($valobj) = @_;

my $d = $this->getCfg('{DefaultUrlHost}');
my $mess = $this->showExpandedValue( $Foswiki::cfg{DefaultUrlHost} );
my $mess = '';

if ( $d && $d ne 'NOT SET' ) {
$mess = $this->SUPER::check(@_);

my $host = $ENV{HTTP_HOST};
if ( $host && $Foswiki::cfg{DefaultUrlHost} !~ /$host/i ) {
if ( $host && $Foswiki::cfg{DefaultUrlHost} !~ m,^https?://$host,i ) {
return $mess
. $this->WARN( 'Current setting does not match HTTP_HOST ',
$ENV{HTTP_HOST} );
Expand All @@ -24,7 +28,8 @@ sub check {
my $protocol = $Foswiki::query->url() || 'http://' . $ENV{HTTP_HOST};
$protocol =~ s(^(.*?://.*?)/.*$)($1);
$Foswiki::cfg{DefaultUrlHost} = $protocol;
return $mess . $this->guessed(0);
$this->{GuessedValue} = $protocol;
$mess = $this->SUPER::check(@_);
}
return $mess;
}
Expand Down
34 changes: 20 additions & 14 deletions core/lib/Foswiki/Configure/Checkers/PubUrlPath.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,36 @@ package Foswiki::Configure::Checkers::PubUrlPath;
use strict;
use warnings;

use Foswiki::Configure::Checker ();
our @ISA = ('Foswiki::Configure::Checker');
require Foswiki::Configure::Checkers::URLPATH;
our @ISA = ('Foswiki::Configure::Checkers::URLPATH');

use Foswiki::Configure qw/:cgi/;

sub check {
my $this = shift;

unless ( $Foswiki::cfg{PubUrlPath}
&& $Foswiki::cfg{PubUrlPath} ne 'NOT SET' )
{
my $guess = $Foswiki::cfg{ScriptUrlPath};
my $guess = $this->getItemCurrentValue('ScriptUrlPath');
$guess =~ s/\/[^\/]*?bin$/\/pub/;
$guess .= '/pub' unless ( $guess =~ m/pub$/ );
$Foswiki::cfg{PubUrlPath} = $guess;
return $this->guessed(0);
$this->{GuessedValue} = $guess;
$this->setItemValue($guess);
return $this->SUPER::check(@_);
}
my $d = $this->getCfg("{PubUrlPath}");
my $mess = $this->showExpandedValue( $Foswiki::cfg{WorkingDir} );

$mess .=
"<div class='configureSetting'>Test the correctness of this path with this link:"
. CGI::br()
. '<a rel="nofollow" target="_new" href="'
. $d
. '">My &quot;pub&quot; directory</a>';
my $d = $this->getCfg;
my $mess = $this->SUPER::check(@_);
my $t = "/System/ProjectLogos/foswiki-logo.png";

$mess .= $this->NOTE("Please wait while the path is tested")
. qq{<div class='configureSetting' onload='\$("[name=\\"\\{PubUrlPath\\}Error\\"]").hide();\$("[name=\\"\\{PubUrlPath\\}Ok\\"]").hide();'>
<img name="{PubUrlPath}TestImage" src="$d$t" testImg="$t" style="height:20px;"
onload='\$("[name=\\"\\{PubUrlPath\\}Error\\"]").hide();\$("[name=\\"\\{PubUrlPath\\}Ok\\"]").show();'
onerror='\$("[name=\\"\\{PubUrlPath\\}Ok\\"]").hide();\$("[name=\\"\\{PubUrlPath\\}Error\\"]").show();'>
<span name="{PubUrlPath}Ok">This setting is correct.</span>
<span name="{PubUrlPath}Error"><img src="${resourceURI}icon_error.png" style="margin-right:5px;">Path is not correct.</span></div>};

return $mess;
}

Expand Down
35 changes: 21 additions & 14 deletions core/lib/Foswiki/Configure/Checkers/ScriptUrlPath.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,50 @@ package Foswiki::Configure::Checkers::ScriptUrlPath;
use strict;
use warnings;

use Foswiki::Configure::Checker ();
our @ISA = ('Foswiki::Configure::Checker');
require Foswiki::Configure::Checkers::URLPATH;
our @ISA = ('Foswiki::Configure::Checkers::URLPATH');

sub check {
my $this = shift;

# Check Script URL Path against REQUEST_URI
my $val = $this->getCfg("{ScriptUrlPath}");
my $val = $this->getCfg;
my $report = '';
my $guess = $ENV{REQUEST_URI} || $ENV{SCRIPT_NAME} || '';

if ( defined $val and $val ne 'NOT SET' ) {
if ( $val and $val ne 'NOT SET' ) {
$report = $this->SUPER::check(@_);
$val = $this->getCfg;

if ( $guess =~ s'/+configure\b.*$'' ) {
if ( $guess !~ /^$val/ ) {
$report .= $this->WARN(
'I expected this to look like "' . $guess . '"' );
$report .=
$this->WARN( 'This item is expected this to look like "'
. $guess
. '"' );
}
}
else {
$report .= $this->WARN(<<HERE);
$report .= $this->WARN(<< "HERE");
This web server does not set REQUEST_URI or SCRIPT_NAME
so it isn't possible to fully check the correctness of this setting.
so it isn't possible to fully validate this setting.
HERE
}
if ( $val =~ m'/$' ) {
if ( $val =~ s'/+$'' ) {
$report .= $this->WARN(
'Don\'t put a / at the end of the path. It\'ll still work, but you will get double // in a few places.'
);
'A trailing / is not recommended and has been removed');
$this->setItemValue($val);
$this->{UpdatedValue} = $val;
}
$report .= $this->showExpandedValue( $Foswiki::cfg{ScriptUrlPath} );
}
else {
if ( $guess =~ s'/+configure\b.*$'' ) {
$report .= $this->guessed(0);
$this->{GuessedValue} = $guess;
$this->setItemValue($guess);
$report .= $this->SUPER::check(@_);
}
else {
$report .= $this->WARN(<<HERE);
$report .= $this->WARN(<< "HERE");
This web server does not set REQUEST_URI or SCRIPT_NAME
so it isn't possible to guess this setting.
HERE
Expand Down
41 changes: 0 additions & 41 deletions core/lib/Foswiki/Configure/Checkers/ScriptUrlPaths/view.pm

This file was deleted.

Loading

0 comments on commit 71ec9b6

Please sign in to comment.