File:  [LON-CAPA] / loncom / interface / lonpreferences.pm
Revision 1.33: download - view: text, annotated - select for diffs
Sat Nov 8 01:45:26 2003 UTC (20 years, 7 months ago) by www
Branches: MAIN
CVS tags: version_1_1_X, version_1_1_3, version_1_1_2, version_1_1_1, version_1_1_0, version_1_0_99_3, version_1_0_99_2, version_1_0_99_1, version_1_0_99, HEAD
Pulldown menu to select language preference.

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

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