Monday, January 2, 2017

curl behind Authentication

curl dm01:8082/nodes

curl -vv -X POST -d username=foo -d password=foo123 dm01:8082/login
* Adding handle: conn: 0x7fcdb980aa00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fcdb980aa00) send_pipe: 1, recv_pipe: 0
* About to connect() to dm01 port 8082 (#0)
* Trying 10.3.48.19...
* Connected to dm01 (10.3.48.19) port 8082 (#0)
> POST /login HTTP/1.1
> User-Agent: curl/7.30.0
> Host: dm01:8082
> Accept: */*
> Content-Length: 28
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 28 out of 28 bytes
< HTTP/1.1 302 Found
< Set-Cookie: session=ufvuwYxNQWg5pjvSRTUyyHA921jwffc8; Max-Age=7776000; HttpOnly
< Set-Cookie: JSESSIONID=15757nag01iw5zxzo52cayz8n;Path=/
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Set-Cookie: session=SRCdeb9kLBH5sSrWkNOQiKt4dlaeBWK2; Max-Age=7776000; HttpOnly
< Location: http://dm01:8082/
< Content-Length: 0
<
* Connection #0 to host dm01 left intact

curl -b session=ufvuwYxNQWg5pjvSRTUyyHA921jwffc8 dm01:8082/nodes
// Should work fine

[PHP] AD/LDAP Integration


// make sure your host is the correct one
// that you issued your secure certificate to
$ldaphost = "";
$ldapport = "";
$ldapbasedn = "ou=box.net,dc=ad,dc=whirl,dc=net";

// using ldap bind
$ldaprdn  = '';     // AD username
$ldappass = '';  // AD password

// connect to ldap server
$ldapconn = ldap_connect($ldaphost, $ldapport)
    or die("Could not connect to LDAP server.");

if ($ldapconn) {

    // binding to ldap server
    @ldap_bind($ldapconn, 'AD\\'.$ldaprdn, $ldappass) or die('Could not bind to AD');

    // verify binding
    if ($ldapconn) {
        $attributes_ad = array("sAMAccountName", "displayName","description","cn","givenName","sn","mail","co","mobile","company");
        $search = ldap_search($ldapconn, $ldapbasedn, "(sAMAccountName=$ldaprdn)", $attributes_ad) or die ("Error in search query");
        $result = ldap_get_entries($ldapconn, $search);
        print_r($result);
        echo PHP_EOL;
    } else {
        echo "LDAP bind failed..." . PHP_EOL;
    }
}