[LON-CAPA-cvs] cvs: loncom /auth lonacc.pm lonauth.pm lonlogin.pm lonrelaunch.pm migrateuser.pm switchserver.pm /interface domainprefs.pm loncommon.pm

raeburn raeburn at source.lon-capa.org
Wed Aug 24 16:58:50 EDT 2022


raeburn		Wed Aug 24 20:58:50 2022 EDT

  Modified files:              
    /loncom/auth	lonacc.pm lonauth.pm lonlogin.pm lonrelaunch.pm 
                	migrateuser.pm switchserver.pm 
    /loncom/interface	domainprefs.pm loncommon.pm 
  Log:
  - Dual SSO and non-SSO login from /adm/login
    - Display of domain configuration for each server split into two tables
      so input textboxes can be longer.
    - "Pop-up if iframe" (Y/N) item added.  If Y, when login page is in an
      iframe, SSO log-in dialog will be displayed in a new window, i.e.,
      not within the iframe, e.g., to satisfy sameorigin requirement in
      x-frame-options in header sent by SSO server.
  
  
-------------- next part --------------
Index: loncom/auth/lonacc.pm
diff -u loncom/auth/lonacc.pm:1.205 loncom/auth/lonacc.pm:1.206
--- loncom/auth/lonacc.pm:1.205	Thu Jun 30 21:04:13 2022
+++ loncom/auth/lonacc.pm	Wed Aug 24 20:58:50 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Cookie Based Access Handler
 #
