File:  [LON-CAPA] / loncom / interface / lonpreferences.pm
Revision 1.24: download - view: text, annotated - select for diffs
Wed May 21 00:48:27 2003 UTC (21 years ago) by www
Branches: MAIN
CVS tags: version_0_99_2, version_0_99_1, version_0_99_0, conference_2003, HEAD
Disable "New Problem" function in DOCS unless $ENV{'user.debug'} is on.
For 0.99.

    1: # The LearningOnline Network
    2: # Preferences
    3: #
    4: # $Id: lonpreferences.pm,v 1.24 2003/05/21 00:48:27 www Exp $
    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: #
   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: #
   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:  
   45: package Apache::lonpreferences;
   46: 
   47: use strict;
   48: use Apache::Constants qw(:common);
   49: use Apache::File;
   50: use Crypt::DES;
   51: use DynaLoader; # for Crypt::DES version
   52: use Apache::loncommon();
   53: use Apache::lonhtmlcommon();
   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 {
   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.
   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))));
   95:     $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
   96:     return $plaintext;
   97: }
   98: 
   99: ################################################################
  100: #                       Handler subroutines                    #
  101: ################################################################
  102: 
  103: ################################################################
  104: #         Anonymous Discussion Name Change Subroutines         #
  105: ################################################################
  106: sub screennamechanger {
  107:     my $r = shift;
  108:     my $user       = $ENV{'user.name'};
  109:     my $domain     = $ENV{'user.domain'};
  110:     my %userenv = &Apache::lonnet::get
  111:         ('environment',['screenname','nickname']);
  112:     my $screenname=$userenv{'screenname'};
  113:     my $nickname=$userenv{'nickname'};
  114:     my $bodytag=&Apache::loncommon::bodytag(
  115:               'Change Your Nickname and Anonymous Screen Name');
  116:     $r->print(<<ENDSCREEN);
  117: <html>
  118: $bodytag
  119: 
  120: <form name="server" action="/adm/preferences" method="post">
  121: <input type="hidden" name="action" value="verify_and_change_screenname" />
  122: <br />New screenname (shown if you post anonymously):
  123: <input type="text" size="20" value="$screenname" name="screenname" />
  124: <br />New nickname (shown if you post non-anonymously):
  125: <input type="text" size="20" value="$nickname" name="nickname" />
  126: <input type="submit" value="Change" />
  127: </form>
  128: </body>
  129: </html>
  130: ENDSCREEN
  131: }
  132: 
  133: sub verify_and_change_screenname {
  134:     my $r = shift;
  135:     my $user       = $ENV{'user.name'};
  136:     my $domain     = $ENV{'user.domain'};
  137: # Screenname
  138:     my $newscreen  = $ENV{'form.screenname'};
  139:     $newscreen=~s/[^ \w]//g;
  140:     my $message='';
  141:     if ($newscreen) {
  142:         &Apache::lonnet::put('environment',{'screenname' => $newscreen});
  143:         &Apache::lonnet::appenv('environment.screenname' => $newscreen);
  144:         $message='Set new screenname to '.$newscreen;
  145:     } else {
  146:         &Apache::lonnet::del('environment',['screenname']);
  147:         &Apache::lonnet::delenv('environment\.screenname');
  148:         $message='Reset screenname';
  149:     }
  150: # Nickname
  151:     $message.='<br />';
  152:     $newscreen  = $ENV{'form.nickname'};
  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: 
  164:     my $bodytag=&Apache::loncommon::bodytag(
  165:                     'Change Your Nickname and Anonymous Screen Name');
  166:     $r->print(<<ENDVCSCREEN);
  167: <html>
  168: $bodytag
  169: </p>
  170: $message
  171: </body></html>
  172: ENDVCSCREEN
  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
  267: }
  268: 
  269: ################################################################
  270: #         Colors                                               #
  271: ################################################################
  272: 
  273: sub colorschanger {
  274:     my $r = shift;
  275:     my $bodytag=&Apache::loncommon::bodytag(
  276:                     'Change Color Scheme for Current Role Type','',
  277:                     'onUnload="pclose();"');
  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='';
  299:     foreach my $item (sort(keys(%colortypes))) {
  300:        my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain);
  301:        $chtable.='<tr><td>'.$colortypes{$item}.'</td><td bgcolor="'.$curcol.
  302:         '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td><input name="'.$item.
  303:         '" size="10" value="'.$curcol.
  304: '" /></td><td><a href="javascript:pjump('."'color_custom','".$colortypes{$item}.
  305: "','".$curcol."','"
  306: 	    .$item."','parmform.pres','psub'".');">Select</a></td></tr>';
  307:     }
  308:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  309:     $r->print(<<ENDCOL);
  310: <html>
  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: 
  319:     $pjump_def
  320: 
  321:     function psub() {
  322:         pclose();
  323:         if (document.parmform.pres_marker.value!='') {
  324:             if (document.parmform.pres_type.value!='') {
  325:                 eval('document.server.'+
  326:                      document.parmform.pres_marker.value+
  327: 		     '.value=document.parmform.pres_value.value;');
  328: 	    }
  329:         } else {
  330:             document.parmform.pres_value.value='';
  331:             document.parmform.pres_marker.value='';
  332:         }
  333:     }
  334: 
  335: 
  336: </script>
  337: $bodytag
  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>
  343: <form name="server" action="/adm/preferences" method="post">
  344: <input type="hidden" name="action" value="verify_and_change_colors" />
  345: <table border="2">
  346: $chtable
  347: </table>
  348: <input type="submit" value="Change Custom Colors" />
  349: <input type="submit" name="resetall" value="Reset All Colors to Default" />
  350: </form>
  351: </body>
  352: </html>
  353: ENDCOL
  354: }
  355: 
  356: sub verify_and_change_colors {
  357:     my $r = shift;
  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: 
  379:     my $message='';
  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:     }
  393:     my $bodytag=&Apache::loncommon::bodytag(
  394:                            'Change Color Scheme for Current Role Type');
  395:     $r->print(<<ENDVCCOL);
  396: <html>
  397: $bodytag
  398: </p>
  399: $message
  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>
  404: </body></html>
  405: ENDVCCOL
  406: }
  407: 
  408: ######################################################
  409: #            password handler subroutines            #
  410: ######################################################
  411: sub passwordchanger {
  412:     # This function is a bit of a mess....
  413:     # Passwords are encrypted using londes.js (DES encryption)
  414:     my $r = shift;
  415:     my $errormessage = shift;
  416:     $errormessage = ($errormessage || '');
  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();
  428:     # Store the keys in the log files
  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);
  435:     # Hexify the keys for output as javascript variables
  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
  443:     # Output DES javascript
  444:     $r->print("<html><head>");
  445:     {
  446: 	my $include = $r->dir_config('lonIncludes');
  447: 	my $jsh=Apache::File->new($include."/londes.js");
  448: 	$r->print(<$jsh>);
  449:     }
  450:     my $bodytag=&Apache::loncommon::bodytag('Change Password','',
  451:                                          'onLoad="init();"');
  452:     $r->print(<<ENDFORM);
  453: </head>
  454: $bodytag
  455: 
  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>
  482: $errormessage
  483: 
  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="" />
  493: <input type="hidden" name="newpass_1"   value="" />
  494: <input type="hidden" name="newpass_2"   value="" />
  495: </form>
  496: 
  497: <form name="client" >
  498: <table>
  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>
  505: <tr><td colspan="2" align="center">
  506:     <input type="button" value="Change Password" onClick="send();">
  507: </table>
  508: <input type="hidden" name="ukey_cpass"  value="$ukey_cpass" />
  509: <input type="hidden" name="lkey_cpass"  value="$lkey_cpass" />
  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);
  527:     # Check for authentication types that allow changing of the password.
  528:     return if ($currentauth !~ /^(unix|internal):/);
  529:     #
  530:     $r->print(<<ENDHEADER);
  531: <html>
  532: <head>
  533: <title>LON-CAPA Preferences:  Change password for $user</title>
  534: </head>
  535: ENDHEADER
  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 
  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>");
  547: 	return;
  548:     }
  549:     # Get the keys
  550:     my $lonhost = $r->dir_config('lonHostID');
  551:     my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
  552:     if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
  553:         # I do not a have a better idea about how to handle this
  554: 	$r->print(<<ENDERROR);
  555: <p>
  556: <font color="#ff0000">ERROR:</font> Unable to retrieve stored token for
  557: password decryption.  Please log out and try again.
  558: </p>
  559: ENDERROR
  560:         # Probably should log an error here
  561:         return;
  562:     }
  563:     my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
  564:     # 
  565:     $currentpass = &des_decrypt($ckey ,$currentpass);
  566:     $newpass1    = &des_decrypt($n1key,$newpass1);
  567:     $newpass2    = &des_decrypt($n2key,$newpass2);
  568:     # 
  569:     if ($newpass1 ne $newpass2) {
  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.');
  581: 	return;
  582:     }
  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: !&quot;\#$%&amp;\'()*+,-./0123456789:;&lt;=&gt;?\@
  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");
  608: <h2>The password for $user was successfully changed</h2>
  609: ENDTEXT
  610:     } else {
  611: 	# error error: run in circles, scream and shout
  612:         $r->print(<<ENDERROR);
  613: <h2><font color="#ff0000">The password for $user was not changed</font></h2>
  614: Please make sure your old password was entered correctly.
  615: ENDERROR
  616:     }
  617:     return;
  618: }
  619: 
  620: ######################################################
  621: #            other handler subroutines               #
  622: ######################################################
  623: 
  624: ################################################################
  625: #                          Main handler                        #
  626: ################################################################
  627: sub handler {
  628:     my $r = shift;
  629:     my $user = $ENV{'user.name'};
  630:     my $domain = $ENV{'user.domain'};
  631:     $r->content_type('text/html');
  632:     # Some pages contain DES keys and should not be cached.
  633:     &Apache::loncommon::no_cache($r);
  634:     $r->send_http_header;
  635:     return OK if $r->header_only;
  636:     #
  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);
  641:     } elsif ($ENV{'form.action'} eq 'changescreenname') {
  642:         &screennamechanger($r);
  643:     } elsif ($ENV{'form.action'} eq 'verify_and_change_screenname') {
  644:         &verify_and_change_screenname($r);
  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);
  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);
  653:     } elsif ($ENV{'form.action'} eq 'debugtoggle') {
  654: 	if (($ENV{'user.name'} eq 'albertel' ) ||
  655:             ($ENV{'user.name'} eq 'kortemey' ) ||
  656:             ($ENV{'user.name'} eq 'korte')) {
  657: 	    if ($ENV{'user.debug'}) {
  658: 		&Apache::lonnet::delenv('user\.debug');
  659: 	    } else {
  660: 		&Apache::lonnet::appenv('user.debug' => 1);
  661: 	    }
  662: 	}
  663:     } else {
  664: 	$r->print(<<ENDHEADER);
  665: <html>
  666: <head>
  667: <title>LON-CAPA Preferences</title>
  668: </head>
  669: ENDHEADER
  670:         $r->print(&Apache::loncommon::bodytag('Change Your Preferences'));
  671: 	# Determine current authentication method
  672: 	my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
  673: 	if ($currentauth =~ /^(unix|internal):/) {
  674: 	    $r->print(<<ENDPASSWORDFORM);
  675: <form name="client" action="/adm/preferences" method="post">
  676: <input type="hidden" name="action" value="changepass" />
  677: <input type="submit" value="Change password" />
  678: </form>
  679: ENDPASSWORDFORM
  680:         }
  681: # Change screen name
  682: 	    $r->print(<<ENDSCREENNAMEFORM);
  683: <form name="client" action="/adm/preferences" method="post">
  684: <input type="hidden" name="action" value="changescreenname" />
  685: <input type="submit" 
  686: value="Change nickname and anonymous discussion screen name" />
  687: </form>
  688: ENDSCREENNAMEFORM
  689: 	    $r->print(<<ENDMSGFORWARDFORM);
  690: <form name="client" action="/adm/preferences" method="post">
  691: <input type="hidden" name="action" value="changemsgforward" />
  692: <input type="submit" value="Change message forwarding and notification addresses" />
  693: </form>
  694: ENDMSGFORWARDFORM
  695: # The "about me" page
  696: 	my $aboutmeaction=
  697: 	    '/adm/'.$ENV{'user.domain'}.'/'.$ENV{'user.name'}.'/aboutme';
  698: 	$r->print(<<ENDABOUTME);
  699: <form name="client" action="$aboutmeaction" method="post">
  700: <input type="hidden" name="action" value="changescreenname" />
  701: <input type="submit" value="Edit the 'About Me' personal information screen" />
  702: </form>
  703: ENDABOUTME
  704: 	    $r->print(<<ENDCOLORFORM);
  705: <form name="client" action="/adm/preferences" method="post">
  706: <input type="hidden" name="action" value="changecolors" />
  707: <input type="submit" value="Change color scheme" />
  708: </form>
  709: ENDCOLORFORM
  710: 
  711: 	if (($ENV{'user.name'} eq 'albertel' ) ||
  712:             ($ENV{'user.name'} eq 'kortemey' ) ||
  713:             ($ENV{'user.name'} eq 'korte')) {
  714: 	    $r->print(<<ENDDEBUG);
  715: <form name="client" action="/adm/preferences" method="post">
  716: <input type="hidden" name="action" value="debugtoggle" />
  717: <input type="submit" value="Toggle Debug" />
  718: Current Debug status is -$ENV{'user.debug'}-.
  719: </form>
  720: ENDDEBUG
  721: 	}
  722: 	# Other preference setting code should be added here
  723:     }
  724:     $r->print(<<ENDFOOTER);
  725: </body>
  726: </html>
  727: ENDFOOTER
  728:     return OK;
  729: }
  730: 
  731: 1;
  732: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>