ce0caaf4a67def494ea8ed9153053f062bb26ff2
bernd webinterface => /webinterface

bernd authored 17 years ago

1) <?php
2) 
3) require_once('inc/debug.php');
4) require_once('inc/db_connect.php');
bernd Logging aktiviert

bernd authored 16 years ago

5) require_once('inc/base.php');
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

6) require_once('inc/security.php');
bernd webinterface => /webinterface

bernd authored 17 years ago

7) 
bernd Domain-Klasse benutzen

bernd authored 16 years ago

8) require_once('class/domain.php');
9) 
bernd webinterface => /webinterface

bernd authored 17 years ago

10) function mailaccounts($uid)
11) {
12)   $uid = (int) $uid;
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

13)   $result = db_query("SELECT m.id,concat_ws('@',`m`.`local`,if(isnull(`m`.`domain`),_utf8'schokokeks.org',`d`.`domainname`)) AS `account`, `m`.`password` AS `cryptpass`,`m`.`maildir` AS `maildir`,aktiv from (`mail`.`mailaccounts` `m` left join `mail`.`v_domains` `d` on((`d`.`id` = `m`.`domain`))) WHERE m.uid=$uid");
bernd webinterface => /webinterface

bernd authored 17 years ago

14)   DEBUG("Found ".@mysql_num_rows($result)." rows!");
15)   $accounts = array();
16)   if (@mysql_num_rows($result) > 0)
17)     while ($acc = @mysql_fetch_object($result))
18)       array_push($accounts, array('id'=> $acc->id, 'account' => $acc->account, 'mailbox' => $acc->maildir, 'cryptpass' => $acc->cryptpass, 'enabled' => ($acc->aktiv == 1)));
19)   return $accounts;
20) }
21) 
22) function get_mailaccount($id)
23) {
24)   $uid = (int) $uid;
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

25)   $result = db_query("SELECT concat_ws('@',`m`.`local`,if(isnull(`m`.`domain`),_utf8'schokokeks.org',`d`.`domainname`)) AS `account`, `m`.`password` AS `cryptpass`,`m`.`maildir` AS `maildir`,aktiv from (`mail`.`mailaccounts` `m` left join `mail`.`v_domains` `d` on((`d`.`id` = `m`.`domain`))) WHERE m.id=$id");
bernd webinterface => /webinterface

bernd authored 17 years ago

26)   DEBUG("Found ".mysql_num_rows($result)." rows!");
27)   $acc = mysql_fetch_object($result);
28)   $ret = array('account' => $acc->account, 'mailbox' => $acc->maildir,  'enabled' => ($acc->aktiv == 1));
29)   DEBUG(print_r($ret, true));
30)   return $ret;
31) }
32) 
33) function encrypt_mail_password($pw)
34) {
35)   DEBUG("unencrypted PW: ".$pw);
bernd pashword-hashing ohne Aufru...

bernd authored 16 years ago

36)   require_once('inc/base.php');
37)   $salt = random_string(8);
38)   $encpw = crypt($pw, "\$1\${$salt}\$");
bernd webinterface => /webinterface

bernd authored 17 years ago

39)   DEBUG("encrypted PW: ".$encpw);
40)   return chop($encpw);
41) 
42) }
43) 
44) function change_mailaccount($id, $arr)
45) {
46)   $id = (int) $id;
47)   $conditions = array();
48) 
49)   if (isset($arr['account']))
50)   {
51)     list($local, $domain) = explode('@', $arr['account'], 2);
bernd Domain-Klasse benutzen

bernd authored 16 years ago

52)     $domain = new Domain( (string) $domain);
53)     if ($domain->id == NULL)
54)       array_push($conditions, "domain=NULL");
55)     else
56)       array_push($conditions, "domain={$domain->id}");
57) 
58)     array_push($conditions, "local='".mysql_real_escape_string($local)."'");
bernd webinterface => /webinterface

bernd authored 17 years ago

59)   }
60)   if (isset($arr['mailbox']))
61)     if ($arr['mailbox'] == '')
62)       array_push($conditions, "`maildir`=NULL");
63)     else
64)       array_push($conditions, "`maildir`='".mysql_real_escape_string($arr['mailbox'])."'");
65) 
66)   if (isset($arr['password']))
67)   {
68)     $encpw = encrypt_mail_password($arr['password']);
69)     array_push($conditions, "`password`='$encpw'");
70)   }
71) 
72)   if (isset($arr['enabled']))
73)     array_push($conditions, "`aktiv`=".($arr['enabled'] == 'Y' ? "1" : "0"));
74) 
75) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

76)   db_query("UPDATE mail.mailaccounts SET ".implode(",", $conditions)." WHERE id='$id' LIMIT 1");
bernd Logging aktiviert

bernd authored 16 years ago

77)   logger("modules/imap/include/mailaccounts.php", "imap", "updated account »{$arr['account']}«");
bernd webinterface => /webinterface

bernd authored 17 years ago

78) 
79) }
80) 
81) function create_mailaccount($arr)
82) {
83)   $values = array();
84) 
85)   if (($arr['account']) == '')
86)     system_failure('empty account name!');
87) 
88)   $values['uid'] = (int) $_SESSION['userinfo']['uid'];
89) 
90)   list($local, $domain) = explode('@', $arr['account'], 2);
bernd Domain-Klasse benutzen

bernd authored 16 years ago

