summaryrefslogtreecommitdiffstats
path: root/src/HTTPParser.py
diff options
context:
space:
mode:
authorAlvaro Neira Ayuso <aneira@soleta.eu>2019-12-27 13:46:49 +0100
committerAlvaro Neira Ayuso <alvaroneay@gmail.com>2020-01-19 19:50:44 +0100
commite20daf639dd271268b172b42adc0d1b9d2103883 (patch)
treeaa9a27298d6a8b88d2a9d1364c5ab8afe00ea780 /src/HTTPParser.py
parentdfc97ffedb9a356299b593f76ce057f5953a77ab (diff)
Add shell run and output commands
Opengnsys needs a support to execute commands on the machine. This patch adds the support for executing two new commands "shell/run" and "shell/output". The first one, give us the support for executing a command in the machine and keep save in a queue the output. The second one, give us the support for sending the output from the command executed.
Diffstat (limited to 'src/HTTPParser.py')
-rw-r--r--src/HTTPParser.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/HTTPParser.py b/src/HTTPParser.py
index 7c64805..47c2204 100644
--- a/src/HTTPParser.py
+++ b/src/HTTPParser.py
@@ -1,5 +1,6 @@
import email
from io import StringIO
+import json
class HTTPParser:
def __init__(self):
@@ -11,24 +12,32 @@ class HTTPParser:
self.contentLen = None
self.operation = None
self.URI = None
+ self.cmd = None
def parser(self,data):
self.requestLine, self.headersAlone = data.split('\n', 1)
self.headers = email.message_from_file(StringIO(self.headersAlone))
- if 'host' in self.headers.keys():
- self.host = self.headers['host']
+ if 'Host' in self.headers.keys():
+ self.host = self.headers['Host']
- if 'content-type' in self.headers.keys():
- self.contentType = self.headers['content-type']
+ if 'Content-Type' in self.headers.keys():
+ self.contentType = self.headers['Content-Type']
- if 'content-length' in self.headers.keys():
- self.contentLen = int(self.headers['content-length'])
+ if 'Content-Length' in self.headers.keys():
+ self.contentLen = int(self.headers['Content-Length'])
if (not self.requestLine == None or not self.requestLine == ''):
self.operation = self.requestLine.split('/', 1)[0]
self.URI = self.requestLine.split('/', 1)[1]
+ if not self.contentLen == 0:
+ msgs = self.headersAlone.rstrip().split('\n')
+ cmd = msgs[len(msgs) - 1]
+ jsoncmd = json.loads(cmd)
+ if "run" in cmd:
+ self.cmd = jsoncmd["run"]
+
def getHeaderLine(self):
return self.headersAlone
@@ -52,3 +61,6 @@ class HTTPParser:
def getURI(self):
return self.URI
+
+ def getCMD(self):
+ return self.cmd