File:  [LON-CAPA] / loncom / interface / lonblockingstatus.pm
Revision 1.23: download - view: text, annotated - select for diffs
Tue Dec 31 19:28:29 2024 UTC (7 weeks, 2 days ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, HEAD
- For IP-based access control set in a domain, blocked functionality in a
  course can include display of a content index, indexed by keyword.
- Blocking Communication/Resource Access in a course can include blocking
  display of a content index, indexed by keyword.

    1: # The LearningOnline Network with CAPA
    2: # displays the blocking status table
    3: #
    4: # $Id: lonblockingstatus.pm,v 1.23 2024/12/31 19:28:29 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: #
   29: package Apache::lonblockingstatus;
   30: 
   31: use strict;
   32: use Apache::Constants qw(:common);
   33: use Apache::loncommon();
   34: use Apache::lonnet;
   35: use Apache::lonlocal;
   36: use LONCAPA qw(:DEFAULT :match);
   37: 
   38: sub handler {
   39:     my $r = shift;
   40:     &Apache::loncommon::no_cache($r);
   41:     &Apache::loncommon::content_type($r,'text/html');
   42: 
   43:     $r->send_http_header;
   44:     return OK if $r->header_only;
   45: 
   46:     my (%activities,$activity,$origurl,$origsymb);
   47:     map { $activities{$_} = 1; } ('boards','chat','com','blogs','about','groups','port','printout','docs','grades','passwd','search','index','wishlist','annotate');
   48: 
   49:     # determine what kind of blocking we want details for
   50:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['activity','url','symb']);
   51:     $activity = $env{'form.activity'};
   52: 
   53:     my $title = 'Communication Blocking Status Information';
   54: 
   55:     if (($activity eq 'docs') || ($activity eq 'printout') ||
   56:         ($activity eq 'grades') || ($activity eq 'passwd') ||
   57:         ($activity eq 'search') || ($activity eq 'wishlist') ||
   58:         ($activity eq 'annotate') || ($activity eq 'index')) {
   59:         $title = 'Blocking Status Information';
   60:         if ($activity eq 'docs') {
   61:             $origurl = $env{'form.url'};
   62:             $origsymb = $env{'form.symb'};
   63:         }
   64:     }
   65:     $r->print(&Apache::loncommon::start_page($title,undef,
   66:                                             {'only_body' => 1}));
   67: 
   68:     if (($activity eq '') || (!$activities{$activity})) {
   69:         $r->print('<p class="LC_error">'.&mt('Error: unknown activity type blocked').'</p>');
   70:     } elsif (($activity eq 'docs') && ($origurl eq '') && ($origsymb eq '')) {
   71:         $r->print('<p class="LC_error">'.&mt('Error: could not determine what content was blocked from access').'</p>');
   72:     } else {
   73:         my $clientip = &Apache::lonnet::get_requestor_ip($r);
   74:         $r->print(&blockpage($activity,$origurl,$origsymb,$clientip));
   75:     }
   76: 
   77:     $r->print(&Apache::loncommon::end_page());
   78: 
   79:     return OK;
   80: }
   81: 
   82: sub blockpage {
   83:     my ($activity,$origurl,$origsymb,$clientip) = @_;
   84: 
   85:     # in case of a portfolio block we need to determine the owner of the files
   86:     # we're trying to look at. This information is passed via query string.
   87:     my ($uname, $udom);
   88: 
   89:     if (($activity eq 'port') || ($activity eq 'about') ||
   90:         (($activity eq 'passwd') && ($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))) {
   91:         &Apache::loncommon::get_unprocessed_cgi(
   92:             $ENV{'QUERY_STRING'}, ['udom', 'uname'] );
   93: 
   94:         ($uname, $udom) = ($env{'form.uname'}, $env{'form.udom'});
   95:         if (($uname !~ /^$match_username$/) || ($udom !~ /^$match_domain$/)) {
   96:             if ($activity eq 'port') {
   97:                 return '<span class="LC_error">'.
   98:                        &mt('Information about the owner of the portfolio files you were trying to view was missing or invalid.').
   99:                        '</span><br />'.
  100:                        &mt('Without valid owner information, the reason why access is blocked can not be determined');
  101:             } elsif ($activity eq 'about') {
  102:                 return '<span class="LC_error">'.
  103:                        &mt('The username and/or domain for the User Information page you were trying to view was missing or invalid.').
  104:                        '</span><br />'.
  105:                        &mt('Without valid information, the reason why access is blocked can not be determined');
  106:             } else {
  107:                 return '<span class="LC_error">'.
  108:                        &mt('Information about the username and/or domain for which you were trying to reset a password was missing or invalid.').
  109:                        '</span><br />'.
  110:                        &mt('Without valid information, the reason why access is blocked can not be determined');
  111:             }
  112:         }
  113:     }
  114: 
  115:     # retrieve start/end of possible active blocking
  116:     my (%setters,$startblock,$endblock,$triggerblock,$by_ip,$blockdom);
  117: 
  118:     if ($activity eq 'docs') {
  119:         my ($cdom,$cnum);
  120:         if ($env{'request.course.id'}) {
  121:             $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  122:             $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  123:         }
  124:         my $cancheck;
  125:         if (($cdom ne '') && ($cnum ne '')) {
  126:             if ($origsymb =~ m{^uploaded/($match_domain)/($match_courseid)/}) {
  127:                 my ($crsdom,$crsnum) = ($1,$2);
  128:                 if (($cdom eq $crsdom) && ($cnum eq $crsnum)) {
  129:                     $cancheck = 1;
  130:                 }
  131:             } else {
  132:                 $cancheck = 1;
  133:             }
  134:         }
  135:         if ($cancheck) {
  136:             ($startblock,$endblock,$triggerblock) =
  137:                 &Apache::loncommon::blockcheck(\%setters,$activity,$clientip,$cnum,$cdom,$origurl,1,$origsymb,'blockingstatus');
  138:         } else {
  139:             return '<p class="LC_info">'.&mt('Could not determine why access is blocked.').'</p>';
  140:         }
  141:     } else {
  142:         ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
  143:             &Apache::loncommon::blockcheck(\%setters,$activity,$clientip,$uname,$udom,$origurl,undef,$origsymb,'blockingstatus');
  144:     }
  145: 
  146:     # nothing to do if there's no active blocking
  147:     unless (($startblock && $endblock) || ($by_ip)) {
  148:         if ($activity eq 'docs') {
  149:             return '<p class="LC_info">'.&mt('Content no longer blocked from access').'</p>';
  150:         }
  151:         return '<p class="LC_info">'.&mt('Access no longer blocked for this activity').'</p>';
  152:     }
  153: 
  154:     # lookup $activity -> description
  155:                    #possible activity          #corresponding description
  156:     my %descs = (
  157:                    boards     => 'Discussion posts in this course',
  158:                    chat       => 'Chat Room',
  159:                    com        => 'This message',
  160:                    blogs      => 'Blogs',
  161:                    about      => 'User information pages',
  162:                    groups     => 'Groups in this course',
  163:                    printout   => 'Printout generation',
  164:                    docs       => 'Course Content',
  165:                    passwd     => 'Changing of passwords',
  166:                    grades     => 'Course Gradebook',
  167:                    search     => 'Content Search',
  168:                    index      => 'Content Index',
  169:                    wishlist   => 'Stored Links', 
  170:                    annotate   => 'Annotations',
  171:                 );
  172: 
  173:     if ($activity eq 'groups' || $activity eq 'boards') {
  174:         if (&Apache::loncommon::course_type() eq 'Community') {
  175:             $descs{'boards'} = 'Discussion posts in this community';
  176:             $descs{'groups'} = 'Groups in this community';
  177:             $descs{'docs'} = 'Community Content';
  178:             $descs{'grades'} = 'Community Gradebook';
  179:         }
  180:     }
  181: 
  182:     my $description = $descs{$activity};
  183:     if ($activity eq 'port') {
  184:         $description = &get_portfolio_category($uname,$udom,$by_ip,\%setters);
  185:     }
  186:     if ($description eq '') {
  187:         $description = 'Communication';
  188:     }
  189: 
  190:     my ($showstart,$showend,$output);
  191:     unless ($by_ip) {
  192:         $showstart = Apache::lonlocal::locallocaltime($startblock);
  193:         $showend   = Apache::lonlocal::locallocaltime($endblock);
  194:     }
  195: 
  196:     if ( ref($description) ne 'ARRAY' ) {
  197:         #default: $description is one of the above descriptions
  198:         if ($activity eq 'docs') {
  199:             $output=&mt( 'Access to the content page you are attempting to'
  200:                          . ' view will be unavailable between [_1] and [_2] because'
  201:                          . ' access to selected '.$description.' is being blocked.'
  202:                          ,$showstart, $showend);
  203:         } elsif (($activity eq 'printout') || ($activity eq 'passwd') ||
  204:                  ($activity eq 'grades') || ($activity eq 'search') ||
  205:                  ($activity eq 'about') || ($activity eq 'wishlist') ||
  206:                  ($activity eq 'annotate') || ($activity eq 'index')) {
  207:             if ($by_ip) {
  208:                 $output = mt( $description
  209:                               . ' unavailable from your current IP address: [_1] '
  210:                               . 'because this functionality is being blocked for certain IP address(es).'
  211:                               ,$clientip);
  212:             } else {
  213:                 $output = mt( $description
  214:                               . ' will be unavailable between [_1] and [_2] because'
  215:                               . ' this functionality is being blocked.'
  216:                               ,$showstart, $showend);
  217:             }
  218:         } else {
  219:             if ($by_ip) {
  220:                 $output = mt( $description
  221:                               . ' unavailable from your current IP address: [_1] '
  222:                               . 'because communication is being blocked for certain IP address(es).'
  223:                               ,$clientip);
  224:             } else {
  225:                 $output = mt( $description
  226:                               . ' will be inaccessible between [_1] and [_2] because'
  227:                               . ' communication is being blocked.'
  228:                               ,$showstart, $showend);
  229:             }
  230:         }
  231:     } else {
  232:         # @$description is is the array returned from get_portfolio_category()
  233:         # and contains the description (e.g. "Portfolio files belonging to [_1]"
  234:         # and the value for [_1]
  235:         if ($by_ip) {
  236:             $output = mt( $$description[0]
  237:                           . ' are inaccessible from your current IP address: [_2] '
  238:                           . 'because communication is being blocked for certain IP address(es).'
  239:                           , $$description[1], $clientip);
  240:         } else {
  241:             $output = mt( $$description[0]
  242:                           . ' will be inaccessible between [_2] and [_3] because'
  243:                           . ' communication is being blocked.'
  244:                           ,$$description[1], $showstart, $showend);
  245:         }
  246:     }
  247: 
  248:     $output = "<p class=\"LC_info\">$output</p>";
  249: 
  250:     # show a table containing details, except if user is trying to look
  251:     # at a different user's portfolio files
  252:     if (   $activity ne 'port'                        # no portfolio
  253:         || (   $uname eq $env{'user.name'}            # or own portfolio
  254:             && $udom  eq $env{'user.domain'} ) 
  255:         || Apache::lonnet::is_course($udom, $uname) ) # or portfolio of a course
  256:     {
  257:         if ($by_ip) {
  258:             my $showdom = &Apache::lonnet::domain($blockdom);
  259:             if ($showdom eq '') {
  260:                 $showdom = $blockdom;
  261:             }
  262:             $output .= '<br />'.
  263:                        &mt('This restriction was set by an administrator in the [_1] LON-CAPA domain.'
  264:                           ,$showdom);
  265:         } else {
  266:             $output .= &build_block_table(\%setters);
  267:         }
  268:     }
  269: 
  270:     return $output;
  271: }
  272: 
  273: sub build_block_table {
  274:     my ($setters) = @_;
  275:     my %lt = &Apache::lonlocal::texthash(
  276:         'cacb' => 'Currently active communication/content blocks',
  277:         'cour' => 'Course',
  278:         'dura' => 'Duration',
  279:         'blse' => 'Block set by'
  280:     );
  281:     my $output;
  282:     $output  = Apache::loncommon::start_data_table()
  283:              . Apache::loncommon::data_table_caption($lt{'cacb'})
  284:              . Apache::loncommon::start_data_table_header_row()
  285:              . "<th>$lt{'cour'}</th> <th>$lt{'dura'}</th> <th>$lt{'blse'}</th>"
  286:              . Apache::loncommon::end_data_table_header_row();
  287: 
  288:     foreach my $course (keys(%{$setters})) {
  289:         my %courseinfo=&Apache::lonnet::coursedescription($course);
  290:         for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
  291:             my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
  292:             my $fullname = Apache::loncommon::plainname($uname,$udom);
  293:             if (defined($env{'user.name'}) && defined($env{'user.domain'})
  294:                 && $env{'user.name'} ne 'public'
  295:                 && $env{'user.domain'} ne 'public') 
  296:             {
  297:                 $fullname = Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
  298:             }
  299:             my $triggertype = $$setters{$course}{triggers}[$i];
  300:             if ($triggertype) {
  301:                 $fullname .= &mt(' (triggered by you when starting timer)');
  302:             }
  303:             my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
  304:             $openblock = &Apache::lonlocal::locallocaltime($openblock);
  305:             $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
  306:             my $duration = mt('[_1] to [_2]', $openblock, $closeblock);
  307:             $output .= Apache::loncommon::start_data_table_row()
  308:                      . "<td>$courseinfo{'description'}</td>"
  309:                      . "<td>$duration</td>"
  310:                      . "<td>$fullname</td>"
  311:                      . Apache::loncommon::end_data_table_row();
  312:         }
  313:     }
  314:     $output .= Apache::loncommon::end_data_table();
  315: }
  316: 
  317: sub get_portfolio_category {
  318:     my ($uname, $udom, $by_ip, $setters) = @_;
  319: 
  320:     if ($uname eq $env{'user.name'} && $udom eq $env{'user.domain'}) {
  321:         # user's portolfio files
  322: 
  323:         return 'Your portfolio files';
  324: 
  325:     } elsif (Apache::lonnet::is_course($udom, $uname)) {
  326:         # group portfolio files
  327: 
  328:         my $coursedesc;
  329: 
  330:         if ($by_ip) {
  331:             my %courseinfo = Apache::lonnet::coursedescription($udom.'_'.$uname);
  332:             $coursedesc    = $courseinfo{'description'};
  333:         } else {
  334:             foreach my $course (keys(%{$setters})) {
  335:                 my %courseinfo = Apache::lonnet::coursedescription($course);
  336:                 $coursedesc    = $courseinfo{'description'};
  337:             }
  338:         }
  339: 
  340:         return ["Group portfolio files in the course '[_1]'", $coursedesc];
  341:         
  342:     } else {
  343:         # different user's portfolio files
  344:         
  345:         my $plainname = Apache::loncommon::plainname($uname, $udom);
  346: 
  347:         unless (   $env{'user.name'}   eq 'public' 
  348:                 && $env{'user.domain'} eq 'public' ) 
  349:         {
  350:             $plainname = Apache::loncommon::aboutmewrapper(
  351:                             $plainname, $uname, $udom);
  352:         }
  353: 
  354:         return ['Portfolio files belonging to [_1]', $plainname];
  355:     }
  356: }
  357: 
  358: 1;
  359: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>