[LON-CAPA-cvs] cvs: doc /loncapafiles loncapafiles.lpml loncom/cgi quotacheck.pl loncom/interface domainprefs.pm domainstatus.pm

raeburn raeburn at source.lon-capa.org
Sun Mar 16 22:37:30 EDT 2014


raeburn		Mon Mar 17 02:37:30 2014 EDT

  Added files:                 
    /loncom/cgi	quotacheck.pl 

  Modified files:              
    /loncom/interface	domainprefs.pm domainstatus.pm 
    /doc/loncapafiles	loncapafiles.lpml 
  Log:
  - Add quotacheck.pl
    - CGI script for use on a library server to display disk usage and quota 
      for course content uploaded directly to course/communities in the domain.
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.228 loncom/interface/domainprefs.pm:1.229
--- loncom/interface/domainprefs.pm:1.228	Mon Mar  3 17:11:42 2014
+++ loncom/interface/domainprefs.pm	Mon Mar 17 02:36:56 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.228 2014/03/03 17:11:42 raeburn Exp $
+# $Id: domainprefs.pm,v 1.229 2014/03/17 02:36:56 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4629,7 +4629,7 @@
     return ('userstatus','lonstatus','loncron','server-status','codeversions',
             'checksums','clusterstatus','metadata_keywords','metadata_harvest',
             'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
-            'uniquecodes');
+            'uniquecodes','diskusage');
 }
 
 sub coursecategories_javascript {
Index: loncom/interface/domainstatus.pm
diff -u loncom/interface/domainstatus.pm:1.6 loncom/interface/domainstatus.pm:1.7
--- loncom/interface/domainstatus.pm:1.6	Wed Jan  1 17:41:47 2014
+++ loncom/interface/domainstatus.pm	Mon Mar 17 02:36:56 2014
@@ -2,7 +2,7 @@
 # Generate a menu page containing links to server status pages accessible
 # to user. 
 #
-# $Id: domainstatus.pm,v 1.6 2014/01/01 17:41:47 raeburn Exp $
+# $Id: domainstatus.pm,v 1.7 2014/03/17 02:36:56 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -163,6 +163,15 @@
                  linktitle => $titles->{'checksums'},
              },
              {
+                 linktext => $linknames->{'diskusage'},
+                 icon => '',
+                 alttext => '',
+                 #help => 'Domain_Coordination_Disk_Usage',
+                 url => '/cgi-bin/quotacheck.pl?domain='.$dom,
+                 permission => $candisplay->{'diskusage'},
+                 linktitle => $titles->{'diskusage'},
+             },
+             {
                  linktext => $linknames->{'uniquecodes'},
                  icon => '',
                  alttext => '',
@@ -242,6 +251,7 @@
                     'clusterstatus' => 'Domain Status',
                     'codeversions' => 'LON-CAPA Modules',
                     'checksums'    => 'Check for LON-CAPA Module changes',   
+                    'diskusage'    => 'Display quotas and usage for Course/Community Content',
                     'showenv' => 'User Environment for current log-in',
                     'loncron' => 'Update Connections and Refresh Status Information',
                     'uniquecodes' => "List Domain's Courses with Assigned Six Character codes",
Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.881 doc/loncapafiles/loncapafiles.lpml:1.882
--- doc/loncapafiles/loncapafiles.lpml:1.881	Wed Feb 19 18:07:16 2014
+++ doc/loncapafiles/loncapafiles.lpml	Mon Mar 17 02:37:30 2014
@@ -2,7 +2,7 @@
  "http://lpml.sourceforge.net/DTD/lpml.dtd">
 <!-- loncapafiles.lpml -->
 
-<!-- $Id: loncapafiles.lpml,v 1.881 2014/02/19 18:07:16 bisitz Exp $ -->
+<!-- $Id: loncapafiles.lpml,v 1.882 2014/03/17 02:37:30 raeburn Exp $ -->
 
 <!--
 
@@ -2023,6 +2023,14 @@
 </description>
 </file>
 <file>
+<source>loncom/cgi/quotacheck.pl</source>
+<target dist='default'>home/httpd/cgi-bin/quotacheck.pl</target>
+<categoryname>script</categoryname>
+<description>CGI script to display disk usage and quota for content  
+uploaded directly to a course/community via the Course Editor.
+</description>
+</file>
+<file>
 <source>loncom/homework/templates/sampleexternal.pl</source>
 <target dist='default'>home/httpd/cgi-bin/sampleexternal.pl</target>
 <categoryname>script</categoryname>

Index: loncom/cgi/quotacheck.pl
+++ loncom/cgi/quotacheck.pl
#!/usr/bin/perl
$|=1;
# Display quotas for uploaded course content, current disk usage and
# percent usage for courses and communities for requested domain.
# Requester should either be an active domain coordinator in 
# requested domain, or current server should belong to requested
# domain.
#
# $Id: quotacheck.pl,v 1.1 2014/03/17 02:37:13 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/
#

use strict;

use lib '/home/httpd/lib/perl/';
use Apache::lonnet();
use Apache::loncommon();
use Apache::lonlocal();
use LONCAPA::Configuration();
use LONCAPA::loncgi();
use LONCAPA::lonauthcgi();
use File::Find;
use CGI qw(:standard);
use LONCAPA;

my $perlvar=&LONCAPA::Configuration::read_conf('loncapa.conf');
my $lonhost;
if (ref($perlvar) eq 'HASH') {
    $lonhost = $perlvar->{'lonHostID'};
}
undef($perlvar);

print &LONCAPA::loncgi::cgi_header('text/html',1);
&main($lonhost);

sub main {
    my ($lonhost) = @_;
    if ($lonhost eq '') {
        &Apache::lonlocal::get_language_handle();
        &Apache::lonhtmlcommon::add_breadcrumb
        ({href=>"/cgi-bin/quotacheck.pl",
          text=>"Content disk usage"});
        print(&Apache::loncommon::start_page('Course/Community disk usage and quotas').
              &Apache::lonhtmlcommon::breadcrumbs('Course/Community status').
              '<p class="LC_error">'.
              &Apache::lonlocal::mt("Error: could not determine server's LON-CAPA hostID.").
              '</p>'
              &Apache::loncommon::end_page());
        return;
    }
    if (&LONCAPA::lonauthcgi::check_ipbased_access('diskusage')) {
        &LONCAPA::loncgi::check_cookie_and_load_env();
    } else {
        if (!&LONCAPA::loncgi::check_cookie_and_load_env()) {
            &Apache::lonlocal::get_language_handle();
            print(&LONCAPA::loncgi::missing_cookie_msg());
            return;
        }
        if (!&LONCAPA::lonauthcgi::can_view('diskusage')) {
            &Apache::lonlocal::get_language_handle();
            print(&LONCAPA::lonauthcgi::unauthorized_msg('diskusage'));
            return;
        }
    }
    my (%gets,%posted,$reqdom,$crstype,%params);

#
#  Get domain -- if this is for an authenticated user (i.e., not IP-based access)
#  Set domain in the order (a) value of fixeddom form element, if submitted
#                          (b) value of domain item in query string
#                          (c) default login domain for current server   
#

    if (($Apache::lonnet::env{'user.name'}) && ($Apache::lonnet::env{'user.domain'})) {
        my $q = CGI->new;
        %params = $q->Vars;
        $crstype = 'Course';
        if ($params{'type'} eq 'Community') {
            $crstype = $params{'type'};
        }
        if ($params{'fixeddom'}) {
            $reqdom = $params{'fixeddom'};
        }
    }
    if (($reqdom eq '') && ($ENV{'QUERY_STRING'})) {
        &LONCAPA::loncgi::cgi_getitems($ENV{'QUERY_STRING'},\%gets);
        if (ref($gets{'domain'}) eq 'ARRAY') {
            $gets{'domain'}->[0] =~ s/^\s+|\s+$//g;
            if ($gets{'domain'}->[0] =~ /^$LONCAPA::match_domain$/) {
                my $domdesc = &Apache::lonnet::domain($gets{'domain'}->[0]);
                unless ($domdesc eq '') {
                    $reqdom = $gets{'domain'}->[0];
                }
            }
        }
    }
    if ($reqdom eq '') {
        $reqdom = &Apache::lonnet::default_login_domain();
    }

    &Apache::lonlocal::get_language_handle();
    &Apache::lonhtmlcommon::add_breadcrumb
    ({href=>"/cgi-bin/quotacheck.pl?domain=$reqdom",
       text=>"Content disk usage"});
    if ($params{'gosearch'}) {
        &Apache::lonhtmlcommon::add_breadcrumb
            ({href=>"/cgi-bin/quotacheck.pl?domain=$reqdom",
              text=>"Result"});
    }
    my $domdesc = &Apache::lonnet::domain($reqdom,'description');
    print(&Apache::loncommon::start_page('Course/Community disk usage and quotas').
          &Apache::lonhtmlcommon::breadcrumbs('Course/Community status').
          '<h2>'.&Apache::lonlocal::mt('Quotas for uploaded course content').'</h2>'.
          '<h3>'.$domdesc.'</h3>');

#
#  If this is for an authenticated user (i.e., not IP-based access)
#  create display to choose filters to restrict courses/communities displayed
#  (e.g., recent activity, recently created, institutional code, course owner etc.)
#

    if (($Apache::lonnet::env{'user.name'}) && ($Apache::lonnet::env{'user.domain'})) {
        my ($numtitles, at codetitles);
        print(&Apache::loncommon::js_changer());
        my ($filterlist,$filter) = &get_filters($reqdom,\%params);
        $Apache::lonnet::env{'form.official'} = $params{'official'};
        if ($params{'official'}) {
            my @standardnames = &Apache::loncommon::get_standard_codeitems();
            pop(@standardnames);
            foreach my $item (@standardnames) {
                if ($params{'official'} eq 'on') {
                    $Apache::lonnet::env{'form.'.$item} = $params{$item};
                } else {
                    $Apache::lonnet::env{'form.'.$item} = 0;
                }
            }
            $Apache::lonnet::env{'form.state'} = $params{'state'};
        }
        print(&Apache::loncommon::build_filters($filterlist,$crstype,undef,undef,$filter,
                                                '/cgi-bin/quotacheck.pl',\$numtitles,
                                                'quotacheck',undef,undef,undef,
                                                \@codetitles,$reqdom,'quotacheck',$reqdom));
        if ($params{'gosearch'}) {
            if ($params{'official'} eq 'on') {
                $Apache::lonnet::env{'form.state'} = $params{'state'};
            }
            my %courses = &Apache::loncommon::search_courses($reqdom,$crstype,$filter,$numtitles,
                                                             undef,undef,undef,\@codetitles);
            my @showcourses = keys(%courses);
            &print_usage($lonhost,$reqdom,\@showcourses);
        }
        print(&Apache::loncommon::end_page());
        return;
    }
    &print_usage($lonhost,$reqdom);
    print(&Apache::loncommon::end_page());
    return;
}

sub print_usage {
    my ($lonhost,$dom,$courses) = @_;
    my @domains = &Apache::lonnet::current_machine_domains();
    my @ids=&Apache::lonnet::current_machine_ids();
    my $domain = &Apache::lonnet::host_domain($lonhost);

#
# If user's current role is domain coordinator, domain of courses/communities
# to be shown needs to be domain being coordinated. 
#
    if ($Apache::lonnet::env{'request.role'} =~ m{^dc\./}) {
        $domain = $Apache::lonnet::env{'request.role.domain'};
        unless ($dom eq $domain) {
            my $otherdomdesc = &Apache::lonnet::domain($domain,'description');
            print('<p class="LC_error">'.
                  &Apache::lonlocal::mt('Requested domain does not match domain being coordinated.').
                  '</p>'."\n".
                  '<p class="LC_info">'.
                  &Apache::lonlocal::mt('Show quotas for the domain being coordinated: [_1]',
                                        '<a href="/cgi-bin/quotacheck.pl?domain='.$domain.'">'.
                                        $otherdomdesc.'</a>').
                  '</p>');
            return;
        }
    } else {
        unless (grep(/^\Q$dom\E/, at domains)) {
            print('<p class="LC_error">'.
                  &Apache::lonlocal::mt('Requested domain is not hosted on this server.').
                  '</p>');
            return;
        }
    }
    my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
    my @showcourses;
    if (ref($courses) eq 'ARRAY') {
        @showcourses = @{$courses};
    } else {
        my %courseshash = &Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',undef,undef,'.');
        if (keys(%courseshash)) {
            @showcourses = keys(%courseshash);
        }
    }
    if (@showcourses) {
        print(&Apache::loncommon::start_data_table().
              &Apache::loncommon::start_data_table_header_row().
              '<th>'.&Apache::lonlocal::mt('Course Type').'</th>'.
              '<th>'.&Apache::lonlocal::mt('Course Title').'</th>'.
              '<th>'.&Apache::lonlocal::mt('Institutional Code').'</th>'.
              '<th>'.&Apache::lonlocal::mt('Quota (MB)').'</th>'.
              '<th>'.&Apache::lonlocal::mt('Usage (MB)').'</th>'.
              '<th>'.&Apache::lonlocal::mt('Percent usage').'</th>'.
              &Apache::loncommon::end_data_table_header_row());
        foreach my $cid (@showcourses) {
            my %courseinfo=&Apache::lonnet::coursedescription($cid,{'one_time' => '1'});
            my $cdesc = $courseinfo{'description'};
            my $cnum = $courseinfo{'num'};
            my $chome = $courseinfo{'home'};
            my $crstype = $courseinfo{'type'};
            if ($crstype eq '') {
                if ($cnum =~ /^$LONCAPA::match_community$/) {
                    $crstype = 'Community';
                } else {
                    $crstype = 'Course';
                }
            }
            my $instcode = $courseinfo{'internal.coursecode'};
            my $quota = $courseinfo{'internal.uploadquota'};
            $quota =~ s/[^\d\.]+//g;
            my $quotatype = 'unofficial';
            if ($crstype eq 'Community') {
                $quotatype = 'community';
            } elsif ($courseinfo{'internal.coursecode'}) {
                $quotatype = 'official';
            } elsif ($courseinfo{'internal.textbook'}) {
                $quotatype = 'textbook';
            }
            if ($quota eq '') {
                $quota = $domdefs{$crstype.'quota'};
            }
            $quota =~ s/[^\d\.]+//g;
            if ($quota eq '') {
                $quota = 500;
            }
            my $current_disk_usage = 0;
            if (grep(/^\Q$chome\E$/, at ids)) {
                my $dir = &propath($dom,$cnum).'/userfiles/';
                foreach my $subdir ('docs','supplemental') {
                    my $ududir = "$dir/$subdir";
                    my $total_size=0;
                    my $code=sub {
                        if (-d $_) { return;}
                        $total_size+=(stat($_))[7];
                    };
                    chdir($ududir);
                    find($code,$ududir);
                    $total_size=int($total_size/(1024*1024));
                    $current_disk_usage += $total_size;
                }
            } else {
                foreach my $subdir ('docs','supplemental') {
                    $current_disk_usage += &Apache::lonnet::diskusage($dom,$cnum,"userfiles/$subdir",1);
                }
            }
            my $percent;
            if (($quota == 0) || ($quota =~ /[^\d\.]/)) {
                $percent = 100.0;
            } else {
                $percent = 100*($current_disk_usage/$quota);
            }
            $current_disk_usage = sprintf("%.0f",$current_disk_usage);
            $quota = sprintf("%.0f",$quota);
            $percent = sprintf("%.0f",$percent);
            print(&Apache::loncommon::start_data_table_row().
                  '<td>'.$quotatype.'</td>'.
                  '<td>'.$cdesc.'</td>'.
                  '<td>'.$instcode.'</td>'.
                  '<td>'.$quota.'</td>'.
                  '<td>'.$current_disk_usage.'</td>'.
                  '<td>'.$percent.'</td>'.
                   &Apache::loncommon::end_data_table_row()
                  );
        }
        print(&Apache::loncommon::end_data_table().'<br /><br />');
    } else {
        print(&Apache::lonlocal::mt('No courses match search criteria.'));
    }
    return;
}

sub get_filters {
    my ($dom,$params) = @_;
    my @filterlist = ('descriptfilter','instcodefilter','ownerfilter',
                      'ownerdomfilter','coursefilter','sincefilter');
    # created filter
    my $loncaparev = &Apache::lonnet::get_server_loncaparev($dom);
    if ($loncaparev ne 'unknown_cmd') {
        push(@filterlist,'createdfilter');
    }
    my %filter;
    foreach my $item (@filterlist) {
        $filter{$item} = '';
    }
    if (ref($params) eq 'HASH') {
        foreach my $item (@filterlist) {
            $filter{$item} = $params->{$item};
        }
    }
    return (\@filterlist,\%filter);
}



More information about the LON-CAPA-cvs mailing list