Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • awit-whmcs/whmcs-coza-epp
  • weheartwebsites/whmcs-coza-epp
  • qbitza/whmcs-coza-epp
  • wyrie/whmcs-coza-epp
  • Woklet/whmcs-coza-epp
  • jaymcc/whmcs-coza-epp
  • cmcawood/whmcs-coza-epp
7 results
Show changes
Showing
with 2611 additions and 0 deletions
...@@ -24,52 +24,110 @@ ...@@ -24,52 +24,110 @@
* @revision $Id: Protocol.php,v 1.4 2011/06/28 09:48:02 gavin Exp $ * @revision $Id: Protocol.php,v 1.4 2011/06/28 09:48:02 gavin Exp $
*/ */
require_once('PEAR.php');
/** /**
* Low-level functions useful for both EPP clients and servers * Low-level functions useful for both EPP clients and servers
* @package Net_EPP * @package Net_EPP
*/ */
class Net_EPP_Protocol { class Net_EPP_Protocol {
/** static function _fread_nb($socket,$length) {
* get an EPP frame from the remote peer $result = '';
* @param resource $socket a socket connected to the remote peer
* @return PEAR_Error|string either an error or a string // Loop reading and checking info to see if we hit timeout
*/ $info = stream_get_meta_data($socket);
static function getFrame($socket) { $time_start = microtime(true);
if (@feof($socket)) return new PEAR_Error('connection closed (socket is EOF)');
while (!$info['timed_out'] && !feof($socket)) {
$hdr = @fread($socket, 4); // Try read remaining data from socket
$buffer = @fread($socket,$length - strlen($result));
if (empty($hdr) && feof($socket)) { // If the buffer actually contains something then add it to the result
return new PEAR_Error('connection closed (no header received and socket is EOF)'); if ($buffer !== false) {
$result .= $buffer;
// If we hit the length we looking for, break
if (strlen($result) == $length) {
break;
}
} else {
// Sleep 0.25s
usleep(250000);
}
// Update metadata
$info = stream_get_meta_data($socket);
$time_end = microtime(true);
if (($time_end - $time_start) > 10) {
throw new exception('Timeout while reading from EPP Server');
}
}
// Check for timeout
if ($info['timed_out']) {
throw new Exception('Timeout while reading data from socket');
}
} elseif (false === $hdr) { return $result;
return new PEAR_Error('Error reading from peer: '.$php_errormsg); }
} else {
$unpacked = unpack('N', $hdr);
$length = $unpacked[1];
if ($length < 5) {
return new PEAR_Error(sprintf('Got a bad frame header length of %d bytes from peer', $length));
static function _fwrite_nb($socket,$buffer,$length) {
// Loop writing and checking info to see if we hit timeout
$info = stream_get_meta_data($socket);
$time_start = microtime(true);
$pos = 0;
while (!$info['timed_out'] && !feof($socket)) {
// Some servers don't like alot of data, so keep it small per chunk
$wlen = $length - $pos;
if ($wlen > 1024) { $wlen = 1024; }
// Try write remaining data from socket
$written = @fwrite($socket,substr($buffer,$pos),$wlen);
// If we read something, bump up the position
if ($written && $written !== false) {
$pos += $written;
// If we hit the length we looking for, break
if ($pos == $length) {
break;
}
} else { } else {
$length -= 4; // discard the length of the header itself // Sleep 0.25s
usleep(250000);
}
// Update metadata
$info = stream_get_meta_data($socket);
$time_end = microtime(true);
if (($time_end - $time_start) > 10) {
throw new exception('Timeout while writing to EPP Server');
}
}
// Check for timeout
if ($info['timed_out']) {
throw new Exception('Timeout while writing data to socket');
}
// sometimes the socket can be buffered with a limit below the frame return $pos;
// length, so we continually read from the socket until we get the full frame: }
$frame = '';
while (strlen($frame) < $length) $frame .= fread($socket, ($length));
if (strlen($frame) > $length) { /**
return new PEAR_Error(sprintf("Frame length (%d bytes) doesn't match header (%d bytes)", strlen($frame), ($length))); * get an EPP frame from the remote peer
* @param resource $socket a socket connected to the remote peer
* @throws Exception on frame errors.
* @return string the frame
*/
static function getFrame($socket) {
// Read header
$hdr = Net_EPP_Protocol::_fread_nb($socket,4);
if (strlen($hdr) < 4) {
throw new Exception(sprintf('Short read of %d bytes from peer', strlen($hdr)));
}
} else { // Unpack first 4 bytes which is our length
return $frame; $unpacked = unpack('N', $hdr);
$length = $unpacked[1];
if ($length < 5) {
throw new Exception(sprintf('Got a bad frame header length of %d bytes from peer', $length));
} } else {
} $length -= 4; // discard the length of the header itself
// Read frame
return Net_EPP_Protocol::_fread_nb($socket,$length);
} }
} }
...@@ -77,8 +135,18 @@ class Net_EPP_Protocol { ...@@ -77,8 +135,18 @@ class Net_EPP_Protocol {
* send an EPP frame to the remote peer * send an EPP frame to the remote peer
* @param resource $socket a socket connected to the remote peer * @param resource $socket a socket connected to the remote peer
* @param string $xml the XML to send * @param string $xml the XML to send
* @throws Exception when it doesn't complete the write to the socket
* @return the amount of bytes written to the frame
*/ */
static function sendFrame($socket, $xml) { static function sendFrame($socket, $xml) {
fwrite($socket, pack('N', (strlen($xml)+4)).$xml); // Grab XML length & add on 4 bytes for the counter
$length = strlen($xml) + 4;
$res = Net_EPP_Protocol::_fwrite_nb($socket, pack('N',$length) . $xml,$length);
// Check our write matches
if ($length != $res) {
throw new Exception("Short write when sending XML");
}
return $res;
} }
} }
This diff is collapsed.
<?php
# Copyright (c) 2012-2015, AllWorldIT
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Official Website:
# http://devlabs.linuxassist.net/projects/whmcs-coza-epp
# Lead developer:
# Nigel Kukard <nkukard@lbsd.net>
# ! ! P L E A S E N O T E ! !
# * If you make changes to this file, please consider contributing
# anything useful back to the community. Don't be a sour prick.
# * If you find this module useful please consider making a
# donation to support modules like this.
# WHMCS hosting, theming, module development, payment gateway
# integration, customizations and consulting all available from
# http://allworldit.com
# This file brings in a few constants we need
require_once dirname(__FILE__) . '/../../../init.php';
# Setup include dir
$include_path = ROOTDIR . '/modules/registrars/cozaepp';
set_include_path($include_path . PATH_SEPARATOR . get_include_path());
# Include EPP stuff we need
require_once 'cozaepp.php';
# Additional functions we need
require_once ROOTDIR . '/includes/functions.php';
# Include registrar functions aswell
require_once ROOTDIR . '/includes/registrarfunctions.php';
require_once 'Net/EPP/Frame.php';
require_once 'Net/EPP/Frame/Command.php';
require_once 'Net/EPP/ObjectSpec.php';
# Grab module parameters
$params = getregistrarconfigoptions('cozaepp');
echo("COZA-EPP Poll Report\n");
echo("---------------------------------------------------\n");
# Request balance from registrar
try {
$client = _cozaepp_Client();
# Loop with message queue
while (!$last) {
# Request messages
$request = $client->request('
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<poll op="req"/>
</command>
</epp>
');
# Decode response
$doc= new DOMDocument();
$doc->loadXML($request);
# Pull off code
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
if ($coderes == 1301 || $coderes == 1300) {
$msgs = $doc->getElementsByTagName('msg');
for ($m = 0; $m < $msgs->length; $m++) {
echo "CODE: $coderes, MESSAGE: '".$msgs->item($m)->textContent."'\n";
// Messages to ignore
$ignored = array(
'Command completed successfully; ack to dequeue',
'Command completed successfully; no messages'
);
// Logging message
if (!in_array(trim($msgs->item($m)->textContent), $ignored)) {
$message = mysql_real_escape_string(trim($msgs->item($m)->textContent));
$result = mysql_query("
INSERT INTO mod_awit_cozaepp_messages
(
created,
code,
message
)
VALUES
(
now(),
'$coderes',
'$message'
)
");
if (mysql_error($result)) {
echo "ERROR: couldn't log epp message: " . mysql_error($result);
}
}
}
# This is the last one
if ($coderes == 1300) {
$last = 1;
}
$msgq = $doc->getElementsByTagName('msgQ')->item(0);
if ($msgq) {
$msgid = $doc->getElementsByTagName('msgQ')->item(0)->getAttribute('id');
try {
$res = _cozaepp_ackpoll($client,$msgid);
} catch (Exception $e) {
echo("ERROR: ".$e->getMessage()."\n");
}
}
} else {
$msgid = $doc->getElementsByTagName('svTRID')->item(0)->textContent;
$msgs = $doc->getElementsByTagName('msg');
for ($m = 0; $m < $msgs->length; $m++) {
echo "\n";
echo "UNKNOWN CODE: $coderes, MESSAGE: '".$msgs->item($m)->textContent."', ID: $msgid\n";
echo $request;
echo "\n\n";
}
}
}
} catch (Exception $e) {
echo("ERROR: ".$e->getMessage(). "\n");
exit;
}
modules/registrars/cozaepp/logo.gif

5.04 KiB

<?php
# Copyright (c) 2012-2015, AllWorldIT
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Official Website:
# http://devlabs.linuxassist.net/projects/whmcs-coza-epp
# Lead developer:
# Nigel Kukard <nkukard@lbsd.net>
# ! ! P L E A S E N O T E ! !
# * If you make changes to this file, please consider contributing
# anything useful back to the community. Don't be a sour prick.
# * If you find this module useful please consider making a
# donation to support modules like this.
# WHMCS hosting, theming, module development, payment gateway
# integration, customizations and consulting all available from
# http://allworldit.com
# Function to implement the cozaepp balance widget
function widget_cozaepp_balance($vars) {
# Setup include dir
$include_path = ROOTDIR . '/modules/registrars/cozaepp';
set_include_path($include_path . PATH_SEPARATOR . get_include_path());
# Include EPP stuff we need
require_once 'cozaepp.php';
# Include registrar functions aswell
require_once ROOTDIR . '/includes/registrarfunctions.php';
# Grab module parameters
$params = getregistrarconfigoptions('cozaepp');
# Set widget contents
$title = "COZA EPP Balance";
$template = '<p align = "center" class="textblack"><strong>%s</strong></p>';
# Request balance from registrar
try {
$client = _cozaepp_Client();
$output = $client->request('
<epp:epp xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" xmlns:contact="urn:ietf:params:xml:ns:contact-1.0"
xmlns:cozacontact="http://co.za/epp/extensions/cozacontact-1-0">
<epp:command>
<epp:info>
<contact:info>
<contact:id>'.$params['Username'].'</contact:id>
</contact:info>
</epp:info>
<epp:extension>
<cozacontact:info>
<cozacontact:balance>true</cozacontact:balance>
</cozacontact:info>
</epp:extension>
</epp:command>
</epp:epp>
');
# Parse XML result
$doc= new DOMDocument();
$doc->loadXML($output);
$coderes = $doc->getElementsByTagName('result')->item(0)->getAttribute('code');
if ($coderes == '1000') {
$balancestr = "Current registrar balance is R ".$doc->getElementsByTagName('balance')->item(0)->nodeValue;
} else {
$balancestr = 'ERROR: Parsing';
}
} catch (Exception $e) {
return array('title'=>$title,'content'=>sprintf($template,"ERROR: ".$e->getMessage()));
}
return array('title'=>$title,'content'=>sprintf($template,$balancestr));
}
add_hook("AdminHomeWidgets",1,"widget_cozaepp_balance");