Need help in retreving account stats
Hey guys i would like to retreive the hosting stats for a giving username/password on my server.
The exact info that we have in the cpanel left side would be greate.
Does anybody have a code that generates this kind of info?
Main Domain ***
Home Directory /home/***
Last login from 70.53.253.54
Disk Space Usage 20.84 / 2,000 MB
Monthly Bandwidth Transfer 173.55 / 20,000 MB
Email Accounts 1 / 100
Subdomains 0 / 10
Parked Domains 0 / 0
Addon Domains 0 / 0
FTP Accounts 0 / 50
Mailing Lists 0 / 10
All SQL Databases 0 / 20
MySQL Databases 0
MySQL Disk Space 0 MB
Mailing List Disk Space 0 MB
Hosting package 2 Gig
Server Name serveur
cPanel Version 11.38.2 (build 6)
Theme x3
Apache version 2.2.24
PHP version 5.3.26
MySQL version 5.1.70-cll
Architecture x86_64
Operating system linux
Shared IP Address ***
Path to sendmail /usr/sbin/sendmail
Path to Perl /usr/bin/perl
Perl version 5.8.8
Kernel version 2.6.32-358.6.1.el6.x86_64
cPanel Pro 1.0 (RC1)
Service Status Click to View
-
You can use the API2 call StatsBar::stat() for this: [url=http://docs.cpanel.net/twiki/bin/view/ApiDocs/Api2/ApiStatsBar]StatsBar Module Documentation A sample call to it looks like: 0, message => '', domain => '', }; my $user; if( $OPTS{'user'} ){ $user = isCpanelUsername( $OPTS{'user'} ) ? $OPTS{'user'} : ''; }else{ $user = $ENV{'REMOTE_USER'}; } if( $user eq '' ){ $return_hash->{message} = 'Invalid or empty {&user=} parameter'; } my $domain = Cpanel::AcctUtils::Domain::getdomain( $user ); if( $domain ){ $return_hash->{status} = 1; $return_hash->{domain} = $domain; $return_hash->{message} = 'Success'; } return $return_hash; } sub isCpanelUsername { unless ( $_[0] ) { return 0; } return $_[0] =~ /^[a-zA-Z][a-zA-Z0-9\-]{0,7}$/ ? 1 : 0; #alpha-numeric + dashes. starts with letter, max 8 chars } 1;
Then call:0 -
Hmm i get an error ... $ip = getenv('**.**.**.**'); $root_pass = getenv('***'); $account = "***"; $xmlapi = new xmlapi($ip); $xmlapi->password_auth($account,$root_pass); $xmlapi->set_debug(1); $args = array('display' => 'ftpaccounts|perlversion|hostname|operatingsystem'); print $xmlapi->api2_query($account, "StatsBar", "stat", $args );
and i get: Fatal error: Uncaught exception 'Exception' with message 'No host defined' in /home/***/public_html/wma/include/xmlapi.php:237 Stack trace: #0 /home/***/public_html/wma/module/accueil/accueil.php(27): xmlapi->__construct(false) #1 /home/***/public_html/wma/index.php(44): include('/home/***/...') #2 {main} thrown in /home/***/public_html/wma/include/xmlapi.php on line 2370 -
[quote="z-hoster, post: 1482931">Hmm i get an error ... $ip = getenv('**.**.**.**'); $root_pass = getenv('***'); $account = "***"; $xmlapi = new xmlapi($ip); $xmlapi->password_auth("***","***"); $xmlapi->set_debug(1); $args = array('display' => 'ftpaccounts|perlversion|hostname|operatingsystem'); $api_result = api2_query($user, 'StatsBar', 'stat', $args); print $xmlapi->$api_result;
and i get: Fatal error: Uncaught exception 'Exception' with message 'No host defined' in /home/***/public_html/wma/include/xmlapi.php:237 Stack trace: #0 /home/***/public_html/wma/module/accueil/accueil.php(27): xmlapi->__construct(false) #1 /home/***/public_html/wma/index.php(44): include('/home/***/...') #2 {main} thrown in /home/***/public_html/wma/include/xmlapi.php on line 237
The source for the PHP library shows that the error on line 237 will be thrown when the host is not set. You should ensure that you are pulling in the IP from getenv (which I'm not sure why you would use getenv() to define the cPanel server's IP address unless the website is on the same server where you'd use something like $_SERVER['HTTP_HOST">):/** * Connection * * $host/XMLAPI_HOST should always be equal to either the IP of the server or it's hostname */ // Set the host, error if not defined if ($host == null) { if ( (defined('XMLAPI_HOST')) && (strlen(XMLAPI_HOST) > 0) ) { $this->host = XMLAPI_HOST; } else { throw new Exception("No host defined"); } } else { $this->host = $host; }
0 -
Yeah thats what i thought but i tryed both ... giving the IP $ip = getenv('**.**.**.**'); and the var like this: $ip = getenv($_SERVER['HTTP_HOST">); both of them return the same error ... btw, thx for your help koston. It's really apreciated ;-) 0 -
[quote="z-hoster, post: 1482991">Yeah thats what i thought but i tryed both ... giving the IP $ip = getenv('**.**.**.**'); and the var like this: $ip = getenv($_SERVER['HTTP_HOST">); both of them return the same error ... btw, thx for your help koston. It's really apreciated ;-)
You shouldn't need the getenv() part. Try one of these:$ip = '**.**.**.**'; $ip = $_SERVER['HTTP_POST">;
0 -
Your right :-) no more error ... but nothing is showing ... how can i retrive the stats i requested to the API? My code looks like this so fare $ip = '**.**.**.**'; $root_pass = '***'; $account = "***"; $args = array('display' => 'ftpaccounts|perlversion|hostname|operatingsystem'); $xmlapi = new xmlapi($ip); $xmlapi->password_auth($account,$root_pass); $xmlapi->set_debug(1); print $xmlapi->api2_query($account, "StatsBar", "stat", $args );
Is the print at the end supose to print out the output? because right now it's sending back nothing. [COLOR="silver">- - - Updated - - - i just noticed the error file. looks like the access was denied ... the user/password was good (100% certain of that) is there something i need to activate in order for the API to work?[15-Oct-2013 10:27:47 America/Toronto] RESPONSE: Access denied 0 Access denied [15-Oct-2013 10:27:47 America/Toronto] SimpleXML var_dump: SimpleXMLElement Object ( [error] => Access denied [data] => SimpleXMLElement Object ( [result] => 0 [reason] => Access denied ) )
0 -
I just noticed that it works with my root user/password ... is it normal that normal users don't have access to the API? When i tryed with the root info i got an other error: Fatal error: Uncaught exception 'Exception' with message 'curl_exec threw error "SSL read: error:1408F119:SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac, errno 0" for 0 -
Since the output will be an object, you should do something like this to visualize it: $result = $xmlapi->api2_query($account, "StatsBar", "stat", $args ); var_dump($result);
The user should have access to api2 but it looks like the library sets the port to 2087 (WHM) by default. You'll need to use the set_port( $port ) function to set it to 2083 (cPanel) to access the API as the user.0 -
It worked. The SSL message i had when trying to log in with root was because the root user does not have a cpanel account. And the access denied i had was because of the port number. Thanks a lot for your help solving this issue. I should have everything i need to query cpanel and put up some nice graph on the users account now. thx a lot! 0
Please sign in to leave a comment.
Comments
11 comments