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