コード例 #1
0
ファイル: Status.php プロジェクト: clue/psocksd
 public function __construct(App $app)
 {
     $that = $this;
     $app->addCommand('status', function () use($that) {
         $that->run();
     })->shortHelp = 'show status';
 }
コード例 #2
0
ファイル: Help.php プロジェクト: clue/psocksd
 public function run(App $app)
 {
     echo 'psocksd help:' . PHP_EOL;
     $commands = $app->getCommands();
     $first = true;
     foreach ($commands as $command) {
         if (!isset($command->shortHelp)) {
             continue;
         }
         if ($first) {
             $first = false;
         } else {
             echo PHP_EOL;
         }
         echo '    ' . (string) $command . PHP_EOL;
         echo '        ' . $command->shortHelp . PHP_EOL;
     }
 }
コード例 #3
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);
 }
コード例 #4
0
ファイル: Quit.php プロジェクト: clue/psocksd
 public function run(App $app)
 {
     echo 'exiting...';
     $app->getLoop()->stop();
     echo PHP_EOL;
 }
コード例 #5
0
ファイル: Via.php プロジェクト: clue/psocksd
 public function runAdd($target, $socket, $priority, App $app)
 {
     try {
         $via = $app->createConnectionManager($socket);
     } catch (Exception $e) {
         echo 'error: invalid target: ' . $e->getMessage() . PHP_EOL;
         return;
     }
     try {
         $priority = $this->coercePriority($priority);
     } catch (Exception $e) {
         echo 'error: invalid priority: ' . $e->getMessage() . PHP_EOL;
         return;
     }
     $host = $target;
     $port = '*';
     $colon = strrpos($host, ':');
     // there is a colon and this is the only colon or there's a closing IPv6 bracket right before it
     if ($colon !== false && (strpos($host, ':') === $colon || strpos($host, ']') === $colon - 1)) {
         $port = (int) substr($host, $colon + 1);
         $host = substr($host, 0, $colon);
         // remove IPv6 square brackets
         if (substr($host, 0, 1) === '[') {
             $host = substr($host, 1, -1);
         }
     }
     $app->getConnectionManager()->addConnectionManagerFor($via, $host, $port, $priority);
 }