--- loncom/homework/lonhomework.pm 2003/09/21 21:40:06 1.151 +++ loncom/homework/lonhomework.pm 2004/02/13 21:21:30 1.163 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Homework handler # -# $Id: lonhomework.pm,v 1.151 2003/09/21 21:40:06 www Exp $ +# $Id: lonhomework.pm,v 1.163 2004/02/13 21:21:30 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -24,11 +24,7 @@ # /home/httpd/html/adm/gpl.txt # # http://www.lon-capa.org/ -# -# Guy Albertelli -# 11/30 Gerd Kortemeyer -# 6/1,8/17,8/18 Gerd Kortemeyer -# 7/18 Jeremy Bowers + package Apache::lonhomework; use strict; @@ -147,6 +143,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 { @@ -163,53 +204,63 @@ sub check_access { &Apache::lonxml::debug("in construction ignoring dates"); $status='CAN_ANSWER'; $datemsg=&mt('is in under construction'); - return ($status,$datemsg); +# return ($status,$datemsg); } &Apache::lonxml::debug("checking for part :$id:"); &Apache::lonxml::debug("time:".time); - foreach $temp ("opendate","duedate","answerdate") { - $lastdate = $date; - $date = &Apache::lonnet::EXT("resource.$id.$temp"); - my $thistype = &Apache::lonnet::EXT("resource.$id.$temp.type"); - if ($thistype =~ /^(con_lost|no_such_host)/ || - $date =~ /^(con_lost|no_such_host)/) { - $status='UNAVAILABLE'; - $date=&mt("may open later."); + + if ($ENV{'request.state'} ne "construct") { + my $allowed=&check_ip_acc(&Apache::lonnet::EXT("resource.$id.acc")); + if (!$allowed && ($Apache::lonhomework::browse ne 'F')) { + $status='INVALID_ACCESS'; + $date=&mt("can not be accessed from your location."); return($status,$date); } - if ($thistype eq 'date_interval') { - if ($temp eq 'opendate') { - $date=&Apache::lonnet::EXT("resource.$id.duedate")-$date; - } - if ($temp eq 'answerdate') { - $date=&Apache::lonnet::EXT("resource.$id.duedate")+$date; + + foreach $temp ("opendate","duedate","answerdate") { + $lastdate = $date; + $date = &Apache::lonnet::EXT("resource.$id.$temp"); + my $thistype = &Apache::lonnet::EXT("resource.$id.$temp.type"); + if ($thistype =~ /^(con_lost|no_such_host)/ || + $date =~ /^(con_lost|no_such_host)/) { + $status='UNAVAILABLE'; + $date=&mt("may open later."); + return($status,$date); } + if ($thistype eq 'date_interval') { + if ($temp eq 'opendate') { + $date=&Apache::lonnet::EXT("resource.$id.duedate")-$date; + } + if ($temp eq 'answerdate') { + $date=&Apache::lonnet::EXT("resource.$id.duedate")+$date; + } + } + &Apache::lonxml::debug("found :$date: for :$temp:"); + if ($date eq '') { + $date = &mt("an unknown date"); $passed = 0; + } elsif ($date eq 'con_lost') { + $date = &mt("an indeterminate date"); $passed = 0; + } else { + if (time < $date) { $passed = 0; } else { $passed = 1; } + $date = localtime $date; + } + if (!$passed) { $type=$temp; last; } } - &Apache::lonxml::debug("found :$date: for :$temp:"); - if ($date eq '') { - $date = &mt("an unknown date"); $passed = 0; - } elsif ($date eq 'con_lost') { - $date = &mt("an indeterminate date"); $passed = 0; - } else { - if (time < $date) { $passed = 0; } else { $passed = 1; } - $date = localtime $date; + &Apache::lonxml::debug("have :$type:$passed:"); + if ($passed) { + $status='SHOW_ANSWER'; + $datemsg=$date; + } elsif ($type eq 'opendate') { + $status='CLOSED'; + $datemsg = &mt("will open on")." $date"; + } elsif ($type eq 'duedate') { + $status='CAN_ANSWER'; + $datemsg = &mt("is due at")." $date"; + } elsif ($type eq 'answerdate') { + $status='CLOSED'; + $datemsg = &mt("was due on")." $lastdate".&mt(", and answers will be available on")." $date"; } - if (!$passed) { $type=$temp; last; } - } - &Apache::lonxml::debug("have :$type:$passed:"); - if ($passed) { - $status='SHOW_ANSWER'; - $datemsg=$date; - } elsif ($type eq 'opendate') { - $status='CLOSED'; - $datemsg = &mt("will open on")." $date"; - } elsif ($type eq 'duedate') { - $status='CAN_ANSWER'; - $datemsg = &mt("is due at")." $date"; - } elsif ($type eq 'answerdate') { - $status='CLOSED'; - $datemsg = &mt("was due on")." $lastdate".&mt(", and answers will be available on")." $date"; } if ($status eq 'CAN_ANSWER') { #check #tries, and if correct. @@ -326,6 +377,8 @@ sub handle_save_or_undo { my $filetmp =$file.".tmp"; my $error=0; + &Apache::lonnet::correct_line_ends($result); + if ($ENV{'form.Undo'} eq &mt('undo')) { my $error=0; if (!copy($file,$filetmp)) { $error=1; } @@ -439,12 +492,12 @@ sub analyze { } $request->print(''); } else { - $request->print('

