--- loncom/auth/lonlogin.pm 2021/05/03 15:27:44 1.183 +++ loncom/auth/lonlogin.pm 2021/10/06 19:28:55 1.188 @@ -1,7 +1,7 @@ # The LearningOnline Network # Login Screen # -# $Id: lonlogin.pm,v 1.183 2021/05/03 15:27:44 raeburn Exp $ +# $Id: lonlogin.pm,v 1.188 2021/10/06 19:28:55 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -38,6 +38,8 @@ use Apache::lonlocal; use Apache::migrateuser(); use lib '/home/httpd/lib/perl/'; use LONCAPA qw(:DEFAULT :match); +use URI::Escape; +use HTML::Entities(); use CGI::Cookie(); sub handler { @@ -47,7 +49,7 @@ sub handler { (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'}, $ENV{'REDIRECT_QUERY_STRING'}), ['interface','username','domain','firsturl','localpath','localres', - 'token','role','symb','iptoken','btoken','ltoken','linkkey']); + 'token','role','symb','iptoken','btoken','ltoken','linkkey','saml']); if (!defined($env{'form.firsturl'})) { &Apache::lonacc::get_posted_cgi($r,['firsturl']); } @@ -111,7 +113,6 @@ sub handler { } my $lonhost = $r->dir_config('lonHostID'); - $env{'form.firsturl'} =~ s/(`)/'/g; # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer) @@ -123,7 +124,12 @@ sub handler { $protocol = 'http' if ($protocol ne 'https'); my $dest = '/adm/roles'; if ($env{'form.firsturl'} ne '') { - $dest = $env{'form.firsturl'}; + if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) { + $dest = &uri_escape_utf8($env{'form.firsturl'}); + } else { + $dest = &uri_escape($env{'form.firsturl'}); + } + $dest = &HTML::Entities::encode($dest,"'"); } my %info = ( balcookie => $lonhost.':'.$balancer_cookie, @@ -141,7 +147,7 @@ sub handler { } my $balancer_token = &Apache::lonnet::tmpput(\%info,$found_server); if ($balancer_token) { - $dest .= (($dest=~/\?/)?'&;':'?') . 'btoken='.$balancer_token; + $dest .= (($dest=~/\?/)?'&':'?') . 'btoken='.$balancer_token; } unless ($found_server eq $lonhost) { my $alias = &Apache::lonnet::use_proxy_alias($r,$found_server); @@ -203,7 +209,12 @@ sub handler { &Apache::loncommon::end_page(); my $dest = '/adm/roles'; if ($env{'form.firsturl'} ne '') { - $dest = $env{'form.firsturl'}; + if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) { + $dest = &uri_escape_utf8($env{'form.firsturl'}); + } else { + $dest = &uri_escape($env{'form.firsturl'}); + } + $dest = &HTML::Entities::encode($dest,"'"); } if (($env{'form.ltoken'}) || ($linkprot)) { unless ($linkprot) { @@ -581,17 +592,9 @@ function enableInput() { ENDSCRIPT -# --------------------------------------------------- Print login screen header - - my %add_entries = ( - bgcolor => "$mainbg", - text => "$font", - link => "$link", - vlink => "$vlink", - alink => "$alink", - onload => 'javascript:enableInput();',); - - my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf); + my ($lonhost_in_use,@hosts,%defaultdomconf,$saml_prefix,$saml_landing, + $samlssotext,$samlnonsso,$samlssoimg,$samlssoalt,$samlssourl,$samltooltip); + %defaultdomconf = &Apache::loncommon::get_domainconf($defdom); @hosts = &Apache::lonnet::current_machine_ids(); $lonhost_in_use = $lonhost; if (@hosts > 1) { @@ -602,7 +605,67 @@ ENDSCRIPT } } } - %defaultdomconf = &Apache::loncommon::get_domainconf($defdom); + $saml_prefix = $defdom.'.login.saml_'; + if ($defaultdomconf{$saml_prefix.$lonhost_in_use}) { + $saml_landing = 1; + $samlssotext = $defaultdomconf{$saml_prefix.'text_'.$lonhost_in_use}; + $samlnonsso = $defaultdomconf{$saml_prefix.'notsso_'.$lonhost_in_use}; + $samlssoimg = $defaultdomconf{$saml_prefix.'img_'.$lonhost_in_use}; + $samlssoalt = $defaultdomconf{$saml_prefix.'alt_'.$lonhost_in_use}; + $samlssourl = $defaultdomconf{$saml_prefix.'url_'.$lonhost_in_use}; + $samltooltip = $defaultdomconf{$saml_prefix.'title_'.$lonhost_in_use}; + } + if ($saml_landing) { + if ($samlssotext eq '') { + $samlssotext = 'SSO Login'; + } + if ($samlnonsso eq '') { + $samlnonsso = 'Non-SSO Login'; + } + $js .= <<"ENDSAMLJS"; + + + +ENDSAMLJS + } + +# --------------------------------------------------- Print login screen header + + my %add_entries = ( + bgcolor => "$mainbg", + text => "$font", + link => "$link", + vlink => "$vlink", + alink => "$alink", + onload => 'javascript:enableInput();',); + + my ($headextra,$headextra_exempt); $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use}; $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use}; if ($headextra) { @@ -647,6 +710,7 @@ ENDSCRIPT 'helpdesk' => 'Contact Helpdesk', 'forgotpw' => 'Forgot password?', 'newuser' => 'New User?', + 'change' => 'Change?', ); # -------------------------------------------------- Change password field name @@ -708,7 +772,7 @@ ENDSERVERFORM $mobileargs = 'autocapitalize="off" autocorrect="off"'; } my $loginform=(< +
:
@@ -729,8 +793,63 @@ LFORM HEADER } - $r->print(< + + my $stdauthformstyle = 'inline-block'; + my $ssoauthstyle = 'none'; + my $logintype; + $r->print('
'); + if ($saml_landing) { + $ssoauthstyle = 'inline-block'; + $stdauthformstyle = 'none'; + $logintype = $samlssotext; + my $ssologin = '/adm/sso'; + if ($samlssourl ne '') { + $ssologin = $samlssourl; + } + if ($env{'form.firsturl'} ne '') { + my $querystring; + if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) { + $querystring = &uri_escape_utf8($env{'form.firsturl'}); + } else { + $querystring = &uri_escape($env{'form.firsturl'}); + } + $querystring = &HTML::Entities::encode($querystring,"'"); + $ssologin .= (($ssologin=~/\?/)?'&':'?') . $querystring; + } + my $ssohref; + if ($samlssoimg ne '') { + $ssohref = ''.$samlssoalt.''; + } else { + $ssohref = ''.$samlssotext.''; + } + if (($env{'form.saml'} eq 'no') || + (($env{'form.username'} ne '') && ($env{'form.domain'} ne ''))) { + $ssoauthstyle = 'none'; + $stdauthformstyle = 'inline-block'; + $logintype = $samlnonsso; + } + $r->print(< +Log-in type: +$logintype
+$lt{'change'} +

+
+
+$ssohref +$noscript_warning +
+
+$loginhelp +$contactblock +$coursecatalog +
+
+ENDSAML + } + + $r->print(<
$logintitle $loginform @@ -746,8 +865,8 @@ HEADER
-
-ENDTOP +ENDLOGIN + $r->print('
'."\n"); if ($showmainlogo) { $r->print(' '."\n"); } @@ -920,12 +1039,19 @@ sub redirect_page { } my $url = $protocol.'://'.$hostname.$path; if ($env{'form.firsturl'} ne '') { - $url .='?firsturl='.$env{'form.firsturl'}; + my $querystring; + if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) { + $querystring = &uri_escape_utf8($env{'form.firsturl'}); + } else { + $querystring = &uri_escape($env{'form.firsturl'}); + } + $querystring = &HTML::Entities::encode($querystring,"'"); + $url .='?firsturl='.$querystring } if ($linkprot) { my $ltoken = &Apache::lonnet::tmpput({linkprot => $linkprot},$desthost); if ($ltoken) { - $url .= (($url =~ /\?/) ? '&' : '?').'ltoken='.$ltoken; + $url .= (($url =~ /\?/) ? '&' : '?').'ltoken='.$ltoken; } } my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,