--- loncom/interface/lonpreferences.pm 2016/08/05 20:47:30 1.196.4.18 +++ loncom/interface/lonpreferences.pm 2013/07/22 18:06:51 1.208 @@ -1,7 +1,7 @@ # The LearningOnline Network # Preferences # -# $Id: lonpreferences.pm,v 1.196.4.18 2016/08/05 20:47:30 raeburn Exp $ +# $Id: lonpreferences.pm,v 1.208 2013/07/22 18:06:51 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,6 +36,8 @@ use strict; use LONCAPA; use Apache::Constants qw(:common); use Apache::File; +use Crypt::DES; +use DynaLoader; # for Crypt::DES version use Apache::loncommon(); use Apache::lonhtmlcommon(); use Apache::lonlocal; @@ -43,6 +45,50 @@ use Apache::lonnet; use LONCAPA::lonauthcgi(); use LONCAPA(); +# +# Write lonnet::passwd to do the call below. +# Use: +# my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver); +# +################################################## +# password associated functions # +################################################## +sub des_keys { + # Make a new key for DES encryption. + # Each key has two parts which are returned separately. + # Please note: Each key must be passed through the &hex function + # before it is output to the web browser. The hex versions cannot + # be used to decrypt. + my @hexstr=('0','1','2','3','4','5','6','7', + '8','9','a','b','c','d','e','f'); + my $lkey=''; + for (0..7) { + $lkey.=$hexstr[rand(15)]; + } + my $ukey=''; + for (0..7) { + $ukey.=$hexstr[rand(15)]; + } + return ($lkey,$ukey); +} + +sub des_decrypt { + my ($key,$cyphertext) = @_; + my $keybin=pack("H16",$key); + my $cypher; + if ($Crypt::DES::VERSION>=2.03) { + $cypher=new Crypt::DES $keybin; + } else { + $cypher=new DES $keybin; + } + my $plaintext= + $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16)))); + $plaintext.= + $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16)))); + $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) ); + return $plaintext; +} + ################################################################ # Handler subroutines # ################################################################ @@ -160,14 +206,12 @@ sub texenginechanger { my $domain = $env{'user.domain'}; my %userenv = &Apache::lonnet::get('environment',['texengine']); my $texengine=$userenv{'texengine'}; - if (lc($texengine) eq 'jsmath') { - $texengine = 'MathJax'; - } my %mathchoices=('' => 'Default', 'tth' => 'tth (TeX to HTML)', #'ttm' => 'TeX to MathML', - 'MathJax' => 'MathJax', + 'jsMath' => 'jsMath', + 'MathJax' => 'MathJax', 'mimetex' => 'mimetex (Convert to Images)', 'raw' => 'Raw (Screen Reader)' ); @@ -178,17 +222,33 @@ sub texenginechanger { 'texengine', \%mathchoices); my $MathJax_start=&Apache::lontexconvert::MathJax_header(); + my $jsMath_start=&Apache::lontexconvert::jsMath_header(); my %lt=&Apache::lonlocal::texthash( 'headline' => 'Change how math is displayed', 'preftxt' => 'Preferred method to display math', 'change' => 'Save', 'exmpl' => 'Examples', 'mathjax' => 'MathJax:', - 'mathjaxinfo' => 'MathJax provides rendered equations whose source code can be extracted in TeX and MathML formats by right clicking the equation.', + 'jsmath' => 'jsMath:', 'tth' => 'tth (TeX to HTML):', 'mimetex' => 'mimetex (Convert to Images):', ); + my $jsMathWarning='

' + .'

' + .&mt("It looks like you don't have the TeX math fonts installed.") + .'
' + .'
' + .&mt('The jsMath example on this page may not look right without them. ' + .'The [_1]jsMath Home Page[_2] has information on how to download the ' + .'needed fonts. In the meantime, jsMath will do the best it can ' + .'with the fonts you have, but it may not be pretty and some equations ' + .'may not be rendered correctly.' + ,'' + ,'') + .'
' + .'

'; + $r->print(<$lt{'headline'}
@@ -205,22 +265,37 @@ $lt{'exmpl'}

$lt{'mathjax'}

- +

-$lt{'mathjaxinfo'} +MathJax provides rendered equations whose source code can be extracted in TeX and MathML formats by right clicking the equation. +

