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