Only allow user input after successfully entering the container

feature/node-rewrite
Sven Slootweg 12 years ago
parent a3d18f2ea1
commit e2e7bd646f

@ -12,6 +12,8 @@ endpoint = "http://cvm.local/api.local.php"
def posix_shell(chan, ctid): def posix_shell(chan, ctid):
oldtty = termios.tcgetattr(sys.stdin) oldtty = termios.tcgetattr(sys.stdin)
enable_input = False
try: try:
tty.setraw(sys.stdin.fileno()) tty.setraw(sys.stdin.fileno())
tty.setcbreak(sys.stdin.fileno()) tty.setcbreak(sys.stdin.fileno())
@ -24,18 +26,27 @@ def posix_shell(chan, ctid):
if chan in r: if chan in r:
try: try:
buff = chan.recv(1024) buff = chan.recv(1024)
if len(buff) == 0: if len(buff) == 0:
print '\r\nYou have been logged out of your container. Goodbye!\r\n', print '\r\nYou have been logged out of your container. Goodbye!\r\n',
break break
if "entered into" in buff:
# Successfully entered into the container, we can enable user input now.
enable_input = True
sys.stdout.write(buff) sys.stdout.write(buff)
sys.stdout.flush() sys.stdout.flush()
except socket.timeout: except socket.timeout:
pass pass
if sys.stdin in r: if sys.stdin in r:
buff = sys.stdin.read(1) if enable_input == True:
if len(buff) == 0: buff = sys.stdin.read(1)
break
chan.send(buff) if len(buff) == 0:
break
chan.send(buff)
finally: finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty) termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)

Loading…
Cancel
Save