File:  [LON-CAPA] / loncom / interface / domainstatus.pm
Revision 1.2: download - view: text, annotated - select for diffs
Thu Dec 25 01:52:50 2008 UTC (15 years, 4 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_9_X, version_2_9_99_0, version_2_9_1, version_2_9_0, version_2_8_X, version_2_8_99_1, version_2_8_99_0, version_2_8_2, version_2_8_1, version_2_8_0, version_2_7_99_1, version_2_7_99_0, bz6209-base, bz6209, bz5969, bz2851, PRINT_INCOMPLETE_base, PRINT_INCOMPLETE, HEAD, GCI_3, GCI_2, GCI_1, BZ5971-printing-apage, BZ5434-fox
- Changes resulting from movement of subroutines from loncgi.pm
  to lonauthcgi.pm.

# The LearningOnline Network
# Generate a menu page containing links to server status pages accessible
# to user. 
#
# $Id: domainstatus.pm,v 1.2 2008/12/25 01:52:50 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA 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.
#
# LON-CAPA 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.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
#
package Apache::domainstatus;

use strict;
use Apache::Constants qw(:common);
use Apache::lonnet;
use Apache::loncommon;
use Apache::lonhtmlcommon;
use Apache::lonlocal;
use LONCAPA::lonauthcgi;

sub handler {
    my $r = shift;
    &Apache::loncommon::content_type($r,'text/html');
    $r->send_http_header;
    if ($r->header_only) {
        return OK;
    }

    &Apache::lonlocal::get_language_handle();
    my $dom = &Apache::lonnet::default_login_domain();

    if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
        $dom = $env{'user.domain'};
        if ($env{'request.role.domain'} ne '') {
            $dom = $env{'request.role.domain'};
        }
    }
    my $domdesc = &Apache::lonnet::domain($dom,'description');

    my %candisplay;
    my $titles = &LONCAPA::lonauthcgi::serverstatus_titles();
    if (ref($titles) eq 'HASH') {
        foreach my $page (keys(%{$titles})) {
            if (&LONCAPA::lonauthcgi::can_view($page)) {
                $candisplay{$page} = 'F';       
            } elsif (&LONCAPA::lonauthcgi::check_ipbased_access($page)) {
                $candisplay{$page} = 'F';
            }
        }
    }

    &Apache::lonhtmlcommon::clear_breadcrumbs();
    &Apache::lonhtmlcommon::add_breadcrumb
    ({href=>"/adm/domainstatus",
      text=>"Server Status Information"});

    $r->print(&Apache::loncommon::start_page('Server Status').
              &Apache::lonhtmlcommon::breadcrumbs('Server Status Information').
              '<div class="LC_clear_float_header"></div>');

    if (keys(%candisplay) > 0) {
        $r->print('<h2>'.&mt('Server Utilities for Domain: [_1]','<i>'.$domdesc.'</i>').
                  '</h2>'.&print_status_menu(\%candisplay));
    } else {
        $r->print('<h2>'.&mt('No information available').'</h2>'.
                  '<span class="LC_error">'.&mt('Your current role and/or IP address does not have permission to display information about server status for servers in the domain: [_1].','<b>'.$domdesc.'</b> ('.$dom.')').'</span>'); 
    }
    $r->print(&Apache::loncommon::end_page());
    return OK;
}

sub print_status_menu {
    my ($candisplay) = @_;
    return '' if (ref($candisplay) ne 'HASH');
    my $menu_html;
    my @menu = &servermenu_items($candisplay);
    foreach my $item (@menu) {
        if (ref($item) eq 'HASH') {
            my $display;
            if (ref($item->{'items'}) eq 'ARRAY') {
                foreach my $page (@{$item->{'items'}}) {
                    if (ref($page) eq 'HASH') {
                        if ($page->{'permission'} eq 'F') {
                            $display .= '<span class="LC_parm_menu_item">';
                            if ($page->{'help'} ne '') {
                                $display .= 
                                    &Apache::loncommon::help_open_topic($page->{'help'});
                            }
                            $display .= '<a href="'.$page->{'url'}.'" title="'.
                                        &mt($page->{'linktitle'}).'">'.
                                        &mt($page->{'linktext'}).
                                        '</a></span><br /><br />'; 
                        }
                    }
                }
            }
            if ($display) {
                $menu_html .= '<div class="LC_left_float">'.
                              '<h3>'.&mt($item->{'categorytitle'}).'</h3>'.
                              $display.'</div>';
            }
        }
    }
    if ($menu_html) {
        $menu_html .= '<div class="LC_clear_float_footer"></div>'; 
    }
    return $menu_html;
}

