Reputation: 5
I'm trying execute a python script from php function shell_exec(), but this script require root privileges.
The python code is very simple. Using libraries wifi python does a scan of all the SSID and provides in output the information on the various wireless networks to which he had a scan in JSON format. WiFi libraries are scanning using iwlist that requires root privileges. If it is performed by a user who does not have root privileges, it returns only the information referring to the wifi where you are connected.
If I plug in my code the string
<?php
echo 'Current script owner:'. get_current_user ();
?>
I print screen "Current script owner: root", but if I try to run my code
<?php
$ Output = shell_exec ("python /home/acme/XDOMV2/conn1.py");
echo $ output;
?>
It will only return information about the network on which my debian system is connected. How to use lighttpd webserver and I have followed several guides about getting to the only result of having to re-install lighttpd. The question is, is there a way to run a python script as root from lighttpd? Where am I wrong?
Upvotes: 0
Views: 1620
Reputation: 23480
I would suggest to run the script as a user with proper privileages. This will minimize the risk for exploits on the system.
Next step would be ro run the script in a cron environment as that user (or root in the worst case scenario) and deliver the result via a database or a cached environment. You could also deliver the result via sockets or file handles.
Never enable a web environment to run scripts or well anything as root, it's dangerous and not how the software(lighttpd) were meant to operate.
This question belongs on UnixExchange but you can check this out:
And also check the docs for your lighttpd version, running as root is possible but not sound in any way.
Upvotes: 1