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