File:  [LON-CAPA] / loncom / interface / lonpreferences.pm
Revision 1.20: download - view: text, annotated - select for diffs
Sat Apr 19 01:42:34 2003 UTC (21 years, 1 month ago) by www
Branches: MAIN
CVS tags: HEAD
Oops, had trashed other settings routine.

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

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