-# $Id: lonacc.pm,v 1.205 2022/06/30 21:04:13 raeburn Exp $
+# $Id: lonacc.pm,v 1.206 2022/08/24 20:58:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -315,7 +315,7 @@
     my %form;
     if ($query) {
         my @items = ('role','symb','iptoken','origurl','ttoken',
-                     'ltoken','linkkey','logtoken','sso');
+                     'ltoken','linkkey','logtoken','sso','lcssowin');
         &Apache::loncommon::get_unprocessed_cgi($query,\@items);
         foreach my $item (@items) {
             if (defined($env{'form.'.$item})) {
@@ -465,6 +465,9 @@
                            linkprotuser => $linkprotuser,
                            linkprotexit => $linkprotexit,
                        );
+            if ($env{'form.lcssowin'}) {
+                $data{'lcssowin'} = $env{'form.lcssowin'};
+            }
             my $token = &Apache::lonnet::tmpput(\%data,$r->dir_config('lonHostID'),'link');
             unless (($token eq 'con_lost') || ($token eq 'refused') || ($token =~ /^error:/) ||
                     ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
@@ -546,6 +549,9 @@
             if ($otherserver ne '') {
                 $redirecturl .= '?otherserver='.$otherserver;
             }
+            if ($form{'lcssowin'}) {
+                $redirecturl .= (($redirecturl=~/\?/)?'&':'?') . 'lcssowin=1';
+            }
 	    $r->internal_redirect($redirecturl);
 	    $r->set_handlers('PerlHandler'=> undef);
 	} else {
@@ -558,7 +564,7 @@
 		      'server'    => $r->dir_config('lonHostID'),
 		      'sso.login' => 1
 		      );
-            foreach my $item ('role','symb','iptoken','origurl') {
+            foreach my $item ('role','symb','iptoken','origurl','lcssowin') {
                 if (exists($form{$item})) {
                     $info{$item} = $form{$item};
                 } elsif ($sessiondata{$item} ne '') {
@@ -624,7 +630,7 @@
             $r->subprocess_env->set('SSOUserDomain' => $domain);
             if (grep(/^sso$/, at cancreate)) {
 #FIXME - need to preserve origurl, role and symb, or linkprot or linkkey for use after account
-# creation
+# creation. If lcssowin is 1, createaccount needs to close pop-up and display in main window.
                 $r->set_handlers('PerlHandler'=> [\&Apache::createaccount::handler]);
                 $r->handler('perl-script');
             } else {
Index: loncom/auth/lonauth.pm
diff -u loncom/auth/lonauth.pm:1.176 loncom/auth/lonauth.pm:1.177
--- loncom/auth/lonauth.pm:1.176	Thu Jun 30 21:04:13 2022
+++ loncom/auth/lonauth.pm	Wed Aug 24 20:58:50 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # User Authentication Module
 #
-# $Id: lonauth.pm,v 1.176 2022/06/30 21:04:13 raeburn Exp $
+# $Id: lonauth.pm,v 1.177 2022/08/24 20:58:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -47,7 +47,7 @@
 # ------------------------------------------------------------ Successful login
 sub success {
     my ($r, $username, $domain, $authhost, $lowerurl, $extra_env,
-	$form,$skipcritical,$cid,$expirepub) = @_;
+	$form,$skipcritical,$cid,$expirepub,$write_to_opener) = @_;
 
 # ------------------------------------------------------------ Get cookie ready
     my $cookie =
@@ -280,7 +280,7 @@
         }
         $start_page=&Apache::loncommon::start_page('',$js,$args);
     } else {
-        $args->{'redirect'} = [0,$destination];
+        $args->{'redirect'} = [0,$destination,'',$write_to_opener];
         $start_page=&Apache::loncommon::start_page('Successful Login',
                                                    $js,$args);
         unless ($env{'request.linkprot'}) {
Index: loncom/auth/lonlogin.pm
diff -u loncom/auth/lonlogin.pm:1.201 loncom/auth/lonlogin.pm:1.202
--- loncom/auth/lonlogin.pm:1.201	Thu Jun 30 21:04:13 2022
+++ loncom/auth/lonlogin.pm	Wed Aug 24 20:58:50 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Login Screen
 #
-# $Id: lonlogin.pm,v 1.201 2022/06/30 21:04:13 raeburn Exp $
+# $Id: lonlogin.pm,v 1.202 2022/08/24 20:58:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -664,7 +664,8 @@
 ENDSCRIPT
 
     my ($lonhost_in_use, at hosts,%defaultdomconf,$saml_prefix,$saml_landing,
-        $samlssotext,$samlnonsso,$samlssoimg,$samlssoalt,$samlssourl,$samltooltip);
+        $samlssotext,$samlnonsso,$samlssoimg,$samlssoalt,$samlssourl,$samltooltip,
+        $samlnoframe,$samlwindow);
     %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
     @hosts = &Apache::lonnet::current_machine_ids();
     $lonhost_in_use = $lonhost;
@@ -685,6 +686,7 @@
         $samlssoalt = $defaultdomconf{$saml_prefix.'alt_'.$lonhost_in_use};
         $samlssourl = $defaultdomconf{$saml_prefix.'url_'.$lonhost_in_use};
         $samltooltip = $defaultdomconf{$saml_prefix.'title_'.$lonhost_in_use};
+        $samlwindow = $defaultdomconf{$saml_prefix.'window_'.$lonhost_in_use};
     }
     if ($saml_landing) {
        if ($samlssotext eq '') {
@@ -872,6 +874,7 @@
 
     my $stdauthformstyle = 'inline-block';
     my $ssoauthstyle = 'none';
+    my $sso_onclick;
     my $logintype;
     $r->print('<div style="float:left;margin-top:0;">');
     if ($saml_landing) {
@@ -882,6 +885,8 @@
         if ($samlssourl  ne '') {
             $ssologin = $samlssourl;
         }
+        my $ssologin_for_js = &js_escape($ssologin);
+        my $querystr_for_js;
         if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
             my $querystring;
             if ($env{'form.firsturl'} ne '') {
@@ -902,16 +907,44 @@
             }
             if ($querystring ne '') {
                 $ssologin .= (($ssologin=~/\?/)?'&':'?') . $querystring;
+                $querystr_for_js = &js_escape($querystring);
             }
         } elsif ($logtoken ne '') {
             $ssologin .= (($ssologin=~/\?/)?'&':'?') . 'logtoken='.$logtoken;
+            $querystr_for_js = &js_escape('logtoken='.$logtoken);
         }
         my $ssohref;
+        if ($samlwindow) {
+            $sso_onclick = <<"ENDJS";
+if (document.getElementById('LC_sso_login_link')) {
+    var ssoelem = document.getElementById('LC_sso_login_link')
+    ssoelem.addEventListener('click',samlWinFunction,false);
+    var windows = {};
+    function samlWinFunction(evt) {
+        evt.preventDefault();
+        var url = '$ssologin_for_js';
+        var name = 'lcssowin';
+        var querystr = '$querystr_for_js';
+        if (querystr) {
+            url += '?'+querystr+'&lcssowin=1';
+        } else {
+            url += '?lcssowin=1';
+        }
+        if ((typeof windows[name] !== 'undefined') && (!windows[name].closed)) {
+            windows[name].close();
+        }
+        windows[name]=window.open(url,name,'width=350,height=600');
+        windows[name].focus();
+        return false;
+    }
+}
+ENDJS
+        }
         if ($samlssoimg ne '') {
-            $ssohref = '<a href="'.$ssologin.'" title="'.$samltooltip.'">'.
+            $ssohref = '<a href="'.$ssologin.'" title="'.$samltooltip.'" id="LC_sso_login_link">'.
                        '<img src="'.$samlssoimg.'" alt="'.$samlssoalt.'" id="lcssobutton" /></a>';
         } else {
-            $ssohref = '<a href="'.$ssologin.'">'.$samlssotext.'</a>';
+            $ssohref = '<a href="'.$ssologin.'" id="LC_sso_login_link">'.$samlssotext.'</a>';
         }
         if (($env{'form.saml'} eq 'no') ||
             (($env{'form.username'} ne '') && ($env{'form.domain'} ne ''))) {
@@ -966,11 +999,22 @@
 // <![CDATA[
 if ((window.self !== window.top) && (document.server.target != '_self')) {
     $set_target
+    $sso_onclick
 }
 // ]]>
 </script>
 ENDJS
         }
+    } elsif ($samlwindow) {
+        $in_frame_js = <<ENDJS;
+<script type="text/javascript">
+// <![CDATA[
+if ((window.self !== window.top) && (document.server.target != '_self')) {
+    $sso_onclick
+}
+// ]]>
+</script>
+ENDJS
     }
 
     $r->print(<<ENDLOGIN);
Index: loncom/auth/lonrelaunch.pm
diff -u loncom/auth/lonrelaunch.pm:1.3 loncom/auth/lonrelaunch.pm:1.4
--- loncom/auth/lonrelaunch.pm:1.3	Sun Jun 26 18:17:01 2022
+++ loncom/auth/lonrelaunch.pm	Wed Aug 24 20:58:50 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Re-launch guidance for deep linked access with username mismatch
 #
-# $Id: lonrelaunch.pm,v 1.3 2022/06/26 18:17:01 raeburn Exp $
+# $Id: lonrelaunch.pm,v 1.4 2022/08/24 20:58:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -91,22 +91,26 @@
                 $url .= '?ltoken='.$env{'form.rtoken'};
                 $r->print(&Apache::loncommon::start_page('Updating session',undef,
                                                          {'only_body'    => 1,
-                                                          'redirect'     => [1,$url]}).
+                                                          'redirect'     => [1,$url,'',$data{'lcssowin'}]}).
                           '<p>'.&mt('Updating old session information').'</p>'.
                           &Apache::loncommon::end_page());
                 return OK;
             }
         }
     }
