first commit

This commit is contained in:
Eliezer Croitoru 2024-01-01 19:35:36 +02:00
commit 21001d3ca9
2 changed files with 84 additions and 0 deletions

47
test-1.php Normal file
View File

@ -0,0 +1,47 @@
<?php
// LDAPS server details
$ldapServer = 'ldaps://your-ldap-server.com';
$ldapPort = 636;
// LDAP bind credentials
$ldapUsername = 'your-ldap-username'; // Usually in the form of username@domain.com
$ldapPassword = 'your-ldap-password';
// Connect to LDAPS server
$ldapConn = ldap_connect($ldapServer, $ldapPort);
// Check for successful connection
if (!$ldapConn) {
die("Could not connect to LDAP server");
}
// Disable SSL/TLS certificate verification
ldap_set_option($ldapConn, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER);
// Set LDAP options
ldap_set_option($ldapConn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapConn, LDAP_OPT_REFERRALS, 0);
// Bind to LDAP server
$ldapBind = ldap_bind($ldapConn, $ldapUsername, $ldapPassword);
// Check for successful bind
if (!$ldapBind) {
die("LDAP bind failed");
}
// Now you can perform LDAP operations, such as searching or modifying data
// For example, searching for a user
$searchDN = 'ou=Users,dc=example,dc=com'; // Adjust the base DN as per your AD structure
$searchFilter = '(sAMAccountName=username)'; // Adjust the filter for your needs
$searchResult = ldap_search($ldapConn, $searchDN, $searchFilter);
$entries = ldap_get_entries($ldapConn, $searchResult);
// Display the results
print_r($entries);
// Don't forget to close the connection when done
ldap_close($ldapConn);
?>

37
test-1.sh Normal file
View File

@ -0,0 +1,37 @@
#!/usr/bin/env bash
LDAP_SERVER="ldaps://your-ldap-server.com:636"
LDAP_BIND_DN="your-ldap-username"
LDAP_BIND_PASSWORD="your-ldap-password"
LDAP_BASE_DN="ou=Users,dc=example,dc=com"
LDAP_SEARCH_USER="username"
# Test 1: Basic connectivity check
echo "Testing basic connectivity..."
ldapsearch -H "$LDAP_SERVER" -x -b "" -s base
if [ $? -ne 0 ]; then
echo "Error: Failed to connect to LDAP server."
exit 1
fi
# Test 2: Bind with user account
echo "Testing bind with user account..."
ldapsearch -H "$LDAP_SERVER" -D "$LDAP_BIND_DN" -w "$LDAP_BIND_PASSWORD" -b "$LDAP_BASE_DN" -s sub "(objectClass=*)"
if [ $? -ne 0 ]; then
echo "Error: Failed to bind with LDAP user account."
exit 1
fi
# Test 3: Search for a user
echo "Searching for user: $LDAP_SEARCH_USER..."
ldapsearch -H "$LDAP_SERVER" -D "$LDAP_BIND_DN" -w "$LDAP_BIND_PASSWORD" -b "$LDAP_BASE_DN" -s sub "(sAMAccountName=$LDAP_SEARCH_USER)"
if [ $? -ne 0 ]; then
echo "Error: Failed to search for user."
exit 1
fi
echo "All tests passed successfully."
exit 0