--- loncom/interface/lonsupportreq.pm 2017/01/23 17:23:03 1.87 +++ loncom/interface/lonsupportreq.pm 2020/12/18 15:23:02 1.101 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Helpdesk request form # -# $Id: lonsupportreq.pm,v 1.87 2017/01/23 17:23:03 raeburn Exp $ +# $Id: lonsupportreq.pm,v 1.101 2020/12/18 15:23:02 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -67,7 +67,9 @@ sub handler { } } my $origurl = $env{'form.origurl'}; - $origurl =~ s{^https?://}{}; + if ($origurl =~ m{^https?://[^/]+(.*)$}) { + $origurl =~ $1; + } $origurl =~ s/(`)//g; $origurl =~ s/\$/\(\$\)/g; my $command = $env{'form.command'}; @@ -79,7 +81,7 @@ sub handler { } return OK; } - + sub print_request_form { my ($r,$origurl,$function) = @_; my ($os,$browser,$bversion,$uname,$udom,$uhome,$urole,$usec,$email,$cid, @@ -105,7 +107,7 @@ sub print_request_form { } } } - if (($env{'user.name'} =~ /^$match_username$/) && + if (($env{'user.name'} =~ /^$match_username$/) && ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) { $knownuser = 1; } else { @@ -149,7 +151,6 @@ sub print_request_form { } } - my %coursecodes; my %codes; my @codetitles; my %cat_titles; @@ -157,9 +158,7 @@ sub print_request_form { my %idlist; my %idnums; my %idlist_titles; - my $caller = 'global'; my $totcodes = 0; - my $format_reply; my $jscript = ''; my $loaditems = qq| function initialize_codes() { @@ -167,10 +166,17 @@ function initialize_codes() { } |; unless ($helpform{'course'} eq 'no') { - $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom); - if ($totcodes > 0) { - $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order); - if ($format_reply eq 'ok') { + my $instcats = &Apache::lonnet::get_dom_instcats($codedom); + if (ref($instcats) eq 'HASH') { + if ((ref($instcats->{'codetitles'}) eq 'ARRAY') && (ref($instcats->{'codes'}) eq 'HASH') && + (ref($instcats->{'cat_titles'}) eq 'HASH') && (ref($instcats->{'cat_order'}) eq 'HASH')) { + %codes = %{$instcats->{'codes'}}; + @codetitles = @{$instcats->{'codetitles'}}; + %cat_titles = %{$instcats->{'cat_titles'}}; + %cat_order = %{$instcats->{'cat_order'}}; + $totcodes = scalar(keys(%codes)); + } + if ($totcodes > 0) { my $numtypes = @codetitles; &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles); my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles); @@ -313,9 +319,10 @@ $jscript $loaditems // ]]> - ENDJS - if ($recaptcha_version >=2) { + if ($knownuser) { + $js .="\n".''; + } elsif ($recaptcha_version >=2) { $js.= "\n".''."\n"; } my %add_entries = ( @@ -350,7 +357,7 @@ ENDJS unless ($helpform{'username'} eq 'no') { my ($reqd,$namefield,$fullname); if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) { - $fullname = "$firstname $lastname"; + $fullname = "$firstname $lastname"; $namefield = $fullname.'&').'" />'."\n"; } else { if (defined($firstname) && $firstname ne '') { @@ -378,7 +385,7 @@ ENDJS &HTML::Entities::encode($email,'"<>&').'" />'."\n"; unless ($shownsubmit) { $output .= $topsubmit; - } + } $output .= &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; @@ -393,7 +400,7 @@ ENDJS } } } - unless ($helpform{'user'} eq 'no') { + unless (($helpform{'user'} eq 'no') || ($env{'request.lti.login'})) { $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'unme'}/$html_lt{'doma'}",undef,$css[$i]); my $udom_input = '&').'" />'."\n"; @@ -430,12 +437,14 @@ ENDJS } $output .= &Apache::lonhtmlcommon::row_closure(); $num ++; + $i = $num%2; + } + unless ($env{'request.lti.login'}) { + $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'urlp'}",undef,$css[$i]). + $server."\n".'&').'" />'."\n". + &Apache::lonhtmlcommon::row_closure(); } - $i = $num%2; - $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'urlp'}",undef,$css[$i]). - $server."\n".'&').'" />'."\n". - &Apache::lonhtmlcommon::row_closure(); unless ($helpform{'phone'} eq 'no') { my $reqd; if ($helpform{'phone'} eq 'req') { @@ -447,7 +456,7 @@ ENDJS $num ++; $i = $num%2; } - unless ($helpform{'course'} eq 'no') { + unless (($helpform{'course'} eq 'no') || ($env{'request.lti.login'})) { $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'crsd'}$details_title",undef,$css[$i]); if ($totcodes > 0) { my $numtitles = @codetitles; @@ -522,7 +531,7 @@ ENDJS $num ++; $i = $num%2; } - unless ($helpform{'section'} eq 'no') { + unless (($helpform{'section'} eq 'no') || ($env{'request.lti.login'})) { $output .= &Apache::lonhtmlcommon::row_title($html_lt{'secn'},undef,$css[$i]); if ($sectionlist) { $output .= "
'."\n". ''."\n"; - } else { + } else { $output .= ''."\n"; } $output .= &Apache::lonhtmlcommon::row_closure(); @@ -569,13 +578,13 @@ ENDJS my $max = 1048576; my $showmax = 1.00; if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) { - $max *= $helpform{'maxsize'}; + $max *= $helpform{'maxsize'}; $showmax = $helpform{'maxsize'}; } $showmax = ' ('.sprintf("%.2f",$showmax).' '.&mt('MB max.').')'; $output .= &Apache::lonhtmlcommon::row_title($html_lt{'opfi'},undef,$css[$i]) - .' ' - .'' + .' ' + .'' .'
'."\n".$html_lt{'uplf'}.$showmax."\n" .&Apache::lonhtmlcommon::row_closure(); $num ++; @@ -627,7 +636,7 @@ sub print_request_receipt { if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) { $public = 1; } - my $lonhost = $r->dir_config('lonHostID'); + my $lonhost = $r->dir_config('lonHostID'); unless (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { my ($captcha_chk,$captcha_error) = &Apache::loncommon::captcha_response('login',$lonhost); @@ -654,17 +663,20 @@ sub print_request_receipt { return; } } - my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME'); + my $ip = &Apache::lonnet::get_requestor_ip(); + my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','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'); - my @cookievars = ('lonID'); + my @cookievars; + if ($ENV{'SERVER_PORT'} == 443) { + @cookievars = ('lonLinkID'); + } else { + @cookievars = ('lonID'); + } my $admin = $Apache::lonnet::perlvar{'lonAdminMail'}; my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'}; my $defdom = &get_domain(); - my ($to,$bcc,$addtext) = - &Apache::loncommon::build_recipient_list(undef,'helpdeskmail', - $defdom,$origmail); my $from = $admin; my %helpform; my %domconfig = @@ -691,10 +703,10 @@ sub print_request_receipt { unless ($helpform{'phone'} eq 'no') { $formvars{'phone'} = 1; } - unless ($helpform{'section'} eq 'no') { + unless (($helpform{'section'} eq 'no') || ($env{'request.lti.login'})) { $formvars{'section'} = 1; } - unless ($helpform{'course'} eq 'no') { + unless (($helpform{'course'} eq 'no') || ($env{'request.lti.login'})) { $formvars{'course'} = 1; } unless ($helpform{'cc'} eq 'no') { @@ -703,13 +715,17 @@ sub print_request_receipt { unless ($helpform{'screenshot'} eq 'no') { $formvars{'screenshot'} = 1; } - my $coursecode; + my ($coursecode,$sourceurl); if ($formvars{'course'}) { $coursecode = $env{'form.coursecode'}; if ($coursecode eq '') { my $totcodes = 0; - my %coursecodes; - $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$defdom); + my $instcats = &Apache::lonnet::get_dom_instcats($defdom); + if (ref($instcats) eq 'HASH') { + if (ref($instcats->{'codes'}) eq 'HASH') { + $totcodes = scalar(keys(%{$instcats->{'codes'}})); + } + } my @standardnames = &Apache::loncommon::get_standard_codeitems(); if ($totcodes > 0) { my $noregexps = 1; @@ -797,7 +813,15 @@ sub print_request_receipt { $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'}."'"; + if ($env{'request.lti.login'}) { + if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) { + $env{'form.user'} = "'".$env{'user.name'}.':'.$env{'user.domain'}."'"; + } + $sourceurl = &Apache::lonnet::absolute_url().$url; + } else { + $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'"; + $sourceurl = $env{'form.sourceurl'}; + } if ($formvars{'course'}) { $env{'form.crsi'} = $env{'form.title'}; if ($coursecode ne '') { @@ -833,10 +857,10 @@ sub print_request_receipt { } if ($formvars{'course'}) { $supportmsg .= "$lt{'crsi'}: $env{'form.crsi'}\n"; - } + } $supportmsg .= "$lt{'subject'}: $env{'form.subject'} $lt{'description'}: $env{'form.description'} -$lt{'sourceurl'}: $env{'form.sourceurl'} +$lt{'sourceurl'}: $sourceurl $lt{'date'}: $reporttime "; @@ -870,6 +894,7 @@ $lt{'date'}: $reporttime next if ($helpform{$item} eq 'no'); } next if (($item eq 'crsi') && ($helpform{'course'} eq 'no')); + next if (($item eq 'user') && ($env{'request.lti.login'})); my $showitem = $env{'form.'.$item}; $showitem = &Apache::loncommon::cleanup_html($showitem); $displaymsg .= @@ -878,6 +903,33 @@ $lt{'date'}: $reporttime } } } + + my ($requname,$requdom,$reqemail); + foreach my $field ('uname','udom','email') { + $env{'form.'.$field} =~ s/^\s+//; + $env{'form.'.$field} =~ s/\s+$//; + } + if ($env{'form.uname'} =~ /^$match_username$/) { + $requname = $env{'form.uname'}; + } + if ($env{'form.udom'} =~ /^$match_domain$/) { + $requdom = $env{'form.udom'}; + } + if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) { + $reqemail = $env{'form.email'}; + } + + my $dom_in_effect; + unless ($env{'user.domain'} eq 'public') { + $dom_in_effect = $env{'user.domain'}; + } + if ($dom_in_effect eq '') { + $dom_in_effect = $requdom; + } + if ($dom_in_effect eq '') { + $dom_in_effect = $defdom; + } + $displaymsg .= ''. $lt{'date'}.': '.$reporttime.'
'."\n"; @@ -900,6 +952,11 @@ END &print_header($r,$url,'process'); } my $bad_email = 0; + my ($to,$bcc,$addtext) = + &Apache::loncommon::build_recipient_list(undef,'helpdeskmail', + $dom_in_effect,$origmail, + $requname,$requdom, + $reqemail); if ($to =~ /,/) { my @ok_email; foreach my $email (split(/,/,$to)) { @@ -937,12 +994,8 @@ END } $r->print(&Apache::loncommon::confirmwrapper($message)); - if (defined($env{'form.email'})) { - $env{'form.email'} =~ s/^\s+//; - $env{'form.email'} =~ s/\s+$//; - if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) { - $from = $env{'form.email'}; - } + if ($reqemail ne '') { + $from = $reqemail; } if (defined($env{'form.cc'})) { @@ -961,21 +1014,22 @@ END my $fname; my $attachmentpath = ''; - my $attachmentsize = ''; + my $showsize = ''; + if ((defined($env{'user.name'})) && (!$public)) { if ($homeserver && $env{'form.screenshot.filename'}) { unless ($helpform{'screenshot'} eq 'no') { - $attachmentsize = length($env{'form.screenshot'}); + my $attachmentsize = length($env{'form.screenshot'}); my $max = 1048576; my $showmax = 1.00; if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) { $max *= $helpform{'maxsize'}; $showmax = $helpform{'maxsize'}; } - $showmax = '('.sprintf("%.2f",$showmax).' MB)'; + $showmax = '('.sprintf("%.2f",$showmax).' MB)'; + $showsize = $attachmentsize/1048576; + $showsize = '('.sprintf("%.2f",$showsize).' MB)'; if ($attachmentsize > $max) { - my $showsize = $attachmentsize/1048576; - $showsize = '('.sprintf("%.2f",$showsize).' MB)'; $displaymsg .= '
'. &mt('The uploaded screenshot file [_1] included with your request exceeded the maximum allowed size [_2], and has therefore been discarded.',$showsize,$showmax).''; } else { @@ -990,13 +1044,26 @@ END if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) { $cookies{'lonID'} = $1; } - + if ($$cookie{'lonLinkID'} =~ /lonLinkID=([a-f0-9]+_linked);/) { + $cookies{'lonLinkID'} = $1; + } + my $lti_info; + if (($env{'request.lti.login'}) && ($env{'request.course.id'})) { + my $ltidom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + if ($ltidom) { + my %lti = &Apache::lonnet::get_domain_lti($ltidom,'provider'); + if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') { + if ($lti{$env{'request.lti.login'}}{'consumer'}) { + $lti_info = "LTI consumer: ".$lti{$env{'request.lti.login'}}{'consumer'}."\n"; + } + } + } + } if ($attachmentpath =~ m-/([^/]+)$-) { $fname = $1; $displaymsg .= '
' - .&mt('An uploaded screenshot file [_1] ([_2] bytes) was included in the request sent by [_3].' - ,''.$fname.'' - ,$attachmentsize + .&mt('An uploaded screenshot file [_1] was included in the request sent by [_2].' + ,''.$fname.' '.$showsize, ,$env{'user.name'}.':'.$env{'user.domain'} ); $supportmsg .= "\n"; @@ -1006,11 +1073,15 @@ END foreach my $var(@ENVvars) { $supportmsg .= "$var: $ENV{$var}\n"; } + $supportmsg .= "REMOTE_ADDR: $ip\n"; foreach my $var (@envvars) { $supportmsg .= "$var: $env{$var}\n"; } + if ($lti_info) { + $supportmsg .= $lti_info; + } } - + my $cc_string; if ($homeserver) { if (@ok_ccs > 0) { @@ -1018,22 +1089,24 @@ END } } - my $attachment_text; + my $attachment_text = ''; unless ($homeserver && $attachmentpath) { - my $envdata = ''; foreach my $var (@cookievars) { - $envdata .= "$var: $cookies{$var}\n"; + $attachment_text .= "$var: $cookies{$var}\n"; } foreach my $var (@ENVvars) { - $envdata .= "$var: $ENV{$var}\n"; + $attachment_text .= "$var: $ENV{$var}\n"; } + $attachment_text .= "REMOTE_ADDR: $ip\n"; foreach my $var (@envvars) { - $envdata .= "$var: $env{$var}\n"; + $attachment_text .= "$var: $env{$var}\n"; } foreach my $var (@loncvars) { - $envdata .= "$var: $env{$var}\n"; + $attachment_text .= "$var: $env{$var}\n"; + } + if ($lti_info) { + $attachment_text .= $lti_info; } - $attachment_text = $envdata; } if ($addtext) { @@ -1047,8 +1120,8 @@ END } # Compose and send a MIME email - &Apache::loncommon::mime_email($from, $to, $subject, $supportmsg, $cc_string, $bcc, - $attachmentpath, $fname, $attachment_text); + &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); @@ -1072,6 +1145,9 @@ END $var.': '.$ENV{$var}.', '; } } + if ($ip ne '') { + $envmsg .= ''. + } 'REMOTE_ADDR: '.$ip.', '; foreach my $var (@envvars) { if ($env{$var} ne '') { $envmsg .= ''.