decrypt_headers.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Script provides form to decode encrypted header information.
  4. *
  5. * @copyright &copy; 2005-2006 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 functions
  17. * script needs OneTimePadDecrypt() (functions/strings.php)
  18. * and sqgetGlobalVar() (functions/global.php, loaded by strings.php)
  19. */
  20. include_once(SM_PATH.'functions/strings.php');
  21. /**
  22. * converts hex string to ip address
  23. * @param string $hex hexadecimal string created with squirrelmail ip2hex
  24. * function in delivery class.
  25. * @return string ip address
  26. * @since 1.5.1 and 1.4.5
  27. */
  28. function hex2ip($hex) {
  29. if (strlen($hex)==8) {
  30. $ret=hexdec(substr($hex,0,2)).'.'
  31. .hexdec(substr($hex,2,2)).'.'
  32. .hexdec(substr($hex,4,2)).'.'
  33. .hexdec(substr($hex,6,2));
  34. } elseif (strlen($hex)==32) {
  35. $ret=substr($hex,0,4).':'
  36. .substr($hex,4,4).':'
  37. .substr($hex,8,4).':'
  38. .substr($hex,12,4).':'
  39. .substr($hex,16,4).':'
  40. .substr($hex,20,4).':'
  41. .substr($hex,24,4).':'
  42. .substr($hex,28,4);
  43. } else {
  44. $ret=$hex;
  45. }
  46. return $ret;
  47. }
  48. /** create page headers */
  49. header('Content-Type: text/html');
  50. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"'."\n"
  51. .' "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">'
  52. ."\n<head>\n<meta name=\"robots\" content=\"noindex,nofollow\">\n"
  53. ."</head><body>";
  54. if (sqgetGlobalVar('submit',$submit,SQ_POST)) {
  55. if (! sqgetGlobalVar('secret',$secret,SQ_POST) ||
  56. empty($secret))
  57. echo "<p>You must enter encryption key.</p>\n";
  58. if (! sqgetGlobalVar('enc_string',$enc_string,SQ_POST) ||
  59. empty($enc_string))
  60. echo "<p>You must enter encrypted string.</p>\n";
  61. if (isset($enc_string) && ! base64_decode($enc_string)) {
  62. echo "<p>Encrypted string should be BASE64 encoded.<br />\n"
  63. ."Please enter all characters that are listed after header name.</p>\n";
  64. } elseif (isset($secret)) {
  65. $string=OneTimePadDecrypt($enc_string,base64_encode($secret));
  66. if (sqgetGlobalVar('ip_addr',$is_addr,SQ_POST)) {
  67. $string=hex2ip($string);
  68. }
  69. echo "<p>Decoded string: ".$string."</p>\n";
  70. }
  71. echo "<hr />";
  72. }
  73. ?>
  74. <form action="<?php echo $PHP_SELF ?>" method="post" >
  75. <p>
  76. Secret key: <input type="password" name="secret"><br />
  77. Encrypted string: <input type="text" name="enc_string"><br />
  78. Check, if it is an address string: <input type="checkbox" name="ip_addr" /><br />
  79. <button type="submit" name="submit" value="submit">Submit</button>
  80. </p>
  81. </form>
  82. </body></html>