Skip to content

Commit

Permalink
Added reverse_ssh.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bwookieeeee committed Sep 6, 2018
1 parent dac8067 commit bc3fdd4
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions reverse_ssh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import argparse
import thread
import subprocess
from socketIO_client import SocketIO, LoggingNamespace

def main():
global commandArgs
global robotID
global appServerSocketIO

parser = argparse.ArgumentParser(description='start robot control program')

parser.add_argument('robot_id')
parser.add_argument('--reverse-ssh-key-file', default='/home/pi/reverse_ssh_key1.pem')
parser.add_argument('--reverse-ssh-host', default='[email protected]')

commandArgs = parser.parse_args()
print commandArgs
robotID = commandArgs.robot_id


print "connecting to app server socket.io"
appServerSocketIO = SocketIO('letsrobot.tv', 8022, LoggingNamespace)
print "finished connecting to app server"

appServerSocketIO.on('connect', onHandleAppServerConnect)
appServerSocketIO.on('reconnect', onHandleAppServerReconnect)
appServerSocketIO.on('disconnect', onHandleAppServerDisconnect)

appServerSocketIO.on('reverse_ssh_8872381747239', startReverseSshProcess)
appServerSocketIO.on('end_reverse_ssh_8872381747239', endReverseSshProcess)


while True:
appServerSocketIO.wait(seconds=1)



def startReverseSshProcess(*args):
thread.start_new_thread(handleStartReverseSshProcess, args)


def endReverseSshProcess(*args):
thread.start_new_thread(handleEndReverseSshProcess, args)



def handleStartReverseSshProcess(args):
print "starting reverse ssh"
appServerSocketIO.emit("reverse_ssh_info", "starting")

returnCode = subprocess.call(["/usr/bin/ssh",
"-X",
"-i", commandArgs.reverse_ssh_key_file,
"-N",
"-R", "2222:localhost:22",
commandArgs.reverse_ssh_host])

appServerSocketIO.emit("reverse_ssh_info", "return code: " + str(returnCode))
print "reverse ssh process has exited with code", str(returnCode)


def handleEndReverseSshProcess(args):
print "handling end reverse ssh process"
resultCode = subprocess.call(["killall", "ssh"])
print "result code of killall ssh:", resultCode



def onHandleAppServerConnect(*args):
print
print "chat socket.io connect"
print
identifyRobotID()


def onHandleAppServerReconnect(*args):
print
print "app server socket.io reconnect"
print
identifyRobotID()


def onHandleAppServerDisconnect(*args):
print
print "app server socket.io disconnect"
print



def identifyRobotID():
"""tells the server which robot is using the connection"""
print "sending identify robot id messages"
appServerSocketIO.emit('identify_robot_id', robotID);





main()

0 comments on commit bc3fdd4

Please sign in to comment.