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