Page 1 of 1

Can Python Plugins access the file system?

Posted: Monday 22 January 2018 11:25
by blauwebuis
Can python plugins call things like..

os.system()
call()

etc?

I can't seem to get this to work on my 433 RF Switches plugin.
https://github.com/flatsiedatsie/433Switches

If it is disabled on purpose somehow (security reasons?), then how can I do this:

- When users click a button in the interface I would like a RF sniffer script to be able to run for ten seconds in the background to listen to the 'on' signal from a remote control. Later on, I would like people to press a switch and then be able to transmit a code for a second.

Since the plugin development wiki page mentions that you should not use sleep and such in a plugin, I opted to call an external script in a new thread that would do this. But it now seems this is not possible? Is there any wat to make this work?

Re: Can Python Plugins access the file system?

Posted: Wednesday 24 January 2018 21:54
by blauwebuis
It took a lot of experimenting, but I managed to get it to work. For anyone else finding this:


callCommand = "sudo " + str(sys.executable) + " " + str(self.dirName) + "/433cloner.py --txpin " + str(self.txpin)
Domoticz.Log(str(callCommand))
try:
call (callCommand, shell=True)
except:
cloner = os.popen(callCommand).read()

Re: Can Python Plugins access the file system?

Posted: Saturday 27 January 2018 4:07
by Dnpwwo
@blauwebuis,

To answer your question, the only constrant on the Python Framework is that authors can't create threads or subprocesses, apart from that they run in the same context and have the same rights as the Domoticz main process.

They can certainly read and write to the filesystem (although you appear to be trying to run a command rather than access the file system).

This is not a security problem or a bug.

Plugin are designed to support hardware and to be equivalent to C++ supported hardware to make it easier for people to add support their own devices and to slow down the new additions to the C++ code base.

From a security prespective you are downloading code from the internet and executing it on your machine which has inherent risk regardless of language.