c0d71b322d25d96ffd425f30120f12c4371406b0
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 webinterface => /webinterface

bernd authored 17 years ago

6) 
bernd Domain-Klasse benutzen

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

12)   $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

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

bernd authored 16 years ago

24)   $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

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

116) 
117) }
118) 
119) 
120) function delete_mailaccount($id)
121) {
122)   $id = (int) $id;
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

125) }
126) 
127) 
128) function check_valid($acc)
129) {
130)   $user = $_SESSION['userinfo'];
131)   DEBUG("Account-data: ".print_r($acc, true));
132)   DEBUG("User-data: ".print_r($user, true));
133)   if ($acc['mailbox'] != '')
134)   {
135)     if (substr($acc['mailbox'], 0, strlen($user['homedir'])+1) != $user['homedir'].'/')
136)       return "Die Mailbox muss innerhalb des Home-Verzeichnisses liegen. Sie haben \"".$acc['mailbox']."\" als Mailbox angegeben, Ihre Home-Verzeichnis ist \"".$user['homedir']."/\".";
137)     if (strstr($acc['mailbox'], '..') or ! preg_match('/^[a-z0-9.\/_-]*$/', $acc['mailbox']))
138)       return "Sie verwenden ungültige Zeichen in Ihrem Mailbox-Pfad.";
139)   }
140) 
141)   if ($acc['account'] == '' || strpos($acc['account'], '@') == 0)
142)     return "Es wurde kein Benutzername angegeben!";
143)   if (strpos($acc['account'], '@') === false)
144)     return "Es wurde kein Domain-Teil im Account-Name angegeben. Account-Namen m&uuml;ssen einen Domain-Teil enthalten. Im Zweifel versuchen Sie &quot;@schokokeks.org&quot;.";
145) 
146)   list($local, $domain) = explode('@', $acc['account'], 2);
bernd Domain-Klasse benutzen

bernd authored 16 years ago

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

bernd authored 17 years ago

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

bernd authored 16 years ago

150)     $domains[] = $dom->fqdn;