[LON-CAPA-cvs] cvs: loncom /auth lonacc.pm lonauth.pm lonlogin.pm lonshibauth.pm migrateuser.pm switchserver.pm /interface lonmsgdisplay.pm

raeburn raeburn at source.lon-capa.org
Sat Sep 17 19:38:51 EDT 2022


raeburn		Sat Sep 17 23:38:51 2022 EDT

  Modified files:              
    /loncom/auth	lonacc.pm lonauth.pm lonlogin.pm lonshibauth.pm 
                	migrateuser.pm switchserver.pm 
    /loncom/interface	lonmsgdisplay.pm 
  Log:
  - Support access to specific LON-CAPA message after login in cases where a
    LON-CAPA loadbalancer node is used as the portal for a domain.
  
  
-------------- next part --------------
Index: loncom/auth/lonacc.pm
diff -u loncom/auth/lonacc.pm:1.206 loncom/auth/lonacc.pm:1.207
--- loncom/auth/lonacc.pm:1.206	Wed Aug 24 20:58:50 2022
+++ loncom/auth/lonacc.pm	Sat Sep 17 23:38:50 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Cookie Based Access Handler
 #
-# $Id: lonacc.pm,v 1.206 2022/08/24 20:58:50 raeburn Exp $
+# $Id: lonacc.pm,v 1.207 2022/09/17 23:38:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -394,6 +394,8 @@
             if ($firsturl =~ m{^/tiny/$match_domain/\w+$}) {
                 $form{'origurl'} = $firsturl;
                 $deeplinkurl = $firsturl;
+            } elsif ($firsturl eq '/adm/email') {
+                $form{'origurl'} = $firsturl;
             }
             if ($form{'linkprot'}) {
                 $linkprot = $form{'linkprot'};
@@ -540,6 +542,12 @@
                     $env{'request.linkkey'} = $linkkey;
                 }
             }
+            if (($r->uri eq '/adm/sso') && ($form{'origurl'} eq '/adm/email')) {
+                if ($form{'display'} && ($env{'form.mailrecip'} eq $user.':'.$domain)) {
+                    $env{'request.display'} = $form{'display'};
+                    $env{'request.mailrecip'} = $env{'form.mailrecip'};
+                }
+            }
             $env{'request.sso.login'} = 1;
             if (defined($r->dir_config("lonSSOReloginServer"))) {
                 $env{'request.sso.reloginserver'} =
@@ -594,6 +602,12 @@
                     $info{'linkkey'} = $linkkey;
                 }
             }
+            if (($r->uri eq '/adm/sso') && ($form{'origurl'} eq '/adm/email')) {
+                if ($form{'display'} && ($form{'mailrecip'} eq $user.':'.$domain)) {
+                    $info{'display'} = &escape($form{'display'});
+                    $info{'mailrecip'} = &escape($form{'mailrecip'});
+                }
+            }
             if ($r->dir_config("ssodirecturl") == 1) {
                 $info{'origurl'} = $r->uri;
             }
Index: loncom/auth/lonauth.pm
diff -u loncom/auth/lonauth.pm:1.177 loncom/auth/lonauth.pm:1.178
--- loncom/auth/lonauth.pm:1.177	Wed Aug 24 20:58:50 2022
+++ loncom/auth/lonauth.pm	Sat Sep 17 23:38:50 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # User Authentication Module
 #
-# $Id: lonauth.pm,v 1.177 2022/08/24 20:58:50 raeburn Exp $
+# $Id: lonauth.pm,v 1.178 2022/09/17 23:38:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -147,6 +147,10 @@
                 $destination .= 'selectrole=1&'.$newrole.'=1';
             }
         }
+    } elsif (defined($form->{display})) {
+        if ($destination =~ m{^/adm/email($|\?)}) {
+            $destination  .= ($destination =~ /\?/) ? '&' : '?' .'display='.&escape($form->{display});
+        }
     }
     if (defined($form->{symb})) {
         my $destsymb = $form->{symb};
@@ -829,6 +833,11 @@
             }
             if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
                 &set_deeplink_login(%form);
