1 | <? |
---|
2 | require_once("m_mail.php"); |
---|
3 | |
---|
4 | class m_mail_egw extends m_mail { |
---|
5 | |
---|
6 | # override mail create function to add an alias |
---|
7 | function create($dom_id, $mail, $type = "", $dontcheck = false) { |
---|
8 | $status = TRUE; |
---|
9 | if ($type != 'mailman') { |
---|
10 | # check if egw worked |
---|
11 | $status = $this->_add_egw_account($dom_id, $mail, $type, $dontcheck); |
---|
12 | } |
---|
13 | return parent::create($dom_id,$mail,$type,$dontcheck); |
---|
14 | } |
---|
15 | |
---|
16 | function set_passwd($mail_id, $pass) { |
---|
17 | if ($this->_set_passwd_egw_account($mail_id, $pass) ) |
---|
18 | if (parent::set_passwd($mail_id, $pass)) |
---|
19 | return true; |
---|
20 | else |
---|
21 | return false; |
---|
22 | else |
---|
23 | return false; |
---|
24 | } |
---|
25 | |
---|
26 | function delete($mail_id) { |
---|
27 | $status = TRUE; |
---|
28 | $mailinfos = $this->get_details($mail_id); |
---|
29 | if ($mailinfos["type"] != 'mailman') { |
---|
30 | # check if egw worked |
---|
31 | $status = $this->_del_egw_account($mail_id); |
---|
32 | } |
---|
33 | return parent::delete($mail_id); # && $status; |
---|
34 | } |
---|
35 | |
---|
36 | function _set_passwd_egw_account($mail_id, $pass) { |
---|
37 | global $db, $err, $admin, $L_EGW_ADMINCLI, $L_EGW_ADMINUSER, $L_EGW_ADMINCLAVE; |
---|
38 | $res = true; |
---|
39 | //$err->log("mail", "set password egwclass", "$mail_id"); |
---|
40 | |
---|
41 | // usamos |
---|
42 | $mailinfos = $this->get_details($mail_id); |
---|
43 | $elmail= $mailinfos['address'] ."@" . $mailinfos['domain']; |
---|
44 | $err->log("mail_egw", "tries to set password for", $elmail); |
---|
45 | |
---|
46 | $dominio = explode('.',$mailinfos['domain']); |
---|
47 | $size = count($dominio); |
---|
48 | if ( $size >= 3 && |
---|
49 | $dominio[$size-2] == "org" && |
---|
50 | $dominio[$size-1] == "ar" ) { |
---|
51 | |
---|
52 | $admincli= $L_EGW_ADMINCLI; |
---|
53 | $command= "--change-pw"; // Command to be performed |
---|
54 | $adminuser = $L_EGW_ADMINUSER; |
---|
55 | $adminclave = $L_EGW_ADMINCLAVE; |
---|
56 | //$adminclave= "*******"; |
---|
57 | $account = $elmail; |
---|
58 | |
---|
59 | $go= $admincli ." " .$command ." " .$adminuser ."," .$adminclave ."," .escapeshellarg($account) ."," .escapeshellarg($pass) ; |
---|
60 | |
---|
61 | echo "<h3>Actualizamos la contrasena en la base ldap</h3>"; |
---|
62 | //echo $go; |
---|
63 | //$cod = exec($go); |
---|
64 | exec($go,$output); |
---|
65 | $cod=$output; |
---|
66 | if ($cod) |
---|
67 | { |
---|
68 | // die ($cod); |
---|
69 | echo "<p class=\"alert alert-danger\">"; |
---|
70 | //echo $cod; |
---|
71 | print_r ($cod); |
---|
72 | echo "</p>"; |
---|
73 | //$res = false; |
---|
74 | } |
---|
75 | |
---|
76 | // mandamos el codigo de error en /var/log/alternc/bureau.log |
---|
77 | // no anda bien, porque el $output es un array |
---|
78 | //$err->log("mail_egw", "del en ldap", $cod); |
---|
79 | |
---|
80 | } |
---|
81 | |
---|
82 | // para no morir aca... |
---|
83 | return $res; |
---|
84 | } |
---|
85 | |
---|
86 | function _add_egw_account($dom_id, $mail, $type, $dontcheck = false) { |
---|
87 | global $err, $db, $quota, $dom, $hooks, $L_EGW_ADMINCLI, $L_EGW_ADMINUSER, $L_EGW_ADMINCLAVE; |
---|
88 | $res = true; |
---|
89 | $err->log("mail", "create_egwclass", "$type $mail $dom_id"); |
---|
90 | $domain = $dom->get_domain_byid($dom_id); |
---|
91 | $err->log("mail", "create_egwclass", "$type $mail $domain"); |
---|
92 | |
---|
93 | $dominio = explode('.',$domain); |
---|
94 | $size = count($dominio); |
---|
95 | if ( $size >= 3 && |
---|
96 | $dominio[$size-2] == "org" && |
---|
97 | $dominio[$size-1] == "ar" ) { |
---|
98 | |
---|
99 | // armamos el commando a executar en el cli de egw |
---|
100 | $admincli= $L_EGW_ADMINCLI; |
---|
101 | $command= "--edit-user"; // Command to be performed |
---|
102 | $adminuser= $L_EGW_ADMINUSER; |
---|
103 | $adminclave= $L_EGW_ADMINCLAVE; |
---|
104 | //$adminclave= "*******"; |
---|
105 | |
---|
106 | $firstname = $mail; // the left side of the email |
---|
107 | $lastname= "-"; // we have a generic lastname |
---|
108 | $pass= hash('sha1', rand()); // TEMPORARY |
---|
109 | $email = $account = $mail ."@" .$domain; // account and email are the same |
---|
110 | $expires= "never"; |
---|
111 | $canchangepw= "yes"; |
---|
112 | $anonuser= "no"; |
---|
113 | $primarygroup = $dominio[$size-3]; // domains in .ar starts at the third level |
---|
114 | //$primarygroup= "cta"; //TEMPORARY |
---|
115 | $secondarygroup = $dominio[$size-4]; // sub-domain as a secondary group |
---|
116 | //$secondarygroup= "cta"; //TEMPORARY |
---|
117 | $homedir = "/home/". $mail ."_" .$domain; // everyone can have a home |
---|
118 | $loginshell = "/bin/bash"; // everyone can have a shell |
---|
119 | |
---|
120 | $go= $admincli ." " .$command ." " .$adminuser ."," .$adminclave ."," .escapeshellarg($account) ."," .$firstname ."," .$lastname ."," .escapeshellarg($pass) ."," .escapeshellarg($email) ."," .$expires ."," .$canchangepw ."," .$anonuser ."," .$primarygroup ; |
---|
121 | |
---|
122 | if (isset($secondarygroup)) { |
---|
123 | $go= $go ."," .$secondarygroup ; |
---|
124 | } |
---|
125 | |
---|
126 | $go= $go ."," .$homedir ."," .$loginshell ; |
---|
127 | |
---|
128 | echo "<h3>Creamos la cuenta en la base ldap</h3>"; |
---|
129 | // echo "<h4>$go</h4>"; // LA CLAVE SALE... ACA |
---|
130 | |
---|
131 | exec($go,$output); |
---|
132 | $cod=$output; |
---|
133 | if ($cod) |
---|
134 | { |
---|
135 | // die ($cod); |
---|
136 | echo "<p class=\"alert alert-danger\">"; |
---|
137 | //echo $cod; |
---|
138 | print_r ($cod); |
---|
139 | echo "</p>"; |
---|
140 | //$res = false; |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | // mandamos el codigo de error en /var/log/alternc/bureau.log |
---|
145 | $err->log("mail_egw", "create", $cod); |
---|
146 | |
---|
147 | // para no morir aca... |
---|
148 | return $res; |
---|
149 | } |
---|
150 | |
---|
151 | function _del_egw_account($mail_id) { |
---|
152 | global $err, $db, $hooks, $L_EGW_ADMINCLI, $L_EGW_ADMINUSER, $L_EGW_ADMINCLAVE; |
---|
153 | |
---|
154 | $res = true; |
---|
155 | |
---|
156 | // usamos |
---|
157 | $mailinfos = $this->get_details($mail_id); |
---|
158 | $elmail= $mailinfos['address'] ."@" . $mailinfos['domain']; |
---|
159 | $err->log("mail_egw", "tries to delete", $elmail); |
---|
160 | |
---|
161 | |
---|
162 | $dominio = explode('.',$mailinfos['domain']); |
---|
163 | $size = count($dominio); |
---|
164 | if ( $size >= 3 && |
---|
165 | $dominio[$size-2] == "org" && |
---|
166 | $dominio[$size-1] == "ar" ) { |
---|
167 | |
---|
168 | $admincli= $L_EGW_ADMINCLI; |
---|
169 | $command= "--delete-user"; // Command to be performed |
---|
170 | $adminuser = $L_EGW_ADMINUSER; |
---|
171 | $adminclave = $L_EGW_ADMINCLAVE; |
---|
172 | //$adminclave= "*******"; |
---|
173 | $account = $elmail; |
---|
174 | |
---|
175 | $go= $admincli ." " .$command ." " .$adminuser ."," .$adminclave ."," .escapeshellarg($account); |
---|
176 | |
---|
177 | echo "<h3>Borramos la cuanta en la base ldap</h3>"; |
---|
178 | //echo $go; |
---|
179 | //$cod = exec($go); |
---|
180 | exec($go,$output); |
---|
181 | $cod=$output; |
---|
182 | if ($cod) |
---|
183 | { |
---|
184 | // die ($cod); |
---|
185 | echo "<p class=\"alert alert-danger\">"; |
---|
186 | //echo $cod; |
---|
187 | print_r ($cod); |
---|
188 | echo "</p>"; |
---|
189 | //$res = false; |
---|
190 | } |
---|
191 | |
---|
192 | // mandamos el codigo de error en /var/log/alternc/bureau.log |
---|
193 | // no anda bien, porque el $output es un array |
---|
194 | //$err->log("mail_egw", "del en ldap", $cod); |
---|
195 | |
---|
196 | } |
---|
197 | |
---|
198 | |
---|
199 | // para no morir aca... |
---|
200 | return $res; |
---|
201 | } |
---|
202 | |
---|
203 | } |
---|
204 | |
---|
205 | ?> |
---|