Changeset 222 for bureau/class/m_mail.php
- Timestamp:
- 02/21/06 23:52:15 (7 years ago)
- File:
-
- 1 edited
-
bureau/class/m_mail.php (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bureau/class/m_mail.php
r174 r222 1 1 <?php 2 2 /* 3 $Id: m_mail.php,v 1. 9 2004/02/17 15:38:26 remiExp $3 $Id: m_mail.php,v 1.10 2004/05/19 14:23:06 benjamin Exp $ 4 4 ---------------------------------------------------------------------- 5 5 LICENSE … … 33 33 class m_mail { 34 34 35 /** Membre dont on gère les mails */36 var $uid=0;37 38 var $alternc_quota_name="mail";39 40 35 /** Connexion ldap 41 36 * @access private … … 58 53 * Constructeur 59 54 */ 60 function m_mail( $membre=0) {55 function m_mail() { 61 56 global $L_LDAP_HOST,$L_LDAP_ROOT,$L_LDAP_ROOTPWD,$L_LDAP_POSTFIX; 62 $this->uid=$membre;63 57 $this->ldap=array( 64 58 "server" => $L_LDAP_HOST, … … 70 64 71 65 /* ----------------------------------------------------------------- */ 66 /** 67 * Liste des quotas 68 */ 69 function alternc_quota_names() { 70 return "mail"; 71 } 72 73 /* ----------------------------------------------------------------- */ 72 74 /** Retourne la liste des domaines hébergés en mails sur le compte. 73 75 * @return array Tableau indexé des domaines hébergés en mail. 74 76 */ 75 77 function enum_domains() { 76 global $db,$err ;78 global $db,$err,$cuid; 77 79 $err->log("mail","enum_domains"); 78 80 if (!is_array($this->domains)) { 79 $db->query("select * from domaines where compte= ".$this->uid."AND gesmx=1;");81 $db->query("select * from domaines where compte='$cuid' AND gesmx=1;"); 80 82 $this->domains=array(); 81 83 if ($db->num_rows()>0) { … … 100 102 */ 101 103 function enum_doms_mails($dom,$sort=0) { 102 global $err ;104 global $err,$cuid; 103 105 $err->log("mail","enum_doms_mails",$dom); 104 106 if (!$this->_connectldap()) { … … 106 108 return false; 107 109 } 108 $sr=ldap_search($this->ds,"dc=domains,".$this->ldap["basedn"],"(&(uid= ".$this->uid.")(type=mail)(mail=*@".$dom."))",array("mail","pop"));110 $sr=ldap_search($this->ds,"dc=domains,".$this->ldap["basedn"],"(&(uid=$cuid)(type=mail)(mail=*@".$dom."))",array("mail","pop")); 109 111 $info = ldap_get_entries($this->ds, $sr); 110 112 if ($info["count"]==0) { … … 115 117 for($i=0;$i<$info["count"];$i++) { 116 118 if ($info[$i]["pop"][0]) { 119 /* 117 120 $size=exec("/usr/lib/alternc/du.pl /var/alternc/mail/".substr($info[$i]["mail"][0],0,1)."/".str_replace("@","_",$info[$i]["mail"][0])); 118 121 $size=$size*1024; 122 */ 123 $size=0; 119 124 } else { 120 125 $size=0; … … 218 223 */ 219 224 function add_wrapper($login,$domain,$command,$type) { 220 global $err ;225 global $err,$cuid; 221 226 if (!$this->_connectldap()) { 222 227 $err->raise("mail",1); … … 227 232 return false; 228 233 } 229 $res=array("mail" => $login."@".$domain, "uid" => $ this->uid, "type" => $type, "objectclass" => "mail", "pop" => "0", "account"=>$login."_".$domain );234 $res=array("mail" => $login."@".$domain, "uid" => $cuid, "type" => $type, "objectclass" => "mail", "pop" => "0", "account"=>$login."_".$domain ); 230 235 if (!ldap_add($this->ds,"mail=".$res["mail"].",dc=domains,".$this->ldap["basedn"],$res)) { 231 236 $err->raise("mail",5,ldap_error($this->ds)); … … 304 309 */ 305 310 function put_mail_details($mail,$pop,$pass,$alias) { 306 global $err ;311 global $err,$cuid; 307 312 $err->log("mail","put_mail_details",$mail); 308 313 $account=array(); … … 355 360 } 356 361 if ($pop) $pop="1"; else $pop="0"; 357 $res=array("mail" => $mail."@".$dom, "uid" => $ this->uid, "type" => "mail", "objectclass" => "mail", "pop"=> $pop);362 $res=array("mail" => $mail."@".$dom, "uid" => $cuid, "type" => "mail", "objectclass" => "mail", "pop"=> $pop); 358 363 $res["account"]=$account; 359 364 //modification du mail dans ldap-domains … … 389 394 */ 390 395 function add_mail($dom,$mail,$pop,$pass,$alias) { 391 global $quota,$err ;396 global $quota,$err,$cuid; 392 397 $err->log("mail","add_mail",$dom."/".$mail); 393 398 $account=array(); … … 446 451 } 447 452 if ($pop!="1" && $pop!="0") $pop="0"; 448 $res=array("mail" => $mail."@".$dom, "uid" => $ this->uid, "type" => "mail", "objectclass" => "mail", "pop" => $pop);453 $res=array("mail" => $mail."@".$dom, "uid" => $cuid, "type" => "mail", "objectclass" => "mail", "pop" => $pop); 449 454 $res["account"]=$account; 450 455 /* QuotaCheck */ … … 512 517 */ 513 518 function _createpop($mail,$dom,$pass) { 514 global $err ;519 global $err,$cuid; 515 520 $err->log("mail","_createpop",$mail."@".$dom); 516 521 $m=substr($mail,0,1); … … 523 528 $res=array( 524 529 "uid" => $mail."_".$dom, 525 "gidnumber" => $ this->uid,530 "gidnumber" => $cuid, 526 531 "uidnumber" => 33, 527 532 "objectclass" => array("posixAccount","shadowAccount"), … … 529 534 "gecos" => $gecos, 530 535 "status" => "y", 531 "userpassword" => "{CRYPT}". $this->_md5cr($pass)536 "userpassword" => "{CRYPT}"._md5cr($pass) 532 537 ); 533 538 @ldap_add($this->ds,"uid=".$mail."_".$dom.",dc=users,".$this->ldap["basedn"],$res); … … 535 540 $res=array( 536 541 "uid" => $mail."@".$dom, 537 "gidnumber" => $ this->uid,542 "gidnumber" => $cuid, 538 543 "uidnumber" => 33, 539 544 "objectclass" => array("posixAccount","shadowAccount"), … … 541 546 "gecos" => $gecos, 542 547 "status" => "y", 543 "userpassword" => "{CRYPT}". $this->_md5cr($pass)548 "userpassword" => "{CRYPT}"._md5cr($pass) 544 549 ); 545 550 if (!ldap_add($this->ds,"uid=".$mail."@".$dom.",dc=users,".$this->ldap["basedn"],$res)) { … … 563 568 return false; 564 569 } else { 565 exec("/usr/lib/alternc/mail_add ".$mail."_".$dom." ".$ this->uid);570 exec("/usr/lib/alternc/mail_add ".$mail."_".$dom." ".$cuid); 566 571 exec("/bin/echo ".escapeshellarg($pass)." | /usr/sbin/saslpasswd -u postfix -c -p ".$mail."@".$dom); 567 572 exec("/bin/echo ".escapeshellarg($pass)." | /usr/sbin/saslpasswd -u postfix -c -p ".$mail."_".$dom); … … 580 585 */ 581 586 function _updatepop($mail,$dom,$pass) { 582 global $err ;587 global $err,$cuid; 583 588 $err->log("mail","_updatepop",$mail."@".$dom); 584 589 $m=substr($mail,0,1); … … 586 591 $res=array( 587 592 "uid" => $mail."_".$dom, 588 "gidnumber" => $ this->uid,593 "gidnumber" => $cuid, 589 594 "uidnumber" => 33, 590 595 "objectclass" => array("posixAccount","shadowAccount"), … … 592 597 "gecos" => $mail, 593 598 "status" => "y", 594 "userpassword" => "{CRYPT}". $this->_md5cr($pass)599 "userpassword" => "{CRYPT}"._md5cr($pass) 595 600 ); 596 601 @ldap_modify($this->ds,"uid=".$mail."_".$dom.",dc=users,".$this->ldap["basedn"],$res); 597 602 $res=array( 598 603 "uid" => $mail."@".$dom, 599 "gidnumber" => $ this->uid,604 "gidnumber" => $cuid, 600 605 "uidnumber" => 33, 601 606 "objectclass" => array("posixAccount","shadowAccount"), … … 603 608 "gecos" => $mail, 604 609 "status" => "y", 605 "userpassword" => "{CRYPT}". $this->_md5cr($pass)610 "userpassword" => "{CRYPT}"._md5cr($pass) 606 611 ); 607 612 if (!ldap_modify($this->ds,"uid=".$mail."@".$dom.",dc=users,".$this->ldap["basedn"],$res)) { … … 705 710 * @return boolean TRUE si le domaine a bien été créé, FALSE si une erreur s'est produite. 706 711 * @access private 712 * TODO : ne créer les entrées que si le MX est à true ! (déplacer a alternc_add_mx_domain 707 713 */ 708 714 function alternc_add_domain($dom) { 709 global $err ;715 global $err,$cuid; 710 716 $err->log("mail","add_dom",$dom); 711 717 if (!$this->_connectldap()) { … … 719 725 return false; 720 726 } 721 $res=array("mail" => $dom, "uid" => $ this->uid, "type" => "domain", "objectclass" => "mail", "account"=> $dom);727 $res=array("mail" => $dom, "uid" => $cuid, "type" => "domain", "objectclass" => "mail", "account"=> $dom); 722 728 if (!ldap_add($this->ds,"mail=$dom,dc=domains,".$this->ldap["basedn"],$res)) { 723 729 $err->raise("mail",5,ldap_error($this->ds)); … … 730 736 function alternc_quota_check($id=-1) { 731 737 global $quota,$err; 732 $err->log("mail","checkquota"); 733 if ($id==-1) $id=$this->uid; 734 if (!$this->_connectldap()) { 735 $err->raise("mail",1); 736 return false; 737 } 738 $sr=ldap_search($this->ds,"dc=domains,".$this->ldap["basedn"],"(&(uid=".$this->uid.")(type=mail))",array("")); 739 $info = ldap_get_entries($this->ds, $sr); 740 $quota->setquota("mail",$info[count],1,$id); 741 738 if ($id==-1) $id=$cuid; 742 739 return true; 743 740 } … … 771 768 } 772 769 773 /* ----------------------------------------------------------------- */774 /** Crypte un mot de passe en clair en MD5 avec un salt aléatoire775 * @param string $pass Mot de passe à crypter (max 32 caractères)776 * @return string Retourne le mot de passe crypté777 * @access private778 */779 function _md5cr($pass) {780 $salt=""; //generate a salt using characters [A-Z][a-z][0-9]./781 $chars="./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";782 for ($i=0;$i<16;$i++) {783 $salt.=substr($chars,(mt_rand(0,strlen($chars))),1);784 }785 return crypt($pass,"$1$".$salt);786 /* " */787 }788 789 770 } /* Class m_mail */ 790 771
Note: See TracChangeset
for help on using the changeset viewer.