+    my $args = {'only_body' => 1};
+    if ($data{'lcssowin'}) {
+        $args->{'redirect'} = [1,$data{'origurl'},'',$data{'lcssowin'}];
+    }
     if ($data{'linkprot'}) {
-        $r->print(&Apache::loncommon::start_page('Updating session',undef,{'only_body' => 1}));
+        $r->print(&Apache::loncommon::start_page('Updating session',undef,$args));
         if ($data{'linkprotuser'} ne '') {
             $r->print(&mt('Although your credentials were authenticated, the username you entered did not match what was expected [_1] from the link you followed',"($data{'linkprotuser'})"));
         } else {
             $r->print(&mt('Expired any existing session'));
         }
     } else {
-        $r->print(&Apache::loncommon::start_page('Session removed',undef,{'only_body' => 1}));
+        $r->print(&Apache::loncommon::start_page('Session removed',undef,$args));
         $r->print(&mt('Expired any existing session'));
     }
     $r->print(&Apache::loncommon::end_page());
Index: loncom/auth/migrateuser.pm
diff -u loncom/auth/migrateuser.pm:1.64 loncom/auth/migrateuser.pm:1.65
--- loncom/auth/migrateuser.pm:1.64	Sat Jul  2 19:55:15 2022
+++ loncom/auth/migrateuser.pm	Wed Aug 24 20:58:50 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Starts a user off based of an existing token.
 #
