Support IPv6 on connect and use SSH connection IP
authorChristian Weiske <cweiske@cweiske.de>
Tue, 6 Sep 2016 21:51:37 +0000 (23:51 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 6 Sep 2016 21:51:37 +0000 (23:51 +0200)
src/shpub/Command/Connect.php

index 0c86a8bac811e503bc26c9956220435203d7388a..b59de5ce10a668bebd91738b87de11af9fd87933 100644 (file)
@@ -65,6 +65,7 @@ class Command_Connect
         }
         $this->cfg->hosts[$hostKey] = $host;
         $this->cfg->save();
         }
         $this->cfg->hosts[$hostKey] = $host;
         $this->cfg->save();
+        echo "Server configuration $hostKey saved successfully.\n";
     }
 
     protected function fetchAccessToken(
     }
 
     protected function fetchAccessToken(
@@ -130,9 +131,20 @@ class Command_Connect
 
     protected function getHttpServerData()
     {
 
     protected function getHttpServerData()
     {
-        //FIXME: get IP from SSH_CONNECTION
         $ip   = '127.0.0.1';
         $port = 12345;
         $ip   = '127.0.0.1';
         $port = 12345;
+
+        if (isset($_SERVER['SSH_CONNECTION'])) {
+            $parts = explode(' ', $_SERVER['SSH_CONNECTION']);
+            if (count($parts) >= 3) {
+                $ip = $parts[2];
+            }
+        }
+        if (strpos($ip, ':') !== false) {
+            //ipv6
+            $ip = '[' . $ip . ']';
+        }
+
         $redirect_uri = 'http://' . $ip . ':' . $port . '/callback';
         $socketStr    = 'tcp://' . $ip . ':' . $port;
         return [$redirect_uri, $socketStr];
         $redirect_uri = 'http://' . $ip . ':' . $port . '/callback';
         $socketStr    = 'tcp://' . $ip . ':' . $port;
         return [$redirect_uri, $socketStr];