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

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

poner el escape para los deletes tambien

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