-# $Id: migrateuser.pm,v 1.64 2022/07/02 19:55:15 raeburn Exp $
+# $Id: migrateuser.pm,v 1.65 2022/08/24 20:58:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -42,6 +42,10 @@
 
 sub goto_login {
     my ($r,$domain,$data) = @_;
+    my $write_to_opener;
+    if (ref($data) eq 'HASH') {
+        $write_to_opener = $data->{'lcssowin'};
+    }
     if ((ref($data) eq 'HASH') && ($data->{'lti.login'})) {
         &Apache::ltiauth::invalid_request($r,'22');
     } else {
@@ -52,7 +56,7 @@
             $url .= '?domain='.$domain;
         }
         $r->print(&Apache::loncommon::start_page('Going to login',undef,
-					         {'redirect' => [0,$url],}).
+					         {'redirect' => [0,$url,'',$write_to_opener],}).
 	          '<h1>'.&mt('One moment please...').'</h1>'.
 	          '<p>'.&mt('Transferring to login page.').'</p>'.
 	          &Apache::loncommon::end_page());
@@ -297,7 +301,7 @@
         }
         $r->print(&Apache::loncommon::start_page($title,undef,
                                                  {'redirect' =>
-                                                  [2,$url],}).
+                                                  [2,$url,'',$dataref->{'lcssowin'}],}).
                   '<h1>'.&mt('One moment please...').'</h1>'.
                   '<p class="LC_warning">'.$message.'</p>'.
                   &Apache::loncommon::end_page());
@@ -336,7 +340,7 @@
         $r->headers_out->add('Set-cookie' => $c);
     }
     my $lonhost = $r->dir_config('lonHostID');
-    my ($url,$token,$delay,%info,%user_info);
+    my ($url,$token,$delay,$write_to_opener,%info,%user_info);
     if (ref($data) eq 'HASH') {
         %user_info=('ip'       => $ip,
                     'domain'   => $data->{'domain'},
@@ -346,6 +350,7 @@
                     'origurl'  => $data->{'origurl'},
                     'symb'     => $data->{'symb'},
                     'server'   => $lonhost);
+        $write_to_opener = $data->{'lcssowin'};
     }
     $delay = 0.1;
     if (ref($linkprot_info) eq 'HASH') {
@@ -379,7 +384,7 @@
     $r->send_http_header;
     $r->print(
         &Apache::loncommon::start_page('Updating Session ...',undef,
-                                       {'redirect'       => [$delay,$url],
+                                       {'redirect'       => [$delay,$url,'',$write_to_opener],
                                         'only_body'      => 1,}).
         &Apache::loncommon::end_page());
     if ($env{'request.balancercookie'}) {
@@ -1002,7 +1007,7 @@
             }
 	    &Apache::lonauth::success($r,$data{'username'},$data{'domain'},
 				      $home,$desturl,$extra_env,\%form,$skipcritical,'',
-                                      $expirepub);
+                                      $expirepub,$data{'lcssowin'});
 	}
 	return OK;
     }
@@ -1083,7 +1088,7 @@
             }
         }
         &Apache::lonauth::success($r,$data{'username'},$data{'domain'},$home,
-                                  $next_url,$extra_env,\%form,'',$cid);
+                                  $next_url,$extra_env,\%form,'',$cid,'',$data{'lcssowin'});
     }
     return OK;
 }
Index: loncom/auth/switchserver.pm
diff -u loncom/auth/switchserver.pm:1.61 loncom/auth/switchserver.pm:1.62
--- loncom/auth/switchserver.pm:1.61	Thu Jun 30 21:04:13 2022
+++ loncom/auth/switchserver.pm	Wed Aug 24 20:58:50 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Switch Servers Handler
 #
