Annotation of loncom/interface/lonpreferences.pm, revision 1.26

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

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