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