- // decrypt
- $words=sqspell_crypto("decrypt", $clear_key, $words);
- if ($words=="PANIC"){
- // AAAAAAAAAAAH!!!!! OK, ok, breathe!
- // Let's hope the decryption failed because the user changed his
- // password. Bring up the option to key in the old password
- // or wipe the file and start over if everything else fails.
- $msg="<p>
- <strong>ATTENTION:</strong><br>
- SquirrelSpell was unable to decrypt your personal dictionary. This is most likely
- due to the fact that you have changed your mailbox password. In order to proceed,
- you will have to supply your old password so that SquirrelSpell can decrypt your
- personal dictionary. It will be re-encrypted with your new password after this.<br>
- If you haven't encrypted your dictionary, then it got mangled and is no longer
- valid. You will have to delete it and start anew. This is also true if you don't
- remember your old password -- without it, the encrypted data is no longer
- accessible.</p>
- <blockquote>
- <form method=\"post\" onsubmit=\"return AYS()\">
- <input type=\"hidden\" name=\"MOD\" value=\"crypto_badkey\">
- <p><input type=\"checkbox\" name=\"delete_words\" value=\"ON\"> Delete my dictionary and start a new one<br>
- Decrypt my dictionary with my old password: <input name=\"old_key\" size=\"10\"></p>
- </blockquote>
- <p align=\"center\"><input type=\"submit\" value=\"Proceed >>\"></p>
- </form>
- ";
- // See if this happened in the pop-up window or when accessing
- // the SpellChecker options page.
- global $SCRIPT_NAME;
- if (strstr($SCRIPT_NAME, "sqspell_options"))
- sqspell_makePage("Error Decrypting Dictionary", "decrypt_error.js", $msg);
- else sqspell_makeWindow(null, "Error Decrypting Dictionary", "decrypt_error.js", $msg);
- exit;
+ /**
+ * Check if this is an encrypted file by looking for
+ * the string "# SquirrelSpell" in it (the crypto
+ * function does that).
+ */
+ if ($words && !strstr($words, "# SquirrelSpell")){
+ /**
+ * This file is encrypted or mangled. Try to decrypt it.
+ * If fails, complain loudly.
+ *
+ * $old_key would be a value submitted by one of the modules with
+ * the user's old mailbox password. I admin, this is rather dirty,
+ * but efficient. ;)
+ */
+ global $key, $onetimepad, $old_key;
+ if ($old_key) {
+ $clear_key=$old_key;
+ } else {
+ /**
+ * Get user's password (the key).
+ */
+ $clear_key = OneTimePadDecrypt($key, $onetimepad);
+ }
+ /**
+ * Invoke the decryption routines.
+ */
+ $words=sqspell_crypto("decrypt", $clear_key, $words);
+ /**
+ * See if decryption failed.
+ */
+ if ($words=="PANIC"){
+ /**
+ * AAAAAAAAAAAH!!!!! OK, ok, breathe!
+ * Let's hope the decryption failed because the user changed his
+ * password. Bring up the option to key in the old password
+ * or wipe the file and start over if everything else fails.
+ *
+ * The _("SquirrelSpell...) line has to be on one line, otherwise
+ * gettext will bork. ;(
+ */
+ $msg = html_tag( 'p', "\n" .
+ '<strong>' . _("ATTENTION:") . '</strong><br>'
+ . _("SquirrelSpell was unable to decrypt your personal dictionary. This is most likely due to the fact that you have changed your mailbox password. In order to proceed, you will have to supply your old password so that SquirrelSpell can decrypt your personal dictionary. It will be re-encrypted with your new password after this.<br>If you haven't encrypted your dictionary, then it got mangled and is no longer valid. You will have to delete it and start anew. This is also true if you don't remember your old password -- without it, the encrypted data is no longer accessible.") ,
+ 'left' ) . "\n"
+ . '<blockquote>' . "\n"
+ . '<form method="post" onsubmit="return AYS()">' . "\n"
+ . '<input type="hidden" name="MOD" value="crypto_badkey">' . "\n"
+ . html_tag( 'p', "\n" .
+ '<input type="checkbox" name="delete_words" value="ON">'
+ . _("Delete my dictionary and start a new one") . '<br>'
+ . _("Decrypt my dictionary with my old password:")
+ . '<input name="old_key" size=\"10\">' ,
+ 'left' ) . "\n"
+ . '</blockquote>' . "\n"
+ . html_tag( 'p', "\n" .
+ '<input type="submit" value="'
+ . _("Proceed") . ' >>">' ,
+ 'center' ) . "\n"
+ . '</form>' . "\n";
+ /**
+ * Add some string vars so they can be i18n'd.
+ */
+ $msg .= "<script type='text/javascript'><!--\n"
+ . "var ui_choice = \"" . _("You must make a choice") ."\";\n"
+ . "var ui_candel = \"" . _("You can either delete your dictionary or type in the old password. Not both.") . "\";\n"
+ . "var ui_willdel = \"" . _("This will delete your personal dictionary file. Proceed?") . "\";\n"
+ . "//--></script>\n";
+ /**
+ * See if this happened in the pop-up window or when accessing
+ * the SpellChecker options page.
+ * This is a dirty solution, I agree. TODO: make this prettier.
+ */
+ global $SCRIPT_NAME;
+ if (strstr($SCRIPT_NAME, "sqspell_options")){
+ sqspell_makePage(_("Error Decrypting Dictionary"),
+ "decrypt_error.js", $msg);
+ } else {
+ sqspell_makeWindow(null, _("Error Decrypting Dictionary"),
+ "decrypt_error.js", $msg);
+ }
+ exit;
+ } else {
+ /**
+ * OK! Phew. Set the encryption flag to true so we can later on
+ * encrypt it again before saving to HDD.
+ */
+ $SQSPELL_CRYPTO=true;
+ }