Annotation of loncom/interface/lonpreferences.pm, revision 1.23
1.1 www 1: # The LearningOnline Network
2: # Preferences
3: #
1.23 ! matthew 4: # $Id: lonpreferences.pm,v 1.22 2003/04/30 15:12:29 matthew Exp $
1.2 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 www 28: # (Internal Server Error Handler
29: #
30: # (Login Screen
31: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
32: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
33: #
34: # 3/1/1 Gerd Kortemeyer)
35: #
36: # 3/1 Gerd Kortemeyer
37: #
1.3 matthew 38: # 2/13/02 2/14 2/15 Matthew Hall
39: #
40: # This package uses the "londes.js" javascript code.
41: #
42: # TODOs that have to be completed:
43: # interface with lonnet to change the password
44:
1.1 www 45: package Apache::lonpreferences;
46:
47: use strict;
48: use Apache::Constants qw(:common);
1.3 matthew 49: use Apache::File;
50: use Crypt::DES;
51: use DynaLoader; # for Crypt::DES version
1.4 matthew 52: use Apache::loncommon();
1.23 ! matthew 53: use Apache::lonhtmlcommon();
1.3 matthew 54:
55: #
56: # Write lonnet::passwd to do the call below.
57: # Use:
58: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
59: #
60: ##################################################
61: # password associated functions #
62: ##################################################
63: sub des_keys {
1.4 matthew 64: # Make a new key for DES encryption.
65: # Each key has two parts which are returned seperately.
66: # Please note: Each key must be passed through the &hex function
67: # before it is output to the web browser. The hex versions cannot
68: # be used to decrypt.
1.3 matthew 69: my @hexstr=('0','1','2','3','4','5','6','7',
70: '8','9','a','b','c','d','e','f');
71: my $lkey='';
72: for (0..7) {
73: $lkey.=$hexstr[rand(15)];
74: }
75: my $ukey='';
76: for (0..7) {
77: $ukey.=$hexstr[rand(15)];
78: }
79: return ($lkey,$ukey);
80: }
81:
82: sub des_decrypt {
83: my ($key,$cyphertext) = @_;
84: my $keybin=pack("H16",$key);
85: my $cypher;
86: if ($Crypt::DES::VERSION>=2.03) {
87: $cypher=new Crypt::DES $keybin;
88: } else {
89: $cypher=new DES $keybin;
90: }
91: my $plaintext=
92: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
93: $plaintext.=
94: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
1.4 matthew 95: $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
1.3 matthew 96: return $plaintext;
97: }
98:
1.4 matthew 99: ################################################################
100: # Handler subroutines #
101: ################################################################
1.9 matthew 102:
103: ################################################################
104: # Anonymous Discussion Name Change Subroutines #
105: ################################################################
1.5 www 106: sub screennamechanger {
107: my $r = shift;
108: my $user = $ENV{'user.name'};
109: my $domain = $ENV{'user.domain'};
1.14 www 110: my %userenv = &Apache::lonnet::get
111: ('environment',['screenname','nickname']);
1.6 www 112: my $screenname=$userenv{'screenname'};
1.14 www 113: my $nickname=$userenv{'nickname'};
1.10 www 114: my $bodytag=&Apache::loncommon::bodytag(
1.14 www 115: 'Change Your Nickname and Anonymous Screen Name');
1.5 www 116: $r->print(<<ENDSCREEN);
117: <html>
1.10 www 118: $bodytag
119:
1.6 www 120: <form name="server" action="/adm/preferences" method="post">
121: <input type="hidden" name="action" value="verify_and_change_screenname" />
1.14 www 122: <br />New screenname (shown if you post anonymously):
1.6 www 123: <input type="text" size="20" value="$screenname" name="screenname" />
1.14 www 124: <br />New nickname (shown if you post non-anonymously):
125: <input type="text" size="20" value="$nickname" name="nickname" />
1.6 www 126: <input type="submit" value="Change" />
127: </form>
1.5 www 128: </body>
129: </html>
130: ENDSCREEN
131: }
1.6 www 132:
133: sub verify_and_change_screenname {
134: my $r = shift;
135: my $user = $ENV{'user.name'};
136: my $domain = $ENV{'user.domain'};
1.14 www 137: # Screenname
1.6 www 138: my $newscreen = $ENV{'form.screenname'};
1.14 www 139: $newscreen=~s/[^ \w]//g;
1.6 www 140: my $message='';
141: if ($newscreen) {
1.7 www 142: &Apache::lonnet::put('environment',{'screenname' => $newscreen});
143: &Apache::lonnet::appenv('environment.screenname' => $newscreen);
1.6 www 144: $message='Set new screenname to '.$newscreen;
145: } else {
146: &Apache::lonnet::del('environment',['screenname']);
1.7 www 147: &Apache::lonnet::delenv('environment\.screenname');
1.6 www 148: $message='Reset screenname';
149: }
1.14 www 150: # Nickname
151: $message.='<br />';
1.17 matthew 152: $newscreen = $ENV{'form.nickname'};
1.14 www 153: $newscreen=~s/[^ \w]//g;
154: if ($newscreen) {
155: &Apache::lonnet::put('environment',{'nickname' => $newscreen});
156: &Apache::lonnet::appenv('environment.nickname' => $newscreen);
157: $message.='Set new nickname to '.$newscreen;
158: } else {
159: &Apache::lonnet::del('environment',['nickname']);
160: &Apache::lonnet::delenv('environment\.nickname');
161: $message.='Reset nickname';
162: }
163:
1.10 www 164: my $bodytag=&Apache::loncommon::bodytag(
1.14 www 165: 'Change Your Nickname and Anonymous Screen Name');
1.6 www 166: $r->print(<<ENDVCSCREEN);
167: <html>
1.10 www 168: $bodytag
1.6 www 169: </p>
170: $message
171: </body></html>
172: ENDVCSCREEN
1.20 www 173: }
174:
175: ################################################################
176: # Message Forward #
177: ################################################################
178:
179: sub msgforwardchanger {
180: my $r = shift;
181: my $user = $ENV{'user.name'};
182: my $domain = $ENV{'user.domain'};
183: my %userenv = &Apache::lonnet::get('environment',['msgforward']);
184: my $msgforward=$userenv{'msgforward'};
185: my $notification=$userenv{'notification'};
186: my $critnotification=$userenv{'critnotification'};
187: my $bodytag=&Apache::loncommon::bodytag(
188: 'Change Your Message Forwarding and Notification');
189: $r->print(<<ENDMSG);
190: <html>
191: $bodytag
192:
193: <form name="server" action="/adm/preferences" method="post">
194: <input type="hidden" name="action" value="verify_and_change_msgforward" />
195: New Forwarding Address(es) (<tt>user:domain,user:domain,...</tt>):
196: <input type="text" size="40" value="$msgforward" name="msgforward" /><hr />
197: New Message Notification Email Address(es) (<tt>joe\@doe.com,jane\@doe.edu,...</tt>):
198: <input type="text" size="40" value="$notification" name="notification" /><hr />
199: New Critical Message Notification Email Address(es) (<tt>joe\@doe.com,jane\@doe.edu,...</tt>):
200: <input type="text" size="40" value="$critnotification" name="critnotification" /><hr />
201: <input type="submit" value="Change" />
202: </form>
203: </body>
204: </html>
205: ENDMSG
206: }
207:
208: sub verify_and_change_msgforward {
209: my $r = shift;
210: my $user = $ENV{'user.name'};
211: my $domain = $ENV{'user.domain'};
212: my $newscreen = '';
213: my $message='';
214: foreach (split(/\,/,$ENV{'form.msgforward'})) {
215: my ($msuser,$msdomain)=split(/[\@\:]/,$_);
216: $msuser=~s/\W//g;
217: $msdomain=~s/\W//g;
218: if (($msuser) && ($msdomain)) {
219: if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') {
220: $newscreen.=$msuser.':'.$msdomain.',';
221: } else {
222: $message.='No such user: '.$msuser.':'.$msdomain.'<br>';
223: }
224: }
225: }
226: $newscreen=~s/\,$//;
227: if ($newscreen) {
228: &Apache::lonnet::put('environment',{'msgforward' => $newscreen});
229: &Apache::lonnet::appenv('environment.msgforward' => $newscreen);
230: $message.='Set new message forwarding to '.$newscreen.'<br />';
231: } else {
232: &Apache::lonnet::del('environment',['msgforward']);
233: &Apache::lonnet::delenv('environment\.msgforward');
234: $message.='Reset message forwarding<br />';
235: }
236: my $notification=$ENV{'form.notification'};
237: $notification=~s/\s//gs;
238: if ($notification) {
239: &Apache::lonnet::put('environment',{'notification' => $notification});
240: &Apache::lonnet::appenv('environment.notification' => $notification);
241: $message.='Set message notification address to '.$notification.'<br />';
242: } else {
243: &Apache::lonnet::del('environment',['notification']);
244: &Apache::lonnet::delenv('environment\.notification');
245: $message.='Reset message notification<br />';
246: }
247: my $critnotification=$ENV{'form.critnotification'};
248: $critnotification=~s/\s//gs;
249: if ($critnotification) {
250: &Apache::lonnet::put('environment',{'critnotification' => $critnotification});
251: &Apache::lonnet::appenv('environment.critnotification' => $critnotification);
252: $message.='Set critical message notification address to '.$critnotification;
253: } else {
254: &Apache::lonnet::del('environment',['critnotification']);
255: &Apache::lonnet::delenv('environment\.critnotification');
256: $message.='Reset critical message notification<br />';
257: }
258: my $bodytag=&Apache::loncommon::bodytag(
259: 'Change Your Message Forwarding and Notifications');
260: $r->print(<<ENDVCMSG);
261: <html>
262: $bodytag
263: </p>
264: $message
265: </body></html>
266: ENDVCMSG
1.6 www 267: }
268:
1.12 www 269: ################################################################
1.19 www 270: # Colors #
1.12 www 271: ################################################################
272:
1.19 www 273: sub colorschanger {
1.12 www 274: my $r = shift;
275: my $bodytag=&Apache::loncommon::bodytag(
1.21 www 276: 'Change Color Scheme for Current Role Type','',
277: 'onUnload="pclose();"');
1.19 www 278: # figure out colors
279: my $function='student';
280: if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
281: $function='coordinator';
282: }
283: if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
284: $function='admin';
285: }
286: if (($ENV{'request.role'}=~/^(au|ca)/) ||
287: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
288: $function='author';
289: }
290: my $domain=&Apache::loncommon::determinedomain();
291: my %colortypes=('pgbg' => 'Page Background',
292: 'tabbg' => 'Header Background',
293: 'sidebg'=> 'Header Border',
294: 'font' => 'Font',
295: 'link' => 'Un-Visited Link',
296: 'vlink' => 'Visited Link',
297: 'alink' => 'Active Link');
298: my $chtable='';
1.22 matthew 299: foreach my $item (sort(keys(%colortypes))) {
1.19 www 300: my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain);
301: $chtable.='<tr><td>'.$colortypes{$item}.'</td><td bgcolor="'.$curcol.
302: '"> </td><td><input name="'.$item.
1.21 www 303: '" size="10" value="'.$curcol.
304: '" /></td><td><a href="javascript:pjump('."'color_custom','".$colortypes{$item}.
1.19 www 305: "','".$curcol."','"
1.21 www 306: .$item."','parmform.pres','psub'".');">Select</a></td></tr>';
1.19 www 307: }
1.23 ! matthew 308: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.19 www 309: $r->print(<<ENDCOL);
1.12 www 310: <html>
1.19 www 311: <script>
312:
313: function pclose() {
314: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
315: "height=350,width=350,scrollbars=no,menubar=no");
316: parmwin.close();
317: }
318:
1.23 ! matthew 319: $pjump_def
1.19 www 320:
321: function psub() {
322: pclose();
323: if (document.parmform.pres_marker.value!='') {
1.21 www 324: if (document.parmform.pres_type.value!='') {
325: eval('document.server.'+
326: document.parmform.pres_marker.value+
1.19 www 327: '.value=document.parmform.pres_value.value;');
1.21 www 328: }
1.19 www 329: } else {
330: document.parmform.pres_value.value='';
331: document.parmform.pres_marker.value='';
332: }
333: }
334:
335:
336: </script>
1.12 www 337: $bodytag
1.21 www 338: <form name="parmform">
339: <input type="hidden" name="pres_marker" />
340: <input type="hidden" name="pres_type" />
341: <input type="hidden" name="pres_value" />
342: </form>
1.12 www 343: <form name="server" action="/adm/preferences" method="post">
1.19 www 344: <input type="hidden" name="action" value="verify_and_change_colors" />
345: <table border="2">
346: $chtable
347: </table>
1.21 www 348: <input type="submit" value="Change Custom Colors" />
349: <input type="submit" name="resetall" value="Reset All Colors to Default" />
1.12 www 350: </form>
351: </body>
352: </html>
1.19 www 353: ENDCOL
1.12 www 354: }
355:
1.19 www 356: sub verify_and_change_colors {
1.12 www 357: my $r = shift;
1.19 www 358: # figure out colors
359: my $function='student';
360: if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
361: $function='coordinator';
362: }
363: if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
364: $function='admin';
365: }
366: if (($ENV{'request.role'}=~/^(au|ca)/) ||
367: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
368: $function='author';
369: }
370: my $domain=&Apache::loncommon::determinedomain();
371: my %colortypes=('pgbg' => 'Page Background',
372: 'tabbg' => 'Header Background',
373: 'sidebg'=> 'Header Border',
374: 'font' => 'Font',
375: 'link' => 'Un-Visited Link',
376: 'vlink' => 'Visited Link',
377: 'alink' => 'Active Link');
378:
1.12 www 379: my $message='';
1.21 www 380: foreach my $item (keys %colortypes) {
381: my $color=$ENV{'form.'.$item};
382: my $entry='color.'.$function.'.'.$item;
383: if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$ENV{'form.resetall'})) {
384: &Apache::lonnet::put('environment',{$entry => $color});
385: &Apache::lonnet::appenv('environment.'.$entry => $color);
386: $message.='Set '.$colortypes{$item}.' to '.$color.'<br />';
387: } else {
388: &Apache::lonnet::del('environment',[$entry]);
389: &Apache::lonnet::delenv('environment\.'.$entry);
390: $message.='Reset '.$colortypes{$item}.'<br />';
391: }
392: }
1.12 www 393: my $bodytag=&Apache::loncommon::bodytag(
1.19 www 394: 'Change Color Scheme for Current Role Type');
395: $r->print(<<ENDVCCOL);
1.12 www 396: <html>
397: $bodytag
398: </p>
399: $message
1.21 www 400: <form name="client" action="/adm/preferences" method="post">
401: <input type="hidden" name="action" value="changecolors" />
402: <input type="submit" value="Revise color scheme again" />
403: </form>
1.12 www 404: </body></html>
1.19 www 405: ENDVCCOL
1.12 www 406: }
407:
1.4 matthew 408: ######################################################
409: # password handler subroutines #
410: ######################################################
1.3 matthew 411: sub passwordchanger {
1.4 matthew 412: # This function is a bit of a mess....
1.3 matthew 413: # Passwords are encrypted using londes.js (DES encryption)
414: my $r = shift;
1.4 matthew 415: my $errormessage = shift;
416: $errormessage = ($errormessage || '');
1.3 matthew 417: my $user = $ENV{'user.name'};
418: my $domain = $ENV{'user.domain'};
419: my $homeserver = $ENV{'user.home'};
420: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
421: # Check for authentication types that allow changing of the password.
422: return if ($currentauth !~ /^(unix|internal):/);
423: #
424: # Generate keys
425: my ($lkey_cpass ,$ukey_cpass ) = &des_keys();
426: my ($lkey_npass1,$ukey_npass1) = &des_keys();
427: my ($lkey_npass2,$ukey_npass2) = &des_keys();
1.4 matthew 428: # Store the keys in the log files
1.3 matthew 429: my $lonhost = $r->dir_config('lonHostID');
430: my $logtoken=Apache::lonnet::reply('tmpput:'
431: .$ukey_cpass . $lkey_cpass .'&'
432: .$ukey_npass1 . $lkey_npass1.'&'
433: .$ukey_npass2 . $lkey_npass2,
434: $lonhost);
1.4 matthew 435: # Hexify the keys for output as javascript variables
1.3 matthew 436: $ukey_cpass = hex($ukey_cpass);
437: $lkey_cpass = hex($lkey_cpass);
438: $ukey_npass1= hex($ukey_npass1);
439: $lkey_npass1= hex($lkey_npass1);
440: $ukey_npass2= hex($ukey_npass2);
441: $lkey_npass2= hex($lkey_npass2);
442: # Output javascript to deal with passwords
1.4 matthew 443: # Output DES javascript
1.9 matthew 444: $r->print("<html><head>");
1.3 matthew 445: {
446: my $include = $r->dir_config('lonIncludes');
447: my $jsh=Apache::File->new($include."/londes.js");
448: $r->print(<$jsh>);
449: }
1.10 www 450: my $bodytag=&Apache::loncommon::bodytag('Change Password','',
451: 'onLoad="init();"');
1.3 matthew 452: $r->print(<<ENDFORM);
1.9 matthew 453: </head>
1.10 www 454: $bodytag
1.1 www 455:
1.3 matthew 456: <script language="JavaScript">
457:
458: function send() {
459: uextkey=this.document.client.elements.ukey_cpass.value;
460: lextkey=this.document.client.elements.lkey_cpass.value;
461: initkeys();
462:
463: this.document.server.elements.currentpass.value
464: =crypted(this.document.client.elements.currentpass.value);
465:
466: uextkey=this.document.client.elements.ukey_npass1.value;
467: lextkey=this.document.client.elements.lkey_npass1.value;
468: initkeys();
469: this.document.server.elements.newpass_1.value
470: =crypted(this.document.client.elements.newpass_1.value);
471:
472: uextkey=this.document.client.elements.ukey_npass2.value;
473: lextkey=this.document.client.elements.lkey_npass2.value;
474: initkeys();
475: this.document.server.elements.newpass_2.value
476: =crypted(this.document.client.elements.newpass_2.value);
477:
478: this.document.server.submit();
479: }
480:
481: </script>
1.4 matthew 482: $errormessage
1.10 www 483:
1.3 matthew 484: <p>
485: <!-- We seperate the forms into 'server' and 'client' in order to
486: ensure that unencrypted passwords will not be sent out by a
487: crappy browser -->
488:
489: <form name="server" action="/adm/preferences" method="post">
490: <input type="hidden" name="logtoken" value="$logtoken" />
491: <input type="hidden" name="action" value="verify_and_change_pass" />
492: <input type="hidden" name="currentpass" value="" />
1.4 matthew 493: <input type="hidden" name="newpass_1" value="" />
494: <input type="hidden" name="newpass_2" value="" />
1.3 matthew 495: </form>
496:
497: <form name="client" >
498: <table>
1.4 matthew 499: <tr><td align="right"> Current password: </td>
500: <td><input type="password" name="currentpass" size="10"/> </td></tr>
501: <tr><td align="right"> New password: </td>
502: <td><input type="password" name="newpass_1" size="10" /> </td></tr>
503: <tr><td align="right"> Confirm password: </td>
504: <td><input type="password" name="newpass_2" size="10" /> </td></tr>
1.3 matthew 505: <tr><td colspan="2" align="center">
506: <input type="button" value="Change Password" onClick="send();">
507: </table>
1.4 matthew 508: <input type="hidden" name="ukey_cpass" value="$ukey_cpass" />
509: <input type="hidden" name="lkey_cpass" value="$lkey_cpass" />
1.3 matthew 510: <input type="hidden" name="ukey_npass1" value="$ukey_npass1" />
511: <input type="hidden" name="lkey_npass1" value="$lkey_npass1" />
512: <input type="hidden" name="ukey_npass2" value="$ukey_npass2" />
513: <input type="hidden" name="lkey_npass2" value="$lkey_npass2" />
514: </form>
515: </p>
516: ENDFORM
517: #
518: return;
519: }
520:
521: sub verify_and_change_password {
522: my $r = shift;
523: my $user = $ENV{'user.name'};
524: my $domain = $ENV{'user.domain'};
525: my $homeserver = $ENV{'user.home'};
526: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1.4 matthew 527: # Check for authentication types that allow changing of the password.
528: return if ($currentauth !~ /^(unix|internal):/);
1.3 matthew 529: #
1.4 matthew 530: $r->print(<<ENDHEADER);
531: <html>
532: <head>
533: <title>LON-CAPA Preferences: Change password for $user</title>
534: </head>
535: ENDHEADER
1.3 matthew 536: #
537: my $currentpass = $ENV{'form.currentpass'};
538: my $newpass1 = $ENV{'form.newpass_1'};
539: my $newpass2 = $ENV{'form.newpass_2'};
540: my $logtoken = $ENV{'form.logtoken'};
541: # Check for empty data
1.4 matthew 542: unless (defined($currentpass) &&
543: defined($newpass1) &&
544: defined($newpass2) ){
545: &passwordchanger($r,"<p>\n<font color='#ff0000'>ERROR</font>".
546: "Password data was blank.\n</p>");
1.3 matthew 547: return;
548: }
1.16 albertel 549: # Get the keys
550: my $lonhost = $r->dir_config('lonHostID');
1.3 matthew 551: my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
552: if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
1.4 matthew 553: # I do not a have a better idea about how to handle this
1.3 matthew 554: $r->print(<<ENDERROR);
555: <p>
556: <font color="#ff0000">ERROR:</font> Unable to retrieve stored token for
1.4 matthew 557: password decryption. Please log out and try again.
1.3 matthew 558: </p>
559: ENDERROR
1.4 matthew 560: # Probably should log an error here
1.3 matthew 561: return;
562: }
563: my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
1.4 matthew 564: #
1.17 matthew 565: $currentpass = &des_decrypt($ckey ,$currentpass);
566: $newpass1 = &des_decrypt($n1key,$newpass1);
567: $newpass2 = &des_decrypt($n2key,$newpass2);
1.4 matthew 568: #
1.3 matthew 569: if ($newpass1 ne $newpass2) {
1.4 matthew 570: &passwordchanger($r,
571: '<font color="#ff0000">ERROR:</font>'.
572: 'The new passwords you entered do not match. '.
573: 'Please try again.');
574: return;
575: }
576: if (length($newpass1) < 7) {
577: &passwordchanger($r,
578: '<font color="#ff0000">ERROR:</font>'.
579: 'Passwords must be a minimum of 7 characters long. '.
580: 'Please try again.');
1.3 matthew 581: return;
582: }
1.4 matthew 583: #
584: # Check for bad characters
585: my $badpassword = 0;
586: foreach (split(//,$newpass1)) {
587: $badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
588: }
589: if ($badpassword) {
590: # I can't figure out how to enter bad characters on my browser.
591: &passwordchanger($r,<<ENDERROR);
592: <font color="#ff0000">ERROR:</font>
593: The password you entered contained illegal characters.<br />
594: Valid characters are: space and <br />
595: <pre>
596: !"\#$%&\'()*+,-./0123456789:;<=>?\@
597: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
598: </pre>
599: ENDERROR
600: }
601: #
602: # Change the password (finally)
603: my $result = &Apache::lonnet::changepass
604: ($user,$domain,$currentpass,$newpass1,$homeserver);
605: # Inform the user the password has (not?) been changed
606: if ($result =~ /^ok$/) {
607: $r->print(<<"ENDTEXT");
1.9 matthew 608: <h2>The password for $user was successfully changed</h2>
1.4 matthew 609: ENDTEXT
610: } else {
611: # error error: run in circles, scream and shout
612: $r->print(<<ENDERROR);
1.9 matthew 613: <h2><font color="#ff0000">The password for $user was not changed</font></h2>
1.8 matthew 614: Please make sure your old password was entered correctly.
1.4 matthew 615: ENDERROR
616: }
617: return;
1.3 matthew 618: }
619:
1.4 matthew 620: ######################################################
621: # other handler subroutines #
622: ######################################################
623:
1.3 matthew 624: ################################################################
625: # Main handler #
626: ################################################################
1.1 www 627: sub handler {
628: my $r = shift;
1.3 matthew 629: my $user = $ENV{'user.name'};
630: my $domain = $ENV{'user.domain'};
1.1 www 631: $r->content_type('text/html');
1.4 matthew 632: # Some pages contain DES keys and should not be cached.
633: &Apache::loncommon::no_cache($r);
1.1 www 634: $r->send_http_header;
635: return OK if $r->header_only;
1.9 matthew 636: #
1.3 matthew 637: if ($ENV{'form.action'} eq 'changepass') {
638: &passwordchanger($r);
639: } elsif ($ENV{'form.action'} eq 'verify_and_change_pass') {
640: &verify_and_change_password($r);
1.5 www 641: } elsif ($ENV{'form.action'} eq 'changescreenname') {
642: &screennamechanger($r);
1.6 www 643: } elsif ($ENV{'form.action'} eq 'verify_and_change_screenname') {
644: &verify_and_change_screenname($r);
1.12 www 645: } elsif ($ENV{'form.action'} eq 'changemsgforward') {
646: &msgforwardchanger($r);
647: } elsif ($ENV{'form.action'} eq 'verify_and_change_msgforward') {
648: &verify_and_change_msgforward($r);
1.19 www 649: } elsif ($ENV{'form.action'} eq 'changecolors') {
650: &colorschanger($r);
651: } elsif ($ENV{'form.action'} eq 'verify_and_change_colors') {
652: &verify_and_change_colors($r);
1.15 albertel 653: } elsif ($ENV{'form.action'} eq 'debugtoggle') {
654: if ($ENV{'user.name'} eq 'albertel' ) {
655: if ($ENV{'user.debug'}) {
656: &Apache::lonnet::delenv('user\.debug');
657: } else {
658: &Apache::lonnet::appenv('user.debug' => 1);
659: }
660: }
1.3 matthew 661: } else {
662: $r->print(<<ENDHEADER);
1.1 www 663: <html>
664: <head>
1.4 matthew 665: <title>LON-CAPA Preferences</title>
1.1 www 666: </head>
1.3 matthew 667: ENDHEADER
1.10 www 668: $r->print(&Apache::loncommon::bodytag('Change Your Preferences'));
1.3 matthew 669: # Determine current authentication method
670: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
671: if ($currentauth =~ /^(unix|internal):/) {
1.4 matthew 672: $r->print(<<ENDPASSWORDFORM);
673: <form name="client" action="/adm/preferences" method="post">
1.14 www 674: <input type="hidden" name="action" value="changepass" />
675: <input type="submit" value="Change password" />
1.4 matthew 676: </form>
677: ENDPASSWORDFORM
1.13 www 678: }
1.5 www 679: # Change screen name
680: $r->print(<<ENDSCREENNAMEFORM);
681: <form name="client" action="/adm/preferences" method="post">
1.14 www 682: <input type="hidden" name="action" value="changescreenname" />
683: <input type="submit"
684: value="Change nickname and anonymous discussion screen name" />
1.5 www 685: </form>
686: ENDSCREENNAMEFORM
1.12 www 687: $r->print(<<ENDMSGFORWARDFORM);
688: <form name="client" action="/adm/preferences" method="post">
1.14 www 689: <input type="hidden" name="action" value="changemsgforward" />
1.18 www 690: <input type="submit" value="Change message forwarding and notification addresses" />
1.12 www 691: </form>
692: ENDMSGFORWARDFORM
1.11 www 693: # The "about me" page
1.15 albertel 694: my $aboutmeaction=
695: '/adm/'.$ENV{'user.domain'}.'/'.$ENV{'user.name'}.'/aboutme';
696: $r->print(<<ENDABOUTME);
1.11 www 697: <form name="client" action="$aboutmeaction" method="post">
1.14 www 698: <input type="hidden" name="action" value="changescreenname" />
1.19 www 699: <input type="submit" value="Edit the 'About Me' personal information screen" />
1.11 www 700: </form>
701: ENDABOUTME
1.19 www 702: $r->print(<<ENDCOLORFORM);
703: <form name="client" action="/adm/preferences" method="post">
704: <input type="hidden" name="action" value="changecolors" />
705: <input type="submit" value="Change color scheme" />
706: </form>
707: ENDCOLORFORM
708:
1.15 albertel 709: if ($ENV{'user.name'} eq 'albertel') {
710: $r->print(<<ENDDEBUG);
711: <form name="client" action="/adm/preferences" method="post">
712: <input type="hidden" name="action" value="debugtoggle" />
713: <input type="submit" value="Toggle Debug" />
714: Current Debug status is -$ENV{'user.debug'}-.
715: </form>
716: ENDDEBUG
717: }
718: # Other preference setting code should be added here
1.3 matthew 719: }
720: $r->print(<<ENDFOOTER);
1.1 www 721: </body>
722: </html>
1.3 matthew 723: ENDFOOTER
1.1 www 724: return OK;
1.13 www 725: }
1.1 www 726:
727: 1;
728: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>