Skip to content

Commit

Permalink
Item12381: Replace "Web Server Environment" tab
Browse files Browse the repository at this point in the history
The Foswiki 1.1.x  "Web Server Enviroment" tab was replaced with the
"Study Server" wizard, which has now been removed.

Implement a %SERVERINFORMATION% macro and
System.FoswikiServerInformation topic to provide similar functionality.

The detailed information is only made available to users with access to
the bin/configure tool.
  • Loading branch information
gac410 committed Jan 28, 2015
1 parent c2b8a7d commit 787fcbe
Show file tree
Hide file tree
Showing 4 changed files with 213 additions and 0 deletions.
21 changes: 21 additions & 0 deletions core/data/System/FoswikiServerInformation.txt
@@ -0,0 +1,21 @@
%META:TOPICINFO{author="ProjectContributor" date="1422413722" format="1.1" version="1"}%
%META:TOPICPARENT{name="InstallationGuide"}%

---+!! Foswiki Server Information

This topic lists the detailed server execution environment. As this is
sensitive information, it is only available to users with access to Configure.

---++ Foswiki information

| Foswiki Version | %WIKIVERSION% |
| Foswiki Release | %WIKIRELEASE% |
| Foswiki Plugin API | %PLUGINVERSION% |

See Also: PerlDependencyReport for details on the installed Perl CPAN modules and InstalledPlugins for diagnostics on the installed plugins.

---++ General execution environment
%SERVERINFORMATION{execution}%

---++ Environment variables
%SERVERINFORMATION{environment}%
1 change: 1 addition & 0 deletions core/lib/Foswiki.pm
Expand Up @@ -305,6 +305,7 @@ BEGIN {
Foswiki::Time::formatTime( time(), $_[1]->{_DEFAULT} || '',
'servertime' );
},
SERVERINFORMATION => undef,
SET => undef,
SHOWPREFERENCE => undef,
SPACEDTOPIC => undef,
Expand Down
3 changes: 3 additions & 0 deletions core/lib/Foswiki/Contrib/core/MANIFEST
Expand Up @@ -155,6 +155,7 @@ data/System/ReleaseNotes01x02.txt 0644
data/System/RenameWeb.txt 0644
data/System/SearchHelp.txt 0644
data/System/SearchPatternCookbook.txt 0644
data/System/FoswikiServerInformation 0644
data/System/ShortcutMacros.txt 0644
data/System/SiteChanges.txt 0644
data/System/SiteMap.txt 0644
Expand Down Expand Up @@ -284,6 +285,7 @@ data/System/VarSCRIPTURL.txt 0644
data/System/VarSCRIPTURLPATH.txt 0644
data/System/VarSEARCH.txt 0644
data/System/VarSERVERTIME.txt 0644
data/System/VarSERVERINFORMATION.txt 0644 Web server detailed execution environment
data/System/VarSESSIONID.txt 0644
data/System/VarSESSIONVAR.txt 0644
data/System/VarSESSIONVARIABLE.txt 0644
Expand Down Expand Up @@ -605,6 +607,7 @@ lib/Foswiki/Macros/RENDERZONE.pm 0444
lib/Foswiki/Macros/REVARG.pm 0444
lib/Foswiki/Macros/REVINFO.pm 0444
lib/Foswiki/Macros/REVTITLE.pm 0444
lib/Foswiki/Macros/SERVERINFORMATION.pm 0444
lib/Foswiki/Macros/SET.pm 0444
lib/Foswiki/Macros/SEARCH.pm 0444
lib/Foswiki/Macros/SHOWPREFERENCE.pm 0444
Expand Down
188 changes: 188 additions & 0 deletions core/lib/Foswiki/Macros/SERVERINFORMATION.pm
@@ -0,0 +1,188 @@
# See bottom of file for license and copyright information
package Foswiki;

# Detailed core and plugin dependency report - see
# System.VarSERVERINFORMATION and System.FoswikiServerInformation

use strict;
use warnings;

use File::Spec;
use Foswiki::Func;
use Config;

