0

I am trying to run python script in Apache 2.x with mod_python. I edited httpd.conf with publisher

     LoadModule python_module /usr/local/apache2/modules/mod_python.so
     <Directory /usr/local/apache2/htdocs/mod_python>

    SetHandler mod_python
    PythonHandler mod_python.publisher
    PythonDebug On
</Directory>

I am trying to add a rule in firewall using python script which require root privilege. it's asking for root privilege ? Please somebody help.

2 Answers 2

1

Check it out.

"Similarly to pfctl(8), py-pf sends commands to the kernel through the ioctl(2) interface provided by the pf(4) pseudo-device; this allows Python to natively communicate with the kernel, thanks to the fcntl and ctypes modules, with no need to write a specific C extension module."

So, check permissions in pf pseudo-device by user running apache.

0

You need to use sudo to run pfctl from your web application and you need to add the "apache" user to the sudoers file with the rights to run pfctl without asking for a password.

NOTE: To modify your sudoers file use the command visudo as root, or an account with elevated privileges to do so.

You might also not want to use the obsolete mod_python way of running python web apps. Something like Bottle or Flask paired with the nginx in base would be a better option.

2
  • I am not using pfctl through python.I am using py-pf for adding rule in firewall(pf).HOw can i execute python script require root privilage. one more constraint from GUI ... exec in PHP is not allowed.. :( Apr 10, 2013 at 6:14
  • Then the python script using py-pf must be standalone from the web app and run with sudo. It's that or running apache as root, which I strongly recommend against. Apr 12, 2013 at 9:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .