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