comment lancer un script python depuis php
Salut à tous,
j'ai un problème de lancer mon script python depuis PHP. En fait, si je lance mon script PHP depuis la console, il fonctionne correctement par contre si j'utilise mon interface web il ne fonctionne pas.
le script python permet de créer un fichier texte qui stock le mot bloc suivi de l'ip passer en $_POST depuis PHP.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| #!/usr/bin/python
import sys
"""
This file will interface with the OSSIM-framework which will pro
bloc + ip
allow + ip
addAgent + ip
delAgent + ip
"""
cmd = sys.argv
wf = open("IPs.txt", "at")
if(cmd[1] == "bloc"):
wf.writelines(cmd[1] + " " + cmd[2] + "\n") |
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 31 32 33
| <html>
<link rel="stylesheet" type="text/css" href="../style/style.css"/>
<head>
<title>Block IP</title>
</script>
</head>
<body>
<h1> MODULE IPS :: BLOCK IP </h1>
<form name="form" method="POST" action="">
<center>
<table border=2 name="table">
<tr>
<th><label for="ip" title="IP a bloque">Adresse Ip To Block</label></th>
<td>
<input type=text name="ip" id="ip" title="Ecrire l'IP a bloque">
</td>
</tr>
<tr >
<td colspan=2><input type=submit value="Block" name="block" id="block" class="btn" style="font-size:12px" >
</tr>
</table>
</form>
<?php
if ($_POST["block"])
{
system("sudo python ifaceHandler.py bloc ".$_POST["ip"]);
echo '<script>alert("Ip ajoutee");</script>';
}
?>
</body>
</html> |