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