Annotation of loncom/interface/loncreateuser.pm, revision 1.8
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.7 www 19: # 2/14,2/17,2/19,2/20,2/21,2/22,2/23,3/2,3/17 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>');
349: }
350: } keys %ENV;
351: map {
352: if (($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {
1.5 www 353: my $url='/'.$1.'/'.$2;
354: if ($ENV{'form.sec_'.$1.'_'.$2.'_'.$3}) {
355: $url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3};
356: }
357: my $start=$now;
358: if ($ENV{'form.start_'.$1.'_'.$2.'_'.$3}) {
359: $start=$ENV{'form.start_'.$1.'_'.$2.'_'.$3};
360: }
361: my $end=0;
362: if ($ENV{'form.end_'.$1.'_'.$2.'_'.$3}) {
363: $end=$ENV{'form.end_'.$1.'_'.$2.'_'.$3};
364: }
365: $r->print('Assigning: '.$3.' in '.$url.': '.
366: &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},
367: $url,$3,$end,$start).'<br>');
1.8 ! www 368: } elsif (($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {
! 369: my $url='/'.$1.'/';
! 370: my $start=$now;
! 371: if ($ENV{'form.start_'.$1.'_'.$2}) {
! 372: $start=$ENV{'form.start_'.$1.'_'.$2};
! 373: }
! 374: my $end=0;
! 375: if ($ENV{'form.end_'.$1.'_'.$2}) {
! 376: $end=$ENV{'form.end_'.$1.'_'.$2};
! 377: }
! 378: $r->print('Assigning: '.$2.' in '.$url.': '.
! 379: &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},
! 380: $url,$2,$end,$start).'<br>');
! 381: }
1.4 www 382: } keys %ENV;
1.5 www 383: $r->print('</body></html>');
1.4 www 384: }
385:
1.2 www 386: # ================================================================ Main Handler
387: sub handler {
388: my $r = shift;
389:
390: if ($r->header_only) {
391: $r->content_type('text/html');
392: $r->send_http_header;
393: return OK;
394: }
395:
396: if ((&Apache::lonnet::allowed('cta',$ENV{'request.course.id'})) ||
397: (&Apache::lonnet::allowed('cin',$ENV{'request.course.id'})) ||
398: (&Apache::lonnet::allowed('ccr',$ENV{'request.course.id'})) ||
399: (&Apache::lonnet::allowed('cep',$ENV{'request.course.id'})) ||
400: (&Apache::lonnet::allowed('mau',$ENV{'user.domain'}))) {
401: $r->content_type('text/html');
402: $r->send_http_header;
403: unless ($ENV{'form.phase'}) {
404: &phase_one($r);
405: }
406: if ($ENV{'form.phase'} eq 'two') {
407: &phase_two($r);
1.4 www 408: } elsif ($ENV{'form.phase'} eq 'three') {
409: &phase_three($r);
1.2 www 410: }
1.1 www 411: } else {
412: $ENV{'user.error.msg'}=
1.2 www 413: "/adm/createcourse:mau:0:0:Cannot modify user data";
1.1 www 414: return HTTP_NOT_ACCEPTABLE;
415: }
416: return OK;
417: }
418:
419: 1;
420: __END__
1.2 www 421:
422:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>