bernd commited on 2008-02-01 19:33:15
Zeige 4 geänderte Dateien mit 103 Einfügungen und 87 Löschungen.
git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@923 87cf0b9e-d624-0410-a070-f6ee81989793
... | ... |
@@ -11,15 +11,13 @@ $accounts = get_vmail_accounts(); |
11 | 11 |
output('<h3>E-Mail-Accounts</h3> |
12 | 12 |
<p>Folgende E-Mail-Konten sind eingerichtet:</p> |
13 | 13 |
<table style="margin-bottom: 1em;"> |
14 |
-<tr><th>Adresse</th><th>Aktion</th><th>...</th><th> </th></tr> |
|
14 |
+<tr><th>Adresse</th><th>...</th><th> </th></tr> |
|
15 | 15 |
'); |
16 | 16 |
|
17 | 17 |
foreach ($accounts as $account) |
18 | 18 |
{ |
19 |
- $action = ($account['type'] == 'mailbox' ? 'Speichern in Postfach' : 'Weiterleiten an '.filter_input_general($account['data'])); |
|
20 | 19 |
output('<tr> |
21 | 20 |
<td>'.internal_link('edit.php', $account['local'].'@'.$account['domain'], 'id='.$account['id']).'</td> |
22 |
- <td>'.$action.'</td> |
|
23 | 21 |
<td><a href="save.php?action=delete&id='.$account['id'].'">löschen</a></td></tr>'); |
24 | 22 |
} |
25 | 23 |
output('</table> |
... | ... |
@@ -25,12 +25,13 @@ else { |
25 | 25 |
} |
26 | 26 |
|
27 | 27 |
|
28 |
-$is_forward = ($account['type'] == 'forward'); |
|
29 |
-$is_mailbox = ( ! $is_forward); |
|
28 |
+$is_forward = (count($account['forwards']) > 0); |
|
29 |
+$is_mailbox = ($account['password'] != NULL || $id == 0); |
|
30 |
+$numforwards = max(count($account['forwards']), 1); |
|
30 | 31 |
|
31 | 32 |
output("<script type=\"text/javascript\"> |
32 | 33 |
|
33 |
- var numForwards = 1; |
|
34 |
+ var numForwards = {$numforwards}; |
|
34 | 35 |
|
35 | 36 |
function moreForward() |
36 | 37 |
{ |
... | ... |
@@ -117,12 +118,12 @@ $form .= "<p style=\"margin-left: 2em;\" id=\"virusfilter_options\"> |
117 | 118 |
*/ |
118 | 119 |
|
119 | 120 |
$password_message = ''; |
120 |
-if ($is_mailbox and ($account['data'] != '')) |
|
121 |
+if ($is_mailbox and ($account['password'] != '')) |
|
121 | 122 |
$password_message = '<span style="font-size: 80%"><br /><em>Sie haben bereits ein Passwort gesetzt. Wenn Sie dieses Feld leer lassen, wird das bisherige Passwort beibehalten.</em></span>'; |
122 | 123 |
|
123 | 124 |
|
124 | 125 |
$form .= " |
125 |
- <p><input type=\"checkbox\" id=\"mailbox\" name=\"type\" value=\"mailbox\" ".($is_mailbox ? 'checked="checked" ' : '')." /><label for=\"mailbox\"> In Mailbox speichern</label></p> |
|
126 |
+ <p><input type=\"checkbox\" id=\"mailbox\" name=\"mailbox\" value=\"yes\" ".($is_mailbox ? 'checked="checked" ' : '')." /><label for=\"mailbox\"> In Mailbox speichern</label></p> |
|
126 | 127 |
<p style=\"margin-left: 2em;\" id=\"mailbox_options\">Passwort für Abruf: <input type=\"password\" id=\"password\" name=\"password\" value=\"\" />{$password_message}</p>"; |
127 | 128 |
|
128 | 129 |
|
... | ... |
@@ -136,24 +137,38 @@ $form .= " |
136 | 137 |
</p> |
137 | 138 |
"; |
138 | 139 |
|
139 |
-$form .= "<p><input type=\"checkbox\" id=\"forward\" name=\"type\" value=\"forward\" ".($is_forward ? 'checked="checked" ' : '')." /><label for=\"forward\"> Weiterleitung an andere E-Mail-Adressen</label></p>"; |
|
140 |
+$form .= "<p><input type=\"checkbox\" id=\"forward\" name=\"forward\" value=\"yes\" ".($is_forward ? 'checked="checked" ' : '')." /><label for=\"forward\"> Weiterleitung an andere E-Mail-Adressen</label></p>"; |
|
140 | 141 |
|
141 | 142 |
$form .= "<table style=\"margin-left: 2em;\" id=\"forward_table\"> |
142 | 143 |
<tr><th>Ziel-Adresse</th><th>Unerwünschte E-Mails</th></tr> |
143 | 144 |
"; |
144 | 145 |
|
146 |
+if ($is_forward) |
|
147 |
+{ |
|
148 |
+ for ($i = 0 ; $i < $numforwards ; $i++) |
|
149 |
+ { |
|
150 |
+ $num = $i+1; |
|
151 |
+ $form .= " |
|
152 |
+<tr> |
|
153 |
+ <td><input type=\"text\" id=\"forward_to_{$num}\" name=\"forward_to_{$num}\" value=\"{$account['forwards'][$i]['destination']}\" /></td> |
|
154 |
+ <td> |
|
155 |
+ ".html_select('spamfilter_action_'.$num, array("none" => 'kein Filter', "tag" => 'markieren und zustellen', "delete" => 'löschen'), $account['forwards'][$i]['spamfilter'])." |
|
156 |
+ </td> |
|
157 |
+</tr> |
|
158 |
+"; |
|
159 |
+ } |
|
160 |
+} |
|
161 |
+else |
|
162 |
+{ |
|
145 | 163 |
$form .= " |
146 | 164 |
<tr> |
147 | 165 |
<td><input type=\"text\" id=\"forward_to_1\" name=\"forward_to_1\" value=\"\" /></td> |
148 | 166 |
<td> |
149 |
- <select id=\"spamfilter_action_1\" name=\"spamfilter_action_1\"> |
|
150 |
- <option value=\"none\">kein Filter</option> |
|
151 |
- <option value=\"tag\">markieren und zustellen</option> |
|
152 |
- <option value=\"delete\">löschen</option> |
|
153 |
- </select> |
|
167 |
+ ".html_select('spamfilter_action_1', array("none" => 'kein Filter', "tag" => 'markieren und zustellen', "delete" => 'löschen'), "none")." |
|
154 | 168 |
</td> |
155 | 169 |
</tr> |
156 | 170 |
"; |
171 |
+} |
|
157 | 172 |
|
158 | 173 |
$form .= '</table> |
159 | 174 |
<p style="margin-left: 2em;">[ <a href="#" onclick="moreForward();">mehr Empfänger</a> ]</p> |
... | ... |
@@ -13,7 +13,7 @@ function empty_account() |
13 | 13 |
'password' => NULL, |
14 | 14 |
'spamfilter' => 'folder', |
15 | 15 |
'spamexpire' => 7, |
16 |
- 'forwards' => array(); |
|
16 |
+ 'forwards' => array() |
|
17 | 17 |
); |
18 | 18 |
return $account; |
19 | 19 |
|
... | ... |
@@ -23,11 +23,23 @@ function get_account_details($id) |
23 | 23 |
{ |
24 | 24 |
$id = (int) $id; |
25 | 25 |
$uid = (int) $_SESSION['userinfo']['uid']; |
26 |
- $result = db_query("SELECT id, local, domainid as domain, type, data, spamfilter, virusfilter from mail.v_virtual_mail WHERE useraccount='{$uid}' AND id={$id} LIMIT 1"); |
|
26 |
+ $result = db_query("SELECT id, local, domain, password, spamfilter, forwards from mail.v_vmail_accounts WHERE useraccount='{$uid}' AND id={$id} LIMIT 1"); |
|
27 | 27 |
if (mysql_num_rows($result) == 0) |
28 | 28 |
system_failure('Ungültige ID oder kein eigener Account'); |
29 |
- return mysql_fetch_assoc($result);; |
|
30 |
- |
|
29 |
+ $acc = empty_account(); |
|
30 |
+ $res = mysql_fetch_assoc($result); |
|
31 |
+ foreach ($res AS $key => $value) { |
|
32 |
+ if ($key == 'forwards') |
|
33 |
+ continue; |
|
34 |
+ $acc[$key] = $value; |
|
35 |
+ } |
|
36 |
+ if ($acc['forwards'] > 0) { |
|
37 |
+ $result = db_query("SELECT id, spamfilter, destination FROM mail.vmail_forward WHERE account={$acc['id']};"); |
|
38 |
+ while ($item = mysql_fetch_assoc($result)){ |
|
39 |
+ array_push($acc['forwards'], array("id" => $item['id'], 'spamfilter' => $item['spamfilter'], 'destination' => $item['destination'])); |
|
40 |
+ } |
|
41 |
+ } |
|
42 |
+ return $acc; |
|
31 | 43 |
} |
32 | 44 |
|
33 | 45 |
function get_vmail_accounts() |
... | ... |
@@ -124,50 +136,40 @@ function save_vmail_account($account) |
124 | 136 |
input_error('Bitte wählen Sie eine Ihrer Domains aus!'); |
125 | 137 |
return false; |
126 | 138 |
} |
127 |
- $type = NULL; |
|
128 |
- switch ($account['type']) |
|
139 |
+ |
|
140 |
+ $forwards = array(); |
|
141 |
+ if (count($account['forwards']) > 0) |
|
129 | 142 |
{ |
130 |
- case 'forward': |
|
131 |
- $forward_to = preg_split("/[\s,]+/", $account['data']); |
|
132 |
- foreach ($forward_to as $addr) |
|
143 |
+ for ($i=0;$i < count($account['forwards']); $i++) |
|
133 | 144 |
{ |
134 |
- $addr = filter_input_general($addr); |
|
135 |
- if (! check_emailaddr($addr)) |
|
136 |
- system_failure('Das Weiterleitungs-Ziel »'.$addr.'« ist keine E-Mail-Adresse!'); |
|
145 |
+ if ($account['forwards'][$i]['spamfilter'] != 'tag' && $account['forwards'][$i]['spamfilter'] != 'delete') |
|
146 |
+ $account['forwards'][$i]['spamfilter'] = ''; |
|
147 |
+ $account['forwards'][$i]['destination'] = filter_input_general($account['forwards'][$i]['destination']); |
|
148 |
+ if (! check_emailaddr($account['forwards'][$i]['destination'])) |
|
149 |
+ system_failure('Das Weiterleitungs-Ziel »'.$account['forwards'][$i]['destination'].'« ist keine E-Mail-Adresse!'); |
|
137 | 150 |
} |
138 |
- $account['data'] = implode(' ', $forward_to); |
|
139 |
- $type = 'forward'; |
|
140 |
- break; |
|
141 |
- case 'mailbox': |
|
142 |
- $account['data'] = stripslashes($account['data']); |
|
143 |
- if ($account['data'] != '') |
|
151 |
+ } |
|
152 |
+ |
|
153 |
+ $password='NULL'; |
|
154 |
+ if ($account['password'] != '') |
|
144 | 155 |
{ |
145 |
- $crack = strong_password($account['data']); |
|
156 |
+ $account['password'] = stripslashes($account['password']); |
|
157 |
+ $crack = strong_password($account['password']); |
|
146 | 158 |
if ($crack !== true) |
147 | 159 |
{ |
148 | 160 |
input_error('Ihr Passwort ist zu einfach. bitte wählen Sie ein sicheres Passwort!'."\nDie Fehlermeldung lautet: »{$crack}«"); |
149 | 161 |
return false; |
150 | 162 |
} |
151 |
- $account['data'] = encrypt_mail_password($account['data']); |
|
152 |
- } |
|
153 |
- $type = 'mailbox'; |
|
154 |
- break; |
|
155 |
- } |
|
156 |
- if ($type == NULL) |
|
157 |
- { |
|
158 |
- input_error('Problem mit der »type«-Variable!'); |
|
159 |
- return false; |
|
163 |
+ $password = "'".encrypt_mail_password($account['password'])."'"; |
|
160 | 164 |
} |
165 |
+ $set_password = ($id == NULL || $password != 'NULL'); |
|
166 |
+ if ($account['password'] === NULL) |
|
167 |
+ $set_password=true; |
|
161 | 168 |
|
162 | 169 |
$spam = 'NULL'; |
163 | 170 |
switch ($account['spamfilter']) |
164 | 171 |
{ |
165 | 172 |
case 'folder': |
166 |
- if ($type == 'forward') |
|
167 |
- { |
|
168 |
- input_error('Sie können nicht in einen IMAP-Unterordner zustellen lassen, wenn Sie gar kein IMAP-Konto anlegen!'); |
|
169 |
- return false; |
|
170 |
- } |
|
171 | 173 |
$spam = "'folder'"; |
172 | 174 |
break; |
173 | 175 |
case 'tag': |
... | ... |
@@ -178,48 +180,43 @@ function save_vmail_account($account) |
178 | 180 |
break; |
179 | 181 |
} |
180 | 182 |
|
181 |
- $virus = 'NULL'; |
|
182 |
- switch ($account['virusfilter']) |
|
183 |
- { |
|
184 |
- case 'folder': |
|
185 |
- if ($type == 'forward') |
|
186 |
- { |
|
187 |
- input_error('Sie können nicht in einen IMAP-Unterordner zustellen lassen, wenn Sie gar kein IMAP-Konto anlegen!'); |
|
188 |
- return false; |
|
189 |
- } |
|
190 |
- $virus = "'folder'"; |
|
191 |
- break; |
|
192 |
- case 'tag': |
|
193 |
- $virus = "'tag'"; |
|
194 |
- break; |
|
195 |
- case 'delete': |
|
196 |
- $virus = "'delete'"; |
|
197 |
- break; |
|
198 |
- } |
|
199 |
- |
|
200 | 183 |
$account['local'] = mysql_real_escape_string($account['local']); |
201 |
- $account['data'] = mysql_real_escape_string($account['data']); |
|
184 |
+ $account['password'] = mysql_real_escape_string($account['password']); |
|
202 | 185 |
$account['spamexpire'] = (int) $account['spamexpire']; |
203 |
- $account['virusexpire'] = (int) $account['virusexpire']; |
|
204 | 186 |
|
205 | 187 |
$query = ''; |
206 | 188 |
if ($id == NULL) |
207 | 189 |
{ |
208 |
- $query = "INSERT INTO mail.virtual_mail (local, domain, type, data, spamfilter, virusfilter, spamexpire, virusexpire) VALUES "; |
|
209 |
- $query .= "('{$account['local']}', {$account['domain']}, '{$type}', '{$account['data']}', {$spam}, {$virus}, {$account['spamexpire']}, {$account['virusexpire']});"; |
|
190 |
+ $query = "INSERT INTO mail.vmail_accounts (local, domain, spamfilter, spamexpire, password) VALUES "; |
|
191 |
+ $query .= "('{$account['local']}', {$account['domain']}, {$spam}, {$account['spamexpire']}, {$account['password']});"; |
|
210 | 192 |
} |
211 | 193 |
else |
212 | 194 |
{ |
213 |
- $password = ", data='{$account['data']}'"; |
|
214 |
- if ($account['data'] == '') |
|
195 |
+ if ($set_password) |
|
196 |
+ $password=", password={$password}"; |
|
197 |
+ else |
|
215 | 198 |
$password=''; |
216 |
- $query = "UPDATE mail.virtual_mail SET local='{$account['local']}', domain={$account['domain']}, type='{$type}'{$password}, "; |
|
217 |
- $query .= "spamfilter={$spam}, virusfilter={$virus}, spamexpire={$account['spamexpire']}, virusexpire={$account['virusexpire']} "; |
|
199 |
+ $query = "UPDATE mail.vmail_accounts SET local='{$account['local']}', domain={$account['domain']}{$password}, "; |
|
200 |
+ $query .= "spamfilter={$spam}, spamexpire={$account['spamexpire']} "; |
|
218 | 201 |
$query .= "WHERE id={$id} LIMIT 1;"; |
219 | 202 |
} |
220 | 203 |
db_query($query); |
221 |
- |
|
222 |
- if ($type == 'mailbox') |
|
204 |
+ db_query("DELETE FROM mail.vmail_forward WHERE account={$id}"); |
|
205 |
+ if (count($account['forwards']) > 0) |
|
206 |
+ { |
|
207 |
+ $forward_query = "INSERT INTO mail.vmail_forward (account,spamfilter,destination) VALUES "; |
|
208 |
+ $first = true; |
|
209 |
+ for ($i=0;$i < count($account['forwards']); $i++) |
|
210 |
+ { |
|
211 |
+ if ($first) |
|
212 |
+ $first = false; |
|
213 |
+ else |
|
214 |
+ $forward_query .= ', '; |
|
215 |
+ $forward_query .= "({$id}, ".maybe_null($account['forwards'][$i]['spamfilter']).", '{$account['forwards'][$i]['destination']}')"; |
|
216 |
+ } |
|
217 |
+ db_query($forward_query); |
|
218 |
+ } |
|
219 |
+ if ($account['password'] != 'NULL') |
|
223 | 220 |
{ |
224 | 221 |
# notify the vmail subsystem of this new account |
225 | 222 |
mail('vmail@schokokeks.org', 'command', "user={$account['local']}\nhost={$domainname}", "X-schokokeks-org-message: command"); |
... | ... |
@@ -231,7 +228,7 @@ function save_vmail_account($account) |
231 | 228 |
function delete_account($id) |
232 | 229 |
{ |
233 | 230 |
$account = get_account_details($id); |
234 |
- db_query("DELETE FROM mail.virtual_mail WHERE id={$account['id']};"); |
|
231 |
+ db_query("DELETE FROM mail.vmail_accounts WHERE id={$account['id']};"); |
|
235 | 232 |
} |
236 | 233 |
|
237 | 234 |
|
... | ... |
@@ -21,17 +21,23 @@ if ($_GET['action'] == 'edit') |
21 | 21 |
$account['id'] = $id; |
22 | 22 |
$account['local'] = $_POST['local']; |
23 | 23 |
$account['domain'] = (int) $_POST['domain']; |
24 |
- $account['type'] = $_POST['type']; |
|
25 |
- if ($_POST['type'] == 'mailbox') |
|
26 |
- $account['data'] = $_POST['password']; |
|
27 |
- else |
|
28 |
- $account['data'] = $_POST['forward_to']; |
|
29 | 24 |
$account['spamfilter'] = $_POST['spamfilter_action']; |
30 |
- if ($_POST['spamfilter'] != '1') |
|
31 |
- $account['spamfilter'] = NULL; |
|
32 |
- $account['virusfilter'] = $_POST['virusfilter_action']; |
|
33 |
- if ($_POST['virusfilter'] != '1') |
|
34 |
- $account['virusfilter'] = NULL; |
|
25 |
+ $account['password'] = $_POST['password']; |
|
26 |
+ if ($_POST['mailbox'] != 'yes') |
|
27 |
+ $account['password'] = NULL; |
|
28 |
+ |
|
29 |
+ if ($_POST['forward'] == 'yes') |
|
30 |
+ { |
|
31 |
+ $num = 1; |
|
32 |
+ while (true) |
|
33 |
+ { |
|
34 |
+ if (! isset($_POST['forward_to_'.$num])) |
|
35 |
+ break; |
|
36 |
+ $fwd = array("spamfilter" => $_POST['spamfilter_action_'.$num], "destination" => $_POST['forward_to_'.$num]); |
|
37 |
+ array_push($account['forwards'], $fwd); |
|
38 |
+ $num++; |
|
39 |
+ } |
|
40 |
+ } |
|
35 | 41 |
|
36 | 42 |
DEBUG($account); |
37 | 43 |
|
38 | 44 |