#!/usr/bin/perl
# CGI-script to run LaTeX, dvips, ps2ps, ps2pdf etc.
#
# $Id: printout.pl,v 1.137 2008/08/27 01:38:10 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
use lib '/home/httpd/lib/perl';
use LONCAPA::loncgi;
use File::Path;
use File::Basename;
use File::Copy;
use IO::File;
use Image::Magick;
use Apache::lonhtmlcommon();
use Apache::lonnet;
use Apache::loncommon();
use Apache::lonlocal;
use Apache::lonmsg();
use LONCAPA::Enrollment;
use LONCAPA::Configuration;
use strict;
my $busy_wait_timeout = 30;
sub debug {
my ($text) = @_;
print "$text
\n";
}
# Determine if a user is operating as a student for this course/domain.
#Parameters:
# none
#Implicit:
# $env{request.role} contains the role under which this user operated this
# this request.
sub is_student {
return ($env{'request.role'}=~/^st\./);
}
#
# Debugging: Dump the environment for debugging.
#
sub dumpenv {
print "
-------------------
";
foreach my $key (sort (keys %env)) {
print "
$key -> $env{$key}";
}
print "
-------------------
";
}
#
# This sub sends a message to the appropriate person if there was an error
# rendering the latex At present, there's only one case to consider:
# a student printing inside a course results in messages to the course coordinator.
#Parmaeters:
# identifier - The unique identifier of this cgi request.
# badresource- Filepath to most likely failing
# logfile - The contents of the log file (included in the message).
# texfile - reference to an array containing the LaTeX input file
# (included in the message).
#Implicit inputs:
# From the environment:
# cgi.$identifier.user - User doing the printing.
# cgi.$identifier.domain - Domain the user is logged in on with printing.
# cgi.$identifier.courseid - Id of the course (if this is a course).
# cgi.$identifier.coursedom- Domain in which course was constituted.
# cgi.$identifier.resources - List of resource URL's for which the print
# was attempted.
#
sub send_error_mail {
my ($identifier, $badresource, $logfile, $texfile) = @_;
my $user = $env{"cgi.$identifier.user"};
my $domain = $env{"cgi.$identifier.domain"};
my $courseid = $env{"cgi.$identifier.courseid"};
my $coursedom= $env{"cgi.$identifier.coursedom"};
my $resources= $env{"cgi.$identifier.resources"};
# resource file->URL
#
my $badurl = &Apache::lonnet::declutter($badresource);
# &dumpenv();
# Only continue if there is a user, domain, courseid, course domain
# and resources:
if(defined($user) && defined($domain) && defined($courseid) &&
defined($coursedom) && defined($resources) ){
# Only mail if the conditions are ripe for it:
# The user is a student in the course:
#
if (&is_student()) {
# build the subject and message body:
# print "sending message to course coordinators.
";
# Todo: Convert badurl into a url from file path:
my $subject = "Error [$badurl] Print failed for $user".'@'.$domain;
my $message .= "Print failed to render LaTeX for $user".'@'."$domain\n";
$message .= " User was attempting to print: \n";
foreach my $resource (split(/:/,$resources)) {
$message .= " $resource\n";
}
$message .= "--------------------LaTeX logfile:------------ \n";
$message .= $logfile;
$message .= "-----------------LaTeX source file: ------------\n";
foreach my $line (@$texfile) {
$message .= "$line\n";
}
my (undef, %receivers) = &Apache::lonmsg::decide_receiver(undef, 0,
1,1,1);
# print "
sending...section: $env{'request.course.sec'}";
foreach my $dest (keys %receivers) {
# print "
dest is $dest";
my @destinfo = split(/:/,$dest);
my $user = $destinfo[0];
my $dom = $destinfo[1];
&Apache::lonmsg::user_normal_msg($user, $dom,
$subject, $message);
# No point in looking at the return status as there's no good
# error action I can think of right now (log maybe?).
}
}
}
}
$|=1;
if (! &LONCAPA::loncgi::check_cookie_and_load_env()) {
print <
Bad Cookie
Your cookie information is incorrect.