Annotation of loncom/interface/loncreateuser.pm, revision 1.7
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>');
232: $r->print('<h4>Domain Level</h4>');
1.2 www 233: map {
234: my $thisdomain=$_;
235: map {
236: if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
237: $r->print($_.' - '.$thisdomain.'<br>');
238: }
239: } ('dc','cc','li','dg','au');
240: } sort keys %incdomains;
1.6 www 241: $r->print('<h4>Course Level</h4>'.
1.3 www 242: '<table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>'.
243: '<th>Group/Section</th><th>Start</th><th>End</th></tr>');
1.2 www 244: map {
245: my $thiscourse=$_;
1.3 www 246: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
247: my $area=$coursedata{'description'};
248: my $bgcol=$thiscourse;
249: $bgcol=~s/[^8-9b-e]//g;
250: $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
1.2 www 251: map {
252: if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
1.3 www 253: my $plrole=&Apache::lonnet::plaintext($_);
254: $r->print(<<ENDROW);
255: <tr bgcolor=#$bgcol>
256: <td><input type=checkbox name="act_$thiscourse\_$_"></td>
257: <td>$plrole</td>
258: <td>$area</td>
259: <td><input type=text size=5 name="sec_$thiscourse\_$_"></td>
260: <td><input type=hidden name="start_$thiscourse\_$_" value=''>
261: <a href=
262: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thiscourse\_$_.value,'start_$thiscourse\_$_','cu.pres','dateset')">Set Start Date</a></td>
263: <td><input type=hidden name="end_$thiscourse\_$_" value=''>
264: <a href=
265: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thiscourse\_$_.value,'end_$thiscourse\_$_','cu.pres','dateset')">Set End Date</a></td>
266: </tr>
267: ENDROW
268:
1.2 www 269: }
270: } ('st','ta','ep','ad','in');
271: } sort keys %inccourses;
1.3 www 272: $r->print('</table>');
1.6 www 273: $r->print('<input type=submit value="Modify User">');
1.2 www 274: $r->print('</form></body></html>');
275: }
1.1 www 276:
1.4 www 277: # ================================================================= Phase Three
278:
279: sub phase_three {
280: my $r=shift;
281: $r->print(<<ENDTHREEHEAD);
282: <html>
283: <head>
284: <title>The LearningOnline Network with CAPA</title>
285: </head>
286: <body bgcolor="#FFFFFF">
287: <img align=right src=/adm/lonIcons/lonlogos.gif>
288: <h1>Create User, Change User Privileges</h1>
289: ENDTHREEHEAD
1.6 www 290: $r->print('<h2>'.$ENV{'form.cuname'}.' at '.$ENV{'form.cdomain'}.'</h2>');
1.4 www 291: if ($ENV{'form.makeuser'}) {
292: $r->print('<h3>Creating User</h3>');
293: if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
294: ($ENV{'form.cdomain'})&&($ENV{'form.cdomain'}!~/\W/)) {
295: my $amode='';
296: my $genpwd='';
297: if ($ENV{'form.login'} eq 'krb') {
298: $amode='krb4';
299: $genpwd=$ENV{'form.krbdom'};
300: } elsif ($ENV{'form.login'} eq 'int') {
301: $amode='internal';
302: $genpwd=$ENV{'form.intpwd'};
303: }
304: if (($amode) && ($genpwd)) {
1.6 www 305: $r->print('Generating user: '.&Apache::lonnet::modifyuser(
1.4 www 306: $ENV{'form.cdomain'},$ENV{'form.cuname'},
307: $ENV{'form.cstid'},$amode,$genpwd,
308: $ENV{'form.cfirst'},$ENV{'form.cmiddle'},
1.6 www 309: $ENV{'form.clast'},$ENV{'form.cgen'}));
310: $r->print('<br>Home server: '.&Apache::lonnet::homeserver
311: ($ENV{'form.cuname'},$ENV{'form.cdomain'}));
312:
1.4 www 313: } else {
314: $r->print('Invalid login mode or password');
315: }
316: } else {
317: $r->print('Invalid username or domain');
318: }
319: }
320: my $now=time;
1.6 www 321: $r->print('<h3>Modifying Roles</h3>');
1.4 www 322: map {
323: if (($_=~/^form\.rev\:([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {
324: $r->print('Revoking '.$2.' in '.$1.': '.
325: &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},
326: $1,$2,$now).'<br>');
327: }
328: } keys %ENV;
329: map {
330: if (($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {
1.5 www 331: my $url='/'.$1.'/'.$2;
332: if ($ENV{'form.sec_'.$1.'_'.$2.'_'.$3}) {
333: $url.='/'.$ENV{'form.sec_'.$1.'_'.$2.'_'.$3};
334: }
335: my $start=$now;
336: if ($ENV{'form.start_'.$1.'_'.$2.'_'.$3}) {
337: $start=$ENV{'form.start_'.$1.'_'.$2.'_'.$3};
338: }
339: my $end=0;
340: if ($ENV{'form.end_'.$1.'_'.$2.'_'.$3}) {
341: $end=$ENV{'form.end_'.$1.'_'.$2.'_'.$3};
342: }
343: $r->print('Assigning: '.$3.' in '.$url.': '.
344: &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},
345: $url,$3,$end,$start).'<br>');
1.4 www 346: }
347: } keys %ENV;
1.5 www 348: $r->print('</body></html>');
1.4 www 349: }
350:
1.2 www 351: # ================================================================ Main Handler
352: sub handler {
353: my $r = shift;
354:
355: if ($r->header_only) {
356: $r->content_type('text/html');
357: $r->send_http_header;
358: return OK;
359: }
360:
361: if ((&Apache::lonnet::allowed('cta',$ENV{'request.course.id'})) ||
362: (&Apache::lonnet::allowed('cin',$ENV{'request.course.id'})) ||
363: (&Apache::lonnet::allowed('ccr',$ENV{'request.course.id'})) ||
364: (&Apache::lonnet::allowed('cep',$ENV{'request.course.id'})) ||
365: (&Apache::lonnet::allowed('mau',$ENV{'user.domain'}))) {
366: $r->content_type('text/html');
367: $r->send_http_header;
368: unless ($ENV{'form.phase'}) {
369: &phase_one($r);
370: }
371: if ($ENV{'form.phase'} eq 'two') {
372: &phase_two($r);
1.4 www 373: } elsif ($ENV{'form.phase'} eq 'three') {
374: &phase_three($r);
1.2 www 375: }
1.1 www 376: } else {
377: $ENV{'user.error.msg'}=
1.2 www 378: "/adm/createcourse:mau:0:0:Cannot modify user data";
1.1 www 379: return HTTP_NOT_ACCEPTABLE;
380: }
381: return OK;
382: }
383:
384: 1;
385: __END__
1.2 www 386:
387:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>