File: 1.13.3b/server/base/tests/ldap.inc.php (View as Code)

1: 2: 3: /** 4: * LDAP Test (C) Copyright 2011 Marc Franquesa 5: * Provided within FreeNATS 6: * 7: * For more information see http://www.purplepixie.org/freenats/ 8: * 9: * Licence: GNU GPL V3 or later 10: **/ 11: 12: 13: global $NATS; 14: 15: class LDAP_Test extends FreeNATS_Local_Test 16: { 17: function DoTest($testname,$param,$hostname,$timeout,$params) 18: { 19: global $NATS; 20: 21: $url = $params[0]; 22: $bind = $params[1]; 23: $pasw = $params[2]; 24: $base = $params[3]; 25: $filter = $params[4]; 26: 27: $ds = ldap_connect($url); 28: if (!$ds) return -2; 29: $ldap = ($bind && $pasw) ? ldap_bind($ds, $bind, $pasw) : ldap_bind($ds); 30: if (!$ldap) return -1; 31: 32: if ($base && $filter) { 33: $search = ldap_search($ds,$base,$filter); 34: $val = ldap_count_entries($ds,$search); 35: } else { 36: $val = 1; 37: } 38: 39: ldap_close($ds); 40: return $val; 41: } 42: 43: function Evaluate($result) 44: { 45: if ($result<0) return 2; // failure 46: if ($result==0) return 1; // warning 47: return 0; // else success 48: } 49: 50: function DisplayForm(&$row) 51: { 52: echo ""; 53: echo ""; 58: 59: echo ""; 64: 65: echo ""; 70: 71: echo ""; 76: 77: echo ""; 82: 83: echo "
"; 54: echo "LDAP URL:"; 55: echo ""; 56: echo ""; 57: echo "
"; 60: echo "Bind DN:"; 61: echo ""; 62: echo ""; 63: echo "Leave empty for anonymous bind
"; 66: echo "Bind Password:"; 67: echo ""; 68: echo ""; 69: echo "Leave empty for anonymous bind
"; 72: echo "Search Base:"; 73: echo ""; 74: echo ""; 75: echo "Leave empty for only test bind
"; 78: echo "Search Filter:"; 79: echo ""; 80: echo ""; 81: echo "Leave empty for only test bind
";
84: } 85: } 86: 87: $params=array(); 88: $NATS->Tests->Register("ldap","LDAP_Test",$params,"LDAP Bind",1,"FreeNATS LDAP Test"); 89: 90: ?> 91: