decrypt_headers.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Script provides form to decode encrypted header information.
  4. *
  5. * @copyright 2005-2025 The SquirrelMail Project Team
  6. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  7. * @version $Id$
  8. * @package squirrelmail
  9. */
  10. /**
  11. * Set constant to path of your SquirrelMail install.
  12. * @ignore
  13. */
  14. define('SM_PATH','../');
  15. /**
  16. * include SquirrelMail string and generic functions
  17. * script needs OneTimePadDecrypt() (functions/strings.php)
  18. * and sqgetGlobalVar() (functions/global.php)
  19. */
  20. include_once(SM_PATH.'functions/global.php');
  21. include_once(SM_PATH.'functions/strings.php');
  22. /**
  23. * converts hex string to ip address
  24. * @param string $hex hexadecimal string created with squirrelmail ip2hex
  25. * function in delivery class.
  26. * @return string ip address
  27. * @since 1.5.1 and 1.4.5
  28. */
  29. function hex2ip($hex) {
  30. if (strlen($hex)==8) {
  31. $ret=hexdec(substr($hex,0,2)).'.'
  32. .hexdec(substr($hex,2,2)).'.'
  33. .hexdec(substr($hex,4,2)).'.'
  34. .hexdec(substr($hex,6,2));
  35. } elseif (strlen($hex)==32) {
  36. $ret=substr($hex,0,4).':'
  37. .substr($hex,4,4).':'
  38. .substr($hex,8,4).':'
  39. .substr($hex,12,4).':'
  40. .substr($hex,16,4).':'
  41. .substr($hex,20,4).':'
  42. .substr($hex,24,4).':'
  43. .substr($hex,28,4);
  44. } else {
  45. $ret=$hex;
  46. }
  47. return $ret;
  48. }
  49. /** create page headers */
  50. header('Content-Type: text/html');
  51. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"'."\n"
  52. .' "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">'
  53. ."\n<head>\n<meta name=\"robots\" content=\"noindex,nofollow\">\n"
  54. ."</head><body>";
  55. if (sqgetGlobalVar('submit',$submit,SQ_POST)) {
  56. $continue = TRUE;
  57. if (! sqgetGlobalVar('secret',$secret,SQ_POST) ||
  58. empty($secret)) {
  59. $continue = FALSE;
  60. echo "<p>You must enter an encryption key.</p>\n";
  61. }
  62. if (! sqgetGlobalVar('enc_string',$enc_string,SQ_POST) ||
  63. empty($enc_string)) {
  64. $continue = FALSE;
  65. echo "<p>You must enter an encrypted string.</p>\n";
  66. }
  67. if ($continue) {
  68. if (isset($enc_string) && ! base64_decode($enc_string)) {
  69. echo "<p>Encrypted string should be BASE64 encoded.<br />\n"
  70. ."Please enter all characters that are listed after header name.</p>\n";
  71. } elseif (isset($secret)) {
  72. $string=OneTimePadDecrypt($enc_string,base64_encode($secret));
  73. if (sqgetGlobalVar('ip_addr',$is_addr,SQ_POST)) {
  74. $string=hex2ip($string);
  75. }
  76. echo "<p>Decoded string: ".htmlspecialchars($string)."</p>\n";
  77. }
  78. }
  79. echo "<hr />";
  80. }
  81. ?>
  82. <form action="" method="post">
  83. <p>
  84. Secret key: <input type="password" name="secret"><br />
  85. Encrypted string: <input type="text" name="enc_string"><br />
  86. <label for="ip_addr">Check here if you are decoding an address string (FromHash/ProxyHash): </label><input type="checkbox" name="ip_addr" id="ip_addr" /><br />
  87. <button type="submit" name="submit" value="submit">Submit</button>
  88. </p>
  89. </form>
  90. </body></html>