summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlvaro Neira Ayuso <aneira@soleta.eu>2020-01-16 17:52:23 +0100
committerAlvaro Neira Ayuso <alvaroneay@gmail.com>2020-01-19 19:50:44 +0100
commit230bdca0ea290541f6d7f835ff7dc8571fc9f506 (patch)
tree9a43962284dc5c596d62510828a8aa7e30ec9348
parentb9c33f2c83e1d77822140f5105cb1f73447361f9 (diff)
Execute cmd command using thread
This patch prepares the code for future stop command.
-rw-r--r--src/ogRest.py37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/ogRest.py b/src/ogRest.py
index b669be4..3775a56 100644
--- a/src/ogRest.py
+++ b/src/ogRest.py
@@ -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()