1 | <? |
---|
2 | require_once("m_mail.php"); |
---|
3 | |
---|
4 | class m_mail_egw extends m_mail { |
---|
5 | |
---|
6 | function create($dom_id, $mail, $type = "", $dontcheck = false) { |
---|
7 | if ($this->_add_egw_account($dom_id, $mail, $type = "", $dontcheck = false)) |
---|
8 | if (parent::create($dom_id,$mail,$type="",$dontcheck=false)) |
---|
9 | return true; |
---|
10 | else |
---|
11 | return false; |
---|
12 | else |
---|
13 | return false; |
---|
14 | } |
---|
15 | |
---|
16 | function delete($mail_id) { |
---|
17 | |
---|
18 | if ($this->_del_egw_account($mail_id) ) |
---|
19 | if (parent::delete($mail_id)) |
---|
20 | return true; |
---|
21 | else |
---|
22 | return false; |
---|
23 | else |
---|
24 | return false; |
---|
25 | } |
---|
26 | |
---|
27 | function _add_egw_account($dom_id, $mail, $type = "", $dontcheck = false) { |
---|
28 | global $err, $db, $quota, $dom, $hooks, $L_EGW_ADMINCLI, $L_EGW_ADMINUSER, $L_EGW_ADMINCLAVE; |
---|
29 | $res = true; |
---|
30 | $err->log("mail", "create_egwclass", "$mail $dom_id"); |
---|
31 | $domain = $dom->get_domain_byid($dom_id); |
---|
32 | $err->log("mail", "create_egwclass", "$mail $domain"); |
---|
33 | |
---|
34 | |
---|
35 | // armamos el commando a executar en el cli de egw |
---|
36 | $admincli= $L_EGW_ADMINCLI; |
---|
37 | $command= "--edit-user"; // Command to be performed |
---|
38 | $adminuser= $L_EGW_ADMINUSER; |
---|
39 | $adminclave= $L_EGW_ADMINCLAVE; |
---|
40 | //$adminclave= "*******"; |
---|
41 | |
---|
42 | $firstname = $mail; // the left side of the email |
---|
43 | $lastname= "-"; // we have a generic lastname |
---|
44 | $pass= "*****"; //TEMPORARY |
---|
45 | $email = $account = $mail ."@" .$domain; // account and email are the same |
---|
46 | $expires= "never"; |
---|
47 | $canchangepw= "yes"; |
---|
48 | $anonuser= "no"; |
---|
49 | // $primarygroup = $domain[$size-3]; // domains in .ar starts at the third level |
---|
50 | $primarygroup= "cta"; //TEMPORARY |
---|
51 | // $secondarygroup = $domain[$size-4]; // sub-domain is used as a secondary group |
---|
52 | $homedir = "/home/". $mail ."_" .$domain; // everyone can have a home |
---|
53 | $loginshell = "/bin/bash"; // everyone can have a shell |
---|
54 | |
---|
55 | $go= $admincli ." " .$command ." " .$adminuser ."," .$adminclave .",\"" .$account ."\"," .$firstname ."," .$lastname ."," .$pass .",\"" .$email ."\"," .$expires ."," .$canchangepw ."," .$anonuser ."," .$primarygroup ; |
---|
56 | |
---|
57 | $go= $go ."," .$homedir ."," .$loginshell ; |
---|
58 | |
---|
59 | echo "<h3>Creamos la cuenta en la base ldap</h3>"; |
---|
60 | // echo "<h4>$go</h4>"; // LA CLAVE SALE... ACA |
---|
61 | |
---|
62 | $cod = exec($go); |
---|
63 | if ($cod) |
---|
64 | { |
---|
65 | // die ($cod); |
---|
66 | echo "<p class=\"error\">"; |
---|
67 | echo $cod; |
---|
68 | echo "</p>"; |
---|
69 | //$res = false; |
---|
70 | } |
---|
71 | |
---|
72 | // mandamos el codigo de error en /var/log/alternc/bureau.log |
---|
73 | $err->log("mail_egw", "create", $cod); |
---|
74 | |
---|
75 | |
---|
76 | // para no morir aca... |
---|
77 | return $res; |
---|
78 | } |
---|
79 | |
---|
80 | function _del_egw_account($mail_id) { |
---|
81 | global $err, $db, $hooks; |
---|
82 | $err->log("mail", "delete_egwclass", $mail_id); |
---|
83 | $res = true; |
---|
84 | |
---|
85 | // desde el mail_id buscamos el dominio |
---|
86 | $query="SELECT domaine FROM domaines |
---|
87 | WHERE id=(SELECT domain_id FROM address where id=\"$mail_id\")"; |
---|
88 | $result_dominio=mysql_query($query); |
---|
89 | |
---|
90 | // print resultados... |
---|
91 | while($row = mysql_fetch_assoc($result_dominio)){ |
---|
92 | foreach($row as $cname => $cvalue){print "$cname: $cvalue\t";} |
---|
93 | print "\r\n"; |
---|
94 | } |
---|
95 | // desde el mail_id buscamos la primera parte del mail |
---|
96 | $query="SELECT address FROM address WHERE id=\"$mail_id\""; |
---|
97 | // print "$query"; |
---|
98 | $result_mail=mysql_query($query); |
---|
99 | // print resultados... |
---|
100 | while($row = mysql_fetch_assoc($result_mail)){ |
---|
101 | foreach($row as $cname => $cvalue){print "$cname: $cvalue\t";} |
---|
102 | print "\r\n"; |
---|
103 | } |
---|
104 | |
---|
105 | // para no morir aca... |
---|
106 | return $res; |
---|
107 | } |
---|
108 | |
---|
109 | } |
---|
110 | |
---|
111 | ?> |
---|