[LON-CAPA-cvs] cvs: loncom /auth lonlogin.pm /interface domainprefs.pm loncommon.pm

raeburn raeburn at source.lon-capa.org
Tue Mar 3 17:06:55 EST 2015


raeburn		Tue Mar  3 22:06:55 2015 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm loncommon.pm 
    /loncom/auth	lonlogin.pm 
  Log:
  - Domain configuration to accommodate inclusion of custom HTML mark-up in
    head block of log-in page (e.g., javascript for analytics) for each server
    in a domain.
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.255 loncom/interface/domainprefs.pm:1.256
--- loncom/interface/domainprefs.pm:1.255	Mon Oct  6 21:08:03 2014
+++ loncom/interface/domainprefs.pm	Tue Mar  3 22:06:50 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.255 2014/10/06 21:08:03 raeburn Exp $
+# $Id: domainprefs.pm,v 1.256 2015/03/03 22:06:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -250,6 +250,8 @@
                       header => [{col1 => 'Log-in Page Items',
                                   col2 => '',},
                                  {col1 => 'Log-in Help',
+                                  col2 => 'Value'},
+                                 {col1 => 'Custom HTML in document head',
                                   col2 => 'Value'}],
                       print => \&print_login,
                       modify => \&modify_login,
@@ -479,6 +481,8 @@
                                        {col1 => 'Log-in Page Items',
                                         col2 => ''},
                                        {col1 => 'Log-in Help',
+                                        col2 => 'Value'},
+                                       {col1 => 'Custom HTML in document head',
                                         col2 => 'Value'}],
                             print => \&print_login,
                             modify => \&modify_login,
@@ -670,7 +674,7 @@
         my $colspan = '';
         my $rightcolspan = '';
         if (($action eq 'rolecolors') || ($action eq 'defaults') ||
-            (($action eq 'login') && ($numheaders < 3))) {
+            (($action eq 'login') && ($numheaders < 4))) {
             $colspan = ' colspan="2"';
         }
         if ($action eq 'usersessions') {
@@ -692,7 +696,7 @@
         } elsif ($action eq 'coursecategories') {
             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
         } elsif ($action eq 'login') {
-            if ($numheaders == 3) {
+            if ($numheaders == 4) {
                 $colspan = ' colspan="2"';
                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
             } else {
@@ -745,7 +749,7 @@
                   ($action eq 'defaults')) {
             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
         } elsif ($action eq 'login') {
-            if ($numheaders == 3) {
+            if ($numheaders == 4) {
                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
            </table>
           </td>
@@ -761,6 +765,27 @@
             } else {
                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
             }
+            $output .= '
+           </table>
+          </td>
+         </tr>
+         <tr>
+           <td>
+            <table class="LC_nested">
+             <tr class="LC_info_row">';
+            if ($numheaders == 4) {
+                $output .= '
+              <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
+              <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
+             </tr>';
+            } else {
+                $output .= '
+              <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
+              <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
+             </tr>';
+            }
+            $rowtotal ++;
+            $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
         } elsif ($action eq 'requestcourses') {
             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
             $rowtotal ++;
@@ -1181,6 +1206,57 @@
             $itemcount ++;
         }
         $datatable .= &captcha_choice('login',$settings,$itemcount);
+    } elsif ($caller eq 'headtag') {
+        my %domservers = &Apache::lonnet::get_servers($dom);
+        my $choice = $choices{'headtag'};
+        $css_class = ' class="LC_odd_row"';
+        $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
+                      '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
+                      '<th>'.$choices{'current'}.'</th>'.
+                      '<th>'.$choices{'action'}.'</th>'.
+                      '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
+        my (%currurls,%currexempt);
+        if (ref($settings) eq 'HASH') {
+            if (ref($settings->{'headtag'}) eq 'HASH') {
+                foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
+                    if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
+                        $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
+                        $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
+                    }
+                }
+            }
+        }
+        my %lt = &Apache::lonlocal::texthash(
+                                               del  => 'Delete?',
+                                               rep  => 'Replace:',
+                                               upl  => 'Upload:',
+                                               curr => 'View contents',
+                                               none => 'None',
+        );
+        my $switchserver = &check_switchserver($dom,$confname);
+        foreach my $lonhost (sort(keys(%domservers))) {
+            my $exempt = &check_exempt_addresses($currexempt{$lonhost});
+            $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
+            if ($currurls{$lonhost}) {
+                $datatable .= '<td class="LC_right_item"><a href="'.
+                              "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
+                              'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
+                              '">'.$lt{'curr'}.'</a></td>'.
+                              '<td><span class="LC_nobreak"><label>'.
+                              '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
+                              $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
+            } else {
+                $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
+            }
+            $datatable .='<br />';
+            if ($switchserver) {
+                $datatable .= &mt('Upload to library server: [_1]',$switchserver);
+            } else {
+                $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
+            }
+            $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
+        }
+        $datatable .= '</table></td></tr>';
     }
     return $datatable;
 }
