Update invirt-vnc-client for recent token format change
[invirt/scripts/vnc-client.git] / invirt-vnc-client
index 8a17f1d..a7b87e9 100755 (executable)
@@ -10,7 +10,8 @@ def usage():
     print """%s [-v] [-l [HOST:]PORT] {-a AUTHTOKEN|VMNAME}
  -l, --listen [HOST:]PORT  port (and optionally host) to listen on for
                            connections (default is 127.0.0.1 and a randomly
-                           chosen port)
+                           chosen port). Use an empty HOST to listen on all
+                           interfaces (INSECURE!)
  -a, --authtoken AUTHTOKEN Authentication token for connecting to the VNC server
  VMNAME                    VM name to connect to (automatically fetches an
                            authentication token using remctl)
@@ -141,8 +142,9 @@ def main():
         elif o in ("-l", "--listen"):
             if ":" in a:
                 listen = a.split(":", 2)
+                listen[1] = int(listen[1])
             else:
-                listen[1] = a
+                listen[1] = int(a)
         elif o in ("-a", "--authtoken"):
             authtoken = a
         else:
@@ -157,12 +159,12 @@ def main():
             sys.exit(2)
         from subprocess import PIPE, Popen
         try:
-            p = Popen(["remctl", "remote", "control", args[0], "vnctoken"],
+            p = Popen(["remctl", "xvm-remote.mit.edu", "control", args[0], "vnctoken"],
                       stdout=PIPE)
         except OSError:
             if verbose: print "remctl not found in path. Trying remctl locker."
             p = Popen(["athrun", "remctl", "remctl",
-                       "remote", "control", args[0], "vnctoken"],
+                       "xvm-remote.mit.edu", "control", args[0], "vnctoken"],
                       stdout=PIPE)
         authtoken = p.communicate()[0]
         if p.returncode != 0:
@@ -173,9 +175,7 @@ def main():
 
     # Unpack authentication token
     try:
-        token_outer = base64.urlsafe_b64decode(authtoken)
-        token_outer = pickle.loads(token_outer)
-        token_inner = pickle.loads(token_outer["data"])
+        token_inner = pickle.loads(base64.urlsafe_b64decode((authtoken.split("."))[0]))
         machine = token_inner["machine"]
         connect_host = token_inner["connect_host"]
         connect_port = token_inner["connect_port"]
@@ -190,9 +190,9 @@ def main():
     if listen[1] is None:
         listen[1] = 5900
         ready = False
-        while not ready:
+        while not ready and listen[1] < 6000:
             try:
-                reactor.listenTCP(listen[1], ProxyFactory(connect_host, connect_port, authtoken, machine))
+                reactor.listenTCP(listen[1], ProxyFactory(connect_host, connect_port, authtoken, machine), interface=listen[0])
                 ready = True
             except error.CannotListenError:
                 listen[1] += 1