Execute cmd command using thread

This patch prepares the code for future stop command.
more_events
Alvaro Neira Ayuso 2020-01-16 17:52:23 +01:00 committed by Alvaro Neira Ayuso
parent b9c33f2c83
commit 230bdca0ea
1 changed files with 18 additions and 19 deletions

View File

@ -47,8 +47,23 @@ class restResponse():
class ogThread():
# Executing cmd thread
def execcmd(httpparser):
return ogOperations.execCMD(httpparser)
def execcmd(client, httpparser):
if httpparser.getCMD() == None:
client.send(restResponse.getResponse(ogResponses.BAD_REQUEST))
return
try:
shellout = ogOperations.execCMD(httpparser)
except ValueError as err:
client.send(restResponse.getResponse(ogResponses.BAD_REQUEST))
return
if httpparser.getEcho():
jsonResp = jsonResponse()
jsonResp.addElement('out', shellout)
client.send(restResponse.getResponse(ogResponses.OK, jsonResp))
else:
client.send(restResponse.getResponse(ogResponses.OK))
# Powering off thread
def poweroff():
@ -180,23 +195,7 @@ class ogRest():
client.send(restResponse.getResponse(ogResponses.OK, jsonResp))
def process_shellrun(self, client, httpparser):
if httpparser.getCMD() == None:
client.send(restResponse.getResponse(ogResponses.BAD_REQUEST))
return
try:
shellout = ogThread.execcmd(httpparser)
except ValueError as err:
print(err.args[0])
client.send(restResponse.getResponse(ogResponses.BAD_REQUEST))
return
if httpparser.getEcho():
jsonResp = jsonResponse()
jsonResp.addElement('out', shellout)
client.send(restResponse.getResponse(ogResponses.OK, jsonResp))
else:
client.send(restResponse.getResponse(ogResponses.OK))
threading.Thread(target=ogThread.execcmd, args=(client, httpparser,)).start()
def process_session(self, client, httpparser):
threading.Thread(target=ogThread.procsession, args=(client, httpparser,)).start()