-# $Id: switchserver.pm,v 1.61 2022/06/30 21:04:13 raeburn Exp $
+# $Id: switchserver.pm,v 1.62 2022/08/24 20:58:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -54,7 +54,7 @@
 }
 
 sub do_redirect {
-    my ($r,$url,$only_body,$extra_text) = @_;
+    my ($r,$url,$only_body,$extra_text,$write_to_opener) = @_;
     $r->send_http_header;
     my $delay = 0.5;
     if ($only_body && !$extra_text) {
@@ -62,7 +62,7 @@
     }
     my $start_page = 
 	&Apache::loncommon::start_page('Switching Server ...',undef,
-				       {'redirect'       => [$delay,$url],
+				       {'redirect'       => [$delay,$url,'',$write_to_opener],
 					'only_body'      => $only_body,});
     my $end_page   = &Apache::loncommon::end_page();
     $r->print($start_page.$extra_text.$end_page);
@@ -102,7 +102,7 @@
     if (!defined($handle)) { return FORBIDDEN; }
 
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
-				['otherserver','role','origurl','symb']);
+				['otherserver','role','origurl','symb','lcssowin']);
 
     my $switch_to=&Apache::lonnet::hostname($env{'form.otherserver'});
     if (! $env{'form.otherserver'}) {
@@ -291,7 +291,8 @@
     if ($env{'form.symb'}) {
         $info{'symb'} = $env{'form.symb'};
     }
-    my $ssologoutscript = ''; 
+    my $ssologoutscript = '';
+    my $write_to_opener;
     if ($env{'request.sso.login'}) {
 	$info{'sso.login'} = $env{'request.sso.login'};
         if (defined($r->dir_config("lonSSOUserLogoutScriptFile_$info{domain}"))) {
@@ -357,12 +358,18 @@
         $info{'lti.target'} = $env{'request.lti.target'};
     }
     my $token = &Apache::lonnet::tmpput(\%info,$env{'form.otherserver'});
-    my $url =$protocol.'://'.$switch_to.'/adm/login?'.
-	'domain='.$env{'user.domain'}.
-	'&username='.$env{'user.name'}.
-	'&token='.$token;
+    my @args = ("domain=$env{'user.domain'}",
+                "username=$env{'user.name'}",
+                "token=$token");
+    my $url = $protocol.'://'.$switch_to.'/adm/login?';
+    if ($env{'form.lcssowin'}) {
+        $url .= join('&', at args);
+        $only_body = 1;
+    } else {
+        $url .= join('&', at args);
+    }
 # --------------------------------------------------------------- Screen Output
-    return &do_redirect($r, $url, $only_body, $ssologoutscript);
+    return &do_redirect($r, $url, $only_body, $ssologoutscript, $env{'form.lcssowin'});
 }
 
 1;
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.411 loncom/interface/domainprefs.pm:1.412
--- loncom/interface/domainprefs.pm:1.411	Tue Jul 26 01:11:43 2022
+++ loncom/interface/domainprefs.pm	Wed Aug 24 20:58:50 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.411 2022/07/26 01:11:43 raeburn Exp $
+# $Id: domainprefs.pm,v 1.412 2022/08/24 20:58:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1628,7 +1628,7 @@
                       '<table><tr><th>'.$choices{'hostid'}.'</th>'.
                       '<th>'.$choices{'samllanding'}.'</th>'.
                       '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
-        my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso,%styleon,%styleoff);
+        my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
         foreach my $lonhost (keys(%domservers)) {
             $samlurl{$lonhost} = '/adm/sso';
             $styleon{$lonhost} = 'display:none';
@@ -1643,6 +1643,7 @@
                     $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
                     $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
                     $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
+                    $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
                     $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
                     $styleon{$lonhost} = '';
                     $styleoff{$lonhost} = 'display:none';
@@ -1660,6 +1661,12 @@
                 $samlon = $samloff;
                 $samloff = ' ';
             }
+            my $samlwinon = '';
+            my $samlwinoff = ' checked="checked"';
+            if ($samlwindow{$lonhost}) {
+                $samlwinon = $samlwinoff;
+                $samlwinoff = '';
+            }
             my $css_class = $itemcount%2?' class="LC_odd_row"':'';
             $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
                           '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
@@ -1669,12 +1676,10 @@
                           'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
                           &mt('Yes').'</label></span></td>'.
                           '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
