--- loncom/interface/domainprefs.pm 2014/10/06 21:08:03 1.255
+++ loncom/interface/domainprefs.pm 2015/03/03 22:06:50 1.256
@@ -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 @@ sub handler {
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 @@ sub handler {
{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 @@ sub print_config_box {
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 @@ sub print_config_box {
} 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 @@ sub print_config_box {
($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).'
@@ -761,6 +765,27 @@ sub print_config_box {
} else {
$output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
}
+ $output .= '
+
+
+
+
+
+
+ ';
+ if ($numheaders == 4) {
+ $output .= '
+ '.&mt($item->{'header'}->[3]->{'col1'}).' |
+ '.&mt($item->{'header'}->[3]->{'col2'}).' |
+ ';
+ } else {
+ $output .= '
+ '.&mt($item->{'header'}->[2]->{'col1'}).' |
+ '.&mt($item->{'header'}->[2]->{'col2'}).' |
+ ';
+ }
+ $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 @@ sub print_login {
$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 .= ''.$choice.' | '.
+ ' | ';
}
return $datatable;
}
@@ -1214,6 +1290,9 @@ sub login_choices {
link => "Link",
alink => "Active link",
vlink => "Visited link",
+ headtag => "Custom markup",
+ action => "Action",
+ current => "Current",
);
return %choices;
}
@@ -5779,6 +5858,7 @@ sub modify_login {
}
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 @@ sub modify_login {
$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(',',@okips);
- } else {
- $new = '';
- }
+ $new = &check_exempt_addresses($new);
}
$loginhash{login}{loginvia}{$lonhost}{$item} = $new;
}
@@ -5932,7 +5997,6 @@ sub modify_login {
$errors .= ''.$puberror.'';
if ((grep(/^\Q$lang\E$/,@currlangs)) &&
(!grep(/^\Q$lang\E$/,@delurls))) {
-
$loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
}
}
@@ -5948,6 +6012,84 @@ sub modify_login {
$errors .= ''.$error.'';
}
}
+
+ my (%currheadtagurls,%currexempt,@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$/,@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 .= ''.$puberror.'';
+ if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
+ (!grep(/^\Q$lonhost\E$/,@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 .= ''.$error.'';
+ }
+ }
&process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
my $defaulthelpfile = '/adm/loginproblems.html';
@@ -6048,6 +6190,25 @@ sub modify_login {
}
}
}
+ } elsif ($item eq 'headtag') {
+ if (ref($changes{$item}) eq 'HASH') {
+ foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
+ if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
+ $resulttext .= ''.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'';
+ } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
+ $resulttext .= ''.&mt('custom markup').' '.&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 .= '';
+ }
+ }
+ }
} elsif ($item eq 'captcha') {
if (ref($loginhash{'login'}) eq 'HASH') {
my $chgtxt;
@@ -6103,6 +6264,28 @@ sub modify_login {
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(',',@okips);
+ } else {
+ $new = '';
+ }
+ return $new;
+}
+
sub color_font_choices {
my %choices =
&Apache::lonlocal::texthash (
|