--- loncom/homework/daxeopen.pm 2017/02/24 17:34:55 1.6 +++ loncom/homework/daxeopen.pm 2023/08/23 20:33:06 1.7 @@ -1,7 +1,7 @@ # The LearningOnline Network # Opening converted problems and directory listings for Daxe # -# $Id: daxeopen.pm,v 1.6 2017/02/24 17:34:55 damieng Exp $ +# $Id: daxeopen.pm,v 1.7 2023/08/23 20:33:06 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -46,11 +46,11 @@ use Apache::post_xml; sub handler { my $request = shift; my $uri = $request->uri; - $uri =~ s/^\/daxeopen//; + $uri =~ s{^/daxeopen}{}; &Apache::loncommon::no_cache($request); - if ($uri =~ /\/$/) { + if ($uri =~ m{/$}) { return directory_listing($uri, $request); - } elsif ($uri =~ /^\/priv\/.*\.(task|problem|exam|quiz|assess|survey|library|xml|html|htm|xhtml|xhtm)$/) { + } elsif ($uri =~ m{^/priv/.*\.(task|problem|exam|quiz|assess|survey|library|xml|html|htm|xhtml|xhtm)$}) { return convert_problem($uri, $request); } else { # Apache should send other files directly @@ -62,7 +62,7 @@ sub handler { sub convert_problem { my ($uri, $request) = @_; - if ($uri =~ /^\/priv\/([^\/]+)\/([^\/]+)\//) { + if ($uri =~ m{^/priv/([^/]+)/([^/]+)/}) { my ($domain, $user) = ($1, $2); my ($uname, $udom) = ($env{'user.name'}, $env{'user.domain'}); if (!defined $uname || !defined $udom || $domain ne $udom || $user ne $uname) { @@ -113,7 +113,7 @@ sub directory_listing { $request->print("Not found: $uri"); $request->status(404); return OK; - } elsif ($uri =~ /^\/res\//) { + } elsif ($uri =~ m{^/res/}) { # NOTE: dirlist does not return an error for /res/idontexist/ (my $listref, $listerror) = &Apache::lonnet::dirlist($uri); if ($listerror) { @@ -121,21 +121,21 @@ sub directory_listing { $request->print("listing error: $listerror"); $request->status(406); return OK; - } elsif ($uri =~ /^\/res\/[^\/]+\/$/ && scalar(@{$listref}) == 0) { + } elsif ($uri =~ m{^/res/[^/]+/$} && scalar(@{$listref}) == 0) { $request->content_type('text/plain'); $request->print("Not found: $uri"); $request->status(404); return OK; } my $dirname = $uri; - $dirname =~ s/^.*\/([^\/]*)$/$1/; + $dirname =~ s{^.*/([^/]*)$}{$1}; $res .= "\n"; if (ref($listref) eq 'ARRAY') { my @lines = @{$listref}; foreach my $line (@lines) { my ($path, $dom, undef, $testdir, undef, undef, undef, undef, $size, undef, $mtime, undef, undef, undef, $obs, undef) = split(/\&/, $line, 16); my $isdir = ($testdir & 16384) || $dom =~ /^(user|domain)$/; - $path =~ s/^\/home\/httpd\/html\/res\///; + $path =~ s{^/home/httpd/html/res/}{}; next if $path eq '.' || $path eq '..'; next if $path =~ /\.meta$/ || $obs || $path =~ /\.\d+\.[^.]+$/; if ($dom ne 'domain') { @@ -151,7 +151,7 @@ sub directory_listing { next if (&Apache::lonnet::is_course($udom, $uname)); } } - $path =~ s/\/$//; + $path =~ s{/$}{}; my $name = $path; if ($isdir) { $res .= "\n"; @@ -172,7 +172,7 @@ sub directory_listing { } $res .= "\n"; $res .= "\n"; - } elsif ($uri =~ /^\/priv\/([^\/]+)\/$/) { + } elsif ($uri =~ m{^/priv/([^/]+)/$}) { my $domain = $1; my ($uname, $udom) = ($env{'user.name'}, $env{'user.domain'}); if (!defined $uname || !defined $udom || $domain ne $udom) { @@ -183,7 +183,7 @@ sub directory_listing { } $res .= "\n"; $res .= "\n"; - } elsif ($uri =~ /^\/priv\/([^\/]+)\/([^\/]+)\//) { + } elsif ($uri =~ m{^/priv/([^/]+)/([^/]+)/}) { my ($domain, $user) = ($1, $2); my ($uname, $udom) = ($env{'user.name'}, $env{'user.domain'}); if (!defined $uname || !defined $udom || $domain ne $udom || $user ne $uname) { @@ -199,12 +199,12 @@ sub directory_listing { $request->status(404); return OK; } - $dirpath =~ s/\/$//; + $dirpath =~ s{/$}{}; opendir my $dir, $dirpath or die "Cannot open directory: $dirpath"; my @files = readdir $dir; closedir $dir; my $dirname = $dirpath; - $dirname =~ s/^.*\/([^\/]*)$/$1/; + $dirname =~ s{^.*/([^/]*)$}{$1}; $res .= "\n"; foreach my $name (@files) { if ($name eq '.' || $name eq '..') {