b631cd6b333df489dfe4cd0c306194fdc828ffe9
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 Anpassung auf neues Interface

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) 
bernd VMail-accounts können sich...

bernd authored 16 years ago

22) function get_account_details($id, $checkuid = true)
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

23) {
24) 	$id = (int) $id;
25) 	$uid = (int) $_SESSION['userinfo']['uid'];
bernd VMail-accounts können sich...

bernd authored 16 years ago

26) 	$uid_check = ($checkuid ? "useraccount='{$uid}' AND " : "");
27) 	$result = db_query("SELECT id, local, domain, password, spamfilter, forwards from mail.v_vmail_accounts WHERE {$uid_check}id={$id} LIMIT 1");
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

28) 	if (mysql_num_rows($result) == 0)
29) 		system_failure('Ungültige ID oder kein eigener Account');
bernd Anpassung auf neues Interface

bernd authored 16 years ago

30) 	$acc = empty_account();
31) 	$res = mysql_fetch_assoc($result);
32) 	foreach ($res AS $key => $value) {
33) 	  if ($key == 'forwards')
34) 	    continue;
35) 	  $acc[$key] = $value;
36) 	}
37) 	if ($acc['forwards'] > 0) {
38) 	  $result = db_query("SELECT id, spamfilter, destination FROM mail.vmail_forward WHERE account={$acc['id']};");
39) 	  while ($item = mysql_fetch_assoc($result)){
40) 	    array_push($acc['forwards'], array("id" => $item['id'], 'spamfilter' => $item['spamfilter'], 'destination' => $item['destination']));
41) 	  }
42) 	}
43) 	return $acc;
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

44) }
45) 
46) function get_vmail_accounts()
47) {
48) 	$uid = (int) $_SESSION['userinfo']['uid'];
bernd Bugfixes

bernd authored 16 years ago

49) 	$result = db_query("SELECT * from mail.v_vmail_accounts WHERE useraccount='{$uid}'");
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

50) 	$ret = array();
51) 	while ($line = mysql_fetch_assoc($result))
52) 	{
53) 		array_push($ret, $line);
54) 	}
55) 	DEBUG($ret);
56) 	return $ret;
57) }
58) 
59) 
60) 
61) function get_vmail_domains()
62) {
63) 	$uid = (int) $_SESSION['userinfo']['uid'];
64) 	$result = db_query("SELECT id, domainname FROM mail.v_vmail_domains WHERE useraccount='{$uid}'");
65) 	if (mysql_num_rows($result) == 0)
66) 		system_failure('Sie haben keine Domains für virtuelle Mail-Verarbeitung');
67) 	$ret = array();
68) 	while ($tmp = mysql_fetch_object($result))
69) 		array_push($ret, $tmp);
70) 	return $ret;
71) }
72) 
73) 
bernd VMail-accounts können sich...

bernd authored 16 years ago

74) function find_account_id($accname)
75) {
76)   $accname = mysql_real_escape_string($accname);
77)   DEBUG($accname);
78)   $tmp = explode('@', $accname, 2);
79)   DEBUG($tmp);
80)   if (count($tmp) != 2)
81)     system_failure("Der Account hat nicht die korrekte Syntax");
82)   list( $local, $domainname) = $tmp;
83) 
84)   $result = db_query("SELECT id FROM mail.v_vmail_accounts WHERE local='{$local}' AND domainname='{$domainname}' LIMIT 1");
85)   if (mysql_num_rows($result) == 0)
86)     system_failure("Der Account konnte nicht gefunden werden");
87)   $tmp = mysql_fetch_array($result);
88)   return $tmp[0];
89) }
90) 
91) 
92) function change_vmail_password($accname, $newpass)
93) {
94)   $accid = find_account_id($accname);
95)   $encpw = mysql_real_escape_string(encrypt_mail_password($newpass));
96)   db_query("UPDATE mail.vmail_accounts SET password='{$encpw}' WHERE id={$accid} LIMIT 1;");
97) }
98) 
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

