2
/////////////////////////////////////////////////////////
4
// source/pref_identities.php
6
// (C)Copyright 2000-2002 Ryo Chijiiwa <Ryo@IlohaMail.org>
8
// This file is part of IlohaMail.
9
// IlohaMail is free software released under the GPL
10
// license. See enclosed file COPYING for details,
11
// or see http://www.fsf.org/copyleft/gpl.html
13
/////////////////////////////////////////////////////////
15
/********************************************************
17
AUTHOR: Ryo Chijiiwa <ryo@ilohamail.org>
18
FILE: source/pref_identities.php
20
Create/edit/delete identities
24
********************************************************/
26
include("../include/super2global.inc");
27
include("../include/header_main.inc");
28
include("../include/langs.inc");
29
include("../include/icl.inc");
30
include("../lang/".$my_prefs["lang"]."prefs.inc");
31
include("../include/gpg.inc");
32
include("../include/pref_header.inc");
36
$conn=iil_Connect($host, $loginID, $password, $AUTH_MODE);
38
if ($ICL_CAPABILITY["folders"]){
39
if ($my_prefs["hideUnsubscribed"]){
40
$mailboxes = iil_C_ListSubscribed($conn, $my_prefs["rootdir"], "*");
42
$mailboxes = iil_C_ListMailboxes($conn, $my_prefs["rootdir"], "*");
48
echo "Authentication failed.";
49
echo "</body></html>\n";
53
$gpg_home = str_replace("%h", $host, str_replace("%u", $loginID, $GPG_HOME_STR));
54
if (file_exists(realpath($gpg_home."/pubring.gpg"))) $key_exists = true;
55
else $key_exists = false;
58
if (empty($name)) $error .= "Name not specified\n";
59
if (empty($email)) $error .= "Password not specified\n";
60
if (strlen($passphrase)<8) $error .= "Passphrase must be ATLEAST 8 characters long\n";
63
//echo "Making dir: $gpg_home <br>";
64
//create file containing key specifications
65
if (!is_dir(realpath($gpg_home))){
66
if (!mkdir($gpg_home, 0700)){
67
$error .= "mkdir() failed <br>\n";
72
//echo "Made dir <br>\n";
73
$temp_file = $gpg_home."/".$user.".tmp";
74
$fp = fopen($temp_file, "w");
76
echo "Opened temp file: $temp_file <br>\n";
77
$output = "Key-Type: DSA\n";
78
$output.= "Key-Length: 1024\n";
79
$output.= "Subkey-Type: ELG-E\n";
80
$output.= "Subkey-Length: 1024\n";
81
$output.= "Name-Real: ".$name."\n";
82
$output.= "#Name-Comment: test\n";
83
$output.= "Name-Email: ".$email."\n";
84
$output.= "Expire-Date: 0\n";
85
$output.= "Passphrase: ".$passphrase."\n";
86
$output.= "%commit\n";
89
//echo "Wrote: <pre>$output</pre><br>\n";
91
$error .= "Temp file not created: $temp_file <br>\n";
96
$command = $GPG_PATH." --home=".realpath($gpg_home)." --batch --gen-key ".realpath($temp_file);
97
//echo "Will run command: <tt>$command</tt><br>\n";
98
$temp = exec($command, $result, $errorno);
99
//echo "Got results: [$errorno]<pre>".implode("\n", $result)."</pre><br>\n";
103
$command = $GPG_PATH." --home=".realpath($gpg_home)." --export -a";
104
//echo "Running: $command <br>\n";
105
$temp = exec($command, $result, $errono);
106
//echo "Got results: [$errorno]<pre>".implode("\n", $result)."</pre><br>\n";
108
if ($errorno==0) $key_exists = true;
110
$error.= "Key generation failed. Erro code: $errorno <br>\n";
117
if ($key_exists && isset($import)){
118
if (empty($public_key)) $error .= "Public key not specified...";
120
$temp_file = $gpg_home."/".$user.".import.tmp";
121
$fp = fopen($temp_file, "w");
123
fputs($fp, $public_key);
125
echo "Wrote: <pre>$output</pre><br>\n";
127
$error .= "Temp file not created: $temp_file <br>\n";
131
$command = $GPG_PATH." --home=".realpath($gpg_home)." --import ".realpath($temp_file);
132
$temp = exec($command, $result, $errorno);
133
"Import: [$errorno] <pre>".implode("\n", $result)."</pre><br>\n";
138
if (isset($show_key) && !empty($person)){
139
echo "Show key for $person <br>\n";
140
$public_key = gpg_export($person);
143
$gpgStrings["genkey"] = "Generate Key";
144
$gpgStrings["name"] = "Name";
145
$gpgStrings["email"] = "Email";
146
$gpgStrings["passphrase"] = "Passphrase";
147
$gpgStrings["generate"] = "Generate Key";
149
<font color="red"><?php echo $error?></font>
155
<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
156
<input type="hidden" name="user" value="<?php echo $user?>">
157
<input type="hidden" name="session" value="<?php echo $user?>">
158
<table border="0" cellspacing="1" cellpadding="1" bgcolor="<?php echo $my_colors["main_hilite"]?>" width="95%">
159
<tr bgcolor="<?php echo $my_colors["main_head_bg"]?>">
160
<td align="center"><span class="tblheader"><?php echo $gpgStrings["genkey"]?></span></td>
161
</tr><tr bgcolor="<?php echo $my_colors["main_bg"]?>">
165
$keys = gpg_list_keys();
167
if (is_array($keys) && count($keys)>0){
168
while (list($k,$str)=each($keys)){
169
$options.= "<option value=\"$k\">$str\n";
173
<select name="person">
174
<?php echo $options ?>
176
<input type="submit" name="show_key" value="Show Key">
177
<p>Add public key:<br>
178
<textarea cols=80 rows=15 name="public_key"><?php echo $public_key?></textarea><br>
179
<input type="submit" name="import" value="Import Public Key">
187
<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
188
<input type="hidden" name="user" value="<?php echo $user?>">
189
<input type="hidden" name="session" value="<?php echo $user?>">
190
<table border="0" cellspacing="1" cellpadding="1" bgcolor="<?php echo $my_colors["main_hilite"]?>" width="95%">
191
<tr bgcolor="<?php echo $my_colors["main_head_bg"]?>">
192
<td align="center"><span class="tblheader"><?php echo $gpgStrings["genkey"]?></span></td>
193
</tr><tr bgcolor="<?php echo $my_colors["main_bg"]?>">
197
<td align="right"><?php echo $gpgStrings["name"]?>:</td>
198
<td><input type="text" name="name" value="<?php echo stripslashes($name)?>" size="45"></td>
201
<td align="right"><?php echo $gpgStrings["email"]?>:</td>
202
<td><input type="text" name="email" value="<?php echo $email ?>" size="45"></td>
205
<td align="right"><?php echo $gpgStrings["passphrase"]?>:</td>
206
<td><input type="password" name="passphrase" value="" size="45"></td>
209
CAUTION! Generating a key could take a long time (a minute or more). If you stop loading before a key is generated, this will screw things up big time (you will have to remove your GPG_HOME folder).
210
<input type="submit" name="genkey" value="<?php echo $gpgStrings["generate"]?>">