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