Exécution Script avec Root sous Apache2
Bonjour à tous,
J’essaye depuis déjà pas mal de temps d'ajouter une exception de privilège pour l'utilisateur apache2 à savoir www-data afin de pouvoir dans un script PHP exécuter un autre script python nécessitant d'être en Root :
Mon script PHP :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
<?php
session_start();
if(isset($_SESSION['confirm']))
{
if(isset($_GET['action'])=='open')
{
system('sudo python /home/door/UP455.py');
}
else
{
system('sudo python /home/door/UP456.py');
}
?>
<div id="principal">
<a href="admin.php?action=open">OPEN</a><a href="admin.php?action=close">CLOSE</a>
</div>
<?php
}
else
{
header('Location: index.php');
}
?> |
Grâce à la commande en root "visudo", j'ai rajouté la ligne :
"www-data ALL=NOPASSWD: /home/door/UP455.py"
Comme ci-dessous dans le fichier Sudoers :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
www-data ALL=NOPASSWD: /home/door/UP455.py
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
pi ALL=(ALL) NOPASSWD: ALL |
Cepandant rien n'y fait, je retrouve toujours dans mes logs Apache2 aprés l’exécution PHP :
soit, ci je ne spécifie pas d'utilisateur :
Code:
sudo: no tty present and no askpass program specified
Ou alors avec dans php, si www-data est spécifié voici le résultat :
Code:
1 2 3 4 5 6 7
| FILE "home/door/UP455.py",line9, in <module>
GPIO.setup(GPIO_RELAY, GPIO.OUT)
RuntimeError : No access to /dev/mem. Try running as Root !
Sorry, user www-data is not allowed to execute /home/door/UP455.py |
Merci d'avance de vos réponses,
Sachant que le Script Python à la base marche très bien. ;)