PHP & cPanel - Is there a way to get total size of all emails on a users account

自古美人都是妖i 提交于 2019-12-13 21:21:45

问题


I am not sure if this is possible. Is there a way with PHP to find out how much storage email accounts are taking on a cPanel server?

If not PHP, is there any way to do it and display on a website?

I've got the code for disk usage in a directory...but not sure how to calculate email storage used.

Note: I am not asking for anyone to write the code for this. If you have it/want to write it and want to share it..I wouldn't complain...but basically trying to find out if its even possible and maybe what to search for on google or something. I have searched for this wording it every way I know how and can't find a solution as of yet, which is why I am asking on here.


回答1:


You can use PHP Class for Interacting with cPanel's XML-API

  • https://github.com/CpanelInc/xmlapi-php
  • http://docs.cpanel.net/twiki/bin/vief/SoftwareDevelopmentKit/WebHome#cPanel%20%20WHM%27s%20API

Example PHP code is as follows:

<?php

include("xmlapi.php");

$ip = "localhost";

# The access has can be found on your server under WHM's "Setup remote access hash" section or at /root/.accesshash
$root_hash = 'MY HASH CODE HERE';

$xmlapi = new xmlapi($ip);
$xmlapi->hash_auth("MY WHM ACCOUNT USERNAME",$root_hash);
$xmlapi->return_xml(1);
$xmlapi->set_debug(1);

$username = CpanelUsername;

$xmlapi->accountsummary($username);

print $xmlapi->accountsummary($username);

?>

and it displays this:

Code:

<accountsummary>
  <acct>
    <disklimit>200M</disklimit>
    <diskused>63M</diskused>
    <domain>domain.com</domain>
    <email>email@domain.com</email>
    <ip>IP</ip>
    <maxaddons>100</maxaddons>
    <maxftp>100</maxftp>
    <maxlst>100</maxlst>
    <maxparked>100</maxparked>
    <maxpop>100</maxpop>
    <maxsql>100</maxsql>
    <maxsub>100</maxsub>
    <owner>OWNER</owner>
    <partition>home</partition>
    <plan>PLAN</plan>
    <shell>/usr/local/cpanel/bin/noshell</shell>
    <startdate>STARTDATE</startdate>
    <suspended>0</suspended>
    <suspendreason>not suspended</suspendreason>
    <suspendtime></suspendtime>
    <theme>x3</theme>
    <unix_startdate>UNIX_STARTDATE</unix_startdate>
    <user>USER</user>
  </acct>
  <status>1</status>
  <statusmsg>Ok</statusmsg>
</accountsummary>

$diskused =  $xmlapi->accountsummary->acct->diskused;

print $diskused;


来源:https://stackoverflow.com/questions/20112589/php-cpanel-is-there-a-way-to-get-total-size-of-all-emails-on-a-users-account

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!