mirror of https://git.48k.eu/ogclient
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.more_events
parent
336b02371d
commit
a9d81adb1f
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue