1: # The LearningOnline Network
2: # Preferences
3: #
4: # $Id: lonpreferences.pm,v 1.51 2004/12/22 11:58:32 foxr 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: # This package uses the "londes.js" javascript code.
29: #
30: # TODOs that have to be completed:
31: # interface with lonnet to change the password
32:
33: package Apache::lonpreferences;
34:
35: use strict;
36: use Apache::Constants qw(:common);
37: use Apache::File;
38: use Crypt::DES;
39: use DynaLoader; # for Crypt::DES version
40: use Apache::loncommon();
41: use Apache::lonhtmlcommon();
42: use Apache::lonlocal;
43:
44: #
45: # Write lonnet::passwd to do the call below.
46: # Use:
47: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
48: #
49: ##################################################
50: # password associated functions #
51: ##################################################
52: sub des_keys {
53: # Make a new key for DES encryption.
54: # Each key has two parts which are returned separately.
55: # Please note: Each key must be passed through the &hex function
56: # before it is output to the web browser. The hex versions cannot
57: # be used to decrypt.
58: my @hexstr=('0','1','2','3','4','5','6','7',
59: '8','9','a','b','c','d','e','f');
60: my $lkey='';
61: for (0..7) {
62: $lkey.=$hexstr[rand(15)];
63: }
64: my $ukey='';
65: for (0..7) {
66: $ukey.=$hexstr[rand(15)];
67: }
68: return ($lkey,$ukey);
69: }
70:
71: sub des_decrypt {
72: my ($key,$cyphertext) = @_;
73: my $keybin=pack("H16",$key);
74: my $cypher;
75: if ($Crypt::DES::VERSION>=2.03) {
76: $cypher=new Crypt::DES $keybin;
77: } else {
78: $cypher=new DES $keybin;
79: }
80: my $plaintext=
81: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
82: $plaintext.=
83: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
84: $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
85: return $plaintext;
86: }
87:
88: ################################################################
89: # Handler subroutines #
90: ################################################################
91:
92: ################################################################
93: # Language Change Subroutines #
94: ################################################################
95:
96: sub wysiwygchanger {
97: my $r = shift;
98: my %userenv = &Apache::lonnet::get
99: ('environment',['wysiwygeditor']);
100: my $offselect='';
101: my $onselect='checked="1"';
102: if ($userenv{'wysiwygeditor'}) {
103: $onselect='';
104: $offselect='checked="1"';
105: }
106: my $switchoff=&mt('Disable WYSIWYG editor');
107: my $switchon=&mt('Enable WYSIWYG editor');
108: $r->print(<<ENDLSCREEN);
109: <form name="server" action="/adm/preferences" method="post">
110: <input type="hidden" name="action" value="set_wysiwyg" />
111: <br />
112: <input type="radio" name="wysiwyg" value="off" $onselect /> $switchoff<br />
113: <input type="radio" name="wysiwyg" value="on" $offselect /> $switchon
114: ENDLSCREEN
115: $r->print('<br /><input type="submit" value="'.&mt('Change').'" />');
116: }
117:
118:
119: sub verify_and_change_wysiwyg {
120: my $r = shift;
121: my $newsetting=$ENV{'form.wysiwyg'};
122: &Apache::lonnet::put('environment',{'wysiwygeditor' => $newsetting});
123: &Apache::lonnet::appenv('environment.wysiwygeditor' => $newsetting);
124: $r->print('<p>'.&mt('Setting WYSIWYG editor to:').' '.&mt($newsetting).'</p>');
125: }
126:
127: ################################################################
128: # Language Change Subroutines #
129: ################################################################
130: sub languagechanger {
131: my $r = shift;
132: my $user = $ENV{'user.name'};
133: my $domain = $ENV{'user.domain'};
134: my %userenv = &Apache::lonnet::get
135: ('environment',['languages']);
136: my $language=$userenv{'languages'};
137:
138: my $pref=&mt('Preferred language');
139: my %langchoices=('' => 'No language preference');
140: foreach (&Apache::loncommon::languageids()) {
141: if (&Apache::loncommon::supportedlanguagecode($_)) {
142: $langchoices{&Apache::loncommon::supportedlanguagecode($_)}
143: = &Apache::loncommon::plainlanguagedescription($_);
144: }
145: }
146: my $selectionbox=&Apache::loncommon::select_form($language,'language',
147: %langchoices);
148: $r->print(<<ENDLSCREEN);
149: <form name="server" action="/adm/preferences" method="post">
150: <input type="hidden" name="action" value="verify_and_change_languages" />
151: <br />$pref: $selectionbox
152: ENDLSCREEN
153: $r->print('<br /><input type="submit" value="'.&mt('Change').'" />');
154: }
155:
156:
157: sub verify_and_change_languages {
158: my $r = shift;
159: my $user = $ENV{'user.name'};
160: my $domain = $ENV{'user.domain'};
161: # Screenname
162: my $newlanguage = $ENV{'form.language'};
163: $newlanguage=~s/[^\-\w]//g;
164: my $message='';
165: if ($newlanguage) {
166: &Apache::lonnet::put('environment',{'languages' => $newlanguage});
167: &Apache::lonnet::appenv('environment.languages' => $newlanguage);
168: $message='Set new preferred languages to '.$newlanguage;
169: } else {
170: &Apache::lonnet::del('environment',['languages']);
171: &Apache::lonnet::delenv('environment\.languages');
172: $message='Reset preferred language';
173: }
174: $r->print(<<ENDVCSCREEN);
175: </p>
176: $message
177: ENDVCSCREEN
178: }
179:
180: ################################################################
181: # Roles Page Preference Change Subroutines #
182: ################################################################
183: sub rolesprefchanger {
184: my $r = shift;
185: my $user = $ENV{'user.name'};
186: my $domain = $ENV{'user.domain'};
187: my %userenv = &Apache::lonnet::get
188: ('environment',['recentroles','recentrolesn']);
189: my $hotlist_flag=$userenv{'recentroles'};
190: my $hotlist_n=$userenv{'recentrolesn'};
191: my $checked;
192: if ($hotlist_flag) {
193: $checked = 'checked="checked"';
194: }
195:
196: if (!$hotlist_n) { $hotlist_n=3; }
197: my $options;
198: for (my $i=1; $i<10; $i++) {
199: my $select;
200: if ($hotlist_n == $i) { $select = 'selected="selected"'; }
201: $options .= "<option $select>$i</option>\n";
202: }
203:
204: $r->print(<<ENDSCREEN);
205: <p>Some LON-CAPA users have a long list of roles. The Recent Roles Hotlist
206: feature keeps track of the last N roles which have been
207: visited and places a table of these at the top of the roles page.
208: People with very few roles should leave this feature disabled.
209: </p>
210:
211: <form name="server" action="/adm/preferences" method="post">
212: <input type="hidden" name="action" value="verify_and_change_rolespref" />
213: <br />Enable Recent Roles Hotlist:
214: <input type="checkbox" $checked name="recentroles" value="true" />
215: <br />Number of roles in Hotlist:
216: <select name="recentrolesn" size="1">
217: $options
218: </select>
219: <br />
220: <input type="submit" value="Change" />
221: </form>
222: ENDSCREEN
223: }
224:
225: sub verify_and_change_rolespref {
226: my $r = shift;
227: my $user = $ENV{'user.name'};
228: my $domain = $ENV{'user.domain'};
229: # Recent Roles Hotlist Flag
230: my $hotlist_flag = $ENV{'form.recentroles'};
231: my $hotlist_n = $ENV{'form.recentrolesn'};
232: my $message='';
233: if ($hotlist_flag) {
234: &Apache::lonnet::put('environment',{'recentroles' => $hotlist_flag});
235: &Apache::lonnet::appenv('environment.recentroles' => $hotlist_flag);
236: $message='Recent Roles Hotlist is Enabled';
237: } else {
238: &Apache::lonnet::del('environment',['recentroles']);
239: &Apache::lonnet::delenv('environment\.recentroles');
240: $message='Recent Roles Hotlist is Disabled';
241: }
242: if ($hotlist_n) {
243: &Apache::lonnet::put('environment',{'recentrolesn' => $hotlist_n});
244: &Apache::lonnet::appenv('environment.recentrolesn' => $hotlist_n);
245: if ($hotlist_flag) {
246: $message.="<br />Display $hotlist_n Most Recent Roles\n";
247: }
248: }
249:
250: $r->print(<<ENDRPSCREEN);
251: </p>
252: $message
253: ENDRPSCREEN
254: }
255:
256:
257:
258: ################################################################
259: # Anonymous Discussion Name Change Subroutines #
260: ################################################################
261: sub screennamechanger {
262: my $r = shift;
263: my $user = $ENV{'user.name'};
264: my $domain = $ENV{'user.domain'};
265: my %userenv = &Apache::lonnet::get
266: ('environment',['screenname','nickname']);
267: my $screenname=$userenv{'screenname'};
268: my $nickname=$userenv{'nickname'};
269: $r->print(<<ENDSCREEN);
270: <form name="server" action="/adm/preferences" method="post">
271: <input type="hidden" name="action" value="verify_and_change_screenname" />
272: <br />New screenname (shown if you post anonymously):
273: <input type="text" size="20" value="$screenname" name="screenname" />
274: <br />New nickname (shown if you post non-anonymously):
275: <input type="text" size="20" value="$nickname" name="nickname" />
276: <input type="submit" value="Change" />
277: </form>
278: ENDSCREEN
279: }
280:
281: sub verify_and_change_screenname {
282: my $r = shift;
283: my $user = $ENV{'user.name'};
284: my $domain = $ENV{'user.domain'};
285: # Screenname
286: my $newscreen = $ENV{'form.screenname'};
287: $newscreen=~s/[^ \w]//g;
288: my $message='';
289: if ($newscreen) {
290: &Apache::lonnet::put('environment',{'screenname' => $newscreen});
291: &Apache::lonnet::appenv('environment.screenname' => $newscreen);
292: $message='Set new screenname to '.$newscreen;
293: } else {
294: &Apache::lonnet::del('environment',['screenname']);
295: &Apache::lonnet::delenv('environment\.screenname');
296: $message='Reset screenname';
297: }
298: # Nickname
299: $message.='<br />';
300: $newscreen = $ENV{'form.nickname'};
301: $newscreen=~s/[^ \w]//g;
302: if ($newscreen) {
303: &Apache::lonnet::put('environment',{'nickname' => $newscreen});
304: &Apache::lonnet::appenv('environment.nickname' => $newscreen);
305: $message.='Set new nickname to '.$newscreen;
306: } else {
307: &Apache::lonnet::del('environment',['nickname']);
308: &Apache::lonnet::delenv('environment\.nickname');
309: $message.='Reset nickname';
310: }
311:
312: $r->print(<<ENDVCSCREEN);
313: </p>
314: $message
315: ENDVCSCREEN
316: }
317:
318: ################################################################
319: # Message Forward #
320: ################################################################
321:
322: sub msgforwardchanger {
323: my $r = shift;
324: my $user = $ENV{'user.name'};
325: my $domain = $ENV{'user.domain'};
326: my %userenv = &Apache::lonnet::get('environment',['msgforward','notification','critnotification']);
327: my $msgforward=$userenv{'msgforward'};
328: my $notification=$userenv{'notification'};
329: my $critnotification=$userenv{'critnotification'};
330: my $forwardingHelp = Apache::loncommon::help_open_topic("Prefs_Forwarding",
331: "What are forwarding ".
332: "and notification ".
333: "addresses");
334: my $criticalMessageHelp = Apache::loncommon::help_open_topic("Course_Critical_Message",
335: "What are critical messages");
336:
337: $r->print(<<ENDMSG);
338: $forwardingHelp <br />
339: <form name="server" action="/adm/preferences" method="post">
340: <input type="hidden" name="action" value="verify_and_change_msgforward" />
341: New Forwarding Address(es) (<tt>user:domain,user:domain,...</tt>):
342: <input type="text" size="40" value="$msgforward" name="msgforward" /><hr />
343: New Message Notification Email Address(es) (<tt>joe\@doe.com,jane\@doe.edu,...</tt>):
344: <input type="text" size="40" value="$notification" name="notification" /><hr />
345: New Critical Message Notification Email Address(es) (<tt>joe\@doe.com,jane\@doe.edu,...</tt>):
346: <input type="text" size="40" value="$critnotification" name="critnotification" />$criticalMessageHelp<hr />
347: <input type="submit" value="Change" />
348: </form>
349: ENDMSG
350: }
351:
352: sub verify_and_change_msgforward {
353: my $r = shift;
354: my $user = $ENV{'user.name'};
355: my $domain = $ENV{'user.domain'};
356: my $newscreen = '';
357: my $message='';
358: foreach (split(/\,/,$ENV{'form.msgforward'})) {
359: my ($msuser,$msdomain)=split(/[\@\:]/,$_);
360: $msuser=~s/\W//g;
361: $msdomain=~s/\W//g;
362: if (($msuser) && ($msdomain)) {
363: if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') {
364: $newscreen.=$msuser.':'.$msdomain.',';
365: } else {
366: $message.='No such user: '.$msuser.':'.$msdomain.'<br>';
367: }
368: }
369: }
370: $newscreen=~s/\,$//;
371: if ($newscreen) {
372: &Apache::lonnet::put('environment',{'msgforward' => $newscreen});
373: &Apache::lonnet::appenv('environment.msgforward' => $newscreen);
374: $message.='Set new message forwarding to '.$newscreen.'<br />';
375: } else {
376: &Apache::lonnet::del('environment',['msgforward']);
377: &Apache::lonnet::delenv('environment\.msgforward');
378: $message.='Reset message forwarding<br />';
379: }
380: my $notification=$ENV{'form.notification'};
381: $notification=~s/\s//gs;
382: if ($notification) {
383: &Apache::lonnet::put('environment',{'notification' => $notification});
384: &Apache::lonnet::appenv('environment.notification' => $notification);
385: $message.='Set message notification address to '.$notification.'<br />';
386: } else {
387: &Apache::lonnet::del('environment',['notification']);
388: &Apache::lonnet::delenv('environment\.notification');
389: $message.='Reset message notification<br />';
390: }
391: my $critnotification=$ENV{'form.critnotification'};
392: $critnotification=~s/\s//gs;
393: if ($critnotification) {
394: &Apache::lonnet::put('environment',{'critnotification' => $critnotification});
395: &Apache::lonnet::appenv('environment.critnotification' => $critnotification);
396: $message.='Set critical message notification address to '.$critnotification;
397: } else {
398: &Apache::lonnet::del('environment',['critnotification']);
399: &Apache::lonnet::delenv('environment\.critnotification');
400: $message.='Reset critical message notification<br />';
401: }
402: $r->print(<<ENDVCMSG);
403: </p>
404: $message
405: ENDVCMSG
406: }
407:
408: ################################################################
409: # Colors #
410: ################################################################
411:
412: sub colorschanger {
413: my $r = shift;
414: # figure out colors
415: my $function='student';
416: if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
417: $function='coordinator';
418: }
419: if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
420: $function='admin';
421: }
422: if (($ENV{'request.role'}=~/^(au|ca)/) ||
423: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
424: $function='author';
425: }
426: my $domain=&Apache::loncommon::determinedomain();
427: my %colortypes=('pgbg' => 'Page Background',
428: 'tabbg' => 'Header Background',
429: 'sidebg'=> 'Header Border',
430: 'font' => 'Font',
431: 'link' => 'Un-Visited Link',
432: 'vlink' => 'Visited Link',
433: 'alink' => 'Active Link');
434: my $chtable='';
435: foreach my $item (sort(keys(%colortypes))) {
436: my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain);
437: $chtable.='<tr><td>'.$colortypes{$item}.'</td><td bgcolor="'.$curcol.
438: '"> </td><td><input name="'.$item.
439: '" size="10" value="'.$curcol.
440: '" /></td><td><a href="javascript:pjump('."'color_custom','".$colortypes{$item}.
441: "','".$curcol."','"
442: .$item."','parmform.pres','psub'".');">Select</a></td></tr>';
443: }
444: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
445: $r->print(<<ENDCOL);
446: <script>
447:
448: function pclose() {
449: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
450: "height=350,width=350,scrollbars=no,menubar=no");
451: parmwin.close();
452: }
453:
454: $pjump_def
455:
456: function psub() {
457: pclose();
458: if (document.parmform.pres_marker.value!='') {
459: if (document.parmform.pres_type.value!='') {
460: eval('document.server.'+
461: document.parmform.pres_marker.value+
462: '.value=document.parmform.pres_value.value;');
463: }
464: } else {
465: document.parmform.pres_value.value='';
466: document.parmform.pres_marker.value='';
467: }
468: }
469:
470:
471: </script>
472: <form name="parmform">
473: <input type="hidden" name="pres_marker" />
474: <input type="hidden" name="pres_type" />
475: <input type="hidden" name="pres_value" />
476: </form>
477: <form name="server" action="/adm/preferences" method="post">
478: <input type="hidden" name="action" value="verify_and_change_colors" />
479: <table border="2">
480: $chtable
481: </table>
482: <input type="submit" value="Change Custom Colors" />
483: <input type="submit" name="resetall" value="Reset All Colors to Default" />
484: </form>
485: ENDCOL
486: }
487:
488: sub verify_and_change_colors {
489: my $r = shift;
490: # figure out colors
491: my $function='student';
492: if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
493: $function='coordinator';
494: }
495: if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
496: $function='admin';
497: }
498: if (($ENV{'request.role'}=~/^(au|ca)/) ||
499: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
500: $function='author';
501: }
502: my $domain=&Apache::loncommon::determinedomain();
503: my %colortypes=('pgbg' => 'Page Background',
504: 'tabbg' => 'Header Background',
505: 'sidebg'=> 'Header Border',
506: 'font' => 'Font',
507: 'link' => 'Un-Visited Link',
508: 'vlink' => 'Visited Link',
509: 'alink' => 'Active Link');
510:
511: my $message='';
512: foreach my $item (keys %colortypes) {
513: my $color=$ENV{'form.'.$item};
514: my $entry='color.'.$function.'.'.$item;
515: if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$ENV{'form.resetall'})) {
516: &Apache::lonnet::put('environment',{$entry => $color});
517: &Apache::lonnet::appenv('environment.'.$entry => $color);
518: $message.='Set '.$colortypes{$item}.' to '.$color.'<br />';
519: } else {
520: &Apache::lonnet::del('environment',[$entry]);
521: &Apache::lonnet::delenv('environment\.'.$entry);
522: $message.='Reset '.$colortypes{$item}.'<br />';
523: }
524: }
525: $r->print(<<ENDVCCOL);
526: </p>
527: $message
528: <form name="client" action="/adm/preferences" method="post">
529: <input type="hidden" name="action" value="changecolors" />
530: </form>
531: ENDVCCOL
532: }
533:
534: ######################################################
535: # password handler subroutines #
536: ######################################################
537: sub passwordchanger {
538: # This function is a bit of a mess....
539: # Passwords are encrypted using londes.js (DES encryption)
540: my $r = shift;
541: my $errormessage = shift;
542: $errormessage = ($errormessage || '');
543: my $user = $ENV{'user.name'};
544: my $domain = $ENV{'user.domain'};
545: my $homeserver = $ENV{'user.home'};
546: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
547: # Check for authentication types that allow changing of the password.
548: return if ($currentauth !~ /^(unix|internal):/);
549: #
550: # Generate keys
551: my ($lkey_cpass ,$ukey_cpass ) = &des_keys();
552: my ($lkey_npass1,$ukey_npass1) = &des_keys();
553: my ($lkey_npass2,$ukey_npass2) = &des_keys();
554: # Store the keys in the log files
555: my $lonhost = $r->dir_config('lonHostID');
556: my $logtoken=Apache::lonnet::reply('tmpput:'
557: .$ukey_cpass . $lkey_cpass .'&'
558: .$ukey_npass1 . $lkey_npass1.'&'
559: .$ukey_npass2 . $lkey_npass2,
560: $lonhost);
561: # Hexify the keys for output as javascript variables
562: $ukey_cpass = hex($ukey_cpass);
563: $lkey_cpass = hex($lkey_cpass);
564: $ukey_npass1= hex($ukey_npass1);
565: $lkey_npass1= hex($lkey_npass1);
566: $ukey_npass2= hex($ukey_npass2);
567: $lkey_npass2= hex($lkey_npass2);
568: # Output javascript to deal with passwords
569: # Output DES javascript
570: $r->print("<html><head>");
571: {
572: my $include = $r->dir_config('lonIncludes');
573: my $jsh=Apache::File->new($include."/londes.js");
574: $r->print(<$jsh>);
575: }
576: $r->print(<<ENDFORM);
577: <script language="JavaScript">
578:
579: function send() {
580: uextkey=this.document.client.elements.ukey_cpass.value;
581: lextkey=this.document.client.elements.lkey_cpass.value;
582: initkeys();
583:
584: this.document.server.elements.currentpass.value
585: =crypted(this.document.client.elements.currentpass.value);
586:
587: uextkey=this.document.client.elements.ukey_npass1.value;
588: lextkey=this.document.client.elements.lkey_npass1.value;
589: initkeys();
590: this.document.server.elements.newpass_1.value
591: =crypted(this.document.client.elements.newpass_1.value);
592:
593: uextkey=this.document.client.elements.ukey_npass2.value;
594: lextkey=this.document.client.elements.lkey_npass2.value;
595: initkeys();
596: this.document.server.elements.newpass_2.value
597: =crypted(this.document.client.elements.newpass_2.value);
598:
599: this.document.server.submit();
600: }
601:
602: </script>
603: $errormessage
604:
605: <p>
606: <!-- We separate the forms into 'server' and 'client' in order to
607: ensure that unencrypted passwords will not be sent out by a
608: crappy browser -->
609:
610: <form name="server" action="/adm/preferences" method="post">
611: <input type="hidden" name="logtoken" value="$logtoken" />
612: <input type="hidden" name="action" value="verify_and_change_pass" />
613: <input type="hidden" name="currentpass" value="" />
614: <input type="hidden" name="newpass_1" value="" />
615: <input type="hidden" name="newpass_2" value="" />
616: </form>
617:
618: <form name="client" >
619: <table>
620: <tr><td align="right"> Current password: </td>
621: <td><input type="password" name="currentpass" size="10"/> </td></tr>
622: <tr><td align="right"> New password: </td>
623: <td><input type="password" name="newpass_1" size="10" /> </td></tr>
624: <tr><td align="right"> Confirm password: </td>
625: <td><input type="password" name="newpass_2" size="10" /> </td></tr>
626: <tr><td colspan="2" align="center">
627: <input type="button" value="Change Password" onClick="send();">
628: </table>
629: <input type="hidden" name="ukey_cpass" value="$ukey_cpass" />
630: <input type="hidden" name="lkey_cpass" value="$lkey_cpass" />
631: <input type="hidden" name="ukey_npass1" value="$ukey_npass1" />
632: <input type="hidden" name="lkey_npass1" value="$lkey_npass1" />
633: <input type="hidden" name="ukey_npass2" value="$ukey_npass2" />
634: <input type="hidden" name="lkey_npass2" value="$lkey_npass2" />
635: </form>
636: </p>
637: ENDFORM
638: #
639: return;
640: }
641:
642: sub verify_and_change_password {
643: my $r = shift;
644: my $user = $ENV{'user.name'};
645: my $domain = $ENV{'user.domain'};
646: my $homeserver = $ENV{'user.home'};
647: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
648: # Check for authentication types that allow changing of the password.
649: return if ($currentauth !~ /^(unix|internal):/);
650: #
651: $r->print(<<ENDHEADER);
652: <html>
653: <head>
654: <title>LON-CAPA Preferences: Change password for $user</title>
655: </head>
656: ENDHEADER
657: #
658: my $currentpass = $ENV{'form.currentpass'};
659: my $newpass1 = $ENV{'form.newpass_1'};
660: my $newpass2 = $ENV{'form.newpass_2'};
661: my $logtoken = $ENV{'form.logtoken'};
662: # Check for empty data
663: unless (defined($currentpass) &&
664: defined($newpass1) &&
665: defined($newpass2) ){
666: &passwordchanger($r,"<p>\n<font color='#ff0000'>ERROR</font>".
667: "Password data was blank.\n</p>");
668: return;
669: }
670: # Get the keys
671: my $lonhost = $r->dir_config('lonHostID');
672: my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
673: if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
674: # I do not a have a better idea about how to handle this
675: $r->print(<<ENDERROR);
676: <p>
677: <font color="#ff0000">ERROR:</font> Unable to retrieve stored token for
678: password decryption. Please log out and try again.
679: </p>
680: ENDERROR
681: # Probably should log an error here
682: return;
683: }
684: my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
685: #
686: $currentpass = &des_decrypt($ckey ,$currentpass);
687: $newpass1 = &des_decrypt($n1key,$newpass1);
688: $newpass2 = &des_decrypt($n2key,$newpass2);
689: #
690: if ($newpass1 ne $newpass2) {
691: &passwordchanger($r,
692: '<font color="#ff0000">ERROR:</font>'.
693: 'The new passwords you entered do not match. '.
694: 'Please try again.');
695: return;
696: }
697: if (length($newpass1) < 7) {
698: &passwordchanger($r,
699: '<font color="#ff0000">ERROR:</font>'.
700: 'Passwords must be a minimum of 7 characters long. '.
701: 'Please try again.');
702: return;
703: }
704: #
705: # Check for bad characters
706: my $badpassword = 0;
707: foreach (split(//,$newpass1)) {
708: $badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
709: }
710: if ($badpassword) {
711: # I can't figure out how to enter bad characters on my browser.
712: &passwordchanger($r,<<ENDERROR);
713: <font color="#ff0000">ERROR:</font>
714: The password you entered contained illegal characters.<br />
715: Valid characters are: space and <br />
716: <pre>
717: !"\#$%&\'()*+,-./0123456789:;<=>?\@
718: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
719: </pre>
720: ENDERROR
721: }
722: #
723: # Change the password (finally)
724: my $result = &Apache::lonnet::changepass
725: ($user,$domain,$currentpass,$newpass1,$homeserver);
726: # Inform the user the password has (not?) been changed
727: if ($result =~ /^ok$/) {
728: $r->print(<<"ENDTEXT");
729: <h2>The password for $user was successfully changed</h2>
730: ENDTEXT
731: } else {
732: # error error: run in circles, scream and shout
733: $r->print(<<ENDERROR);
734: <h2><font color="#ff0000">The password for $user was not changed</font></h2>
735: Please make sure your old password was entered correctly.
736: ENDERROR
737: }
738: return;
739: }
740:
741: ################################################################
742: # discussion display subroutines
743: ################################################################
744: sub discussionchanger {
745: my $r = shift;
746: my $user = $ENV{'user.name'};
747: my $domain = $ENV{'user.domain'};
748: my %userenv = &Apache::lonnet::get
749: ('environment',['discdisplay','discmarkread']);
750: my $discdisp = 'allposts';
751: my $discmark = 'onmark';
752:
753: if (defined($userenv{'discdisplay'})) {
754: unless ($userenv{'discdisplay'} eq '') {
755: $discdisp = $userenv{'discdisplay'};
756: }
757: }
758: if (defined($userenv{'discmarkread'})) {
759: unless ($userenv{'discdisplay'} eq '') {
760: $discmark = $userenv{'discmarkread'};
761: }
762: }
763:
764: my $newdisp = 'unread';
765: my $newmark = 'ondisp';
766:
767: my $function = &Apache::loncommon::get_users_function();
768: my $color = &Apache::loncommon::designparm($function.'.tabbg',
769: $ENV{'user.domain'});
770: my %lt = &Apache::lonlocal::texthash(
771: 'pref' => 'Display Preference',
772: 'curr' => 'Current setting ',
773: 'actn' => 'Action',
774: 'sdpf' => 'Set display preferences for discussion posts for both bulletin boards and individual resources in all your courses.',
775: 'prca' => 'Preferences can be set that determine',
776: 'whpo' => 'Which posts are displayed when you display a bulletin board or resource, and',
777: 'unwh' => 'Under what circumstances posts are identfied as "New"',
778: 'allposts' => 'All posts',
779: 'unread' => 'New posts only',
780: 'ondisp' => 'Once displayed',
781: 'onmark' => 'Once marked as read',
782: 'disa' => 'Posts displayed?',
783: 'npmr' => 'New posts cease to be identified as "New"?',
784: 'thde' => 'The preferences you set here can be overridden within each individual discussion.',
785: 'chgt' => 'Change to '
786: );
787: my $dispchange = $lt{'unread'};
788: my $markchange = $lt{'ondisp'};
789: my $currdisp = $lt{'allposts'};
790: my $currmark = $lt{'onmark'};
791:
792: if ($discdisp eq 'unread') {
793: $dispchange = $lt{'allposts'};
794: $currdisp = $lt{'unread'};
795: $newdisp = 'allposts';
796: }
797:
798: if ($discmark eq 'ondisp') {
799: $markchange = $lt{'onmark'};
800: $currmark = $lt{'ondisp'};
801: $newmark = 'onmark';
802: }
803:
804: $r->print(<<"END");
805: <form name="server" action="/adm/preferences" method="post">
806: <input type="hidden" name="action" value="verify_and_change_discussion" />
807: <br />
808: $lt{'sdpf'}<br/> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol>
809: <br />
810: <br />
811: <table border="0" cellpadding="0" cellspacing="0">
812: <tr>
813: <td width="100%" bgcolor="#000000">
814: <table width="100%" border="0" cellpadding="1" cellspacing="0">
815: <tr>
816: <td width="100%" bgcolor="#000000">
817: <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF">
818: <tr bgcolor="$color">
819: <td><b>$lt{'pref'}</b></td>
820: <td><b>$lt{'curr'}</b></td>
821: <td><b>$lt{'actn'}?</b></td>
822: </tr>
823: <tr bgcolor="#dddddd">
824: <td>$lt{'disa'}</td>
825: <td>$lt{$discdisp}</td>
826: <td><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" /> $lt{'chgt'} "$dispchange"</td>
827: </tr><tr bgcolor="#eeeeee">
828: <td>$lt{'npmr'}</td>
829: <td>$lt{$discmark}</td>
830: <td><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" /> $lt{'chgt'} "$markchange"</td>
831: </tr>
832: </table>
833: </td>
834: </tr>
835: </table>
836: </td>
837: </tr>
838: </table>
839: <br />
840: <br />
841: <input type="submit" name="sub" value="Store Changes" />
842: <br />
843: <br />
844: Note: $lt{'thde'}
845: </form>
846: END
847: }
848:
849: sub verify_and_change_discussion {
850: my $r = shift;
851: my $user = $ENV{'user.name'};
852: my $domain = $ENV{'user.domain'};
853: my $message='';
854: if (defined($ENV{'form.discdisp'}) ) {
855: my $newdisp = $ENV{'form.newdisp'};
856: if ($newdisp eq 'unread') {
857: $message .='In discussions: only new posts will be displayed.<br/>';
858: &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
859: &Apache::lonnet::appenv('environment.discdisplay' => $newdisp);
860: } else {
861: $message .= 'In discussions: all posts will be displayed.<br/>';
862: &Apache::lonnet::del('environment',['discdisplay']);
863: &Apache::lonnet::delenv('environment\.discdisplay');
864: }
865: }
866: if (defined($ENV{'form.discmark'}) ) {
867: my $newmark = $ENV{'form.newmark'};
868: if ($newmark eq 'ondisp') {
869: $message.='In discussions: new posts will be cease to be identified as "new" after display.<br/>';
870: &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
871: &Apache::lonnet::appenv('environment.discmarkread' => $newmark);
872: } else {
873: $message.='In discussions: posts will be identified as "new" until marked as read by the reader.<br/>';
874: &Apache::lonnet::del('environment',['discmarkread']);
875: &Apache::lonnet::delenv('environment\.discmarkread');
876: }
877: }
878: $r->print(<<ENDVCSCREEN);
879: </p>
880: $message
881: ENDVCSCREEN
882: }
883:
884: ######################################################
885: # other handler subroutines #
886: ######################################################
887:
888: ################################################################
889: # Main handler #
890: ################################################################
891: sub handler {
892: my $r = shift;
893: my $user = $ENV{'user.name'};
894: my $domain = $ENV{'user.domain'};
895: &Apache::loncommon::content_type($r,'text/html');
896: # Some pages contain DES keys and should not be cached.
897: &Apache::loncommon::no_cache($r);
898: $r->send_http_header;
899: return OK if $r->header_only;
900: #
901: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
902: ['action','wysiwyg','returnurl']);
903: #
904: &Apache::lonhtmlcommon::clear_breadcrumbs();
905: &Apache::lonhtmlcommon::add_breadcrumb
906: ({href => '/adm/preferences',
907: text => 'Set User Preferences'});
908:
909: my @Options;
910: # Determine current authentication method
911: my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
912: if ($currentauth =~ /^(unix|internal):/) {
913: push (@Options,({ action => 'changepass',
914: linktext => 'Change Password',
915: href => '/adm/preferences',
916: help => 'Change_Password',
917: subroutine => \&passwordchanger,
918: breadcrumb =>
919: { href => '/adm/preferences?action=changepass',
920: text => 'Change Password'},
921: },
922: { action => 'verify_and_change_pass',
923: subroutine => \&verify_and_change_password,
924: breadcrumb =>
925: { href =>'/adm/preferences?action=changepass',
926: text => 'Change Password'},
927: printmenu => 'yes',
928: }));
929: }
930: push (@Options,({ action => 'changescreenname',
931: linktext => 'Change Screen Name',
932: href => '/adm/preferences',
933: help => 'Prefs_Screen_Name_Nickname',
934: subroutine => \&screennamechanger,
935: breadcrumb =>
936: { href => '/adm/preferences?action=changescreenname',
937: text => 'Change Screen Name'},
938: },
939: { action => 'verify_and_change_screenname',
940: subroutine => \&verify_and_change_screenname,
941: breadcrumb =>
942: { href => '/adm/preferences?action=changescreenname',
943: text => 'Change Screen Name'},
944: printmenu => 'yes',
945: }));
946:
947: push (@Options,({ action => 'changemsgforward',
948: linktext => 'Change Message Forwarding and Notification Addresses',
949: href => '/adm/preferences',
950: help => 'Prefs_Forwarding',
951: breadcrumb =>
952: { href => '/adm/preferences?action=changemsgforward',
953: text => 'Change Message Forwarding'},
954: subroutine => \&msgforwardchanger,
955: },
956: { action => 'verify_and_change_msgforward',
957: breadcrumb =>
958: { href => '/adm/preferences?action=changemsgforward',
959: text => 'Change Message Forwarding'},
960: printmenu => 'yes',
961: subroutine => \&verify_and_change_msgforward }));
962: my $aboutmeaction=
963: '/adm/'.$ENV{'user.domain'}.'/'.$ENV{'user.name'}.'/aboutme';
964: push (@Options,{ action => 'none',
965: linktext =>
966: q{Edit the 'About Me' Personal Information Screen},
967: help => 'Prefs_About_Me',
968: href => $aboutmeaction});
969: push (@Options,({ action => 'changecolors',
970: linktext => 'Change Color Scheme',
971: href => '/adm/preferences',
972: help => 'Change_Colors',
973: breadcrumb =>
974: { href => '/adm/preferences?action=changecolors',
975: text => 'Change Colors'},
976: subroutine => \&colorschanger,
977: },
978: { action => 'verify_and_change_colors',
979: breadcrumb =>
980: { href => '/adm/preferences?action=changecolors',
981: text => 'Change Colors'},
982: printmenu => 'yes',
983: subroutine => \&verify_and_change_colors,
984: }));
985: push (@Options,({ action => 'changelanguages',
986: linktext => 'Change Language Preferences',
987: href => '/adm/preferences',
988: help => 'Prefs_Language',
989: breadcrumb=>
990: { href => '/adm/preferences?action=changelanguages',
991: text => 'Change Language'},
992: subroutine => \&languagechanger,
993: },
994: { action => 'verify_and_change_languages',
995: breadcrumb=>
996: {href => '/adm/preferences?action=changelanguages',
997: text => 'Change Language'},
998: printmenu => 'yes',
999: subroutine=>\&verify_and_change_languages, }
1000: ));
1001: push (@Options,({ action => 'changewysiwyg',
1002: linktext => 'Change WYSIWYG Editor Preferences',
1003: href => '/adm/preferences',
1004: breadcrumb =>
1005: { href => '/adm/preferences?action=changewysiwyg',
1006: text => 'Change WYSIWYG Preferences'},
1007: subroutine => \&wysiwygchanger,
1008: },
1009: { action => 'set_wysiwyg',
1010: breadcrumb =>
1011: { href => '/adm/preferences?action=changewysiwyg',
1012: text => 'Change WYSIWYG Preferences'},
1013: printmenu => 'yes',
1014: subroutine => \&verify_and_change_wysiwyg, }
1015: ));
1016: push (@Options,({ action => 'changediscussions',
1017: linktext => 'Change Discussion Display Preferences',
1018: href => '/adm/preferences',
1019: help => 'Change_Discussion_Display',
1020: breadcrumb =>
1021: { href => '/adm/preferences?action=changediscussions',
1022: text => 'Change Discussion Preferences'},
1023: subroutine => \&discussionchanger,
1024: },
1025: { action => 'verify_and_change_discussion',
1026: breadcrumb =>
1027: { href => '/adm/preferences?action=changediscussions',
1028: text => 'Change Discussion Preferences'},
1029: printmenu => 'yes',
1030: subroutine => \&verify_and_change_discussion, }
1031: ));
1032:
1033: push (@Options,({ action => 'changerolespref',
1034: linktext => 'Change Roles Page Preferences',
1035: href => '/adm/preferences',
1036: subroutine => \&rolesprefchanger,
1037: breadcrumb =>
1038: { href => '/adm/preferences?action=changerolespref',
1039: text => 'Change Roles Pref'},
1040: },
1041: { action => 'verify_and_change_rolespref',
1042: subroutine => \&verify_and_change_rolespref,
1043: breadcrumb =>
1044: { href => '/adm/preferences?action=changerolespref',
1045: text => 'Change Roles Preferences'},
1046: printmenu => 'yes',
1047: }));
1048:
1049:
1050: if ($ENV{'user.name'} =~ /^(albertel|fox|foxr|koretemey|korte|hallmat3|turtle)$/) {
1051: push (@Options,({ action => 'debugtoggle',
1052: printmenu => 'yes',
1053: subroutine => \&toggle_debug,
1054: }));
1055: }
1056: $r->print(<<ENDHEADER);
1057: <html>
1058: <head>
1059: <title>LON-CAPA Preferences</title>
1060: </head>
1061: ENDHEADER
1062: my $call = undef;
1063: my $help = undef;
1064: my $printmenu = 'yes';
1065: foreach my $option (@Options) {
1066: if ($option->{'action'} eq $ENV{'form.action'}) {
1067: $call = $option->{'subroutine'};
1068: $printmenu = $option->{'printmenu'};
1069: if (exists($option->{'breadcrumb'})) {
1070: &Apache::lonhtmlcommon::add_breadcrumb
1071: ($option->{'breadcrumb'});
1072: }
1073: $help=$option->{'help'};
1074: }
1075: }
1076: $r->print(&Apache::loncommon::bodytag('Change Preferences'));
1077: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1078: (undef,'Change Preferences',$help));
1079: if (defined($call)) {
1080: $call->($r);
1081: }
1082: if (($printmenu eq 'yes') && (!$ENV{'form.returnurl'})) {
1083: my $optionlist = '<table cellpadding="5">';
1084: if ($ENV{'user.name'} =~
1085: /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle)$/
1086: ) {
1087: push (@Options,({ action => 'debugtoggle',
1088: linktext => 'Toggle Debug Messages',
1089: text => 'Current Debug status is -'.
1090: $ENV{'user.debug'}.'-.',
1091: href => '/adm/preferences',
1092: printmenu => 'yes',
1093: subroutine => \&toggle_debug,
1094: }));
1095: }
1096: foreach my $option(@Options) {
1097: my $optiontext = '';
1098: if (exists($option->{'href'})) {
1099: $optiontext .=
1100: '<a href="'.$option->{'href'}.
1101: '?action='.$option->{'action'}.'">'.
1102: &mt($option->{'linktext'}).'</a>';
1103: }
1104: if (exists($option->{'text'})) {
1105: $optiontext .= ' '.&mt($option->{'text'});
1106: }
1107: if ($optiontext ne '') {
1108: $optiontext = '<font size="+1">'.$optiontext.'</font>';
1109: my $helplink = ' ';
1110: if (exists($option->{'help'})) {
1111: $helplink = &Apache::loncommon::help_open_topic
1112: ($option->{'help'});
1113: }
1114: $optionlist .= '<tr>'.
1115: '<td>'.$helplink.'</td>'.
1116: '<td>'.$optiontext.'</td>'.
1117: '</tr>';
1118: }
1119: }
1120: $optionlist .= '</table>';
1121: $r->print($optionlist);
1122: } elsif ($ENV{'form.returnurl'}) {
1123: $r->print('<br /><a href="'.$ENV{'form.returnurl'}.'"><font size="+1">'.
1124: &mt('Return').'</font></a>');
1125: }
1126: $r->print(<<ENDFOOTER);
1127: </body>
1128: </html>
1129: ENDFOOTER
1130: return OK;
1131: }
1132:
1133: sub toggle_debug {
1134: if ($ENV{'user.debug'}) {
1135: &Apache::lonnet::delenv('user\.debug');
1136: } else {
1137: &Apache::lonnet::appenv('user.debug' => 1);
1138: }
1139: }
1140:
1141: 1;
1142: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>