mirror of https://git.48k.eu/ogclient
#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)more_events
parent
69d214f63b
commit
ab7abf96a6
|
@ -7,10 +7,13 @@
|
||||||
# (at your option) any later version.
|
# (at your option) any later version.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from pystray import Icon, Menu, MenuItem
|
import subprocess
|
||||||
|
from subprocess import CalledProcessError
|
||||||
import multiprocessing as mp
|
import multiprocessing as mp
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
|
|
||||||
from PIL import Image, ImageDraw
|
from PIL import Image, ImageDraw
|
||||||
|
from pystray import Icon, Menu, MenuItem
|
||||||
|
|
||||||
from src.ogRest import ThreadState
|
from src.ogRest import ThreadState
|
||||||
|
|
||||||
|
@ -74,7 +77,21 @@ class OgLinuxOperations:
|
||||||
os.system('systemctl reboot')
|
os.system('systemctl reboot')
|
||||||
|
|
||||||
def shellrun(self, request, ogRest):
|
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):
|
def session(self, request, ogRest):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
Loading…
Reference in New Issue