';
+ }
+ my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
+ $r->print(<
+
+ function pclose() {
+ parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
+ "height=350,width=350,scrollbars=no,menubar=no");
+ parmwin.close();
+ }
+
+ $pjump_def
+
+ function psub() {
+ pclose();
+ if (document.parmform.pres_marker.value!='') {
+ if (document.parmform.pres_type.value!='') {
+ eval('document.server.'+
+ document.parmform.pres_marker.value+
+ '.value=document.parmform.pres_value.value;');
+ }
+ } else {
+ document.parmform.pres_value.value='';
+ document.parmform.pres_marker.value='';
+ }
+ }
+
+
+
+
+
+ENDCOL
+}
+
+sub verify_and_change_colors {
+ my $r = shift;
+# figure out colors
+ my $function='student';
+ if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
+ $function='coordinator';
+ }
+ if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
+ $function='admin';
+ }
+ if (($ENV{'request.role'}=~/^(au|ca)/) ||
+ ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
+ $function='author';
+ }
+ my $domain=&Apache::loncommon::determinedomain();
+ my %colortypes=('pgbg' => 'Page Background',
+ 'tabbg' => 'Header Background',
+ 'sidebg'=> 'Header Border',
+ 'font' => 'Font',
+ 'link' => 'Un-Visited Link',
+ 'vlink' => 'Visited Link',
+ 'alink' => 'Active Link');
+
+ my $message='';
+ foreach my $item (keys %colortypes) {
+ my $color=$ENV{'form.'.$item};
+ my $entry='color.'.$function.'.'.$item;
+ if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$ENV{'form.resetall'})) {
+ &Apache::lonnet::put('environment',{$entry => $color});
+ &Apache::lonnet::appenv('environment.'.$entry => $color);
+ $message.='Set '.$colortypes{$item}.' to '.$color.' ';
+ } else {
+ &Apache::lonnet::del('environment',[$entry]);
+ &Apache::lonnet::delenv('environment\.'.$entry);
+ $message.='Reset '.$colortypes{$item}.' ';
+ }
+ }
+ $r->print(<
+$message
+
+ENDVCCOL
+}
+
+######################################################
+# password handler subroutines #
+######################################################
+sub passwordchanger {
+ # This function is a bit of a mess....
+ # Passwords are encrypted using londes.js (DES encryption)
+ my $r = shift;
+ my $errormessage = shift;
+ $errormessage = ($errormessage || '');
+ my $user = $ENV{'user.name'};
+ my $domain = $ENV{'user.domain'};
+ my $homeserver = $ENV{'user.home'};
+ my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
+ # Check for authentication types that allow changing of the password.
+ return if ($currentauth !~ /^(unix|internal):/);
+ #
+ # Generate 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:'
+ .$ukey_cpass . $lkey_cpass .'&'
+ .$ukey_npass1 . $lkey_npass1.'&'
+ .$ukey_npass2 . $lkey_npass2,
+ $lonhost);
+ # Hexify the keys for output as javascript variables
+ $ukey_cpass = hex($ukey_cpass);
+ $lkey_cpass = hex($lkey_cpass);
+ $ukey_npass1= hex($ukey_npass1);
+ $lkey_npass1= hex($lkey_npass1);
+ $ukey_npass2= hex($ukey_npass2);
+ $lkey_npass2= hex($lkey_npass2);
+ # Output javascript to deal with passwords
+ # Output DES javascript
+ $r->print("");
+ {
+ my $include = $r->dir_config('lonIncludes');
+ my $jsh=Apache::File->new($include."/londes.js");
+ $r->print(<$jsh>);
+ }
+ $r->print(<
+
+ function send() {
+ uextkey=this.document.client.elements.ukey_cpass.value;
+ lextkey=this.document.client.elements.lkey_cpass.value;
+ initkeys();
+
+ this.document.server.elements.currentpass.value
+ =crypted(this.document.client.elements.currentpass.value);
+
+ uextkey=this.document.client.elements.ukey_npass1.value;
+ lextkey=this.document.client.elements.lkey_npass1.value;
+ initkeys();
+ this.document.server.elements.newpass_1.value
+ =crypted(this.document.client.elements.newpass_1.value);
+
+ uextkey=this.document.client.elements.ukey_npass2.value;
+ lextkey=this.document.client.elements.lkey_npass2.value;
+ initkeys();
+ this.document.server.elements.newpass_2.value
+ =crypted(this.document.client.elements.newpass_2.value);
+
+ this.document.server.submit();
+ }
+
+
+$errormessage
+
+
+
+
+
+
+
+
+ENDFORM
+ #
+ return;
+}
+
+sub verify_and_change_password {
+ my $r = shift;
+ my $user = $ENV{'user.name'};
+ my $domain = $ENV{'user.domain'};
+ my $homeserver = $ENV{'user.home'};
+ my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
+ # Check for authentication types that allow changing of the password.
+ return if ($currentauth !~ /^(unix|internal):/);
+ #
+ $r->print(<
+
+LON-CAPA Preferences: Change password for $user
+
+ENDHEADER
+ #
+ my $currentpass = $ENV{'form.currentpass'};
+ my $newpass1 = $ENV{'form.newpass_1'};
+ my $newpass2 = $ENV{'form.newpass_2'};
+ my $logtoken = $ENV{'form.logtoken'};
+ # Check for empty data
+ unless (defined($currentpass) &&
+ defined($newpass1) &&
+ defined($newpass2) ){
+ &passwordchanger($r,"
\nERROR".
+ "Password data was blank.\n
");
+ return;
+ }
+ # Get the keys
+ my $lonhost = $r->dir_config('lonHostID');
+ my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
+ if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
+ # I do not a have a better idea about how to handle this
+ $r->print(<
+ERROR: Unable to retrieve stored token for
+password decryption. Please log out and try again.
+
+ENDERROR
+ # Probably should log an error here
+ return;
+ }
+ my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
+ #
+ $currentpass = &des_decrypt($ckey ,$currentpass);
+ $newpass1 = &des_decrypt($n1key,$newpass1);
+ $newpass2 = &des_decrypt($n2key,$newpass2);
+ #
+ if ($newpass1 ne $newpass2) {
+ &passwordchanger($r,
+ 'ERROR:'.
+ 'The new passwords you entered do not match. '.
+ 'Please try again.');
+ return;
+ }
+ if (length($newpass1) < 7) {
+ &passwordchanger($r,
+ 'ERROR:'.
+ 'Passwords must be a minimum of 7 characters long. '.
+ 'Please try again.');
+ return;
+ }
+ #
+ # Check for bad characters
+ my $badpassword = 0;
+ foreach (split(//,$newpass1)) {
+ $badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
+ }
+ if ($badpassword) {
+ # I can't figure out how to enter bad characters on my browser.
+ &passwordchanger($r,<ERROR:
+The password you entered contained illegal characters.
+Valid characters are: space and
+
+ENDERROR
+ }
+ #
+ # Change the password (finally)
+ my $result = &Apache::lonnet::changepass
+ ($user,$domain,$currentpass,$newpass1,$homeserver);
+ # Inform the user the password has (not?) been changed
+ if ($result =~ /^ok$/) {
+ $r->print(<<"ENDTEXT");
+