-                          '<table><tr><th colspan="5" align="center">'.&mt('SSO').'</th><th align="center">'.
-                          '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
+                          '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
                           '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
-                          '<th>'.&mt('Alt Text').'</th><th>'.&mt('URL').'</th>'.
-                          '<th>'.&mt('Tool Tip').'</th><th>'.&mt('Text').'</th></tr>'.
-                          '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="8" value="'.
+                          '<th>'.&mt('Alt Text').'</th></tr>'.
+                          '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
                           $samltext{$lonhost}.'" /></td><td>';
             if ($samlimg{$lonhost}) {
                 $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
@@ -1691,13 +1696,21 @@
                 $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
             }
             $datatable .= '</td>'.
-                          '<td><input type="text" name="saml_alt_'.$lonhost.'" size="20" '.
-                          'value="'.$samlalt{$lonhost}.'" /></td>'.
-                          '<td><input type="text" name="saml_url_'.$lonhost.'" size="8" '.
+                          '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
+                          'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
+                          '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
+                          '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
+                          '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
+                          '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
+                          '<tr'.$css_class.'>'.
+                          '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
                           'value="'.$samlurl{$lonhost}.'" /></td>'.
-                          '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="15">'.
+                          '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
                           $samltitle{$lonhost}.'</textarea></td>'.
-                          '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="8" '.
+                          '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
+                          &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
+                          'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
+                          '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
                           'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
                           '</table></td>'.
                           '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
@@ -12254,7 +12267,7 @@
     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
         %curr_loginvia,%loginhash, at currlangs, at newlangs,$addedfile,%title, at offon,
-        %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
+        %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
     %title = ( coursecatalog => 'Display course catalog',
                adminmail => 'Display administrator E-mail address',
                helpdesk  => 'Display "Contact Helpdesk" link',
@@ -12278,6 +12291,7 @@
                     $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
                     $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
                     $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
+                    $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
                     $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
                 }
             }
@@ -12535,10 +12549,13 @@
             if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
                 push(@newsamlimgs,$lonhost);
             }
-            foreach my $item ('text','alt','url','title','notsso') {
+            foreach my $item ('text','alt','url','title','window','notsso') {
                 $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
             }
             if ($saml{$lonhost}) {
+                if ($env{'form.saml_window_'.$lonhost} ne '1') {
+                    $env{'form.saml_window_'.$lonhost} = '';
+                }
                 if (grep(/^\Q$lonhost\E$/, at delsamlimg)) {
 #FIXME Need to obsolete published image
                     delete($currsaml{$lonhost}{'img'});
@@ -12556,13 +12573,16 @@
                 if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
                     $changes{'saml'}{$lonhost} = 1;
                 }
+                if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
+                    $changes{'saml'}{$lonhost} = 1;
+                }
                 if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
                     $changes{'saml'}{$lonhost} = 1;
                 }
             } else {
                 $changes{'saml'}{$lonhost} = 1;
             }
