Encoded From headers now properly quoted (#2830141). A better fix might be to re...
[squirrelmail.git] / contrib / decrypt_headers.php
index 48c39a18f159e7bf102269ed9ee0284e1b59b13f..2fec8df750be760566416fba12271da8c9f77e5b 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * Script provides form to decode encrypted header information.
  *
- * @copyright © 2005 The SquirrelMail Project Team
+ * @copyright 2005-2010 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
 define('SM_PATH','../');
 
 /**
- * include SquirrelMail string functions
+ * include SquirrelMail string and generic functions
  * script needs OneTimePadDecrypt() (functions/strings.php)
- * and sqgetGlobalVar() (functions/global.php, loaded by strings.php)
+ * and sqgetGlobalVar() (functions/global.php)
  */
+include_once(SM_PATH.'functions/global.php');
 include_once(SM_PATH.'functions/strings.php');
 
 /**
@@ -36,14 +37,14 @@ function hex2ip($hex) {
             .hexdec(substr($hex,4,2)).'.'
             .hexdec(substr($hex,6,2));
     } elseif (strlen($hex)==32) {
-        $ret=hexdec(substr($hex,0,4)).':'
-            .hexdec(substr($hex,4,4)).':'
-            .hexdec(substr($hex,8,4)).':'
-            .hexdec(substr($hex,12,4)).':'
-            .hexdec(substr($hex,16,4)).':'
-            .hexdec(substr($hex,20,4)).':'
-            .hexdec(substr($hex,24,4)).':'
-            .hexdec(substr($hex,28,4));
+        $ret=substr($hex,0,4).':'
+            .substr($hex,4,4).':'
+            .substr($hex,8,4).':'
+            .substr($hex,12,4).':'
+            .substr($hex,16,4).':'
+            .substr($hex,20,4).':'
+            .substr($hex,24,4).':'
+            .substr($hex,28,4);
     } else {
         $ret=$hex;
     }
@@ -53,38 +54,46 @@ function hex2ip($hex) {
 /** create page headers */
 header('Content-Type: text/html');
 
-echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'
+echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"'."\n"
+    .'  "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">'
     ."\n<head>\n<meta name=\"robots\" content=\"noindex,nofollow\">\n"
     ."</head><body>";
 
 if (sqgetGlobalVar('submit',$submit,SQ_POST)) {
+    $continue = TRUE;
     if (! sqgetGlobalVar('secret',$secret,SQ_POST) ||
-        empty($secret))
-        echo "<p>You must enter encryption key.</p>\n";
+        empty($secret)) {
+        $continue = FALSE;
+        echo "<p>You must enter an encryption key.</p>\n";
+    }
     if (! sqgetGlobalVar('enc_string',$enc_string,SQ_POST) ||
-        empty($enc_string))
-        echo "<p>You must enter encrypted string.</p>\n";
+        empty($enc_string)) {
+        $continue = FALSE;
+        echo "<p>You must enter an encrypted string.</p>\n";
+    }
 
-    if (isset($enc_string) && ! base64_decode($enc_string)) {
-        echo "<p>Encrypted string should be BASE64 encoded.<br />\n"
-            ."Please enter all characters that are listed after header name.</p>\n";
-    } elseif (isset($secret)) {
-        $string=OneTimePadDecrypt($enc_string,base64_encode($secret));
+    if ($continue) {
+        if (isset($enc_string) && ! base64_decode($enc_string)) {
+            echo "<p>Encrypted string should be BASE64 encoded.<br />\n"
+                ."Please enter all characters that are listed after header name.</p>\n";
+        } elseif (isset($secret)) {
+            $string=OneTimePadDecrypt($enc_string,base64_encode($secret));
 
-        if (sqgetGlobalVar('ip_addr',$is_addr,SQ_POST)) {
-            $string=hex2ip($string);
+            if (sqgetGlobalVar('ip_addr',$is_addr,SQ_POST)) {
+                $string=hex2ip($string);
+            }
+            echo "<p>Decoded string: ".htmlspecialchars($string)."</p>\n";
         }
-        echo "<p>Decoded string: ".$string."</p>\n";
     }
     echo "<hr />";
 }
 ?>
-<form action="<?php echo $PHP_SELF ?>" method="post" >
+<form action="" method="post">
 <p>
 Secret key: <input type="password" name="secret"><br />
 Encrypted string: <input type="text" name="enc_string"><br />
-Check, if it is an address string: <input type="checkbox" name="ip_addr" /><br />
+<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 />
 <button type="submit" name="submit" value="submit">Submit</button>
 </p>
 </form>
-</body></html>
\ No newline at end of file
+</body></html>