version 1.1075.2.141.2.6, 2020/09/08 04:19:48
|
version 1.1075.2.149, 2020/11/12 01:18:26
|
Line 83 use Crypt::DES;
|
Line 83 use Crypt::DES;
|
use DynaLoader; # for Crypt::DES version |
use DynaLoader; # for Crypt::DES version |
use File::Copy(); |
use File::Copy(); |
use File::Path(); |
use File::Path(); |
use String::CRC32(); |
|
use Short::URL(); |
|
|
|
# ---------------------------------------------- Designs |
# ---------------------------------------------- Designs |
use vars qw(%defaultdesign); |
use vars qw(%defaultdesign); |
Line 4425 sub get_student_view_with_retries {
|
Line 4423 sub get_student_view_with_retries {
|
} |
} |
} |
} |
|
|
|
sub css_links { |
|
my ($currsymb,$level) = @_; |
|
my ($links,@symbs,%cssrefs,%httpref); |
|
if ($level eq 'map') { |
|
my $navmap = Apache::lonnavmaps::navmap->new(); |
|
if (ref($navmap)) { |
|
my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb); |
|
my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0); |
|
foreach my $res (@resources) { |
|
if (ref($res) && $res->symb()) { |
|
push(@symbs,$res->symb()); |
|
} |
|
} |
|
} |
|
} else { |
|
@symbs = ($currsymb); |
|
} |
|
foreach my $symb (@symbs) { |
|
my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb); |
|
if ($css_href =~ /\S/) { |
|
unless ($css_href =~ m{https?://}) { |
|
my $url = (&Apache::lonnet::decode_symb($symb))[-1]; |
|
my $proburl = &Apache::lonnet::clutter($url); |
|
my ($probdir) = ($proburl =~ m{(.+)/[^/]+$}); |
|
unless ($css_href =~ m{^/}) { |
|
$css_href = &Apache::lonnet::hreflocation($probdir,$css_href); |
|
} |
|
if ($css_href =~ m{^/(res|uploaded)/}) { |
|
unless (($httpref{'httpref.'.$css_href}) || |
|
(&Apache::lonnet::is_on_map($css_href))) { |
|
my $thisurl = $proburl; |
|
if ($env{'httpref.'.$proburl}) { |
|
$thisurl = $env{'httpref.'.$proburl}; |
|
} |
|
$httpref{'httpref.'.$css_href} = $thisurl; |
|
} |
|
} |
|
} |
|
$cssrefs{$css_href} = 1; |
|
} |
|
} |
|
if (keys(%httpref)) { |
|
&Apache::lonnet::appenv(\%httpref); |
|
} |
|
if (keys(%cssrefs)) { |
|
foreach my $css_href (keys(%cssrefs)) { |
|
next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)}); |
|
$links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n"; |
|
} |
|
} |
|
return $links; |
|
} |
|
|
=pod |
=pod |
|
|
=item * &get_student_answers() |
=item * &get_student_answers() |
Line 4680 sub findallcourses {
|
Line 4731 sub findallcourses {
|
############################################### |
############################################### |
|
|
sub blockcheck { |
sub blockcheck { |
my ($setters,$activity,$uname,$udom,$url,$is_course) = @_; |
my ($setters,$activity,$uname,$udom,$url,$is_course,$symb,$caller) = @_; |
|
|
if (defined($udom) && defined($uname)) { |
if (defined($udom) && defined($uname)) { |
# If uname and udom are for a course, check for blocks in the course. |
# If uname and udom are for a course, check for blocks in the course. |
if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) { |
if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) { |
my ($startblock,$endblock,$triggerblock) = |
my ($startblock,$endblock,$triggerblock) = |
&get_blocks($setters,$activity,$udom,$uname,$url); |
&get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller); |
return ($startblock,$endblock,$triggerblock); |
return ($startblock,$endblock,$triggerblock); |
} |
} |
} else { |
} else { |
Line 4703 sub blockcheck {
|
Line 4754 sub blockcheck {
|
# boards, chat or groups, check for blocking in current course only. |
# boards, chat or groups, check for blocking in current course only. |
|
|
if (($activity eq 'boards' || $activity eq 'chat' || |
if (($activity eq 'boards' || $activity eq 'chat' || |
$activity eq 'groups' || $activity eq 'printout' || |
$activity eq 'groups' || $activity eq 'printout') && |
$activity eq 'reinit' || $activity eq 'alert') && |
|
($env{'request.course.id'})) { |
($env{'request.course.id'})) { |
foreach my $key (keys(%live_courses)) { |
foreach my $key (keys(%live_courses)) { |
if ($key ne $env{'request.course.id'}) { |
if ($key ne $env{'request.course.id'}) { |
Line 4814 sub blockcheck {
|
Line 4864 sub blockcheck {
|
# of specified user, unless user has 'evb' privilege. |
# of specified user, unless user has 'evb' privilege. |
|
|
my ($start,$end,$trigger) = |
my ($start,$end,$trigger) = |
&get_blocks($setters,$activity,$cdom,$cnum,$url); |
&get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller); |
if (($start != 0) && |
if (($start != 0) && |
(($startblock == 0) || ($startblock > $start))) { |
(($startblock == 0) || ($startblock > $start))) { |
$startblock = $start; |
$startblock = $start; |
Line 4834 sub blockcheck {
|
Line 4884 sub blockcheck {
|
} |
} |
|
|
sub get_blocks { |
sub get_blocks { |
my ($setters,$activity,$cdom,$cnum,$url) = @_; |
my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_; |
my $startblock = 0; |
my $startblock = 0; |
my $endblock = 0; |
my $endblock = 0; |
my $triggerblock = ''; |
my $triggerblock = ''; |
Line 4847 sub get_blocks {
|
Line 4897 sub get_blocks {
|
my $now = time; |
my $now = time; |
my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum); |
my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum); |
if ($activity eq 'docs') { |
if ($activity eq 'docs') { |
@blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks); |
my ($blocked,$nosymbcache,$noenccheck); |
|
if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) { |
|
$blocked = 1; |
|
$nosymbcache = 1; |
|
$noenccheck = 1; |
|
} |
|
@blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks); |
foreach my $block (@blockers) { |
foreach my $block (@blockers) { |
if ($block =~ /^firstaccess____(.+)$/) { |
if ($block =~ /^firstaccess____(.+)$/) { |
my $item = $1; |
my $item = $1; |
Line 4969 sub parse_block_record {
|
Line 5025 sub parse_block_record {
|
} |
} |
|
|
sub blocking_status { |
sub blocking_status { |
my ($activity,$uname,$udom,$url,$is_course) = @_; |
my ($activity,$uname,$udom,$url,$is_course,$symb,$caller) = @_; |
my %setters; |
my %setters; |
|
|
# check for active blocking |
# check for active blocking |
my ($startblock,$endblock,$triggerblock) = |
my ($startblock,$endblock,$triggerblock) = |
&blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course); |
&blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course,$symb,$caller); |
my $blocked = 0; |
my $blocked = 0; |
if ($startblock && $endblock) { |
if ($startblock && $endblock) { |
$blocked = 1; |
$blocked = 1; |
Line 4990 sub blocking_status {
|
Line 5046 sub blocking_status {
|
$querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/); |
$querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/); |
$querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/); |
$querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/); |
} elsif ($activity eq 'docs') { |
} elsif ($activity eq 'docs') { |
$querystring .= '&url='.&HTML::Entities::encode($url,'&"'); |
my $showurl = &Apache::lonenc::check_encrypt($url); |
|
$querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>'); |
|
if ($symb) { |
|
my $showsymb = &Apache::lonenc::check_encrypt($symb); |
|
$querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>'); |
|
} |
} |
} |
|
|
my $output .= <<'END_MYBLOCK'; |
my $output .= <<'END_MYBLOCK'; |
Line 5015 END_MYBLOCK
|
Line 5076 END_MYBLOCK
|
$text = &mt('Printing Blocked'); |
$text = &mt('Printing Blocked'); |
} elsif ($activity eq 'passwd') { |
} elsif ($activity eq 'passwd') { |
$text = &mt('Password Changing Blocked'); |
$text = &mt('Password Changing Blocked'); |
} elsif ($activity eq 'grades') { |
|
$text = &mt('Gradebook Blocked'); |
|
} elsif ($activity eq 'alert') { |
|
$text = &mt('Checking Critical Messages Blocked'); |
|
} elsif ($activity eq 'reinit') { |
|
$text = &mt('Checking Course Update Blocked'); |
|
} |
} |
$output .= <<"END_BLOCK"; |
$output .= <<"END_BLOCK"; |
<div class='$class'> |
<div class='$class'> |
Line 5044 sub check_ip_acc {
|
Line 5099 sub check_ip_acc {
|
if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) { |
if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) { |
return 1; |
return 1; |
} |
} |
my ($ip,$allowed); |
my $allowed=0; |
|
my $ip; |
if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') || |
if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') || |
($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) { |
($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) { |
$ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip; |
$ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip; |
Line 5053 sub check_ip_acc {
|
Line 5109 sub check_ip_acc {
|
} |
} |
|
|
my $name; |
my $name; |
my %access = ( |
foreach my $pattern (split(',',$acc)) { |
allowfrom => 1, |
$pattern =~ s/^\s*//; |
denyfrom => 0, |
$pattern =~ s/\s*$//; |
); |
|
my @allows; |
|
my @denies; |
|
foreach my $item (split(',',$acc)) { |
|
$item =~ s/^\s*//; |
|
$item =~ s/\s*$//; |
|
if ($item =~ /^\!(.+)$/) { |
|
push(@denies,$1); |
|
} else { |
|
push(@allows,$item); |
|
} |
|
} |
|
my $numdenies = scalar(@denies); |
|
my $numallows = scalar(@allows); |
|
my $count = 0; |
|
foreach my $pattern (@denies,@allows) { |
|
$count ++; |
|
my $acctype = 'allowfrom'; |
|
if ($count <= $numdenies) { |
|
$acctype = 'denyfrom'; |
|
} |
|
if ($pattern =~ /\*$/) { |
if ($pattern =~ /\*$/) { |
#35.8.* |
#35.8.* |
$pattern=~s/\*//; |
$pattern=~s/\*//; |
if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; } |
if ($ip =~ /^\Q$pattern\E/) { $allowed=1; } |
} elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) { |
} elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) { |
#35.8.3.[34-56] |
#35.8.3.[34-56] |
my $low=$2; |
my $low=$2; |
Line 5088 sub check_ip_acc {
|
Line 5123 sub check_ip_acc {
|
$pattern=$1; |
$pattern=$1; |
if ($ip =~ /^\Q$pattern\E/) { |
if ($ip =~ /^\Q$pattern\E/) { |
my $last=(split(/\./,$ip))[3]; |
my $last=(split(/\./,$ip))[3]; |
if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; } |
if ($last <=$high && $last >=$low) { $allowed=1; } |
} |
} |
} elsif ($pattern =~ /^\*/) { |
} elsif ($pattern =~ /^\*/) { |
#*.msu.edu |
#*.msu.edu |
Line 5098 sub check_ip_acc {
|
Line 5133 sub check_ip_acc {
|
my $netaddr=inet_aton($ip); |
my $netaddr=inet_aton($ip); |
($name)=gethostbyaddr($netaddr,AF_INET); |
($name)=gethostbyaddr($netaddr,AF_INET); |
} |
} |
if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; } |
if ($name =~ /\Q$pattern\E$/i) { $allowed=1; } |
} elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) { |
} elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) { |
#127.0.0.1 |
#127.0.0.1 |
if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; } |
if ($ip =~ /^\Q$pattern\E/) { $allowed=1; } |
} else { |
} else { |
#some.name.com |
#some.name.com |
if (!defined($name)) { |
if (!defined($name)) { |
Line 5109 sub check_ip_acc {
|
Line 5144 sub check_ip_acc {
|
my $netaddr=inet_aton($ip); |
my $netaddr=inet_aton($ip); |
($name)=gethostbyaddr($netaddr,AF_INET); |
($name)=gethostbyaddr($netaddr,AF_INET); |
} |
} |
if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; } |
if ($name =~ /\Q$pattern\E$/i) { $allowed=1; } |
} |
|
if ($allowed =~ /^(0|1)$/) { last; } |
|
} |
|
if ($allowed eq '') { |
|
if ($numdenies && !$numallows) { |
|
$allowed = 1; |
|
} else { |
|
$allowed = 0; |
|
} |
} |
|
if ($allowed) { last; } |
} |
} |
return $allowed; |
return $allowed; |
} |
} |
Line 15089 sub check_clone {
|
Line 15117 sub check_clone {
|
my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'}; |
my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'}; |
my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid); |
my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid); |
my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom); |
my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom); |
my $clonetitle; |
my $clonemsg; |
my @clonemsg; |
|
my $can_clone = 0; |
my $can_clone = 0; |
my $lctype = lc($args->{'crstype'}); |
my $lctype = lc($args->{'crstype'}); |
if ($lctype ne 'community') { |
if ($lctype ne 'community') { |
Line 15098 sub check_clone {
|
Line 15125 sub check_clone {
|
} |
} |
if ($clonehome eq 'no_host') { |
if ($clonehome eq 'no_host') { |
if ($args->{'crstype'} eq 'Community') { |
if ($args->{'crstype'} eq 'Community') { |
push(@clonemsg,({ |
$clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'}); |
mt => 'No new community created.', |
|
args => [], |
|
}, |
|
{ |
|
mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.', |
|
args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}], |
|
})); |
|
} else { |
} else { |
push(@clonemsg,({ |
$clonemsg = &mt('No new course created.').$linefeed.&mt('A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',$args->{'clonecourse'}.':'.$args->{'clonedomain'}); |
mt => 'No new course created.', |
} |
args => [], |
|
}, |
|
{ |
|
mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.', |
|
args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}], |
|
})); |
|
} |
|
} else { |
} else { |
my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1}); |
my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1}); |
$clonetitle = $clonedesc{'description'}; |
|
if ($args->{'crstype'} eq 'Community') { |
if ($args->{'crstype'} eq 'Community') { |
if ($clonedesc{'type'} ne 'Community') { |
if ($clonedesc{'type'} ne 'Community') { |
push(@clonemsg,({ |
$clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'}); |
mt => 'No new community created.', |
return ($can_clone, $clonemsg, $cloneid, $clonehome); |
args => [], |
|
}, |
|
{ |
|
mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.', |
|
args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}], |
|
})); |
|
return ($can_clone,\@clonemsg,$cloneid,$clonehome); |
|
} |
} |
} |
} |
if (($env{'request.role.domain'} eq $args->{'clonedomain'}) && |
if (($env{'request.role.domain'} eq $args->{'clonedomain'}) && |
Line 15218 sub check_clone {
|
Line 15223 sub check_clone {
|
} |
} |
unless ($can_clone) { |
unless ($can_clone) { |
if ($args->{'crstype'} eq 'Community') { |
if ($args->{'crstype'} eq 'Community') { |
push(@clonemsg,({ |
$clonemsg = &mt('No new community created.').$linefeed.&mt('The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}); |
mt => 'No new community created.', |
|
args => [], |
|
}, |
|
{ |
|
mt => 'The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).', |
|
args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}], |
|
})); |
|
} else { |
} else { |
push(@clonemsg,({ |
$clonemsg = &mt('No new course created.').$linefeed.&mt('The new course could not be cloned from the existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}); |
mt => 'No new course created.', |
} |
args => [], |
|
}, |
|
{ |
|
mt => 'The new course could not be cloned from the existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).', |
|
args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}], |
|
})); |
|
} |
|
} |
} |
} |
} |
} |
} |
return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle); |
return ($can_clone, $clonemsg, $cloneid, $clonehome); |
} |
} |
|
|
sub construct_course { |
sub construct_course { |
my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context, |
my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context, |
$cnum,$category,$coderef,$callercontext,$user_lh) = @_; |
$cnum,$category,$coderef) = @_; |
my ($outcome,$msgref,$clonemsgref); |
my $outcome; |
my $linefeed = '<br />'."\n"; |
my $linefeed = '<br />'."\n"; |
if ($context eq 'auto') { |
if ($context eq 'auto') { |
$linefeed = "\n"; |
$linefeed = "\n"; |
Line 15254 sub construct_course {
|
Line 15245 sub construct_course {
|
# |
# |
# Are we cloning? |
# Are we cloning? |
# |
# |
my ($can_clone,$cloneid,$clonehome,$clonetitle); |
my ($can_clone, $clonemsg, $cloneid, $clonehome); |
if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) { |
if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) { |
($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed); |
($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed); |
|
if ($context ne 'auto') { |
|
if ($clonemsg ne '') { |
|
$clonemsg = '<span class="LC_error">'.$clonemsg.'</span>'; |
|
} |
|
} |
|
$outcome .= $clonemsg.$linefeed; |
|
|
if (!$can_clone) { |
if (!$can_clone) { |
return (0,$outcome,$clonemsgref); |
return (0,$outcome); |
} |
} |
} |
} |
|
|
Line 15276 sub construct_course {
|
Line 15274 sub construct_course {
|
$args->{'ccuname'}.':'. |
$args->{'ccuname'}.':'. |
$args->{'ccdomain'}, |
$args->{'ccdomain'}, |
$args->{'crstype'}, |
$args->{'crstype'}, |
$cnum,$context,$category, |
$cnum,$context,$category); |
$callercontext); |
|
|
|
# Note: The testing routines depend on this being output; see |
# Note: The testing routines depend on this being output; see |
# Utils::Course. This needs to at least be output as a comment |
# Utils::Course. This needs to at least be output as a comment |
# if anyone ever decides to not show this, and Utils::Course::new |
# if anyone ever decides to not show this, and Utils::Course::new |
# will need to be suitably modified. |
# will need to be suitably modified. |
if (($callercontext eq 'auto') && ($user_lh ne '')) { |
$outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed; |
$outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed; |
|
} else { |
|
$outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed; |
|
} |
|
if ($$courseid =~ /^error:/) { |
if ($$courseid =~ /^error:/) { |
return (0,$outcome,$clonemsgref); |
return (0,$outcome); |
} |
} |
|
|
# |
# |
Line 15298 sub construct_course {
|
Line 15291 sub construct_course {
|
($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid); |
($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid); |
my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom); |
my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom); |
if ($crsuhome eq 'no_host') { |
if ($crsuhome eq 'no_host') { |
if (($callercontext eq 'auto') && ($user_lh ne '')) { |
$outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed; |
$outcome .= &mt_user($user_lh, |
return (0,$outcome); |
'Course creation failed, unrecognized course home server.'); |
|
} else { |
|
$outcome .= &mt('Course creation failed, unrecognized course home server.'); |
|
} |
|
$outcome .= $linefeed; |
|
return (0,$outcome,$clonemsgref); |
|
} |
} |
$outcome .= &mt('Created on').': '.$crsuhome.$linefeed; |
$outcome .= &mt('Created on').': '.$crsuhome.$linefeed; |
|
|
# |
# |
# Do the cloning |
# Do the cloning |
# |
# |
my @clonemsg; |
|
if ($can_clone && $cloneid) { |
if ($can_clone && $cloneid) { |
push(@clonemsg, |
$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome); |
{ |
if ($context ne 'auto') { |
mt => 'Created [_1] by cloning from [_2]', |
$clonemsg = '<span class="LC_success">'.$clonemsg.'</span>'; |
args => [$crstype,$clonetitle], |
} |
}); |
$outcome .= $clonemsg.$linefeed; |
my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum); |
my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum); |
# Copy all files |
# Copy all files |
my @info = |
&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'}); |
&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'}, |
|
$args->{'dateshift'},$args->{'crscode'}, |
|
$args->{'ccuname'}.':'.$args->{'ccdomain'}, |
|
$args->{'tinyurls'}); |
|
if (@info) { |
|
push(@clonemsg,@info); |
|
} |
|
# Restore URL |
# Restore URL |
$cenv{'url'}=$oldcenv{'url'}; |
$cenv{'url'}=$oldcenv{'url'}; |
# Restore title |
# Restore title |
Line 15635 sub construct_course {
|
Line 15614 sub construct_course {
|
$outcome .= ($fatal?$errtext:'write ok').$linefeed; |
$outcome .= ($fatal?$errtext:'write ok').$linefeed; |
} |
} |
|
|
return (1,$outcome,\@clonemsg); |
return (1,$outcome); |
} |
} |
|
|
sub make_unique_code { |
sub make_unique_code { |
Line 16784 sub needs_coursereinit {
|
Line 16763 sub needs_coursereinit {
|
$interval = 600; |
$interval = 600; |
} |
} |
if (($now-$env{'request.course.timechecked'})>$interval) { |
if (($now-$env{'request.course.timechecked'})>$interval) { |
&Apache::lonnet::appenv({'request.course.timechecked'=>$now}); |
|
my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1); |
|
if ($blocked) { |
|
return (); |
|
} |
|
my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum); |
my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum); |
|
&Apache::lonnet::appenv({'request.course.timechecked'=>$now}); |
if ($lastchange > $env{'request.course.tied'}) { |
if ($lastchange > $env{'request.course.tied'}) { |
my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired'); |
my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired'); |
if ($curr_reqd_hash{'internal.releaserequired'} ne '') { |
if ($curr_reqd_hash{'internal.releaserequired'} ne '') { |
Line 17245 sub cleanup_html {
|
Line 17220 sub cleanup_html {
|
|
|
# Checks for critical messages and returns a redirect url if one exists. |
# Checks for critical messages and returns a redirect url if one exists. |
# $interval indicates how often to check for messages. |
# $interval indicates how often to check for messages. |
# $context is the calling context -- roles, grades, contents, menu or flip. |
|
sub critical_redirect { |
sub critical_redirect { |
my ($interval,$context) = @_; |
my ($interval) = @_; |
if ((time-$env{'user.criticalcheck.time'})>$interval) { |
if ((time-$env{'user.criticalcheck.time'})>$interval) { |
if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) { |
|
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; |
|
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; |
|
my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1); |
|
if ($blocked) { |
|
my $checkrole = "cm./$cdom/$cnum"; |
|
if ($env{'request.course.sec'} ne '') { |
|
$checkrole .= "/$env{'request.course.sec'}"; |
|
} |
|
unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) && |
|
($env{'request.role'} !~ m{^st\./$cdom/$cnum})) { |
|
return; |
|
} |
|
} |
|
} |
|
my @what=&Apache::lonnet::dump('critical', $env{'user.domain'}, |
my @what=&Apache::lonnet::dump('critical', $env{'user.domain'}, |
$env{'user.name'}); |
$env{'user.name'}); |
&Apache::lonnet::appenv({'user.criticalcheck.time'=>time}); |
&Apache::lonnet::appenv({'user.criticalcheck.time'=>time}); |
Line 17329 sub des_decrypt {
|
Line 17288 sub des_decrypt {
|
return $plaintext; |
return $plaintext; |
} |
} |
|
|
sub get_requested_shorturls { |
|
my ($cdom,$cnum,$navmap) = @_; |
|
return unless (ref($navmap)); |
|
my ($numnew,$errors); |
|
my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny'); |
|
if (@toshorten) { |
|
my (%maps,%resources,%titles); |
|
&Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles, |
|
'shorturls',$cdom,$cnum); |
|
if (keys(%resources)) { |
|
my %tocreate; |
|
foreach my $item (sort {$a <=> $b} (@toshorten)) { |
|
my $symb = $resources{$item}; |
|
if ($symb) { |
|
$tocreate{$cnum.'&'.$symb} = 1; |
|
} |
|
} |
|
if (keys(%tocreate)) { |
|
($numnew,$errors) = &make_short_symbs($cdom,$cnum, |
|
\%tocreate); |
|
} |
|
} |
|
} |
|
return ($numnew,$errors); |
|
} |
|
|
|
sub make_short_symbs { |
|
my ($cdom,$cnum,$tocreateref,$lockuser) = @_; |
|
my ($numnew,@errors); |
|
if (ref($tocreateref) eq 'HASH') { |
|
my %tocreate = %{$tocreateref}; |
|
if (keys(%tocreate)) { |
|
my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum); |
|
my $su = Short::URL->new(no_vowels => 1); |
|
my $init = ''; |
|
my (%newunique,%addcourse,%courseonly,%failed); |
|
# get lock on tiny db |
|
my $now = time; |
|
if ($lockuser eq '') { |
|
$lockuser = $env{'user.name'}.':'.$env{'user.domain'}; |
|
} |
|
my $lockhash = { |
|
"lock\0$now" => $lockuser, |
|
}; |
|
my $tries = 0; |
|
my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom); |
|
my ($code,$error); |
|
while (($gotlock ne 'ok') && ($tries<3)) { |
|
$tries ++; |
|
sleep 1; |
|
$gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom); |
|
} |
|
if ($gotlock eq 'ok') { |
|
$init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique, |
|
\%addcourse,\%courseonly,\%failed); |
|
if (keys(%failed)) { |
|
my $numfailed = scalar(keys(%failed)); |
|
push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed)); |
|
} |
|
if (keys(%newunique)) { |
|
my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom); |
|
if ($putres eq 'ok') { |
|
$numnew = scalar(keys(%newunique)); |
|
my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum); |
|
unless ($newputres eq 'ok') { |
|
push(@errors,&mt('error: could not store course look-up of short URLs')); |
|
} |
|
} else { |
|
push(@errors,&mt('error: could not store unique six character URLs')); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
return ($numnew,\@errors); |
|
} |
|
|
|
sub shorten_symbs { |
|
my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_; |
|
return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') && |
|
(ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') && |
|
(ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH')); |
|
my (%possibles,%collisions); |
|
foreach my $key (keys(%{$tocreate})) { |
|
my $num = String::CRC32::crc32($key); |
|
my $tiny = $su->encode($num,$init); |
|
if ($tiny) { |
|
$possibles{$tiny} = $key; |
|
} |
|
} |
|
if (!$init) { |
|
$init = 1; |
|
} else { |
|
$init ++; |
|
} |
|
if (keys(%possibles)) { |
|
my @posstiny = keys(%possibles); |
|
my $configuname = &Apache::lonnet::get_domainconfiguser($cdom); |
|
my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname); |
|
if (keys(%currtiny)) { |
|
foreach my $key (keys(%currtiny)) { |
|
next if ($currtiny{$key} eq ''); |
|
if ($currtiny{$key} eq $possibles{$key}) { |
|
my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key}); |
|
unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) { |
|
$courseonly->{$tsymb} = $key; |
|
} |
|
} else { |
|
$collisions{$possibles{$key}} = 1; |
|
} |
|
delete($possibles{$key}); |
|
} |
|
} |
|
foreach my $key (keys(%possibles)) { |
|
$newunique->{$key} = $possibles{$key}; |
|
my ($tcnum,$tsymb) = split(/\&/,$possibles{$key}); |
|
unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) { |
|
$addcourse->{$tsymb} = $key; |
|
} |
|
} |
|
} |
|
if (keys(%collisions)) { |
|
if ($init <5) { |
|
if (!$init) { |
|
$init = 1; |
|
} else { |
|
$init ++; |
|
} |
|
$init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions, |
|
$newunique,$addcourse,$courseonly,$failed); |
|
} else { |
|
foreach my $key (keys(%collisions)) { |
|
$failed->{$key} = 1; |
|
$failed->{$key} = 1; |
|
} |
|
} |
|
} |
|
return $init; |
|
} |
|
|
|
sub is_nonframeable { |
sub is_nonframeable { |
my ($url,$absolute,$hostname,$ip,$nocache) = @_; |
my ($url,$absolute,$hostname,$ip,$nocache) = @_; |
my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i); |
my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i); |