Annotation of loncom/interface/loncreateuser.pm, revision 1.15
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.15 ! albertel 269: my $protectedcourse=$_;
! 270: $thiscourse=~s:_:/:g;
1.3 www 271: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
272: my $area=$coursedata{'description'};
273: my $bgcol=$thiscourse;
274: $bgcol=~s/[^8-9b-e]//g;
275: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
1.2 www 276: map {
277: if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
1.3 www 278: my $plrole=&Apache::lonnet::plaintext($_);
279: $r->print(<<ENDROW);
280: <tr bgcolor=#$bgcol>
1.15 ! albertel 281: <td><input type=checkbox name="act_$protectedcourse\_$_"></td>
1.3 www 282: <td>$plrole</td>
283: <td>$area</td>
1.15 ! albertel 284: <td><input type=text size=5 name="sec_$protectedcourse\_$_"></td>
! 285: <td><input type=hidden name="start_$protectedcourse\_$_" value=''>
1.3 www 286: <a href=
1.15 ! albertel 287: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$protectedcourse\_$_.value,'start_$protectedcourse\_$_','cu.pres','dateset')">Set Start Date</a></td>
! 288: <td><input type=hidden name="end_$protectedcourse\_$_" value=''>
1.3 www 289: <a href=
1.15 ! albertel 290: "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 291: </tr>
292: ENDROW
293:
1.2 www 294: }
1.12 www 295: } ('st','ta','ep','ad','in','cc');
1.2 www 296: } sort keys %inccourses;
1.3 www 297: $r->print('</table>');
1.6 www 298: $r->print('<input type=submit value="Modify User">');
1.2 www 299: $r->print('</form></body></html>');
300: }
1.1 www 301:
1.4 www 302: # ================================================================= Phase Three
303:
304: sub phase_three {
305: my $r=shift;
306: $r->print(<<ENDTHREEHEAD);
307: <html>
308: <head>
309: <title>The LearningOnline Network with CAPA</title>
310: </head>
311: <body bgcolor="#FFFFFF">
312: <img align=right src=/adm/lonIcons/lonlogos.gif>
313: <h1>Create User, Change User Privileges</h1>
314: ENDTHREEHEAD
1.6 www 315: $r->print('<h2>'.$ENV{'form.cuname'}.' at '.$ENV{'form.cdomain'}.'</h2>');
1.4 www 316: if ($ENV{'form.makeuser'}) {
317: $r->print('<h3>Creating User</h3>');
318: if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
319: ($ENV{'form.cdomain'})&&($ENV{'form.cdomain'}!~/\W/)) {
320: my $amode='';
321: my $genpwd='';
322: if ($ENV{'form.login'} eq 'krb') {
323: $amode='krb4';
324: $genpwd=$ENV{'form.krbdom'};
325: } elsif ($ENV{'form.login'} eq 'int') {
326: $amode='internal';
327: $genpwd=$ENV{'form.intpwd'};
328: }
329: if (($amode) && ($genpwd)) {
1.6 www 330: $r->print('Generating user: '.&Apache::lonnet::modifyuser(
1.4 www 331: $ENV{'form.cdomain'},$ENV{'form.cuname'},
332: $ENV{'form.cstid'},$amode,$genpwd,
333: $ENV{'form.cfirst'},$ENV{'form.cmiddle'},
1.6 www 334: $ENV{'form.clast'},$ENV{'form.cgen'}));
335: $r->print('<br>Home server: '.&Apache::lonnet::homeserver
336: ($ENV{'form.cuname'},$ENV{'form.cdomain'}));
337:
1.4 www 338: } else {
339: $r->print('Invalid login mode or password');
340: }
341: } else {
342: $r->print('Invalid username or domain');
343: }
344: }
345: my $now=time;
1.6 www 346: $r->print('<h3>Modifying Roles</h3>');
1.4 www 347: map {
348: if (($_=~/^form\.rev\:([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {
349: $r->print('Revoking '.$2.' in '.$1.': '.
350: &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},
351: $1,$2,$now).'<br>');
1.11 www 352: if ($2 eq 'st') {
353: $1=~/^\/(\w+)\/(\w+)/;
354: my $cid=$1.'_'.$2;
355: $r->print('Drop from classlist: '.
356: &Apache::lonnet::critical('put:'.$ENV{'course.'.$cid.'.domain'}.':'.
357: $ENV{'course.'.$cid.'.num'}.':classlist:'.
358: &Apache::lonnet::escape($ENV{'form.cuname'}.':'.
359: $ENV{'form.cdomain'}).'='.
360: &Apache::lonnet::escape($now.':'),
361: $ENV{'course.'.$cid.'.home'}).'<br>');
362: }
1.4 www 363: }
364: } keys %ENV;
365: map {
366: if (($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {
1.5 www 367: my $url='/'.$1.'/'.$2;
368: if ($ENV{'form.sec_'.$1.'_'.$2.'_'.$3}) {
369: $url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3};
370: }
371: my $start=$now;
372: if ($ENV{'form.start_'.$1.'_'.$2.'_'.$3}) {
373: $start=$ENV{'form.start_'.$1.'_'.$2.'_'.$3};
374: }
375: my $end=0;
376: if ($ENV{'form.end_'.$1.'_'.$2.'_'.$3}) {
377: $end=$ENV{'form.end_'.$1.'_'.$2.'_'.$3};
378: }
379: $r->print('Assigning: '.$3.' in '.$url.': '.
380: &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},
381: $url,$3,$end,$start).'<br>');
1.10 www 382: if ($3 eq 'st') {
1.11 www 383: $url=~/^\/(\w+)\/(\w+)/;
384: my $cid=$1.'_'.$2;
1.10 www 385: $r->print('Add to 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($end.':'.$start),
391: $ENV{'course.'.$cid.'.home'}).'<br>');
392: }
1.8 www 393: } elsif (($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {
394: my $url='/'.$1.'/';
395: my $start=$now;
396: if ($ENV{'form.start_'.$1.'_'.$2}) {
397: $start=$ENV{'form.start_'.$1.'_'.$2};
398: }
399: my $end=0;
400: if ($ENV{'form.end_'.$1.'_'.$2}) {
401: $end=$ENV{'form.end_'.$1.'_'.$2};
402: }
403: $r->print('Assigning: '.$2.' in '.$url.': '.
404: &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},
405: $url,$2,$end,$start).'<br>');
406: }
1.4 www 407: } keys %ENV;
1.5 www 408: $r->print('</body></html>');
1.4 www 409: }
410:
1.2 www 411: # ================================================================ Main Handler
412: sub handler {
413: my $r = shift;
414:
415: if ($r->header_only) {
416: $r->content_type('text/html');
417: $r->send_http_header;
418: return OK;
419: }
420:
421: if ((&Apache::lonnet::allowed('cta',$ENV{'request.course.id'})) ||
422: (&Apache::lonnet::allowed('cin',$ENV{'request.course.id'})) ||
423: (&Apache::lonnet::allowed('ccr',$ENV{'request.course.id'})) ||
424: (&Apache::lonnet::allowed('cep',$ENV{'request.course.id'})) ||
425: (&Apache::lonnet::allowed('mau',$ENV{'user.domain'}))) {
426: $r->content_type('text/html');
427: $r->send_http_header;
428: unless ($ENV{'form.phase'}) {
429: &phase_one($r);
430: }
431: if ($ENV{'form.phase'} eq 'two') {
432: &phase_two($r);
1.4 www 433: } elsif ($ENV{'form.phase'} eq 'three') {
434: &phase_three($r);
1.2 www 435: }
1.1 www 436: } else {
437: $ENV{'user.error.msg'}=
1.9 albertel 438: "/adm/createuser:mau:0:0:Cannot modify user data";
1.1 www 439: return HTTP_NOT_ACCEPTABLE;
440: }
441: return OK;
442: }
443:
444: 1;
445: __END__
1.2 www 446:
447:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>