source: trunk/alternc/patches/class/m_mail_egw.php @ 792

Last change on this file since 792 was 792, checked in by autocommit@…, 7 years ago

probamos cuando hay que suprimir una lista, de no tocar ldap... (no anda por ahora)

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