--- loncom/interface/domainprefs.pm 2012/08/21 21:12:08 1.164 +++ loncom/interface/domainprefs.pm 2012/08/25 21:48:12 1.166 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.164 2012/08/21 21:12:08 raeburn Exp $ +# $Id: domainprefs.pm,v 1.166 2012/08/25 21:48:12 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -353,10 +353,10 @@ sub handler { 'helpsettings' => {text => 'Help page settings', help => 'Domain_Configuration_Help_Settings', - header => [{col1 => 'Authenticated Help Settings', - col2 => ''}, - {col1 => 'Unauthenticated Help Settings', - col2 => ''}], + header => [{col1 => 'Help Settings (logged-in users)', + col2 => 'Value'}, + {col1 => 'Help Settings (before log-in)', + col2 => 'Value'}], }, 'coursedefaults' => {text => 'Course/Community defaults', @@ -410,7 +410,7 @@ sub handler { if ($phase eq 'process') { &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles); } elsif ($phase eq 'display') { - my $js; + my $js = &recaptcha_js(); if (keys(%servers) > 1) { my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom); @@ -533,7 +533,7 @@ sub print_config_box { if ($numheaders > 1) { my $colspan = ''; my $rightcolspan = ''; - if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) { + if (($action eq 'rolecolors') || ($action eq 'coursecategories')) { $colspan = ' colspan="2"'; } if ($action eq 'usersessions') { @@ -2263,105 +2263,70 @@ sub print_contacts { } sub print_helpsettings { + my ($position,$dom,$confname,$settings,$rowtotal) = @_; + my ($css_class,$datatable,$itemcount); + my $switchserver = &check_switchserver($dom,$confname); + $itemcount = 1; + if ($position eq 'top') { + my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles,$align); + $choices{'submitbugs'} = &mt('Display link to: [_1]?', + &Apache::loncommon::modal_link('http://bugs.loncapa.org', + &mt('LON-CAPA bug tracker'),600,500)); + %defaultchecked = ('submitbugs' => 'on'); + @toggles = ('submitbugs',); + $align = 'LC_left_item'; - my ($position,$dom,$confname,$settings,$rowtotal) = @_; - my ($css_class,$datatable); - - my $switchserver = &check_switchserver($dom,$confname); - - my $itemcount = 1; - - if ($position eq 'top') { - - my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles); - - %choices = - &Apache::lonlocal::texthash ( - submitbugs => 'Display "Submit a bug" link?', - ); - - %defaultchecked = ('submitbugs' => 'on'); - - @toggles = ('submitbugs',); - - foreach my $item (@toggles) { - if ($defaultchecked{$item} eq 'on') { - $checkedon{$item} = ' checked="checked" '; - $checkedoff{$item} = ' '; - } elsif ($defaultchecked{$item} eq 'off') { - $checkedoff{$item} = ' checked="checked" '; - $checkedon{$item} = ' '; - } - } - - if (ref($settings) eq 'HASH') { - foreach my $item (@toggles) { - if ($settings->{$item} eq '1') { - $checkedon{$item} = ' checked="checked" '; - $checkedoff{$item} = ' '; - } elsif ($settings->{$item} eq '0') { - $checkedoff{$item} = ' checked="checked" '; - $checkedon{$item} = ' '; - } - } - } - - foreach my $item (@toggles) { - $css_class = $itemcount%2 ? ' class="LC_odd_row"' : ''; - $datatable .= - ' - '.$choices{$item}.' -   - -   - '. - ''. - ''; - $itemcount ++; - } - - } else { - - $css_class = $itemcount%2 ? ' class="LC_odd_row"' : ''; - - $datatable .= ''; - - if (ref($settings) eq 'HASH') { - if ($settings->{'loginhelpurl'} ne '') { - my($directory, $filename) = $settings->{'loginhelpurl'} =~ m/(.*\/)(.*)$/; - $datatable .= ''; - $datatable .= '' - } else { - $datatable .= ''; - $datatable .= ' '; - } - } else { - $datatable .= ' '; - $datatable .= ' '; - } - - $datatable .= ''; - if ($switchserver) { - $datatable .= &mt('Upload to library server: [_1]',$switchserver); + ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked, + \%choices,$itemcount); + } else { + $css_class = $itemcount%2 ? ' class="LC_odd_row"' : ''; + $datatable .= ''; + my $url = '/adm/loginproblems.html'; + my $type = 'default'; + my %lt = &Apache::lonlocal::texthash ( + del => 'Delete?', + rep => 'Replace:', + upl => 'Upload:', + default => 'Default', + custom => 'Custom', + ); + if (ref($settings) eq 'HASH') { + if (ref($settings->{'loginhelpurl'}) eq 'HASH') { + + } elsif ($settings->{'loginhelpurl'} ne '') { + $type = 'custom'; + $url = $settings->{'loginhelpurl'}.'?inhibitmenu=yes'; + } + } + $datatable .= ''. + &mt('Log-in help page currently in use: [_1]', + &Apache::loncommon::modal_link($url,$lt{$type},600,500)). + ''."\n". + ''; + if ($type eq 'custom') { + $datatable .= ' '.$lt{'rep'}.''; } else { - $datatable .= &mt('Upload Custom Login Page Help File:'); - $datatable .=''; + $datatable .= $lt{'upl'}; } - $datatable .= ''; - - } - - return $datatable; - + $datatable .='
'; + if ($switchserver) { + $datatable .= &mt('Upload to library server: [_1]',$switchserver); + } else { + $datatable .= ''; + } + $datatable .= ''; + } + return $datatable; } - sub radiobutton_prefs { my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_; return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') && (ref($choices) eq 'HASH')); - my (%checkedon,%checkedoff,$datatable,$css_class); + my (%checkedon,%checkedoff,$datatable,$css_class,$cell_colspan); foreach my $item (@{$toggles}) { if ($defaultchecked->{$item} eq 'on') { @@ -3266,18 +3231,19 @@ sub print_usercreation { } my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom); + my $createsettings; + if (ref($settings) eq 'HASH') { + $createsettings = $settings->{cancreate}; + } if (ref($usertypes) eq 'HASH') { if (keys(%{$usertypes}) > 0) { - my $createsettings; - if (ref($settings) eq 'HASH') { - $createsettings = $settings->{cancreate}; - } $datatable .= &insttypes_row($createsettings,$types,$usertypes, $dom,$numinrow,$othertitle, 'statustocreate'); $$rowtotal ++; } } + $datatable .= &captcha_choice('cancreate',$createsettings); } else { my @contexts = ('author','course','domain'); my @authtypes = ('int','krb4','krb5','loc'); @@ -3329,6 +3295,63 @@ sub print_usercreation { return $datatable; } +sub captcha_choice { + my ($context,$settings) = @_; + my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext); + my %lt = &captcha_phrases(); + $keyentry = 'hidden'; + if ($context eq 'cancreate') { + $rowname = &mt('CAPTCHA validation (e-mail as username)'); + } elsif ($context eq 'help') { + $rowname = &mt('CAPTCHA validation'); + } + if (ref($settings) eq 'HASH') { + if ($settings->{'captcha'}) { + $checked{$settings->{'captcha'}} = ' checked="checked"'; + } else { + $checked{'original'} = ' checked="checked"'; + } + if ($settings->{'captcha'} eq 'recaptcha') { + $pubtext = $lt{'pub'}; + $privtext = $lt{'priv'}; + $keyentry = 'text'; + } + if (ref($settings->{'recaptchakeys'}) eq 'HASH') { + $currpub = $settings->{'recaptchakeys'}{'public'}; + $currpriv = $settings->{'recaptchakeys'}{'private'}; + } + } else { + $checked{'original'} = ' checked="checked"'; + } + my $output = ''. + ''.$rowname.''."\n". + ''."\n". + '
'."\n"; + foreach my $option ('original','recaptcha','notused') { + $output .= ''; + unless ($option eq 'notused') { + $output .= (' 'x2)."\n"; + } + } +# +# Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit: +# https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple +# servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu) +# specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain. +# + $output .= '
'."\n". + ''.$pubtext.' '."\n". + '
'."\n". + ''.$privtext.' '."\n". + '
'."\n". + ''; + return $output; +} + sub user_formats_row { my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_; my $output; @@ -4293,9 +4316,13 @@ sub insttypes_row { if ($context eq 'cansearch') { $showdom = ' ('.$dom.')'; } + my $class = 'LC_left_item'; + if ($context eq 'statustocreate') { + $class = 'LC_right_item'; + } my $output = ''. ''.$lt{$context}.$showdom. - ''; + '
'; my $rem; if (ref($types) eq 'ARRAY') { for (my $i=0; $i<@{$types}; $i++) { @@ -6317,6 +6344,7 @@ sub modify_usercreation { } push(@contexts,'statustocreate'); } + &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation); if (ref($curr_usercreation{'cancreate'}) eq 'HASH') { foreach my $item (@contexts) { if (($item eq 'selfcreate') || ($item eq 'statustocreate')) { @@ -6499,7 +6527,7 @@ sub modify_usercreation { my %lt = &usercreation_types(); foreach my $type (@{$changes{'cancreate'}}) { my $chgtext; - unless ($type eq 'statustocreate') { + unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) { $chgtext = $lt{$type}.', '; } if ($type eq 'selfcreate') { @@ -6558,6 +6586,35 @@ sub modify_usercreation { } } } + } elsif ($type eq 'captcha') { + if ($cancreate{$type} eq 'notused') { + $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.'); + } else { + my %captchas = &captcha_phrases(); + if ($captchas{$cancreate{$type}}) { + $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}."); + } else { + $chgtext .= &mt('Validation for self-creation screen set to unknown type.'); + } + } + } elsif ($type eq 'recaptchakeys') { + my ($privkey,$pubkey); + if (ref($cancreate{$type}) eq 'HASH') { + $pubkey = $cancreate{$type}{'public'}; + $privkey = $cancreate{$type}{'private'}; + } + $chgtext .= &mt('ReCAPTCHA keys changes').'
    '; + if (!$pubkey) { + $chgtext .= '
  • '.&mt('Public key deleted').'
  • '; + } else { + $chgtext .= '
  • '.&mt('Public key set to [_1]',$pubkey).'
  • '; + } + if (!$privkey) { + $chgtext .= '
  • '.&mt('Private key deleted').'
  • '; + } else { + $chgtext .= '
  • '.&mt('Private key set to [_1]',$pubkey).'
  • '; + } + $chgtext .= '
'; } else { if ($cancreate{$type} eq 'none') { $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.'); @@ -6657,6 +6714,43 @@ sub modify_usercreation { return $resulttext; } +sub process_captcha { + my ($container,$changes,$newsettings,$current) = @_; + return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH')); + $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'}; + unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') { + $newsettings->{'captcha'} = 'original'; + } + if ($current->{'captcha'} ne $newsettings->{'captcha'}) { + if (ref($changes->{'cancreate'}) eq 'ARRAY') { + push(@{$changes->{'cancreate'}},'captcha'); + } elsif (!defined($changes->{'cancreate'})) { + $changes->{'cancreate'} = ['captcha']; + } + } + my ($newpub,$newpriv,$currpub,$currpriv); + if ($newsettings->{'captcha'} eq 'recaptcha') { + $newpub = $env{'form.'.$container.'_recaptchapub'}; + $newpriv = $env{'form.'.$container.'_recaptchapriv'}; + } + $newsettings->{'recaptchakeys'} = { + public => $newpub, + private => $newpriv, + }; + if (ref($current->{'recaptchakeys'}) eq 'HASH') { + $currpub = $current->{'recaptchakeys'}{'public'}; + $currpriv = $current->{'recaptchakeys'}{'private'}; + } + if (($newpub ne $currpub) || ($newpriv ne $currpriv)) { + if (ref($changes->{'cancreate'}) eq 'ARRAY') { + push(@{$changes->{'cancreate'}},'recaptchakeys'); + } elsif (!defined($changes->{'cancreate'})) { + $changes->{'cancreate'} = ['recaptchakeys']; + } + } + return; +} + sub modify_usermodification { my ($dom,%domconfig) = @_; my ($resulttext,%curr_usermodification,%changes); @@ -7313,80 +7407,75 @@ sub modify_serverstatuses { sub modify_helpsettings { my ($r,$dom,$confname,%domconfig) = @_; - my ($resulttext,$errors,%changes,%helphash); - - my $customhelpfile = $env{'form.loginhelpurl.filename'}; - my $defaulthelpfile = 'defaulthelp.html'; - my $servadm = $r->dir_config('lonAdmEMail'); - my ($configuserok,$author_ok,$switchserver) = - &config_check($dom,$confname,$servadm); - - my %defaultchecked = ('submitbugs' => 'on'); - my @offon = ('off','on'); - my %title = ( submitbugs => 'Display link for users to submit a bug', - loginhelpurl => 'Unauthenticated login help page set to custom file'); - + my ($resulttext,$errors,%changes,%helphash); + my $customhelpfile = $env{'form.loginhelpurl.filename'}; + my $defaulthelpfile = '/adm/loginproblems.html'; + my $defaulttext = &mt('Default in use'); + my $servadm = $r->dir_config('lonAdmEMail'); + my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm); + my %defaultchecked = ('submitbugs' => 'on'); + my @offon = ('off','on'); + my %title = ( + submitbugs => 'Display link for users to submit a bug', + loginhelpurl => 'Unauthenticated login help page set to custom file' + ); my @toggles = ('submitbugs'); - $helphash{'helpsettings'} = {}; - if (ref($domconfig{'helpsettings'}) ne 'HASH') { if ($domconfig{'helpsettings'} eq '') { $domconfig{'helpsettings'} = {}; } } - if (ref($domconfig{'helpsettings'}) eq 'HASH') { - foreach my $item (@toggles) { - - if ($defaultchecked{$item} eq 'on') { - if (($domconfig{'helpsettings'}{$item} eq '') && - ($env{'form.'.$item} eq '0')) { - $changes{$item} = 1; - } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) { - $changes{$item} = 1; - } - } elsif ($defaultchecked{$item} eq 'off') { - if (($domconfig{'helpsettings'}{$item} eq '') && - ($env{'form.'.$item} eq '1')) { - $changes{$item} = 1; - } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) { - $changes{$item} = 1; - } - } - $helphash{'helpsettings'}{$item} = $env{'form.'.$item}; - } - - if ($customhelpfile ne '') { - my $error; - if ($configuserok eq 'ok') { - if ($switchserver) { - $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver); - } else { - if ($author_ok eq 'ok') { - my ($result,$loginhelpurl) = - &publishlogo($r,'upload','loginhelpurl',$dom, - $confname,'help','','',$customhelpfile); - if ($result eq 'ok') { - $helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl; - $changes{'loginhelpurl'} = 1; - } else { - $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result); - } - } else { - $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$customhelpfile,$confname,$dom,$author_ok); - } - } - } else { - $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$customhelpfile,$confname,$dom,$configuserok); - } - if ($error) { - &Apache::lonnet::logthis($error); - $errors .= '
  • '.$error.'
  • '; - } - } - + if ($defaultchecked{$item} eq 'on') { + if ($domconfig{'helpsettings'}{$item} eq '') { + if ($env{'form.'.$item} eq '0') { + $changes{$item} = 1; + } + } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) { + $changes{$item} = 1; + } + } elsif ($defaultchecked{$item} eq 'off') { + if ($domconfig{'helpsettings'}{$item} eq '') { + if ($env{'form.'.$item} eq '1') { + $changes{$item} = 1; + } + } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) { + $changes{$item} = 1; + } + } + if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) { + $helphash{'helpsettings'}{$item} = $env{'form.'.$item}; + } + } + if ($customhelpfile ne '') { + my $error; + if ($configuserok eq 'ok') { + if ($switchserver) { + $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver); + } else { + if ($author_ok eq 'ok') { + my ($result,$loginhelpurl) = &publishlogo($r,'upload','loginhelpurl',$dom, + $confname,'help','','',$customhelpfile); + if ($result eq 'ok') { + $helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl; + $changes{'loginhelpurl'} = 1; + } else { + $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result); + } + } else { + $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$customhelpfile,$confname,$dom,$author_ok); + } + } + } else { + $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$customhelpfile,$confname,$dom,$configuserok); + } + if ($error) { + &Apache::lonnet::logthis($error); + $errors .= '
  • '.$error.'
  • '; + } + } if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') { if ($env{'form.loginhelpurl_del'}) { $helphash{'helpsettings'}{'loginhelpurl'} = ''; @@ -7394,38 +7483,42 @@ sub modify_helpsettings { } } } - - my $putresult; - if (keys(%changes) > 0) { - $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom); + $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom); } else { - $putresult = 'ok'; + $putresult = 'ok'; } - if ($putresult eq 'ok') { if (keys(%changes) > 0) { - $resulttext = &mt('Changes made:').'
      '; - foreach my $item (sort(keys(%changes))) { - if ($item eq 'submitbugs') { - $resulttext .= '
    • '.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'
    • '; - } - if ($item eq 'loginhelpurl') { - if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') { - $resulttext .= '
    • '.&mt('[_1] help file removed; [_2] file will be used for the unathorized help page in this domain.',$customhelpfile,$defaulthelpfile).'
    • '; - } else { - $resulttext .= '
    • '.&mt("$title{$item} [_1]",$customhelpfile).'
    • '; - } - } - } - $resulttext .= '
    '; - } else { - $resulttext = &mt('No changes made to help settings'); - } + $resulttext = &mt('Changes made:').'
      '; + foreach my $item (sort(keys(%changes))) { + if ($item eq 'submitbugs') { + $resulttext .= '
    • '.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".', + &Apache::loncommon::modal_link('http://bugs.loncapa.org', + &mt('LON-CAPA bug tracker'),600,500)).'
    • '; + } + if ($item eq 'loginhelpurl') { + if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') { + $resulttext .= '
    • '.&mt('custom log-in help file removed.').' '. + &Apache::loncommon::modal_link($defaulthelpfile, + $defaulttext,600,500).'
    • '; + } else { + $resulttext .= '
    • '.&Apache::loncommon::modal_link( + $helphash{'helpsettings'}{'loginhelpurl'}. + '?inhibitmenu=yes', + &mt('custom log-in help file'),600,500). + '
    • '; + } + } + } + $resulttext .= '
    '; + } else { + $resulttext = &mt('No changes made to help settings'); + } } else { - $resulttext = ''. - &mt('An error occurred: [_1]',$putresult).''; + $errors .= '
  • '.&mt('An error occurred storing the settings: [_1]', + $putresult).'
  • '; } if ($errors) { $resulttext .= &mt('The following errors occurred: ').'
      '. @@ -8422,4 +8515,71 @@ END } +sub recaptcha_js { + my %lt = &captcha_phrases(); + return <<"END"; + + + +END + +} + +sub captcha_phrases { + return &Apache::lonlocal::texthash ( + priv => 'Private key', + pub => 'Public key', + original => 'original (CAPTCHA)', + recaptcha => 'successor (ReCAPTCHA)', + notused => 'unused', + ); +} + 1;