@@ -1214,6 +1290,9 @@
             link          => "Link",
             alink         => "Active link",
             vlink         => "Visited link",
+            headtag       => "Custom markup",
+            action        => "Action",
+            current       => "Current",
         );
     return %choices;
 }
@@ -5779,6 +5858,7 @@
     }
 
     my %servers = &Apache::lonnet::internet_dom_servers($dom);
+    my %domservers = &Apache::lonnet::get_servers($dom);
     my @loginvia_attribs = ('serverpath','custompath','exempt');
     if (keys(%servers) > 1) {
         foreach my $lonhost (keys(%servers)) {
@@ -5821,22 +5901,7 @@
                             $changes{'loginvia'}{$lonhost} = 1;
                         }
                         if ($item eq 'exempt') {
-                            $new =~ s/^\s+//;
-                            $new =~ s/\s+$//;
-                            my @poss_ips = split(/\s*[,:]\s*/,$new);
-                            my @okips;
-                            foreach my $ip (@poss_ips) {
-                                if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
-                                    if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
-                                        push(@okips,$ip); 
-                                    }
-                                }
-                            }
-                            if (@okips > 0) {
-                                $new = join(',', at okips); 
-                            } else {
-                                $new = ''; 
-                            }
+                            $new = &check_exempt_addresses($new);
                         }
                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                     }
@@ -5932,7 +5997,6 @@
                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                         if ((grep(/^\Q$lang\E$/, at currlangs)) &&
                             (!grep(/^\Q$lang\E$/, at delurls))) {
-
                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                         }
                     }
@@ -5948,6 +6012,84 @@
             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
         }
     }
+
+    my (%currheadtagurls,%currexempt, at newhosts,%newheadtagurls,%possexempt);
+    if (ref($domconfig{'login'}) eq 'HASH') {
+        if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
+            foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
+                if ($domservers{$lonhost}) {
+                    if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
+                        $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
+                        $currexempt{$lonhost} = $domconfig{'login'}{'headtagexempt'}{$lonhost}{'exempt'}
+                    }
+                }
+            }
+        }
+    }
+    my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
+    foreach my $lonhost (sort(keys(%domservers))) {
+        if (grep(/^\Q$lonhost\E$/, at delheadtagurls)) {
+            $changes{'headtag'}{$lonhost} = 1;
+        } else {
+            if ($env{'form.loginheadtagexempt_'.$lonhost}) {
+                $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
+            }
+            if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
+                push(@newhosts,$lonhost);
+            } elsif ($currheadtagurls{$lonhost}) {
+                $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
+                if ($currexempt{$lonhost}) {
+                    if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) { 
+                        $changes{'headtag'}{$lonhost} = 1;
+                    }
+                } elsif ($possexempt{$lonhost}) {
+                    $changes{'headtag'}{$lonhost} = 1;
+                }
+                if ($possexempt{$lonhost}) {
+                    $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
+                }
+            }
+        }
+    }
+    if (@newhosts) {
+        my $error;
+        my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
+        if ($configuserok eq 'ok') {
+            if ($switchserver) {
+                $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
+            } elsif ($author_ok eq 'ok') {
+                foreach my $lonhost (@newhosts) {
+                    my $formelem = 'loginheadtag_'.$lonhost;
+                    (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
+                                                                          "login/headtag/$lonhost",'','',
+                                                                          $env{'form.loginheadtag_'.$lonhost.'.filename'});
+                    if ($result eq 'ok') {
+                        $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
+                        $changes{'headtag'}{$lonhost} = 1;
+                        if ($possexempt{$lonhost}) {
+                            $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
+                        }
+                    } else {
+                        my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
+                                           $newheadtagurls{$lonhost},$result);
+                        $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
+                        if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
+                            (!grep(/^\Q$lonhost\E$/, at delheadtagurls))) {
+                            $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
+                        }
+                    }
+                }
+            } else {
+                $error = &mt("Upload of custom markup file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2].  Error was: [_3].",$confname,$dom,$author_ok);
+            }
+        } else {
+            $error = &mt("Upload of custom markup file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2].  Error was: [_3].",$confname,$dom,$configuserok);
+        }
+        if ($error) {
+            &Apache::lonnet::logthis($error);
+            $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
+        }
+    }
     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
 
     my $defaulthelpfile = '/adm/loginproblems.html';
@@ -6048,6 +6190,25 @@
                             }
                         }
                     }
