c2fdf5e33d33da11d7f9ce02b6a187a11727fa91
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

1) <?php
2) require_once('inc/base.php');
3) require_once('inc/debug.php');
4) 
bernd Bugfix: Funktion-Dopplung v...

bernd authored 16 years ago

5) require_once('hasdomain.php');
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

6) 
7) function empty_account()
8) {
9) 	$account = array(
10) 		'id' => NULL,
11) 		'local' => '',
12) 		'domain' => NULL,
bernd Neues VMail-Interface (funk...

bernd authored 16 years ago

13) 		'password' => NULL,
bernd Spam- und viren nur noch ei...

bernd authored 16 years ago

14) 		'spamfilter' => 'folder',
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

15) 		'spamexpire' => 7,
bernd Neues VMail-Interface (funk...

bernd authored 16 years ago

16) 		'forwards' => array();
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

17) 		);
18) 	return $account;
19) 
20) }
21) 
22) function get_account_details($id)
23) {
24) 	$id = (int) $id;
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");
27) 	if (mysql_num_rows($result) == 0)
28) 		system_failure('Ungültige ID oder kein eigener Account');
29) 	return mysql_fetch_assoc($result);;
30) 	
31) }
32) 
33) function get_vmail_accounts()
34) {
35) 	$uid = (int) $_SESSION['userinfo']['uid'];
36) 	$result = db_query("SELECT * from mail.v_virtual_mail WHERE useraccount='{$uid}'");
37) 	$ret = array();
38) 	while ($line = mysql_fetch_assoc($result))
39) 	{
40) 		array_push($ret, $line);
41) 	}
42) 	DEBUG($ret);
43) 	return $ret;
44) }
45) 
46) 
47) 
48) function get_vmail_domains()
49) {
50) 	$uid = (int) $_SESSION['userinfo']['uid'];
51) 	$result = db_query("SELECT id, domainname FROM mail.v_vmail_domains WHERE useraccount='{$uid}'");
52) 	if (mysql_num_rows($result) == 0)
53) 		system_failure('Sie haben keine Domains für virtuelle Mail-Verarbeitung');
54) 	$ret = array();
55) 	while ($tmp = mysql_fetch_object($result))
56) 		array_push($ret, $tmp);
57) 	return $ret;
58) }
59) 
60) 
61) 
62) function domainselect($selected = NULL, $selectattribute = '')
63) {
bernd Bugfix: Funktion-Dopplung v...

bernd authored 16 years ago

64)   $domainlist = get_vmail_domains();
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

65)   $selected = (int) $selected;
66) 
67)   $ret = '<select id="domain" name="domain" size="1" '.$selectattribute.' >';
68)   foreach ($domainlist as $dom)
69)   {
70)     $s = ($selected == $dom->id) ? ' selected="selected" ': '';
71)     $ret .= "<option value=\"{$dom->id}\"{$s}>{$dom->domainname}</option>\n";
72)   }
73)   $ret .= '</select>';
74)   return $ret;
75) }
76) 
77) 
78) function encrypt_mail_password($pw)
79) {
80)   DEBUG("unencrypted PW: ".$pw);
81)   require_once('inc/base.php');
82)   $salt = random_string(8);
83)   $encpw = crypt($pw, "\$1\${$salt}\$");
84)   DEBUG("encrypted PW: ".$encpw);
85)   return chop($encpw);
86) 
87) }
88) 
89) 
90) 
91) function save_vmail_account($account)
92) {
93)   $uid = (int) $_SESSION['userinfo']['uid'];
94)   $id = $account['id'];
95)   if ($id != NULL)
96)   {
97)     $id = (int) $id;
98)     $oldaccount = get_account_details($id);
99)     // Erzeugt einen system_error() wenn ID ungültig
100)   }
101)   // Ab hier ist $id sicher, entweder NULL oder eine gültige ID des aktuellen users
102) 
103)   $account['local'] = filter_input_username($account['local']);
104)   if ($account['local'] == '')
105)   {
106)     input_error('Die E-Mail-Adresse braucht eine Angabe vor dem »@«!');
107)     return false;
108)   }
109)   $account['domain'] = (int) $account['domain'];
110)   $domainlist = get_vmail_domains();
111)   $valid_domain = false;
bernd Benachrichtige vmail-userac...

