432db2fc |
1 | <?php |
2 | /** |
3 | * Script provides form to decode encrypted header information. |
4 | * |
5 | * Copyright (c) 2005 The SquirrelMail Project Team |
6 | * This file is part of SquirrelMail webmail interface. |
7 | * |
8 | * SquirrelMail is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. |
12 | * |
13 | * SquirrelMail is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with SquirrelMail; if not, write to the Free Software |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 | * |
22 | * @version $Id$ |
23 | * @package squirrelmail |
24 | */ |
25 | |
26 | /** |
27 | * Set constant to path of your SquirrelMail install. |
28 | * @ignore |
29 | */ |
30 | define('SM_PATH','../'); |
31 | |
32 | /** |
33 | * include SquirrelMail string functions |
34 | * script needs OneTimePadDecrypt() (functions/strings.php) |
35 | * and sqgetGlobalVar() (functions/global.php, loaded by strings.php) |
36 | */ |
37 | include_once(SM_PATH.'functions/strings.php'); |
38 | |
39 | /** |
40 | * converts hex string to ip address |
41 | * @param string $hex hexadecimal string created with squirrelmail ip2hex |
42 | * function in delivery class. |
43 | * @return string ip address |
44 | * @since 1.5.1 |
45 | */ |
46 | function hex2ip($hex) { |
47 | if (strlen($hex)==8) { |
48 | $ret=hexdec(substr($hex,0,2)).'.' |
49 | .hexdec(substr($hex,2,2)).'.' |
50 | .hexdec(substr($hex,4,2)).'.' |
51 | .hexdec(substr($hex,6,2)); |
52 | } elseif (strlen($hex)==32) { |
53 | $ret=hexdec(substr($hex,0,4)).':' |
54 | .hexdec(substr($hex,4,4)).':' |
55 | .hexdec(substr($hex,8,4)).':' |
56 | .hexdec(substr($hex,12,4)).':' |
57 | .hexdec(substr($hex,16,4)).':' |
58 | .hexdec(substr($hex,20,4)).':' |
59 | .hexdec(substr($hex,24,4)).':' |
60 | .hexdec(substr($hex,28,4)); |
61 | } else { |
62 | $ret=$hex; |
63 | } |
64 | return $ret; |
65 | } |
66 | |
67 | /** create page headers */ |
68 | header('Content-Type: text/html'); |
69 | |
70 | echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' |
71 | ."\n<head>\n<meta name=\"robots\" content=\"noindex,nofollow\">\n" |
72 | ."</head><body>"; |
73 | |
74 | if (sqgetGlobalVar('submit',$submit,SQ_POST)) { |
75 | if (! sqgetGlobalVar('secret',$secret,SQ_POST) || |
76 | empty($secret)) |
77 | echo "<p>You must enter encryption key.</p>\n"; |
78 | if (! sqgetGlobalVar('enc_string',$enc_string,SQ_POST) || |
79 | empty($enc_string)) |
80 | echo "<p>You must enter encrypted string.</p>\n"; |
81 | |
82 | if (isset($enc_string) && ! base64_decode($enc_string)) { |
83 | echo "<p>Encrypted string should be BASE64 encoded.<br />\n" |
84 | ."Please enter all characters that are listed after header name.</p>\n"; |
85 | } elseif (isset($secret)) { |
86 | $string=OneTimePadDecrypt($enc_string,base64_encode($secret)); |
87 | |
88 | if (sqgetGlobalVar('ip_addr',$is_addr,SQ_POST)) { |
89 | $string=hex2ip($string); |
90 | } |
91 | echo "<p>Decoded string: ".$string."</p>\n"; |
92 | } |
93 | echo "<hr />"; |
94 | } |
95 | ?> |
96 | <form action="<?php echo $PHP_SELF ?>" method="post" > |
97 | <p> |
98 | Secret key: <input type="password" name="secret"><br /> |
99 | Encrypted string: <input type="text" name="enc_string"><br /> |
100 | Check, if it is an address string: <input type="checkbox" name="ip_addr" /><br /> |
101 | <button type="submit" name="submit" value="submit">Submit</button> |
102 | </p> |
103 | </form> |
104 | </body></html> |