Exemplo n.º 1
0
function coza_Sync($params)
{
    // ok here is another WHMCS fuckup. We can only do the following:
    // inactive => active
    // active => expired
    // e.g. it is not possible to mark domains that were transfered out as such.
    // we will do manual sql queries to achieve that. In future we might actually
    // delete the domain completely out of the DB instead, but currently I'd
    // like to know which domains were tagged as deleted and manually remove
    // them out of the DB if needed...
    // @todo check if domain is set to expire / donotrenew
    // https://www.registry.net.za/content.php?wiki=1&contentid=19&title=EPP%20Domain%20Extensions#autorenew_command
    $epp_client = \COZA\Factory::build($params);
    try {
        $epp_client->connect();
        // get domain info
        $frame = new \AfriCC\EPP\Frame\Command\Info\Domain();
        $frame->setDomain(\COZA\Factory::getDomain($params), 'none');
        $response = $epp_client->request($frame);
        unset($frame);
        if (!$response instanceof \AfriCC\EPP\Frame\Response) {
            unset($epp_client);
            return ['error' => 'COZA/Sync: unable to get response'];
        }
        // domain does not exist
        // @todo figure out if domain is still wanted or not
        if ($response->code() === 2303) {
            unset($epp_client);
            return ['error' => 'COZA/Sync: domain is not registered'];
        }
        // generic error
        if (!$response->success()) {
            unset($epp_client);
            return ['error' => 'COZA/Sync: ' . $response->message()];
        }
        $data = $response->data();
        if (empty($data['infData']['clID']) || empty($data['infData']['exDate'])) {
            unset($epp_client);
            return ['error' => 'COZA/Sync: unable to parse response'];
        }
        // lets check if domain still belongs to us, if not it was either
        // transferred out or never belonged to us in first place
        if ($data['infData']['clID'] !== \COZA\Factory::getRegistrarId($params)) {
            // as stated above we will have to do a manual sql query
            update_query('tbldomains', ['status' => 'Cancelled'], ['id' => (int) $params['domainid']]);
            unset($epp_client);
            return ['active' => false];
        }
        // check if expired...
        if (!empty($data['infData']['status'])) {
            if (!is_array($data['infData']['status'])) {
                $data['infData']['status'] = [$data['infData']['status']];
            }
            // https://www.registry.net.za/content2.php?contentid=55
            foreach ($data['infData']['status'] as $status) {
                if ($status === 'inactive' || $status === 'pendingDelete') {
                    unset($epp_client);
                    return ['expired' => true];
                }
            }
        }
        // else all fine, lets set to active and the new expiration date
        unset($epp_client);
        return ['active' => true, 'expirydate' => date('Y-m-d', strtotime($data['infData']['exDate']))];
    } catch (Exception $e) {
        unset($epp_client);
        return ['error' => sprintf('COZA/TransferSync: %s', $e->getMessage())];
    }
}