+ +

$lt{'jsmath'}

+

+$jsMath_start + +

$lt{'mimetex'}

- +

$lt{'tth'}

- +

ENDLSCREEN + if ($env{'environment.texengine'} ne 'jsMath') { + $r->print(''); + } } @@ -231,9 +306,6 @@ sub verify_and_change_texengine { # Screenname my $newtexengine = $env{'form.texengine'}; $newtexengine=~s/[^\-\w]//g; - if (lc($newtexengine) eq 'jsmath') { - $newtexengine = 'MathJax'; - } if ($newtexengine eq 'ttm') { &Apache::lonnet::appenv({'browser.mathml' => 1}); } else { @@ -282,7 +354,7 @@ sub rolesprefchanger { my $hotlist_n=$userenv{'recentrolesn'}; my ($checkedon,$checkedoff); if ($hotlist_flag) { - $checkedon = 'checked="checked"'; + $checkedon = 'checked="checked"'; } else { $checkedoff = 'checked="checked"'; } @@ -365,7 +437,7 @@ $options.' &Apache::lonhtmlcommon::row_closure(1). &Apache::lonhtmlcommon::end_pick_box().' '); - if ($roles_check_list) { + if ($roles_check_list) { $r->print('

'.&mt('Freeze Roles').'

'.&mt('The table below can be used to [_1]freeze[_2] '.$lc_role.'s in the Hotlist.','','').'
'. @@ -375,7 +447,7 @@ $options.'

'); } else { $r->print('
'. - &mt('Once the Hotlist contains recently visited '.$lc_role.'s you can return to this page to also set frozen roles.')); + &mt('Once the Hotlist contains recently visited '.$lc_role.'s, you can return to this page to also set frozen roles.')); } $r->print('
@@ -762,7 +834,7 @@ sub lockwarning { my $textbottom=&mt('Changing roles or logging out may result in data corruption.'); my ($num,%which)=&Apache::lonnet::get_locks(); my $which=''; - foreach my $id (keys(%which)) { + foreach my $id (keys %which) { $which.='
  • '.$which{$id}.'
  • '; } my $change=&mt('Override'); @@ -1139,10 +1211,10 @@ sub colorschanger { foreach my $item (sort(keys(%colortypes))) { my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain); $chtable.=&Apache::loncommon::start_data_table_row(). - ''.$colortypes{$item}.''. - &Apache::loncommon::end_data_table_row()."\n"; + ''.$colortypes{$item}.''. + &Apache::loncommon::end_data_table_row()."\n"; } my $end_data_table = &Apache::loncommon::end_data_table(); my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition(); @@ -1154,7 +1226,6 @@ sub colorschanger { ' . $colorchooser . ' '); - $r->print(< @@ -1193,11 +1264,11 @@ sub verify_and_change_colors { ); my $message=''; - foreach my $item (keys(%colortypes)) { + foreach my $item (keys %colortypes) { my $color=$env{'form.'.$item}; - if (!($color =~ /^#/)) { - $color = '#' . $color; - } + if (!($color =~ /^#/)) { + $color = '#' . $color; + } my $entry='color.'.$function.'.'.$item; if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) { &Apache::lonnet::put('environment',{$entry => $color}); @@ -1236,12 +1307,6 @@ sub passwordchanger { $r->print(Apache::loncommon::start_page('Personal Data')); $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Password')); } - my ($blocked,$blocktext) = - &Apache::loncommon::blocking_status('passwd'); - if ($blocked) { - $r->print('

    '.$blocktext.'

    '); - return; - } if ((!defined($caller)) || ($caller eq 'preferences')) { $user = $env{'user.name'}; $domain = $env{'user.domain'}; @@ -1254,7 +1319,7 @@ sub passwordchanger { $r->print( '

    ' .&mt('Sorry, the URL you provided to complete the reset of your password was invalid. Either the token included in the URL has been deleted or the URL you provided was invalid. Please submit a [_1]new request[_2] for a password reset, and follow the link to the new URL included in the e-mail that will be sent to you, to allow you to enter a new password.' - ,'','') + ,'','') .'

    ' ); return; @@ -1275,9 +1340,9 @@ sub passwordchanger { } } else { $r->print( - '

    ' - .&mt('Sorry, the URL generated when you requested reset of' - .' your password contained incomplete information.') + '

    ' + .&mt('Sorry, the URL generated when you requested reset of' + .' your password contained incomplete information.') .'

    ' ); return; @@ -1298,9 +1363,9 @@ sub passwordchanger { return if ($currentauth !~ /^(unix|internal):/); # # Generate keys - my ($lkey_cpass ,$ukey_cpass ) = &Apache::loncommon::des_keys(); - my ($lkey_npass1,$ukey_npass1) = &Apache::loncommon::des_keys(); - my ($lkey_npass2,$ukey_npass2) = &Apache::loncommon::des_keys(); + my ($lkey_cpass ,$ukey_cpass ) = &des_keys(); + my ($lkey_npass1,$ukey_npass1) = &des_keys(); + my ($lkey_npass2,$ukey_npass2) = &des_keys(); # Store the keys in the log files my $lonhost = $r->dir_config('lonHostID'); my $logtoken=Apache::lonnet::reply('tmpput:' @@ -1470,12 +1535,6 @@ sub server_form { sub verify_and_change_password { my ($r,$caller,$mailtoken) = @_; my ($user,$domain,$homeserver); - my ($blocked,$blocktext) = - &Apache::loncommon::blocking_status('passwd'); - if ($blocked) { - $r->print('

    '.$blocktext.'

    '); - return; - } if ($caller eq 'reset_by_email') { $user = $env{'form.uname'}; $domain = $env{'form.udom'}; @@ -1545,9 +1604,9 @@ ENDERROR } my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo); # - $currentpass = &Apache::loncommon::des_decrypt($ckey ,$currentpass); - $newpass1 = &Apache::loncommon::des_decrypt($n1key,$newpass1); - $newpass2 = &Apache::loncommon::des_decrypt($n2key,$newpass2); + $currentpass = &des_decrypt($ckey ,$currentpass); + $newpass1 = &des_decrypt($n1key,$newpass1); + $newpass2 = &des_decrypt($n2key,$newpass2); # if ($caller eq 'reset_by_email') { my %data = &Apache::lonnet::tmpget($mailtoken); @@ -1760,7 +1819,7 @@ sub verify_and_change_discussion { if (defined($env{'form.discmark'}) ) { my $newmark = $env{'form.newmark'}; if ($newmark eq 'ondisp') { - $message.=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: new posts will cease to be identified as "NEW" after display.')).'
    '; + $message.=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: new posts will be cease to be identified as "NEW" after display.')).'
    '; &Apache::lonnet::put('environment',{'discmarkread' => $newmark}); &Apache::lonnet::appenv({'environment.discmarkread' => $newmark}); } else { @@ -2066,25 +2125,6 @@ push(@{ $menu[0]->{items} }, { linktitle => 'Change your password.', }); } - if ($env{'environment.remote'} eq 'off') { -push(@{ $menu[1]->{items} }, { - linktext => 'Launch Remote Control', - url => '/adm/remote?url=/adm/preferences&action=launch', - permission => 'F', - #help => '', - icon => 'remotecontrol.png', - linktitle => 'Launch the remote control for LON-CAPA.', - }); - }else{ -push(@{ $menu[1]->{items} }, { - linktext => 'Collapse Remote Control', - url => '/adm/remote?url=/adm/preferences&action=collapse', - permission => 'F', - #help => '', - icon => 'remotecontrol.png', - linktitle => 'Collapse the remote control for LON-CAPA.', - }); - } if (&can_toggle_namelocking()) { push(@{ $menu[0]->{items} }, { @@ -2166,7 +2206,7 @@ sub handler { } else { $brlink ='/adm/preferences'; $brtxt = 'Set User Preferences'; - $brhelp = 'Prefs_About_Me,Prefs_Language,Prefs_Screen_Name_Nickname,Change_Colors,Change_Password,Prefs_Messages,Change_Discussion_Display'; + $brhelp = 'Prefs_About_Me,Prefs_Language,Prefs_Screen_Name_Nickname,Change_Colors,Change_Password,Prefs_Messages,Change_Discussion_Display'; } Apache::lonhtmlcommon::add_breadcrumb ({href => $brlink,