+            } elsif ($firsturl eq '/adm/email') {
+                if ($form{'display'} && ($form{'mailrecip'} eq "$form{'uname'}:$form{'udom'}")) {
+                    $env{'request.display'} = $form{'display'};
+                    $env{'request.mailrecip'} = $form{'mailrecip'};
+                }
             }
             $r->internal_redirect($switchto);
         } else {
@@ -865,6 +874,11 @@
                 }
                 if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
                     &set_deeplink_login(%form);
+                } elsif ($firsturl eq '/adm/email') {
+                    if ($form{'display'} && ($form{'mailrecip'} eq "$form{'uname'}:$form{'udom'}")) {
+                        $env{'request.display'} = $form{'display'};
+                        $env{'request.mailrecip'} = $form{'mailrecip'};
+                    }
                 }
                 $r->internal_redirect($switchto);
             } else {
@@ -904,6 +918,11 @@
                 }
                 if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
                     &set_deeplink_login(%form);
+                } elsif ($firsturl eq '/adm/email') {
+                    if ($form{'display'} && ($form{'mailrecip'} eq "$form{'uname'}:$form{'udom'}")) {
+                        $env{'request.display'} = $form{'display'};
+                        $env{'request.mailrecip'} = $form{'mailrecip'};
+                    }
                 }
                 $r->internal_redirect('/adm/switchserver?otherserver='.$unloaded.'&origurl='.$firsturl);
                 return OK;
@@ -923,6 +942,14 @@
                         $form{$item} = $sessiondata{$item};
                     }
                 }
