2 /* This program is free software. It comes without any warranty, to
3 * the extent permitted by applicable law. You can redistribute it
4 * and/or modify it under the terms of the Do What The Fuck You Want
5 * To Public License, Version 2, as published by Sam Hocevar. See
6 * http://sam.zoy.org/wtfpl/COPYING for more details. */
18 function replicate($uid,$hkid,$password) {
20 $admindn = "cn=kyberia,ou=Directory Administrators,dc=h-k,dc=sk";
23 $this->dn = "ou=People,dc=h-k,dc=sk";
25 $this->ldif['cn'] = $uid;
26 $this->ldif['sn'] = $uid;
27 $this->ldif['hkid'] = $hkid;
28 $this->ldif['userpassword'] = "{clear}".$password;
29 $this->ldif['o'] = "h-k.sk";
30 // $this->ldif['homeDirectory'] = "/home/".$hkid;
31 // $this->ldif['loginShell'] = "/bin/false";
32 // $this->ldif['deliveryMode'] = "normal";
33 // $this->ldif['mailQuotaCount'] = "10000";
34 // $this->ldif['mailQuotaSize'] = "100000000";
35 // $this->ldif['mailSizeMax'] = "10000000";
36 // $this->ldif['mail'] = strtolower($uid)."@h-k.sk";
37 // $this->ldif['mailalternateaddress'][0] = strtolower($uid)."@h-k.sk";
38 // $this->ldif['mailalternateaddress'][1] = strtolower($uid)."@kyberia.sk";
39 // $this->ldif['mailalternateaddress'][2] = strtolower($uid)."@hysteria.sk";
40 // $this->ldif['accountstatus'] = "disabled";
41 // $this->ldif['qmailUID'] = "123";
42 // $this->ldif['uidnumber'] = "123";
43 // $this->ldif['gidnumber'] = "123";
44 // $this->ldif['qmailGID'] = "123";
45 $this->ldif['uid'] = $uid;
48 $this->ldif['objectclass'][0] = "inetOrgPerson";
49 // $this->ldif['objectclass'][1] = "posixAccount";
50 $this->ldif['objectclass'][1] = "OpenLDAPPerson";
51 $this->ldif['objectclass'][2] = "pilotPerson";
52 $this->ldif['objectclass'][3] = "inetLocalMailRecipient";
53 // $this->ldif['objectclass'][] = "qmailUser";
54 $this->ldif['objectclass'][4] = "top";
55 $this->ldif['objectclass'][5] = "person";
56 $this->ldif['objectclass'][6] = "hkuser";
58 $c = ldap_connect("localhost");
59 $b = ldap_bind($c, $admindn, $adminpw);
60 $r = ldap_add($c, "hkid=".$hkid.",".$this->dn, $this->ldif);
62 //system("echo \"".$uid.":".$hkid."(".ldap_error($c).")\" >> /tmp/ldaprepl.log");
68 function change_pass($uid,$old_pass,$new_pass) {
70 $c = ldap_connect("localhost");
73 $this->dn = "ou=People,dc=h-k,dc=sk";
74 $this->values = array("dn");
75 $this->filter = "hkid=".$uid;
77 $sr = ldap_search($c, $this->dn, $this->filter, $this->values);
79 $res = ldap_get_entries($c, $sr);
80 $this->dn = $res[0]["dn"];
82 if ($res['count'] != 1) {
86 if ($old_pass == "") {
90 $b = ldap_bind($c, $this->dn, $old_pass);
91 echo "binding".$this->dn." with $old_pass";
93 $this->ldif['userpassword'] = "{clear}".$new_pass;
94 $mod_ret = ldap_modify($c, $this->dn, $this->ldif);
102 function auth($uid,$password) {
104 $c = ldap_connect("localhost");
107 $this->dn = "ou=People,dc=h-k,dc=sk";
108 $this->values = array("dn");
109 $this->filter = "hkid=".$uid;
111 $sr = ldap_search($c, $this->dn, $this->filter, $this->values);
113 $res = ldap_get_entries($c, $sr);
115 if ($res['count'] != 1) {
116 //system("echo \"(".$uid.") NOT FOUND\" >> /tmp/ldaprepl.log");
120 $this->dn = $res[0]["dn"];
122 //system("echo \"BINDING:".$this->dn."\" >> /tmp/ldaprepl.log");
124 if ($password == "") {
125 //system("echo \"(".$this->dn.") BIND FAILED (empty password)\" >> /tmp/ldaprepl.log");
129 $b = ldap_bind($c, $this->dn, $password);
132 //system("echo \"(".$this->dn.") BIND OK\" >> /tmp/ldaprepl.log");
136 //system("echo \"(".$this->dn.") BIND FAILED\" >> /tmp/ldaprepl.log");