[35] | 1 | <? |
---|
| 2 | require_once("m_mail.php"); |
---|
| 3 | |
---|
| 4 | class m_mail_egw extends m_mail { |
---|
| 5 | |
---|
[792] | 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 | } |
---|
[35] | 15 | |
---|
[783] | 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 | |
---|
[782] | 26 | function delete($mail_id) { |
---|
[792] | 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; |
---|
[58] | 33 | } |
---|
| 34 | |
---|
[783] | 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); |
---|
[787] | 42 | $elmail= $mailinfos['address'] ."@" . $mailinfos['domain']; |
---|
[783] | 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= "*******"; |
---|
[788] | 56 | $account = $elmail; |
---|
[783] | 57 | |
---|
[788] | 58 | $go= $admincli ." " .$command ." " .$adminuser ."," .$adminclave ."," .escapeshellarg($account) ."," .escapeshellarg($pass) ; |
---|
[783] | 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 | |
---|
[785] | 85 | function _add_egw_account($dom_id, $mail, $type, $dontcheck = false) { |
---|
[782] | 86 | global $err, $db, $quota, $dom, $hooks, $L_EGW_ADMINCLI, $L_EGW_ADMINUSER, $L_EGW_ADMINCLAVE; |
---|
| 87 | $res = true; |
---|
[785] | 88 | $err->log("mail", "create_egwclass", "$type $mail $dom_id"); |
---|
[782] | 89 | $domain = $dom->get_domain_byid($dom_id); |
---|
[785] | 90 | $err->log("mail", "create_egwclass", "$type $mail $domain"); |
---|
[60] | 91 | |
---|
[784] | 92 | $dominio = explode('.',$domain); |
---|
| 93 | $size = count($dominio); |
---|
| 94 | if ( $size >= 3 && |
---|
| 95 | $dominio[$size-2] == "org" && |
---|
| 96 | $dominio[$size-1] == "ar" ) { |
---|
[35] | 97 | |
---|
[784] | 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= "*******"; |
---|
[35] | 104 | |
---|
[784] | 105 | $firstname = $mail; // the left side of the email |
---|
| 106 | $lastname= "-"; // we have a generic lastname |
---|
[786] | 107 | $pass= hash('sha1', rand()); // TEMPORARY |
---|
[790] | 108 | $email = $account = $mail ."@" .$domain; // account and email are the same |
---|
[784] | 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 | |
---|
[790] | 119 | $go= $admincli ." " .$command ." " .$adminuser ."," .$adminclave ."," .escapeshellarg($account) ."," .$firstname ."," .$lastname ."," .escapeshellarg($pass) ."," .escapeshellarg($email) ."," .$expires ."," .$canchangepw ."," .$anonuser ."," .$primarygroup ; |
---|
[782] | 120 | |
---|
[784] | 121 | if (isset($secondarygroup)) { |
---|
| 122 | $go= $go ."," .$secondarygroup ; |
---|
| 123 | } |
---|
[199] | 124 | |
---|
[784] | 125 | $go= $go ."," .$homedir ."," .$loginshell ; |
---|
| 126 | |
---|
| 127 | echo "<h3>Creamos la cuenta en la base ldap</h3>"; |
---|
[782] | 128 | // echo "<h4>$go</h4>"; // LA CLAVE SALE... ACA |
---|
[199] | 129 | |
---|
[784] | 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 | } |
---|
[35] | 142 | |
---|
[782] | 143 | // mandamos el codigo de error en /var/log/alternc/bureau.log |
---|
| 144 | $err->log("mail_egw", "create", $cod); |
---|
[58] | 145 | |
---|
[782] | 146 | // para no morir aca... |
---|
| 147 | return $res; |
---|
[58] | 148 | } |
---|
[784] | 149 | |
---|
[783] | 150 | function _del_egw_account($mail_id) { |
---|
| 151 | global $err, $db, $hooks, $L_EGW_ADMINCLI, $L_EGW_ADMINUSER, $L_EGW_ADMINCLAVE; |
---|
[58] | 152 | |
---|
[782] | 153 | $res = true; |
---|
[60] | 154 | |
---|
[783] | 155 | // usamos |
---|
| 156 | $mailinfos = $this->get_details($mail_id); |
---|
[791] | 157 | $elmail= $mailinfos['address'] ."@" . $mailinfos['domain']; |
---|
[783] | 158 | $err->log("mail_egw", "tries to delete", $elmail); |
---|
[60] | 159 | |
---|
| 160 | |
---|
[783] | 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 | |
---|
[791] | 174 | $go= $admincli ." " .$command ." " .$adminuser ."," .$adminclave ."," .escapeshellarg($account); |
---|
[783] | 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 | |
---|
[782] | 198 | // para no morir aca... |
---|
| 199 | return $res; |
---|
[60] | 200 | } |
---|
[782] | 201 | |
---|
[35] | 202 | } |
---|
| 203 | |
---|
| 204 | ?> |
---|