The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Formatting dumpzone results

Discussion in 'cPanel Developers' started by simonpearce, May 9, 2010.

  1. simonpearce

    simonpearce Well-Known Member

    Joined:
    Jun 20, 2003
    Messages:
    90
    Likes Received:
    0
    Trophy Points:
    6
  2. leefrom

    leefrom Active Member

    Joined:
    May 27, 2008
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    6
    Hi Simon,

    While it shouldn't be too bad to parse out the MX line, I agree it's inelegant. You might consider one of the relevant Email:: functions:

    ApiEmail < ApiDocs/Api1 < TWiki

    such as Email::listmxs, and then Email::delmx for deleting them nicely.
     
  3. FrankLaszlo

    FrankLaszlo Active Member

    Joined:
    Dec 19, 2008
    Messages:
    35
    Likes Received:
    0
    Trophy Points:
    6
    This may help. Here is my authentication function along with another function to convert the xml object to an array.

    Code:
    <?php
    
    include('config.php');
    
    function objectsIntoArray($arrObjData, $arrSkipIndices = array()) {
    
        $arrData = array();
        if (is_object($arrObjData)) {
            $arrObjData = get_object_vars($arrObjData);
        }
        if (is_array($arrObjData)) {
            foreach ($arrObjData as $index => $value) {
                if (is_object($value) || is_array($value)) {
                    $value = objectsIntoArray($value, $arrSkipIndices);
                }
                if (in_array($index, $arrSkipIndices)) {
                    continue;
                }
                $arrData[$index] = $value;
            }
        }
        return $arrData;
    }
    
    function cpdo($srv_ip, $whmhash, $query) {
    
        $myquery = "https://$srv_ip:2087/$query";
        $whmuser = 'root';
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $header[0] = "Authorization: WHM $whmuser:" . $whmhash;
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($curl, CURLOPT_URL, $myquery);
        $r = curl_exec($curl);
        if ($r == false) {
            error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $myquery");
        }
        curl_close($curl);
    
        $xmlObj = simplexml_load_string($r);
        $arrResult = objectsIntoArray($xmlObj);
        return $arrResult;
    }
    
    ?>
    
    From there, you can do something like this:

    Code:
            $query = "xml-api/dumpzone?domain=$domain";
            $zdata = cpdo($whmip, $whmhash, $query);
            foreach ($zdata['result']['record'] as $key => $val) {
                if ($val['type'] == "MX") {
                    print "This is an MX record\n";
                    print_r($val);
                }
            }
    
    Cheers.
     

Share This Page