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