--- loncom/interface/domainprefs.pm 2008/07/19 02:28:44 1.64
+++ loncom/interface/domainprefs.pm 2008/11/28 21:02:35 1.69
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.64 2008/07/19 02:28:44 raeburn Exp $
+# $Id: domainprefs.pm,v 1.69 2008/11/28 21:02:35 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -37,11 +37,13 @@ use Apache::loncommon();
use Apache::lonhtmlcommon();
use Apache::lonlocal;
use Apache::lonmsg();
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
use LONCAPA::Enrollment;
+use LONCAPA::loncgi();
use File::Copy;
use Locale::Language;
use DateTime::TimeZone;
+use DateTime::Locale;
sub handler {
my $r=shift;
@@ -72,15 +74,15 @@ sub handler {
&Apache::lonnet::get_dom('configuration',['login','rolecolors',
'quotas','autoenroll','autoupdate','directorysrch',
'usercreation','usermodification','contacts','defaults',
- 'scantron','coursecategories'],$dom);
+ 'scantron','coursecategories','serverstatuses'],$dom);
my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
'autoupdate','directorysrch','contacts',
'usercreation','usermodification','scantron',
- 'coursecategories');
+ 'coursecategories','serverstatuses');
my %prefs = (
'rolecolors' =>
{ text => 'Default color schemes',
- help => 'Default_Color_Schemes',
+ help => 'Domain_Configuration_Color_Schemes',
header => [{col1 => 'Student Settings',
col2 => '',},
{col1 => 'Coordinator Settings',
@@ -92,31 +94,31 @@ sub handler {
},
'login' =>
{ text => 'Log-in page options',
- help => 'Domain_Log-in_Page',
+ help => 'Domain_Configuration_Login_Page',
header => [{col1 => 'Item',
col2 => '',}],
},
'defaults' =>
{ text => 'Default authentication/language/timezone',
- help => '',
+ help => 'Domain_Configuration_LangTZAuth',
header => [{col1 => 'Setting',
col2 => 'Value'}],
},
'quotas' =>
{ text => 'Default quotas for user portfolios',
- help => 'Default_User_Quota',
+ help => 'Domain_Configuration_Quotas',
header => [{col1 => 'User type',
col2 => 'Default quota'}],
},
'autoenroll' =>
{ text => 'Auto-enrollment settings',
- help => 'Domain_Auto_Enrollment',
+ help => 'Domain_Configuration_Auto_Enrollment',
header => [{col1 => 'Configuration setting',
col2 => 'Value(s)'}],
},
'autoupdate' =>
{ text => 'Auto-update settings',
- help => 'Domain_Auto_Update',
+ help => 'Domain_Configuration_Auto_Updates',
header => [{col1 => 'Setting',
col2 => 'Value',},
{col1 => 'User population',
@@ -124,20 +126,20 @@ sub handler {
},
'directorysrch' =>
{ text => 'Institutional directory searches',
- help => 'Domain_Directory_Search',
+ help => 'Domain_Configuration_InstDirectory_Search',
header => [{col1 => 'Setting',
col2 => 'Value',}],
},
'contacts' =>
{ text => 'Contact Information',
- help => 'Domain_Contact_Information',
+ help => 'Domain_Configuration_Contact_Info',
header => [{col1 => 'Setting',
col2 => 'Value',}],
},
'usercreation' =>
{ text => 'User creation',
- help => 'Domain_User_Creation',
+ help => 'Domain_Configuration_User_Creation',
header => [{col1 => 'Format rule type',
col2 => 'Format rules in force'},
{col1 => 'User account creation',
@@ -145,9 +147,9 @@ sub handler {
{col1 => 'Context',
col2 => 'Assignable authentication types'}],
},
- 'usermodification' =>
+ 'usermodification' =>
{ text => 'User modification',
- help => 'Domain_User_Modification',
+ help => 'Domain_Configuration_User_Modification',
header => [{col1 => 'Target user has role',
col2 => 'User information updateable in author context'},
{col1 => 'Target user has role',
@@ -155,22 +157,30 @@ sub handler {
{col1 => "Status of user",
col2 => 'Information settable when self-creating account (if directory data blank)'}],
},
- 'scantron' =>
+ 'scantron' =>
{ text => 'Scantron format file',
- help => 'Domain_Scantron_Formats',
+ help => 'Domain_Configuration_Scantron_Format',
header => [ {col1 => 'Item',
col2 => '',
}],
},
- 'coursecategories' =>
+ 'coursecategories' =>
{ text => 'Cataloging of courses',
- help => 'Domain_Course_Catalog',
- header => [{col1 => 'Category settings',
+ help => 'Domain_Configuration_Cataloging_Courses',
+ header => [{col1 => 'Category settings',
col2 => '',},
{col1 => 'Categories',
col2 => '',
}],
- }
+ },
+ 'serverstatuses' =>
+ {text => 'Access to Server Status Pages',
+ help => 'Domain_Configuration_Server_Status',
+ header => [{col1 => 'Status Page',
+ col2 => 'Other named users',
+ col3 => 'Specific IPs',
+ }],
+ },
);
my @roles = ('student','coordinator','author','admin');
my @actions = &Apache::loncommon::get_env_multiple('form.actions');
@@ -319,7 +329,10 @@ sub handler {
}
$count = 0;
foreach my $item (@prefs_order) {
- $r->print('
');
+ $r->print(''.
+ &Apache::loncommon::help_open_topic($prefs{$item}->{'help'}).
+ '
');
$count ++;
if ((!$seconddiv) && ($count >= $midpoint)) {
$r->print(''."\n".''."\n");
@@ -368,6 +381,8 @@ sub process_changes {
$output = &modify_scantron($r,$dom,$confname,%domconfig);
} elsif ($action eq 'coursecategories') {
$output = &modify_coursecategories($dom,%domconfig);
+ } elsif ($action eq 'serverstatuses') {
+ $output = &modify_serverstatuses($dom,%domconfig);
}
return $output;
}
@@ -382,13 +397,10 @@ sub print_config_box {
$output .=
'
- '.&mt($item->{text}).
- ' |
';
-#
-# FIXME - put the help link back in when the help files exist
-# '.&mt($item->{text}).' '.
-# &Apache::loncommon::help_open_topic($item->{'help'}).' |
-# ');
+ '.
+ &mt($item->{text}).' '.
+ &Apache::loncommon::help_open_topic($item->{'help'}).' | '."\n".
+ '';
$rowtotal ++;
if (($action eq 'autoupdate') || ($action eq 'rolecolors') ||
($action eq 'usercreation') || ($action eq 'usermodification') ||
@@ -405,7 +417,7 @@ sub print_config_box {
'.&mt($item->{'header'}->[0]->{'col1'}).' |
'.&mt($item->{'header'}->[0]->{'col2'}).' |
';
- $rowtotal ++;
+ $rowtotal ++;
if ($action eq 'autoupdate') {
$output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
} elsif ($action eq 'usercreation') {
@@ -470,8 +482,10 @@ sub print_config_box {
- '.&mt($item->{'header'}->[2]->{'col1'}).' |
- '.&mt($item->{'header'}->[2]->{'col2'}).' |
+ '.
+ &mt($item->{'header'}->[2]->{'col1'}).' |
+ '.
+ &mt($item->{'header'}->[2]->{'col2'}).' |
'.
&print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
@@ -496,13 +510,33 @@ sub print_config_box {
if (($action eq 'login') || ($action eq 'directorysrch')) {
$output .= '
| '.&mt($item->{'header'}->[0]->{'col1'}).' | ';
+ } elsif ($action eq 'serverstatuses') {
+ $output .= '
+ '.&mt($item->{'header'}->[0]->{'col1'}).
+ ' ('.&mt('Automatic access for Dom. Coords.').') | ';
+
} else {
$output .= '
- '.&mt($item->{'header'}->[0]->{'col1'}).' | ';
+ '.&mt($item->{'header'}->[0]->{'col1'}).' | ';
}
- $output .= '
- '.&mt($item->{'header'}->[0]->{'col2'}).' |
- ';
+ if ($action eq 'serverstatuses') {
+ $output .= ''.
+ &mt($item->{'header'}->[0]->{'col2'}).
+ ' ('.&mt('user1:domain1,user2:domain2 etc.').')';
+ } else {
+ $output .= ' | '.
+ &mt($item->{'header'}->[0]->{'col2'});
+ }
+ $output .= ' | ';
+ if ($item->{'header'}->[0]->{'col3'}) {
+ $output .= ''.
+ &mt($item->{'header'}->[0]->{'col3'});
+ if ($action eq 'serverstatuses') {
+ $output .= ' ('.&mt('IP1,IP2 etc.').')';
+ }
+ $output .= ' | ';
+ }
+ $output .= '';
$rowtotal ++;
if ($action eq 'login') {
$output .= &print_login($dom,$confname,$phase,$settings,\$rowtotal);
@@ -518,6 +552,8 @@ sub print_config_box {
$output .= &print_defaults($dom,\$rowtotal);
} elsif ($action eq 'scantron') {
$output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
+ } elsif ($action eq 'serverstatuses') {
+ $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
}
}
$output .= '
@@ -1465,24 +1501,17 @@ sub print_contacts {
my $rownum = 0;
my $css_class;
foreach my $item (@contacts) {
- if ($rownum%2) {
- $css_class = '';
- } else {
- $css_class = ' class="LC_odd_row" ';
- }
+ $rownum ++;
+ $css_class = $rownum%2?' class="LC_odd_row"':'';
$datatable .= ''.
''.$titles->{$item}.
' | '.
' |
';
- $rownum ++;
}
foreach my $type (@mailings) {
- if ($rownum%2) {
- $css_class = '';
- } else {
- $css_class = ' class="LC_odd_row" ';
- }
+ $rownum ++;
+ $css_class = $rownum%2?' class="LC_odd_row"':'';
$datatable .= ''.
''.
$titles->{$type}.': | '.
@@ -1499,7 +1528,6 @@ sub print_contacts {
''.
'
'."\n";
- $rownum ++;
}
$$rowtotal += $rownum;
return $datatable;
@@ -1508,7 +1536,7 @@ sub print_contacts {
sub contact_titles {
my %titles = &Apache::lonlocal::texthash (
'supportemail' => 'Support E-mail address',
- 'adminemail' => 'Default Server Admin E-mail address',
+ 'adminemail' => 'Default Server Admin E-mail address',
'errormail' => 'Error reports to be e-mailed to',
'packagesmail' => 'Package update alerts to be e-mailed to',
'helpdeskmail' => 'Helpdesk requests to be e-mailed to'
@@ -1823,7 +1851,8 @@ sub print_usermodification {
sub print_defaults {
my ($dom,$rowtotal) = @_;
- my @items = ('auth_def','auth_arg_def','lang_def','timezone_def');
+ my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
+ 'datelocale_def');
my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
my $titles = &defaults_titles();
my $rownum = 0;
@@ -1858,6 +1887,9 @@ sub print_defaults {
} elsif ($item eq 'timezone_def') {
my $includeempty = 1;
$datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
+ } elsif ($item eq 'datelocale_def') {
+ my $includeempty = 1;
+ $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
} else {
$datatable .= '';
@@ -1875,6 +1907,7 @@ sub defaults_titles {
'auth_arg_def' => 'Default authentication argument',
'lang_def' => 'Default language',
'timezone_def' => 'Default timezone',
+ 'datelocale_def' => 'Default locale for dates',
);
return (\%titles);
}
@@ -1985,14 +2018,15 @@ sub print_scantronformat {
$css_class = $itemcount%2?' class="LC_odd_row"':'';
$datatable .= '';
if (!$is_custom) {
- $datatable .= ''.&mt('Default in use:').' ';
+ $datatable .= ' | '.&mt('Default in use:').' '.
+ '';
if ($scantronurl) {
$datatable .= ''.
&mt('Default scantron format file').'';
} else {
$datatable = &mt('File unavailable for display');
}
- $datatable .= ' | ';
+ $datatable .= '';
if (keys(%error) == 0) {
$datatable .= '';
if (!$switchserver) {
@@ -2013,19 +2047,21 @@ sub print_scantronformat {
}
$datatable .= ' | '.$errorstr.' | ';
} elsif ($scantronurl) {
- $datatable .= ' | '
- .&mt('Custom scantron format file').''
- .' | '
- .''.&mt('Replace:').' ';
+ $datatable .= ' | '.
+ ''.
+ &mt('Custom scantron format file').' | '.
+ ' '.
+ &mt('Replace:').' ';
}
}
if (keys(%error) == 0) {
if ($switchserver) {
$datatable .= &mt('Upload to library server: [_1]',$switchserver);
} else {
- $datatable .=' ';
+ $datatable .=' '.
+ '';
}
}
$datatable .= ' |
';
@@ -2201,6 +2237,58 @@ sub print_coursecategories {
return $datatable;
}
+sub print_serverstatuses {
+ my ($dom,$settings,$rowtotal) = @_;
+ my $datatable;
+ my @pages = &serverstatus_pages();
+ my (%namedaccess,%machineaccess);
+ foreach my $type (@pages) {
+ $namedaccess{$type} = '';
+ $machineaccess{$type}= '';
+ }
+ if (ref($settings) eq 'HASH') {
+ foreach my $type (@pages) {
+ if (exists($settings->{$type})) {
+ if (ref($settings->{$type}) eq 'HASH') {
+ foreach my $key (keys(%{$settings->{$type}})) {
+ if ($key eq 'namedusers') {
+ $namedaccess{$type} = $settings->{$type}->{$key};
+ } elsif ($key eq 'machines') {
+ $machineaccess{$type} = $settings->{$type}->{$key};
+ }
+ }
+ }
+ }
+ }
+ }
+ my $titles= &LONCAPA::loncgi::serverstatus_titles();
+ my $rownum = 0;
+ my $css_class;
+ foreach my $type (@pages) {
+ $rownum ++;
+ $css_class = $rownum%2?' class="LC_odd_row"':'';
+ $datatable .= ''.
+ ''.
+ $titles->{$type}.' | '.
+ ''.
+ ' | '.
+ ''.
+ ''.
+ ''.
+ ' |
'."\n";
+ }
+ $$rowtotal += $rownum;
+ return $datatable;
+}
+
+sub serverstatus_pages {
+ return ('userstatus','lonstatus','loncron','server-status','codeversions',
+ 'clusterstatus','metadata_keywords','metadata_harvest',
+ 'takeoffline','takeonline','showenv');
+}
+
sub coursecategories_javascript {
my ($settings) = @_;
my ($output,$jstext,$cathash);
@@ -4248,7 +4336,7 @@ sub modify_defaults {
my ($dom,$r) = @_;
my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
- my @items = ('auth_def','auth_arg_def','lang_def','timezone_def');
+ my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def');
my @authtypes = ('internal','krb4','krb5','localauth');
foreach my $item (@items) {
$newvalues{$item} = $env{'form.'.$item};
@@ -4275,6 +4363,13 @@ sub modify_defaults {
push(@errors,$item);
}
}
+ } elsif ($item eq 'datelocale_def') {
+ if ($newvalues{$item} ne '') {
+ my @datelocale_ids = DateTime::Locale->ids();
+ if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
+ push(@errors,$item);
+ }
+ }
}
if (grep(/^\Q$item\E$/,@errors)) {
$newvalues{$item} = $domdefaults{$item};
@@ -4287,6 +4382,7 @@ sub modify_defaults {
auth_arg_def => $newvalues{'auth_arg_def'},
lang_def => $newvalues{'lang_def'},
timezone_def => $newvalues{'timezone_def'},
+ datelocale_def => $newvalues{'datelocale_def'},
}
);
my $title = &defaults_titles();
@@ -4319,7 +4415,7 @@ sub modify_defaults {
my $cachetime = 24*60*60;
&Apache::lonnet::do_cache_new('domdefaults',$dom,
$defaults_hash{'defaults'},$cachetime);
- if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'}) {
+ if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
my $sysmail = $r->dir_config('lonSysEMail');
&Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
}
@@ -4600,6 +4696,132 @@ sub modify_coursecategories {
}
return $resulttext;
}
+
+sub modify_serverstatuses {
+ my ($dom,%domconfig) = @_;
+ my ($resulttext,%changes,%currserverstatus,%newserverstatus);
+ if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
+ %currserverstatus = %{$domconfig{'serverstatuses'}};
+ }
+ my @pages = &serverstatus_pages();
+ foreach my $type (@pages) {
+ $newserverstatus{$type}{'namedusers'} = '';
+ $newserverstatus{$type}{'machines'} = '';
+ if (defined($env{'form.'.$type.'_namedusers'})) {
+ my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
+ my @okusers;
+ foreach my $user (@users) {
+ my ($uname,$udom) = split(/:/,$user);
+ if (($udom =~ /^$match_domain$/) &&
+ (&Apache::lonnet::domain($udom)) &&
+ ($uname =~ /^$match_username$/)) {
+ if (!grep(/^\Q$user\E/,@okusers)) {
+ push(@okusers,$user);
+ }
+ }
+ }
+ if (@okusers > 0) {
+ @okusers = sort(@okusers);
+ $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
+ }
+ }
+ if (defined($env{'form.'.$type.'_machines'})) {
+ my @machines = split(/,/,$env{'form.'.$type.'_machines'});
+ my @okmachines;
+ foreach my $ip (@machines) {
+ my @parts = split(/\./,$ip);
+ next if (@parts < 4);
+ my $badip = 0;
+ for (my $i=0; $i<4; $i++) {
+ if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
+ $badip = 1;
+ last;
+ }
+ }
+ if (!$badip) {
+ push(@okmachines,$ip);
+ }
+ }
+ @okmachines = sort(@okmachines);
+ $newserverstatus{$type}{'machines'} = join(',',@okmachines);
+ }
+ }
+ my %serverstatushash = (
+ serverstatuses => \%newserverstatus,
+ );
+ my $putresult = &Apache::lonnet::put_dom('configuration',\%serverstatushash,
+ $dom);
+ my %changes;
+ foreach my $type (@pages) {
+ if (ref($currserverstatus{$type}) eq 'HASH') {
+ my @currnamed = split(/,/,$currserverstatus{$type}{'namedusers'});
+ my @newusers = split(/,/,$newserverstatus{$type}{'namedusers'});
+ foreach my $item (@currnamed) {
+ if (!grep(/^\Q$item\E$/,@newusers)) {
+ $changes{$type}{'namedusers'} = 1;
+ last;
+ }
+ }
+ foreach my $item (@newusers) {
+ if (!grep(/^\Q$item\E$/,@currnamed)) {
+ $changes{$type}{'namedusers'} = 1;
+ last;
+ }
+ }
+ my @currmachines = split(/,/,$currserverstatus{$type}{'machines'});
+ my @newmachines = split(/,/,$newserverstatus{$type}{'machines'});
+ foreach my $item (@currmachines) {
+ if (!grep(/^\Q$item\E$/,@newmachines)) {
+ $changes{$type}{'machines'} = 1;
+ last;
+ }
+ }
+ foreach my $item (@newmachines) {
+ if (!grep(/^\Q$item\E$/,@currmachines)) {
+ $changes{$type}{'machines'} = 1;
+ last;
+ }
+ }
+
+ }
+ }
+ if (keys(%changes) > 0) {
+ my $titles= &LONCAPA::loncgi::serverstatus_titles();
+ my $putresult = &Apache::lonnet::put_dom('configuration',
+ \%serverstatushash,$dom);
+ if ($putresult eq 'ok') {
+ $resulttext .= &mt('Changes made:').'';
+ foreach my $type (@pages) {
+ if (defined($changes{$type})) {
+ $resulttext .= '- '.$titles->{$type}.'
';
+ if (defined($changes{$type}{'namedusers'})) {
+ if ($newserverstatus{$type}{'namedusers'} eq '') {
+ $resulttext .= '- '.&mt("Access terminated for all specific (named) users").'
'."\n";
+ } else {
+ $resulttext .= '- '.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'
'."\n";
+ }
+ } elsif (defined($changes{$type}{'machines'})) {
+ if ($newserverstatus{$type}{'machines'} eq '') {
+ $resulttext .= '- '.&mt("Access terminated for all specific IP addresses").'
'."\n";
+ } else {
+ $resulttext .= '- '.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'
'."\n";
+ }
+
+ }
+ $resulttext .= '
';
+ }
+ }
+ $resulttext .= '
';
+ } else {
+ $resulttext = ''.
+ &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'';
+
+ }
+ } else {
+ $resulttext = &mt('No changes made to access to server status pages');
+ }
+ return $resulttext;
+}
sub recurse_check {
my ($chkcats,$categories,$depth,$name) = @_;