File:  [LON-CAPA] / loncom / interface / loncreateuser.pm
Revision 1.49: download - view: text, annotated - select for diffs
Sun Mar 23 08:31:41 2003 UTC (21 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- su was allowed to make dc for invalid domains (hostids)

    1: # The LearningOnline Network with CAPA
    2: # Create a user
    3: #
    4: # $Id: loncreateuser.pm,v 1.49 2003/03/23 08:31:41 albertel Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: # (Create a course
   29: # (My Desk
   30: #
   31: # (Internal Server Error Handler
   32: #
   33: # (Login Screen
   34: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
   35: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
   36: #
   37: # YEAR=2001
   38: # 3/1/1 Gerd Kortemeyer)
   39: #
   40: # 3/1 Gerd Kortemeyer)
   41: #
   42: # 2/14 Gerd Kortemeyer)
   43: #
   44: # 2/14,2/17,2/19,2/20,2/21,2/22,2/23,3/2,3/17,3/24,04/12 Gerd Kortemeyer
   45: # April Guy Albertelli
   46: # 05/10,10/16 Gerd Kortemeyer 
   47: # 02/11/02 Matthew Hall
   48: #
   49: # $Id: loncreateuser.pm,v 1.49 2003/03/23 08:31:41 albertel Exp $
   50: ###
   51: 
   52: package Apache::loncreateuser;
   53: 
   54: use strict;
   55: use Apache::Constants qw(:common :http);
   56: use Apache::lonnet;
   57: 
   58: my $loginscript; # piece of javascript used in two separate instances
   59: my $generalrule;
   60: my $authformnop;
   61: my $authformkrb;
   62: my $authformint;
   63: my $authformfsys;
   64: my $authformloc;
   65: 
   66: BEGIN {
   67:     $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
   68:     my $krbdefdom=$1;
   69:     $krbdefdom=~tr/a-z/A-Z/;
   70:     my %param = ( formname => 'document.cu',
   71:                   kerb_def_dom => $krbdefdom 
   72:                   );
   73: # no longer static due to configurable kerberos defaults
   74: #    $loginscript  = &Apache::loncommon::authform_header(%param);
   75:     $generalrule  = &Apache::loncommon::authform_authorwarning(%param);
   76:     $authformnop  = &Apache::loncommon::authform_nochange(%param);
   77: # no longer static due to configurable kerberos defaults
   78: #    $authformkrb  = &Apache::loncommon::authform_kerberos(%param);
   79:     $authformint  = &Apache::loncommon::authform_internal(%param);
   80:     $authformfsys = &Apache::loncommon::authform_filesystem(%param);
   81:     $authformloc  = &Apache::loncommon::authform_local(%param);
   82: }
   83: 
   84: 
   85: 
   86: # ==================================================== Figure out author access
   87: 
   88: sub authorpriv {
   89:     my ($auname,$audom)=@_;
   90:     if (($auname ne $ENV{'user.name'}) ||
   91:         (($audom ne $ENV{'user.domain'}) &&
   92:          ($audom ne $ENV{'request.role.domain'}))) { return ''; }
   93:     unless (&Apache::lonnet::allowed('cca',$audom)) { return ''; }
   94:     return 1;
   95: }
   96: 
   97: # =================================================================== Phase one
   98: 
   99: sub print_username_entry_form {
  100:     my $r=shift;
  101:     my $defdom=$ENV{'request.role.domain'};
  102:     my @domains = &Apache::loncommon::get_domains();
  103:     my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
  104:     my $bodytag =&Apache::loncommon::bodytag(
  105:                                   'Create Users, Change User Privileges');
  106:     my $selscript=&Apache::loncommon::studentbrowser_javascript();
  107:     my $sellink=&Apache::loncommon::selectstudent_link
  108:                                         ('crtuser','ccuname','ccdomain');
  109:     $r->print(<<"ENDDOCUMENT");
  110: <html>
  111: <head>
  112: <title>The LearningOnline Network with CAPA</title>
  113: $selscript
  114: </head>
  115: $bodytag
  116: <form action="/adm/createuser" method="post" name="crtuser">
  117: <input type="hidden" name="phase" value="get_user_info">
  118: <p>
  119: <table>
  120: <tr><td>Username:</td><td><input type="text" size="15" name="ccuname">
  121: </td><td rowspan="2">$sellink</td></tr><tr><td>
  122: Domain:</td><td>$domform</td></tr>
  123: </table> 
  124: </p>
  125: <input type="submit" value="Continue">
  126: </form>
  127: </body>
  128: </html>
  129: ENDDOCUMENT
  130: }
  131: 
  132: # =================================================================== Phase two
  133: sub print_user_modification_page {
  134:     my $r=shift;
  135:     my $ccuname=$ENV{'form.ccuname'};
  136:     my $ccdomain=$ENV{'form.ccdomain'};
  137: 
  138:     my $defdom=$ENV{'request.role.domain'};
  139: 
  140:     my ($krbdef,$krbdefdom) =
  141:        &Apache::loncommon::get_kerberos_defaults($defdom);
  142: 
  143:     my %param = ( formname => 'document.cu',
  144:                   kerb_def_dom => $krbdefdom,
  145:                   kerb_def_auth => $krbdef
  146:                   );
  147:     $loginscript  = &Apache::loncommon::authform_header(%param);
  148:     $authformkrb  = &Apache::loncommon::authform_kerberos(%param);
  149: 
  150:     $ccuname=~s/\W//g;
  151:     $ccdomain=~s/\W//g;
  152:     my $dochead =<<"ENDDOCHEAD";
  153: <html>
  154: <head>
  155: <title>The LearningOnline Network with CAPA</title>
  156: <script type="text/javascript" language="Javascript">
  157: 
  158:     function pclose() {
  159:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
  160:                  "height=350,width=350,scrollbars=no,menubar=no");
  161:         parmwin.close();
  162:     }
  163: 
  164:     function pjump(type,dis,value,marker,ret,call) {
  165:         parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
  166:                  +"&value="+escape(value)+"&marker="+escape(marker)
  167:                  +"&return="+escape(ret)
  168:                  +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
  169:                  "height=350,width=350,scrollbars=no,menubar=no");
  170: 
  171:     }
  172: 
  173:     function dateset() {
  174:         eval("document.cu."+document.cu.pres_marker.value+
  175:             ".value=document.cu.pres_value.value");
  176:         pclose();
  177:     }
  178: 
  179: </script>
  180: </head>
  181: ENDDOCHEAD
  182:     $r->print(&Apache::loncommon::bodytag(
  183:                                      'Create Users, Change User Privileges'));
  184:     my $forminfo =<<"ENDFORMINFO";
  185: <form action="/adm/createuser" method="post" name="cu">
  186: <input type="hidden" name="phase"       value="update_user_data">
  187: <input type="hidden" name="ccuname"     value="$ccuname">
  188: <input type="hidden" name="ccdomain"    value="$ccdomain">
  189: <input type="hidden" name="pres_value"  value="" >
  190: <input type="hidden" name="pres_type"   value="" >
  191: <input type="hidden" name="pres_marker" value="" >
  192: ENDFORMINFO
  193:     my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
  194:     my %incdomains; 
  195:     my %inccourses;
  196:     foreach (values(%Apache::lonnet::hostdom)) {
  197:        $incdomains{$_}=1;
  198:     }
  199:     foreach (keys(%ENV)) {
  200: 	if ($_=~/^user\.priv\.cm\.\/(\w+)\/(\w+)/) {
  201: 	    $inccourses{$1.'_'.$2}=1;
  202:         }
  203:     }
  204:     if ($uhome eq 'no_host') {
  205:         my $home_server_list=
  206:             '<option value="default" selected>default</option>'."\n".
  207:                 &Apache::loncommon::home_server_option_list($ccdomain);
  208:         
  209: 	$r->print(<<ENDNEWUSER);
  210: $dochead
  211: <h1>Create New User</h1>
  212: $forminfo
  213: <h2>New user "$ccuname" in domain $ccdomain</h2>
  214: <script type="text/javascript" language="Javascript">
  215: $loginscript
  216: </script>
  217: <input type='hidden' name='makeuser' value='1' />
  218: <h3>Personal Data</h3>
  219: <p>
  220: <table>
  221: <tr><td>First Name  </td>
  222:     <td><input type='text' name='cfirst'  size='15' /></td></tr>
  223: <tr><td>Middle Name </td> 
  224:     <td><input type='text' name='cmiddle' size='15' /></td></tr>
  225: <tr><td>Last Name   </td>
  226:     <td><input type='text' name='clast'   size='15' /></td></tr>
  227: <tr><td>Generation  </td>
  228:     <td><input type='text' name='cgen'    size='5'  /></td></tr>
  229: </table>
  230: ID/Student Number <input type='text' name='cstid'   size='15' /></p>
  231: Home Server: <select name="hserver" size="1"> $home_server_list </select>
  232: <hr />
  233: <h3>Login Data</h3>
  234: <p>$generalrule </p>
  235: <p>$authformkrb </p>
  236: <p>$authformint </p>
  237: <p>$authformfsys</p>
  238: <p>$authformloc </p>
  239: ENDNEWUSER
  240:     } else { # user already exists
  241: 	$r->print(<<ENDCHANGEUSER);
  242: $dochead
  243: <h1>Change User Privileges</h1>
  244: $forminfo
  245: <h2>User "$ccuname" in domain $ccdomain </h2>
  246: ENDCHANGEUSER
  247:         # Get the users information
  248:         my %userenv = &Apache::lonnet::get('environment',
  249:                           ['firstname','middlename','lastname','generation'],
  250:                           $ccdomain,$ccuname);
  251:         my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
  252:         $r->print(<<END);
  253: <hr />
  254: <table border="2">
  255: <tr>
  256: <th>first name</th><th>middle name</th><th>last name</th><th>generation</th>
  257: </tr>
  258: <tr>
  259: END
  260:         foreach ('firstname','middlename','lastname','generation') {
  261:            if (&Apache::lonnet::allowed('mau',$ccdomain)) {
  262:               $r->print(<<"END");            
  263: <td><input type="text" name="c$_" value="$userenv{$_}" size="15"/></td>
  264: END
  265:            } else {
  266:                $r->print('<td>'.$userenv{$_}.'</td>');
  267:            }
  268:         }
  269:         $r->print(<<END);
  270: </tr>
  271: </table>
  272: END
  273:         # Build up table of user roles to allow revocation of a role.
  274:         my ($tmp) = keys(%rolesdump);
  275:         unless ($tmp =~ /^(con_lost|error)/i) {
  276:            my $now=time;
  277:            $r->print(<<END);
  278: <hr />
  279: <h3>Revoke Existing Roles</h3>
  280: <table border=2>
  281: <tr><th>Revoke</th><th>Role</th><th>Extent</th><th>Start</th><th>End</th>
  282: END
  283: 	   foreach my $area (keys(%rolesdump)) {
  284:                next if ($area =~ /^rolesdef/);
  285:                my $role = $rolesdump{$area};
  286:                my $thisrole=$area;
  287:                $area =~ s/\_\w\w$//;
  288:                my ($role_code,$role_end_time,$role_start_time) = 
  289:                    split(/_/,$role);
  290:                my $bgcol='ffffff';
  291:                my $allowed=0;
  292:                if ($area =~ /^\/(\w+)\/(\d\w+)/ ) {
  293:                    my %coursedata=
  294:                        &Apache::lonnet::coursedescription($1.'_'.$2);
  295:                    my $carea='Course: '.$coursedata{'description'};
  296:                    $inccourses{$1.'_'.$2}=1;
  297:                    if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) {
  298:                        $allowed=1;
  299:                    }
  300:                    # Compute the background color based on $area
  301:                    $bgcol=$1.'_'.$2;
  302:                    $bgcol=~s/[^8-9b-e]//g;
  303:                    $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
  304:                    if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
  305:                        $carea.='<br>Section/Group: '.$3;
  306:                    }
  307:                    $area=$carea;
  308:                } else {
  309:                    # Determine if current user is able to revoke privileges
  310:                    if ($area=~ /^\/(\w+)\//) {
  311:                        if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
  312:                            $allowed=1;
  313:                        }
  314:                    } else {
  315:                        if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
  316:                            $allowed=1;
  317:                        }
  318:                    }
  319:                }
  320:                if ($role_code eq 'ca') {
  321:                    $area=~/\/(\w+)\/(\w+)/;
  322: 		   if (&authorpriv($2,$1)) {
  323: 		       $allowed=1;
  324:                    } else {
  325:                        $allowed=0;
  326:                    }
  327:                }
  328:                my $row = '';
  329:                $row.='<tr bgcolor=#"'.$bgcol.'"><td>';
  330:                my $active=1;
  331:                $active=0 if (($role_end_time) && ($now>$role_end_time));
  332:                if (($active) && ($allowed)) {
  333:                    $row.= '<input type="checkbox" name="rev:'.$thisrole.'">';
  334:                } else {
  335:                    $row.='&nbsp;';
  336:                }
  337:                $row.= '</td><td>'.&Apache::lonnet::plaintext($role_code).
  338:                       '</td><td>'.$area.
  339:                       '</td><td>'.($role_start_time?localtime($role_start_time)
  340:                                                    : '&nbsp;' ).
  341:                       '</td><td>'.($role_end_time  ?localtime($role_end_time)
  342:                                                    : '&nbsp;' )
  343:                       ."</td></tr>\n";
  344:                $r->print($row);
  345:            } # end of foreach        (table building loop)
  346: 	   $r->print('</table>');
  347:         }  # End of unless
  348: 	my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
  349: 	if ($currentauth=~/^krb(4|5):/) {
  350: 	    $currentauth=~/^krb(4|5):(.*)/;
  351: 	    my $krbdefdom=$1;
  352:             my %param = ( formname => 'document.cu',
  353:                           kerb_def_dom => $krbdefdom 
  354:                           );
  355:             $loginscript  = &Apache::loncommon::authform_header(%param);
  356: 	}
  357: 	# Check for a bad authentication type
  358:         unless ($currentauth=~/^krb(4|5):/ or
  359: 		$currentauth=~/^unix:/ or
  360: 		$currentauth=~/^internal:/ or
  361: 		$currentauth=~/^localauth:/
  362: 		) { # bad authentication scheme
  363: 	    if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
  364: 		$r->print(<<ENDBADAUTH);
  365: <hr />
  366: <script type="text/javascript" language="Javascript">
  367: $loginscript
  368: </script>
  369: <font color='#ff0000'>ERROR:</font>
  370: This user has an unrecognized authentication scheme ($currentauth).
  371: Please specify login data below.
  372: <h3>Login Data</h3>
  373: <p>$generalrule</p>
  374: <p>$authformkrb</p>
  375: <p>$authformint</p>
  376: <p>$authformfsys</p>
  377: <p>$authformloc</p>
  378: ENDBADAUTH
  379:             } else { 
  380:                 # This user is not allowed to modify the users 
  381:                 # authentication scheme, so just notify them of the problem
  382: 		$r->print(<<ENDBADAUTH);
  383: <hr />
  384: <script type="text/javascript" language="Javascript">
  385: $loginscript
  386: </script>
  387: <font color="#ff0000"> ERROR: </font>
  388: This user has an unrecognized authentication scheme ($currentauth).
  389: Please alert a domain coordinator of this situation.
  390: <hr />
  391: ENDBADAUTH
  392:             }
  393:         } else { # Authentication type is valid
  394: 	    my $authformcurrent='';
  395: 	    my $authform_other='';
  396: 	    if ($currentauth=~/^krb(4|5):/) {
  397: 		$authformcurrent=$authformkrb;
  398: 		$authform_other="<p>$authformint</p>\n".
  399:                     "<p>$authformfsys</p><p>$authformloc</p>";
  400: 	    }
  401: 	    elsif ($currentauth=~/^internal:/) {
  402: 		$authformcurrent=$authformint;
  403: 		$authform_other="<p>$authformkrb</p>".
  404:                     "<p>$authformfsys</p><p>$authformloc</p>";
  405: 	    }
  406: 	    elsif ($currentauth=~/^unix:/) {
  407: 		$authformcurrent=$authformfsys;
  408: 		$authform_other="<p>$authformkrb</p>".
  409:                     "<p>$authformint</p><p>$authformloc;</p>";
  410: 	    }
  411: 	    elsif ($currentauth=~/^localauth:/) {
  412: 		$authformcurrent=$authformloc;
  413: 		$authform_other="<p>$authformkrb</p>".
  414:                     "<p>$authformint</p><p>$authformfsys</p>";
  415: 	    }
  416: 	    $authformcurrent=<<ENDCURRENTAUTH;
  417: <table border='1'>
  418: <tr>
  419: <td><font color='#ff0000'>* * * WARNING * * *</font></td>
  420: <td><font color='#ff0000'>* * * WARNING * * *</font></td>
  421: </tr>
  422: <tr><td bgcolor='#cbbcbb'>$authformcurrent</td>
  423: <td bgcolor='#cbbcbb'>Changing this value will overwrite existing authentication for the user; you should notify the user of this change.</td></tr>
  424: </table>
  425: ENDCURRENTAUTH
  426:             if (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'})) {
  427: 		# Current user has login modification privileges
  428: 		$r->print(<<ENDOTHERAUTHS);
  429: <hr />
  430: <script type="text/javascript" language="Javascript">
  431: $loginscript
  432: </script>
  433: <h3>Change Current Login Data</h3>
  434: <p>$generalrule</p>
  435: <p>$authformnop</p>
  436: <p>$authformcurrent</p>
  437: <h3>Enter New Login Data</h3>
  438: $authform_other
  439: ENDOTHERAUTHS
  440:             }
  441:         }  ## End of "check for bad authentication type" logic
  442:     } ## End of new user/old user logic
  443:     $r->print('<hr /><h3>Add Roles</h3>');
  444: #
  445: # Co-Author
  446: # 
  447:     if (&authorpriv($ENV{'user.name'},$ENV{'request.role.domain'}) &&
  448:         ($ENV{'user.name'} ne $ccuname || $ENV{'user.domain'} ne $ccdomain)) {
  449:         # No sense in assigning co-author role to yourself
  450: 	my $cuname=$ENV{'user.name'};
  451:         my $cudom=$ENV{'request.role.domain'};
  452:        $r->print(<<ENDCOAUTH);
  453: <h4>Construction Space</h4>
  454: <table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>
  455: <th>Start</th><th>End</th></tr>
  456: <tr>
  457: <td><input type=checkbox name="act_$cudom\_$cuname\_ca"></td>
  458: <td>Co-Author</td>
  459: <td>$cudom\_$cuname</td>
  460: <td><input type=hidden name="start_$cudom\_$cuname\_ca" value=''>
  461: <a href=
  462: "javascript:pjump('date_start','Start Date Co-Author',document.cu.start_$cudom\_$cuname\_ca.value,'start_$cudom\_$cuname\_ca','cu.pres','dateset')">Set Start Date</a></td>
  463: <td><input type=hidden name="end_$cudom\_$cuname\_ca" value=''>
  464: <a href=
  465: "javascript:pjump('date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset')">Set End Date</a></td>
  466: </tr>
  467: </table>
  468: ENDCOAUTH
  469:     }
  470: #
  471: # Domain level
  472: #
  473:     $r->print('<h4>Domain Level</h4>'.
  474:     '<table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>'.
  475:     '<th>Start</th><th>End</th></tr>');
  476:     foreach ( sort( keys(%incdomains))) {
  477: 	my $thisdomain=$_;
  478:         foreach ('dc','li','dg','au') {
  479:             if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
  480:                my $plrole=&Apache::lonnet::plaintext($_);
  481:                $r->print(<<ENDDROW);
  482: <tr>
  483: <td><input type=checkbox name="act_$thisdomain\_$_"></td>
  484: <td>$plrole</td>
  485: <td>$thisdomain</td>
  486: <td><input type=hidden name="start_$thisdomain\_$_" value=''>
  487: <a href=
  488: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thisdomain\_$_.value,'start_$thisdomain\_$_','cu.pres','dateset')">Set Start Date</a></td>
  489: <td><input type=hidden name="end_$thisdomain\_$_" value=''>
  490: <a href=
  491: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thisdomain\_$_.value,'end_$thisdomain\_$_','cu.pres','dateset')">Set End Date</a></td>
  492: </tr>
  493: ENDDROW
  494:             }
  495:         } 
  496:     }
  497:     $r->print('</table>');
  498: #
  499: # Course level
  500: #
  501:     $r->print(&course_level_table(%inccourses));
  502:     $r->print("<hr /><input type=submit value=\"Modify User\">\n");
  503:     $r->print("</form></body></html>");
  504: }
  505: 
  506: # ================================================================= Phase Three
  507: sub update_user_data {
  508:     my $r=shift;
  509:     my $uhome=&Apache::lonnet::homeserver($ENV{'form.ccuname'},
  510:                                           $ENV{'form.ccdomain'});
  511:     # Error messages
  512:     my $error     = '<font color="#ff0000">Error:</font>';
  513:     my $end       = '</body></html>';
  514:     # Print header
  515:     $r->print(<<ENDTHREEHEAD);
  516: <html>
  517: <head>
  518: <title>The LearningOnline Network with CAPA</title>
  519: </head>
  520: ENDTHREEHEAD
  521:     my $title;
  522:     if (exists($ENV{'form.makeuser'})) {
  523: 	$title='Set Privileges for New User';
  524:     } else {
  525:         $title='Modify User Privileges';
  526:     }
  527:     $r->print(&Apache::loncommon::bodytag($title));
  528:     # Check Inputs
  529:     if (! $ENV{'form.ccuname'} ) {
  530: 	$r->print($error.'No login name specified.'.$end);
  531: 	return;
  532:     }
  533:     if (  $ENV{'form.ccuname'}  =~/\W/) {
  534: 	$r->print($error.'Invalid login name.  '.
  535: 		  'Only letters, numbers, and underscores are valid.'.
  536: 		  $end);
  537: 	return;
  538:     }
  539:     if (! $ENV{'form.ccdomain'}       ) {
  540: 	$r->print($error.'No domain specified.'.$end);
  541: 	return;
  542:     }
  543:     if (  $ENV{'form.ccdomain'} =~/\W/) {
  544: 	$r->print($error.'Invalid domain name.  '.
  545: 		  'Only letters, numbers, and underscores are valid.'.
  546: 		  $end);
  547: 	return;
  548:     }
  549:     if (! exists($ENV{'form.makeuser'})) {
  550:         # Modifying an existing user, so check the validity of the name
  551:         if ($uhome eq 'no_host') {
  552:             $r->print($error.'Unable to determine home server for '.
  553:                       $ENV{'form.ccuname'}.' in domain '.
  554:                       $ENV{'form.ccdomain'}.'.');
  555:             return;
  556:         }
  557:     }
  558:     # Determine authentication method and password for the user being modified
  559:     my $amode='';
  560:     my $genpwd='';
  561:     if ($ENV{'form.login'} eq 'krb') {
  562: 	$amode='krb';
  563: 	$amode.=$ENV{'form.krbver'};
  564: 	$genpwd=$ENV{'form.krbarg'};
  565:     } elsif ($ENV{'form.login'} eq 'int') {
  566: 	$amode='internal';
  567: 	$genpwd=$ENV{'form.intarg'};
  568:     } elsif ($ENV{'form.login'} eq 'fsys') {
  569: 	$amode='unix';
  570: 	$genpwd=$ENV{'form.fsysarg'};
  571:     } elsif ($ENV{'form.login'} eq 'loc') {
  572: 	$amode='localauth';
  573: 	$genpwd=$ENV{'form.locarg'};
  574: 	$genpwd=" " if (!$genpwd);
  575:     } elsif (($ENV{'form.login'} eq 'nochange') ||
  576:              ($ENV{'form.login'} eq ''        )) { 
  577:         # There is no need to tell the user we did not change what they
  578:         # did not ask us to change.
  579:         # If they are creating a new user but have not specified login
  580:         # information this will be caught below.
  581:     } else {
  582: 	    $r->print($error.'Invalid login mode or password'.$end);    
  583: 	    return;
  584:     }
  585:     if ($ENV{'form.makeuser'}) {
  586:         # Create a new user
  587: 	$r->print(<<ENDNEWUSERHEAD);
  588: <h3>Creating user "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"</h2>
  589: ENDNEWUSERHEAD
  590:         # Check for the authentication mode and password
  591:         if (! $amode || ! $genpwd) {
  592: 	    $r->print($error.'Invalid login mode or password'.$end);    
  593: 	    return;
  594: 	}
  595:         # Determine desired host
  596:         my $desiredhost = $ENV{'form.hserver'};
  597:         if (lc($desiredhost) eq 'default') {
  598:             $desiredhost = undef;
  599:         } else {
  600:             my %home_servers = &Apache::loncommon::get_library_servers
  601:                 ($ENV{'form.ccdomain'});  
  602:             if (! exists($home_servers{$desiredhost})) {
  603:                 $r->print($error.'Invalid home server specified');
  604:                 return;
  605:             }
  606:         }
  607: 	# Call modifyuser
  608: 	my $result = &Apache::lonnet::modifyuser
  609: 	    ($ENV{'form.ccdomain'},$ENV{'form.ccuname'},$ENV{'form.cstid'},
  610:              $amode,$genpwd,$ENV{'form.cfirst'},
  611:              $ENV{'form.cmiddle'},$ENV{'form.clast'},$ENV{'form.cgen'},
  612:              undef,$desiredhost
  613: 	     );
  614: 	$r->print('Generating user: '.$result);
  615:         my $home = &Apache::lonnet::homeserver($ENV{'form.ccuname'},
  616:                                                $ENV{'form.ccdomain'});
  617:         $r->print('<br>Home server: '.$home.' '.
  618:                   $Apache::lonnet::libserv{$home});
  619:     } elsif (($ENV{'form.login'} ne 'nochange') &&
  620:              ($ENV{'form.login'} ne ''        )) {
  621: 	# Modify user privileges
  622: 	$r->print(<<ENDMODIFYUSERHEAD);
  623: <h2>User "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"</h2>
  624: ENDMODIFYUSERHEAD
  625:         if (! $amode || ! $genpwd) {
  626: 	    $r->print($error.'Invalid login mode or password'.$end);    
  627: 	    return;
  628: 	}
  629: 	# Only allow authentification modification if the person has authority
  630: 	if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'})) {
  631: 	    $r->print('Modifying authentication: '.
  632:                       &Apache::lonnet::modifyuserauth(
  633: 		       $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
  634:                        $amode,$genpwd));
  635:             $r->print('<br>Home server: '.&Apache::lonnet::homeserver
  636: 		  ($ENV{'form.ccuname'},$ENV{'form.ccdomain'}));
  637: 	} else {
  638: 	    # Okay, this is a non-fatal error.
  639: 	    $r->print($error.'You do not have the authority to modify '.
  640: 		      'this users authentification information.');    
  641: 	}
  642:     }
  643:     ##
  644:     if (! $ENV{'form.makeuser'} ) {
  645:         # Check for need to change
  646:         my %userenv = &Apache::lonnet::get
  647:             ('environment',['firstname','middlename','lastname','generation'],
  648:              $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
  649:         my ($tmp) = keys(%userenv);
  650:         if ($tmp =~ /^(con_lost|error)/i) { 
  651:             %userenv = ();
  652:         }
  653:         # Check to see if we need to change user information
  654:         foreach ('firstname','middlename','lastname','generation') {
  655:             # Strip leading and trailing whitespace
  656:             $ENV{'form.c'.$_} =~ s/(\s+$|^\s+)//g; 
  657:         }
  658:         if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'}) && 
  659:             ($ENV{'form.cfirstname'}  ne $userenv{'firstname'}  ||
  660:              $ENV{'form.cmiddlename'} ne $userenv{'middlename'} ||
  661:              $ENV{'form.clastname'}   ne $userenv{'lastname'}   ||
  662:              $ENV{'form.cgeneration'} ne $userenv{'generation'} )) {
  663:             # Make the change
  664:             my %changeHash;
  665:             $changeHash{'firstname'}  = $ENV{'form.cfirstname'};
  666:             $changeHash{'middlename'} = $ENV{'form.cmiddlename'};
  667:             $changeHash{'lastname'}   = $ENV{'form.clastname'};
  668:             $changeHash{'generation'} = $ENV{'form.cgeneration'};
  669:             my $putresult = &Apache::lonnet::put
  670:                 ('environment',\%changeHash,
  671:                  $ENV{'form.ccdomain'},$ENV{'form.ccuname'});
  672:             if ($putresult eq 'ok') {
  673:             # Tell the user we changed the name
  674:                 $r->print(<<"END");
  675: <table border="2">
  676: <caption>User Information Changed</caption>
  677: <tr><th>&nbsp;</th>
  678:     <th>first</th>
  679:     <th>middle</th>
  680:     <th>last</th>
  681:     <th>generation</th></tr>
  682: <tr><td>Previous</td>
  683:     <td>$userenv{'firstname'}  </td>
  684:     <td>$userenv{'middlename'} </td>
  685:     <td>$userenv{'lastname'}   </td>
  686:     <td>$userenv{'generation'} </td></tr>
  687: <tr><td>Changed To</td>
  688:     <td>$ENV{'form.cfirstname'}  </td>
  689:     <td>$ENV{'form.cmiddlename'} </td>
  690:     <td>$ENV{'form.clastname'}   </td>
  691:     <td>$ENV{'form.cgeneration'} </td></tr>
  692: </table>
  693: END
  694:             } else { # error occurred
  695:                 $r->print("<h2>Unable to successfully change environment for ".
  696:                       $ENV{'form.ccuname'}." in domain ".
  697:                       $ENV{'form.ccdomain'}."</h2>");
  698:             }
  699:         }  else { # End of if ($ENV ... ) logic
  700:             # They did not want to change the users name but we can
  701:             # still tell them what the name is
  702:                 $r->print(<<"END");
  703: <h2>User "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"</h2>
  704: <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} </h4>
  705: <h4>Generation: $userenv{'generation'}</h4>
  706: END
  707:         }
  708:     }
  709:     ##
  710:     my $now=time;
  711:     $r->print('<h3>Modifying Roles</h3>');
  712:     foreach (keys (%ENV)) {
  713: 	next if (! $ENV{$_});
  714: 	# Revoke roles
  715: 	if ($_=~/^form\.rev/) {
  716: 	    if ($_=~/^form\.rev\:([^\_]+)\_([^\_]+)$/) {
  717: 	        $r->print('Revoking '.$2.' in '.$1.': '.
  718:                      &Apache::lonnet::assignrole($ENV{'form.ccdomain'},
  719:                      $ENV{'form.ccuname'},$1,$2,$now).'<br>');
  720: 		if ($2 eq 'st') {
  721: 		    $1=~/^\/(\w+)\/(\w+)/;
  722: 		    my $cid=$1.'_'.$2;
  723: 		    $r->print('Drop from classlist: '.
  724: 			 &Apache::lonnet::critical('put:'.
  725:                              $ENV{'course.'.$cid.'.domain'}.':'.
  726: 	                     $ENV{'course.'.$cid.'.num'}.':classlist:'.
  727:                          &Apache::lonnet::escape($ENV{'form.ccuname'}.':'.
  728:                              $ENV{'form.ccdomain'}).'='.
  729:                          &Apache::lonnet::escape($now.':'),
  730: 	                     $ENV{'course.'.$cid.'.home'}).'<br>');
  731: 		}
  732: 	    } 
  733: 	} elsif ($_=~/^form\.act/) {
  734: 	    if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) {
  735: 		# Activate roles for sections with 3 id numbers
  736: 		# set start, end times, and the url for the class
  737: 		my $start = ( $ENV{'form.start_'.$1.'_'.$2} ? 
  738: 			      $ENV{'form.start_'.$1.'_'.$2} : 
  739: 			      $now );
  740: 		my $end   = ( $ENV{'form.end_'.$1.'_'.$2} ? 
  741: 			      $ENV{'form.end_'.$1.'_'.$2} :
  742: 			      0 );
  743: 		my $url='/'.$1.'/'.$2;
  744: 		if ($ENV{'form.sec_'.$1.'_'.$2.'_'.$3}) {
  745: 		    $url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3};
  746: 		}
  747: 		# Assign the role and report it
  748: 		$r->print('Assigning: '.$3.' in '.$url.': '.
  749:                           &Apache::lonnet::assignrole(
  750:                               $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
  751:                               $url,$3,$end,$start).
  752: 			  '<br>');
  753: 		# Handle students differently
  754: 		if ($3 eq 'st') {
  755: 		    $url=~/^\/(\w+)\/(\w+)/;
  756: 		    my $cid=$1.'_'.$2;
  757: 		    $r->print('Add to classlist: '.
  758: 			      &Apache::lonnet::critical(
  759: 				  'put:'.$ENV{'course.'.$cid.'.domain'}.':'.
  760: 	                           $ENV{'course.'.$cid.'.num'}.':classlist:'.
  761:                                    &Apache::lonnet::escape(
  762:                                        $ENV{'form.ccuname'}.':'.
  763:                                        $ENV{'form.ccdomain'} ).'='.
  764:                                    &Apache::lonnet::escape($end.':'.$start),
  765: 				       $ENV{'course.'.$cid.'.home'})
  766: 			      .'<br>');
  767: 		}
  768: 	    } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
  769: 		# Activate roles for sections with two id numbers
  770: 		# set start, end times, and the url for the class
  771: 		my $start = ( $ENV{'form.start_'.$1.'_'.$2} ? 
  772: 			      $ENV{'form.start_'.$1.'_'.$2} : 
  773: 			      $now );
  774: 		my $end   = ( $ENV{'form.end_'.$1.'_'.$2} ? 
  775: 			      $ENV{'form.end_'.$1.'_'.$2} :
  776: 			      0 );
  777: 		my $url='/'.$1.'/';
  778: 		# Assign the role and report it.
  779: 		$r->print('Assigning: '.$2.' in '.$url.': '.
  780:                           &Apache::lonnet::assignrole(
  781:                               $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
  782:                               $url,$2,$end,$start)
  783: 			  .'<br>');
  784: 	    }
  785: 	} 
  786:     } # End of foreach (keys(%ENV))
  787:     $r->print('</body></html>');
  788: }
  789: 
  790: # ================================================================ Main Handler
  791: sub handler {
  792:     my $r = shift;
  793: 
  794:     if ($r->header_only) {
  795:        $r->content_type('text/html');
  796:        $r->send_http_header;
  797:        return OK;
  798:     }
  799: 
  800:     if ((&Apache::lonnet::allowed('cta',$ENV{'request.course.id'})) ||
  801:         (&Apache::lonnet::allowed('cin',$ENV{'request.course.id'})) || 
  802:         (&Apache::lonnet::allowed('ccr',$ENV{'request.course.id'})) || 
  803:         (&Apache::lonnet::allowed('cep',$ENV{'request.course.id'})) ||
  804:         (&Apache::lonnet::allowed('cca',$ENV{'request.role.domain'})) ||
  805:         (&Apache::lonnet::allowed('mau',$ENV{'request.role.domain'}))) {
  806:        $r->content_type('text/html');
  807:        $r->send_http_header;
  808:        unless ($ENV{'form.phase'}) {
  809: 	   &print_username_entry_form($r);
  810:        }
  811:        if ($ENV{'form.phase'} eq 'get_user_info') {
  812:            &print_user_modification_page($r);
  813:        } elsif ($ENV{'form.phase'} eq 'update_user_data') {
  814:            &update_user_data($r);
  815:        }
  816:    } else {
  817:       $ENV{'user.error.msg'}=
  818:         "/adm/createuser:mau:0:0:Cannot modify user data";
  819:       return HTTP_NOT_ACCEPTABLE; 
  820:    }
  821:    return OK;
  822: } 
  823: 
  824: #-------------------------------------------------- functions for &phase_two
  825: sub course_level_table {
  826:     my %inccourses = @_;
  827:     my $table = '';
  828:     foreach (sort( keys(%inccourses))) {
  829: 	my $thiscourse=$_;
  830: 	my $protectedcourse=$_;
  831: 	$thiscourse=~s:_:/:g;
  832: 	my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
  833: 	my $area=$coursedata{'description'};
  834: 	my $bgcol=$thiscourse;
  835: 	$bgcol=~s/[^8-9b-e]//g;
  836: 	$bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
  837: 	foreach  ('st','ta','ep','ad','in','cc') {
  838: 	    if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
  839: 		my $plrole=&Apache::lonnet::plaintext($_);
  840: 		$table .= <<ENDEXTENT;
  841: <tr bgcolor="#$bgcol">
  842: <td><input type="checkbox" name="act_$protectedcourse\_$_"></td>
  843: <td>$plrole</td>
  844: <td>$area</td>
  845: ENDEXTENT
  846: 	        if ($_ ne 'cc') {
  847: 		    $table .= <<ENDSECTION;
  848: <td><input type="text" size="5" name="sec_$protectedcourse\_$_"></td>
  849: ENDSECTION
  850:                 } else { 
  851: 		    $table .= <<ENDSECTION;
  852: <td>&nbsp</td> 
  853: ENDSECTION
  854:                 }
  855: 		$table .= <<ENDTIMEENTRY;
  856: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
  857: <a href=
  858: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">Set Start Date</a></td>
  859: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
  860: <a href=
  861: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">Set End Date</a></td>
  862: ENDTIMEENTRY
  863:                 $table.= "</tr>\n";
  864:             }
  865:         }
  866:     }
  867:     return '' if ($table eq ''); # return nothing if there is nothing 
  868:                                  # in the table
  869:     my $result = <<ENDTABLE;
  870: <h4>Course Level</h4>
  871: <table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>
  872: <th>Group/Section</th><th>Start</th><th>End</th></tr>
  873: $table
  874: </table>
  875: ENDTABLE
  876:     return $result;
  877: }
  878: #---------------------------------------------- end functions for &phase_two
  879: 
  880: #--------------------------------- functions for &phase_two and &phase_three
  881: 
  882: #--------------------------end of functions for &phase_two and &phase_three
  883: 
  884: 1;
  885: __END__
  886: 
  887: 

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