Annotation of loncom/interface/lonpreferences.pm, revision 1.27
1.1 www 1: # The LearningOnline Network
2: # Preferences
3: #
1.27 ! bowersj2 4: # $Id: lonpreferences.pm,v 1.26 2003/07/05 10:07:11 www 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'};
1.26 www 183: my %userenv = &Apache::lonnet::get('environment',['msgforward','notification','critnotification']);
1.20 www 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');
1.25 bowersj2 189: my $forwardingHelp = Apache::loncommon::help_open_topic("Prefs_Forwarding",
190: "What are forwarding ".
191: "and notification ".
192: "addresses");
1.27 ! bowersj2 193: my $criticalMessageHelp = Apache::loncommon::help_open_topic("Course_Critical_Message",
! 194: "What are critical messages");
! 195:
1.20 www 196: $r->print(<<ENDMSG);
197: <html>
198: $bodytag
1.25 bowersj2 199: $forwardingHelp <br />
1.20 www 200: <form name="server" action="/adm/preferences" method="post">
201: <input type="hidden" name="action" value="verify_and_change_msgforward" />
202: New Forwarding Address(es) (<tt>user:domain,user:domain,...</tt>):
203: <input type="text" size="40" value="$msgforward" name="msgforward" /><hr />
204: New Message Notification Email Address(es) (<tt>joe\@doe.com,jane\@doe.edu,...</tt>):
205: <input type="text" size="40" value="$notification" name="notification" /><hr />
206: New Critical Message Notification Email Address(es) (<tt>joe\@doe.com,jane\@doe.edu,...</tt>):
1.27 ! bowersj2 207: <input type="text" size="40" value="$critnotification" name="critnotification" />$criticalMessageHelp<hr />
1.20 www 208: <input type="submit" value="Change" />
209: </form>
210: </body>
211: </html>
212: ENDMSG
213: }
214:
215: sub verify_and_change_msgforward {
216: my $r = shift;
217: my $user = $ENV{'user.name'};
218: my $domain = $ENV{'user.domain'};
219: my $newscreen = '';
220: my $message='';
221: foreach (split(/\,/,$ENV{'form.msgforward'})) {
222: my ($msuser,$msdomain)=split(/[\@\:]/,$_);
223: $msuser=~s/\W//g;
224: $msdomain=~s/\W//g;
225: if (($msuser) && ($msdomain)) {
226: if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') {
227: $newscreen.=$msuser.':'.$msdomain.',';
228: } else {
229: $message.='No such user: '.$msuser.':'.$msdomain.'<br>';
230: }
231: }
232: }
233: $newscreen=~s/\,$//;
234: if ($newscreen) {
235: &Apache::lonnet::put('environment',{'msgforward' => $newscreen});
236: &Apache::lonnet::appenv('environment.msgforward' => $newscreen);
237: $message.='Set new message forwarding to '.$newscreen.'<br />';
238: } else {
239: &Apache::lonnet::del('environment',['msgforward']);
240: &Apache::lonnet::delenv('environment\.msgforward');
241: $message.='Reset message forwarding<br />';
242: }
243: my $notification=$ENV{'form.notification'};
244: $notification=~s/\s//gs;
245: if ($notification) {
246: &Apache::lonnet::put('environment',{'notification' => $notification});
247: &Apache::lonnet::appenv('environment.notification' => $notification);
248: $message.='Set message notification address to '.$notification.'<br />';
249: } else {
250: &Apache::lonnet::del('environment',['notification']);
251: &Apache::lonnet::delenv('environment\.notification');
252: $message.='Reset message notification<br />';
253: }
254: my $critnotification=$ENV{'form.critnotification'};
255: $critnotification=~s/\s//gs;
256: if ($critnotification) {
257: &Apache::lonnet::put('environment',{'critnotification' => $critnotification});
258: &Apache::lonnet::appenv('environment.critnotification' => $critnotification);
259: $message.='Set critical message notification address to '.$critnotification;
260: } else {
261: &Apache::lonnet::del('environment',['critnotification']);
262: &Apache::lonnet::delenv('environment\.critnotification');
263: $message.='Reset critical message notification<br />';
264: }
265: my $bodytag=&Apache::loncommon::bodytag(
266: 'Change Your Message Forwarding and Notifications');
267: $r->print(<<ENDVCMSG);
268: <html>
269: $bodytag
270: </p>
271: $message
272: </body></html>
273: ENDVCMSG
1.6 www 274: }
275:
1.12 www 276: ################################################################
1.19 www 277: # Colors #
1.12 www 278: ################################################################
279:
1.19 www 280: sub colorschanger {
1.12 www 281: my $r = shift;
282: my $bodytag=&Apache::loncommon::bodytag(
1.21 www 283: 'Change Color Scheme for Current Role Type','',
284: 'onUnload="pclose();"');
1.19 www 285: # figure out colors
286: my $function='student';
287: if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
288: $function='coordinator';
289: }
290: if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
291: $function='admin';
292: }
293: if (($ENV{'request.role'}=~/^(au|ca)/) ||
294: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
295: $function='author';
296: }
297: my $domain=&Apache::loncommon::determinedomain();
298: my %colortypes=('pgbg' => 'Page Background',
299: 'tabbg' => 'Header Background',
300: 'sidebg'=> 'Header Border',
301: 'font' => 'Font',
302: 'link' => 'Un-Visited Link',
303: 'vlink' => 'Visited Link',
304: 'alink' => 'Active Link');
305: my $chtable='';
1.22 matthew 306: foreach my $item (sort(keys(%colortypes))) {
1.19 www 307: my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain);
308: $chtable.='<tr><td>'.$colortypes{$item}.'</td><td bgcolor="'.$curcol.
309: '"> </td><td><input name="'.$item.
1.21 www 310: '" size="10" value="'.$curcol.
311: '" /></td><td><a href="javascript:pjump('."'color_custom','".$colortypes{$item}.
1.19 www 312: "','".$curcol."','"
1.21 www 313: .$item."','parmform.pres','psub'".');">Select</a></td></tr>';
1.19 www 314: }
1.23 matthew 315: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.19 www 316: $r->print(<<ENDCOL);
1.12 www 317: <html>
1.19 www 318: <script>
319:
320: function pclose() {
321: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
322: "height=350,width=350,scrollbars=no,menubar=no");
323: parmwin.close();
324: }
325:
1.23 matthew 326: $pjump_def
1.19 www 327:
328: function psub() {
329: pclose();
330: if (document.parmform.pres_marker.value!='') {
1.21 www 331: if (document.parmform.pres_type.value!='') {
332: eval('document.server.'+
333: document.parmform.pres_marker.value+
1.19 www 334: '.value=document.parmform.pres_value.value;');
1.21 www 335: }
1.19 www 336: } else {
337: document.parmform.pres_value.value='';
338: document.parmform.pres_marker.value='';
339: }
340: }
341:
342:
343: </script>
1.12 www 344: $bodytag
1.21 www 345: <form name="parmform">
346: <input type="hidden" name="pres_marker" />
347: <input type="hidden" name="pres_type" />
348: <input type="hidden" name="pres_value" />
349: </form>
1.12 www 350: <form name="server" action="/adm/preferences" method="post">
1.19 www 351: <input type="hidden" name="action" value="verify_and_change_colors" />
352: <table border="2">
353: $chtable
354: </table>
1.21 www 355: <input type="submit" value="Change Custom Colors" />
356: <input type="submit" name="resetall" value="Reset All Colors to Default" />
1.12 www 357: </form>
358: </body>
359: </html>
1.19 www 360: ENDCOL
1.12 www 361: }
362:
1.19 www 363: sub verify_and_change_colors {
1.12 www 364: my $r = shift;
1.19 www 365: # figure out colors
366: my $function='student';
367: if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
368: $function='coordinator';
369: }
370: if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
371: $function='admin';
372: }
373: if (($ENV{'request.role'}=~/^(au|ca)/) ||
374: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
375: $function='author';
376: }
377: my $domain=&Apache::loncommon::determinedomain();
378: my %colortypes=('pgbg' => 'Page Background',
379: 'tabbg' => 'Header Background',
380: 'sidebg'=> 'Header Border',
381: 'font' => 'Font',
382: 'link' => 'Un-Visited Link',
383: 'vlink' => 'Visited Link',
384: 'alink' => 'Active Link');
385:
1.12 www 386: my $message='';
1.21 www 387: foreach my $item (keys %colortypes) {
388: my $color=$ENV{'form.'.$item};
389: my $entry='color.'.$function.'.'.$item;
390: if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$ENV{'form.resetall'})) {
391: &Apache::lonnet::put('environment',{$entry => $color});
392: &Apache::lonnet::appenv('environment.'.$entry => $color);
393: $message.='Set '.$colortypes{$item}.' to '.$color.'<br />';
394: } else {
395: &Apache::lonnet::del('environment',[$entry]);
396: &Apache::lonnet::delenv('environment\.'.$entry);
397: $message.='Reset '.$colortypes{$item}.'<br />';
398: }
399: }
1.12 www 400: my $bodytag=&Apache::loncommon::bodytag(
1.19 www 401: 'Change Color Scheme for Current Role Type');
402: $r->print(<<ENDVCCOL);
1.12 www 403: <html>
404: $bodytag
405: </p>
406: $message
1.21 www 407: <form name="client" action="/adm/preferences" method="post">
408: <input type="hidden" name="action" value="changecolors" />
409: <input type="submit" value="Revise color scheme again" />
410: </form>
1.12 www 411: </body></html>
1.19 www 412: ENDVCCOL
1.12 www 413: }
414:
1.4 matthew 415: ######################################################
416: # password handler subroutines #
417: ######################################################
1.3 matthew 418: sub passwordchanger {
1.4 matthew 419: # This function is a bit of a mess....
1.3 matthew 420: # Passwords are encrypted using londes.js (DES encryption)
421: my $r = shift;
1.4 matthew 422: my $errormessage = shift;
423: $errormessage = ($errormessage || '');
1.3 matthew 424: my $user = $ENV{'user.name'};
425: my $domain = $ENV{'user.domain'};
426: my $homeserver = $ENV{'user.home'};
427: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
428: # Check for authentication types that allow changing of the password.
429: return if ($currentauth !~ /^(unix|internal):/);
430: #
431: # Generate keys
432: my ($lkey_cpass ,$ukey_cpass ) = &des_keys();
433: my ($lkey_npass1,$ukey_npass1) = &des_keys();
434: my ($lkey_npass2,$ukey_npass2) = &des_keys();
1.4 matthew 435: # Store the keys in the log files
1.3 matthew 436: my $lonhost = $r->dir_config('lonHostID');
437: my $logtoken=Apache::lonnet::reply('tmpput:'
438: .$ukey_cpass . $lkey_cpass .'&'
439: .$ukey_npass1 . $lkey_npass1.'&'
440: .$ukey_npass2 . $lkey_npass2,
441: $lonhost);
1.4 matthew 442: # Hexify the keys for output as javascript variables
1.3 matthew 443: $ukey_cpass = hex($ukey_cpass);
444: $lkey_cpass = hex($lkey_cpass);
445: $ukey_npass1= hex($ukey_npass1);
446: $lkey_npass1= hex($lkey_npass1);
447: $ukey_npass2= hex($ukey_npass2);
448: $lkey_npass2= hex($lkey_npass2);
449: # Output javascript to deal with passwords
1.4 matthew 450: # Output DES javascript
1.9 matthew 451: $r->print("<html><head>");
1.3 matthew 452: {
453: my $include = $r->dir_config('lonIncludes');
454: my $jsh=Apache::File->new($include."/londes.js");
455: $r->print(<$jsh>);
456: }
1.10 www 457: my $bodytag=&Apache::loncommon::bodytag('Change Password','',
458: 'onLoad="init();"');
1.3 matthew 459: $r->print(<<ENDFORM);
1.9 matthew 460: </head>
1.10 www 461: $bodytag
1.1 www 462:
1.3 matthew 463: <script language="JavaScript">
464:
465: function send() {
466: uextkey=this.document.client.elements.ukey_cpass.value;
467: lextkey=this.document.client.elements.lkey_cpass.value;
468: initkeys();
469:
470: this.document.server.elements.currentpass.value
471: =crypted(this.document.client.elements.currentpass.value);
472:
473: uextkey=this.document.client.elements.ukey_npass1.value;
474: lextkey=this.document.client.elements.lkey_npass1.value;
475: initkeys();
476: this.document.server.elements.newpass_1.value
477: =crypted(this.document.client.elements.newpass_1.value);
478:
479: uextkey=this.document.client.elements.ukey_npass2.value;
480: lextkey=this.document.client.elements.lkey_npass2.value;
481: initkeys();
482: this.document.server.elements.newpass_2.value
483: =crypted(this.document.client.elements.newpass_2.value);
484:
485: this.document.server.submit();
486: }
487:
488: </script>
1.4 matthew 489: $errormessage
1.10 www 490:
1.3 matthew 491: <p>
492: <!-- We seperate the forms into 'server' and 'client' in order to
493: ensure that unencrypted passwords will not be sent out by a
494: crappy browser -->
495:
496: <form name="server" action="/adm/preferences" method="post">
497: <input type="hidden" name="logtoken" value="$logtoken" />
498: <input type="hidden" name="action" value="verify_and_change_pass" />
499: <input type="hidden" name="currentpass" value="" />
1.4 matthew 500: <input type="hidden" name="newpass_1" value="" />
501: <input type="hidden" name="newpass_2" value="" />
1.3 matthew 502: </form>
503:
504: <form name="client" >
505: <table>
1.4 matthew 506: <tr><td align="right"> Current password: </td>
507: <td><input type="password" name="currentpass" size="10"/> </td></tr>
508: <tr><td align="right"> New password: </td>
509: <td><input type="password" name="newpass_1" size="10" /> </td></tr>
510: <tr><td align="right"> Confirm password: </td>
511: <td><input type="password" name="newpass_2" size="10" /> </td></tr>
1.3 matthew 512: <tr><td colspan="2" align="center">
513: <input type="button" value="Change Password" onClick="send();">
514: </table>
1.4 matthew 515: <input type="hidden" name="ukey_cpass" value="$ukey_cpass" />
516: <input type="hidden" name="lkey_cpass" value="$lkey_cpass" />
1.3 matthew 517: <input type="hidden" name="ukey_npass1" value="$ukey_npass1" />
518: <input type="hidden" name="lkey_npass1" value="$lkey_npass1" />
519: <input type="hidden" name="ukey_npass2" value="$ukey_npass2" />
520: <input type="hidden" name="lkey_npass2" value="$lkey_npass2" />
521: </form>
522: </p>
523: ENDFORM
524: #
525: return;
526: }
527:
528: sub verify_and_change_password {
529: my $r = shift;
530: my $user = $ENV{'user.name'};
531: my $domain = $ENV{'user.domain'};
532: my $homeserver = $ENV{'user.home'};
533: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
1.4 matthew 534: # Check for authentication types that allow changing of the password.
535: return if ($currentauth !~ /^(unix|internal):/);
1.3 matthew 536: #
1.4 matthew 537: $r->print(<<ENDHEADER);
538: <html>
539: <head>
540: <title>LON-CAPA Preferences: Change password for $user</title>
541: </head>
542: ENDHEADER
1.3 matthew 543: #
544: my $currentpass = $ENV{'form.currentpass'};
545: my $newpass1 = $ENV{'form.newpass_1'};
546: my $newpass2 = $ENV{'form.newpass_2'};
547: my $logtoken = $ENV{'form.logtoken'};
548: # Check for empty data
1.4 matthew 549: unless (defined($currentpass) &&
550: defined($newpass1) &&
551: defined($newpass2) ){
552: &passwordchanger($r,"<p>\n<font color='#ff0000'>ERROR</font>".
553: "Password data was blank.\n</p>");
1.3 matthew 554: return;
555: }
1.16 albertel 556: # Get the keys
557: my $lonhost = $r->dir_config('lonHostID');
1.3 matthew 558: my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
559: if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
1.4 matthew 560: # I do not a have a better idea about how to handle this
1.3 matthew 561: $r->print(<<ENDERROR);
562: <p>
563: <font color="#ff0000">ERROR:</font> Unable to retrieve stored token for
1.4 matthew 564: password decryption. Please log out and try again.
1.3 matthew 565: </p>
566: ENDERROR
1.4 matthew 567: # Probably should log an error here
1.3 matthew 568: return;
569: }
570: my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
1.4 matthew 571: #
1.17 matthew 572: $currentpass = &des_decrypt($ckey ,$currentpass);
573: $newpass1 = &des_decrypt($n1key,$newpass1);
574: $newpass2 = &des_decrypt($n2key,$newpass2);
1.4 matthew 575: #
1.3 matthew 576: if ($newpass1 ne $newpass2) {
1.4 matthew 577: &passwordchanger($r,
578: '<font color="#ff0000">ERROR:</font>'.
579: 'The new passwords you entered do not match. '.
580: 'Please try again.');
581: return;
582: }
583: if (length($newpass1) < 7) {
584: &passwordchanger($r,
585: '<font color="#ff0000">ERROR:</font>'.
586: 'Passwords must be a minimum of 7 characters long. '.
587: 'Please try again.');
1.3 matthew 588: return;
589: }
1.4 matthew 590: #
591: # Check for bad characters
592: my $badpassword = 0;
593: foreach (split(//,$newpass1)) {
594: $badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
595: }
596: if ($badpassword) {
597: # I can't figure out how to enter bad characters on my browser.
598: &passwordchanger($r,<<ENDERROR);
599: <font color="#ff0000">ERROR:</font>
600: The password you entered contained illegal characters.<br />
601: Valid characters are: space and <br />
602: <pre>
603: !"\#$%&\'()*+,-./0123456789:;<=>?\@
604: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
605: </pre>
606: ENDERROR
607: }
608: #
609: # Change the password (finally)
610: my $result = &Apache::lonnet::changepass
611: ($user,$domain,$currentpass,$newpass1,$homeserver);
612: # Inform the user the password has (not?) been changed
613: if ($result =~ /^ok$/) {
614: $r->print(<<"ENDTEXT");
1.9 matthew 615: <h2>The password for $user was successfully changed</h2>
1.4 matthew 616: ENDTEXT
617: } else {
618: # error error: run in circles, scream and shout
619: $r->print(<<ENDERROR);
1.9 matthew 620: <h2><font color="#ff0000">The password for $user was not changed</font></h2>
1.8 matthew 621: Please make sure your old password was entered correctly.
1.4 matthew 622: ENDERROR
623: }
624: return;
1.3 matthew 625: }
626:
1.4 matthew 627: ######################################################
628: # other handler subroutines #
629: ######################################################
630:
1.3 matthew 631: ################################################################
632: # Main handler #
633: ################################################################
1.1 www 634: sub handler {
635: my $r = shift;
1.3 matthew 636: my $user = $ENV{'user.name'};
637: my $domain = $ENV{'user.domain'};
1.1 www 638: $r->content_type('text/html');
1.4 matthew 639: # Some pages contain DES keys and should not be cached.
640: &Apache::loncommon::no_cache($r);
1.1 www 641: $r->send_http_header;
642: return OK if $r->header_only;
1.9 matthew 643: #
1.3 matthew 644: if ($ENV{'form.action'} eq 'changepass') {
645: &passwordchanger($r);
646: } elsif ($ENV{'form.action'} eq 'verify_and_change_pass') {
647: &verify_and_change_password($r);
1.5 www 648: } elsif ($ENV{'form.action'} eq 'changescreenname') {
649: &screennamechanger($r);
1.6 www 650: } elsif ($ENV{'form.action'} eq 'verify_and_change_screenname') {
651: &verify_and_change_screenname($r);
1.12 www 652: } elsif ($ENV{'form.action'} eq 'changemsgforward') {
653: &msgforwardchanger($r);
654: } elsif ($ENV{'form.action'} eq 'verify_and_change_msgforward') {
655: &verify_and_change_msgforward($r);
1.19 www 656: } elsif ($ENV{'form.action'} eq 'changecolors') {
657: &colorschanger($r);
658: } elsif ($ENV{'form.action'} eq 'verify_and_change_colors') {
659: &verify_and_change_colors($r);
1.15 albertel 660: } elsif ($ENV{'form.action'} eq 'debugtoggle') {
1.24 www 661: if (($ENV{'user.name'} eq 'albertel' ) ||
662: ($ENV{'user.name'} eq 'kortemey' ) ||
663: ($ENV{'user.name'} eq 'korte')) {
1.15 albertel 664: if ($ENV{'user.debug'}) {
665: &Apache::lonnet::delenv('user\.debug');
666: } else {
667: &Apache::lonnet::appenv('user.debug' => 1);
668: }
669: }
1.3 matthew 670: } else {
671: $r->print(<<ENDHEADER);
1.1 www 672: <html>
673: <head>
1.4 matthew 674: <title>LON-CAPA Preferences</title>
1.1 www 675: </head>
1.3 matthew 676: ENDHEADER
1.10 www 677: $r->print(&Apache::loncommon::bodytag('Change Your Preferences'));
1.3 matthew 678: # Determine current authentication method
679: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
680: if ($currentauth =~ /^(unix|internal):/) {
1.4 matthew 681: $r->print(<<ENDPASSWORDFORM);
682: <form name="client" action="/adm/preferences" method="post">
1.14 www 683: <input type="hidden" name="action" value="changepass" />
684: <input type="submit" value="Change password" />
1.4 matthew 685: </form>
686: ENDPASSWORDFORM
1.13 www 687: }
1.5 www 688: # Change screen name
689: $r->print(<<ENDSCREENNAMEFORM);
690: <form name="client" action="/adm/preferences" method="post">
1.14 www 691: <input type="hidden" name="action" value="changescreenname" />
692: <input type="submit"
693: value="Change nickname and anonymous discussion screen name" />
1.5 www 694: </form>
695: ENDSCREENNAMEFORM
1.12 www 696: $r->print(<<ENDMSGFORWARDFORM);
697: <form name="client" action="/adm/preferences" method="post">
1.14 www 698: <input type="hidden" name="action" value="changemsgforward" />
1.18 www 699: <input type="submit" value="Change message forwarding and notification addresses" />
1.12 www 700: </form>
701: ENDMSGFORWARDFORM
1.11 www 702: # The "about me" page
1.15 albertel 703: my $aboutmeaction=
704: '/adm/'.$ENV{'user.domain'}.'/'.$ENV{'user.name'}.'/aboutme';
705: $r->print(<<ENDABOUTME);
1.11 www 706: <form name="client" action="$aboutmeaction" method="post">
1.14 www 707: <input type="hidden" name="action" value="changescreenname" />
1.19 www 708: <input type="submit" value="Edit the 'About Me' personal information screen" />
1.11 www 709: </form>
710: ENDABOUTME
1.19 www 711: $r->print(<<ENDCOLORFORM);
712: <form name="client" action="/adm/preferences" method="post">
713: <input type="hidden" name="action" value="changecolors" />
714: <input type="submit" value="Change color scheme" />
715: </form>
716: ENDCOLORFORM
717:
1.24 www 718: if (($ENV{'user.name'} eq 'albertel' ) ||
719: ($ENV{'user.name'} eq 'kortemey' ) ||
720: ($ENV{'user.name'} eq 'korte')) {
1.15 albertel 721: $r->print(<<ENDDEBUG);
722: <form name="client" action="/adm/preferences" method="post">
723: <input type="hidden" name="action" value="debugtoggle" />
724: <input type="submit" value="Toggle Debug" />
725: Current Debug status is -$ENV{'user.debug'}-.
726: </form>
727: ENDDEBUG
728: }
729: # Other preference setting code should be added here
1.3 matthew 730: }
731: $r->print(<<ENDFOOTER);
1.1 www 732: </body>
733: </html>
1.3 matthew 734: ENDFOOTER
1.1 www 735: return OK;
1.13 www 736: }
1.1 www 737:
738: 1;
739: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>