X-Git-Url: http://git.pjr.cc/?p=ga4php.git;a=blobdiff_plain;f=example%2Factivedirectory%2Fextend.php;fp=example%2Factivedirectory%2Fextend.php;h=a551202c194e50abedc42ba88f2561eaadc6fbaf;hp=0000000000000000000000000000000000000000;hb=6d65f8b20aa37e21eb2f68bb47c8ef30059aba71;hpb=a492905529352ba1c6f7bf675f53e8498745c9bf diff --git a/example/activedirectory/extend.php b/example/activedirectory/extend.php new file mode 100644 index 0000000..a551202 --- /dev/null +++ b/example/activedirectory/extend.php @@ -0,0 +1,114 @@ +"; + //print_r($info); + //echo ""; + + $attr_name = false; + for($i=1; $i<15; $i++) { + $valname = "extensionattribute$i"; + if(isset($info[0]["$valname"][0])) { + $val = $info[0]["$valname"][0]; + // we are looking for an extension attribute that has a start of "ga4php" + if(preg_match('/^ga4php.*/', $val)>0) { + $attr_name = $valname; + } + } + + } + + // yeah, totally works.... HAH + if($attr_name != false) { + $tokend = $info[0]["$attr_name"][0]; + $expl = explode(":", $tokend); + $tokendata = $expl[1]; + } + + return $tokendata; + + // and there you have it, simple eh? + } + + + // now we need a function for putting the data back into our user table. + // in this example, we wont check anything, we'll just overwrite it. + function putData($username, $data) { + global $dsconnect, $host, $binduser, $bindpass, $basecn; + + if($data!="") { + $data .= "ga4php:"; + } + + // set this to default to begin with + $tokendata = false; + + // we need to track the "first" blank attribute + $blank_attr = false; + + // we search for a username that matches what we've been passed + $sr = ldap_search($dsconnect, "$basecn", "samaccountname=$username"); + $info = ldap_get_entries($dsconnect, $sr); + $dn = $info[0]["distinguishedname"][0]; + + //echo "
";
+		//print_r($info);
+		//echo "
"; + + $attr_name = false; + for($i=1; $i<15; $i++) { + $valname = "extensionattribute$i"; + if(isset($info[0]["$valname"][0])) { + $val = $info[0]["$valname"][0]; + // we are looking for an extension attribute that has a start of "ga4php" + if(preg_match('/^ga4php.*/', $val)>0) { + $attr_name = $valname; + } + } else { + if($blank_attr == false) { + // this will cathc the first unset extension variable name, if we need it + $blank_attr = "$valname"; + } + } + + } + + // if the attr_name is not set, we need to set $blank_attr + if($attr_name == false) { + // we use $blank_attr + error_log("setting for $username, $blank_attr"); + $infod["$blank_attr"][0] = "$data"; + } else { + error_log("setting for $username, $attr_name"); + $infod["$attr_name"][0] = "$data"; + } + + error_log("att end of put data for $dn, $infod"); + + return ldap_modify($dsconnect, $dn, $infod); + // even simpler! + } + + // not implemented yet + function getUsers() { + return false; + } +} + +?>