Exemplo n.º 1
0
<?php

include 'detect_porte.class.php';
//echo 'début </br>';
$odetect_porte = new detect_porte();
$result = $odetect_porte->launch_detect();
echo $result;
//fwrite($fp,"1\n");
//echo 'fwrite ok ';
/*
//création du fichier de flag disant au programme de continuer tant qu'il existe  
$fp=fopen("running_flag.txt","c+");
if (fwrite($fp,"1\n")) { 
echo "Le fichier à été créé avec succès</br>"; 
} else { 
// Erreur 
echo "Impossible de créer le fichier</br>"; 
} 
fclose($fp);
//lancement du programme de détection



//on vérifie que le fichier de flag du prog C n'existe pas sinon on va lancer 2 programmes en parallèle
$fichier = 'running_C.txt';
if( file_exists ( $fichier))
  echo "le programme est déjà en train de tourner</br>";
else
  exec("sudo /var/www/detect_porte/detect_porte /var/www/detect_porte/detect_porte.php  1");
*/
/*
function detectporte_action()
{
    global $_, $conf;
    $odetect_porte = new detect_porte();
    switch ($_['action']) {
        case 'detectporte_sors':
            global $_;
            //activation de la détection
            $result = $odetect_porte->launch_detect();
            if ($result == 1) {
                $possible_answers = array('OK. Jactive la sécurité.', 'Jactive la sécurité. Passe une bonne journée', 'OK. Jactive la sécurité. A plus', 'OK. Je moccupe du reste');
            } else {
                $possible_answers = array('OK. La sécurité tourne déjà.', ' La sécurité tourne déjà. Passe une bonne journée', 'OK.  La sécurité tourne déjà. A plus', 'OK. Je moccupe du reste');
            }
            $affirmation = $possible_answers[rand(0, count($possible_answers) - 1)];
            $response = array('responses' => array(array('type' => 'talk', 'sentence' => $affirmation)));
            $json = json_encode($response);
            echo $json == '[]' ? '{}' : $json;
            break;
        case 'detectporte_securite':
            global $_;
            //activation de la détection
            $result = $odetect_porte->launch_detect();
            if ($result == 1) {
                $possible_answers = array('Sécurité activée.', "OK. C'est fait");
            } else {
                $possible_answers = array('Il tourne déjà');
            }
            $affirmation = $possible_answers[rand(0, count($possible_answers) - 1)];
            $response = array('responses' => array(array('type' => 'talk', 'sentence' => $affirmation)));
            $json = json_encode($response);
            echo $json == '[]' ? '{}' : $json;
            break;
        case 'detectporte_desactive':
            global $_;
            //activation de la détection
            $result = $odetect_porte->stop_detect();
            if ($result == 1) {
                $possible_answers = array('Sécurité désactivée.');
            } else {
                $possible_answers = array('Il est déjà stopé', 'Il ne tournait pas');
            }
            $affirmation = $possible_answers[rand(0, count($possible_answers) - 1)];
            $response = array('responses' => array(array('type' => 'talk', 'sentence' => $affirmation)));
            $json = json_encode($response);
            echo $json == '[]' ? '{}' : $json;
            break;
        case 'detectporte_rentre':
            global $_;
            //activation de la détection
            $result = $odetect_porte->stop_detect();
            if ($result == 1) {
                $possible_answers = array('Bienvenu. Je désactive la Sécurité.', "Coucou. j'ai coupé la sécurité");
            } else {
                $possible_answers = array('Bienvenu. ', 'Coucou.');
            }
            $affirmation = $possible_answers[rand(0, count($possible_answers) - 1)];
            $response = array('responses' => array(array('type' => 'talk', 'sentence' => $affirmation)));
            $json = json_encode($response);
            echo $json == '[]' ? '{}' : $json;
            break;
    }
}