--- loncom/interface/lonsupportreq.pm 2013/01/04 19:07:17 1.67.2.1 +++ loncom/interface/lonsupportreq.pm 2016/02/19 02:39:07 1.82 @@ -1,5 +1,5 @@ # -# $Id: lonsupportreq.pm,v 1.67.2.1 2013/01/04 19:07:17 raeburn Exp $ +# $Id: lonsupportreq.pm,v 1.82 2016/02/19 02:39:07 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -27,8 +27,6 @@ package Apache::lonsupportreq; use strict; -use MIME::Types; -use MIME::Lite; use CGI::Cookie(); use Apache::Constants qw(:common); use Apache::loncommon(); @@ -36,6 +34,7 @@ use Apache::lonhtmlcommon; use Apache::lonnet; use Apache::lonlocal; use Apache::lonacc(); +use Apache::lonauth(); use Apache::courseclassifier; use LONCAPA qw(:DEFAULT :match); use HTML::Entities; @@ -83,7 +82,8 @@ sub print_request_form { my ($r,$origurl,$function) = @_; my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$urole,$usec,$email,$cid, $cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server, - $formname,$public,$homeserver); + $formname,$public,$homeserver,$knownuser,$captcha_form,$captcha_error, + $captcha,$recaptcha_version); $function = &Apache::loncommon::get_users_function() if (!$function); $ccode = ''; $os = $env{'browser.os'}; @@ -104,6 +104,14 @@ sub print_request_form { } } } + if (($env{'user.name'} =~ /^$match_username$/) && + ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) { + $knownuser = 1; + } else { + my $lonhost = $r->dir_config('lonHostID'); + ($captcha_form,$captcha_error,$captcha,$recaptcha_version) = + &Apache::loncommon::captcha_display('login',$lonhost); + } if ($homeserver) { $uhome = $env{'user.home'}; $urole = $env{'request.role'}; @@ -113,13 +121,15 @@ sub print_request_form { $formname = 'logproblem'; my $machine = &Apache::lonnet::absolute_url(); my $sourceurl = $machine.$origurl; - $server = $machine.&cleanup_html($origurl); + $server = $machine.&Apache::loncommon::cleanup_html($origurl); $server =~ s/\?.*$//; - my %lt = &Apache::lonlocal::texthash ( + my %js_lt = &Apache::lonlocal::texthash ( email => 'The e-mail address you entered', notv => 'is not a valid e-mail address', rsub => 'You must include a subject', rdes => 'You must include a description', + ); + my %html_lt = &Apache::lonlocal::texthash ( name => 'Name', subm => 'Submit Request', emad => 'Your e-mail address', @@ -142,22 +152,24 @@ sub print_request_form { subj => 'Subject', detd => 'Detailed Description', opfi => 'Optional file upload', - uplf => 'Upload a file (e.g., a screenshot) relevant to your help request (128 KB max.)', + uplf => 'Upload a file (e.g., a screenshot) relevant to your help request (1 MB max.)', fini => 'Finish', clfm => 'Clear Form', ); + &js_escape(\%js_lt); + &html_escape(\%html_lt); my $scripttag = (<<"END"); function validate() { if (validmail(document.logproblem.email) == false) { - alert("$lt{'email'}: "+document.logproblem.email.value+" $lt{'notv'}."); + alert("$js_lt{'email'}: "+document.logproblem.email.value+" $js_lt{'notv'}."); return; } if (document.logproblem.subject.value == '') { - alert("$lt{'rsub'}."); + alert("$js_lt{'rsub'}."); return; } if (document.logproblem.description.value == '') { - alert("$lt{'rdes'}."); + alert("$js_lt{'rdes'}."); return; } document.logproblem.submit(); @@ -270,7 +282,11 @@ $jscript $loaditems // ]]> + ENDJS + if ($recaptcha_version >=2) { + $js.= "\n".''."\n"; + } my %add_entries = ( style => "margin-top:0px;margin-bottom:0px;", onload => "initialize_codes();", @@ -293,7 +309,12 @@ ENDJS } $r->print('
'."\n"); my $output = &Apache::lonhtmlcommon::start_pick_box(). - &Apache::lonhtmlcommon::row_title($lt{'name'},undef,$css[$num])."\n"; + &Apache::lonhtmlcommon::row_headline(). + ''. + &mt('(All fields marked with * are required.)'). + ''. + &Apache::lonhtmlcommon::row_closure(). + &Apache::lonhtmlcommon::row_title($html_lt{'name'},undef,$css[$num])."\n"; my $fullname = ''; if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) { $fullname = "$firstname $lastname"; @@ -306,73 +327,75 @@ ENDJS } $output .= '&').'" />'."\n"; } - $output .= '      '. + $output .= '      '. &Apache::lonhtmlcommon::row_closure()."\n"; $num ++; $i = $num%2; - $output .= &Apache::lonhtmlcommon::row_title($lt{'emad'},undef,$css[$i]). + $output .= &Apache::lonhtmlcommon::row_title( + ''. + $html_lt{'emad'}.' *' + ,undef,$css[$i]). '&').'" />
'."\n". &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; - if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { - if ($homeserver) { - $output .= &Apache::lonhtmlcommon::row_title($lt{'emac'},undef,$css[$i]). + if ($knownuser) { + if ($homeserver) { + $output .= &Apache::lonhtmlcommon::row_title($html_lt{'emac'},undef,$css[$i]). '
'."\n". &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; } } - $output .= &Apache::lonhtmlcommon::row_title("$lt{'unme'}/$lt{'doma'}",undef,$css[$i]); + $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'unme'}/$html_lt{'doma'}",undef,$css[$i]); my $udom_input = '&').'" />'."\n"; my $uname_input = '&').'" />'."\n"; - if (($env{'user.name'} =~ /^$match_username$/) && - ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) { - $output .= ''.$lt{'unme'}.': '.$uname.'  '.$lt{'doma'}.': '.$udom.$udom_input.$uname_input; + if ($knownuser) { + $output .= ''.$html_lt{'unme'}.': '.$uname.'  '.$html_lt{'doma'}.': '.$udom.$udom_input.$uname_input; } else { my $udomform = ''; my $unameform = ''; if (($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) { - $output .= $lt{'entu'}; + $output .= $html_lt{'entu'}; } elsif (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { - $output .= $lt{'chdo'}; + $output .= $html_lt{'chdo'}; } else { - $output .= $lt{'entr'}; + $output .= $html_lt{'entr'}; } $output .= '
'."\n"; if (!$public) { if ($env{'user.domain'} =~ /^$match_domain$/) { - $udomform = ''.$lt{'doma'}.': '.$udom.$udom_input; + $udomform = ''.$html_lt{'doma'}.': '.$udom.$udom_input; } elsif ($env{'user.name'} =~ /^$match_username$/) { - $unameform = ''.$lt{'unme'}.': '.$uname.'  '.$uname_input; + $unameform = ''.$html_lt{'unme'}.': '.$uname.'  '.$uname_input; } } if ($udomform eq '') { - $udomform = ''.$lt{'doma'}.': '; + $udomform = ''.$html_lt{'doma'}.': '; $udomform .= &Apache::loncommon::select_dom_form($codedom,'udom')."\n"; } if ($unameform eq '') { - $unameform= ''.$lt{'unme'}.'  '; + $unameform= ''.$html_lt{'unme'}.'  '; } $output .= $unameform.$udomform; } $output .= &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; - $output .= &Apache::lonhtmlcommon::row_title("$lt{'urlp'}",undef,$css[$i]). + $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'urlp'}",undef,$css[$i]). $server."\n".'&').'" />'."\n". &Apache::lonhtmlcommon::row_closure(). - &Apache::lonhtmlcommon::row_title("$lt{'phon'}",undef,'LC_evenrow_value'). + &Apache::lonhtmlcommon::row_title("$html_lt{'phon'}",undef,'LC_evenrow_value'). '
'."\n". &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; - $output .= &Apache::lonhtmlcommon::row_title("$lt{'crsd'}$details_title",undef,$css[$i]); + $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'crsd'}$details_title",undef,$css[$i]); if ($cnum) { if ($coursecodes{$cnum}) { foreach my $item (@codetitles) { @@ -380,14 +403,14 @@ ENDJS } $output .= ' &').'" />'."\n"; } else { - $output .= $lt{'enin'}.':  + $output .= $html_lt{'enin'}.':  '."\n"; } } else { if ($totcodes > 0) { my $numtitles = @codetitles; if ($numtitles == 0) { - $output .= $lt{'enin'}.':  + $output .= $html_lt{'enin'}.':  '."\n"; } else { my @standardnames = &Apache::loncommon::get_standard_codeitems(); @@ -397,7 +420,7 @@ ENDJS } $output .= ''."\n"; } @@ -434,30 +457,30 @@ ENDJS if ($numtitles > 4) { $output .= '

'.$codetitles[$numtitles].'
'."\n". ''."\n"; } } } else { - $output .= $lt{'enin'}.':  + $output .= $html_lt{'enin'}.':  '."\n"; } } if ($ctitle) { - $output .= '
'.$lt{'titl'}.': '.$ctitle. + $output .= '
'.$html_lt{'titl'}.': '.$ctitle. '&').'" />'."\n"; } else { - $output .= '
'.$lt{'enct'}.':  + $output .= '
'.$html_lt{'enct'}.':  '."\n"; } $output .= &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; - $output .= &Apache::lonhtmlcommon::row_title($lt{'secn'},undef,$css[$i]); + $output .= &Apache::lonhtmlcommon::row_title($html_lt{'secn'},undef,$css[$i]); if ($sectionlist) { $output .= ""; @@ -476,36 +499,55 @@ ENDJS $output .= &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; - $output .= &Apache::lonhtmlcommon::row_title($lt{'subj'},undef,'LC_oddrow_value'). - ' '."\n". + $output .= &Apache::lonhtmlcommon::row_title( + ''. + $html_lt{'subj'}.' *' + ,undef,'LC_oddrow_value'). + ''."\n". &Apache::lonhtmlcommon::row_closure(). - &Apache::lonhtmlcommon::row_title($lt{'detd'},undef,'LC_evenrow_value'). - ' '."\n". &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; - if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { + if ($knownuser) { if ($homeserver) { - $output .= &Apache::lonhtmlcommon::row_title($lt{'opfi'},undef,$css[$i]). - '
'. - "\n".$lt{'uplf'}."\n". + $output .= &Apache::lonhtmlcommon::row_title($html_lt{'opfi'},undef,$css[$i]) + .' ' + .'' + .'
'."\n".$html_lt{'uplf'}."\n" + .&Apache::lonhtmlcommon::row_closure(); + $num ++; + $i = $num%2; + } + } else { + if ($captcha_form) { + $output .= &Apache::lonhtmlcommon::row_title( + ''. + &mt('Validation'). + ' *' + ,undef,$css[$i]). + $captcha_form."\n". &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; } } - $output .= &Apache::lonhtmlcommon::row_title($lt{'fini'},undef,$css[$i]); + $output .= &Apache::lonhtmlcommon::row_title($html_lt{'fini'},undef,$css[$i]); $output .= <
'.$codetitles[0].'
'."\n". '
'.$codetitles[$i].'
'."\n". ''."\n". '
-   +     - +
@@ -523,6 +565,37 @@ END sub print_request_receipt { my ($r,$url,$function) = @_; + my $public; + if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) { + $public = 1; + } + unless (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { + my $lonhost = $r->dir_config('lonHostID'); + my ($captcha_chk,$captcha_error) = + &Apache::loncommon::captcha_response('login',$lonhost); + if ($captcha_chk != 1) { + $r->print(&Apache::loncommon::start_page('Support request failed',undef, + {'function' => $function, + 'add_entries' => { + topmargin => "0", + marginheight => "0", + }, + 'only_body' => 1,})); + if ($r->uri eq '/adm/helpdesk') { + &print_header($r,$url,'process'); + } + $r->print( + '

'.&mt('Support request failed').'

'. + &Apache::lonhtmlcommon::confirm_success( + &mt('Validation of the code you entered failed.'),1). + '

'. + &Apache::lonhtmlcommon::actionbox([ + &mt('[_1]Go back[_2] and try again', + '','')]). + &Apache::loncommon::end_page()); + return; + } + } my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME'); my @envvars = ('browser.os','browser.type','browser.version','user.home','request.role'); my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id'); @@ -602,10 +675,8 @@ sub print_request_receipt { adin => 'Additional information recorded', ); - my (@ok_ccs,@bad_ccs,$badccmsg,$okcclist,$public,$homeserver); - if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) { - $public = 1; - } else { + my (@ok_ccs,@bad_ccs,$badccmsg,$okcclist,$homeserver); + unless ($public) { if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) { $homeserver = &Apache::lonnet::homeserver($env{'user.name'}, $env{'user.domain'}); @@ -639,10 +710,10 @@ sub print_request_receipt { } if (@bad_ccs == 1) { if ($bad_ccs[0] ne '') { - $badccmsg .= '
'.&mt('The following Cc e-mail address is invalid: ').&cleanup_html($bad_ccs[0]); + $badccmsg .= '
'.&mt('The following Cc e-mail address is invalid: ').&Apache::loncommon::cleanup_html($bad_ccs[0]); } } elsif (@bad_ccs > 1) { - $badccmsg .= '
'.&mt('The following Cc e-mail addresses are invalid: '). &cleanup_html(join(', ',@bad_ccs)); + $badccmsg .= '
'.&mt('The following Cc e-mail addresses are invalid: '). &Apache::loncommon::cleanup_html(join(', ',@bad_ccs)); } } $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'"; @@ -665,7 +736,7 @@ END if ($env{'form.'.$item} ne '') { if ($item eq 'description') { my $descrip = $env{'form.description'}; - $descrip = &cleanup_html($descrip); + $descrip = &Apache::loncommon::cleanup_html($descrip); $descrip =~ s|[\n\r\f]|
|g; $displaymsg .= ''. @@ -673,20 +744,20 @@ END } elsif ($item eq 'sourceurl') { my $showurl = $env{'form.sourceurl'}; $showurl =~ s/\?.*$//; - $showurl = &cleanup_html($showurl); + $showurl = &Apache::loncommon::cleanup_html($showurl); $displaymsg .= ''. "$lt{$item}: $showurl
\n"; } elsif ($item eq 'cc') { if ($okcclist) { - my $showcclist = &cleanup_html($okcclist); + my $showcclist = &Apache::loncommon::cleanup_html($okcclist); $displaymsg .= ''. "$lt{$item}: $showcclist
\n"; } } else { my $showitem = $env{'form.'.$item}; - $showitem = &cleanup_html($showitem); + $showitem = &Apache::loncommon::cleanup_html($showitem); $displaymsg .= ''. "$lt{$item}: $showitem
\n"; @@ -707,7 +778,7 @@ END $r->print(<<"END"); $start_page - + END @@ -777,12 +848,12 @@ END my $attachmentpath = ''; my $attachmentsize = ''; - if ((defined($env{'user.name'})) && ($env{'user.name'} ne 'public') - && ($env{'user.domain'} ne 'public')) { + if ((defined($env{'user.name'})) && (!$public)) { if ($homeserver && $env{'form.screenshot.filename'}) { $attachmentsize = length($env{'form.screenshot'}); - if ($attachmentsize > 131072) { - $displaymsg .= '
'.&mt('The uploaded screenshot file ([_1] bytes) included with your request exceeded the maximum allowed size - 128 KB, and has therefore been discarded.',$attachmentsize); + if ($attachmentsize > 1048576) { + $displaymsg .= '
'. + &mt('The uploaded screenshot file ([_1] bytes) included with your request exceeded the maximum allowed size - 1 MB, and has therefore been discarded.',$attachmentsize).''; } else { $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests'); } @@ -815,33 +886,15 @@ END } } - my $msg = MIME::Lite->new( - From => $from, - To => $to, - Subject => $subject, - Type =>'TEXT', - Data => $supportmsg, - ); + my $cc_string; if ($homeserver) { if (@ok_ccs > 0) { - my $cc_string = join(', ',@ok_ccs); - $msg->add("Cc" => $cc_string); + $cc_string = join(', ',@ok_ccs); } } - if ($bcc ne '') { - $msg->add("Bcc" => $bcc); - } - $msg->attr("content-type" => "text/plain"); - $msg->attr("content-type.charset" => "UTF-8"); - - if ($homeserver && $attachmentpath) { - my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath); - $msg->attach(Type => $type, - Path => $attachmentpath, - Filename => $fname - ); - } else { + my $attachment_text; + unless ($homeserver && $attachmentpath) { my $envdata = ''; foreach my $var (@cookievars) { $envdata .= "$var: $cookies{$var}\n"; @@ -855,12 +908,12 @@ END foreach my $var (@loncvars) { $envdata .= "$var: $env{$var}\n"; } - $msg->attach(Type => 'TEXT', - Data => $envdata); + $attachment_text = $envdata; } - -### Send it: - $msg->send('sendmail'); + + # Compose and send a MIME email + &Apache::loncommon::mime_email($from, $to, $subject, $supportmsg, $cc_string, $bcc, + $attachmentpath, $fname, $attachment_text); if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) { unlink($attachmentpath); @@ -929,6 +982,10 @@ sub print_header { } else { $linkback = &HTML::Entities::encode($origurl,'"<>&'); } + my $loginhelp = &Apache::lonauth::loginhelpdisplay(); + if ($loginhelp eq '') { + $loginhelp = '/adm/loginproblems.html'; + } $r->print(<<"END"); @@ -941,7 +998,7 @@ sub print_header {
- + $getstartlink @@ -960,10 +1017,11 @@ END $r->print(<<"END"); END @@ -990,26 +1048,4 @@ sub get_domain { return $codedom; } -sub cleanup_html { - my ($incoming) = @_; - my $outgoing; - if ($incoming ne '') { - $outgoing = $incoming; - $outgoing =~ s/;/;/g; - $outgoing =~ s/\#/#/g; - $outgoing =~ s/\&/&/g; - $outgoing =~ s//>/g; - $outgoing =~ s/\(/(/g; - $outgoing =~ s/\)/)/g; - $outgoing =~ s/"/"/g; - $outgoing =~ s/'/'/g; - $outgoing =~ s/\$/$/g; - $outgoing =~ s{/}{/}g; - $outgoing =~ s/=/=/g; - $outgoing =~ s/\\/\/g - } - return $outgoing; -} - 1;