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

Last change on this file since 60 was 60, checked in by sebas, 16 years ago

codigo para el cambio de clave en ldap/egw desde alternc #5

File size: 5.1 KB
Line 
1<?
2require_once("m_mail.php");
3
4class m_mail_egw extends m_mail {
5
6
7//      function __construct () {
8//              global $mail;
9//              $mail = $this;
10//      }
11//      function _createpop($mail,$dom,$pass) {
12//              global $err,$cuid,$db;
13//              $err->log("mail","_createpop",$mail."@".$dom);
14//              $m=substr($mail,0,1);
15//              $gecos=$mail;
16//              if (!$mail) {
17//              // Cas du CATCH-ALL
18//              $gecos="Catch-All";
19//              $m="_";
20//              }
21//              $db->query("INSERT INTO mail_users (uid,alias,path,password) VALUES ('$cuid','".$mail."_".$dom."','/var/alternc/mail/".$m."/".$mail."_".$dom."','"._md5cr($pass)."');");
22//              $db->query("INSERT INTO mail_users (uid,alias,path,password) VALUES ('$cuid','".$mail."@".$dom."','/var/alternc/mail/".$m."/".$mail."_".$dom."','"._md5cr($pass)."');");
23//              $db->query("INSERT INTO mail_alias (mail,alias) VALUES ('".$mail."_".$dom."','/var/alternc/mail/".$m."/".$mail."_".$dom."/Maildir/');");
24//             
25//              $f=fopen("/var/lib/squirrelmail/data/".$mail."_".$dom.".pref","wb");
26//              $g=0; $g=@fopen("/etc/squirrelmail/default_pref","rb");
27//              fputs($f,"email_address=$mail@$dom\nchosen_theme=default_theme.php\n");
28//              if ($g) {
29//              while ($s=fgets($g,1024)) {
30//                      if (substr($s,0,14)!="email_address=" && substr($s,0,13)!="chosen_theme=") {
31//                      fputs($f,$s);
32//                      }
33//              }
34//              fclose($g);
35//              }
36//              fclose($f);
37//              @copy("/var/lib/squirrelmail/data/".$mail."_".$dom.".pref","/var/lib/squirrelmail/data/".$mail."@".$dom.".pref");
38//              exec("/usr/lib/alternc/mail_add ".$mail."_".$dom." ".$cuid);
39//              return true;
40//      }
41
42        function _createpop($mail,$dom,$pass) {
43       
44                if ($this->_add_egw_account($mail,$dom,$pass) )
45                        if (parent::_createpop($mail,$dom,$pass))
46                                return true;
47                        else
48                                return false;
49                else
50                        return false;
51
52        }
53
54        function _deletepop($mail,$dom) {
55       
56                if ($this->_del_egw_account($mail,$dom) )
57                        if (parent::_deletepop($mail,$dom))
58                                return true;
59                        else
60                                return false;
61                else
62                        return false;
63
64        }
65
66        function _updatepop($mail,$dom,$pass) {
67       
68                if ($this->_update_passwd_egw_account($mail,$dom,$pass) )
69                        if (parent::_updatepop($mail,$dom,$pass))
70                                return true;
71                        else
72                                return false;
73                else
74                        return false;
75
76        }
77
78        function _add_egw_account($mail,$dom,$pass) {
79
80                $res = true;
81                $domain = explode('.',$dom);
82                $size = count($domain);
83                if (  $size >= 3 && 
84                        $domain[$size-3] == "cta" &&
85                        $domain[$size-2] == "org" &&
86                        $domain[$size-1] == "ar" ) {
87
88                        $admincli= $GLOBALS["L_EGW_ADMINCLI"];
89                        $command= "--edit-user";                        // Command to be performed
90                        $adminuser = $GLOBALS["L_EGW_ADMINUSER"];
91                        $adminclave = $GLOBALS["L_EGW_ADMINCLAVE"];
92                        // $account - we use the email address which is extracted from the DB
93                        // $firstname - we use the left side of the email adress, which will be extracted from the database
94                        $lastname= "-";                                 // we have a generic lastname
95                        // $passwd will be generated with some magic
96                        // $email you know that, from the db
97                        $expires= "never";
98                        $canchangepw= "yes";
99                        $anonuser= "no";
100                        $primarygroup = $domain[$size-3];
101                        $secundarygroup = join(',', array_slice($domain,0,-3));
102                        $lastname = "-";
103                        $firstname = $mail;
104                        $email = $account = $mail ."@" .$dom;
105
106                        $go= $admincli ." " .$command ." " .$adminuser ."," .$adminclave .",\"" .$account ."\"," .$firstname ."," .$lastname ."," .$pass .",\"" .$email ."\"," .$expires ."," .$canchangepw ."," .$anonuser ."," .$primarygroup ;
107                       
108                        if (isset($secondarygroup)) {
109                        $go= $go ."," .$secondarygroup;
110                        }
111                        echo ($go);     
112                        // exit();
113                        $cod = exec($go);
114                        if ($cod)
115                        {
116                        die ($cod);
117                                $res = false;
118                        }       
119                }
120                return $res;
121
122        }       
123
124        function _del_egw_account($mail,$dom) {
125
126                $res = true;
127                $domain = explode('.',$dom);
128                $size = count($domain);
129                if (  $size >= 3 && 
130                        $domain[$size-3] == "cta" &&
131                        $domain[$size-2] == "org" &&
132                        $domain[$size-1] == "ar" ) {
133
134                        $admincli= $GLOBALS["L_EGW_ADMINCLI"];
135                        $command= "--delete-user";                        // Command to be performed
136                        $adminuser = $GLOBALS["L_EGW_ADMINUSER"];
137                        $adminclave = $GLOBALS["L_EGW_ADMINCLAVE"];
138                        // $account - we use the email address which is extracted from the DB
139                        $email = $account = $mail ."@" .$dom;
140
141                        $go= $admincli ." " .$command ." " .$adminuser ."," .$adminclave .",\"" .$account ."\"" ;
142                       
143                        echo ($go);     
144                        // exit();
145                        $cod = exec($go);
146                        if ($cod)
147                        {
148                        die ($cod);
149                                $res = false;
150                        }       
151                }
152                return $res;
153
154        }       
155
156
157        function _update_passwd_egw_account($mail,$dom,$pass) {
158
159                $res = true;
160                $domain = explode('.',$dom);
161                $size = count($domain);
162                if (  $size >= 3 && 
163                        $domain[$size-3] == "cta" &&
164                        $domain[$size-2] == "org" &&
165                        $domain[$size-1] == "ar" ) {
166
167                        $admincli= $GLOBALS["L_EGW_ADMINCLI"];
168                        $command= "--edit-user";                        // Command to be performed
169                        $adminuser = $GLOBALS["L_EGW_ADMINUSER"];
170                        $adminclave = $GLOBALS["L_EGW_ADMINCLAVE"];
171                        $email = $account = $mail ."@" .$dom;
172
173                        $go= $admincli ." " .$command ." " .$adminuser ."," .$adminclave .",\"" .$account ."\",,," .$pass ;
174                       
175                        echo ($go);     
176                        // exit();
177                        $cod = exec($go);
178                        if ($cod)
179                        {
180                        die ($cod);
181                                $res = false;
182                        }       
183                }
184                return $res;
185
186        }       
187
188}
189
190
191
192?>
Note: See TracBrowser for help on using the repository browser.