cPanel API for 2082
-
[quote="vijayv2205, post: 1624522">But I am unable to get list of all domain in side a particular account via 2082 port.
Could you elaborate on how you are attempting to obtain this list? Are you seeking to have parked/addon/subdomains of an account listed? Thank you.0 -
Hello, You can only call listaccts from WHM, not cPanel. All these calls are only available via 2087: [url=http://docs.cpanel.net/twiki/bin/view/SoftwareDevelopmentKit/XmlApi]XML and JSON APIs If you want to get the list of domains within an account as a user, unfortunately, you have to call multiple API2 calls like so to get parked,addon,and main domains, then another to get subdomains: $account = "username"; $xmlapi->set_port(2083); $parked_addon_main_domains = $xmlapi->api2_query($account, "DomainLookup", "getbasedomains" ); $sub_domains = $xmlapi->api2_query($account, "SubDomain", "listsubdomains" );
Unfortunately, this will also give you subdomains that are actually just the subdomain aliases for parked or addon domains. So, you'll actually want to do something like this:password_auth($cpanel_username,$cpanel_password); $xmlapi->set_output("json"); $xmlapi->set_port(2083); $xmlapi->set_debug(1); $domains = get_all_cpanel_domains($xmlapi, $cpanel_username); echo "DOMAINS:\n"; print_r($domains); function get_all_cpanel_domains($xmlapi, $username){ $all_sites_without_subdomains_that_are_actually_parked_or_addons = array(); $main_domain = get_primary_domain($xmlapi, $username); $document_roots = get_document_roots($xmlapi, $username); foreach ( $document_roots as $doc_root ) { $addon = 0; $matches = array(); #If the domain name is something.$mainDomain, it's either a sub or addon sub if( preg_match("/([a-zA-Z0-9\-]+)\.$main_domain/", $doc_root->domain, $matches ) ){ #now if the first part of the domain name is the same as the folder name, it's a subdomain, not an addon if( preg_match( "/.+$matches[0]$/", $doc_root->docRoot)) { $addon = 1; } } if ( !$addon ) { array_push( $all_sites_without_subdomains_that_are_actually_parked_or_addons, $doc_root ); #If you want just the domain name, and not also the doc root, comment out the line above #and uncomment the line below: #array_push( $all_sites_without_subdomains_that_are_actually_parked_or_addons, $doc_root->domain ); } } return $all_sites_without_subdomains_that_are_actually_parked_or_addons; } function get_primary_domain($xmlapi, $username){ $json = $xmlapi->api2_query($username, "DomainLookup", "getmaindomain" ); $result = json_decode($json); var_dump($result); #Debug info $main_domain = $result->cpanelresult->data[0]->main_domain; return $main_domain; } function get_document_roots($xmlapi, $username){ $json = $xmlapi->api2_query($username, "DomainLookup", "getdocroots" ); $result = json_decode($json); var_dump($result); #Debug info $document_roots = $result->cpanelresult->data; return $document_roots; }
It's also possible that you may not want to include domains that are redirected to another domain in your results. You'd have to do a similar filter against Mime::listredirects: [url=http://docs.cpanel.net/twiki/bin/view/ApiDocs/Api2/ApiMime#Mime::listredirects]Mime Module Documentation0
Please sign in to leave a comment.
Comments
2 comments