+                if ($sessiondata{'origurl'} eq '/adm/email') {
+                    if (($sessiondata{'display'}) && ($sessiondata{'mailrecip'})) {
+                        if (&unescape($sessiondata{'mailrecip'}) eq "$form{'uname'}:$form{'udom'}") {
+                            $form{'display'} = &unescape($sessiondata{'display'});
+                            $form{'mailrecip'} = &unescape($sessiondata{'mailrecip'});
+                        }
+                    }
+                }
             }
         }
         if ($form{'linkprot'}) {
@@ -1121,6 +1148,11 @@
                      $form);
             if ($form->{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
                 $env{'request.deeplink.login'} = $form->{'firsturl'};
+            } elsif ($form->{'firsturl'} eq '/adm/email') {
+                if ($form->{'display'} && ($form->{'mailrecip'} eq $form->{'uname'}.':'.$form->{'udom'})) {
+                    $env{'request.display'} = $form->{'mailrecip'};
+                    $env{'request.mailrecip'} = $form->{'mailrecip'};
+                }
             }
             if ($form->{'linkprot'}) {
                 $env{'request.linkprot'} = $form->{'linkprot'};
Index: loncom/auth/lonlogin.pm
diff -u loncom/auth/lonlogin.pm:1.203 loncom/auth/lonlogin.pm:1.204
--- loncom/auth/lonlogin.pm:1.203	Tue Aug 30 12:25:03 2022
+++ loncom/auth/lonlogin.pm	Sat Sep 17 23:38:50 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Login Screen
 #
-# $Id: lonlogin.pm,v 1.203 2022/08/30 12:25:03 raeburn Exp $
+# $Id: lonlogin.pm,v 1.204 2022/09/17 23:38:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -50,7 +50,7 @@
 	      $ENV{'REDIRECT_QUERY_STRING'}),
 	 ['interface','username','domain','firsturl','localpath','localres',
 	  'token','role','symb','iptoken','btoken','ltoken','ttoken','linkkey',
-          'saml','sso','retry']); 
+          'saml','sso','retry','display']); 
 
 # -- check if they are a migrating user
     if (defined($env{'form.token'})) {
@@ -175,6 +175,19 @@
             if ($env{'form.symb'}) {
                 $info{'symb'} = $env{'form.symb'};
             }
+            if (($env{'form.firsturl'} eq '/adm/email') && ($env{'form.display'} ne '')) {
+                if ($env{'form.sso'}) {
+                    if ($env{'form.mailrecip'}) {
+                        $info{'display'} = &escape($env{'form.display'});
+                        $info{'mailrecip'} = &escape($env{'form.mailrecip'});
+                    }
+                } else {
+                    if (($env{'form.username'}) && ($env{'form.domain'})) {
+                        $info{'display'} = &escape($env{'form.display'});
+                        $info{'mailrecipient'} = &escape($env{'form.username'}.':'.$env{'form.domain'});
+                    }
+                }
+            }
             my $balancer_token = &Apache::lonnet::tmpput(\%info,$found_server);
             unless (($balancer_token eq 'con_lost') || ($balancer_token eq 'refused') ||
                     ($balancer_token eq 'unknown_cmd') || ($balancer_token eq 'no_such_host')) {
@@ -228,6 +241,11 @@
         $balcookie = $info{'balcookie'};
         &Apache::lonnet::tmpdel($env{'form.btoken'});
         delete($env{'form.btoken'});
+        if (($env{'form.firsturl'} eq '/adm/email') &&
+            (exists($info{'display'})) && (exists($info{'mailrecip'}))) {
+            $env{'form.display'} = &unescape($info{'display'});
+            $env{'form.mailrecip'} = &unescape($info{'mailrecip'});
+        }
     }
 
 #
@@ -339,6 +357,17 @@
         if ($env{'form.ltoken'}) {
             my $delete = &Apache::lonnet::tmpdel($env{'form.ltoken'});
         }
+        if (($env{'form.firsturl'} eq '/adm/email') && ($env{'form.display'})) {
+            if ($env{'form.mailrecip'}) {
+                if ($env{'form.mailrecip'} eq "$env{'user.name'}:$env{'user.domain'}") {
+                    $dest .= (($dest=~/\?/)?'&':'?') . 'display='.&escape($env{'form.display'}).
+                                                           '&mailrecip='.&escape($env{'form.mailrecip'});
+                }
+            } elsif (($env{'form.username'} eq $env{'user.name'}) && ($env{'form.domain'} eq $env{'user.domain'})) {
+                $dest .= (($dest=~/\?/)?'&':'?') . 'display='.&escape($env{'form.display'}).
+                                                       '&mailrecip='.&escape("$env{'user.name'}:$env{'form.domain'}");
+            }
+        }
 	$r->print(
                   $start_page
                  .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
@@ -464,7 +493,7 @@
 
 # -------------------------------------------------------- Store away log token
     my ($tokenextras,$tokentype,$linkprot_for_login);
-    my @names = ('role','symb','iptoken','ltoken','linkprotuser','linkprotexit','linkprot','linkkey');
+    my @names = ('role','symb','iptoken','ltoken','linkprotuser','linkprotexit','linkprot','linkkey','display');
     foreach my $name (@names) {
         if ($env{'form.'.$name} ne '') {
             if ($name eq 'ltoken') {
@@ -480,6 +509,16 @@
                     $tokentype = 'link';
                     last;
                 }
+            } elsif ($env{'form.display'} && ($env{'form.firsturl'} eq '/adm/email')) {
+                if (($env{'form.mailrecip'}) ||
+                    ($env{'form.username'} =~ /^$match_username$/) && ($env{'form.domain'} =~ /^$match_domain$/)) {
+                    $tokenextras .= '&'.$name.'='.&escape($env{'form.display'});
+                    if ($env{'form.mailrecip'}) {
+                        $tokenextras .= '&mailrecip='.&escape($env{'form.mailrecip'});
+                    } else {
+                        $tokenextras .= '&mailrecip='.&escape($env{'form.username'}.':'.$env{'form.domain'});
+                    }
+                }
             } else {
                 $tokenextras .= '&'.$name.'='.&escape($env{'form.'.$name});
                 if (($name eq 'linkkey') || ($name eq 'linkprot')) {
Index: loncom/auth/lonshibauth.pm
diff -u loncom/auth/lonshibauth.pm:1.16 loncom/auth/lonshibauth.pm:1.17
--- loncom/auth/lonshibauth.pm:1.16	Thu Jun 30 21:04:13 2022
+++ loncom/auth/lonshibauth.pm	Sat Sep 17 23:38:50 2022
@@ -2,7 +2,7 @@
 # Redirect Single Sign On authentication to designated URL: 
 # /adm/sso, by default.
 #
-# $Id: lonshibauth.pm,v 1.16 2022/06/30 21:04:13 raeburn Exp $
+# $Id: lonshibauth.pm,v 1.17 2022/09/17 23:38:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -202,6 +202,22 @@
 then the LTI number, type (c or d), and tiny URL will be saved as the
 linkprot item in a token file.
 
+=item set_mailtoken()
+
+Inputs: 2
+$r - request object
+$lonhost - hostID of current server
+
+Output: 1
+$querystring - query string to append to URL
+when redirecting.
+
+Called if requested URL is /adm/email, dual SSO and non-SSO login
+are supported by /adm/login and original query string contains values 
+for elements: display, username and domain, which will then be
+stored in the token file on the server to support direct access
+to a specific message sent to the user.
+
 =back
 
 =cut
@@ -239,7 +255,13 @@
         }
         my $dest = $protocol.'://'.$hostname.$target;
         if ($target eq '/adm/login') {
-             my $querystring = &set_token($r,$lonhost);
+             my $uri = $r->uri;
+             my $querystring;
+             if (($uri eq '/adm/email') && ($r->args ne '')) {
+                 $querystring = &set_mailtoken($r,$lonhost);
+             } else {
+                 $querystring = &set_token($r,$lonhost);
+             }
              if ($querystring ne '') {
                  $dest .= '?'.$querystring;
              }
@@ -250,6 +272,12 @@
                 if ($querystring ne '') {
                     $dest .= '?'.$querystring;
                 }
+            } elsif ((&Apache::lonnet::get_saml_landing()) &&
+                     ($uri eq '/adm/email') && ($r->args ne '')) {
+                my $querystring = &set_mailtoken($r,$lonhost);
+                if ($querystring ne '') {
+                    $dest .= '?'.$querystring;
+                }
             } else {
                 if ($r->args ne '') {
                     $dest .= (($dest=~/\?/)?'&':'?').$r->args;
@@ -336,5 +364,35 @@
     return $querystring;
 }
 
+sub set_mailtoken {
+    my ($r,$lonhost) = @_;
+    my $firsturl = $r->uri;
+    my ($querystring,$ssotoken,$extras);
+    &Apache::loncommon::get_unprocessed_cgi($r->args);
+    my $extras;
+    if (($env{'form.display'} ne '') &&
+        ($env{'form.username'} =~ /^$match_username$/) &&
+        ($env{'form.domain'} =~ /^$match_domain$/)) {  
+        $extras .= '&display='.&escape($env{'form.display'}).
+                   '&mailrecip='.&escape($env{'form.username'}.':'.$env{'form.domain'});
+    }
+    if (($firsturl ne '') || ($extras ne '')) {
+        $extras .= ':sso';
+        $ssotoken = &Apache::lonnet::reply('tmpput:'.&escape($firsturl).
+                                           $extras,$lonhost);
+        $querystring = 'sso='.$ssotoken;
+    }
+    if ($r->args ne '') {
+        foreach my $key (sort(keys(%env))) {
+            if ($key =~ /^form\.(.+)$/) {
+                my $name = $1;
+                next if (($name eq 'display') || ($name eq 'username') || ($name eq 'domain'));
+                $querystring .= '&'.$name.'='.$env{$key};
+            }
+        }
+    }
+    return $querystring;
+}
+
 1;
 __END__
Index: loncom/auth/migrateuser.pm
diff -u loncom/auth/migrateuser.pm:1.65 loncom/auth/migrateuser.pm:1.66
--- loncom/auth/migrateuser.pm:1.65	Wed Aug 24 20:58:50 2022
+++ loncom/auth/migrateuser.pm	Sat Sep 17 23:38:50 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Starts a user off based of an existing token.
 #
-# $Id: migrateuser.pm,v 1.65 2022/08/24 20:58:50 raeburn Exp $
+# $Id: migrateuser.pm,v 1.66 2022/09/17 23:38:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -295,6 +295,14 @@
                 $info{$name} = $dataref->{$name};
             }
         }
+        if ($info{'origurl'} eq '/adm/email') {
+            if (($dataref->{'display'}) && ($dataref->{'mailrecip'})) {
+                if (&unescape($dataref->{'mailrecip'}) eq $dataref->{'username'}.':'.$dataref->{'domain'}) {
+                    $info{'display'} = $dataref->{'display'};
+                    $info{'mailrecip'} = $dataref->{'mailrecip'};
+                }
+            }
+        }
         my $iptoken = &Apache::lonnet::tmpput(\%info,$switchto,'link');
         unless ($iptoken eq 'conlost') {
             $url .= (($url =~ /\?/) ? '&' : '?') . 'iptoken='.$iptoken;
@@ -996,6 +1004,13 @@
                         $extra_env = {'request.deeplink.login' => $data{'deeplink.login'}};
                     }
                 }
+                if ($desturl eq '/adm/email') {
+                    if (($data{'display'}) && ($data{'mailrecip'})) {
+                        if (&unescape($data{'mailrecip'}) eq "$data{'username'}:$data{'domain'}") {
+                            $form{'display'} = &unescape($data{'display'});
+                        }
+                    }
+                }
             }
             my $skipcritical;
             if ($data{'lti.login'}) {
Index: loncom/auth/switchserver.pm
diff -u loncom/auth/switchserver.pm:1.63 loncom/auth/switchserver.pm:1.64
--- loncom/auth/switchserver.pm:1.63	Tue Sep 13 12:22:14 2022
+++ loncom/auth/switchserver.pm	Sat Sep 17 23:38:50 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Switch Servers Handler
 #
-# $Id: switchserver.pm,v 1.63 2022/09/13 12:22:14 raeburn Exp $
+# $Id: switchserver.pm,v 1.64 2022/09/17 23:38:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -330,6 +330,12 @@
     }
     if ($env{'form.origurl'}) {
         $info{'origurl'} = $env{'form.origurl'};
+        if ($env{'form.origurl'} eq '/adm/email') {
+            if ($env{'request.display'} && ($env{'request.mailrecip'} eq "$env{'user.name'}:$env{'user.domain'}")) {
+                $info{'display'} = &escape($env{'request.display'});
+                $info{'mailrecip'} = &escape($env{'request.mailrecip'});
+            }
+        }
     }
     if ($env{'form.symb'}) {
         $info{'symb'} = $env{'form.symb'};
Index: loncom/interface/lonmsgdisplay.pm
diff -u loncom/interface/lonmsgdisplay.pm:1.197 loncom/interface/lonmsgdisplay.pm:1.198
--- loncom/interface/lonmsgdisplay.pm:1.197	Wed Jan 19 15:04:15 2022
+++ loncom/interface/lonmsgdisplay.pm	Sat Sep 17 23:38:51 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging display
 #
-# $Id: lonmsgdisplay.pm,v 1.197 2022/01/19 15:04:15 raeburn Exp $
+# $Id: lonmsgdisplay.pm,v 1.198 2022/09/17 23:38:51 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3264,9 +3264,24 @@
          'sendreply','compose','sendmail','critical','recname','recdom',
          'recordftf','sortedby','folder','startdis','interdis',
 	 'showcommentbaseurl','dismode','group','subject','text','ref',
-         'msgstatus']);
+         'msgstatus','btoken']);
     $sqs='&sortedby='.$env{'form.sortedby'};
 
+# ----------- Check if access was from balancer to server with existing session
+
+    if ($env{'form.btoken'}) {
+        my %info = &Apache::lonnet::tmpget($env{'form.btoken'});
+        &Apache::lonnet::tmpdel($env{'form.btoken'});
+        delete($env{'form.btoken'});
+        unless ($env{'form.display'}) {
+            if (($info{'display'}) && ($info{'mailrecip'})) {
+                if (&unescape($info{'mailrecip'}) eq $env{'user.name'}.':'.$env{'user.domain'}) {
+                    $env{'form.display'} = &unescape($info{'display'});
+                }
+            }
+        }
+    }
+
 # ------------------------------------------------------ They checked for email
     &Apache::lonnet::put('email_status',{'recnewemail'=>0});
 


More information about the LON-CAPA-cvs mailing list