bernd authored 16 years ago

112)   $domainname = NULL;
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

113)   foreach ($domainlist as $dom)
114)   {
115)     if ($dom->id == $account['domain'])
116)     {
bernd Benachrichtige vmail-userac...

bernd authored 16 years ago

117)       $domainname = $dom->domainname;
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

118)       $valid_domain = true;
119)       break;
120)     }
121)   }
122)   if (($account['domain'] == 0) || (! $valid_domain))
123)   {
124)     input_error('Bitte wählen Sie eine Ihrer Domains aus!');
125)     return false;
126)   }
127)   $type = NULL;
128)   switch ($account['type'])
129)   {
130)     case 'forward':
bernd mehrere Adressen erlauben

bernd authored 16 years ago

131)                      $forward_to = preg_split("/[\s,]+/", $account['data']);
132) 		     foreach ($forward_to as $addr)
133) 		     {
134)                        $addr = filter_input_general($addr);
135)                        if (! check_emailaddr($addr))
bernd Fehlerhafte Adresse in die...

bernd authored 16 years ago

136)                          system_failure('Das Weiterleitungs-Ziel »'.$addr.'« ist keine E-Mail-Adresse!');
bernd mehrere Adressen erlauben

bernd authored 16 years ago

137) 		     }
138) 		     $account['data'] = implode(' ', $forward_to);
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

139) 		     $type = 'forward';
140)                      break;
141)     case 'mailbox':
142)                      $account['data'] = stripslashes($account['data']);
143)                      if ($account['data'] != '')
144)                      {
145)                        $crack = strong_password($account['data']);
146)                        if ($crack !== true)
147)                        {
148)                          input_error('Ihr Passwort ist zu einfach. bitte wählen Sie ein sicheres Passwort!'."\nDie Fehlermeldung lautet: »{$crack}«");
149)                          return false;
150)                        }
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;
160)   }
161) 
162)   $spam = 'NULL';
163)   switch ($account['spamfilter'])
164)   {
165)     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)       $spam = "'folder'";
172)       break;
173)     case 'tag':
174)       $spam = "'tag'";
175)       break;
176)     case 'delete':
177)       $spam = "'delete'";
178)       break;
179)   }
180) 
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)   $account['local'] = mysql_real_escape_string($account['local']);
201)   $account['data'] = mysql_real_escape_string($account['data']);
202)   $account['spamexpire'] = (int) $account['spamexpire'];
203)   $account['virusexpire'] = (int) $account['virusexpire'];
204) 
205)   $query = '';
206)   if ($id == NULL)
207)   {
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']});";
210)   }
211)   else
212)   {
213)     $password = ", data='{$account['data']}'";
214)     if ($account['data'] == '')
215)       $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']} ";
218)     $query .= "WHERE id={$id} LIMIT 1;";
219)   }
220)   db_query($query); 
bernd Benachrichtige vmail-userac...

bernd authored 16 years ago

221) 
222)   if ($type == 'mailbox')
223)   {
224)     # notify the vmail subsystem of this new account
225)     mail('vmail@schokokeks.org', 'command', "user={$account['local']}\nhost={$domainname}", "X-schokokeks-org-message: command");
226)   }
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

227) }
228) 
229) 
230) 
bernd Löschen geht jetzt auch

bernd authored 16 years ago

231) function delete_account($id)
232) {
233)   $account = get_account_details($id);
234)   db_query("DELETE FROM mail.virtual_mail WHERE id={$account['id']};");
235) }
236)