summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2021-11-15 12:08:43 +0100
committerJose M. Guisado <jguisado@soleta.eu>2021-11-15 13:39:42 +0100
commitab7abf96a6832a227fe2218bb191cc2d1fc73030 (patch)
tree108fecd80c757711553bc5488b4b96878fc8e12c
parent69d214f63b2aa8ef60489d56468393b70795124a (diff)
#1065 linux: add shell run operation
- Executed script runs with same privilege as ogClient process. - Uses subprocess.run instead of subprocess.Popen, it's a bit simpler. We can't specify executable, though. Shouldn't need so in Linux mode. - Uses shell=True, keep in mind security considerations listed at: https://docs.python.org/3/library/subprocess.html#security-considerations (shlex.quote can be used for unix shells)
-rw-r--r--src/linux/ogOperations.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/linux/ogOperations.py b/src/linux/ogOperations.py
index 3970d41..f47b7a8 100644
--- a/src/linux/ogOperations.py
+++ b/src/linux/ogOperations.py
@@ -7,10 +7,13 @@
# (at your option) any later version.
import os
-from pystray import Icon, Menu, MenuItem
+import subprocess
+from subprocess import CalledProcessError
import multiprocessing as mp
from multiprocessing import Process
+
from PIL import Image, ImageDraw
+from pystray import Icon, Menu, MenuItem
from src.ogRest import ThreadState
@@ -74,7 +77,21 @@ class OgLinuxOperations:
os.system('systemctl reboot')
def shellrun(self, request, ogRest):
- raise NotImplementedError
+ cmd = request.getrun()
+ try:
+ result = subprocess.run(cmd,
+ shell=True,
+ stdin=subprocess.DEVNULL,
+ capture_output=True,
+ text=True,
+ check=True)
+ except CalledProcessError as error:
+ if error.stderr:
+ return error.stderr
+ if error.stdout:
+ return error.stdout
+ return "{Non zero exit code and empty output}"
+ return result.stdout
def session(self, request, ogRest):
raise NotImplementedError