--- loncom/homework/lonhomework.pm 2003/06/16 21:32:43 1.135 +++ loncom/homework/lonhomework.pm 2003/10/15 22:18:26 1.138.2.1 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Homework handler # -# $Id: lonhomework.pm,v 1.135 2003/06/16 21:32:43 www Exp $ +# $Id: lonhomework.pm,v 1.138.2.1 2003/10/15 22:18:26 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -50,7 +50,7 @@ use Apache::essayresponse(); use Apache::externalresponse(); use Apache::rankresponse(); use Apache::matchresponse(); -#use Apache::chemresponse(); +use Apache::chemresponse(); use Apache::Constants qw(:common); use HTML::Entities(); use Apache::loncommon(); @@ -72,7 +72,8 @@ sub get_target { } if ( defined($ENV{'form.submitted'}) && - ( !defined($ENV{'form.resetdata'}))) { + ( !defined($ENV{'form.resetdata'})) && + ( !defined($ENV{'form.newrandomization'}))) { return ('grade', 'web'); } else { return ('web'); @@ -91,7 +92,8 @@ sub get_target { if ( $ENV{'form.problemmode'} eq 'View' || $ENV{'form.problemmode'} eq 'Discard Edits and View') { if ( defined($ENV{'form.submitted'}) && - (!defined($ENV{'form.resetdata'})) ) { + (!defined($ENV{'form.resetdata'})) && + (!defined($ENV{'form.newrandomization'}))) { return ('grade', 'web','answer'); } else { return ('web','answer'); @@ -144,6 +146,51 @@ sub send_footer { $Apache::lonxml::browse=''; +sub check_ip_acc { + my ($acc)=@_; + if (!defined($acc) || $acc =~ /^\s*$/) { return 1; } + my $allowed=0; + my $ip=$ENV{'REMOTE_ADDR'}; + my $name; + foreach my $pattern (split(',',$acc)) { + if ($pattern =~ /\*$/) { + #35.8.* + $pattern=~s/\*//; + if ($ip =~ /^\Q$pattern\E/) { $allowed=1; } + } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) { + #35.8.3.[34-56] + my $low=$2; + my $high=$3; + $pattern=$1; + if ($ip =~ /^\Q$pattern\E/) { + my $last=(split(/\./,$ip))[3]; + if ($last <=$high && $last >=$low) { $allowed=1; } + } + } elsif ($pattern =~ /^\*/) { + #*.msu.edu + $pattern=~s/\*//; + if (!defined($name)) { + use Socket; + my $netaddr=inet_aton($ip); + ($name)=gethostbyaddr($netaddr,AF_INET); + } + if ($name =~ /\Q$pattern\E$/i) { $allowed=1; } + } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) { + #127.0.0.1 + if ($ip =~ /^\Q$pattern\E/) { $allowed=1; } + } else { + #some.name.com + if (!defined($name)) { + use Socket; + my $netaddr=inet_aton($ip); + ($name)=gethostbyaddr($netaddr,AF_INET); + } + if ($name =~ /\Q$pattern\E$/i) { $allowed=1; } + } + if ($allowed) { last; } + } + return $allowed; +} # JB, 9/24/2002: Any changes in this function may require a change # in lonnavmaps::resource::getDateStatus. sub check_access { @@ -165,6 +212,14 @@ sub check_access { &Apache::lonxml::debug("checking for part :$id:"); &Apache::lonxml::debug("time:".time); + + my $allowed=&check_ip_acc(&Apache::lonnet::EXT("resource.$id.acc")); + if (!$allowed) { + $status='INVALID_ACCESS'; + $date=&mt("can not be accessed from your location."); + return($status,$date); + } + foreach $temp ("opendate","duedate","answerdate") { $lastdate = $date; $date = &Apache::lonnet::EXT("resource.$id.$temp"); @@ -469,15 +524,8 @@ sub editxmlmode { &renderpage($request,$file); } else { my ($rows,$cols) = &Apache::edit::textarea_sizes(\$problem); - my $xml_help = '
'. - &Apache::loncommon::help_open_topic("Problem_Editor_XML_Index",'Problem Editing Help') - .''. - &Apache::loncommon::help_open_topic("Greek_Symbols",'Greek Symbols', - undef,undef,600) - .''. - &Apache::loncommon::help_open_topic("Other_Symbols",'Other Symbols', - undef,undef,600) - .'
'; + my $xml_help = Apache::loncommon::helpLatexCheatsheet("Problem_Editor_XML_Index", + "Problem Editing Help"); if ($cols > 80) { $cols = 80; } if ($cols < 70) { $cols = 70; } if ($rows < 20) { $rows = 20; } @@ -670,9 +718,11 @@ sub handler { &Apache::lonxml::debug('symb is '.$symb); if ($ENV{'request.state'} eq "construct" || $symb eq '') { if ($ENV{'form.resetdata'} eq 'Reset Submissions' || - $ENV{'form.resetdata'} eq 'New Problem Variation' ) { + $ENV{'form.resetdata'} eq 'New Problem Variation' || + $ENV{'form.newrandomization'} eq 'New Randomization') { my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser(); &Apache::lonnet::tmpreset($symb,'',$domain,$name); +&Apache::lonxml::debug("Attempt reset"); } } if ($ENV{'request.state'} eq "construct") {