summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlvaro Neira Ayuso <aneira@soleta.eu>2020-01-14 18:35:47 +0100
committerAlvaro Neira Ayuso <alvaroneay@gmail.com>2020-01-19 19:50:44 +0100
commita9d81adb1f0e77bfae8a462d509206d43809f7a8 (patch)
tree8202689593429cbf906a70d28c0f4761bd471304 /src
parent336b02371df2dcce36fbe41531309c045ecbb4c1 (diff)
Include echo option for returning shell output
This patch adds a new echo option in /shell/run command. In case that the option is set up to true, the server will receive in the response a json with the shell output. Otherwise, the server will receive a response message without json body. A side effect of this change is that the command /shell/output/ disapears.
Diffstat (limited to 'src')
-rw-r--r--src/HTTPParser.py8
-rw-r--r--src/ogRest.py24
2 files changed, 15 insertions, 17 deletions
diff --git a/src/HTTPParser.py b/src/HTTPParser.py
index 819cd74..c422c12 100644
--- a/src/HTTPParser.py
+++ b/src/HTTPParser.py
@@ -23,6 +23,7 @@ class HTTPParser:
self.type = None
self.profile = None
self.id = None
+ self.echo = None
def parser(self,data):
self.requestLine, self.headersAlone = data.split('\n', 1)
@@ -52,6 +53,10 @@ class HTTPParser:
if "run" in cmd:
self.cmd = jsoncmd["run"]
+ try:
+ self.echo = jsoncmd["echo"]
+ except:
+ pass
if "disk" in cmd:
self.disk = jsoncmd["disk"]
@@ -140,3 +145,6 @@ class HTTPParser:
def getId(self):
return self.id
+
+ def getEcho(self):
+ return self.echo
diff --git a/src/ogRest.py b/src/ogRest.py
index c18b9f3..7d9120f 100644
--- a/src/ogRest.py
+++ b/src/ogRest.py
@@ -44,9 +44,8 @@ class restResponse():
class ogThread():
# Executing cmd thread
- def execcmd(msgqueue, httpparser):
- msgqueue.queue.clear()
- msgqueue.put(ogOperations.execCMD(httpparser))
+ def execcmd(httpparser):
+ return ogOperations.execCMD(httpparser)
# Powering off thread
def poweroff():
@@ -128,17 +127,12 @@ class ogResponses(Enum):
INTERNAL_ERR=3
class ogRest():
- def __init__(self):
- self.msgqueue = queue.Queue(1000)
-
def processOperation(self, httpparser, client):
op = httpparser.getRequestOP()
URI = httpparser.getURI()
if ("GET" in op):
if ("probe" in URI):
self.process_probe(client)
- elif ("shell/output" in URI):
- self.process_shellout(client)
elif ("hardware" in URI):
self.process_hardware(client)
elif ("run/schedule" in URI):
@@ -188,22 +182,18 @@ class ogRest():
return
try:
- ogThread.execcmd(self.msgqueue, httpparser)
+ shellout = ogThread.execcmd(httpparser)
except ValueError as err:
print(err.args[0])
client.send(restResponse.getResponse(ogResponses.BAD_REQUEST))
return
- client.send(restResponse.getResponse(ogResponses.OK))
-
- def process_shellout(self, client):
- jsonResp = jsonResponse()
- if self.msgqueue.empty():
- jsonResp.addElement('out', '')
+ if httpparser.getEcho() == "true":
+ jsonResp = jsonResponse()
+ jsonResp.addElement('out', shellout)
client.send(restResponse.getResponse(ogResponses.OK, jsonResp))
else:
- jsonResp.addElement('out', self.msgqueue.get())
- client.send(restResponse.getResponse(ogResponses.OK, jsonResp))
+ client.send(restResponse.getResponse(ogResponses.OK))
def process_session(self, client, httpparser):
threading.Thread(target=ogThread.procsession, args=(client, httpparser,)).start()