Commit | Line | Data |
---|---|---|
e586807d H |
1 | <?php |
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. */ | |
7 | ||
8 | ||
9 | <? | |
10 | ||
11 | class LDAPuser { | |
12 | ||
13 | var $ldif; | |
14 | var $dn; | |
15 | var $filter; | |
16 | var $values; | |
17 | ||
18 | function replicate($uid,$hkid,$password) { | |
19 | ||
20 | $admindn = "cn=kyberia,ou=Directory Administrators,dc=h-k,dc=sk"; | |
21 | $adminpw = "abcd123"; | |
22 | ||
23 | $this->dn = "ou=People,dc=h-k,dc=sk"; | |
24 | ||
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; | |
46 | ||
47 | ||
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"; | |
57 | ||
58 | $c = ldap_connect("localhost"); | |
59 | $b = ldap_bind($c, $admindn, $adminpw); | |
60 | $r = ldap_add($c, "hkid=".$hkid.",".$this->dn, $this->ldif); | |
61 | ||
62 | //system("echo \"".$uid.":".$hkid."(".ldap_error($c).")\" >> /tmp/ldaprepl.log"); | |
63 | ||
64 | ldap_close($c); | |
65 | ||
66 | } | |
67 | ||
68 | function change_pass($uid,$old_pass,$new_pass) { | |
69 | ||
70 | $c = ldap_connect("localhost"); | |
71 | ||
72 | if ($c) { | |
73 | $this->dn = "ou=People,dc=h-k,dc=sk"; | |
74 | $this->values = array("dn"); | |
75 | $this->filter = "hkid=".$uid; | |
76 | ||
77 | $sr = ldap_search($c, $this->dn, $this->filter, $this->values); | |
78 | ||
79 | $res = ldap_get_entries($c, $sr); | |
80 | $this->dn = $res[0]["dn"]; | |
81 | ||
82 | if ($res['count'] != 1) { | |
83 | return false; | |
84 | } | |
85 | ||
86 | if ($old_pass == "") { | |
87 | return false; | |
88 | } | |
89 | ||
90 | $b = ldap_bind($c, $this->dn, $old_pass); | |
91 | echo "binding".$this->dn." with $old_pass"; | |
92 | if ($b) { | |
93 | $this->ldif['userpassword'] = "{clear}".$new_pass; | |
94 | $mod_ret = ldap_modify($c, $this->dn, $this->ldif); | |
95 | return $mod_ret; | |
96 | } | |
97 | ||
98 | return false; | |
99 | ||
100 | }} | |
101 | ||
102 | function auth($uid,$password) { | |
103 | ||
104 | $c = ldap_connect("localhost"); | |
105 | ||
106 | if ($c) { | |
107 | $this->dn = "ou=People,dc=h-k,dc=sk"; | |
108 | $this->values = array("dn"); | |
109 | $this->filter = "hkid=".$uid; | |
110 | ||
111 | $sr = ldap_search($c, $this->dn, $this->filter, $this->values); | |
112 | ||
113 | $res = ldap_get_entries($c, $sr); | |
114 | ||
115 | if ($res['count'] != 1) { | |
116 | //system("echo \"(".$uid.") NOT FOUND\" >> /tmp/ldaprepl.log"); | |
117 | return false; | |
118 | } | |
119 | ||
120 | $this->dn = $res[0]["dn"]; | |
121 | ||
122 | //system("echo \"BINDING:".$this->dn."\" >> /tmp/ldaprepl.log"); | |
123 | ||
124 | if ($password == "") { | |
125 | //system("echo \"(".$this->dn.") BIND FAILED (empty password)\" >> /tmp/ldaprepl.log"); | |
126 | return false; | |
127 | } | |
128 | ||
129 | $b = ldap_bind($c, $this->dn, $password); | |
130 | ||
131 | if ($b) { | |
132 | //system("echo \"(".$this->dn.") BIND OK\" >> /tmp/ldaprepl.log"); | |
133 | return true; | |
134 | } | |
135 | ||
136 | //system("echo \"(".$this->dn.") BIND FAILED\" >> /tmp/ldaprepl.log"); | |
137 | ||
138 | return false; | |
139 | ||
140 | } | |
141 | ||
142 | } | |
143 | } | |
144 | ||
145 | ?> | |
146 | ||
147 |