Annotation of loncom/interface/loncreateuser.pm, revision 1.17
1.1 www 1: # The LearningOnline Network
2: # Create a user
3: #
4: # (Create a course
5: # (My Desk
6: #
7: # (Internal Server Error Handler
8: #
9: # (Login Screen
10: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
11: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
12: #
13: # 3/1/1 Gerd Kortemeyer)
14: #
15: # 3/1 Gerd Kortemeyer)
16: #
17: # 2/14 Gerd Kortemeyer)
18: #
1.12 www 19: # 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 20: # April Guy Albertelli
! 21: # 05/10 Gerd Kortemeyer
1.1 www 22: #
23: package Apache::loncreateuser;
24:
25: use strict;
26: use Apache::Constants qw(:common :http);
27: use Apache::lonnet;
28:
1.2 www 29: # =================================================================== Phase one
1.1 www 30:
1.2 www 31: sub phase_one {
32: my $r=shift;
33: my $defdom=$ENV{'user.domain'};
1.1 www 34: $r->print(<<ENDDOCUMENT);
35: <html>
36: <head>
37: <title>The LearningOnline Network with CAPA</title>
38: </head>
39: <body bgcolor="#FFFFFF">
40: <h1>Create User, Change User Privileges</h1>
1.2 www 41: <form action=/adm/createuser method=post>
42: <input type=hidden name=phase value=two>
43: Username: <input type=text size=15 name=ccuname><br>
44: Domain: <input type=text size=15 name=ccdomain value=$defdom><p>
45: <input type=submit value="Continue">
46: </form>
1.1 www 47: </body>
48: </html>
49: ENDDOCUMENT
1.2 www 50: }
51:
52: # =================================================================== Phase two
53:
54: sub phase_two {
55: my $r=shift;
56: my $ccuname=$ENV{'form.ccuname'};
57: my $ccdomain=$ENV{'form.ccdomain'};
1.4 www 58:
59: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
60: my $krbdefdom=$1;
61: $krbdefdom=~tr/a-z/A-Z/;
62:
63: my $defdom=$ENV{'user.domain'};
64:
1.2 www 65: $ccuname=~s/\W//g;
66: $ccdomain=~s/\W//g;
67: $r->print(<<ENDENHEAD);
68: <html>
69: <head>
70: <title>The LearningOnline Network with CAPA</title>
1.3 www 71: <script>
72:
73: function pclose() {
74: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
75: "height=350,width=350,scrollbars=no,menubar=no");
76: parmwin.close();
77: }
78:
79: function pjump(type,dis,value,marker,ret,call) {
80: parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
81: +"&value="+escape(value)+"&marker="+escape(marker)
82: +"&return="+escape(ret)
83: +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
84: "height=350,width=350,scrollbars=no,menubar=no");
85:
86: }
87:
88: function dateset() {
89: eval("document.cu."+document.cu.pres_marker.value+
90: ".value=document.cu.pres_value.value");
91: pclose();
92: }
93:
94: </script>
1.2 www 95: </head>
96: <body bgcolor="#FFFFFF">
97: <img align=right src=/adm/lonIcons/lonlogos.gif>
98: <h1>Create User, Change User Privileges</h1>
1.3 www 99: <form action=/adm/createuser method=post name=cu>
1.2 www 100: <input type=hidden name=phase value=three>
101: <input type=hidden name=ccuname value=$ccuname>
102: <input type=hidden name=ccdomain value=$ccdomain>
1.3 www 103: <input type="hidden" value='' name="pres_value">
104: <input type="hidden" value='' name="pres_type">
105: <input type="hidden" value='' name="pres_marker">
1.6 www 106: <input type=hidden name=cuname value="$ccuname">
107: <input type=hidden name=cdomain value="$ccdomain">
1.3 www 108:
1.2 www 109: ENDENHEAD
110: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
111: my %incdomains;
112: my %inccourses;
1.13 www 113: map {
114: $incdomains{$_}=1;
1.16 albertel 115: } values %Apache::lonnet::hostdom;
1.2 www 116: map {
117: if ($_=~/^user\.priv\.cm\.\/(\w+)\/(\w+)/) {
118: $inccourses{$1.'_'.$2}=1;
119: }
120: } %ENV;
121: if ($uhome eq 'no_host') {
1.4 www 122: $r->print(<<ENDNUSER);
1.6 www 123: <h2>New user $ccuname at $ccdomain</h2>
1.4 www 124: <script>
125: function setkrb(vf) {
126: if (vf.krbdom.value!='') {
127: vf.login[0].checked=true;
128: vf.krbdom.value=vf.krbdom.value.toUpperCase();
129: vf.intpwd.value='';
130: }
131: }
132:
133: function setint(vf) {
134: if (vf.intpwd.value!='') {
135: vf.login[1].checked=true;
136: vf.krbdom.value='';
137: }
138: }
139:
140: function clickkrb(vf) {
141: vf.krbdom.value='$krbdefdom';
142: vf.intpwd.value='';
143: }
144:
145: function clickint(vf) {
146: vf.krbdom.value='';
147: }
148: </script>
149: <input type=hidden name=makeuser value=1>
150: <h3>Personal Data</h3>
151: First Name: <input type=text name=cfirst size=15><br>
152: Middle Name: <input type=text name=cmiddle size=15><br>
153: Last Name: <input type=text name=clast size=15><br>
154: Generation: <input type=text name=cgen size=5><p>
155:
156: ID/Student Number: <input type=text name=cstid size=10><p>
157:
158: <h3>Login Data</h3>
159: <input type=radio name=login value=krb onClick="clickkrb(this.form);">
160: Kerberos authenticated with domain
161: <input type=text size=10 name=krbdom onChange="setkrb(this.form);"><p>
162: <input type=radio name=login value=int onClick="clickint(this.form);">
163: Internally authenticated (with initial password
164: <input type=text size=10 name=intpwd onChange="setint(this.form);">)
165: ENDNUSER
1.2 www 166: } else {
1.6 www 167: $r->print('<h2>Existing user '.$ccuname.' at '.$ccdomain.'</h2>');
1.5 www 168:
1.2 www 169: my $rolesdump=&Apache::lonnet::reply(
170: "dump:$ccdomain:$ccuname:roles",$uhome);
171: unless ($rolesdump eq 'con_lost') {
172: my $now=time;
173: $r->print('<h4>Revoke Existing Roles</h4>'.
174: '<table border=2><tr><th>Revoke</th><th>Role</th><th>Extent</th>'.
175: '<th>Start</th><th>End</th>');
176: map {
177: if ($_!~/^rolesdef\&/) {
178:
179: my ($area,$role)=split(/=/,$_);
180: my $thisrole=$area;
181: $area=~s/\_\w\w$//;
182: my ($trole,$tend,$tstart)=split(/_/,$role);
1.3 www 183: my $bgcol='ffffff';
1.2 www 184: my $allows=0;
1.5 www 185: if ($area=~/^\/(\w+)\/(\d\w+)/) {
1.2 www 186: my %coursedata=&Apache::lonnet::coursedescription($1.'_'.$2);
1.5 www 187: my $carea='Course: '.$coursedata{'description'};
1.2 www 188: $inccourses{$1.'_'.$2}=1;
1.7 www 189: if (&Apache::lonnet::allowed('c'.$trole,$1.'/'.$2)) {
1.2 www 190: $allows=1;
191: }
1.3 www 192: $bgcol=$1.'_'.$2;
193: $bgcol=~s/[^8-9b-e]//g;
194: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
1.5 www 195: if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
196: $carea.='<br>Section/Group: '.$3;
197: }
198: $area=$carea;
1.2 www 199: } else {
1.7 www 200: if ($area=~/^\/(\w+)\//) {
1.2 www 201: if (&Apache::lonnet::allowed('c'.$trole,$1)) {
1.7 www 202: $allows=1;
203: }
204: } else {
205: if (&Apache::lonnet::allowed('c'.$trole,'/')) {
1.2 www 206: $allows=1;
207: }
208: }
209: }
210:
211: my $active=1;
212: if (($tend) && ($now>$tend)) { $active=0; }
213:
1.3 www 214: $r->print('<tr bgcolor=#'.$bgcol.'><td>');
1.2 www 215: if ($active) {
216: if ($allows) {
217: $r->print(
218: '<input type=checkbox name="rev:'.$thisrole.'">');
219: } else {
220: $r->print(' ');
221: }
222: } else {
223: $r->print(' ');
224: }
225: $r->print('</td><td>'.&Apache::lonnet::plaintext($trole).
226: '</td><td>'.$area.'</td><td>'.
227: ($tstart?localtime($tstart):' ').'</td><td>'.
228: ($tend?localtime($tend):' ')."</td></tr>\n");
229: }
230: } split(/&/,$rolesdump);
231: $r->print('</table>');
232: }
233: }
1.13 www 234: $r->print('<hr><h3>Add Roles</h3>');
1.17 ! www 235: #
! 236: # Co-Author
! 237: #
! 238:
! 239: if (&Apache::lonnet::allowed('cca',$ENV{'user.domain'})) {
! 240: my $cuname=$ENV{'user.name'};
! 241: my $cudom=$ENV{'user.domain'};
! 242: $r->print(<<ENDCOAUTH);
! 243: <h4>Construction Space</h4>
! 244: <table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>
! 245: <th>Start</th><th>End</th></tr>
! 246: <tr>
! 247: <td><input type=checkbox name="act_$cudom\_$cuname\_ca"></td>
! 248: <td>Co-Author</td>
! 249: <td>$cudom\_$cuname</td>
! 250: <td><input type=hidden name="start_$cudom\_$cuname\_ca" value=''>
! 251: <a href=
! 252: "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>
! 253: <td><input type=hidden name="end_$cudom\_$cuname\_ca" value=''>
! 254: <a href=
! 255: "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>
! 256: </tr>
! 257: </table>
! 258: ENDCOAUTH
! 259: }
1.8 www 260: #
261: # Domain level
262: #
263: $r->print('<h4>Domain Level</h4>'.
264: '<table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>'.
265: '<th>Start</th><th>End</th></tr>');
1.2 www 266: map {
267: my $thisdomain=$_;
268: map {
269: if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
1.8 www 270: my $plrole=&Apache::lonnet::plaintext($_);
271: $r->print(<<ENDDROW);
272: <tr>
273: <td><input type=checkbox name="act_$thisdomain\_$_"></td>
274: <td>$plrole</td>
275: <td>$thisdomain</td>
276: <td><input type=hidden name="start_$thisdomain\_$_" value=''>
277: <a href=
278: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thisdomain\_$_.value,'start_$thisdomain\_$_','cu.pres','dateset')">Set Start Date</a></td>
279: <td><input type=hidden name="end_$thisdomain\_$_" value=''>
280: <a href=
281: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thisdomain\_$_.value,'end_$thisdomain\_$_','cu.pres','dateset')">Set End Date</a></td>
282: </tr>
283: ENDDROW
1.2 www 284: }
1.12 www 285: } ('dc','li','dg','au');
1.2 www 286: } sort keys %incdomains;
1.8 www 287: $r->print('</table>');
288: #
289: # Course level
290: #
1.6 www 291: $r->print('<h4>Course Level</h4>'.
1.3 www 292: '<table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>'.
293: '<th>Group/Section</th><th>Start</th><th>End</th></tr>');
1.2 www 294: map {
295: my $thiscourse=$_;
1.15 albertel 296: my $protectedcourse=$_;
297: $thiscourse=~s:_:/:g;
1.3 www 298: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
299: my $area=$coursedata{'description'};
300: my $bgcol=$thiscourse;
301: $bgcol=~s/[^8-9b-e]//g;
302: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
1.2 www 303: map {
304: if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
1.3 www 305: my $plrole=&Apache::lonnet::plaintext($_);
1.16 albertel 306: $r->print("
1.3 www 307: <tr bgcolor=#$bgcol>
1.16 albertel 308: <td><input type=checkbox name=\"act_$protectedcourse\_$_\"></td>
1.3 www 309: <td>$plrole</td>
310: <td>$area</td>
1.16 albertel 311: <td>");
312: if ($_ ne 'cc') {
313: $r->print("<input type=text size=5 name=\"sec_$protectedcourse\_$_\">");
314: } else { $r->print(" "); }
315: $r->print(<<ENDROW);
1.15 albertel 316: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
1.3 www 317: <a href=
1.15 albertel 318: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">Set Start Date</a></td>
319: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
1.3 www 320: <a href=
1.15 albertel 321: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$_.value,'end_$protectedcourse\_$_','cu.pres','dateset')">Set End Date</a></td>
1.3 www 322: </tr>
323: ENDROW
1.2 www 324: }
1.12 www 325: } ('st','ta','ep','ad','in','cc');
1.2 www 326: } sort keys %inccourses;
1.3 www 327: $r->print('</table>');
1.6 www 328: $r->print('<input type=submit value="Modify User">');
1.2 www 329: $r->print('</form></body></html>');
330: }
1.1 www 331:
1.4 www 332: # ================================================================= Phase Three
333:
334: sub phase_three {
335: my $r=shift;
336: $r->print(<<ENDTHREEHEAD);
337: <html>
338: <head>
339: <title>The LearningOnline Network with CAPA</title>
340: </head>
341: <body bgcolor="#FFFFFF">
342: <img align=right src=/adm/lonIcons/lonlogos.gif>
343: <h1>Create User, Change User Privileges</h1>
344: ENDTHREEHEAD
1.6 www 345: $r->print('<h2>'.$ENV{'form.cuname'}.' at '.$ENV{'form.cdomain'}.'</h2>');
1.4 www 346: if ($ENV{'form.makeuser'}) {
347: $r->print('<h3>Creating User</h3>');
348: if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
349: ($ENV{'form.cdomain'})&&($ENV{'form.cdomain'}!~/\W/)) {
350: my $amode='';
351: my $genpwd='';
352: if ($ENV{'form.login'} eq 'krb') {
353: $amode='krb4';
354: $genpwd=$ENV{'form.krbdom'};
355: } elsif ($ENV{'form.login'} eq 'int') {
356: $amode='internal';
357: $genpwd=$ENV{'form.intpwd'};
358: }
359: if (($amode) && ($genpwd)) {
1.6 www 360: $r->print('Generating user: '.&Apache::lonnet::modifyuser(
1.4 www 361: $ENV{'form.cdomain'},$ENV{'form.cuname'},
362: $ENV{'form.cstid'},$amode,$genpwd,
363: $ENV{'form.cfirst'},$ENV{'form.cmiddle'},
1.6 www 364: $ENV{'form.clast'},$ENV{'form.cgen'}));
365: $r->print('<br>Home server: '.&Apache::lonnet::homeserver
366: ($ENV{'form.cuname'},$ENV{'form.cdomain'}));
367:
1.4 www 368: } else {
369: $r->print('Invalid login mode or password');
370: }
371: } else {
372: $r->print('Invalid username or domain');
373: }
374: }
375: my $now=time;
1.6 www 376: $r->print('<h3>Modifying Roles</h3>');
1.4 www 377: map {
378: if (($_=~/^form\.rev\:([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {
379: $r->print('Revoking '.$2.' in '.$1.': '.
380: &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},
381: $1,$2,$now).'<br>');
1.11 www 382: if ($2 eq 'st') {
383: $1=~/^\/(\w+)\/(\w+)/;
384: my $cid=$1.'_'.$2;
385: $r->print('Drop from classlist: '.
386: &Apache::lonnet::critical('put:'.$ENV{'course.'.$cid.'.domain'}.':'.
387: $ENV{'course.'.$cid.'.num'}.':classlist:'.
388: &Apache::lonnet::escape($ENV{'form.cuname'}.':'.
389: $ENV{'form.cdomain'}).'='.
390: &Apache::lonnet::escape($now.':'),
391: $ENV{'course.'.$cid.'.home'}).'<br>');
392: }
1.4 www 393: }
394: } keys %ENV;
395: map {
396: if (($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {
1.5 www 397: my $url='/'.$1.'/'.$2;
398: if ($ENV{'form.sec_'.$1.'_'.$2.'_'.$3}) {
399: $url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3};
400: }
401: my $start=$now;
402: if ($ENV{'form.start_'.$1.'_'.$2.'_'.$3}) {
403: $start=$ENV{'form.start_'.$1.'_'.$2.'_'.$3};
404: }
405: my $end=0;
406: if ($ENV{'form.end_'.$1.'_'.$2.'_'.$3}) {
407: $end=$ENV{'form.end_'.$1.'_'.$2.'_'.$3};
408: }
409: $r->print('Assigning: '.$3.' in '.$url.': '.
410: &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},
411: $url,$3,$end,$start).'<br>');
1.10 www 412: if ($3 eq 'st') {
1.11 www 413: $url=~/^\/(\w+)\/(\w+)/;
414: my $cid=$1.'_'.$2;
1.10 www 415: $r->print('Add to classlist: '.
416: &Apache::lonnet::critical('put:'.$ENV{'course.'.$cid.'.domain'}.':'.
417: $ENV{'course.'.$cid.'.num'}.':classlist:'.
418: &Apache::lonnet::escape($ENV{'form.cuname'}.':'.
419: $ENV{'form.cdomain'}).'='.
420: &Apache::lonnet::escape($end.':'.$start),
421: $ENV{'course.'.$cid.'.home'}).'<br>');
422: }
1.8 www 423: } elsif (($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {
424: my $url='/'.$1.'/';
425: my $start=$now;
426: if ($ENV{'form.start_'.$1.'_'.$2}) {
427: $start=$ENV{'form.start_'.$1.'_'.$2};
428: }
429: my $end=0;
430: if ($ENV{'form.end_'.$1.'_'.$2}) {
431: $end=$ENV{'form.end_'.$1.'_'.$2};
432: }
433: $r->print('Assigning: '.$2.' in '.$url.': '.
434: &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},
435: $url,$2,$end,$start).'<br>');
436: }
1.4 www 437: } keys %ENV;
1.5 www 438: $r->print('</body></html>');
1.4 www 439: }
440:
1.2 www 441: # ================================================================ Main Handler
442: sub handler {
443: my $r = shift;
444:
445: if ($r->header_only) {
446: $r->content_type('text/html');
447: $r->send_http_header;
448: return OK;
449: }
450:
451: if ((&Apache::lonnet::allowed('cta',$ENV{'request.course.id'})) ||
452: (&Apache::lonnet::allowed('cin',$ENV{'request.course.id'})) ||
453: (&Apache::lonnet::allowed('ccr',$ENV{'request.course.id'})) ||
454: (&Apache::lonnet::allowed('cep',$ENV{'request.course.id'})) ||
455: (&Apache::lonnet::allowed('mau',$ENV{'user.domain'}))) {
456: $r->content_type('text/html');
457: $r->send_http_header;
458: unless ($ENV{'form.phase'}) {
459: &phase_one($r);
460: }
461: if ($ENV{'form.phase'} eq 'two') {
462: &phase_two($r);
1.4 www 463: } elsif ($ENV{'form.phase'} eq 'three') {
464: &phase_three($r);
1.2 www 465: }
1.1 www 466: } else {
467: $ENV{'user.error.msg'}=
1.9 albertel 468: "/adm/createuser:mau:0:0:Cannot modify user data";
1.1 www 469: return HTTP_NOT_ACCEPTABLE;
470: }
471: return OK;
472: }
473:
474: 1;
475: __END__
1.2 www 476:
477:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>