91)   $domain = new Domain( (string) $domain);
92)   if ($domain->id == NULL)
93)     $values['domain'] = "NULL";
94)   else
95)     $values['domain'] = $domain->id;
96) 
bernd webinterface => /webinterface

bernd authored 17 years ago

97)   $values['local'] = "'".mysql_real_escape_string($local)."'";
98) 
99)   if (isset($arr['mailbox']))
100)     if ($arr['mailbox'] == '')
101)       $values['maildir'] = 'NULL';
102)     else
103)       $values['maildir']= "'".mysql_real_escape_string($arr['mailbox'])."'";
104) 
105) 
106)   if (isset($arr['password']))
107)   {
108)     $values['password'] = "'".encrypt_mail_password($arr['password'])."'";
109)   }
110) 
111)   if (isset($arr['enabled']))
112)     $values['aktiv'] = ($arr['enabled'] == 'Y' ? "1" : "0" );
113) 
114) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

115)   db_query("INSERT INTO mail.mailaccounts (".implode(',', array_keys($values)).") VALUES (".implode(",", array_values($values)).")");
bernd Logging aktiviert

bernd authored 16 years ago

116)   logger("modules/imap/include/mailaccounts.php", "imap", "created account »{$arr['account']}«");
bernd webinterface => /webinterface

bernd authored 17 years ago

117) 
118) }
119) 
bernd Auch mailaccounts können si...

bernd authored 16 years ago

120)     
121) function get_mailaccount_id($accountname)
122) {
123)   list($local, $domain) = explode('@', $accountname, 2);
124)   if ($domain == 'schokokeks.org')
125)     $domain = '';
126) 
127)   $local = mysql_real_escape_string($local);
128)   $domain = maybe_null($domain);
129) 
130)   $result = db_query("SELECT acc.id FROM mail.mailaccounts AS acc LEFT JOIN mail.v_domains AS dom ON (dom.id=acc.domain) WHERE local='{$local}' AND dom.domainname={$domain}");
131)   if (mysql_num_rows($result) != 1)
132)     system_failure('account nicht eindeutig');
133)   $acc = mysql_fetch_assoc($result);
134)   return $acc['id'];
135) }
136)     
bernd webinterface => /webinterface

bernd authored 17 years ago

137) 
138) function delete_mailaccount($id)
139) {
140)   $id = (int) $id;
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

141)   db_query("DELETE FROM mail.mailaccounts WHERE id=".$id." LIMIT 1");
bernd Logging aktiviert

bernd authored 16 years ago

142)   logger("modules/imap/include/mailaccounts.php", "imap", "deleted account »{$id}«");
bernd webinterface => /webinterface

bernd authored 17 years ago

143) }
144) 
145) 
146) function check_valid($acc)
147) {
148)   $user = $_SESSION['userinfo'];
149)   DEBUG("Account-data: ".print_r($acc, true));
150)   DEBUG("User-data: ".print_r($user, true));
151)   if ($acc['mailbox'] != '')
152)   {
153)     if (substr($acc['mailbox'], 0, strlen($user['homedir'])+1) != $user['homedir'].'/')
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

154)       return "Die Mailbox muss innerhalb des Home-Verzeichnisses liegen. Sie haben »".$acc['mailbox']."« als Mailbox angegeben, Ihr Home-Verzeichnis ist »".$user['homedir']."/«.";
155)     if (! check_path($acc['mailbox']))
bernd webinterface => /webinterface

bernd authored 17 years ago

156)       return "Sie verwenden ungültige Zeichen in Ihrem Mailbox-Pfad.";
157)   }
158) 
159)   if ($acc['account'] == '' || strpos($acc['account'], '@') == 0)
160)     return "Es wurde kein Benutzername angegeben!";
161)   if (strpos($acc['account'], '@') === false)
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

162)     return "Es wurde kein Domain-Teil im Account-Name angegeben. Account-Namen müssen einen Domain-Teil enthalten. Im Zweifel versuchen Sie »@schokokeks.org«.";
bernd webinterface => /webinterface

bernd authored 17 years ago

163) 
164)   list($local, $domain) = explode('@', $acc['account'], 2);
hanno Hatte die Kompatibilität ge...

hanno authored 16 years ago

165)   verify_input_username($local);
bernd Domain-Klasse benutzen

bernd authored 16 years ago

166)   $tmpdomains = get_domain_list($user['customerno'], $user['uid']);
bernd webinterface => /webinterface

bernd authored 17 years ago

167)   $domains = array();
168)   foreach ($tmpdomains as $dom)
bernd Domain-Klasse benutzen

bernd authored 16 years ago

169)     $domains[] = $dom->fqdn;
bernd webinterface => /webinterface

bernd authored 17 years ago

170) 
171)   if (array_search($domain, $domains) === false)
172)   {
173)     if ($domain == "schokokeks.org")
174)     {
175)       if (substr($local, 0, strlen($user['username'])) != $user['username'] || ($acc['account'][strlen($user['username'])] != '-' && $acc['account'][strlen($user['username'])] != '@'))
176)       {
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

177)         return "Sie haben »@schokokeks.org« als Domain-Teil angegeben, aber der Benutzer-Teil beginnt nicht mit Ihrem Benutzername!";
bernd webinterface => /webinterface

bernd authored 17 years ago

178)       }
179)     }
180)     else
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

181)       return "Der angegebene Domain-Teil (»".htmlentities($domain, ENT_QUOTES, "UTF-8")."«) ist nicht für Ihren Account eingetragen. Sollte dies ein Fehler sein, wenden sie sich bitte an einen Administrator!";