255b2a4acc8e2f21a8614d404bc5d527d489678b
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,
13) 		'type' => 'mailbox',
14) 		'data' => NULL,
bernd Spam- und viren nur noch ei...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

141) 		     $type = 'forward';
142)                      break;
143)     case 'mailbox':
144)                      $account['data'] = stripslashes($account['data']);
145)                      if ($account['data'] != '')
146)                      {
147)                        $crack = strong_password($account['data']);
148)                        if ($crack !== true)
149)                        {
150)                          input_error('Ihr Passwort ist zu einfach. bitte wählen Sie ein sicheres Passwort!'."\nDie Fehlermeldung lautet: »{$crack}«");
151)                          return false;
152)                        }
153)                        $account['data'] = encrypt_mail_password($account['data']);
154)                      }
155)                      $type = 'mailbox';
156)                      break;
157)   }
158)   if ($type == NULL)
159)   {
160)     input_error('Problem mit der »type«-Variable!');
161)     return false;
162)   }
163) 
164)   $spam = 'NULL';
165)   switch ($account['spamfilter'])
166)   {
167)     case 'folder':
168)       if ($type == 'forward')
169)       {
170)         input_error('Sie können nicht in einen IMAP-Unterordner zustellen lassen, wenn Sie gar kein IMAP-Konto anlegen!');
171) 	return false;
172)       }
173)       $spam = "'folder'";
174)       break;
175)     case 'tag':
176)       $spam = "'tag'";
177)       break;
178)     case 'delete':
179)       $spam = "'delete'";
180)       break;
181)   }
182) 
183)   $virus = 'NULL';
184)   switch ($account['virusfilter'])
185)   {
186)     case 'folder':
187)       if ($type == 'forward')
188)       {
189)         input_error('Sie können nicht in einen IMAP-Unterordner zustellen lassen, wenn Sie gar kein IMAP-Konto anlegen!');
190) 	return false;
191)       }
192)       $virus = "'folder'";
193)       break;
194)     case 'tag':
195)       $virus = "'tag'";
196)       break;
197)     case 'delete':
198)       $virus = "'delete'";
199)       break;
200)   }
201) 
202)   $account['local'] = mysql_real_escape_string($account['local']);
203)   $account['data'] = mysql_real_escape_string($account['data']);
204)   $account['spamexpire'] = (int) $account['spamexpire'];
205)   $account['virusexpire'] = (int) $account['virusexpire'];
206) 
207)   $query = '';
208)   if ($id == NULL)
209)   {
210)     $query = "INSERT INTO mail.virtual_mail (local, domain, type, data, spamfilter, virusfilter, spamexpire, virusexpire) VALUES ";
211)     $query .= "('{$account['local']}', {$account['domain']}, '{$type}', '{$account['data']}', {$spam}, {$virus}, {$account['spamexpire']}, {$account['virusexpire']});";
212)   }
213)   else
214)   {
215)     $password = ", data='{$account['data']}'";
216)     if ($account['data'] == '')
217)       $password = '';
218)     $query = "UPDATE mail.virtual_mail SET local='{$account['local']}', domain={$account['domain']}, type='{$type}'{$password}, ";
219)     $query .= "spamfilter={$spam}, virusfilter={$virus}, spamexpire={$account['spamexpire']}, virusexpire={$account['virusexpire']} ";
220)     $query .= "WHERE id={$id} LIMIT 1;";
221)   }
222)   db_query($query); 
bernd Benachrichtige vmail-userac...

bernd authored 16 years ago

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

bernd authored 16 years ago

229) }
230) 
231) 
232) 
bernd Löschen geht jetzt auch

bernd authored 16 years ago

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