sub servermenu_items {
    my ($candisplay) = @_;
    my $titles = &LONCAPA::lonauthcgi::serverstatus_titles();
    my $linknames = &serverstatus_links();
    my @menu;
    if ((ref($candisplay) eq 'HASH') && (ref($titles) eq 'HASH') && 
        (ref($linknames) eq 'HASH')) { 
        @menu = ( {categorytitle => 'Status information',
                  items =>
                 [{
                 linktext => $linknames->{'userstatus'},
                 #icon => '',
                 #help => 'Domain_Coordination_Userstatus',
                 url => '/cgi-bin/userstatus.pl',
                 permission => $candisplay->{'userstatus'},
                 linktitle =>  $titles->{'userstatus'},
             },
             {
                 linktext => $linknames->{'lonstatus'},
                 #icon => '',
                 #help => 'Domain_Coordination_Connection_Status',
                 url => '/lon-status/',
                 permission => $candisplay->{'lonstatus'},
                 linktitle => $titles->{'lonstatus'},
             },
             {
                 linktext => $linknames->{'server-status'},
                 #icon => '',
                 #help => 'Domain_Coordination_Apache_Status',
                 url => '/server-status',
                 permission => $candisplay->{'server-status'},
                 linktitle => $titles->{'server-status'},
             },
             {
                 linktext => $linknames->{'clusterstatus'},
                 #icon => '',
                 #help => 'Domain_Coordination_Apache_Status',
                 url => '/cgi-bin/clusterstatus.pl',
                 permission => $candisplay->{'clusterstatus'},
                 linktitle => $titles->{'clusterstatus'},
             },
             {
                 linktext => $linknames->{'codeversions'},
                 #icon => '',
                 #help => 'Domain_Coordination_Code_Versions',
                 url => '/cgi-bin/lonversions.pl',
                 permission => $candisplay->{'codeversions'},
                 linktitle => $titles->{'codeversions'},
             },
             {
                 linktext => $linknames->{'showenv'},
                 #icon => '',
                 #help => 'Domain_Coordination_User_Environment',
                 url => '/adm/test',
                 permission => $candisplay->{'showenv'},
                 linktitle => $titles->{'showenv'},
             }]},
             {categorytitle => 'Server Actions',
             items =>
             [{
                 linktext => $linknames->{'loncron'},
                 #icon => '',
                 #help => 'Domain_Coordination_Connection_Reload',
                 url => '/cgi-bin/loncron.pl',
                 permission => $candisplay->{'loncron'},
                 linktitle => $titles->{'loncron'},
             },
             {
                 linktext => $linknames->{'takeoffline'},
                 #icon => '',
                 #help => 'Domain_Coordination_Server_Offline',
                 url => '/cgi-bin/takeoffline.pl',
                 permission => $candisplay->{'takeoffline'},
                 linktitle => $titles->{'takeoffline'},
             },
             {
                 linktext => $linknames->{'takeonline'},
                 #icon => '',
                 #help => 'Domain_Coordination_Server_Online',
                 url => '/cgi-bin/takeonline.pl',
                 permission => $candisplay->{'takeonline'},
                 linktitle => $titles->{'takeonline'},
             }]},
             {categorytitle => 'Metadata Information',
             items =>
             [{
                 linktext => $linknames->{'metadata_keywords'},
                 #icon => '',
                 #help => 'Domain_Coordination_Metadata_Keywords',
                 url => '/cgi-bin/metadata_keywords.pl',
                 permission => $candisplay->{'metadata_keywords'},
                 linktitle => $titles->{'metadata_keywords'},
             },
             {
                 linktext => $linknames->{'metadata_harvest'},
                 #icon => '',
                 #help => 'Domain_Coordination_Metadata_Harvest',
                 url => '/cgi-bin/metadata_harvest.pl',
                 permission => $candisplay->{'metadata_harvest'},
                 linktitle => $titles->{'metadata_harvest'},
             }]},
           );
        }
    return @menu;
}

sub serverstatus_links {
    my $linkname = { 
                    'userstatus' => 'User Sessions',
                    'lonstatus' => 'Connection Status',
                    'server-status' => 'Apache Server Status',
                    'clusterstatus' => 'Domain Status',
                    'codeversions' => 'LON-CAPA Modules',
                    'showenv' => 'User Environment for current log-in',
                    'loncron' => 'Update Connections and Refresh Status Information',
                    'takeoffline' => 'Replace log-in page with offline notice',
                    'takeonline' => 'Replace offline notice with log-in page',
                    'metadata_keywords' => 'Display Metadata Keywords',
                    'metadata_harvest' => 'Harvest Metadata Keywords',
    };
    return $linkname;
}

1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.