crypto_badkey.mod 4.0 KB

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