83d84151cce9becf193a835f58e12b2b579d174e
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) 
22) function get_account_details($id)
23) {
24) 	$id = (int) $id;
25) 	$uid = (int) $_SESSION['userinfo']['uid'];
bernd Anpassung auf neues Interface

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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;
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

43) }
44) 
45) function get_vmail_accounts()
46) {
47) 	$uid = (int) $_SESSION['userinfo']['uid'];
48) 	$result = db_query("SELECT * from mail.v_virtual_mail WHERE useraccount='{$uid}'");
49) 	$ret = array();
50) 	while ($line = mysql_fetch_assoc($result))
51) 	{
52) 		array_push($ret, $line);
53) 	}
54) 	DEBUG($ret);
55) 	return $ret;
56) }
57) 
58) 
59) 
60) function get_vmail_domains()
61) {
62) 	$uid = (int) $_SESSION['userinfo']['uid'];
63) 	$result = db_query("SELECT id, domainname FROM mail.v_vmail_domains WHERE useraccount='{$uid}'");
64) 	if (mysql_num_rows($result) == 0)
65) 		system_failure('Sie haben keine Domains für virtuelle Mail-Verarbeitung');
66) 	$ret = array();
67) 	while ($tmp = mysql_fetch_object($result))
68) 		array_push($ret, $tmp);
69) 	return $ret;
70) }
71) 
72) 
73) 
74) function domainselect($selected = NULL, $selectattribute = '')
75) {
bernd Bugfix: Funktion-Dopplung v...

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

125)   foreach ($domainlist as $dom)
126)   {
127)     if ($dom->id == $account['domain'])
128)     {
bernd Benachrichtige vmail-userac...

bernd authored 16 years ago

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

bernd authored 16 years ago

130)       $valid_domain = true;
131)       break;
132)     }
133)   }
134)   if (($account['domain'] == 0) || (! $valid_domain))
135)   {
136)     input_error('Bitte wählen Sie eine Ihrer Domains aus!');
137)     return false;
138)   }
bernd Anpassung auf neues Interface

bernd authored 16 years ago

139)   
140)   $forwards = array();
141)   if (count($account['forwards']) > 0) 
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

142)   {
bernd Anpassung auf neues Interface

bernd authored 16 years ago

143)     for ($i=0;$i < count($account['forwards']); $i++)
144)     {
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!');
150)     }
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

151)   }
bernd Anpassung auf neues Interface

bernd authored 16 years ago

152)     
153)   $password='NULL';
154)   if ($account['password'] != '')
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

155)   {
bernd Anpassung auf neues Interface

bernd authored 16 years ago

156)     $account['password'] = stripslashes($account['password']);
157)     $crack = strong_password($account['password']);
158)     if ($crack !== true)
159)     {
160)       input_error('Ihr Passwort ist zu einfach. bitte wählen Sie ein sicheres Passwort!'."\nDie Fehlermeldung lautet: »{$crack}«");
161)       return false;
162)     }
163)     $password = "'".encrypt_mail_password($account['password'])."'";
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

164)   }
bernd Anpassung auf neues Interface

bernd authored 16 years ago

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

bernd authored 16 years ago

168) 
169)   $spam = 'NULL';
170)   switch ($account['spamfilter'])
171)   {
172)     case 'folder':
173)       $spam = "'folder'";
174)       break;
175)     case 'tag':
176)       $spam = "'tag'";
177)       break;
178)     case 'delete':
179)       $spam = "'delete'";
180)       break;
181)   }
182) 
183)   $account['local'] = mysql_real_escape_string($account['local']);
bernd Anpassung auf neues Interface

bernd authored 16 years ago

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

bernd authored 16 years ago

185)   $account['spamexpire'] = (int) $account['spamexpire'];
186) 
187)   $query = '';
188)   if ($id == NULL)
189)   {
bernd Anpassung auf neues Interface

bernd authored 16 years ago

190)     $query = "INSERT INTO mail.vmail_accounts (local, domain, spamfilter, spamexpire, password) VALUES ";
191)     $query .= "('{$account['local']}', {$account['domain']}, {$spam}, {$account['spamexpire']}, {$account['password']});";
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

192)   }
193)   else
194)   {
bernd Anpassung auf neues Interface

bernd authored 16 years ago

195)     if ($set_password)
196)       $password=", password={$password}";
197)     else
198)       $password='';
199)     $query = "UPDATE mail.vmail_accounts SET local='{$account['local']}', domain={$account['domain']}{$password}, ";
200)     $query .= "spamfilter={$spam}, spamexpire={$account['spamexpire']} ";
bernd Erste Version des vmail-Modul

bernd authored 16 years ago

201)     $query .= "WHERE id={$id} LIMIT 1;";
202)   }
203)   db_query($query); 
bernd Anpassung auf neues Interface

bernd authored 16 years ago

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')
bernd Benachrichtige vmail-userac...

bernd authored 16 years ago

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

bernd authored 16 years ago

224) }
225) 
226) 
227) 
bernd Löschen geht jetzt auch

bernd authored 16 years ago

228) function delete_account($id)
229) {
230)   $account = get_account_details($id);
bernd Anpassung auf neues Interface

bernd authored 16 years ago

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

bernd authored 16 years ago

232) }
233)