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