sub SERVERINFORMATION {
my ( $this, $params ) = @_;
my $authorized;
my $session = $Foswiki::Plugins::SESSION;

if ( defined $Foswiki::cfg{FeatureAccess}{Configure}
&& length( $Foswiki::cfg{FeatureAccess}{Configure} ) )
{
foreach my $authuser (
split( /[,\s]/, $Foswiki::cfg{FeatureAccess}{Configure} ) )
{
if ( $session->{user} eq $authuser ) {
$authorized = 1;
last;
}
}
}
else {
$authorized = Foswiki::Func::isAnAdmin();
}

return
"Server information is only accessible to authorized configure users."
unless $authorized;

my $report;
if ( ( !defined $params->{_DEFAULT} )
|| $params->{_DEFAULT} eq 'environment' )
{
$report .= _report_environment();
}

if ( ( !defined $params->{_DEFAULT} )
|| $params->{_DEFAULT} eq 'execution' )
{
$report .= _report_execution();
}

return $report;
}

sub _report_environment {

my $report = <<DONE;
<noautolink>
%TABLE{sort="off"}%
| *Key* | *Value* |
DONE

my @cgivars = (

# CGI 'Standard'
qw/AUTH_TYPE CONTENT_LENGTH CONTENT_TYPE GATEWAY_INTERFACE/,
qw/PATH_INFO PATH_TRANSLATED QUERY_STRING REMOTE_ADDR/,
qw/REMOTE_HOST REMOTE_IDENT REMOTE_USER REQUEST_METHOD/,
qw/SCRIPT_NAME SERVER_NAME SERVER_PORT SERVER_PROTOCOL/,
qw/SERVER_SOFTWARE/,

# Apache/common extensions
qw/DOCUMENT_ROOT REQUEST_URI SCRIPT_FILENAME/,
qw/SCRIPT_URI SCRIPT_URL SERVER_ADDR SERVER_ADMIN SERVER_SIGNATURE/,
qw/UNIQUE_ID /,

# Foswiki Extensions
grep( /^(?:FOSWIKI)_/, keys %ENV ),

# Perl Environment
grep( /^(?:PERL)/, keys %ENV ),

# System temporary dirs
qw/TEMP TMP TMPDIR/,

# HTTP headers & SSL data
grep( /^(?:HTTP|SSL)_/, keys %ENV ),

# Other
qw/PATH MOD_PERL MOD_PERL_API_VERSION/,
);

foreach my $key ( sort @cgivars ) {

#foreach my $key ( sort keys %ENV ) {
my $value = $ENV{$key};
my $decoded = '';
if ( $key eq 'HTTP_COOKIE' && $value ) {

# url decode for readability
#$value =~ s/%7C/ | /go;
$value =~ s/%3D/=/go;
}
$value =~ s/\n/\\n/g if defined $value;
$report .=
"| $key | " . ( ( defined $value ) ? $value : '_undef_' ) . " |\n";
}

$report .= '</noautolink>';

return $report;
}

sub _report_execution {

my $report = <<DONE;
<noautolink>
%TABLE{sort="off"}%
| *Area* | *Details* |
DONE

$report .= '| @INC Library Path | ' . join( '%BR%', @INC ) . " |\n";

# report the umask
my $pUmask = sprintf( '%03o', umask() );
$report .= "| UMASK | $pUmask |\n";

my $uid = getlogin() || getpwuid($>);
my $user = 'userid: ' . ( $uid ? "*$uid*" : 'unknown' );
$report .= "| User | $user _Your scripts are executing as this user_ |\n";

my @gids;
eval {
@gids = map { lc getgrgid($_) } split( ' ', $( );
};
if ($@) {
@gids =
( lc( qx(sh -c '( id -un ; id -gn) 2>/dev/null' 2>nul ) || 'n/a' ) );
}

$report .= '| Groups | ' . join( ',', @gids ) . " |\n";

#OS
my $n =
ucfirst( lc( $Config::Config{osname} ) ) . ' '
. $Config::Config{osvers} . ' ('
. $Config::Config{archname} . ')';
$report .= "| Operating system | $n |\n";

# Perl version and type
if ( $] =~ /^(\d+)\.(\d{3})(\d{3})$/ ) {
$n = sprintf( "%d.%d.%d", $1, $2, $3 );
}
else {
$n = $];
}
$n .= " ($Config::Config{osname})";
$report .= "| Perl version | $n |\n";
$report .=
"| File System | Case "
. ( ( File::Spec->case_tolerant() ) ? 'Insensitive' : 'Sensitive' )
. " |\n";
$report .= '</noautolink>';

return $report;

}

1;

__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2014-2015 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.

0 comments on commit 787fcbe

Please sign in to comment.