'.&mt('Part').' '.$part.' '. + $request->print('

'.&mt('Response').' '.$part.' '. &mt('is not analyzable at this time').'

'); } } if (scalar(keys(%allparts)) == 0 ) { - $request->print('

'.&mt('Found no analyzable parts in this problem, currently only Numerical, Formula and String response styles are supported.').'

'); + $request->print('

'.&mt('Found no analyzable respones in this problem, currently only Numerical, Formula and String response styles are supported.').'

'); } &Apache::lonhtmlcommon::Close_PrgWin($request,\%prog_state); &analyze_footer($request); @@ -473,8 +526,12 @@ sub editxmlmode { &renderpage($request,$file); } else { my ($rows,$cols) = &Apache::edit::textarea_sizes(\$problem); - my $xml_help = Apache::loncommon::helpLatexCheatsheet("Problem_Editor_XML_Index", - "Problem Editing Help"); + my $xml_help = '
'. + &Apache::loncommon::helpLatexCheatsheet("Problem_Editor_XML_Index", + "Problem Editing Help"). + ''. + &Apache::loncommon::help_open_faq(5). + &Apache::loncommon::help_open_bug('Authoring').'
'; if ($cols > 80) { $cols = 80; } if ($cols < 70) { $cols = 70; } if ($rows < 20) { $rows = 20; } @@ -502,6 +559,7 @@ sub renderpage { my ($request,$file) = @_; my (@targets) = &get_target(); + &Apache::lonhomework::showhashsubset(\%ENV,'form.'); &Apache::lonxml::debug("Running targets ".join(':',@targets)); foreach my $target (@targets) { #my $t0 = [&gettimeofday()]; @@ -589,12 +647,15 @@ sub newproblem { &renderpage($request,$dest); } else { my $url=$request->uri; + my $shownurl=$url; + $shownurl=~s-^/~-/priv/-; my $dest = &Apache::lonnet::filelocation("",$request->uri); my $errormsg; if ($ENV{'form.newfile'}) { $errormsg='

'.&mt('You did not select a template.').'

'."\n"; } my $instructions; + my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1); if ($templatelist) { $instructions=&mt(", select a template from the pull-down menu below.").'
'.&mt("Then");} my %lt=&Apache::lonlocal::texthash( 'create' => 'Creating a new', 'resource' => 'resource', @@ -605,10 +666,10 @@ sub newproblem { 'Create' => 'Create', 'button' => 'button'); $request->print(< +$bodytag

$lt{'create'} $extension $lt{'resource'}

$errormsg -$lt{'requested'} $url $lt{'not exist'}. +$lt{'requested'} $shownurl $lt{'not exist'}.

$lt{'createnew'} $extension$instructions $lt{'click'} "$lt{'Create'} $extension" $lt{'button'}.

@@ -647,7 +708,6 @@ sub handler { my $request=$_[0]; $Apache::lonxml::debug=$ENV{'user.debug'}; - if (&setupheader($request)) { return OK; } $ENV{'request.uri'}=$request->uri;