99) 
100) function domainselect($selected = NULL, $selectattribute = '')
101) {
bernd Bugfix: Funktion-Dopplung v...

bernd authored 16 years ago

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

bernd authored 16 years ago

103)   $selected = (int) $selected;
104) 
105)   $ret = '<select id="domain" name="domain" size="1" '.$selectattribute.' >';
106)   foreach ($domainlist as $dom)
107)   {
108)     $s = ($selected == $dom->id) ? ' selected="selected" ': '';
109)     $ret .= "<option value=\"{$dom->id}\"{$s}>{$dom->domainname}</option>\n";
110)   }
111)   $ret .= '</select>';
112)   return $ret;
113) }
114) 
115) 
116) function encrypt_mail_password($pw)
117) {
118)   DEBUG("unencrypted PW: ".$pw);
119)   require_once('inc/base.php');
120)   $salt = random_string(8);
121)   $encpw = crypt($pw, "\$1\${$salt}\$");
122)   DEBUG("encrypted PW: ".$encpw);
123)   return chop($encpw);
124) 
125) }
126) 
127) 
128) 
129) function save_vmail_account($account)
130) {
131)   $uid = (int) $_SESSION['userinfo']['uid'];
132)   $id = $account['id'];
133)   if ($id != NULL)
134)   {
135)     $id = (int) $id;
136)     $oldaccount = get_account_details($id);
137)     // Erzeugt einen system_error() wenn ID ungültig
138)   }
139)   // Ab hier ist $id sicher, entweder NULL oder eine gültige ID des aktuellen users
140) 
141)   $account['local'] = filter_input_username($account['local']);
142)   if ($account['local'] == '')
143)   {
144)     input_error('Die E-Mail-Adresse braucht eine Angabe vor dem »@«!');
145)     return false;
146)   }
147)   $account['domain'] = (int) $account['domain'];
148)   $domainlist = get_vmail_domains();
149)   $valid_domain = false;
bernd Benachrichtige vmail-userac...

bernd authored 16 years ago

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

bernd authored 16 years ago

151)   foreach ($domainlist as $dom)
152)   {
153)     if ($dom->id == $account['domain'])
154)     {
bernd Benachrichtige vmail-userac...

bernd authored 16 years ago

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

bernd authored 16 years ago

156)       $valid_domain = true;
157)       break;
158)     }
159)   }
160)   if (($account['domain'] == 0) || (! $valid_domain))
161)   {
162)     input_error('Bitte wählen Sie eine Ihrer Domains aus!');
163)     return false;
164)   }
bernd Anpassung auf neues Interface

bernd authored 16 years ago

165)   
166)   $forwards = array();
167)   if (count($account['forwards']) > 0) 
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

168)   {
bernd Anpassung auf neues Interface

bernd authored 16 years ago

169)     for ($i=0;$i < count($account['forwards']); $i++)
170)     {
171)       if ($account['forwards'][$i]['spamfilter'] != 'tag' && $account['forwards'][$i]['spamfilter'] != 'delete')
172)         $account['forwards'][$i]['spamfilter'] = '';
173)       $account['forwards'][$i]['destination'] = filter_input_general($account['forwards'][$i]['destination']);
174)       if (! check_emailaddr($account['forwards'][$i]['destination']))
175)         system_failure('Das Weiterleitungs-Ziel »'.$account['forwards'][$i]['destination'].'« ist keine E-Mail-Adresse!');
176)     }
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

177)   }
bernd Anpassung auf neues Interface

bernd authored 16 years ago

178)     
179)   $password='NULL';
180)   if ($account['password'] != '')
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

