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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| 1 - formulaire html
2 - script
<script type="text/javascript"
$("#lm2sstreamForm").validator().on("submit", function (event) {
if (event.isDefaultPrevented()) {
formError();
submitMSG(false, "Avez vous bien complete le formulaire ?");
} else {
event.preventDefault();
submitForm();
}
});
function submitForm(){
var url = $("#url").val();
var cle = $("#cle").val();
$.ajax({
type: "GET",
url: "http://192.168.1.38:2929/cgi-bin/test.cgi",
dataType : 'html',
data: "url=" + url + "&cle=" + cle,
success : function(text, statut){
if (text == "success"){
formSuccess();
} else {
formError();
submitMSG(false,text);
}
}
});
}
function formSuccess(){
$("#lm2sstreamForm")[0].reset();
submitMSG(true, "Lancement du programme OK !")
}
function formError(){
$("#lm2sstreamForm").removeClass().addClass('shake animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
$(this).removeClass();
});
}
function submitMSG(valid, msg){
if(valid){
var msgClasses = "h3 text-center tada animated text-success";
} else {
var msgClasses = "h3 text-center text-danger";
}
$("#msgSubmit").removeClass().addClass(msgClasses).text(msg);
}
</script>
3 - script cgi
#!/bin/sh
echo "Content-type: text/html; charset=UTF_8"
echo "Access-Control-Allow-Origin: *"
echo "Access-Control-Allow-Methods: GET, POST"
echo ""
if [ "$REQUEST_METHOD" = "GET" ]; then
Var1=$(echo "$QUERY_STRING" | sed -n 's/^.*url=\([^&]*\).*$/\1/p')
URL=$(echo -e $(echo "$Var1" | sed 's/+/ /g;s/%\(..\)/\\x\1/g;'))
Var2=$(echo "$QUERY_STRING" | sed -n 's/^.*cle=\([^&]*\).*$/\1/p')
CLE=$(echo -e $(echo "$Var2" | sed 's/+/ /g;s/%\(..\)/\\x\1/g;'))
echo "URL=${URL} -- CLE=${CLE}" > /tmp/myprogramm.trace
/usr/local/packages/myprogramm ${URL} ${CLE} >/dev/null 2>/dev/null &
echo $! > /tmp/myprogramm.pid
echo "success" # ceci s'affiche bien sur la page du formulaire une fois l'ensemble éxécuté.
else
echo "error"
fi
exit 0 |
Partager