Ejemplo n.º 1
0
 /**
  * Returns a LDIF representation of the current node
  *
  * @param  array $options Additional options used during encoding
  * @return string
  */
 public function toLdif(array $options = [])
 {
     $attributes = array_merge(['dn' => $this->getDnString()], $this->getData(false));
     return Ldif\Encoder::encode($attributes, $options);
 }
Ejemplo n.º 2
0
 public function testEncodingWithJapaneseCharacters()
 {
     $data = array('dn' => 'uid=rogasawara,ou=営業部,o=Airius', 'objectclass' => array('top', 'person', 'organizationalPerson', 'inetOrgPerson'), 'uid' => array('rogasawara'), 'mail' => array('*****@*****.**'), 'givenname;lang-ja' => array('ロドニー'), 'sn;lang-ja' => array('小笠原'), 'cn;lang-ja' => array('小笠原 ロドニー'), 'title;lang-ja' => array('営業部 部長'), 'preferredlanguage' => array('ja'), 'givenname' => array('ロドニー'), 'sn' => array('小笠原'), 'cn' => array('小笠原 ロドニー'), 'title' => array('営業部 部長'), 'givenname;lang-ja;phonetic' => array('ろどにー'), 'sn;lang-ja;phonetic' => array('おがさわら'), 'cn;lang-ja;phonetic' => array('おがさわら ろどにー'), 'title;lang-ja;phonetic' => array('えいぎょうぶ ぶちょう'), 'givenname;lang-en' => array('Rodney'), 'sn;lang-en' => array('Ogasawara'), 'cn;lang-en' => array('Rodney Ogasawara'), 'title;lang-en' => array('Sales, Director'));
     $expected = 'dn:: dWlkPXJvZ2FzYXdhcmEsb3U95Za25qWt6YOoLG89QWlyaXVz' . PHP_EOL . 'objectclass: top' . PHP_EOL . 'objectclass: person' . PHP_EOL . 'objectclass: organizationalPerson' . PHP_EOL . 'objectclass: inetOrgPerson' . PHP_EOL . 'uid: rogasawara' . PHP_EOL . 'mail: rogasawara@airius.co.jp' . PHP_EOL . 'givenname;lang-ja:: 44Ot44OJ44OL44O8' . PHP_EOL . 'sn;lang-ja:: 5bCP56yg5Y6f' . PHP_EOL . 'cn;lang-ja:: 5bCP56yg5Y6fIOODreODieODi+ODvA==' . PHP_EOL . 'title;lang-ja:: 5Za25qWt6YOoIOmDqOmVtw==' . PHP_EOL . 'preferredlanguage: ja' . PHP_EOL . 'givenname:: 44Ot44OJ44OL44O8' . PHP_EOL . 'sn:: 5bCP56yg5Y6f' . PHP_EOL . 'cn:: 5bCP56yg5Y6fIOODreODieODi+ODvA==' . PHP_EOL . 'title:: 5Za25qWt6YOoIOmDqOmVtw==' . PHP_EOL . 'givenname;lang-ja;phonetic:: 44KN44Gp44Gr44O8' . PHP_EOL . 'sn;lang-ja;phonetic:: 44GK44GM44GV44KP44KJ' . PHP_EOL . 'cn;lang-ja;phonetic:: 44GK44GM44GV44KP44KJIOOCjeOBqeOBq+ODvA==' . PHP_EOL . 'title;lang-ja;phonetic:: 44GI44GE44GO44KH44GG44G2IOOBtuOBoeOCh+OBhg==' . PHP_EOL . 'givenname;lang-en: Rodney' . PHP_EOL . 'sn;lang-en: Ogasawara' . PHP_EOL . 'cn;lang-en: Rodney Ogasawara' . PHP_EOL . 'title;lang-en: Sales, Director';
     $actual = Ldif\Encoder::encode($data, array('sort' => false, 'version' => null));
     $this->assertEquals($expected, $actual);
 }