181)   {
bernd Anpassung auf neues Interface

bernd authored 16 years ago

182)     $account['password'] = stripslashes($account['password']);
183)     $crack = strong_password($account['password']);
184)     if ($crack !== true)
185)     {
186)       input_error('Ihr Passwort ist zu einfach. bitte wählen Sie ein sicheres Passwort!'."\nDie Fehlermeldung lautet: »{$crack}«");
187)       return false;
188)     }
189)     $password = "'".encrypt_mail_password($account['password'])."'";
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

190)   }
bernd Anpassung auf neues Interface

bernd authored 16 years ago

191)   $set_password = ($id == NULL || $password != 'NULL');
192)   if ($account['password'] === NULL)
193)     $set_password=true;
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

194) 
195)   $spam = 'NULL';
196)   switch ($account['spamfilter'])
197)   {
198)     case 'folder':
199)       $spam = "'folder'";
200)       break;
201)     case 'tag':
202)       $spam = "'tag'";
203)       break;
204)     case 'delete':
205)       $spam = "'delete'";
206)       break;
207)   }
208) 
209)   $account['local'] = mysql_real_escape_string($account['local']);
bernd Anpassung auf neues Interface

bernd authored 16 years ago

210)   $account['password'] = mysql_real_escape_string($account['password']);
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

211)   $account['spamexpire'] = (int) $account['spamexpire'];
212) 
213)   $query = '';
214)   if ($id == NULL)
215)   {
bernd Anpassung auf neues Interface

bernd authored 16 years ago

216)     $query = "INSERT INTO mail.vmail_accounts (local, domain, spamfilter, spamexpire, password) VALUES ";
bernd Bei neuen Accounts wurde da...

bernd authored 16 years ago

217)     $query .= "('{$account['local']}', {$account['domain']}, {$spam}, {$account['spamexpire']}, {$password});";
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

218)   }
219)   else
220)   {
bernd Anpassung auf neues Interface

bernd authored 16 years ago

221)     if ($set_password)
222)       $password=", password={$password}";
223)     else
224)       $password='';
225)     $query = "UPDATE mail.vmail_accounts SET local='{$account['local']}', domain={$account['domain']}{$password}, ";
226)     $query .= "spamfilter={$spam}, spamexpire={$account['spamexpire']} ";
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

227)     $query .= "WHERE id={$id} LIMIT 1;";
228)   }
229)   db_query($query); 
bernd Bugfixes

bernd authored 16 years ago

230)   if ($id)
231)     db_query("DELETE FROM mail.vmail_forward WHERE account={$id}");
bernd VMail-accounts können sich...

bernd authored 16 years ago

232)   else
233)     $id = mysql_insert_id();
234) 
bernd Anpassung auf neues Interface

bernd authored 16 years ago

235)   if (count($account['forwards']) > 0)
236)   {
237)     $forward_query = "INSERT INTO mail.vmail_forward (account,spamfilter,destination) VALUES ";
238)     $first = true;
239)     for ($i=0;$i < count($account['forwards']); $i++)
240)     { 
241)       if ($first)
242)         $first = false;
243)       else
244)         $forward_query .= ', ';
245)       $forward_query .= "({$id}, ".maybe_null($account['forwards'][$i]['spamfilter']).", '{$account['forwards'][$i]['destination']}')";
246)     }
247)     db_query($forward_query);
248)   }
249)   if ($account['password'] != 'NULL')
bernd Benachrichtige vmail-userac...

bernd authored 16 years ago

250)   {
251)     # notify the vmail subsystem of this new account
252)     mail('vmail@schokokeks.org', 'command', "user={$account['local']}\nhost={$domainname}", "X-schokokeks-org-message: command");
253)   }
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

254) }
255) 
256) 
257) 
bernd Löschen geht jetzt auch

bernd authored 16 years ago

258) function delete_account($id)
259) {
260)   $account = get_account_details($id);
bernd Anpassung auf neues Interface

bernd authored 16 years ago

261)   db_query("DELETE FROM mail.vmail_accounts WHERE id={$account['id']};");
bernd Löschen geht jetzt auch

bernd authored 16 years ago

262) }
263)