コード例 #1
0
ファイル: Ping.php プロジェクト: clue/psocksd
 public function runPing($socket, App $app)
 {
     try {
         $parsed = $app->parseSocksSocket($socket);
     } catch (Exception $e) {
         echo 'error: invalid ping target: ' . $e->getMessage() . PHP_EOL;
         return;
     }
     // TODO: remove hack
     // resolver can not resolve 'localhost' ATM
     if ($parsed['host'] === 'localhost') {
         $parsed['host'] = '127.0.0.1';
     }
     $direct = new Connector($app->getLoop(), $app->getResolver());
     $via = new Client($parsed['host'] . ':' . $parsed['port'], $app->getLoop(), $direct, $app->getResolver());
     if (isset($parsed['protocolVersion'])) {
         try {
             $via->setProtocolVersion($parsed['protocolVersion']);
         } catch (Exception $e) {
             echo 'error: invalid protocol version: ' . $e->getMessage() . PHP_EOL;
             return;
         }
     }
     if (isset($parsed['user']) || isset($parsed['pass'])) {
         $parsed += array('user' => '', 'pass' => '');
         try {
             $via->setAuth($parsed['user'], $parsed['pass']);
         } catch (Exception $e) {
             echo 'error: invalid authentication info: ' . $e->getMessage() . PHP_EOL;
             return;
         }
     }
     try {
         $via->setResolveLocal(false);
     } catch (UnexpectedValueException $ignore) {
         // ignore in case it's not allowed (SOCKS4 client)
     }
     $this->pingEcho($via->createConnector(), 'www.google.com', 80);
 }
コード例 #2
0
ファイル: App.php プロジェクト: clue/psocksd
 public function createConnectionManager($socket)
 {
     if ($socket === 'reject') {
         $this->stdio->write('reject' . PHP_EOL);
         return new ConnectionManagerLabeled(new ConnectionManagerReject(), '-reject-');
     }
     $direct = new Connector($this->loop, $this->resolver);
     if ($socket === 'none') {
         $via = new ConnectionManagerLabeled($direct, '-direct-');
         $this->stdio->write('use direct connection to target' . PHP_EOL);
     } else {
         $parsed = $this->parseSocksSocket($socket);
         // TODO: remove hack
         // resolver can not resolve 'localhost' ATM
         if ($parsed['host'] === 'localhost') {
             $parsed['host'] = '127.0.0.1';
         }
         $via = new Client($parsed['host'] . ':' . $parsed['port'], $this->loop, $direct, $this->resolver);
         if (isset($parsed['protocolVersion'])) {
             try {
                 $via->setProtocolVersion($parsed['protocolVersion']);
             } catch (Exception $e) {
                 throw new Exception('invalid protocol version: ' . $e->getMessage());
             }
         }
         if (isset($parsed['user']) || isset($parsed['pass'])) {
             $parsed += array('user' => '', 'pass' => '');
             try {
                 $via->setAuth($parsed['user'], $parsed['pass']);
             } catch (Exception $e) {
                 throw new Exception('invalid authentication info: ' . $e->getMessage());
             }
         }
         $this->stdio->write('use ' . $this->reverseSocksSocket($parsed) . ' as next hop');
         try {
             $via->setResolveLocal(false);
             $this->stdio->write(' (resolve remotely)');
         } catch (UnexpectedValueException $ignore) {
             // ignore in case it's not allowed (SOCKS4 client)
             $this->stdio->write(' (resolve locally)');
         }
         $via = new ConnectionManagerLabeled($via->createConnector(), $this->reverseSocksSocket($parsed));
         $this->stdio->write(PHP_EOL);
     }
     return $via;
 }