Ejemplo n.º 3
0
 public function testRoundtripEncoding()
 {
     $node = $this->_createTestNode();
     $ldif = $node->toLdif();
     $data = Ldif\Encoder::decode($ldif);
     $expected = array_merge(array('dn' => $node->getDnString()), $node->getData(false));
     $this->assertEquals($expected, $data);
 }
 /**
  * processClientHandshake($clientId, &$buffer) request header action
  * @param int $clientId connection id
  * @param string $buffer request message
  * @accss public
  * @return boolean
  */
 public function processClientHandshake($clientId, &$buffer)
 {
     $params = array();
     $this->console(sprintf("Clients: %d / %d", $this->_clientCount, $this->config['max_clients']));
     if (preg_match("/Sec-WebSocket-Version: (.*)\r\n/", $buffer, $match)) {
         $params['version'] = $match[1];
     } else {
         $this->console("The client doesn't support WebSocket");
         return false;
     }
     if ($params['version'] > 8) {
         // Extract header variables
         if (preg_match("/GET (.*) HTTP/", $buffer, $match)) {
             $params['root'] = $match[1];
         }
         if (preg_match("/Host: (.*)\r\n/", $buffer, $match)) {
             $params['host'] = $match[1];
         }
         if (preg_match("/Origin: (.*)\r\n/", $buffer, $match)) {
             $params['origin'] = $match[1];
         }
         if (preg_match("/Sec-WebSocket-Key: (.*)\r\n/", $buffer, $match)) {
             $params['key'] = $match[1];
         }
         // check request data
         if (array_search('', $params)) {
             return false;
         }
         $this->console("New client headers are:");
         $this->console("\t- Root: " . $params['root']);
         $this->console("\t- Host: " . $params['host']);
         $this->console("\t- Origin: " . $params['origin']);
         $this->console("\t- Sec-WebSocket-Key: " . $params['key']);
         $this->console("\t- Sec-WebSocket-Version: " . $params['version']);
         $acceptKey = Encoder::encode(pack('H*', sha1($params['key'] . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')));
         // setting up new response headers
         $headers = ['HTTP/1.1 101 WebSocket Protocol Handshake', 'Upgrade: websocket', 'Connection: Upgrade', 'WebSocket-Origin: ' . $params['origin'], 'WebSocket-Location: ws://' . $params['host'] . $params['root'], 'Sec-WebSocket-Accept: ' . $acceptKey];
         $headers = implode("\r\n", $headers) . "\r\n\r\n";
         // send headers back to client
         $socket = $this->clients[$clientId][0];
         //$this->console("Sending this response to the client {$clientId}:\r\n".$headers);
         $left = strlen($headers);
         $this->__sendframe($socket, $headers, $left);
         return true;
     } else {
         $this->console("WebSocket version 13 required (the client supports version {$params['version']})");
         return false;
     }
 }
Ejemplo n.º 5
0
 public function testDecodeSimpleSingleItemWithMultilineComment()
 {
     $data = "version: 1\ndn: cn=test3,ou=example,dc=cno\nobjectclass: oc1\nattr3:: w7bDpMO8\n\n# This is a comment\n on multiple lines\ndn: cn=test4,ou=example,dc=cno\nobjectclass: oc1\nattr3:: w7bDpMO8";
     $expected = array('dn' => 'cn=test3,ou=example,dc=cno', 'objectclass' => array('oc1'), 'attr3' => array('öäü'));
     $actual = Ldif\Encoder::decode($data);
     $this->assertEquals($expected, $actual[0]);
 }
Ejemplo n.º 6
0
 /**
  * Returns a LDIF representation of the current node
  *
  * @param  array $options Additional options used during encoding
  * @return string
  */
 public function toLdif(array $options = array())
 {
     $attributes = array_merge(array('dn' => $this->getDnString()), $this->getData(false));
     return LDAP\LDIF\Encoder::encode($attributes, $options);
 }