fd5a219c8cd6b064981e79394353b98f63374933
[squirrelmail.git] / plugins / squirrelspell / modules / crypto_badkey.mod
1 <?php
2 /**
3 * crypto_badkey.mod
4 * ------------------
5 * Squirrelspell module
6 *
7 * Copyright (c) 1999-2005 The SquirrelMail Project Team
8 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 *
10 * This module tries to decrypt the user dictionary with a newly provided
11 * old password, or erases the file if everything else fails. :(
12 *
13 * @author Konstantin Riabitsev <icon@duke.edu>
14 * @version $Id$
15 * @package plugins
16 * @subpackage squirrelspell
17 */
18
19 /** get script name*/
20 sqgetGlobalVar('SCRIPT_NAME',$SCRIPT_NAME,SQ_SERVER);
21
22 if (! sqgetGlobalVar('delete_words',$delete_words,SQ_POST)){
23 $delete_words = 'OFF';
24 }
25 if (! sqgetGlobalVar('old_key',$old_key,SQ_POST)) {
26 $old_key=null;
27 }
28
29 if (! sqgetGlobalVar('old_setup',$temp,SQ_POST)) {
30 $old_setup = false;
31 } else {
32 $old_setup = true;
33 }
34
35 /**
36 * Displays information about deleted dictionary
37 * @since 1.5.1 (sqspell 0.5)
38 */
39 function sqspell_dict_deleted() {
40 global $SCRIPT_NAME;
41 /**
42 * See where we were called from -- pop-up window or options page
43 * and call whichever wrapper is appropriate.
44 * I agree, this is dirty.
45 * TODO: make it so it's not dirty.
46 * TODO: add upgrade handing
47 */
48 if (strstr($SCRIPT_NAME, 'sqspell_options')){
49 $msg='<p>' . _("Your personal dictionary was erased.") . '</p>';
50 sqspell_makePage(_("Dictionary Erased"), null, $msg);
51 } else {
52 /**
53 * The _("Your....") has to be on one line. Otherwise xgettext borks
54 * on getting the strings.
55 */
56 $msg = '<p>'
57 . _("Your personal dictionary was erased. Please close this window and click \"Check Spelling\" button again to start your spellcheck over.")
58 . '</p> '
59 . '<p align="center"><form>'
60 . '<input type="button" value=" '
61 . _("Close this Window") . ' " onclick="self.close()" />'
62 . '</form></p>';
63 sqspell_makeWindow(null, _("Dictionary Erased"), null, $msg);
64 }
65 exit;
66 }
67
68 /**
69 * Displays information about reencrypted dictionary
70 * @since 1.5.1 (sqspell 0.5)
71 */
72 function sqspell_dict_reencrypted() {
73 global $SCRIPT_NAME;
74 /**
75 * See where we are and call a necessary GUI-wrapper.
76 * Also dirty.
77 * TODO: Make this not dirty.
78 * TODO: add upgrade handing
79 */
80 if (strstr($SCRIPT_NAME, 'sqspell_options')){
81 $msg = '<p>'
82 . _("Your personal dictionary was re-encrypted successfully. Now return to the &quot;SpellChecker options&quot; menu and make your selection again." )
83 . '</p>';
84 sqspell_makePage(_("Successful re-encryption"), null, $msg);
85 } else {
86 $msg = '<p>'
87 . _("Your personal dictionary was re-encrypted successfully. Please close this window and click \"Check Spelling\" button again to start your spellcheck over.")
88 . '</p><form><p align="center"><input type="button" value=" '
89 . _("Close this Window") . ' "'
90 . 'onclick="self.close()" /></p></form>';
91 sqspell_makeWindow(null, _("Dictionary re-encrypted"), null, $msg);
92 }
93 exit;
94 }
95
96 // main code
97 if (! $old_setup && $delete_words=='ON') {
98 if (sqgetGlobalVar('dict_lang',$dict_lang,SQ_POST)) {
99 sqspell_deleteWords($dict_lang);
100 sqspell_dict_deleted();
101 }
102 } elseif ($delete_words=='ON'){
103 /**
104 * $delete_words is passed via the query_string. If it's set, then
105 * the user asked to delete the file. Erase the bastard and hope
106 * this never happens again.
107 */
108 sqspell_deleteWords_old();
109 sqspell_dict_deleted();
110 }
111
112 if (! $old_setup && $old_key) {
113 if (sqgetGlobalVar('dict_lang',$dict_lang,SQ_POST)) {
114 $words=sqspell_getLang($dict_lang);
115 sqspell_writeWords($words,$dict_lang);
116 sqspell_dict_reencrypted();
117 }
118 } elseif ($old_key){
119 /**
120 * User provided another key to try and decrypt the dictionary.
121 * Call sqspell_getWords. If this key fails, the function will
122 * handle it.
123 */
124 $words=sqspell_getWords_old();
125 /**
126 * It worked! Pinky, you're a genius!
127 * Write it back this time encrypted with a new key.
128 */
129 sqspell_writeWords_old($words);
130 sqspell_dict_reencrypted();
131 }
132
133 // TODO: handle broken calls
134
135 /**
136 * For Emacs weenies:
137 * Local variables:
138 * mode: php
139 * End:
140 * vim: syntax=php
141 */
142 ?>