27f758e4ffaa2fdb83053d8b66253ae65d53e5a3
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) 
7) function mailaccounts($uid)
8) {
9)   $uid = (int) $uid;
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

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

bernd authored 16 years ago

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

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

bernd authored 16 years ago

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

bernd authored 17 years ago

36)   DEBUG("encrypted PW: ".$encpw);
37)   return chop($encpw);
38) 
39) }
40) 
41) function get_domain_id($domain) 
42) {
43)   $domain = mysql_real_escape_string($domain);
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

44)   $result = db_query("SELECT id FROM mail.v_domains WHERE domainname = '{$domain}';");
bernd webinterface => /webinterface

bernd authored 17 years ago

45)   if (mysql_num_rows($result) == 0)
46)     return NULL;
47)   return mysql_fetch_object($result)->id;
48) }
49) 
50) 
51) function change_mailaccount($id, $arr)
52) {
53)   $id = (int) $id;
54)   $conditions = array();
55) 
56)   if (isset($arr['account']))
57)   {
58)     list($local, $domain) = explode('@', $arr['account'], 2);
59)     $domainid = get_domain_id($domain);
60)     if ($domainid == NULL)
61)       $domainid='NULL';
62)     array_push($conditions, "local='".mysql_real_escape_string($local)."', domain=$domainid");
63)   }
64)   if (isset($arr['mailbox']))
65)     if ($arr['mailbox'] == '')
66)       array_push($conditions, "`maildir`=NULL");
67)     else
68)       array_push($conditions, "`maildir`='".mysql_real_escape_string($arr['mailbox'])."'");
69) 
70)   if (isset($arr['password']))
71)   {
72)     $encpw = encrypt_mail_password($arr['password']);
73)     array_push($conditions, "`password`='$encpw'");
74)   }
75) 
76)   if (isset($arr['enabled']))
77)     array_push($conditions, "`aktiv`=".($arr['enabled'] == 'Y' ? "1" : "0"));
78) 
79) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

82) 
83) }
84) 
85) function create_mailaccount($arr)
86) {
87)   $values = array();
88) 
89)   if (($arr['account']) == '')
90)     system_failure('empty account name!');
91) 
92)   $values['uid'] = (int) $_SESSION['userinfo']['uid'];
93) 
94)   list($local, $domain) = explode('@', $arr['account'], 2);
95)   $domainid = get_domain_id($domain);
96)   if ($domainid == NULL)
97)     $domainid='NULL';
98)   $values['local'] = "'".mysql_real_escape_string($local)."'";
99)   $values['domain'] = $domainid;
100) 
101)   if (isset($arr['mailbox']))
102)     if ($arr['mailbox'] == '')
103)       $values['maildir'] = 'NULL';
104)     else
105)       $values['maildir']= "'".mysql_real_escape_string($arr['mailbox'])."'";
106) 
107) 
108)   if (isset($arr['password']))
109)   {
110)     $values['password'] = "'".encrypt_mail_password($arr['password'])."'";
111)   }
112) 
113)   if (isset($arr['enabled']))
114)     $values['aktiv'] = ($arr['enabled'] == 'Y' ? "1" : "0" );
115) 
116) 
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 17 years ago

119) 
120) }
121) 
122) 
123) function delete_mailaccount($id)
124) {
125)   $id = (int) $id;
bernd sql-abfragen abstrahiert

bernd authored 16 years ago

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

bernd authored 16 years ago

127)   logger("modules/imap/include/mailaccounts.php", "imap", "deleted account »{$id}«");