-            foreach my $item ('text','alt','url','title','notsso') {
+            foreach my $item ('text','alt','url','title','window','notsso') {
                 $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
             }
         } else {
@@ -12763,19 +12783,22 @@
                                        alt    => 'Alt text for button image',
                                        url    => 'SSO URL',
                                        title  => 'Tooltip for SSO link',
+                                       window => 'Pop-up window if iframe',
                                        notsso => 'Text for non-SSO log-in',
                                     );
                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                             if (ref($currsaml{$lonhost}) eq 'HASH') {
                                 $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
                                                '<ul>';
-                                foreach my $key ('text','img','alt','url','title','notsso') {
+                                foreach my $key ('text','img','alt','url','title','window','notsso') {
                                     if ($currsaml{$lonhost}{$key} eq '') {
                                         $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
                                     } else {
                                         my $value = "'$currsaml{$lonhost}{$key}'";
                                         if ($key eq 'img') {
                                             $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
+                                        } elsif ($key eq 'window') {
+                                            $value = 'On';
                                         }
                                         $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
                                                                   $value).'</li>';
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1385 loncom/interface/loncommon.pm:1.1386
--- loncom/interface/loncommon.pm:1.1385	Thu Jun 30 21:04:14 2022
+++ loncom/interface/loncommon.pm	Wed Aug 24 20:58:50 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1385 2022/06/30 21:04:14 raeburn Exp $
+# $Id: loncommon.pm,v 1.1386 2022/08/24 20:58:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -5998,7 +5998,7 @@
                                 foreach my $host (keys(%{$domconfig{'login'}{$key}})) {
                                     if (ref($domconfig{'login'}{$key}{$host}) eq 'HASH') {
                                         $designhash{$udom.'.login.'.$key.'_'.$host} = 1;
-                                        foreach my $item ('text','img','alt','url','title','notsso') {
+                                        foreach my $item ('text','img','alt','url','title','window','notsso') {
                                             $designhash{$udom.'.login.'.$key.'_'.$item.'_'.$host} = $domconfig{'login'}{$key}{$host}{$item};
                                         }
                                     }
@@ -6674,8 +6674,38 @@
     }
     if ( exists( $env{'internal.head.redirect'} ) ) {
         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
+            my ($endbodyjs,$idattr);
+            if ($env{'internal.head.to_opener'}) {
+                my $linkid = 'LC_continue_link';
+                $idattr = ' id="'.$linkid.'"';
+                my $redirect_for_js = &js_escape($env{'internal.head.redirect'});
+                $endbodyjs=<<ENDJS;
+<script type="text/javascript">
+// <![CDATA[
+function ebFunction(evt) {
+    evt.preventDefault();
+    var dest = '$redirect_for_js';
+    if (window.opener != null && !window.opener.closed) {
+        window.opener.location.href=dest;
+        window.close();
+    } else {
+        window.location.href=dest;
+    }
+    return false;
+}
+
+\$(document).ready(function () {
+  if (document.getElementById('$linkid')) {
+    var clickelem = document.getElementById('$linkid');
+    clickelem.addEventListener('click',ebFunction,false);
+  }
+});
+// ]]>
+</script>
+ENDJS
+            }
 	    $endbodytag=
-	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
+	        "$endbodyjs<br /><a href=\"$env{'internal.head.redirect'}\"$idattr>".
 	        &mt('Continue').'</a>'.
 	        $endbodytag;
         }
@@ -8845,7 +8875,12 @@
                                    3- whether the side effect should occur
                            (side effect of setting 
                                $env{'internal.head.redirect'} to the url 
-                               redirected too)
+                               redirected to)
+                                   4- whether the redirect target should be
+                                      the opener of the current (pop-up)
+                                      window (side effect of setting
+                                      $env{'internal.head.to_opener'} to
+                                      1, if true.
             domain         -> force to color decorate a page for a specific
                                domain
             function       -> force usage of a specific rolish color scheme
@@ -8908,15 +8943,43 @@
         }
     }
     if (ref($args->{'redirect'})) {
-	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
+	my ($time,$url,$inhibit_continue,$to_opener) = @{$args->{'redirect'}};
 	$url = &Apache::lonenc::check_encrypt($url);
 	if (!$inhibit_continue) {
 	    $env{'internal.head.redirect'} = $url;
 	}
-	$result.=<<ADDMETA
+	$result.=<<"ADDMETA";
 <meta http-equiv="pragma" content="no-cache" />
+ADDMETA
+        if ($to_opener) {
+            $env{'internal.head.to_opener'} = 1;
+            my $dest = &js_escape($url);
+            my $timeout = int($time * 1000);
+            $result .=<<"ENDJS";
+<script type="text/javascript">
+// <![CDATA[
+function LC_To_Opener() {
+    var dest = '$dest';
+    if (dest != '') {
+        if (window.opener != null && !window.opener.closed) {
+            window.opener.location.href=dest;
+            window.close();
+        } else {
+            window.location.href=dest;
+        }
+    }
+}
+\$(document).ready(function () {
+    setTimeout('LC_To_Opener()',$timeout);
+});
+// ]]>
+</script>
+ENDJS
+        } else {
+            $result.=<<"ADDMETA";
 <meta http-equiv="Refresh" content="$time; url=$url" />
 ADDMETA
+        }
     } else {
         unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
             my $requrl = $env{'request.uri'};


More information about the LON-CAPA-cvs mailing list