Erste Version des vmail-Modul
bernd

bernd commited on 2007-11-20 10:30:34
Zeige 6 geänderte Dateien mit 493 Einfügungen und 3 Löschungen.


git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@791 87cf0b9e-d624-0410-a070-f6ee81989793
... ...
@@ -40,6 +40,16 @@ function success_msg($msg)
40 40
 }
41 41
 
42 42
 
43
+function we_have_an_error()
44
+{
45
+  global $input_error;
46
+  global $warning;
47
+
48
+  return ((count($input_error) + count($warning)) > 0);
49
+
50
+}
51
+
52
+
43 53
 function show_messages()
44 54
 {
45 55
   global $input_error;
... ...
@@ -54,7 +64,7 @@ function show_messages()
54 64
     ';
55 65
     foreach ($input_error as $error)
56 66
     {
57
-      echo '<li>'.filter_input_general($error)."</li>\n";
67
+      echo '<li>'.nl2br(filter_input_general($error))."</li>\n";
58 68
     }
59 69
     echo '</ul>
60 70
     </div>';
... ...
@@ -66,7 +76,7 @@ function show_messages()
66 76
     ';
67 77
     foreach ($warning as $msg)
68 78
     {
69
-      echo '<li>'.filter_input_general($msg)."</li>\n";
79
+      echo '<li>'.nl2br(filter_input_general($msg))."</li>\n";
70 80
     }
71 81
     echo '</ul>
72 82
     </div>';
... ...
@@ -78,7 +88,7 @@ function show_messages()
78 88
     ';
79 89
     foreach ($success_msg as $msg)
80 90
     {
81
-      echo '<li>'.filter_input_general($msg)."</li>\n";
91
+      echo '<li>'.nl2br(filter_input_general($msg))."</li>\n";
82 92
     }
83 93
     echo '</ul>
84 94
     </div>';
... ...
@@ -0,0 +1,32 @@
1
+<?php
2
+
3
+require_once('inc/base.php');
4
+require_once('inc/security.php');
5
+require_role(ROLE_SYSTEMUSER);
6
+
7
+require_once('vmail.php');
8
+
9
+$accounts = get_vmail_accounts();
10
+
11
+output('<h3>E-Mail-Accounts</h3>
12
+<p>Folgende E-Mail-Konten sind eingerichtet:</p>
13
+<table style="margin-bottom: 1em;">
14
+<tr><th>Adresse</th><th>Aktion</th><th>...</th><th>&#160;</th></tr>
15
+');
16
+
17
+        foreach ($accounts as $account)
18
+        {
19
+	    $action = ($account['type'] == 'mailbox' ? 'Speichern in Postfach' : 'Weiterleiten an '.filter_input_general($account['data']));
20
+            output('<tr>
21
+            <td>'.internal_link('edit.php', $account['local'].'@'.$account['domain'], 'id='.$account['id']).'</td>
22
+            <td>'.$action.'</td>
23
+            <td><a href="delete.php?account='.$account['id'].'">löschen</a></td></tr>');
24
+        }
25
+        output('</table>
26
+<p><a href="edit.php">Neuen Account anlegen</a></p>
27
+
28
+');
29
+
30
+
31
+
32
+?>
... ...
@@ -0,0 +1,139 @@
1
+<?php
2
+
3
+require_once('inc/debug.php');
4
+require_once('inc/security.php');
5
+
6
+require_once('vmail.php');
7
+
8
+$title = "E-Mail-Adresse bearbeiten";
9
+$section = 'vmail_accounts';
10
+require_role(ROLE_SYSTEMUSER);
11
+
12
+$id = (int) $_GET['id'];
13
+$vhost = empty_account();
14
+
15
+if ($id != 0)
16
+  $account = get_account_details($id);
17
+
18
+DEBUG($account);
19
+if ($id == 0) {
20
+  output("<h3>Neue E-Mail-Adresse anlegen</h3>");
21
+  $title = "E-Mail-Adresse anlegen";
22
+}
23
+else {
24
+  output("<h3>E-Mail-Adresse bearbeiten</h3>");
25
+}
26
+
27
+
28
+$is_forward = ($mailbox['type'] == 'forward');
29
+$is_mailbox = ( ! $is_forward);
30
+
31
+output("<script type=\"text/javascript\">
32
+  
33
+  function selectForwarding() {
34
+    // document.getElementById('forward_options').style.visibility = 'visible';
35
+    // document.getElementById('mailbox_options').style.visibility = 'hidden';
36
+    document.getElementById('forward_options').style.display = 'block';
37
+    document.getElementById('mailbox_options').style.display = 'none';
38
+    document.getElementById('spamfilter_folder').disabled = true;
39
+    document.getElementById('virusfilter_folder').disabled = true;
40
+    }
41
+  
42
+  function selectMailbox() {
43
+    // document.getElementById('mailbox_options').style.visibility = 'visible';
44
+    // document.getElementById('forward_options').style.visibility = 'hidden';
45
+    document.getElementById('mailbox_options').style.display = 'block';
46
+    document.getElementById('forward_options').style.display = 'none';
47
+    document.getElementById('spamfilter_folder').disabled = false;
48
+    document.getElementById('virusfilter_folder').disabled = false;
49
+    }
50
+  
51
+  function toggleSpamfilterOptions() {
52
+    if (document.getElementById('spamfilter').checked)
53
+      document.getElementById('spamfilter_options').style.display = 'block';
54
+    else
55
+      document.getElementById('spamfilter_options').style.display = 'none';
56
+    }
57
+  
58
+  function toggleVirusfilterOptions() {
59
+    if (document.getElementById('virusfilter').checked)
60
+      document.getElementById('virusfilter_options').style.display = 'block';
61
+    else
62
+      document.getElementById('virusfilter_options').style.display = 'none';
63
+    }
64
+
65
+  </script>");
66
+
67
+$form = "
68
+    <p><strong>E-Mail-Adresse:</strong>&#160;<input type=\"text\" name=\"local\" id=\"local\" size=\"10\" value=\"{$account['local']}\" /><strong style=\"font-size: 1.5em;\">&#160;@&#160;</strong>".domainselect($account['domainid'])."</p>";
69
+
70
+$form .= "<p><input type=\"checkbox\" id=\"spamfilter\" name=\"spamfilter\" value=\"1\" ".($account['spamfilter'] != NULL ? 'checked="checked" ' : '')." onclick=\"toggleSpamfilterOptions()\" /><label for=\"spamfilter\">&#160;Spam-Filter</label></p>";
71
+
72
+$form .= "<p style=\"margin-left: 2em; ".($account['spamfilter'] != NULL ? '' : 'display: none;')."\" id=\"spamfilter_options\">
73
+  <em>Was soll mit E-Mails geschehen, die als Spam eingestuft wurden?</em><br />
74
+  <input type=\"radio\" id=\"spamfilter_folder\" name=\"spamfilter_action\" value=\"folder\" ".($account['spamfilter'] == 'folder' ? 'checked="checked" ' : '')."/><label for=\"spamfilter_folder\">&#160;In IMAP-Unterordner »Spam« ablegen</label><br />
75
+  <input type=\"radio\" id=\"spamfilter_tag\" name=\"spamfilter_action\" value=\"tag\" ".($account['spamfilter'] == 'tag' ? 'checked="checked" ' : '')."/><label for=\"spamfilter_tag\">&#160;Markieren und ganz normal zustellen</label><br />
76
+<input type=\"radio\" id=\"spamfilter_delete\" name=\"spamfilter_action\" value=\"delete\" ".($account['spamfilter'] == 'delete' ? 'checked="checked" ' : '')."/><label for=\"spamfilter_delete\">&#160;Löschen</label>
77
+  </p>
78
+  ";
79
+
80
+  
81
+$form .= "<p><input type=\"checkbox\" id=\"virusfilter\" name=\"virusfilter\" value=\"1\" ".($account['virusfilter'] != NULL ? 'checked="checked" ' : '')." onclick=\"toggleVirusfilterOptions()\" /><label for=\"virusfilter\">&#160;Viren-Scanner</label></p>";
82
+
83
+$form .= "<p style=\"margin-left: 2em; ".($account['virusfilter'] != NULL ? '' : 'display: none;')."\" id=\"virusfilter_options\">
84
+  <em>Was soll mit E-Mails geschehen, in denen ein Virus erkannt wurde?</em><br />
85
+  <input type=\"radio\" id=\"virusfilter_folder\" name=\"virusfilter_action\" value=\"folder\" ".($account['virusfilter'] == 'folder' ? 'checked="checked" ' : '')."/><label for=\"virusfilter_folder\">&#160;In IMAP-Unterordner »Viren« ablegen</label><br />
86
+  <input type=\"radio\" id=\"virusfilter_tag\" name=\"virusfilter_action\" value=\"tag\" ".($account['virusfilter'] == 'tag' ? 'checked="checked" ' : '')."/><label for=\"virusfilter_tag\">&#160;Markieren und ganz normal zustellen</label><br />
87
+<input type=\"radio\" id=\"virusfilter_delete\" name=\"virusfilter_action\" value=\"delete\" ".($account['virusfilter'] == 'delete' ? 'checked="checked" ' : '')."/><label for=\"virusfilter_delete\">&#160;Löschen</label>
88
+  </p>
89
+  ";
90
+
91
+$password_message = '';
92
+if ($is_mailbox and ($account['data'] != ''))
93
+  $password_message = '<spam 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>';
94
+  
95
+
96
+$form .= "<p>
97
+    <input type=\"radio\" id=\"forward\" name=\"type\" value=\"forward\" ".($is_forward ? 'checked="checked" ' : '')." onclick=\"selectForwarding()\" /><label for=\"forward\">&#160;Weiterleitung an andere E-Mail-Adresse</label></p>
98
+    <p style=\"margin-left: 2em; ".($is_mailbox ? 'display: none' : '')."\" id=\"forward_options\">Weiterleitung an:&#160;<input type=\"text\" id=\"forward_to\" name=\"forward_to\" value=\"".($is_forward ? $account['data'] : '')."\" /></p>
99
+    <p><input type=\"radio\" id=\"mailbox\" name=\"type\" value=\"mailbox\" ".($is_mailbox ? 'checked="checked" ' : '')." onclick=\"selectMailbox()\" /><label for=\"mailbox\">&#160;In Mailbox speichern</label></p>
100
+    <p style=\"margin-left: 2em; ".($is_forward ? 'display: none' : '')."\" id=\"mailbox_options\">Passwort für Abruf:&#160;<input type=\"password\" id=\"password\" name=\"password\" value=\"\" />{$password_message}</p>";
101
+    
102
+/*
103
+$form .= "<tr><td>PHP</td>
104
+    <td><select name=\"php\" id=\"php\">
105
+      <option value=\"none\" ".($vhost['php'] == NULL ? 'selected="selected"' : '')." >kein PHP</option>
106
+      <option value=\"mod_php\" ".($vhost['php'] == 'mod_php' ? 'selected="selected"' : '')." >als Apache-Modul</option>
107
+      <option value=\"fastcgi\" ".($vhost['php'] == 'fastcgi' ? 'selected="selected"' : '')." >FastCGI</option>
108
+    </select>
109
+    </td>
110
+    <td id=\"defaultphp\">als Apache-Modul</td></tr>
111
+    <tr><td>SSL-Verschlüsselung</td>
112
+    <td><select name=\"ssl\" id=\"ssl\">
113
+      <option value=\"none\" ".($vhost['ssl'] == NULL ? 'selected="selected"' : '')." >SSL optional anbieten</option>
114
+      <option value=\"http\" ".($vhost['ssl'] == 'http' ? 'selected="selected"' : '')." >kein SSL</option>
115
+      <option value=\"https\" ".($vhost['ssl'] == 'https' ? 'selected="selected"' : '')." >nur SSL</option>
116
+      <option value=\"forward\" ".($vhost['ssl'] == 'forward' ? 'selected="selected"' : '')." >Immer auf SSL umleiten</option>
117
+    </select>
118
+    </td>
119
+    <td id=\"defaultssl\">SSL optional anbieten</td></tr>
120
+    <tr>
121
+      <td>Logfiles <span class=\"warning\">*</span></td>
122
+      <td><select name=\"logtype\" id=\"logtype\">
123
+      <option value=\"none\" ".($vhost['logtype'] == NULL ? 'selected="selected"' : '')." >keine Logfiles</option>
124
+      <option value=\"anonymous\" ".($vhost['logtype'] == 'anonymous' ? 'selected="selected"' : '')." >anonymisiert</option>
125
+      <option value=\"default\" ".($vhost['logtype'] == 'default' ? 'selected="selected"' : '')." >vollständige Logfile</option>
126
+    </select><br />
127
+    <input type=\"checkbox\" id=\"errorlog\" name=\"errorlog\" value=\"1\" ".($vhost['errorlog'] == 1 ? ' checked="checked" ' : '')." />&#160;<label for=\"errorlog\">Fehlerprotokoll (error_log) einschalten</label>
128
+    </td>
129
+    <td id=\"defaultlogtype\">keine Logfiles</td></tr>
130
+    ";
131
+
132
+*/
133
+$form .= '
134
+  <p><input type="submit" value="Speichern" />&#160;&#160;&#160;&#160;'.internal_link('accounts.php', 'Abbrechen').'</p>';
135
+
136
+output(html_form('vmail_edit_mailbox', 'save.php', 'action=edit'.($id != 0 ? '&id='.$id : ''), $form));
137
+
138
+
139
+?>
... ...
@@ -0,0 +1,239 @@
1
+<?php
2
+require_once('inc/base.php');
3
+require_once('inc/debug.php');
4
+
5
+
6
+function user_has_vmail_domain() 
7
+{
8
+	$role = $_SESSION['role'];
9
+	if (! ($role & ROLE_SYSTEMUSER)) {
10
+		return false;
11
+	}
12
+	$uid = (int) $_SESSION['userinfo']['uid'];
13
+	$result = db_query("SELECT COUNT(*) FROM mail.v_vmail_domains WHERE useraccount='{$uid}'");
14
+	$row = mysql_fetch_array($result);
15
+	$count = $row[0];
16
+	DEBUG("User has {$count} vmail-domains");
17
+	return ( (int) $count > 0 );
18
+}
19
+
20
+
21
+function empty_account()
22
+{
23
+	$account = array(
24
+		'id' => NULL,
25
+		'local' => '',
26
+		'domain' => NULL,
27
+		'type' => 'mailbox',
28
+		'data' => NULL,
29
+		'spamfilter' => NULL,
30
+		'virusfilter' => NULL,
31
+		'spamexpire' => 7,
32
+		'virusexpire' => 7
33
+		);
34
+	return $account;
35
+
36
+}
37
+
38
+function get_account_details($id)
39
+{
40
+	$id = (int) $id;
41
+	$uid = (int) $_SESSION['userinfo']['uid'];
42
+	$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");
43
+	if (mysql_num_rows($result) == 0)
44
+		system_failure('Ungültige ID oder kein eigener Account');
45
+	return mysql_fetch_assoc($result);;
46
+	
47
+}
48
+
49
+function get_vmail_accounts()
50
+{
51
+	$uid = (int) $_SESSION['userinfo']['uid'];
52
+	$result = db_query("SELECT * from mail.v_virtual_mail WHERE useraccount='{$uid}'");
53
+	$ret = array();
54
+	while ($line = mysql_fetch_assoc($result))
55
+	{
56
+		array_push($ret, $line);
57
+	}
58
+	DEBUG($ret);
59
+	return $ret;
60
+}
61
+
62
+
63
+
64
+function get_vmail_domains()
65
+{
66
+	$uid = (int) $_SESSION['userinfo']['uid'];
67
+	$result = db_query("SELECT id, domainname FROM mail.v_vmail_domains WHERE useraccount='{$uid}'");
68
+	if (mysql_num_rows($result) == 0)
69
+		system_failure('Sie haben keine Domains für virtuelle Mail-Verarbeitung');
70
+	$ret = array();
71
+	while ($tmp = mysql_fetch_object($result))
72
+		array_push($ret, $tmp);
73
+	return $ret;
74
+}
75
+
76
+
77
+
78
+function domainselect($selected = NULL, $selectattribute = '')
79
+{
80
+  global $domainlist;
81
+  if ($domainlist == NULL)
82
+    $domainlist = get_vmail_domains();
83
+  $selected = (int) $selected;
84
+
85
+  $ret = '<select id="domain" name="domain" size="1" '.$selectattribute.' >';
86
+  foreach ($domainlist as $dom)
87
+  {
88
+    $s = ($selected == $dom->id) ? ' selected="selected" ': '';
89
+    $ret .= "<option value=\"{$dom->id}\"{$s}>{$dom->domainname}</option>\n";
90
+  }
91
+  $ret .= '</select>';
92
+  return $ret;
93
+}
94
+
95
+
96
+function encrypt_mail_password($pw)
97
+{
98
+  DEBUG("unencrypted PW: ".$pw);
99
+  require_once('inc/base.php');
100
+  $salt = random_string(8);
101
+  $encpw = crypt($pw, "\$1\${$salt}\$");
102
+  DEBUG("encrypted PW: ".$encpw);
103
+  return chop($encpw);
104
+
105
+}
106
+
107
+
108
+
109
+function save_vmail_account($account)
110
+{
111
+  $uid = (int) $_SESSION['userinfo']['uid'];
112
+  $id = $account['id'];
113
+  if ($id != NULL)
114
+  {
115
+    $id = (int) $id;
116
+    $oldaccount = get_account_details($id);
117
+    // Erzeugt einen system_error() wenn ID ungültig
118
+  }
119
+  // Ab hier ist $id sicher, entweder NULL oder eine gültige ID des aktuellen users
120
+
121
+  $account['local'] = filter_input_username($account['local']);
122
+  if ($account['local'] == '')
123
+  {
124
+    input_error('Die E-Mail-Adresse braucht eine Angabe vor dem »@«!');
125
+    return false;
126
+  }
127
+  $account['domain'] = (int) $account['domain'];
128
+  $domainlist = get_vmail_domains();
129
+  $valid_domain = false;
130
+  foreach ($domainlist as $dom)
131
+  {
132
+    if ($dom->id == $account['domain'])
133
+    {
134
+      $valid_domain = true;
135
+      break;
136
+    }
137
+  }
138
+  if (($account['domain'] == 0) || (! $valid_domain))
139
+  {
140
+    input_error('Bitte wählen Sie eine Ihrer Domains aus!');
141
+    return false;
142
+  }
143
+  $type = NULL;
144
+  switch ($account['type'])
145
+  {
146
+    case 'forward':
147
+                     $account['data'] = filter_input_general($account['data']);
148
+                     if (! check_emailaddr($account['data']))
149
+		       system_failure('Das Weiterleitungs-Ziel ist keine E-Mail-Adresse!');
150
+		     $type = 'forward';
151
+                     break;
152
+    case 'mailbox':
153
+                     $account['data'] = stripslashes($account['data']);
154
+                     if ($account['data'] != '')
155
+                     {
156
+                       $crack = strong_password($account['data']);
157
+                       if ($crack !== true)
158
+                       {
159
+                         input_error('Ihr Passwort ist zu einfach. bitte wählen Sie ein sicheres Passwort!'."\nDie Fehlermeldung lautet: »{$crack}«");
160
+                         return false;
161
+                       }
162
+                       $account['data'] = encrypt_mail_password($account['data']);
163
+                     }
164
+                     $type = 'mailbox';
165
+                     break;
166
+  }
167
+  if ($type == NULL)
168
+  {
169
+    input_error('Problem mit der »type«-Variable!');
170
+    return false;
171
+  }
172
+
173
+  $spam = 'NULL';
174
+  switch ($account['spamfilter'])
175
+  {
176
+    case 'folder':
177
+      if ($type == 'forward')
178
+      {
179
+        input_error('Sie können nicht in einen IMAP-Unterordner zustellen lassen, wenn Sie gar kein IMAP-Konto anlegen!');
180
+	return false;
181
+      }
182
+      $spam = "'folder'";
183
+      break;
184
+    case 'tag':
185
+      $spam = "'tag'";
186
+      break;
187
+    case 'delete':
188
+      $spam = "'delete'";
189
+      break;
190
+  }
191
+
192
+  $virus = 'NULL';
193
+  switch ($account['virusfilter'])
194
+  {
195
+    case 'folder':
196
+      if ($type == 'forward')
197
+      {
198
+        input_error('Sie können nicht in einen IMAP-Unterordner zustellen lassen, wenn Sie gar kein IMAP-Konto anlegen!');
199
+	return false;
200
+      }
201
+      $virus = "'folder'";
202
+      break;
203
+    case 'tag':
204
+      $virus = "'tag'";
205
+      break;
206
+    case 'delete':
207
+      $virus = "'delete'";
208
+      break;
209
+  }
210
+
211
+  $account['local'] = mysql_real_escape_string($account['local']);
212
+  $account['data'] = mysql_real_escape_string($account['data']);
213
+  $account['spamexpire'] = (int) $account['spamexpire'];
214
+  $account['virusexpire'] = (int) $account['virusexpire'];
215
+
216
+  $query = '';
217
+  if ($id == NULL)
218
+  {
219
+    $query = "INSERT INTO mail.virtual_mail (local, domain, type, data, spamfilter, virusfilter, spamexpire, virusexpire) VALUES ";
220
+    $query .= "('{$account['local']}', {$account['domain']}, '{$type}', '{$account['data']}', {$spam}, {$virus}, {$account['spamexpire']}, {$account['virusexpire']});";
221
+  }
222
+  else
223
+  {
224
+    $password = ", data='{$account['data']}'";
225
+    if ($account['data'] == '')
226
+      $password = '';
227
+    $query = "UPDATE mail.virtual_mail SET local='{$account['local']}', domain={$account['domain']}, type='{$type}'{$password}, ";
228
+    $query .= "spamfilter={$spam}, virusfilter={$virus}, spamexpire={$account['spamexpire']}, virusexpire={$account['virusexpire']} ";
229
+    $query .= "WHERE id={$id} LIMIT 1;";
230
+  }
231
+  db_query($query); 
232
+
233
+
234
+}
235
+
236
+
237
+
238
+
239
+?>
... ...
@@ -0,0 +1,20 @@
1
+<?php
2
+
3
+$menu = array();
4
+
5
+$role = $_SESSION['role'];
6
+
7
+require_once('include/vmail.php');
8
+
9
+
10
+if (($role & ROLE_SYSTEMUSER) && user_has_vmail_domain())
11
+{
12
+  $menu["vmail_accounts"] = array("label" => "E-Mail", "file" => "accounts.php", "weight" => 10);
13
+}
14
+
15
+
16
+if (empty($menu))
17
+  $menu = false;
18
+
19
+
20
+?>
... ...
@@ -0,0 +1,50 @@
1
+<?php
2
+
3
+require_once('session/start.php');
4
+
5
+require_once('vmail.php');
6
+
7
+require_role(ROLE_SYSTEMUSER);
8
+
9
+require_once("inc/debug.php");
10
+global $debugmode;
11
+
12
+
13
+if ($_GET['action'] == 'edit')
14
+{
15
+  check_form_token('vmail_edit_mailbox');
16
+  $id = (int) $_GET['id'];
17
+
18
+  $account = empty_account();
19
+  $account['id'] = NULL;
20
+  if ($id)
21
+    $account['id'] = $id;
22
+  $account['local'] = $_POST['local'];
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
+  $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;
35
+
36
+  DEBUG($account);
37
+
38
+  save_vmail_account($account);
39
+
40
+  if (! ($debugmode || we_have_an_error()))
41
+    header('Location: accounts.php');
42
+
43
+}
44
+else
45
+  system_failure("Unimplemented action");
46
+
47
+output('');
48
+
49
+
50
+?>
0 51