+                } elsif ($item eq 'headtag') {
+                    if (ref($changes{$item}) eq 'HASH') {
+                        foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
+                            if (grep(/^\Q$lonhost\E$/, at delheadtagurls)) {
+                                $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
+                            } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
+                                $resulttext .= '<li><a href="'.
+                                               "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
+                                               'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
+                                               '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
+                                if ($possexempt{$lonhost}) {
+                                    $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
+                                } else {
+                                    $resulttext .= &mt('included for any client IP');
+                                }
+                                $resulttext .= '</li>';
+                            }
+                        }
+                    }
                 } elsif ($item eq 'captcha') {
                     if (ref($loginhash{'login'}) eq 'HASH') {
                         my $chgtxt;
@@ -6103,6 +6264,28 @@
     return $resulttext;
 }
 
+
+sub check_exempt_addresses {
+    my ($iplist) = @_;
+    $iplist =~ s/^\s+//;
+    $iplist =~ s/\s+$//;
+    my @poss_ips = split(/\s*[,:]\s*/,$iplist);
+    my (@okips,$new);
+    foreach my $ip (@poss_ips) {
+        if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
+            if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
+                push(@okips,$ip);
+            }
+        }
+    }
+    if (@okips > 0) {
+        $new = join(',', at okips);
+    } else {
+        $new = '';
+    }
+    return $new;
+}
+
 sub color_font_choices {
     my %choices =
         &Apache::lonlocal::texthash (
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1207 loncom/interface/loncommon.pm:1.1208
--- loncom/interface/loncommon.pm:1.1207	Sun Mar  1 22:20:56 2015
+++ loncom/interface/loncommon.pm	Tue Mar  3 22:06:50 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1207 2015/03/01 22:20:56 raeburn Exp $
+# $Id: loncommon.pm,v 1.1208 2015/03/03 22:06:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -5076,23 +5076,29 @@
             if (keys(%{$domconfig{'login'}})) {
                 foreach my $key (keys(%{$domconfig{'login'}})) {
                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
-                        if ($key eq 'loginvia') {
-                            if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
-                                foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
-                                    if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
-                                        if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
-                                            my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
-                                            $designhash{$udom.'.login.loginvia'} = $server;
-                                            if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
-
-                                                $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
-                                            } else {
-                                                $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
+                        if (($key eq 'loginvia') || ($key eq 'headtag')) {
+                            if (ref($domconfig{'login'}{$key}) eq 'HASH') {
+                                foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
+                                    if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
+                                        if ($key eq 'loginvia') {
+                                            if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
+                                                my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
+                                                $designhash{$udom.'.login.loginvia'} = $server;
+                                                if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
+
+                                                    $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
+                                                } else {
+                                                    $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
+                                                }
                                             }
-                                            if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
-                                                $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
+                                        } elsif ($key eq 'headtag') {
+                                            if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
+                                                $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
                                             }
                                         }
+                                        if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
+                                            $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
+                                        }
                                     }
                                 }
                             }
@@ -8071,7 +8077,7 @@
 		modalWindow.height = height;
 		modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
 		modalWindow.open();
-	};	
+	};
 // END LON-CAPA Internal -->
 // ]]>
 </script>
Index: loncom/auth/lonlogin.pm
diff -u loncom/auth/lonlogin.pm:1.160 loncom/auth/lonlogin.pm:1.161
--- loncom/auth/lonlogin.pm:1.160	Fri Dec  5 12:03:20 2014
+++ loncom/auth/lonlogin.pm	Tue Mar  3 22:06:55 2015
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Login Screen
 #
-# $Id: lonlogin.pm,v 1.160 2014/12/05 12:03:20 kruse Exp $
+# $Id: lonlogin.pm,v 1.161 2015/03/03 22:06:55 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -126,6 +126,7 @@
 
     my $lonhost = $r->dir_config('lonHostID');
     my $domain = &Apache::lonnet::default_login_domain();
+    my $defdom = $domain;
     if ($lonhost ne '') {
         unless ($sessiondata{'sessionserver'}) {
             my $redirect = &check_loginvia($domain,$lonhost);
@@ -385,6 +386,29 @@
 	       alink        => "$alink",
                onload       => 'javascript:enableInput();',);
 
+    my %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
+    my $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost};
+    my $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost};
+    if ($headextra) {
+        my $omitextra;
+        if ($headextra_exempt ne '') {
+            my @exempt = split(',',$headextra_exempt);
+            my $ip = $ENV{'REMOTE_ADDR'};
+            if (grep(/^\Q$ip\E$/, at exempt)) {
+                $omitextra = 1;
+            }
+        }
+        unless ($omitextra) {
+            my $confname = $defdom.'-domainconfig';
+            if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost/\E}) {
+                my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
+                unless ($extra eq '-1') {
+                    $js .= "\n".$extra."\n";
+                }
+            }
+        }
+    }
+
     $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
 			       { 'redirect'       => [$expire,'/adm/roles'], 
 				 'add_entries' => \%add_entries,


More information about the LON-CAPA-cvs mailing list