function widget_coza_balance($vars)
{
    require_once ROOTDIR . '/includes/registrarfunctions.php';
    require_once ROOTDIR . '/includes/classes/AfriCC/autoload.php';
    require_once ROOTDIR . '/modules/registrars/coza/Factory.php';
    $params = getRegistrarConfigOptions('coza');
    $title = 'CO.ZA Balance';
    $content = '<p align ="center" class="textblack"><strong>%s</strong></p>';
    $epp_client = \COZA\Factory::build($params);
    try {
        $epp_client->connect();
        $frame = new \AfriCC\EPP\Extension\COZA\Info\CozaContact();
        $frame->setId(!empty($params['OTE']) && $params['OTE'] === 'on' ? $params['TestUsername'] : $params['Username']);
        $frame->requestBalance();
        $response = $epp_client->request($frame);
        if (!$response instanceof \AfriCC\EPP\Frame\Response) {
            unset($epp_client);
            return ['title' => $title, 'content' => sprintf($content, 'ERROR: no response')];
        }
        if (!$response->success()) {
            unset($epp_client);
            return ['title' => $title, 'content' => sprintf($content, sprintf('ERROR (%d): %s', $response->code(), $response->message()))];
        }
        $data = $response->data();
        if (empty($data) || !is_array($data) || empty($data['infData']['balance'])) {
            unset($epp_client);
            return ['title' => $title, 'content' => sprintf($content, 'ERROR: empty response')];
        }
        unset($epp_client);
        return ['title' => $title, 'content' => sprintf($content, 'Current registrar balance is R ' . $data['infData']['balance'])];
    } catch (Exception $e) {
        unset($epp_client);
        return ['title' => $title, 'content' => sprintf($content, 'ERROR: ' . $e->getMessage())];
    }
}
Exemplo n.º 2
0
/**
 * @link http://docs.whmcs.com/Hooks:ClientEdit
 * @param array $vars
 */
function hook_coza_client_update($vars)
{
    $params = getRegistrarConfigOptions('coza');
    $contact = getClientsDetails($vars['userid'], 0);
    $epp_client = \COZA\Factory::build($params);
    try {
        $epp_client->connect();
        try {
            \COZA\Factory::updateContactIfExists($epp_client, \COZA\Factory::getContactHandle($params, (int) $vars['userid']), $contact);
        } catch (Exception $e) {
            unset($epp_client);
            logActivity($e->getMessage(), $vars['userid']);
            return;
        }
        unset($epp_client);
        return;
    } catch (Exception $e) {
        unset($epp_client);
        logActivity('COZA/ContactUpdate: ' . $e->getMessage(), $vars['userid']);
        return;
    }
}
Exemplo n.º 3
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())];
    }
}
chdir(__DIR__);
// get system path
require 'config.php';
$whmcspath = realpath($whmcspath);
// required libs
require_once $whmcspath . '/init.php';
require_once $whmcspath . '/includes/registrarfunctions.php';
require_once $whmcspath . '/includes/classes/AfriCC/autoload.php';
require_once $whmcspath . '/modules/registrars/coza/Factory.php';
$result = mysql_query('SELECT * FROM `mod_coza_contact_deletequeue` WHERE `deleted` = 0 AND `next_due` < NOW() LIMIT 10');
if ($result === false || mysql_num_rows($result) === 0) {
    unset($result);
    exit(0);
}
$params = getRegistrarConfigOptions('coza');
$epp_client = \COZA\Factory::build($params);
try {
    $epp_client->connect();
    while ($row = mysql_fetch_assoc($result)) {
        $frame = new \AfriCC\EPP\Frame\Command\Delete\Contact();
        $frame->setId($row['contact_handle']);
        $response = $epp_client->request($frame);
        if (!$response instanceof \AfriCC\EPP\Frame\Response) {
            unset($epp_client);
            echo date('Y-m-d H:i:s ') . 'unable to get response' . PHP_EOL;
            exit(1);
        }
        if (!$response->success()) {
            echo date('Y-m-d H:i:s ') . $response->code() . ' - ' . $response->message() . PHP_EOL;
            update_query('mod_coza_contact_deletequeue', ['next_due' => date('Y-m-d H:i:s', strtotime('+6 day'))], ['id' => (int) $row['id']]);
        } else {