391c907dc9e64ff7cf138ea4a41bcfdeae4ae5c2
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) 
120) 
121) function delete_mailaccount($id)
122) {
123)   $id = (int) $id;
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

126) }
127) 
128) 
129) function check_valid($acc)
130) {
131)   $user = $_SESSION['userinfo'];
132)   DEBUG("Account-data: ".print_r($acc, true));
133)   DEBUG("User-data: ".print_r($user, true));
134)   if ($acc['mailbox'] != '')
135)   {
136)     if (substr($acc['mailbox'], 0, strlen($user['homedir'])+1) != $user['homedir'].'/')
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

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

bernd authored 17 years ago

139)       return "Sie verwenden ungültige Zeichen in Ihrem Mailbox-Pfad.";
140)   }
141) 
142)   if ($acc['account'] == '' || strpos($acc['account'], '@') == 0)
143)     return "Es wurde kein Benutzername angegeben!";
144)   if (strpos($acc['account'], '@') === false)
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

145)     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

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

hanno authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

153) 
154)   if (array_search($domain, $domains) === false)
155)   {
156)     if ($domain == "schokokeks.org")
157)     {
158)       if (substr($local, 0, strlen($user['username'])) != $user['username'] || ($acc['account'][strlen($user['username'])] != '-' && $acc['account'][strlen($user['username'])] != '@'))
159)       {
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

160)         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

161)       }
162)     }
163)     else
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

164)       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!";