0

I'm trying to list all domains including domain pointers using the DirectAdmin API. I currently have the following code:

//list users
$sock->query('/CMD_API_SHOW_USERS');
$users=$sock->fetch_parsed_body();

foreach($users['list'] as $user) {
    //get domains for user
    $sock->query(
        '/CMD_API_SHOW_USER_DOMAINS',
        array(
            'user'=>$user
        )
    );

    $domains=$sock->fetch_parsed_body();

    echo str_replace('_', '.', $domain).'<br>';

    //print_r($domains);

    foreach($domains as $domain=>$data) {
        //get domain pointers for domain
        $sock->query(
            '/CMD_API_DOMAIN_POINTER',
            array(
                'domain'=>str_replace('_', '.', $domain)
            )
        );

        $domain_pointers=$sock->fetch_parsed_body();

        print_r($domain_pointers);
    }
}

The CMD_API_DOMAIN_POINTER command however only returns "Could not execute your request" and "You do not own that domain".

Am I doing this the right way?

I found the ""Login-as" with the API" (https://www.directadmin.com/api.html), but I don't seem to be able to find how to work with this.

vespino
  • 1,714
  • 3
  • 15
  • 28

1 Answers1

0

This is the way to go:

include_once 'httpsocket.php';

$sock=new HTTPSocket;
$sock->connect('ssl://fqdn', 2222);
$sock->set_login('admin', 'pass');

//list users
$sock->query('/CMD_API_SHOW_USERS');
$users=$sock->fetch_parsed_body();

foreach($users['list'] as $user) {
    //get domains for user
    $sock->query(
        '/CMD_API_SHOW_USER_DOMAINS',
        array(
            'user'=>$user
        )
    );

$domains=$sock->fetch_parsed_body();

echo str_replace('_', '.', $domain).'<br>';

//print_r($domains);

$sock2=new HTTPSocket;
$sock2->connect('ssl://fqdn', 2222);
$sock2->set_login('admin|'.$user, 'pass');

    foreach($domains as $domain=>$data) {
        //get domain pointers for domain
        $sock2->query(
            '/CMD_API_DOMAIN_POINTER',
            array(
                'domain'=>str_replace('_', '.', $domain)
            )
        );

        $domain_pointers=$sock2->fetch_parsed_body();

        print_r($domain_pointers);
    }
}

Hope this helps someone in the future.

vespino
  • 1,714
  • 3
  • 15
  • 28