Re: Re: Connecting to an epp server

From: Date: Fri, 11 Apr 2008 06:31:05 +0000
Subject: Re: Re: Connecting to an epp server
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-272865@lists.php.net to get a copy of this message
epp-example from dns.be: <?php //============================================ function mod ($a, $b) { return $a % $b; } //============================================ class EppSocket { var $fp = null; function EppSocket() { } function connect($addr, $port, $timeout) {
    $this->fp = fsockopen ($addr, $port , $errno, $errstr, $timeout);
    return 0;
} function readInteger() {
    $buf = fread($this->fp, 4);
    if (strlen($buf) < 4)
    {
      echo "failed to read 4 bytes \n";
      exit;
    }
    $b0 = ord($buf[0]);
    $b1 = ord($buf[1]);
    $b2 = ord($buf[2]);
    $b3 = ord($buf[3]);
    $value = $b3 + 256* ($b2 + 256* ($b1 + 256* $b0));
    echo "integer read from socket: $value \n";
    return $value;
} function readString ($bytes) {
    echo "waiting for $bytes bytes\n";
    $left = $bytes;
    $data = '';
    while ( !feof($this->fp) ) {
      $chunk = fread($this->fp, $left);
      $data .= $chunk;
      $left = $left - strlen($chunk);
      if ($left == 0)
        break;
    }
    return $data;
} function readEppString() {
    $len = $this->readInteger();
    $len = $len - 4;
    return $this->readString ($len);
} function close() {
    fclose ($this->fp);
} // this will fail for values bigger than 0x7FFFFFFF (since PHP sucks at math) // on Windows: PHP thinks that 0xFFFFFFFE modulo 256 = 256 !?! // on Linux : PHP thinks that 0xFFFFFFFE modulo 256 = -2 !?! function writeInteger ($value) {
    $b3 = mod ($value, 256);
    $value = ($value - $b3)/256;
    $b2 = mod ($value, 256);
    $value = ($value - $b2)/256;
    $b1 = mod ($value, 256);
    $value = ($value - $b1)/256;
    $b0 = mod ($value, 256);
    echo "$value split up in bytes : $b0 $b1 $b2 $b3 \n";
    fwrite ($this->fp, chr($b0), 1);
    fwrite ($this->fp, chr($b1), 1);
    fwrite ($this->fp, chr($b2), 1);
    fwrite ($this->fp, chr($b3), 1);
} function writeEppString ($message) {
    $len = strlen ($message);
    echo "len: $len \n";
    $len = $len + 4;
    echo "total message length: $len bytes \n";
    $this->writeInteger ($len);
    echo "writing message itself \n";
    $written = fwrite ($this->fp, $message);
    echo "bytes written: $written \n";
} } //===================================================== { $socket = new EppSocket(); $server = "ssl://epp.example.org"; // replace with hostname of your registry's epp server $port = 33123; $timeout = 30; $ok = $socket->connect ($server, $port, $timeout); if ( $ok != 0) {
    echo "failed to connect to $server, check server name !!";
    exit;
} echo "ok, connected to $server at port $port\n"; $greeting = $socket->readEppString(); echo "=====================\n"; echo "$greeting "; echo "=====================\n"; $hello = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><epp xmlns=\"urn:ietf:params:xml:ns:epp-1.0\"> <hello/></epp>"; $socket->writeEppString ($hello); echo "waiting for reply \n"; $response = $socket->readEppString(); echo "=====================\n"; echo "$response "; echo "=====================\n"; $garbage = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><epp xmlns=\"urn:ietf:params:xml:ns:epp-1.0\"> <garbage/></epp>"; $socket->writeEppString ($garbage); $response = $socket->readEppString(); echo "=====================\n"; echo "$response "; echo "=====================\n"; $socket->close(); } ?> Alan Willsher schreef:
What is 4 bytes ? On Thu, Apr 10, 2008 at 3:35 PM, Paul van Brouwershaven < paul@vanbrouwershaven.com> wrote:
don't forget to send the 4 bytes! Alan Willsher schreef: Hi im trying to connect to Nominets EPP server
Details can be found here http://www.nominet.org.uk/registrars/systems/epp/ Im trying to send a login request the example can be found here http://www.nominet.org.uk/registrars/systems/epp/login/ My script seems to connect ok, but im recieving no response when I try to send the login xml details. <? $fp = @fsockopen('ssl://testbed-epp.nominet.org.uk', 700, $errno, $errstr, 100); echo "(".$errno." ".$errstr.")"; if(!$fp) { echo "Not Connected!"; } else { echo "Connected!\r\n"; $xml = '<?xml version="1.0" encoding="UTF-8"?> <epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<command>
     <login>
       <clID>EXAMPLE-TAG</clID>
       <pw>foo-BAR2</pw>
       <options>
         <version>1.0</version>
         <lang>en</lang>
       </options>
       <svcs>
          <objURI>http://www.nominet.org.uk/epp/xml/nom-account-1.0
</objURI>
          <objURI>http://www.nominet.org.uk/epp/xml/nom-domain-1.0
</objURI>
          <objURI>http://www.nominet.org.uk/epp/xml/nom-contact-1.0
</objURI>
          <objURI>http://www.nominet.org.uk/epp/xml/nom-ns-1.0</objURI>
       </svcs>
     </login>
     <clTRID>ABC-12345</clTRID>
</command> </epp>'; fputs($fp, $xml, strlen($xml)); while (!feof($fp)) {
     $response .= fgets($fp, 128);
} echo $response; fclose($fp); } ?>
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#272865) next »