--- loncom/homework/lonhomework.pm 2003/09/21 21:40:06 1.151 +++ loncom/homework/lonhomework.pm 2003/12/22 22:15:27 1.159 @@ -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.159 2003/12/22 22:15:27 www 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 { @@ -168,6 +209,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"); @@ -326,6 +375,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; } @@ -589,12 +640,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 +659,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'}.