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