fb92f399e1c896d31edec5dbc0ed57928f18d6ba
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;
10)   $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";
11)   DEBUG("SQL-Query: {$query}");
12)   $result = @mysql_query($query);
13)   if (mysql_error())
14)     system_failure(mysql_error());
15)   DEBUG("Found ".@mysql_num_rows($result)." rows!");
16)   $accounts = array();
17)   if (@mysql_num_rows($result) > 0)
18)     while ($acc = @mysql_fetch_object($result))
19)       array_push($accounts, array('id'=> $acc->id, 'account' => $acc->account, 'mailbox' => $acc->maildir, 'cryptpass' => $acc->cryptpass, 'enabled' => ($acc->aktiv == 1)));
20)   return $accounts;
21) }
22) 
23) function get_mailaccount($id)
24) {
25)   $uid = (int) $uid;
26)   $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";
27)   $result = mysql_query($query);
28)   DEBUG("Found ".mysql_num_rows($result)." rows!");
29)   $acc = mysql_fetch_object($result);
30)   $ret = array('account' => $acc->account, 'mailbox' => $acc->maildir,  'enabled' => ($acc->aktiv == 1));
31)   DEBUG(print_r($ret, true));
32)   return $ret;
33) }
34) 
35) function encrypt_mail_password($pw)
36) {
37)   DEBUG("unencrypted PW: ".$pw);
bernd pashword-hashing ohne Aufru...

bernd authored 17 years ago

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

bernd authored 17 years ago

41)   DEBUG("encrypted PW: ".$encpw);
42)   return chop($encpw);
43) 
44) }
45) 
46) function get_domain_id($domain) 
47) {
48)   $domain = mysql_real_escape_string($domain);
49)   $result = mysql_query("SELECT id FROM mail.v_domains WHERE domainname = '{$domain}';");
50)   if (mysql_num_rows($result) == 0)
51)     return NULL;
52)   return mysql_fetch_object($result)->id;
53) }
54) 
55) 
56) function change_mailaccount($id, $arr)
57) {
58)   $id = (int) $id;
59)   $conditions = array();
60) 
61)   if (isset($arr['account']))
62)   {
63)     list($local, $domain) = explode('@', $arr['account'], 2);
64)     $domainid = get_domain_id($domain);
65)     if ($domainid == NULL)
66)       $domainid='NULL';
67)     array_push($conditions, "local='".mysql_real_escape_string($local)."', domain=$domainid");
68)   }
69)   if (isset($arr['mailbox']))
70)     if ($arr['mailbox'] == '')
71)       array_push($conditions, "`maildir`=NULL");
72)     else
73)       array_push($conditions, "`maildir`='".mysql_real_escape_string($arr['mailbox'])."'");
74) 
75)   if (isset($arr['password']))
76)   {
77)     $encpw = encrypt_mail_password($arr['password']);
78)     array_push($conditions, "`password`='$encpw'");
79)   }
80) 
81)   if (isset($arr['enabled']))
82)     array_push($conditions, "`aktiv`=".($arr['enabled'] == 'Y' ? "1" : "0"));
83) 
84) 
85)   $query = "UPDATE mail.mailaccounts SET ".implode(",", $conditions)." WHERE id='$id' LIMIT 1";
86)   DEBUG("Query: ".$query);
87) 
88)   mysql_query($query);
89)   if (mysql_error())
90)     system_failure('Beim &Auml;ndern der Account-Daten ist ein Fehler aufgetreten. Sollte dies wiederholt vorkommen, senden Sie bitte die Fehlermeldung ('.mysql_error().') an einen Administrator.');
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 17 years ago

92) 
93) }
94) 
95) function create_mailaccount($arr)
96) {
97)   $values = array();
98) 
99)   if (($arr['account']) == '')
100)     system_failure('empty account name!');
101) 
102)   $values['uid'] = (int) $_SESSION['userinfo']['uid'];
103) 
104)   list($local, $domain) = explode('@', $arr['account'], 2);
105)   $domainid = get_domain_id($domain);
106)   if ($domainid == NULL)
107)     $domainid='NULL';
108)   $values['local'] = "'".mysql_real_escape_string($local)."'";
109)   $values['domain'] = $domainid;
110) 
111)   if (isset($arr['mailbox']))
112)     if ($arr['mailbox'] == '')
113)       $values['maildir'] = 'NULL';
114)     else
115)       $values['maildir']= "'".mysql_real_escape_string($arr['mailbox'])."'";
116) 
117) 
118)   if (isset($arr['password']))
119)   {
120)     $values['password'] = "'".encrypt_mail_password($arr['password'])."'";
121)   }
122) 
123)   if (isset($arr['enabled']))
124)     $values['aktiv'] = ($arr['enabled'] == 'Y' ? "1" : "0" );
125) 
126) 
127)   $query = "INSERT INTO mail.mailaccounts (".implode(',', array_keys($values)).") VALUES (".implode(",", array_values($values)).")";
128)   DEBUG("Query: ".$query);
129) 
130)   mysql_query($query);
131)   if (mysql_error())
132)     system_failure('Beim Anlegen des Kontos ist ein Fehler aufgetreten. Sollte dies wiederholt vorkommen, senden Sie bitte die Fehlermeldung ('.mysql_error().') an einen Administrator.');
bernd Logging aktiviert

bernd authored 16 years ago

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

bernd authored 17 years ago

134) 
135) }
136) 
137) 
138) function delete_mailaccount($id)
139) {
140)   $id = (int) $id;
141)   $query = "DELETE FROM mail.mailaccounts WHERE id=".$id." LIMIT 1";
142)   mysql_query($query);
143)   if (mysql_error())
144)     system_failure('Beim L&ouml;schen des Kontos ist ein Fehler aufgetreten. Sollte dies wiederholt vorkommen, senden Sie bitte die Fehlermeldung ('.mysql_error().') an einen Administrator.');
bernd Logging aktiviert

bernd authored 16 years ago

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