Diff for /loncom/interface/domainprefs.pm between versions 1.378 and 1.386

version 1.378, 2021/02/01 15:58:41 version 1.386, 2021/09/21 22:54:26
Line 223  sub handler { Line 223  sub handler {
                 'ltitools','ssl','trust','lti','privacy','passwords',                  'ltitools','ssl','trust','lti','privacy','passwords',
                 'proctoring','wafproxy'],$dom);                  'proctoring','wafproxy'],$dom);
     my %encconfig =      my %encconfig =
         &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring'],$dom);          &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring'],$dom,undef,1);
     if (ref($domconfig{'ltitools'}) eq 'HASH') {      if (ref($domconfig{'ltitools'}) eq 'HASH') {
         if (ref($encconfig{'ltitools'}) eq 'HASH') {          if (ref($encconfig{'ltitools'}) eq 'HASH') {
             foreach my $id (keys(%{$domconfig{'ltitools'}})) {              foreach my $id (keys(%{$domconfig{'ltitools'}})) {
Line 297  sub handler { Line 297  sub handler {
                                  {col1 => 'Log-in Help',                                   {col1 => 'Log-in Help',
                                   col2 => 'Value'},                                    col2 => 'Value'},
                                  {col1 => 'Custom HTML in document head',                                   {col1 => 'Custom HTML in document head',
                                   col2 => 'Value'}],                                    col2 => 'Value'},
                                    {col1 => 'SSO',
                                     col2 => 'Dual login: SSO and non-SSO options'},
                                   ],
                       print => \&print_login,                        print => \&print_login,
                       modify => \&modify_login,                        modify => \&modify_login,
                     },                      },
Line 311  sub handler { Line 314  sub handler {
                       print => \&print_defaults,                        print => \&print_defaults,
                       modify => \&modify_defaults,                        modify => \&modify_defaults,
                     },                      },
         'wafproxy' =>            'wafproxy' =>
                     { text => 'Web Application Firewall/Reverse Proxy',                        { text => 'Web Application Firewall/Reverse Proxy',
                       help => 'Domain_Configuration_WAF_Proxy',                        help => 'Domain_Configuration_WAF_Proxy',
                       header => [{col1 => 'Domain server',                        header => [{col1 => 'Domain(s)',
                                   col2 => 'Alias for WAF/Reverse Proxy',                                    col2 => 'Servers and WAF/Reverse Proxy alias(es)',
                                  },                                   },
                                  {col1 => 'Setting',                                   {col1 => 'Domain(s)',
                                   col2 => 'Value',}],                                    col2 => 'WAF Configuration',}],
                       print => \&print_wafproxy,                        print => \&print_wafproxy,
                       modify => \&modify_wafproxy,                         modify => \&modify_wafproxy,
                     },                      },
         'passwords' =>          'passwords' =>
                     { text => 'Passwords (Internal authentication)',                      { text => 'Passwords (Internal authentication)',
Line 632  sub handler { Line 635  sub handler {
                                        {col1 => 'Log-in Help',                                         {col1 => 'Log-in Help',
                                         col2 => 'Value'},                                          col2 => 'Value'},
                                        {col1 => 'Custom HTML in document head',                                         {col1 => 'Custom HTML in document head',
                                         col2 => 'Value'}],                                          col2 => 'Value'},
                                          {col1 => 'SSO',
                                           col2 => 'Dual login: SSO and non-SSO options'},
                                         ],
                             print => \&print_login,                              print => \&print_login,
                             modify => \&modify_login,                              modify => \&modify_login,
                            };                             };
Line 855  sub print_config_box { Line 861  sub print_config_box {
         $output .= &lti_javascript($settings);          $output .= &lti_javascript($settings);
     } elsif ($action eq 'proctoring') {      } elsif ($action eq 'proctoring') {
         $output .= &proctoring_javascript($settings);          $output .= &proctoring_javascript($settings);
       } elsif ($action eq 'wafproxy') {
           $output .= &wafproxy_javascript($dom);
       } elsif ($action eq 'autoupdate') {
           $output .= &autoupdate_javascript();
       } elsif ($action eq 'login') {
           $output .= &saml_javascript();
     }      }
     $output .=      $output .=
          '<table class="LC_nested_outer">           '<table class="LC_nested_outer">
Line 874  sub print_config_box { Line 886  sub print_config_box {
         my $leftnobr = '';          my $leftnobr = '';
         if (($action eq 'rolecolors') || ($action eq 'defaults') ||          if (($action eq 'rolecolors') || ($action eq 'defaults') ||
             ($action eq 'directorysrch') ||              ($action eq 'directorysrch') ||
             (($action eq 'login') && ($numheaders < 4))) {              (($action eq 'login') && ($numheaders < 5))) {
             $colspan = ' colspan="2"';              $colspan = ' colspan="2"';
         }          }
         if ($action eq 'usersessions') {          if ($action eq 'usersessions') {
Line 905  sub print_config_box { Line 917  sub print_config_box {
         } elsif ($action eq 'scantron') {          } elsif ($action eq 'scantron') {
             $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);              $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
         } elsif ($action eq 'login') {          } elsif ($action eq 'login') {
             if ($numheaders == 4) {              if ($numheaders == 5) {
                 $colspan = ' colspan="2"';                  $colspan = ' colspan="2"';
                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);                  $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
             } else {              } else {
Line 1046  sub print_config_box { Line 1058  sub print_config_box {
               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.                <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
                            $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);                             $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
         } elsif ($action eq 'login') {          } elsif ($action eq 'login') {
             if ($numheaders == 4) {              if ($numheaders == 5) {
                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'                  $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
            </table>             </table>
           </td>            </td>
Line 1070  sub print_config_box { Line 1082  sub print_config_box {
            <td>             <td>
             <table class="LC_nested">              <table class="LC_nested">
              <tr class="LC_info_row">';               <tr class="LC_info_row">';
             if ($numheaders == 4) {              if ($numheaders == 5) {
                 $output .= '                  $output .= '
               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>                <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>                <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
Line 1082  sub print_config_box { Line 1094  sub print_config_box {
              </tr>';               </tr>';
             }              }
             $rowtotal ++;              $rowtotal ++;
             $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);              $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
              </table>
             </td>
            </tr>
            <tr>
              <td>
               <table class="LC_nested">
                <tr class="LC_info_row">';
               if ($numheaders == 5) {
                   $output .= '
                 <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                 <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
                </tr>';
               } else {
                   $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>';
               }
               $rowtotal ++;
               $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
         } elsif ($action eq 'requestcourses') {          } elsif ($action eq 'requestcourses') {
             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);              $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
             $rowtotal ++;              $rowtotal ++;
Line 1217  sub print_config_box { Line 1249  sub print_config_box {
   
 sub print_login {  sub print_login {
     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;      my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
     my ($css_class,$datatable);      my ($css_class,$datatable,$switchserver,%lt);
     my %choices = &login_choices();      my %choices = &login_choices();
       if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
           %lt = &login_file_options();
           $switchserver = &check_switchserver($dom,$confname);
       }
     if ($caller eq 'service') {      if ($caller eq 'service') {
         my %servers = &Apache::lonnet::internet_dom_servers($dom);          my %servers = &Apache::lonnet::internet_dom_servers($dom);
         my $choice = $choices{'disallowlogin'};          my $choice = $choices{'disallowlogin'};
Line 1413  sub print_login { Line 1448  sub print_login {
         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);          $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
         $datatable .= '</tr></table></td></tr>';          $datatable .= '</tr></table></td></tr>';
     } elsif ($caller eq 'help') {      } elsif ($caller eq 'help') {
         my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);          my ($defaulturl,$defaulttype,%url,%type,%langchoices);
         my $switchserver = &check_switchserver($dom,$confname);  
         my $itemcount = 1;          my $itemcount = 1;
         $defaulturl = '/adm/loginproblems.html';          $defaulturl = '/adm/loginproblems.html';
         $defaulttype = 'default';          $defaulttype = 'default';
         %lt = &Apache::lonlocal::texthash (  
                      del     => 'Delete?',  
                      rep     => 'Replace:',  
                      upl     => 'Upload:',  
                      default => 'Default',  
                      custom  => 'Custom',  
                                              );  
         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());          %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
         my @currlangs;          my @currlangs;
         if (ref($settings) eq 'HASH') {          if (ref($settings) eq 'HASH') {
Line 1521  sub print_login { Line 1548  sub print_login {
                 }                  }
             }              }
         }          }
         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))) {          foreach my $lonhost (sort(keys(%domservers))) {
             my $exempt = &check_exempt_addresses($currexempt{$lonhost});              my $exempt = &check_exempt_addresses($currexempt{$lonhost});
             $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';              $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
Line 1552  sub print_login { Line 1571  sub print_login {
             $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';              $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
         }          }
         $datatable .= '</table></td></tr>';          $datatable .= '</table></td></tr>';
       } elsif ($caller eq 'saml') {
           my %domservers = &Apache::lonnet::get_servers($dom);
           $datatable .= '<tr><td colspan="3" style="text-align: left">'.
                         '<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);
           foreach my $lonhost (keys(%domservers)) {
               $samlurl{$lonhost} = '/adm/sso';
               $styleon{$lonhost} = 'display:none';
               $styleoff{$lonhost} = '';
           }
           if (ref($settings->{'saml'}) eq 'HASH') {
               foreach my $lonhost (keys(%{$settings->{'saml'}})) {
                   if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
                       $saml{$lonhost} = 1;
                       $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
                       $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
                       $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
                       $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
                       $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
                       $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
                       $styleon{$lonhost} = '';
                       $styleoff{$lonhost} = 'display:none';
                   } else {
                       $styleon{$lonhost} = 'display:none';
                       $styleoff{$lonhost} = '';
                   }
               }
           }
           my $itemcount = 1;
           foreach my $lonhost (sort(keys(%domservers))) {
               my $samlon = ' ';
               my $samloff = ' checked="checked" ';
               if ($saml{$lonhost}) {
                   $samlon = $samloff;
                   $samloff = ' ';
               }
               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.
                             'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
                             &mt('No').'</label>'.('&nbsp;'x2).
                             '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
                             '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>'.
                             '<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="'.
                             $samltext{$lonhost}.'" /></td><td>';
               if ($samlimg{$lonhost}) {
                   $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
                                 '<span class="LC_nobreak"><label>'.
                                 '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
                                 $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
               } else {
                   $datatable .= $lt{'upl'};
               }
               $datatable .='<br />';
               if ($switchserver) {
                   $datatable .= &mt('Upload to library server: [_1]',$switchserver);
               } else {
                   $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" '.
                             'value="'.$samlurl{$lonhost}.'" /></td>'.
                             '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="15">'.
                             $samltitle{$lonhost}.'</textarea></td>'.
                             '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="8" '.
                             'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
                             '</table></td>'.
                             '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%">&nbsp;</td></tr>';
              $itemcount ++;
           }
           $datatable .= '</table></td></tr>';
     }      }
     return $datatable;      return $datatable;
 }  }
Line 1588  sub login_choices { Line 1689  sub login_choices {
             headtag       => "Custom markup",              headtag       => "Custom markup",
             action        => "Action",              action        => "Action",
             current       => "Current",              current       => "Current",
               samllanding   => "Dual login?",
               samloptions   => "Options",
         );          );
     return %choices;      return %choices;
 }  }
   
   sub login_file_options {
         return &Apache::lonlocal::texthash(
                                              del     => 'Delete?',
                                              rep     => 'Replace:',
                                              upl     => 'Upload:',
                                              curr    => 'View contents',
                                              default => 'Default',
                                              custom  => 'Custom',
                                              none    => 'None',
         );
   }
   
 sub print_rolecolors {  sub print_rolecolors {
     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;      my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
     my %choices = &color_font_choices();      my %choices = &color_font_choices();
Line 2844  function toggleLTITools(form,setting,ite Line 2959  function toggleLTITools(form,setting,ite
 ENDSCRIPT  ENDSCRIPT
 }  }
   
   sub wafproxy_javascript {
       my ($dom) = @_;
       return <<"ENDSCRIPT";
   <script type="text/javascript">
   // <![CDATA[
   function updateWAF() {
       if (document.getElementById('wafproxy_remoteip')) {
           var wafremote = 0;
           if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
               wafremote = 1;
           }
           var fields = new Array('header','trust');
           for (var i=0; i<fields.length; i++) {
               if (document.getElementById('wafproxy_'+fields[i])) {
                   if (wafremote == 1) {
                       document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
                   }
                   else {
                       document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
                   }
               }
           }
           if (document.getElementById('wafproxyranges_$dom')) {
               if (wafremote == 1) {
                   document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
               } else {
                   for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
                       if (document.display.wafproxy_vpnaccess[i].checked) {
                           if (document.display.wafproxy_vpnaccess[i].value == 0) {
                               document.getElementById('wafproxyranges_$dom').style.display = 'none';
                           }
                       }
                   }
               }
           }
       }
       return;
   }
   
   function checkWAF() {
       if (document.getElementById('wafproxy_remoteip')) {
           var wafvpn = 0;
           for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
               if (document.display.wafproxy_vpnaccess[i].checked) {
                   if (document.display.wafproxy_vpnaccess[i].value == 1) {
                       wafvpn = 1;
                   }
                   break;
               }
           }
           var vpn = new Array('vpnint','vpnext');
           for (var i=0; i<vpn.length; i++) {
               if (document.getElementById('wafproxy_show_'+vpn[i])) {
                   if (wafvpn == 1) {
                       document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
                   }
                   else {
                       document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
                   }
               }
           }
           if (document.getElementById('wafproxyranges_$dom')) {
               if (wafvpn == 1) {
                   document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
               }
               else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
                   document.getElementById('wafproxyranges_$dom').style.display = 'none';
               }
           }
       }
       return;
   }
   
   function toggleWAF() {
       if (document.getElementById('wafproxy_table')) {
           var wafproxy = 0;
           for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
                if (document.display.wafproxy_${dom}[i].checked) {
                    if (document.display.wafproxy_${dom}[i].value == 1) {
                        wafproxy = 1;
                        break;
                   }
               }
           }
           if (wafproxy == 1) {
               document.getElementById('wafproxy_table').style.display='inline';
           }
           else {
              document.getElementById('wafproxy_table').style.display='none';
           }
           if (document.getElementById('wafproxyrow_${dom}')) {
               if (wafproxy == 1) {
                   document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
               }
               else {
                   document.getElementById('wafproxyrow_${dom}').style.display = 'none';
               }
           }
           if (document.getElementById('nowafproxyrow_$dom')) {
               if (wafproxy == 1) {
                   document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
               }
               else {
                   document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
               }
           }
       }
       return;
   }
   // ]]>
   </script>
   
   ENDSCRIPT
   }
   
 sub proctoring_javascript {  sub proctoring_javascript {
     my ($settings) = @_;      my ($settings) = @_;
     my (%ordered,$total,%jstext);      my (%ordered,$total,%jstext);
Line 3194  function toggleLTI(form,setting,item) { Line 3424  function toggleLTI(form,setting,item) {
 ENDSCRIPT  ENDSCRIPT
 }  }
   
   sub autoupdate_javascript {
       return <<"ENDSCRIPT";
   <script type="text/javascript">
   // <![CDATA[
   function toggleLastActiveDays(form) {
       var radioname = 'lastactive';
       var divid = 'lastactive_div';
       var num = form.elements[radioname].length;
       if (num) {
           var setvis = '';
           for (var i=0; i<num; i++) {
               if (form.elements[radioname][i].checked) {
                   if (form.elements[radioname][i].value == '1') {
                       if (document.getElementById(divid)) {
                           document.getElementById(divid).style.display = 'inline-block';
                       }
                       setvis = 1;
                   }
                   break;
               }
           }
           if (!setvis) {
               if (document.getElementById(divid)) {
                   document.getElementById(divid).style.display = 'none';
               }
           }
       }
       return;
   }
   // ]]>
   </script>
   
   ENDSCRIPT
   }
   
   sub saml_javascript {
       return <<"ENDSCRIPT";
   <script type="text/javascript">
   // <![CDATA[
   function toggleSamlOptions(form,hostid) { 
       var radioname = 'saml_'+hostid;
       var tablecellon = 'samloptionson_'+hostid;
       var tablecelloff = 'samloptionsoff_'+hostid;
       var num = form.elements[radioname].length;
       if (num) {
           var setvis = ''; 
           for (var i=0; i<num; i++) {
               if (form.elements[radioname][i].checked) {
                   if (form.elements[radioname][i].value == '1') { 
                       if (document.getElementById(tablecellon)) {
                           document.getElementById(tablecellon).style.display='';
                       }
                       if (document.getElementById(tablecelloff)) {
                           document.getElementById(tablecelloff).style.display='none';
                       }
                       setvis = 1;
                   }
                   break;
               }
           }
           if (!setvis) {
               if (document.getElementById(tablecellon)) {
                   document.getElementById(tablecellon).style.display='none';
               }
               if (document.getElementById(tablecelloff)) {
                   document.getElementById(tablecelloff).style.display='';
               }
           }
       }
       return;
   }
   // ]]>
   </script>
   
   ENDSCRIPT
   }
   
 sub print_autoenroll {  sub print_autoenroll {
     my ($dom,$settings,$rowtotal) = @_;      my ($dom,$settings,$rowtotal) = @_;
     my $autorun = &Apache::lonnet::auto_run(undef,$dom),      my $autorun = &Apache::lonnet::auto_run(undef,$dom),
Line 3280  sub print_autoenroll { Line 3587  sub print_autoenroll {
   
 sub print_autoupdate {  sub print_autoupdate {
     my ($position,$dom,$settings,$rowtotal) = @_;      my ($position,$dom,$settings,$rowtotal) = @_;
     my $datatable;      my ($enable,$datatable);
     if ($position eq 'top') {      if ($position eq 'top') {
           my %choices = &Apache::lonlocal::texthash (
                             run        => 'Auto-update active?',
                             classlists => 'Update information in classlists?',
                             unexpired  => 'Skip updates for users without active or future roles?',
                             lastactive => 'Skip updates for inactive users?',
           );
           my $itemcount = 0;
         my $updateon = ' ';          my $updateon = ' ';
         my $updateoff = ' checked="checked" ';          my $updateoff = ' checked="checked" ';
         my $classlistson = ' ';  
         my $classlistsoff = ' checked="checked" ';  
         if (ref($settings) eq 'HASH') {          if (ref($settings) eq 'HASH') {
             if ($settings->{'run'} eq '1') {              if ($settings->{'run'} eq '1') {
                 $updateon = $updateoff;                  $updateon = $updateoff;
                 $updateoff = ' ';                  $updateoff = ' ';
             }              }
             if ($settings->{'classlists'} eq '1') {  
                 $classlistson = $classlistsoff;  
                 $classlistsoff = ' ';  
             }  
         }          }
         my %title = (          $enable = '<tr class="LC_odd_row">'.
                    run => 'Auto-update active?',                    '<td>'.$choices{'run'}.'</td>'.
                    classlists => 'Update information in classlists?',                    '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
                     );  
         $datatable = '<tr class="LC_odd_row">'.   
                   '<td>'.&mt($title{'run'}).'</td>'.  
                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.  
                   '<input type="radio" name="autoupdate_run"'.                    '<input type="radio" name="autoupdate_run"'.
                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.                    $updateoff.' value="0" />'.&mt('No').'</label>&nbsp;'.
                   '<label><input type="radio" name="autoupdate_run"'.                    '<label><input type="radio" name="autoupdate_run"'.
                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.                    $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
                   '</tr><tr>'.  
                   '<td>'.&mt($title{'classlists'}).'</td>'.  
                   '<td class="LC_right_item"><span class="LC_nobreak">'.  
                   '<label><input type="radio" name="classlists"'.  
                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.  
                   '<label><input type="radio" name="classlists"'.  
                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.  
                   '</tr>';                    '</tr>';
         $$rowtotal += 2;          my @toggles = ('classlists','unexpired');
           my %defaultchecked = ('classlists' => 'off',
                                 'unexpired'  => 'off'
                                 );
           $$rowtotal ++;
           ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                                                        \%choices,$itemcount,'','','left','no');
           $datatable = $enable.$datatable;
           $$rowtotal += $itemcount;
           my $lastactiveon = ' ';
           my $lastactiveoff = ' checked="checked" ';
           my $lastactivestyle = 'none';
           my $lastactivedays;
           my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
           if (ref($settings) eq 'HASH') {
               if ($settings->{'lastactive'} =~ /^\d+$/) {
                   $lastactiveon = $lastactiveoff;
                   $lastactiveoff = ' ';
                   $lastactivestyle = 'inline-block';
                   $lastactivedays = $settings->{'lastactive'};
               }
           }
           my $css_class = $itemcount%2?' class="LC_odd_row"':'';
           $datatable .= '<tr'.$css_class.'>'.
                         '<td>'.$choices{'lastactive'}.'</td>'.
                         '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
                         '<input type="radio" name="lastactive"'.
                         $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
                         '&nbsp;<label>'.
                         '<input type="radio" name="lastactive"'.
                         $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
                         '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
                         ':&nbsp;'.&mt('inactive = no activity in last [_1] days',
                             '<input type="text" size="5" name="lastactivedays" value="'.
                             $lastactivedays.'" />').
                         '</span></td>'.
                         '</tr>';
           $$rowtotal ++;
     } elsif ($position eq 'middle') {      } elsif ($position eq 'middle') {
         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);          my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
         my $numinrow = 3;          my $numinrow = 3;
Line 4444  sub helpdeskroles_access { Line 4778  sub helpdeskroles_access {
   
 sub radiobutton_prefs {  sub radiobutton_prefs {
     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,      my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
         $additional,$align) = @_;          $additional,$align,$firstval) = @_;
     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&      return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                    (ref($choices) eq 'HASH'));                     (ref($choices) eq 'HASH'));
   
Line 4484  sub radiobutton_prefs { Line 4818  sub radiobutton_prefs {
         } else {          } else {
             $datatable .= '<td class="LC_right_item">';              $datatable .= '<td class="LC_right_item">';
         }          }
         $datatable .=          $datatable .= '<span class="LC_nobreak">';
             '<span class="LC_nobreak">'.          if ($firstval eq 'no') {
             '<label><input type="radio" name="'.              $datatable .=
             $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').                  '<label><input type="radio" name="'.
             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.                  $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
             $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.                  '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
             '</span>'.$additional.                  $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
             '</td>'.          } else {
             '</tr>';              $datatable .=
                   '<label><input type="radio" name="'.
                   $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
                   '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
                   $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
           }
           $datatable .= '</span>'.$additional.'</td></tr>';
         $itemcount ++;          $itemcount ++;
     }      }
     return ($datatable,$itemcount);      return ($datatable,$itemcount);
Line 6155  sub print_coursedefaults { Line 6495  sub print_coursedefaults {
         my $currcanclone = 'none';          my $currcanclone = 'none';
         my $onclick;          my $onclick;
         my @cloneoptions = ('none','domain');          my @cloneoptions = ('none','domain');
         my %clonetitles = (          my %clonetitles = &Apache::lonlocal::texthash (
                              none     => 'No additional course requesters',                               none     => 'No additional course requesters',
                              domain   => "Any course requester in course's domain",                               domain   => "Any course requester in course's domain",
                              instcode => 'Course requests for official courses ...',                               instcode => 'Course requests for official courses ...',
Line 7178  sub print_wafproxy { Line 7518  sub print_wafproxy {
     my $itemcount = 0;      my $itemcount = 0;
     my $datatable;      my $datatable;
     my %servers = &Apache::lonnet::internet_dom_servers($dom);      my %servers = &Apache::lonnet::internet_dom_servers($dom);
     my (%othercontrol,%otherdoms,%aliases,%values,$setdom);      my (%othercontrol,%otherdoms,%aliases,%values,$setdom,$showdom);
     my %lt = &wafproxy_titles();      my %lt = &wafproxy_titles();
     foreach my $server (sort(keys(%servers))) {      foreach my $server (sort(keys(%servers))) {
         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});          my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
           next if ($serverhome eq '');
         my $serverdom;          my $serverdom;
         if ($serverhome ne $server) {          if ($serverhome ne $server) {
             $serverdom = &Apache::lonnet::host_domain($serverhome);              $serverdom = &Apache::lonnet::host_domain($serverhome);
             $othercontrol{$server} = $serverdom;              if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
                   $othercontrol{$server} = $serverdom;
               }
         } else {          } else {
             $serverdom = &Apache::lonnet::host_domain($server);              $serverdom = &Apache::lonnet::host_domain($server);
               next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
             if ($serverdom ne $dom) {              if ($serverdom ne $dom) {
                 $othercontrol{$server} = $serverdom;                  $othercontrol{$server} = $serverdom;
             } else {              } else {
                 $setdom = 1;                  $setdom = 1;
                 if (ref($settings) eq 'HASH') {                  if (ref($settings) eq 'HASH') {
                     %{$values{$dom}} = ();  
                     if (ref($settings->{'alias'}) eq 'HASH') {                      if (ref($settings->{'alias'}) eq 'HASH') {
                         $aliases{$dom} = $settings->{'alias'};                          $aliases{$dom} = $settings->{'alias'};
                     }                          if ($aliases{$dom} ne '') {
                     foreach my $item ('ipheader','trusted','vpnint','vpnext') {                              $showdom = 1;
                         $values{$dom}{$item} = $settings->{$item};                          }
                     }                      }
                 }                  }
             }              }
         }          }
     }      }
       if ($setdom) {
           %{$values{$dom}} = ();
           if (ref($settings) eq 'HASH') {
               foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
                   $values{$dom}{$item} = $settings->{$item};
               }
           }
       }
     if (keys(%othercontrol)) {      if (keys(%othercontrol)) {
         %otherdoms = reverse(%othercontrol);          %otherdoms = reverse(%othercontrol);
         foreach my $domain (keys(%otherdoms)) {          foreach my $domain (keys(%otherdoms)) {
             %{$values{$domain}} = ();              %{$values{$domain}} = ();
             my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);              my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
             if (ref($config{$domain}) eq 'HASH') {              if (ref($config{'wafproxy'}) eq 'HASH') {
                 if (ref($config{$domain}{'wafproxy'}) eq 'HASH') {                  $aliases{$domain} = $config{'wafproxy'}{'alias'};
                     $aliases{$domain} = $config{$domain}{'wafproxy'}{'alias'};                  foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
                     foreach my $item ('ipheader','trusted','vpnint','vpnext') {                      $values{$domain}{$item} = $config{'wafproxy'}{$item};
                         $values{$domain}{$item} = $config{$domain}{'wafproxy'}{$item};  
                     }  
                 }                  }
             }              }
         }          }
     }      }
     if ($position eq 'top') {      if ($position eq 'top') {
         my %servers = &Apache::lonnet::internet_dom_servers($dom);          my %servers = &Apache::lonnet::internet_dom_servers($dom);
           my %aliasinfo;
         foreach my $server (sort(keys(%servers))) {          foreach my $server (sort(keys(%servers))) {
             $itemcount ++;               $itemcount ++;
             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';              my $dom_in_effect;
             $datatable .= '<tr'.$css_class.'>'.              my $aliasrows = '<tr>'.
                           '<td>'.&mt('Hostname').':&nbsp;'.                              '<td class="LC_left_item" style="vertical-align: baseline;">'.
                                 &Apache::lonnet::hostname($server).'</td>'.                              &mt('Hostname').':&nbsp;'.
                           '<td class="LC_right_item">';                              '<i>'.&Apache::lonnet::hostname($server).'</i></td><td>&nbsp;</td>';
             if ($othercontrol{$server}) {              if ($othercontrol{$server}) {
                   $dom_in_effect = $othercontrol{$server};
                 my $current;                  my $current;
                 if (ref($aliases{$othercontrol{$server}}) eq 'HASH') {                  if (ref($aliases{$dom_in_effect}) eq 'HASH') {
                     $current = $aliases{$othercontrol{$server}{$server}};                      $current = $aliases{$dom_in_effect}{$server};
                 }                  }
                   $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
                                 &mt('Alias').':&nbsp';
                 if ($current) {                  if ($current) {
                     $datatable .= $current;                      $aliasrows .= $current;
                 } else {                  } else {
                     $datatable .= &mt('None in effect');                      $aliasrows .= &mt('None');
                 }                  }
                 $datatable .= '<br /><span class="LC_small">('.                  $aliasrows .= '&nbsp;<span class="LC_small">('.
                               &mt('WAF/Reverse Proxy controlled by domain: [_1]',                                &mt('controlled by domain: [_1]',
                                   '<b>'.$othercontrol{$server}.'</b>').'</span>';                                    '<b>'.$dom_in_effect.'</b>').')</span></td>';
             } else {              } else {
                   $dom_in_effect = $dom;
                 my $current;                  my $current;
                 if (ref($aliases{$dom}) eq 'HASH') {                  if (ref($aliases{$dom}) eq 'HASH') {
                     if ($aliases{$dom}{$server}) {                      if ($aliases{$dom}{$server}) {
                         $current = $aliases{$dom}{$server};                          $current = $aliases{$dom}{$server};
                     }                      }
                 }                  }
                 $datatable .= '<input type="text" name="wafproxy_alias_'.$server.'" '.                  $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
                               'value="'.$current.'" size="30" />';                                &mt('Alias').':&nbsp;'.
                                 '<input type="text" name="wafproxy_alias_'.$server.'" '.
                                 'value="'.$current.'" size="30" /></td>';
               }
               $aliasrows .= '</tr>';
               $aliasinfo{$dom_in_effect} .= $aliasrows;
           }
           if ($aliasinfo{$dom}) {
               my ($onclick,$wafon,$wafoff,$showtable);
               $onclick = ' onclick="javascript:toggleWAF();"';
               $wafoff = ' checked="checked"';
               $showtable = ' style="display:none";';
               if ($showdom) {
                   $wafon = $wafoff;
                   $wafoff = '';
                   $showtable = ' style="display:inline;"';
               }
               $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
               $datatable = '<tr'.$css_class.'>'.
                            '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
                            '<span class="LC_nobreak">'.&mt('WAF in use?').'&nbsp;<label>'.
                            '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
                            &mt('Yes').'</label>'.('&nbsp;'x2).'<label>'.
                            '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
                            &mt('No').'</label></span></td>'.
                            '<td class="LC_left_item">'.
                            '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
                            '</table></td></tr>';
               $itemcount++;
           }
           if (keys(%otherdoms)) {
               foreach my $key (sort(keys(%otherdoms))) {
                   $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   $datatable .= '<tr'.$css_class.'>'.
                                 '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
                                 '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
                                 '</table></td></tr>';
                   $itemcount++;
             }              }
             $datatable .= '</td></tr>';  
         }          }
     } else {      } else {
           my %ip_methods = &remoteip_methods();
         if ($setdom) {          if ($setdom) {
             $itemcount ++;              $itemcount ++;
             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';              $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
             $datatable .= '<tr'.$css_class.'>'.              my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
                   $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
               $wafstyle = ' style="display:none;"';
               $nowafstyle = ' style="display:table-row;"';
               $currwafdisplay = ' style="display: none"';
               $wafrangestyle = ' style="display: none"';
               $curr_remotip = 'n';
               $ssltossl = ' checked="checked"';
               if ($showdom) {
                   $wafstyle = ' style="display:table-row;"';
                   $nowafstyle =  ' style="display:none;"';
                   if (keys(%{$values{$dom}})) {
                       if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
                           $curr_remotip = $values{$dom}{remoteip};
                       }
                       if ($curr_remotip eq 'h') {
                           $currwafdisplay = ' style="display:table-row"';
                           $wafrangestyle = ' style="display:inline-block;"';
                       }
                       if ($values{$dom}{'sslopt'}) {
                           $alltossl = ' checked="checked"';
                           $ssltossl = '';
                       }
                   }
                   if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
                       $vpndircheck = ' checked="checked"';
                       $currwafvpn = ' style="display:table-row;"';
                       $wafrangestyle = ' style="display:inline-block;"';
                   } else {
                       $vpnaliascheck = ' checked="checked"';
                       $currwafvpn = ' style="display:none;"';
                   }
               }
               $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
                             '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
                             '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
                             '</tr>'.
                             '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
                           '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.                            '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
                           &mt('Format for comma separated IP blocks').':<br />'.                            '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
                           &mt('A.B.C.D/N or A.B.C.D - E.F.G.H').'</td>'.                            &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'</div></td>'.
                           '<td class="LC_left_item"><table>';                            '<td class="LC_left_item"><table>'.
             foreach my $item ('ipheader','trusted','vpnint','vpnext') {                            '<tr>'.
                 $datatable .= '<tr>'.                            '<td valign="top">'.$lt{'remoteip'}.':&nbsp;'.
                               '<td valign="top">'.$lt{$item}.':&nbsp;';                            '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
                 if ($item eq 'ipheader') {              foreach my $option ('m','h','n') {
                     $datatable .= '<input type="text" value="'.$values{$dom}{$item}.'" '.                  my $sel;
                                   'name="wafproxy_'.$item.'" />';                  if ($option eq $curr_remotip) {
                       $sel = ' selected="selected"';
                 } else {                  }
                     $datatable .= '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.                  $datatable .= '<option value="'.$option.'"'.$sel.'>'.
                                   $values{$dom}{$item}.'</textarea>';                                $ip_methods{$option}.'</option>';
                 }              }
                 $datatable .= '</td></tr>';              $datatable .= '</select></td></tr>'."\n".
             }                            '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
             $datatable .= '</table></td></tr>';                            $lt{'ipheader'}.':&nbsp;'.
                             '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
                             'name="wafproxy_ipheader" />'.
                             '</td></tr>'."\n".
                             '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
                             $lt{'trusted'}.':<br />'.
                             '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
                             $values{$dom}{'trusted'}.'</textarea>'.
                             '</td></tr>'."\n".
                             '<tr><td><hr /></td></tr>'."\n".
                             '<tr>'.
                             '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
                             '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
                             $lt{'vpndirect'}.'</label>'.('&nbsp;'x2).
                             '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
                             $lt{'vpnaliased'}.'</label></span></td></tr>';
               foreach my $item ('vpnint','vpnext') {
                   $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
                                 '<td valign="top">'.$lt{$item}.':<br />'.
                                 '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
                                 $values{$dom}{$item}.'</textarea>'.
                                 '</td></tr>'."\n";
               }
               $datatable .= '<tr><td><hr /></td></tr>'."\n".
                             '<tr>'.
                             '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
                             '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
                             $lt{'alltossl'}.'</label>'.('&nbsp;'x2).
                             '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
                             $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
                             '</table></td></tr>';
         }          }
         if (keys(%otherdoms)) {          if (keys(%otherdoms)) {
             foreach my $domain (sort(keys(%otherdoms))) {              foreach my $domain (sort(keys(%otherdoms))) {
                 $itemcount ++;                  $itemcount ++;
                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';                  $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                 $datatable .= '<tr'.$css_class.'>'.                  $datatable .= '<tr'.$css_class.'>'.
                               '<td class="LC_left_item">'.&mt('Domain: [_1]',$domain).'</td>'.                                '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
                               '<td class="LC_left_item"><table>';                                '<td class="LC_left_item"><table>';
                 foreach my $item ('ipheader','trusted','vpnint','vpnext') {                  foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
                     my $showval = &mt('None');                      my $showval = &mt('None');
                       if ($item eq 'ssl') {
                           $showval = $lt{'ssltossl'};
                       }
                     if ($values{$domain}{$item}) {                      if ($values{$domain}{$item}) {
                         $showval = $values{$domain}{$item};                           $showval = $values{$domain}{$item};
                           if ($item eq 'ssl') {
                               $showval = $lt{'alltossl'};
                           } elsif ($item eq 'remoteip') {
                               $showval = $ip_methods{$values{$domain}{$item}};
                           }
                     }                      }
                     $datatable .= '<tr>'.                      $datatable .= '<tr>'.
                                   '<td>'.$lt{$item}.':&nbsp;'.$showval.'</td></tr>';                                    '<td>'.$lt{$item}.':&nbsp;'.$showval.'</td></tr>';
                 }                  }
                 $datatable .= '</table></td></tr>';                   $datatable .= '</table></td></tr>';
             }              }
         }          }
     }      }
Line 7302  sub print_wafproxy { Line 7768  sub print_wafproxy {
   
 sub wafproxy_titles {  sub wafproxy_titles {
     return &Apache::lonlocal::texthash(      return &Apache::lonlocal::texthash(
                vpnint => 'Internal IP Range(s) for VPN sessions',                 remoteip   => "Method for determining user's IP",
                vpnext => 'IP Range for backend WAF connections',                 ipheader   => 'Request header containing remote IP',
                trusted => 'Trusted IP range(s)',                 trusted    => 'Trusted IP range(s)',
                ipheader => 'Custom request header',                 vpnaccess  => 'Access from institutional VPN',
                  vpndirect  => 'via regular hostname (no WAF)',
                  vpnaliased => 'via aliased hostname (WAF)',
                  vpnint     => 'Internal IP Range(s) for VPN sessions',
                  vpnext     => 'IP Range(s) for backend WAF connections',
                  sslopt     => 'Forwarding http/https',
                  alltossl   => 'WAF forwards both http and https requests to https',
                  ssltossl   => 'WAF forwards http requests to http and https to https',
              );
   }
   
   sub remoteip_methods {
       return &Apache::lonlocal::texthash(
                 m => 'Use Apache mod_remoteip',
                 h => 'Use headers parsed by LON-CAPA',
                 n => 'Not in use',
            );             );
 }  }
   
Line 9395  sub print_defaults { Line 9876  sub print_defaults {
                     $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.                      $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.
                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.                                    '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
                                   &mt('delete').'</span></td>'.                                    &mt('delete').'</span></td>'.
                                   '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').                                    '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.                                    '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
                                   '</span></td></tr>';                                    '</span></td></tr>';
                 }                  }
Line 9415  sub print_defaults { Line 9896  sub print_defaults {
                               '<input type="text" size="10" name="addinststatus" value="" />'.                                '<input type="text" size="10" name="addinststatus" value="" />'.
                               '&nbsp;'.&mt('(new)').                                '&nbsp;'.&mt('(new)').
                               '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.                                '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
                               &mt('Name displayed:').                                &mt('Name displayed').':'.
                               '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.                                '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
                               '</tr>'."\n";                                '</tr>'."\n";
                 $rownum ++;                  $rownum ++;
Line 10424  ENDSCRIPT Line 10905  ENDSCRIPT
 sub initialize_categories {  sub initialize_categories {
     my ($itemcount) = @_;      my ($itemcount) = @_;
     my ($datatable,$css_class,$chgstr);      my ($datatable,$css_class,$chgstr);
     my %default_names = (      my %default_names = &Apache::lonlocal::texthash (
                       instcode    => 'Official courses (with institutional codes)',                        instcode    => 'Official courses (with institutional codes)',
                       communities => 'Communities',                        communities => 'Communities',
                       placement   => 'Placement Tests',                        placement   => 'Placement Tests',
Line 10923  sub usertype_update_row { Line 11404  sub usertype_update_row {
 sub modify_login {  sub modify_login {
     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;      my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,      my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);          %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
           %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
     %title = ( coursecatalog => 'Display course catalog',      %title = ( coursecatalog => 'Display course catalog',
                adminmail => 'Display administrator E-mail address',                 adminmail => 'Display administrator E-mail address',
                helpdesk  => 'Display "Contact Helpdesk" link',                 helpdesk  => 'Display "Contact Helpdesk" link',
                newuser => 'Link for visitors to create a user account',                 newuser => 'Link for visitors to create a user account',
                loginheader => 'Log-in box header');                 loginheader => 'Log-in box header',
                  saml => 'Dual SSO and non-SSO login');
     @offon = ('off','on');      @offon = ('off','on');
     if (ref($domconfig{login}) eq 'HASH') {      if (ref($domconfig{login}) eq 'HASH') {
         if (ref($domconfig{login}{loginvia}) eq 'HASH') {          if (ref($domconfig{login}{loginvia}) eq 'HASH') {
Line 10936  sub modify_login { Line 11419  sub modify_login {
                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};                  $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
             }              }
         }          }
           if (ref($domconfig{login}{'saml'}) eq 'HASH') {
               foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
                   if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
                       $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
                       $saml{$lonhost} = 1;
                       $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
                       $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
                       $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
                       $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
                       $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
                       $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
                   }
               }
           }
     }      }
     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],      ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                                            \%domconfig,\%loginhash);                                             \%domconfig,\%loginhash);
Line 11182  sub modify_login { Line 11679  sub modify_login {
             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';              $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
         }          }
     }      }
       my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
       my @newsamlimgs;
       foreach my $lonhost (keys(%domservers)) {
           if ($env{'form.saml_'.$lonhost}) {
               if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
                   push(@newsamlimgs,$lonhost);
               }
               foreach my $item ('text','alt','url','title','notsso') {
                   $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
               }
               if ($saml{$lonhost}) {
                   if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
   #FIXME Need to obsolete published image
                       delete($currsaml{$lonhost}{'img'});
                       $changes{'saml'}{$lonhost} = 1;
                   }
                   if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
                       $changes{'saml'}{$lonhost} = 1;
                   }
                   if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
                       $changes{'saml'}{$lonhost} = 1;
                   }
                   if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
                       $changes{'saml'}{$lonhost} = 1;
                   }
                   if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$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') {
                   $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
               }
           } else {
               delete($currsaml{$lonhost});
           }
       }
       foreach my $posshost (keys(%currsaml)) {
           unless (exists($domservers{$posshost})) { 
               delete($currsaml{$posshost}); 
           }
       }
       %{$loginhash{'login'}{'saml'}} = %currsaml;
       if (@newsamlimgs) {
           my $error;
           my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
           if ($configuserok eq 'ok') {
               if ($switchserver) {
                   $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
               } elsif ($author_ok eq 'ok') {
                   foreach my $lonhost (@newsamlimgs) {
                       my $formelem = 'saml_img_'.$lonhost;
                       my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                                                           "login/saml/$lonhost",'','',
                                                           $env{'form.saml_img_'.$lonhost.'.filename'});
                       if ($result eq 'ok') {
                           $currsaml{$lonhost}{'img'} = $imgurl;
                           $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
                           $changes{'saml'}{$lonhost} = 1;
                       } else {
                           my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
                                              $lonhost,$result);
                           $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                       }
                   }
               } else {
                   $error = &mt("Upload of SSO button image 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 SSO button image 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'});      &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
   
     my $defaulthelpfile = '/adm/loginproblems.html';      my $defaulthelpfile = '/adm/loginproblems.html';
Line 11222  sub modify_login { Line 11799  sub modify_login {
         }          }
         if (keys(%changes) > 0 || $colchgtext) {          if (keys(%changes) > 0 || $colchgtext) {
             &Apache::loncommon::devalidate_domconfig_cache($dom);              &Apache::loncommon::devalidate_domconfig_cache($dom);
               if (exists($changes{'saml'})) {
                   my $hostid_in_use;
                   my @hosts = &Apache::lonnet::current_machine_ids();
                   if (@hosts > 1) {
                       foreach my $hostid (@hosts) {
                           if (&Apache::lonnet::host_domain($hostid) eq $dom) {
                               $hostid_in_use = $hostid;
                               last;
                           }
                       }
                   } else {
                       $hostid_in_use = $r->dir_config('lonHostID');
                   }
                   if (($hostid_in_use) &&
                       (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
                       &devalidate_cache_new('samllanding',$hostid_in_use);
                   }
                   if (ref($lastactref) eq 'HASH') {
                       if (ref($changes{'saml'}) eq 'HASH') {
                           my %updates;
                           map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
                           $lastactref->{'samllanding'} = \%updates;
                       }
                   }
               }
             if (ref($lastactref) eq 'HASH') {              if (ref($lastactref) eq 'HASH') {
                 $lastactref->{'domainconfig'} = 1;                  $lastactref->{'domainconfig'} = 1;
             }              }
Line 11301  sub modify_login { Line 11903  sub modify_login {
                             }                              }
                         }                          }
                     }                      }
                   } elsif ($item eq 'saml') {
                       if (ref($changes{$item}) eq 'HASH') {
                           my %notlt = (
                                          text   => 'Text for log-in by SSO',
                                          img    => 'SSO button image',
                                          alt    => 'Alt text for button image',
                                          url    => 'SSO URL',
                                          title  => 'Tooltip for SSO link',
                                          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') {
                                       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}.'" />';
                                           }
                                           $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
                                                                     $value).'</li>';
                                       }
                                   }
                                   $resulttext .= '</ul></li>';
                               } else {
                                   $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
                               }
                           }
                       }
                 } elsif ($item eq 'captcha') {                  } elsif ($item eq 'captcha') {
                     if (ref($loginhash{'login'}) eq 'HASH') {                      if (ref($loginhash{'login'}) eq 'HASH') {
                         my $chgtxt;                          my $chgtxt;
Line 13269  sub modify_ltitools { Line 13903  sub modify_ltitools {
         my %ltienchash = (          my %ltienchash = (
                              $action => { %encconfig }                               $action => { %encconfig }
                          );                           );
         &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);          &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
         if (keys(%changes) > 0) {          if (keys(%changes) > 0) {
             my $cachetime = 24*60*60;              my $cachetime = 24*60*60;
             my %ltiall = %confhash;              my %ltiall = %confhash;
Line 13843  sub modify_proctoring { Line 14477  sub modify_proctoring {
         my %proc_enchash = (          my %proc_enchash = (
                              $action => { %encconfhash }                               $action => { %encconfhash }
                          );                           );
         &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom);          &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
         if (keys(%changes) > 0) {          if (keys(%changes) > 0) {
             my $cachetime = 24*60*60;              my $cachetime = 24*60*60;
             my %procall = %confhash;              my %procall = %confhash;
Line 14335  sub modify_lti { Line 14969  sub modify_lti {
         my %ltienchash = (          my %ltienchash = (
                              $action => { %encconfig }                               $action => { %encconfig }
                          );                           );
         &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);          &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
         if (keys(%changes) > 0) {          if (keys(%changes) > 0) {
             my $cachetime = 24*60*60;              my $cachetime = 24*60*60;
             my %ltiall = %confhash;              my %ltiall = %confhash;
Line 14677  sub modify_autoupdate { Line 15311  sub modify_autoupdate {
     }      }
     my @offon = ('off','on');      my @offon = ('off','on');
     my %title = &Apache::lonlocal::texthash (      my %title = &Apache::lonlocal::texthash (
                    run => 'Auto-update:',                      run        => 'Auto-update:',
                    classlists => 'Updates to user information in classlists?'                      classlists => 'Updates to user information in classlists?',
                       unexpired  => 'Skip updates for users without active or future roles?',
                       lastactive => 'Skip updates for inactive users?',
                 );                  );
     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);      my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
     my %fieldtitles = &Apache::lonlocal::texthash (      my %fieldtitles = &Apache::lonlocal::texthash (
Line 14722  sub modify_autoupdate { Line 15358  sub modify_autoupdate {
     my %updatehash = (      my %updatehash = (
                       autoupdate => { run => $env{'form.autoupdate_run'},                        autoupdate => { run => $env{'form.autoupdate_run'},
                                       classlists => $env{'form.classlists'},                                        classlists => $env{'form.classlists'},
                                         unexpired  => $env{'form.unexpired'},
                                       fields => {%fields},                                        fields => {%fields},
                                       lockablenames => \@lockablenames,                                        lockablenames => \@lockablenames,
                                     }                                      }
                      );                       );
       my $lastactivedays;
       if ($env{'form.lastactive'}) {
           $lastactivedays = $env{'form.lastactivedays'};
           $lastactivedays =~ s/^\s+|\s+$//g;
           unless ($lastactivedays =~ /^\d+$/) {
               undef($lastactivedays);
               $env{'form.lastactive'} = 0;
           }
       }
       $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
     foreach my $key (keys(%currautoupdate)) {      foreach my $key (keys(%currautoupdate)) {
         if (($key eq 'run') || ($key eq 'classlists')) {          if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
             if (exists($updatehash{autoupdate}{$key})) {              if (exists($updatehash{autoupdate}{$key})) {
                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {                  if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                     $changes{$key} = 1;                      $changes{$key} = 1;
Line 14773  sub modify_autoupdate { Line 15420  sub modify_autoupdate {
             $changes{'lockablenames'} = 1;              $changes{'lockablenames'} = 1;
         }          }
     }      }
       unless (grep(/^unexpired$/,keys(%currautoupdate))) {
           if ($updatehash{'autoupdate'}{'unexpired'}) {
               $changes{'unexpired'} = 1;
           }
       }
       unless (grep(/^lastactive$/,keys(%currautoupdate))) {
           if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
               $changes{'lastactive'} = 1;
           }
       }
     foreach my $item (@{$types},'default') {      foreach my $item (@{$types},'default') {
         if (defined($fields{$item})) {          if (defined($fields{$item})) {
             if (ref($currautoupdate{'fields'}) eq 'HASH') {              if (ref($currautoupdate{'fields'}) eq 'HASH') {
Line 14835  sub modify_autoupdate { Line 15492  sub modify_autoupdate {
                     my $newvalue;                      my $newvalue;
                     if ($key eq 'run') {                      if ($key eq 'run') {
                         $newvalue = $offon[$env{'form.autoupdate_run'}];                          $newvalue = $offon[$env{'form.autoupdate_run'}];
                       } elsif ($key eq 'lastactive') {
                           $newvalue = $offon[$env{'form.lastactive'}];
                           unless ($lastactivedays eq '') {
                               $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
                           }
                     } else {                      } else {
                         $newvalue = $offon[$env{'form.'.$key}];                          $newvalue = $offon[$env{'form.'.$key}];
                     }                      }
Line 16366  sub modify_passwords { Line 17028  sub modify_passwords {
                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';                                  $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
                             }                              }
                         } else {                          } else {
                             $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';                              $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
                         }                          }
                         if ($confighash{'passwords'}{'resetremove'}) {                          if ($confighash{'passwords'}{'resetremove'}) {
                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';                              $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
Line 19582  sub modify_wafproxy { Line 20244  sub modify_wafproxy {
             my $serverdom = &Apache::lonnet::host_domain($server);              my $serverdom = &Apache::lonnet::host_domain($server);
             if ($serverdom eq $dom) {              if ($serverdom eq $dom) {
                 $canset{$server} = 1;                  $canset{$server} = 1;
                 if (ref($domconfig{'wafproxy'}) eq 'HASH') {  
                     %{$values{$dom}} = ();  
                     if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {  
                         %curralias = %{$domconfig{'wafproxy'}{'alias'}};  
                     }  
                     foreach my $item ('ipheader','trusted','exempt') {  
                         $currvalue{$item} = $domconfig{'wafproxy'}{$item};  
                     }  
                 }  
             }              }
         }          }
     }      }
       if (ref($domconfig{'wafproxy'}) eq 'HASH') {
           %{$values{$dom}} = ();
           if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
               %curralias = %{$domconfig{'wafproxy'}{'alias'}};
           }
           foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
               $currvalue{$item} = $domconfig{'wafproxy'}{$item};
           }
       }
     my $output;      my $output;
     if (keys(%canset)) {      if (keys(%canset)) {
         %{$wafproxy{'alias'}} = ();          %{$wafproxy{'alias'}} = ();
         foreach my $key (sort(keys(%canset))) {          foreach my $key (sort(keys(%canset))) {
             $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};              if ($env{'form.wafproxy_'.$dom}) {
             $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;                  $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
             if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {                  $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
                 $changes{'alias'} = 1;                  if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
                       $changes{'alias'} = 1;
                   }
               } else {
                   $wafproxy{'alias'}{$key} = '';
                   if ($curralias{$key}) {
                       $changes{'alias'} = 1;
                   }
             }              }
             if ($wafproxy{'alias'}{$key} eq '') {              if ($wafproxy{'alias'}{$key} eq '') {
                 if ($curralias{$key}) {                  if ($curralias{$key}) {
Line 19616  sub modify_wafproxy { Line 20285  sub modify_wafproxy {
         # Localization for values in %warn occus in &mt() calls separately.          # Localization for values in %warn occus in &mt() calls separately.
         my %warn = (          my %warn = (
                      trusted => 'trusted IP range(s)',                       trusted => 'trusted IP range(s)',
                      exempt => 'exempt IP range(s)',                        vpnint => 'internal IP range(s) for VPN sessions(s)',
                        vpnext => 'IP range(s) for backend WAF connections',
                    );                     );
         foreach my $item ('ipheader','trusted','exempt') {          foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
             my $possible = $env{'form.wafproxy_'.$item};              my $possible = $env{'form.wafproxy_'.$item};
             $possible =~ s/^\s+|\s+$//g;              $possible =~ s/^\s+|\s+$//g;
             if ($possible ne '') {              if ($possible ne '') {
                 if ($item eq 'ipheader') {                  if ($item eq 'remoteip') {
                     $wafproxy{$item} = $possible;                      if ($possible =~ /^[mhn]$/) {
                           $wafproxy{$item} = $possible;
                       }
                   } elsif ($item eq 'ipheader') {
                       if ($wafproxy{'remoteip'} eq 'h') {
                           $wafproxy{$item} = $possible;
                       }
                   } elsif ($item eq 'sslopt') {
                       if ($possible =~ /^0|1$/) {
                           $wafproxy{$item} = $possible;
                       }
                 } else {                  } else {
                     my (@ok,$count);                      my (@ok,$count);
                     $possible =~ s/[\r\n]+/\s/g;                      if (($item eq 'vpnint') || ($item eq 'vpnext')) {
                     $possible =~ s/\s*-\s*/-/g;                          unless ($env{'form.wafproxy_vpnaccess'}) {
                     $possible =~ s/\s+/,/g;                              $possible = '';
                           }
                       } elsif ($item eq 'trusted') {
                           unless ($wafproxy{'remoteip'} eq 'h') {
                               $possible = '';
                           }
                       }
                       unless ($possible eq '') {
                           $possible =~ s/[\r\n]+/\s/g;
                           $possible =~ s/\s*-\s*/-/g;
                           $possible =~ s/\s+/,/g;
                       }
                     $count = 0;                      $count = 0;
                     if ($possible) {                      if ($possible ne '') {
                         foreach my $poss (split(/\,/,$possible)) {                          foreach my $poss (split(/\,/,$possible)) {
                             $count ++;                              $count ++;
                             if (&validate_ip_pattern($poss)) {                              if (&validate_ip_pattern($poss)) {
Line 19647  sub modify_wafproxy { Line 20338  sub modify_wafproxy {
                                      $diff,$warn{$item}).                                       $diff,$warn{$item}).
                                  '</li>');                                   '</li>');
                         }                          }
                         if ($wafproxy{$item} ne $currvalue{$item}) {  
                             $changes{$item} = 1;   
                         }  
                     }                      }
                 }                  }
             } else {                  if ($wafproxy{$item} ne $currvalue{$item}) {
                 if ($currvalue{$item}) {  
                     $changes{$item} = 1;                      $changes{$item} = 1;
                 }                  }
               } elsif ($currvalue{$item}) {
                   $changes{$item} = 1;
               } 
           }
       } else {
           if (keys(%curralias)) {
               $changes{'alias'} = 1;
           } 
           if (keys(%currvalue)) {
               foreach my $key (keys(%currvalue)) {
                   $changes{$key} = 1;
             }              }
         }          }
     }      }
Line 19668  sub modify_wafproxy { Line 20366  sub modify_wafproxy {
         if ($putresult eq 'ok') {          if ($putresult eq 'ok') {
             my $cachetime = 24*60*60;              my $cachetime = 24*60*60;
             my (%domdefaults,$updatedomdefs);              my (%domdefaults,$updatedomdefs);
             foreach my $item ('ipheader','trusted','exempt') {              foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
                 if ($changes{$item}) {                  if ($changes{$item}) {
                     unless ($updatedomdefs) {                      unless ($updatedomdefs) {
                         %domdefaults = &Apache::lonnet::get_domain_defaults($dom);                          %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
Line 19705  sub modify_wafproxy { Line 20403  sub modify_wafproxy {
                 }                  }
             }              }
             $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';              $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
             foreach my $item ('alias','ipheader','trusted','exempt') {              foreach my $item ('alias','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
                 if ($changes{$item}) {                  if ($changes{$item}) {
                     if ($item eq 'alias') {                      if ($item eq 'alias') {
                         my $numaliased = 0;                          my $numaliased = 0;
Line 19728  sub modify_wafproxy { Line 20426  sub modify_wafproxy {
                             $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';                              $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
                         }                          }
                     } else {                      } else {
                         if ($item eq 'ipheader') {                          if ($item eq 'remoteip') {
                               my %ip_methods = &remoteip_methods();
                               if ($wafproxy{$item} =~ /^[mh]$/) {
                                   $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
                                                         $ip_methods{$wafproxy{$item}}).'</li>';
                               } else {
                                   if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
                                       $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
                                                  '</li>';
                                   } else {
                                       $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
                                   }
                               }
                           } elsif ($item eq 'ipheader') {
                             if ($wafproxy{$item}) {                              if ($wafproxy{$item}) {
                                 $output .= '<li>'.&mt('Custom request header set to [_1]',                                  $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
                                                       $wafproxy{$item}).'</li>';                                                        $wafproxy{$item}).'</li>';
                             } else {                              } else {
                                 $output .= '<li>'.&mt('Custom request header deleted').'</li>';                                  $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
                             }                              }
                         } elsif ($item eq 'trusted') {                          } elsif ($item eq 'trusted') {
                             if ($wafproxy{$item}) {                              if ($wafproxy{$item}) {
                                 $output .= '<li>'.&mt('Trusted IP range(s) set to [_1]',                                  $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
                                                       $wafproxy{$item}).'</li>';                                                        $wafproxy{$item}).'</li>';
                             } else {                              } else {
                                 $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';                                  $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
                             }                              }
                         } elsif ($item eq 'exempt') {                          } elsif ($item eq 'vpnint') {
                               if ($wafproxy{$item}) {
                                   $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
                                                          $wafproxy{$item}).'</li>';
                               } else {
                                   $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
                               }
                           } elsif ($item eq 'vpnext') {
                             if ($wafproxy{$item}) {                              if ($wafproxy{$item}) {
                                 $output .= '<li>'.&mt('Exempt IP range(s) set to [_1]',                                  $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
                                                        $wafproxy{$item}).'</li>';                                                         $wafproxy{$item}).'</li>';
                             } else {                              } else {
                                 $output .= '<li>'.&mt('Exempt IP range(s) deleted').'</li>';                                  $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
                               }
                           } elsif ($item eq 'sslopt') {
                               if ($wafproxy{$item}) {
                                   $output .= '<li>'.&mt('WAF/Reverse Proxy expected to forward requests to https on LON-CAPA node, regardless of original protocol in web browser (http or https).').'</li>';
                               } else {
                                   $output .= '<li>'.&mt('WAF/Reverse Proxy expected to preserve original protocol in web browser (either http or https) when forwarding to LON-CAPA node.').'</li>';
                             }                              }
                         }                          }
                     }                      }
Line 21495  sub devalidate_remote_domconfs { Line 22219  sub devalidate_remote_domconfs {
     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();      map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
     my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',      my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
                       'directorysrch','passwdconf','cats','proxyalias');                        'directorysrch','passwdconf','cats','proxyalias');
       my %cache_by_lonhost;
       if (exists($cachekeys->{'samllanding'})) {
           if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
               my %landing = %{$cachekeys->{'samllanding'}};
               my %domservers = &Apache::lonnet::get_servers($dom);
               if (keys(%domservers)) {
                   foreach my $server (keys(%domservers)) {
                       my @cached;
                       next if ($thismachine{$server});
                       if ($landing{$server}) {
                           push(@cached,&escape('samllanding').':'.&escape($server));
                       }
                       if (@cached) {
                           $cache_by_lonhost{$server} = \@cached;
                       }
                   }
               }
           }
       }
     if (keys(%servers)) {      if (keys(%servers)) {
         foreach my $server (keys(%servers)) {          foreach my $server (keys(%servers)) {
             next if ($thismachine{$server});              next if ($thismachine{$server});
Line 21502  sub devalidate_remote_domconfs { Line 22245  sub devalidate_remote_domconfs {
             foreach my $name (@posscached) {              foreach my $name (@posscached) {
                 if ($cachekeys->{$name}) {                  if ($cachekeys->{$name}) {
                     if ($name eq 'proxyalias') {                      if ($name eq 'proxyalias') {
                         if (ref($cachekeys->{$name}) eq 'HASH') {                            if (ref($cachekeys->{$name}) eq 'HASH') {
                             foreach my $key (keys(%{$cachekeys->{$name}})) {                              foreach my $key (keys(%{$cachekeys->{$name}})) {
                                 push(@cached,&escape($name).':'.&escape($key));                                  push(@cached,&escape($name).':'.&escape($key));
                             }                              }
Line 21512  sub devalidate_remote_domconfs { Line 22255  sub devalidate_remote_domconfs {
                     }                      }
                 }                  }
             }              }
               if ((exists($cache_by_lonhost{$server})) &&
                   (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
                   push(@cached,@{$cache_by_lonhost{$server}});
               }
             if (@cached) {              if (@cached) {
                 &Apache::lonnet::remote_devalidate_cache($server,\@cached);                  &Apache::lonnet::remote_devalidate_cache($server,\@cached);
             }              }

Removed from v.1.378  
changed lines
  Added in v.1.386


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>