Annotation of loncom/interface/loncreateuser.pm, revision 1.19
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
1.19 ! www 21: # 05/10,10/16 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='';
1.18 albertel 130: vf.locarg.value='';
1.4 www 131: }
132: }
133:
134: function setint(vf) {
135: if (vf.intpwd.value!='') {
136: vf.login[1].checked=true;
137: vf.krbdom.value='';
1.18 albertel 138: vf.locarg.value='';
139: }
140: }
141:
142: function setloc(vf) {
143: if (vf.locarg.value!='') {
144: vf.login[2].checked=true;
145: vf.krbdom.value='';
146: vf.intpwd.value='';
1.4 www 147: }
148: }
149:
150: function clickkrb(vf) {
151: vf.krbdom.value='$krbdefdom';
152: vf.intpwd.value='';
1.18 albertel 153: vf.locarg.value='';
1.4 www 154: }
155:
156: function clickint(vf) {
157: vf.krbdom.value='';
1.18 albertel 158: vf.locarg.value='';
159: }
160:
161: function clickloc(vf) {
162: vf.krbdom.value='';
163: vf.intpwd.value='';
1.4 www 164: }
165: </script>
166: <input type=hidden name=makeuser value=1>
167: <h3>Personal Data</h3>
168: First Name: <input type=text name=cfirst size=15><br>
169: Middle Name: <input type=text name=cmiddle size=15><br>
170: Last Name: <input type=text name=clast size=15><br>
171: Generation: <input type=text name=cgen size=5><p>
172:
173: ID/Student Number: <input type=text name=cstid size=10><p>
174:
175: <h3>Login Data</h3>
176: <input type=radio name=login value=krb onClick="clickkrb(this.form);">
177: Kerberos authenticated with domain
178: <input type=text size=10 name=krbdom onChange="setkrb(this.form);"><p>
179: <input type=radio name=login value=int onClick="clickint(this.form);">
180: Internally authenticated (with initial password
181: <input type=text size=10 name=intpwd onChange="setint(this.form);">)
1.18 albertel 182: <p>
183: <input type=radio name=login value=loc onClick="clickloc(this.form);" />
184: Local Authentication with argument
185: <input type=text size=10 name=locarg onChange="setloc(this.form);" />
186: </p>
1.4 www 187: ENDNUSER
1.2 www 188: } else {
1.6 www 189: $r->print('<h2>Existing user '.$ccuname.' at '.$ccdomain.'</h2>');
1.5 www 190:
1.2 www 191: my $rolesdump=&Apache::lonnet::reply(
192: "dump:$ccdomain:$ccuname:roles",$uhome);
193: unless ($rolesdump eq 'con_lost') {
194: my $now=time;
195: $r->print('<h4>Revoke Existing Roles</h4>'.
196: '<table border=2><tr><th>Revoke</th><th>Role</th><th>Extent</th>'.
197: '<th>Start</th><th>End</th>');
198: map {
199: if ($_!~/^rolesdef\&/) {
200:
201: my ($area,$role)=split(/=/,$_);
202: my $thisrole=$area;
203: $area=~s/\_\w\w$//;
204: my ($trole,$tend,$tstart)=split(/_/,$role);
1.3 www 205: my $bgcol='ffffff';
1.2 www 206: my $allows=0;
1.5 www 207: if ($area=~/^\/(\w+)\/(\d\w+)/) {
1.2 www 208: my %coursedata=&Apache::lonnet::coursedescription($1.'_'.$2);
1.5 www 209: my $carea='Course: '.$coursedata{'description'};
1.2 www 210: $inccourses{$1.'_'.$2}=1;
1.7 www 211: if (&Apache::lonnet::allowed('c'.$trole,$1.'/'.$2)) {
1.2 www 212: $allows=1;
213: }
1.3 www 214: $bgcol=$1.'_'.$2;
215: $bgcol=~s/[^8-9b-e]//g;
216: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
1.5 www 217: if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
218: $carea.='<br>Section/Group: '.$3;
219: }
220: $area=$carea;
1.2 www 221: } else {
1.7 www 222: if ($area=~/^\/(\w+)\//) {
1.2 www 223: if (&Apache::lonnet::allowed('c'.$trole,$1)) {
1.7 www 224: $allows=1;
225: }
226: } else {
227: if (&Apache::lonnet::allowed('c'.$trole,'/')) {
1.2 www 228: $allows=1;
229: }
230: }
231: }
232:
233: my $active=1;
234: if (($tend) && ($now>$tend)) { $active=0; }
235:
1.3 www 236: $r->print('<tr bgcolor=#'.$bgcol.'><td>');
1.2 www 237: if ($active) {
238: if ($allows) {
239: $r->print(
240: '<input type=checkbox name="rev:'.$thisrole.'">');
241: } else {
242: $r->print(' ');
243: }
244: } else {
245: $r->print(' ');
246: }
247: $r->print('</td><td>'.&Apache::lonnet::plaintext($trole).
248: '</td><td>'.$area.'</td><td>'.
249: ($tstart?localtime($tstart):' ').'</td><td>'.
250: ($tend?localtime($tend):' ')."</td></tr>\n");
251: }
252: } split(/&/,$rolesdump);
253: $r->print('</table>');
254: }
255: }
1.13 www 256: $r->print('<hr><h3>Add Roles</h3>');
1.17 www 257: #
258: # Co-Author
259: #
260:
261: if (&Apache::lonnet::allowed('cca',$ENV{'user.domain'})) {
262: my $cuname=$ENV{'user.name'};
263: my $cudom=$ENV{'user.domain'};
264: $r->print(<<ENDCOAUTH);
265: <h4>Construction Space</h4>
266: <table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>
267: <th>Start</th><th>End</th></tr>
268: <tr>
269: <td><input type=checkbox name="act_$cudom\_$cuname\_ca"></td>
270: <td>Co-Author</td>
271: <td>$cudom\_$cuname</td>
272: <td><input type=hidden name="start_$cudom\_$cuname\_ca" value=''>
273: <a href=
274: "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>
275: <td><input type=hidden name="end_$cudom\_$cuname\_ca" value=''>
276: <a href=
277: "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>
278: </tr>
279: </table>
280: ENDCOAUTH
281: }
1.8 www 282: #
283: # Domain level
284: #
285: $r->print('<h4>Domain Level</h4>'.
286: '<table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>'.
287: '<th>Start</th><th>End</th></tr>');
1.2 www 288: map {
289: my $thisdomain=$_;
290: map {
291: if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
1.8 www 292: my $plrole=&Apache::lonnet::plaintext($_);
293: $r->print(<<ENDDROW);
294: <tr>
295: <td><input type=checkbox name="act_$thisdomain\_$_"></td>
296: <td>$plrole</td>
297: <td>$thisdomain</td>
298: <td><input type=hidden name="start_$thisdomain\_$_" value=''>
299: <a href=
300: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thisdomain\_$_.value,'start_$thisdomain\_$_','cu.pres','dateset')">Set Start Date</a></td>
301: <td><input type=hidden name="end_$thisdomain\_$_" value=''>
302: <a href=
303: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thisdomain\_$_.value,'end_$thisdomain\_$_','cu.pres','dateset')">Set End Date</a></td>
304: </tr>
305: ENDDROW
1.2 www 306: }
1.12 www 307: } ('dc','li','dg','au');
1.2 www 308: } sort keys %incdomains;
1.8 www 309: $r->print('</table>');
310: #
311: # Course level
312: #
1.6 www 313: $r->print('<h4>Course Level</h4>'.
1.3 www 314: '<table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>'.
315: '<th>Group/Section</th><th>Start</th><th>End</th></tr>');
1.2 www 316: map {
317: my $thiscourse=$_;
1.15 albertel 318: my $protectedcourse=$_;
319: $thiscourse=~s:_:/:g;
1.3 www 320: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
321: my $area=$coursedata{'description'};
322: my $bgcol=$thiscourse;
323: $bgcol=~s/[^8-9b-e]//g;
324: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
1.2 www 325: map {
326: if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
1.3 www 327: my $plrole=&Apache::lonnet::plaintext($_);
1.16 albertel 328: $r->print("
1.3 www 329: <tr bgcolor=#$bgcol>
1.16 albertel 330: <td><input type=checkbox name=\"act_$protectedcourse\_$_\"></td>
1.3 www 331: <td>$plrole</td>
332: <td>$area</td>
1.16 albertel 333: <td>");
334: if ($_ ne 'cc') {
335: $r->print("<input type=text size=5 name=\"sec_$protectedcourse\_$_\">");
336: } else { $r->print(" "); }
337: $r->print(<<ENDROW);
1.15 albertel 338: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
1.3 www 339: <a href=
1.15 albertel 340: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">Set Start Date</a></td>
341: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
1.3 www 342: <a href=
1.15 albertel 343: "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 344: </tr>
345: ENDROW
1.2 www 346: }
1.12 www 347: } ('st','ta','ep','ad','in','cc');
1.2 www 348: } sort keys %inccourses;
1.3 www 349: $r->print('</table>');
1.6 www 350: $r->print('<input type=submit value="Modify User">');
1.2 www 351: $r->print('</form></body></html>');
352: }
1.1 www 353:
1.4 www 354: # ================================================================= Phase Three
355:
356: sub phase_three {
357: my $r=shift;
358: $r->print(<<ENDTHREEHEAD);
359: <html>
360: <head>
361: <title>The LearningOnline Network with CAPA</title>
362: </head>
363: <body bgcolor="#FFFFFF">
364: <img align=right src=/adm/lonIcons/lonlogos.gif>
365: <h1>Create User, Change User Privileges</h1>
366: ENDTHREEHEAD
1.6 www 367: $r->print('<h2>'.$ENV{'form.cuname'}.' at '.$ENV{'form.cdomain'}.'</h2>');
1.4 www 368: if ($ENV{'form.makeuser'}) {
369: $r->print('<h3>Creating User</h3>');
370: if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
371: ($ENV{'form.cdomain'})&&($ENV{'form.cdomain'}!~/\W/)) {
372: my $amode='';
373: my $genpwd='';
374: if ($ENV{'form.login'} eq 'krb') {
375: $amode='krb4';
376: $genpwd=$ENV{'form.krbdom'};
377: } elsif ($ENV{'form.login'} eq 'int') {
378: $amode='internal';
379: $genpwd=$ENV{'form.intpwd'};
1.18 albertel 380: } elsif ($ENV{'form.login'} eq 'loc') {
381: $amode='localauth';
382: $genpwd=$ENV{'form.locarg'};
383: if (!$genpwd) { $genpwd=" "; }
384: }
1.4 www 385: if (($amode) && ($genpwd)) {
1.6 www 386: $r->print('Generating user: '.&Apache::lonnet::modifyuser(
1.4 www 387: $ENV{'form.cdomain'},$ENV{'form.cuname'},
388: $ENV{'form.cstid'},$amode,$genpwd,
389: $ENV{'form.cfirst'},$ENV{'form.cmiddle'},
1.6 www 390: $ENV{'form.clast'},$ENV{'form.cgen'}));
391: $r->print('<br>Home server: '.&Apache::lonnet::homeserver
392: ($ENV{'form.cuname'},$ENV{'form.cdomain'}));
393:
1.4 www 394: } else {
395: $r->print('Invalid login mode or password');
396: }
397: } else {
398: $r->print('Invalid username or domain');
399: }
400: }
401: my $now=time;
1.6 www 402: $r->print('<h3>Modifying Roles</h3>');
1.4 www 403: map {
404: if (($_=~/^form\.rev\:([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {
405: $r->print('Revoking '.$2.' in '.$1.': '.
406: &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},
407: $1,$2,$now).'<br>');
1.11 www 408: if ($2 eq 'st') {
409: $1=~/^\/(\w+)\/(\w+)/;
410: my $cid=$1.'_'.$2;
411: $r->print('Drop from classlist: '.
412: &Apache::lonnet::critical('put:'.$ENV{'course.'.$cid.'.domain'}.':'.
413: $ENV{'course.'.$cid.'.num'}.':classlist:'.
414: &Apache::lonnet::escape($ENV{'form.cuname'}.':'.
415: $ENV{'form.cdomain'}).'='.
416: &Apache::lonnet::escape($now.':'),
417: $ENV{'course.'.$cid.'.home'}).'<br>');
418: }
1.4 www 419: }
420: } keys %ENV;
421: map {
422: if (($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {
1.5 www 423: my $url='/'.$1.'/'.$2;
424: if ($ENV{'form.sec_'.$1.'_'.$2.'_'.$3}) {
425: $url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3};
426: }
427: my $start=$now;
428: if ($ENV{'form.start_'.$1.'_'.$2.'_'.$3}) {
429: $start=$ENV{'form.start_'.$1.'_'.$2.'_'.$3};
430: }
431: my $end=0;
432: if ($ENV{'form.end_'.$1.'_'.$2.'_'.$3}) {
433: $end=$ENV{'form.end_'.$1.'_'.$2.'_'.$3};
434: }
435: $r->print('Assigning: '.$3.' in '.$url.': '.
436: &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},
437: $url,$3,$end,$start).'<br>');
1.10 www 438: if ($3 eq 'st') {
1.11 www 439: $url=~/^\/(\w+)\/(\w+)/;
440: my $cid=$1.'_'.$2;
1.10 www 441: $r->print('Add to classlist: '.
442: &Apache::lonnet::critical('put:'.$ENV{'course.'.$cid.'.domain'}.':'.
443: $ENV{'course.'.$cid.'.num'}.':classlist:'.
444: &Apache::lonnet::escape($ENV{'form.cuname'}.':'.
445: $ENV{'form.cdomain'}).'='.
446: &Apache::lonnet::escape($end.':'.$start),
447: $ENV{'course.'.$cid.'.home'}).'<br>');
448: }
1.8 www 449: } elsif (($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {
450: my $url='/'.$1.'/';
451: my $start=$now;
452: if ($ENV{'form.start_'.$1.'_'.$2}) {
453: $start=$ENV{'form.start_'.$1.'_'.$2};
454: }
455: my $end=0;
456: if ($ENV{'form.end_'.$1.'_'.$2}) {
457: $end=$ENV{'form.end_'.$1.'_'.$2};
458: }
459: $r->print('Assigning: '.$2.' in '.$url.': '.
460: &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},
461: $url,$2,$end,$start).'<br>');
462: }
1.4 www 463: } keys %ENV;
1.5 www 464: $r->print('</body></html>');
1.4 www 465: }
466:
1.2 www 467: # ================================================================ Main Handler
468: sub handler {
469: my $r = shift;
470:
471: if ($r->header_only) {
472: $r->content_type('text/html');
473: $r->send_http_header;
474: return OK;
475: }
476:
477: if ((&Apache::lonnet::allowed('cta',$ENV{'request.course.id'})) ||
478: (&Apache::lonnet::allowed('cin',$ENV{'request.course.id'})) ||
479: (&Apache::lonnet::allowed('ccr',$ENV{'request.course.id'})) ||
480: (&Apache::lonnet::allowed('cep',$ENV{'request.course.id'})) ||
1.19 ! www 481: (&Apache::lonnet::allowed('cca',$ENV{'user.domain'})) ||
1.2 www 482: (&Apache::lonnet::allowed('mau',$ENV{'user.domain'}))) {
483: $r->content_type('text/html');
484: $r->send_http_header;
485: unless ($ENV{'form.phase'}) {
486: &phase_one($r);
487: }
488: if ($ENV{'form.phase'} eq 'two') {
489: &phase_two($r);
1.4 www 490: } elsif ($ENV{'form.phase'} eq 'three') {
491: &phase_three($r);
1.2 www 492: }
1.1 www 493: } else {
494: $ENV{'user.error.msg'}=
1.9 albertel 495: "/adm/createuser:mau:0:0:Cannot modify user data";
1.1 www 496: return HTTP_NOT_ACCEPTABLE;
497: }
498: return OK;
499: }
500:
501: 1;
502: __END__
1.2 www 503:
504:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>