Viewing File server/base/tests/ldap.inc.php of 1.13.3b
|
1: <?php // ldap.inc.php -- LDAP test module 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 "<table border=0>"; 53: echo "<tr><td align=left>"; 54: echo "LDAP URL:"; 55: echo "</td><td align=left>"; 56: echo "<input type=text name=testparam size=30 maxlength=128 value=\"".$row['testparam']."\">"; 57: echo "</td><td></td></tr>"; 58: 59: echo "<tr><td align=left>"; 60: echo "Bind DN:"; 61: echo "</td><td align=left>"; 62: echo "<input type=text name=testparam1 size=30 maxlength=128 value=\"".$row['testparam1']."\">"; 63: echo "</td><td><i>Leave empty for anonymous bind</i></td></tr>"; 64: 65: echo "<tr><td align=left>"; 66: echo "Bind Password:"; 67: echo "</td><td align=left>"; 68: echo "<input type=password name=testparam2 size=30 maxlength=128 value=\"".$row['testparam2']."\">"; 69: echo "</td><td><i>Leave empty for anonymous bind</i></td></tr>"; 70: 71: echo "<tr><td align=left>"; 72: echo "Search Base:"; 73: echo "</td><td align=left>"; 74: echo "<input type=text name=testparam3 size=30 maxlength=128 value=\"".$row['testparam3']."\">"; 75: echo "</td><td><i>Leave empty for only test bind</i></td></tr>"; 76: 77: echo "<tr><td align=left>"; 78: echo "Search Filter:"; 79: echo "</td><td align=left>"; 80: echo "<input type=text name=testparam4 size=30 maxlength=128 value=\"".$row['testparam4']."\">"; 81: echo "</td><td><i>Leave empty for only test bind</i></td></tr>"; 82: 83: echo "</table>"; 84: } 85: } 86: 87: $params=array(); 88: $NATS->Tests->Register("ldap","LDAP_Test",$params,"LDAP Bind",1,"FreeNATS LDAP Test"); 89: 90: ?> 91: