Пример #1
0
 static function getAllUsers()
 {
     $userManager = new User();
     $users = $userManager->populate();
     Plugin::callHook("user_get_all", array(&$users));
     usort($users, "User::userorder");
     return $users;
 }
Пример #2
0
 function handleData($client, $data)
 {
     $_ = json_decode($data, true);
     if (!isset($_['action'])) {
         $_['action'] = '';
     }
     switch ($_['action']) {
         case 'CLIENT_INFOS':
             $client->type = $_['type'];
             $client->location = $_['location'];
             $this->log('setting infos ' . $client->location . ' for ' . $client->name);
             break;
         case 'GET_SPEECH_COMMANDS':
             $response = array();
             Plugin::callHook("vocal_command", array(&$response, YANA_URL));
             $this->send($this->connected[$client->id]->socket, '{"action":"ADD_COMMANDS","commands":' . json_encode($response['commands']) . '}');
             break;
         case 'CATCH_COMMAND':
             $response = array();
             Plugin::callHook("vocal_command", array(&$response, ''));
             foreach ($response['commands'] as $command) {
                 if ($command['command'] != $_['command']) {
                     continue;
                 }
                 if (isset($command['url'])) {
                     $this->url(YANA_URL . '/action.php' . $command['url']);
                 }
             }
             Plugin::callHook('listen', array($_['command'], $_['text'], $_['confidence']));
             break;
         case '':
         default:
             //$this->talk("Coucou");
             //$this->sound("C:/poule.wav");
             //$this->execute("C:\Program Files (x86)\PuTTY\putty.exe");
             $this->log($client->name . '(' . $client->type . ') send ' . $data);
             break;
     }
     $this->updateClient($client);
     //system('php '.realpath(dirname(__FILE__)).'\action.php '.$json['action'],$out);
     //$this->send($socket,$out);
 }
Пример #3
0
function room_plugin_page($_)
{
    if (isset($_['module']) && $_['module'] == 'room') {
        $roomManager = new Room();
        $rooms = $roomManager->populate();
        //if (!isset($_['id']) && count($rooms)>0)  $_['id'] = $rooms[0]->getId();
        $currentRoom = new Room();
        ?>

		<div class="row">
			<div class="span12">
				<ul class="nav nav-tabs">
				<li <?php 
        if (!isset($_['id'])) {
            ?>
 class="active" <?php 
        }
        ?>
><a href="index.php?module=room"><i class="fa fa-angle-right"></i> Toutes les pièces</a></li>
					<?php 
        foreach ($rooms as $room) {
            if (isset($_['id']) && $room->getId() == $_['id']) {
                $currentRoom = $room;
            }
            ?>
					<li <?php 
            echo isset($_['id']) && $room->getId() == $_['id'] ? 'class="active"' : '';
            ?>
><a href="index.php?module=room&id=<?php 
            echo $room->getId();
            ?>
"><i class="fa fa-angle-right"></i> <?php 
            echo $room->getName();
            ?>
</a></li>
					<?php 
        }
        ?>
				</ul>

			</div>
		</div>
		<div class="row">

			<div class="span12">

				<?php 
        if ($currentRoom->getId() != 0) {
            Plugin::callHook("node_display", array($currentRoom));
        } else {
            foreach ($rooms as $room) {
                Plugin::callHook("node_display", array($room));
            }
        }
        ?>

			</div>
		</div>


		<?php 
    }
}
Пример #4
0
<?php

require_once dirname(__FILE__) . '/common.php';
$menuItems = array();
Plugin::callHook("menubar_pre_home", array(&$menuItems));
uasort($menuItems, function ($a, $b) {
    return $a['sort'] > $b['sort'] ? 1 : -1;
});
$tpl->assign('menuItems', $menuItems);
?>

Пример #5
0
 function handleData($client, $data)
 {
     $this->log("Try to parse received data : " . $data);
     try {
         $datas = explode('<EOF>', $data);
         foreach ($datas as $data) {
             $_ = json_decode($data, true);
             if (!$_) {
                 throw new Exception("Unable to parse data : " . $data);
             }
             if (!isset($_['action'])) {
                 $_['action'] = '';
             }
             $this->log("Parsed action : " . $_['action']);
             switch ($_['action']) {
                 case 'TALK':
                     $this->talkAnimate();
                     $this->talk($_['parameter']);
                     break;
                 case 'TALK_FINISHED':
                     $this->muteAnimate();
                     break;
                 case 'EMOTION':
                     $this->emotion($_['parameter']);
                     break;
                 case 'IMAGE':
                     $this->image($_['parameter']);
                     break;
                 case 'SOUND':
                     $this->sound($_['parameter']);
                     break;
                 case 'EXECUTE':
                     $this->execute($_['parameter']);
                     break;
                 case 'CLIENT_INFOS':
                     $client->type = $_['type'];
                     $client->location = $_['location'];
                     $userManager = new User();
                     $myUser = $userManager->load(array('token' => $_['token']));
                     if (isset($myUser) && $myUser != false) {
                         $myUser->loadRight();
                     }
                     $client->user = !$myUser ? new User() : $myUser;
                     $this->log('setting infos ' . $client->type . ' - ' . $client->location . ' for ' . $client->name . ' with user:'******'GET_SPEECH_COMMANDS':
                     $response = array();
                     Plugin::callHook("vocal_command", array(&$response, YANA_URL));
                     $commands = array();
                     foreach ($response['commands'] as $command) {
                         unset($command['url']);
                         $this->send($this->connected[$client->id]->socket, '{"action":"ADD_COMMAND","command":' . json_encode($command) . '}');
                     }
                     $this->send($this->connected[$client->id]->socket, '{"action":"UPDATE_COMMANDS"}');
                     break;
                 case 'CATCH_COMMAND':
                     $response = "";
                     $this->log("Call listen hook (v2.0 plugins) with params " . $_['command'] . " > " . $_['text'] . " > " . $_['confidence']);
                     Plugin::callHook('listen', array($_['command'], trim(str_replace($_['command'], '', $_['text'])), $_['confidence']));
                     break;
                 case '':
                 default:
                     //$this->talk("Coucou");
                     //$this->sound("C:/poule.wav");
                     //$this->execute("C:\Program Files (x86)\PuTTY\putty.exe");
                     $this->log($client->name . '(' . $client->type . ') send ' . $data);
                     break;
             }
             $this->updateClient($client);
         }
     } catch (Exception $e) {
         $this->log("ERROR : " . $e->getMessage());
     }
     //system('php '.realpath(dirname(__FILE__)).'\action.php '.$json['action'],$out);
     //$this->send($socket,$out);
 }
Пример #6
0
        $page = isset($_['page']) ? $_['page'] : 1;
        $pages = $articlePerPages > 0 ? ceil($numberOfItem / $articlePerPages) : 1;
        $startArticle = ($page - 1) * $articlePerPages;
        if ($articleDisplayHomeSort) {
            $order = 'pubdate desc';
        } else {
            $order = 'pubdate asc';
        }
        if ($optionFeedIsVerbose) {
            $events = $eventManager->loadAllOnlyColumn($target, $filter, $order, $startArticle . ',' . $articlePerPages);
        } else {
            $events = $eventManager->getEventsNotVerboseFeed($startArticle, $articlePerPages, $order, $target);
        }
        $tpl->assign('numberOfItem', $numberOfItem);
        break;
}
$tpl->assign('pages', $pages);
$tpl->assign('page', $page);
for ($i = $page - PAGINATION_SCALE <= 0 ? 1 : $page - PAGINATION_SCALE; $i < ($page + PAGINATION_SCALE > $pages + 1 ? $pages + 1 : $page + PAGINATION_SCALE); $i++) {
    $pagesArray[] = $i;
}
$tpl->assign('pagesArray', $pagesArray);
$tpl->assign('previousPages', $page - PAGINATION_SCALE < 0 ? -1 : $page - PAGINATION_SCALE - 1);
$tpl->assign('nextPages', $page + PAGINATION_SCALE > $pages + 1 ? -1 : $page + PAGINATION_SCALE);
Plugin::callHook("index_post_treatment", array(&$events));
$tpl->assign('events', $events);
$tpl->assign('time', $_SERVER['REQUEST_TIME']);
$tpl->assign('hightlighted', 0);
$tpl->assign('scroll', false);
$view = 'index';
require_once 'footer.php';
function dash_monitoring_plugin_actions()
{
    global $myUser, $_, $conf;
    switch ($_['action']) {
        case 'dash_monitoring_plugin_load':
            if ($myUser == false) {
                exit('Vous devez vous connecter pour cette action.');
            }
            header('Content-type: application/json');
            $response = array();
            switch ($_['bloc']) {
                case 'ram':
                    $response['title'] = 'RAM';
                    $hdds = Monitoring::ram();
                    $response['content'] = '
						<div style="width: 100%">
							<canvas id="RAM_PIE"></canvas>
							<br/><br/>
							<ul class="graphic_pane">
								<li class="pane_orange">
									<h1>RAM UTILISEE</h1>
									<h2>' . $hdds['percentage'] . '%</h2>
								</li><li class="pane_cyan">
									<h1>RAM LIBRE</h1>
									<h2>' . $hdds['free'] . ' Mo</h2>
								</li><li class="pane_red">
									<h1>RAM TOTALE</h1>
									<h2>' . $hdds['total'] . ' Mo</h2>
								</li>
							</ul>
						</div>

						<script>

							$("#RAM_PIE:visible").chart({
								type : "doughnut",
								label : ["RAM UTILISEE","RAM LIBRE"],
								backgroundColor : ["' . ($hdds['percentage'] > 80 ? '#E64C65' : '#FCB150') . '","#4FC4F6"],
								segmentShowStroke:false,
								data : [' . $hdds['percentage'] . ',' . (100 - $hdds['percentage']) . ']
							});
							
						</script>';
                    break;
                case 'system':
                    $response['title'] = 'Système';
                    if (PHP_OS != 'WINNT') {
                        $heat = Monitoring::heat();
                        $cpu = Monitoring::cpu();
                    }
                    $response['content'] = '<ul class="yana-list">
				    	<li><strong>Distribution :</strong> ' . Monitoring::distribution() . '</li>
				    	<li><strong>Kernel :</strong> ' . Monitoring::kernel() . '</li>
				    	<li><strong>HostName :</strong> ' . Monitoring::hostname() . '</li>
				    	<li><strong>Température :</strong>  <span class="label ' . $heat["label"] . '">' . $heat["degrees"] . '°C</span></li>
				    	<li><strong>Temps de marche :</strong> ' . Monitoring::uptime() . '</li>
				    	<li><strong>CPU :</strong>  <span class="label label-info">' . $cpu['current_frequency'] . ' Mhz</span> (Max ' . $cpu['maximum_frequency'] . '  Mhz/ Min ' . $cpu['minimum_frequency'] . '  Mhz)</li>
				    	<li><strong>Charge :</strong>  <span class="label label-info">' . $cpu['loads'] . ' </span>  | ' . $cpu['loads5'] . '  5min | ' . $cpu['loads15'] . '  15min</li>
				    </ul>';
                    break;
                case 'vocal':
                    if ($myUser->getId() == '') {
                        exit('{"error":"invalid or missing token"}');
                    }
                    if (!$myUser->can('vocal', 'r')) {
                        exit('{"error":"insufficient permissions for this account"}');
                    }
                    list($host, $port) = explode(':', $_SERVER['HTTP_HOST']);
                    $actionUrl = 'http://' . $host . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'];
                    $actionUrl = substr($actionUrl, 0, strpos($actionUrl, '?'));
                    Plugin::callHook("vocal_command", array(&$response, $actionUrl));
                    $response['title'] = count($response['commands']) . ' Commandes vocales';
                    $response['content'] = '<ul class="yana-list">';
                    foreach ($response['commands'] as $command) {
                        $response['content'] .= '<li title="Sensibilité : ' . $command['confidence'] . '">' . $command['command'] . '</li>';
                    }
                    $response['content'] .= '</ul>';
                    break;
                case 'logs':
                    if ($myUser->getId() == '') {
                        exit('{"error":"invalid or missing token"}');
                    }
                    $response['title'] = 'Logs';
                    $logs = dirname(__FILE__) . '/../../' . LOG_FILE;
                    $response['content'] = '<div style="overflow:auto;max-height:200px;"><ul class="yana-list" style="margin:0px;">';
                    if (file_exists($logs)) {
                        $lines = file($logs);
                        foreach ($lines as $i => $line) {
                            $response['content'] .= '<li style="font-size:8px;' . ($i % 2 == 0 ? 'background-color:#F4F4F4;' : '') . '">' . $line . '</li>';
                        }
                    } else {
                        $response['content'] .= '<li>Aucun logs</li>';
                    }
                    $response['content'] .= '</ul></div>';
                    break;
                case 'network':
                    $response['title'] = 'Réseau';
                    $ethernet = array();
                    $lan = '';
                    $wan = '';
                    $http = '';
                    $connections = '';
                    if (PHP_OS != 'WINNT') {
                        $ethernet = Monitoring::ethernet();
                        $lan = Monitoring::internalIp();
                        $wan = Monitoring::externalIp();
                        $http = Monitoring::webServer();
                        $connections = Monitoring::connections();
                    }
                    $response['content'] = '<ul class="yana-list">
					    	<li><strong>IP LAN :</strong> <code>' . $lan . '</code></li>
					    	<li><strong>IP WAN :</strong> <code>' . $wan . '</code></li>
					    	<li><strong>Serveur HTTP :</strong> ' . $http . '</li>
					    	<li><strong>Ethernet :</strong> ' . $ethernet['up'] . ' Montant / ' . $ethernet['down'] . ' Descendant</li>
					    	<li><strong>Connexions :</strong>  <span class="label label-info">' . $connections . '</span></li>
					    </ul>';
                    break;
                case 'gpio':
                    $response['title'] = 'GPIO';
                    $gpios = array();
                    $gpios = Monitoring::gpio();
                    $model = System::getModel();
                    $pinLabelsRange = System::getPinForModel($model['type'], $model['version']);
                    $response['title'] = 'RPI Type ' . $model['type'] . ' V' . $model['version'] . ' (' . count($gpios) . ' pins)';
                    $response['content'] .= '<table class="gpio_container">';
                    $response['content'] .= '<tr>';
                    foreach ($pinLabelsRange as $range => $pinLabels) {
                        $response['content'] .= '<td valign="top"><table>';
                        foreach ($pinLabels as $pin) {
                            $roleColor = 'transparent';
                            $class = 'gpio_state_' . ($gpios[$pin->wiringPiNumber] ? 'on' : 'off');
                            if ($pin->name == '5V' || $pin->name == '3.3V') {
                                $class = 'gpio_power';
                            }
                            if ($pin->name == '0V' || $pin->name == 'DNC') {
                                $class = 'gpio_ground';
                            }
                            $response['content'] .= '<div class="' . $class . '" title="Role : ' . ($pin->role == '' ? 'GPIO' : $pin->role) . ', Position physique : ' . $pin->physicalNumber . ', Numero BMC : ' . $pin->bcmNumber . '" onclick="change_gpio_state(' . $pin->wiringPiNumber . ',this);">';
                            $response['content'] .= '<span style="' . ($range == 0 ? 'float:right;' : '') . '"></span> ' . $pin->name . ' <small>(' . ($pin->role == '' ? 'GPIO' : $pin->role) . ')</small>';
                            $response['content'] .= '</div>';
                        }
                        $response['content'] .= '</table></td>';
                    }
                    $response['content'] .= '</tr>';
                    $response['content'] .= '</table>';
                    break;
                case 'users':
                    $users = array();
                    if (PHP_OS != 'WINNT') {
                        $users = Monitoring::users();
                    }
                    $response['title'] = count($users) . ' utilisateurs connectés';
                    $response['content'] = '<ul class="yana-list">';
                    foreach ($users as $value) {
                        $response['content'] .= '<li>Utilisateur <strong class="badge">' . $value['user'] . '</strong> IP : <code>' . $value['ip'] . '</code>, Connexion : ' . $value['hour'] . ' </li>';
                    }
                    $response['content'] .= '</ul>';
                    break;
                case 'services':
                    $response['title'] = 'Services';
                    $services = array();
                    if (PHP_OS != 'WINNT') {
                        $services = Monitoring::services();
                        $response['content'] = '<ul class="yana-list">';
                        foreach ($services as $value) {
                            $response['content'] .= '<li ' . ($value['status'] ? 'class="service-active"' : '') . '>- ' . $value['name'] . '</li>';
                        }
                        $response['content'] .= '</ul>';
                    } else {
                        $response['content'] .= 'Information indisponible sur cet OS :' . PHP_OS;
                    }
                    break;
                case 'hdd':
                    $response['title'] = 'HDD';
                    $hdds = array();
                    if (PHP_OS != 'WINNT') {
                        $hdds = Monitoring::hdd();
                        $response['content'] = '<ul class="yana-list">';
                        foreach ($hdds as $value) {
                            $response['content'] .= '<li><strong class="badge">' . $value['name'] . '</strong><br><strong> Espace :</strong> ' . $value['used'] . '/' . $value['total'] . '<strong> Format :</strong> ' . $value['format'] . ' </li>';
                        }
                        $response['content'] .= '</ul>';
                    } else {
                        $response['content'] .= 'Information indisponible sur cet OS :' . PHP_OS;
                    }
                    break;
                case 'disk':
                    $response['title'] = 'Disques';
                    $disks = array();
                    if (PHP_OS != 'WINNT') {
                        $disks = Monitoring::disks();
                        $response['content'] = '<ul class="yana-list">';
                        foreach ($disks as $value) {
                            $response['content'] .= '<li><strong class="badge">' . $value['name'] . '</strong> Statut : ' . $value['size'] . ' Type : ' . $value['type'] . ' Chemin : ' . $value['mountpoint'] . '  </li>';
                        }
                        $response['content'] .= '</ul>';
                    } else {
                        $response['content'] .= 'Information indisponible sur cet OS :' . PHP_OS;
                    }
                    break;
            }
            echo json_encode($response);
            exit(0);
            break;
        case 'dash_monitoring_plugin_edit':
            echo '<label>Time Zone</label><input id="zone" type="text">';
            break;
        case 'dash_monitoring_plugin_save':
            break;
        case 'dash_monitoring_plugin_delete':
            break;
        case 'dash_monitoring_plugin_move':
            break;
    }
}
Пример #8
0
        } else {
            Gpio::write($_["pin"], $_["state"], true);
        }
        break;
        // Gestion des interfaces de seconde génération
    // Gestion des interfaces de seconde génération
    case 'SUBSCRIBE_TO_CLIENT':
        Action::write(function ($_, &$response) {
            global $myUser, $conf;
            if (!isset($_['ip'])) {
                throw new Exception("IP invalide");
            }
            if (!isset($_['port']) || !is_numeric($_['port'])) {
                throw new Exception("Port invalide");
            }
            $url = Functions::getBaseUrl('action.php') . '/action.php';
            $client = new CLient($_['ip'], $_['port']);
            Plugin::callHook("vocal_command", array(&$vocal, $url));
            $conf = array('VOCAL_ENTITY_NAME' => $conf->put('VOCAL_ENTITY_NAME', 'YANA'), 'SPEECH_COMMAND' => $vocal);
            if (!$client->suscribe($url, $myUser->getToken())) {
                throw new Exception("Appairage impossible");
            }
            if (!$client->configure($conf)) {
                throw new Exception("Configuration impossible");
            }
        }, array('user' => 'u'));
        break;
    default:
        Plugin::callHook("action_post_case", array());
        break;
}
Пример #9
0
function common_listen($command, $text, $confidence)
{
    echo "\n" . 'diction de la commande : ' . $command;
    $response = array();
    Plugin::callHook("vocal_command", array(&$response, YANA_URL));
    $commands = array();
    echo "\n" . 'Test de comparaison avec ' . count($response['commands']) . ' commandes';
    foreach ($response['commands'] as $cmd) {
        if ($command != $cmd['command']) {
            continue;
        }
        if (!isset($cmd['parameters'])) {
            $cmd['parameters'] = array();
        }
        if (isset($cmd['callback'])) {
            echo "\n" . 'Commande trouvée, execution de la fonction plugin ' . $cmd['callback'];
            call_user_func($cmd['callback'], $text, $confidence, $cmd['parameters']);
        }
    }
}
function dash_monitoring_plugin_actions()
{
    global $myUser, $_, $conf;
    switch ($_['action']) {
        case 'dash_monitoring_plugin_load':
            if ($myUser == false) {
                exit('Vous devez vous connecter pour cette action.');
            }
            header('Content-type: application/json');
            $response = array();
            switch ($_['bloc']) {
                case 'ram':
                    $response['title'] = 'RAM';
                    $hdds = Monitoring::ram();
                    $response['content'] = '
						<div style="width: 100%">
							<canvas id="RAM_PIE"></canvas>
							<br/><br/>
							<ul class="graphic_pane">
								<li class="pane_orange">
									<h1>RAM UTILISEE</h1>
									<h2>' . $hdds['percentage'] . '%</h2>
								</li><li class="pane_cyan">
									<h1>RAM LIBRE</h1>
									<h2>' . $hdds['free'] . ' Mo</h2>
								</li><li class="pane_red">
									<h1>RAM TOTALE</h1>
									<h2>' . $hdds['total'] . ' Mo</h2>
								</li>
							</ul>
						</div>

						<script>

							$("#RAM_PIE:visible").chart({
								type : "doughnut",
								label : ["RAM UTILISEE","RAM LIBRE"],
								backgroundColor : ["' . ($hdds['percentage'] > 80 ? '#E64C65' : '#FCB150') . '","#4FC4F6"],
								segmentShowStroke:false,
								data : [' . $hdds['percentage'] . ',' . (100 - $hdds['percentage']) . ']
							});
							
						</script>';
                    break;
                case 'system':
                    $response['title'] = 'Système';
                    if (PHP_OS != 'WINNT') {
                        $heat = Monitoring::heat();
                        $cpu = Monitoring::cpu();
                    }
                    $response['content'] = '<ul>
				    	<li><strong>Distribution :</strong> ' . Monitoring::distribution() . '</li>
				    	<li><strong>Kernel :</strong> ' . Monitoring::kernel() . '</li>
				    	<li><strong>HostName :</strong> ' . Monitoring::hostname() . '</li>
				    	<li><strong>Température :</strong>  <span class="label ' . $heat["label"] . '">' . $heat["degrees"] . '°C</span></li>
				    	<li><strong>Temps de marche :</strong> ' . Monitoring::uptime() . '</li>
				    	<li><strong>CPU :</strong>  <span class="label label-info">' . $cpu['current_frequency'] . ' Mhz</span> (Max ' . $cpu['maximum_frequency'] . '  Mhz/ Min ' . $cpu['minimum_frequency'] . '  Mhz)</li>
				    	<li><strong>Charge :</strong>  <span class="label label-info">' . $cpu['loads'] . ' </span>  | ' . $cpu['loads5'] . '  5min | ' . $cpu['loads15'] . '  15min</li>
				    	<li><strong>Version WiringPi : </strong> ' . exec("gpio -v | grep 'gpio version' | cut -c15-") . '</li>
				    	<li><strong>Raspberry Pi Details : </strong> ' . exec("gpio -v") . '</li>
				    </ul>';
                    break;
                case 'vocal':
                    if ($myUser->getId() == '') {
                        exit('{"error":"invalid or missing token"}');
                    }
                    if (!$myUser->can('vocal', 'r')) {
                        exit('{"error":"insufficient permissions for this account"}');
                    }
                    list($host, $port) = explode(':', $_SERVER['HTTP_HOST']);
                    $actionUrl = 'http://' . $host . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'];
                    $actionUrl = substr($actionUrl, 0, strpos($actionUrl, '?'));
                    Plugin::callHook("vocal_command", array(&$response, $actionUrl));
                    $response['title'] = count($response['commands']) . ' Commandes vocales';
                    $response['content'] = '<ul>';
                    foreach ($response['commands'] as $command) {
                        $response['content'] .= '<li title="Sensibilité : ' . $command['confidence'] . '">' . $command['command'] . '</li>';
                    }
                    $response['content'] .= '</ul>';
                    break;
                case 'network':
                    $response['title'] = 'Réseau';
                    $ethernet = array();
                    $lan = '';
                    $wan = '';
                    $http = '';
                    $connections = '';
                    if (PHP_OS != 'WINNT') {
                        $ethernet = Monitoring::ethernet();
                        $lan = Monitoring::internalIp();
                        $wan = Monitoring::externalIp();
                        $http = Monitoring::webServer();
                        $connections = Monitoring::connections();
                    }
                    $response['content'] = '<ul>
					    	<li><strong>IP LAN :</strong> <code>' . $lan . '</code></li>
					    	<li><strong>IP WAN :</strong> <code>' . $wan . '</code></li>
					    	<li><strong>Serveur HTTP :</strong> ' . $http . '</li>
					    	<li><strong>Ethernet :</strong> ' . $ethernet['up'] . ' Montant / ' . $ethernet['down'] . ' Descendant</li>
					    	<li><strong>Connexions :</strong>  <span class="label label-info">' . $connections . '</span></li>
					    </ul>';
                    break;
                case 'gpio':
                    $response['title'] = 'GPIO';
                    if (PHP_OS != 'WINNT') {
                        $version = Functions::getRaspVersion();
                        $response['content'] .= '<pre><table style="width:100%;text-align:center;"><tbody>';
                        // getListOptionalWiringPin
                        //
                        // Liste des GPIO
                        $i = 0;
                        // var_dump(Gpio::getListWiringPin($version));
                        foreach (Gpio::getListWiringPin($version) as $key => $GPIO) {
                            $class = 'info';
                            $value = 'off';
                            if (Gpio::read_($key, false)) {
                                $class = 'warning';
                                $value = 'on';
                            }
                            if ($i % 2 == 0) {
                                $response['content'] .= '<tr><td><strong>' . $GPIO . '</strong></td><td>-></td><td> <span onclick="change_gpio_state(' . $key . ',this);" style="width:20px;text-align:center;" class="label label-' . $class . ' pointer">' . $value . '</span> </td>';
                            } else {
                                $response['content'] .= '<td> <span onclick="change_gpio_state(' . $key . ',this);" style="width:20px;text-align:center;" class="pointer label label-' . $class . '">' . $value . '</span> </td><td><-</td><td><strong>' . $GPIO . '</strong></td></tr>';
                            }
                            $i++;
                        }
                        $listeOfOptionnalGpios = Gpio::getListOptionalWiringPin($version);
                        if (!empty($listeOfOptionnalGpios)) {
                            $response['content'] .= '<tr><td colspan="6">Liste des Gpio optionnels</td></tr>';
                            //liste des GPIO optionnels
                            $i = 0;
                            foreach (Gpio::getListOptionalWiringPin($version) as $GPIO) {
                                $class = 'info';
                                $value = 'off';
                                if (Gpio::read_($key, false)) {
                                    $class = 'warning';
                                    $value = 'on';
                                }
                                if ($i % 2 == 0) {
                                    $response['content'] .= '<tr><td><strong>' . Gpio::getNameOfWiringPins($i) . '</strong></td><td>-></td><td> <span onclick="change_gpio_state(' . $i . ',this);" style="width:20px;text-align:center;" class="label label-' . $class . ' pointer">' . $value . '</span> </td>';
                                } else {
                                    $response['content'] .= '<td> <span onclick="change_gpio_state(' . $i . ',this);" style="width:20px;text-align:center;" class="pointer label label-' . $class . '">' . $value . '</span> </td><td><-</td><td><strong>' . Gpio::getNameOfWiringPins($i + 1) . '</strong></td></tr>';
                                }
                                $i++;
                            }
                        }
                        $response['content'] .= '</tbody></table></pre>';
                    } else {
                        $response['content'] .= 'Information indisponible sur cet OS :' . PHP_OS;
                    }
                    break;
                case 'pins':
                    $response['title'] = 'PINS';
                    if (PHP_OS != 'WINNT') {
                        $version = Functions::getRaspVersion();
                        //un peu de style
                        $response["content"] .= '<style>.label_pin{padding:5px;border: 1px solid #FFF;}.pin_gpio{background: #FCBF21}.pin_power{background: #FB0C1A}.pin_ground{background: #000}.pin_UART{background: #00AF08}.pin_SPI{background: #9B04EF}.pin_I2C{background: #0044AB}.legende_pins a{color:#FFF}.legende_pins{margin:5px; border: 1px solid #FFF;display:inline;padding: 5px}</style>';
                        $response["content"] .= '<pre><table style="width:100%;text-align:center;margin:5px;"><tbody>';
                        //on met les titres
                        $response["content"] .= '<tr><th>WiringPi</th><th>Nom</th><th></th><th></th><th>Nom</th><th>WiringPi</th></tr>';
                        $i = 0;
                        foreach (Gpio::getListPins($version) as $numero => $infos) {
                            $wiringPi = is_null($infos[0]) ? "N/A" : $infos[0];
                            $nom = $infos[1];
                            $class = "";
                            //on détermine les class
                            switch ($nom) {
                                case preg_match("~GPIO~Uis", $nom) ? true : false:
                                    $class = "gpio";
                                    break;
                                case "0V":
                                    $class = "ground";
                                    break;
                                case "3,3V":
                                case "5V":
                                    $class = "power";
                                    break;
                                case "MOSI":
                                case "MISO":
                                case "SCLK":
                                case "CE0":
                                case "CE1":
                                    $class = "SPI";
                                    break;
                                case "RxD":
                                case "TxD":
                                    $class = "UART";
                                    break;
                                case preg_match("~SDA~Uis", $nom) ? true : false:
                                case preg_match("~SCL~Uis", $nom) ? true : false:
                                    $class = "I2C";
                                    break;
                                default:
                                    $class = "";
                                    break;
                            }
                            $class = !empty($class) ? 'pin_' . $class : "";
                            if ($i % 2 == 0) {
                                $response['content'] .= '<tr><td>' . $wiringPi . '</td><td>' . $nom . '</td><td class="label_pin ' . $class . '" ><i class="fa fa-dot-circle-o"></i></td>';
                            } else {
                                $response['content'] .= '<td class="label_pin ' . $class . '" ><i class="fa fa-dot-circle-o"></i></td><td>' . $nom . '</td><td>' . $wiringPi . '</td></tr>';
                            }
                            $i++;
                        }
                        $temp_list = Gpio::getListOptionalPins($version);
                        if (!empty($temp_list)) {
                            $response['content'] .= '<tr><td colspan="6">Pins optionnels</td></tr>';
                            $i = 0;
                            foreach (Gpio::getListOptionalPins($version) as $numero => $infos) {
                                $wiringPi = is_null($infos[0]) ? "N/A" : $infos[0];
                                $nom = $infos[1];
                                $class = "";
                                //on détermine les class
                                switch ($nom) {
                                    case preg_match("~GPIO~Uis", $nom) ? true : false:
                                        $class = "gpio";
                                        break;
                                    case "0V":
                                        $class = "ground";
                                        break;
                                    case "3,3V":
                                    case "5V":
                                        $class = "power";
                                        break;
                                    case "MOSI":
                                    case "MISO":
                                    case "SCLK":
                                    case "CE0":
                                    case "CE1":
                                        $class = "SPI";
                                        break;
                                    case "RxD":
                                    case "TxD":
                                        $class = "UART";
                                        break;
                                    case preg_match("~SDA~Uis", $nom) ? true : false:
                                    case preg_match("~SCL~Uis", $nom) ? true : false:
                                        $class = "I2C";
                                        break;
                                    default:
                                        $class = "";
                                        break;
                                }
                                $class = !empty($class) ? 'pin_' . $class : "";
                                if ($i % 2 == 0) {
                                    $response['content'] .= '<tr><td>' . $wiringPi . '</td><td>' . $nom . '</td><td class="label_pin ' . $class . '" ><i class="fa fa-dot-circle-o"></i></td>';
                                } else {
                                    $response['content'] .= '<td class="label_pin ' . $class . '" ><i class="fa fa-dot-circle-o"></i></td><td>' . $nom . '</td><td>' . $wiringPi . '</td></tr>';
                                }
                                $i++;
                            }
                        }
                        $response['content'] .= '</tbody></table>';
                        $response['content'] .= '<div class="legende_pins pin_ground"><a href="http://fr.wikipedia.org/wiki/Terre_(%C3%A9lectricit%C3%A9)">ground</a></div><div class="legende_pins pin_power"><a href="http://fr.wikipedia.org/wiki/Alimentation_%C3%A9lectrique">power</a></div><div class="legende_pins pin_gpio"><a href="http://fr.wikipedia.org/wiki/General_Purpose_Input/Output">gpio</a></div><div class="legende_pins pin_SPI"><a href="http://fr.wikipedia.org/wiki/Serial_Peripheral_Interface">SPI</a></div><div class="legende_pins pin_UART"><a href="http://fr.wikipedia.org/wiki/UART">UART</a></div><div class="legende_pins pin_I2C"><a href="http://fr.wikipedia.org/wiki/I2C">I2C</a></div></tr>';
                        $response['content'] .= '</pre>';
                    } else {
                        $response['content'] .= 'Information indisponible sur cet OS :' . PHP_OS;
                    }
                    break;
                case 'users':
                    $users = array();
                    if (PHP_OS != 'WINNT') {
                        $users = Monitoring::users();
                    }
                    $response['title'] = count($users) . ' utilisateurs connectés';
                    $response['content'] = '<ul>';
                    foreach ($users as $value) {
                        $response['content'] .= '<li>Utilisateur <strong class="badge">' . $value['user'] . '</strong> IP : <code>' . $value['ip'] . '</code>, Connexion : ' . $value['hour'] . ' </li>';
                    }
                    $response['content'] .= '</ul>';
                    break;
                case 'services':
                    $response['title'] = 'Services';
                    $services = array();
                    if (PHP_OS != 'WINNT') {
                        $services = Monitoring::services();
                        $response['content'] = '<ul>';
                        foreach ($services as $value) {
                            $response['content'] .= '<li ' . ($value['status'] ? 'class="service-active"' : '') . '>- ' . $value['name'] . '</li>';
                        }
                        $response['content'] .= '</ul>';
                    } else {
                        $response['content'] .= 'Information indisponible sur cet OS :' . PHP_OS;
                    }
                    break;
                case 'hdd':
                    $response['title'] = 'HDD';
                    $hdds = array();
                    if (PHP_OS != 'WINNT') {
                        $hdds = Monitoring::hdd();
                        $response['content'] = '<ul>';
                        foreach ($hdds as $value) {
                            $response['content'] .= '<li><strong class="badge">' . $value['name'] . '</strong><br><strong> Espace :</strong> ' . $value['used'] . '/' . $value['total'] . '<strong> Format :</strong> ' . $value['format'] . ' </li>';
                        }
                        $response['content'] .= '</ul>';
                    } else {
                        $response['content'] .= 'Information indisponible sur cet OS :' . PHP_OS;
                    }
                    break;
                case 'disk':
                    $response['title'] = 'Disques';
                    $disks = array();
                    if (PHP_OS != 'WINNT') {
                        $disks = Monitoring::disks();
                        $response['content'] = '<ul>';
                        foreach ($disks as $value) {
                            $response['content'] .= '<li><strong class="badge">' . $value['name'] . '</strong> Statut : ' . $value['size'] . ' Type : ' . $value['type'] . ' Chemin : ' . $value['mountpoint'] . '  </li>';
                        }
                        $response['content'] .= '</ul>';
                    } else {
                        $response['content'] .= 'Information indisponible sur cet OS :' . PHP_OS;
                    }
                    break;
            }
            echo json_encode($response);
            exit(0);
            break;
        case 'dash_monitoring_plugin_edit':
            echo '<label>Time Zone</label><input id="zone" type="text">';
            break;
        case 'dash_monitoring_plugin_save':
            break;
        case 'dash_monitoring_plugin_delete':
            break;
        case 'dash_monitoring_plugin_move':
            break;
    }
}
Пример #11
0
         exit;
     }
     // chargement du content de l'article souhaité
     $newEvent = new Event();
     $event = $newEvent->getById($_['event_id']);
     if ($_['articleDisplayMode'] == 'content') {
         //error_log(print_r($_SESSION['events'],true));
         $content = $event->getContent();
     } else {
         $content = $event->getDescription();
     }
     echo $content;
     break;
 default:
     require_once "SimplePie.class.php";
     Plugin::callHook("action_post_case", array(&$_, $myUser));
     //exit('0');
     break;
     //Installation d'un nouveau plugin
 //Installation d'un nouveau plugin
 case 'installPlugin':
     $tempZipName = 'plugins/' . md5(microtime());
     echo '<br/>Téléchargement du plugin...';
     file_put_contents($tempZipName, file_get_contents(urldecode($_['zip'])));
     if (file_exists($tempZipName)) {
         echo '<br/>Plugin téléchargé <span class="label label-success">OK</span>';
         echo '<br/>Extraction du plugin...';
         $zip = new ZipArchive();
         $res = $zip->open($tempZipName);
         if ($res === TRUE) {
             $tempZipFolder = $tempZipName . '_';
Пример #12
0
</button></li>
	<li><button <?php 
if ($event->getFavorite()) {
    ?>
class="eventFavorite"<?php 
}
?>
 onclick="favorize(this,<?php 
echo $_GET['event'] . ',\'' . $rootPath . '\'';
?>
);"><?php 
echo !$event->getFavorite() ? 'Favoriser' : 'Défavoriser';
?>
</button></li>
	<?php 
Plugin::callHook("leed_browser_toolbar", array(&$events));
?>
	<li><button onclick="window.location='<?php 
echo $_GET['link'];
?>
';">Sortir</button></li>
</ul>
</div>
<iframe id="browser-content" src="<?php 
echo $_GET['link'];
?>
"></iframe>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script src="js/main.js"></script>
</body>
</html>
function preference_plugin_page()
{
    global $myUser, $_;
    if (isset($_['section']) && $_['section'] == 'preference' || !isset($_['section'])) {
        if ($myUser != false) {
            ?>

		<div class="span9 userBloc">
		<h1>Préférence</h1>
		<p>Gestion des préférences du programme</p>

		<ul class="nav nav-tabs">
			<li <?php 
            echo isset($_['block']) && $_['block'] == 'global' ? 'class="active"' : '';
            ?>
 ><a href="setting.php?section=preference&amp;block=global"><i class="fa fa-angle-right"></i> Général</a></li>
	       <?php 
            Plugin::callHook("preference_menu", array());
            ?>
	    </ul>
			
		
		 <?php 
            if (isset($_['section']) && $_['section'] == 'preference' && @$_['block'] == 'global' || !isset($_['section'])) {
                if ($myUser != false) {
                    ?>

					<div class="span9 userBloc">
							<table class="table table-striped table-bordered" id="setting_table">
							<tr><th>Clé</th><th>Valeur</th><tr>
							<?php 
                    $conf = new Configuration();
                    $confs = $conf->populate();
                    foreach ($confs as $value) {
                        $ns = 'conf';
                        $key = $value->getKey();
                        $infos = explode(':', $key);
                        if (count($infos) == 2) {
                            list($ns, $key) = $infos;
                        }
                        if ($ns != 'conf') {
                            continue;
                        }
                        echo '<tr><td>' . $key . '</td><td><input class="input-xxlarge" type="text" value="' . $value->getValue() . '" id="' . $value->getId() . '"></td></tr>';
                    }
                    ?>
							<tr><td colspan="2"><button type="submit" onclick="save_settings();" class="btn">Modifier</button></td></tr>
							</table>
						
					</div>

					<?php 
                } else {
                    ?>

					<div id="main" class="wrapper clearfix">
						<article>
							<h3>Vous devez être connecté</h3>
						</article>
					</div>
					<?php 
                }
            }
            Plugin::callHook("preference_content", array());
            ?>
		</div>

<?php 
        } else {
            ?>

		<div id="main" class="wrapper clearfix">
			<article>
					<h3>Vous devez être connecté</h3>
			</article>
		</div>
<?php 
        }
    }
}
Пример #14
0
<?php

require_once 'header.php';
Plugin::callHook("index_pre_treatment", array(&$_));
if (!$myUser) {
    $view = 'login';
} else {
    $view = 'index';
    //if($conf->get('HOME_PAGE') != '' && $conf->get('HOME_PAGE')!='index.php')
    //header('location: '.$conf->get('HOME_PAGE'));
}
require_once 'footer.php';
Пример #15
0
function dashboard_plugin_actions()
{
    global $myUser, $_, $conf;
    switch ($_['action']) {
        case 'GET_WIDGETS':
            header('Content-type: application/json');
            require_once dirname(__FILE__) . '/Dashboard.class.php';
            require_once dirname(__FILE__) . '/Widget.class.php';
            $dashManager = new Dashboard();
            $dashManager->change(array('default' => '0'));
            $dashManager->change(array('default' => '1'), array('id' => $_['dashboard']));
            $widgetManager = new Widget();
            $model = array();
            Plugin::callHook("widgets", array(&$model));
            $widgets = $widgetManager->loadAll(array('dashboard' => $_['dashboard']), 'cell');
            $data = array();
            foreach ($widgets as $widget) {
                $data[] = array('data' => $widget->data, 'column' => $widget->column, 'id' => $widget->id, 'cell' => $widget->cell, 'minified' => $widget->minified, 'model' => $widget->model);
            }
            echo json_encode(array('model' => $model, 'data' => $data));
            break;
        case 'ADD_WIDGET':
            header('Content-type: application/json');
            require_once dirname(__FILE__) . '/Widget.class.php';
            $response = array();
            $widget = new Widget();
            $widget->data = json_encode($_POST['data']);
            $widget->column = $_['column'];
            $widget->cell = $_['cell'];
            $widget->model = $_['model'];
            $widget->dashboard = $_['view'];
            $widget->save();
            $response['id'] = $widget->id;
            echo json_encode($response);
            break;
        case 'MINIMIZE_WIDGET':
            header('Content-type: application/json');
            require_once dirname(__FILE__) . '/Widget.class.php';
            $response = array();
            $widgetManager = new Widget();
            $widgetManager = $widgetManager->getById($_['id']);
            $widgetManager->minified = 1;
            $widgetManager->save();
            echo json_encode($response);
            break;
        case 'MAXIMIZE_WIDGET':
            header('Content-type: application/json');
            require_once dirname(__FILE__) . '/Widget.class.php';
            $response = array();
            $widgetManager = new Widget();
            $widgetManager = $widgetManager->getById($_['id']);
            $widgetManager->minified = 0;
            $widgetManager->save();
            echo json_encode($response);
            break;
        case 'MOVE_WIDGET':
            header('Content-type: application/json');
            require_once dirname(__FILE__) . '/Widget.class.php';
            $response = array();
            $widgetManager = new Widget();
            foreach ($_['sort']['cells'] as $id => $sort) {
                $widgetManager->change(array('cell' => $sort['cell'], 'column' => $sort['column']), array('id' => $id));
            }
            echo json_encode($response);
            break;
        case 'DELETE_WIDGET':
            header('Content-type: application/json');
            require_once dirname(__FILE__) . '/Widget.class.php';
            $response = array();
            $widgetManager = new Widget();
            $widgetManager->delete(array('id' => $_['id']));
            echo json_encode($response);
            break;
        case 'DASH_ADD_VIEW':
            global $_, $myUser;
            require_once dirname(__FILE__) . '/Dashboard.class.php';
            $entity = new Dashboard();
            $entity->user = $myUser->getId();
            $entity->label = $_['viewName'];
            $entity->default = 0;
            $entity->save();
            header('location: setting.php?section=preference&block=dashboard');
            break;
        case 'DASH_DELETE_VIEW':
            global $_, $myUser;
            require_once dirname(__FILE__) . '/Dashboard.class.php';
            $entity = new Dashboard();
            $entity->delete(array('id' => $_['id']));
            header('location: setting.php?section=preference&block=dashboard');
            break;
    }
}
Пример #16
0
function vocalinfo_action()
{
    global $_, $conf;
    switch ($_['action']) {
        case 'plugin_vocalinfo_save':
            $commands = json_decode(file_get_contents(Plugin::path() . '/' . VOCALINFO_COMMAND_FILE), true);
            foreach ($_['config'] as $key => $config) {
                $commands[$key]['confidence'] = $config['confidence'];
                $commands[$key]['disabled'] = $config['disabled'];
            }
            file_put_contents(Plugin::path() . '/' . VOCALINFO_COMMAND_FILE, json_encode($commands));
            echo 'Enregistré';
            break;
        case 'vocalinfo_plugin_setting':
            $conf->put('plugin_vocalinfo_place', $_['weather_place']);
            $conf->put('plugin_vocalinfo_woeid', $_['woeid']);
            header('location:setting.php?section=preference&block=vocalinfo');
            break;
        case 'vocalinfo_sound':
            global $_;
            $response = array('responses' => array(array('type' => 'sound', 'file' => $_['sound'])));
            $json = json_encode($response);
            echo $json == '[]' ? '{}' : $json;
            break;
        case 'vocalinfo_devmod':
            $response = array('responses' => array(array('type' => 'command', 'program' => 'C:\\Program Files\\Sublime Text 2\\sublime_text.exe'), array('type' => 'talk', 'sentence' => 'Sublim text lancé.')));
            $json = json_encode($response);
            echo $json == '[]' ? '{}' : $json;
            break;
        case 'vocalinfo_gpio_diag':
            $sentence = '';
            $gpio = array('actif' => array(), 'inactif' => array());
            for ($i = 0; $i < 26; $i++) {
                $commands = array();
                exec("/usr/local/bin/gpio read " . $i, $commands, $return);
                if (trim($commands[0]) == "1") {
                    $gpio['actif'][] = $i;
                } else {
                    $gpio['inactif'][] = $i;
                }
            }
            if (count($gpio['actif']) == 0) {
                $sentence .= 'Tous les GPIO sont inactifs.';
            } else {
                if (count($gpio['inactif']) == 0) {
                    $sentence .= 'Tous les GPIO sont actifs.';
                } else {
                    $sentence .= 'GPIO actifs: ' . implode(', ', $gpio['actif']) . '. GPIO inactifs: ' . implode(', ', $gpio['inactif']) . '.';
                }
            }
            $response = array('responses' => array(array('type' => 'talk', 'sentence' => $sentence)));
            $json = json_encode($response);
            echo $json == '[]' ? '{}' : $json;
            break;
        case 'vocalinfo_commands':
            $actionUrl = 'http://' . $_SERVER['SERVER_ADDR'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'];
            $actionUrl = substr($actionUrl, 0, strpos($actionUrl, '?'));
            $commands = array();
            Plugin::callHook("vocal_command", array(&$commands, $actionUrl));
            $sentence = 'Je répond aux commandes suivantes: ';
            foreach ($commands['commands'] as $command) {
                $sentence .= $command['command'] . '. ';
            }
            $response = array('responses' => array(array('type' => 'talk', 'sentence' => $sentence)));
            $json = json_encode($response);
            echo $json == '[]' ? '{}' : $json;
            break;
        case 'vocalinfo_meteo':
            global $_;
            if ($conf->get('plugin_vocalinfo_woeid') != '') {
                $contents = file_get_contents('http://weather.yahooapis.com/forecastrss?w=' . $conf->get('plugin_vocalinfo_woeid') . '&u=c');
                $xml = simplexml_load_string($contents);
                if (isset($_['today'])) {
                    $weekdays = $xml->xpath('/rss/channel/item/yweather:condition');
                } else {
                    $weekdays = $xml->xpath('/rss/channel/item/yweather:forecast');
                }
                //Codes disponibles ici: http://developer.yahoo.com/weather/#codes
                $textTranslate = array('Showers' => 'des averses', 'Tornado' => 'Attention: Tornade!', 'Hurricane' => 'Attention: Ouragan!', 'Severe thunderstorms' => 'Orages violents', 'Mixed rain and snow' => 'Pluie et neiges', 'Mixed rain and sleet' => 'Pluie et neige fondue', 'Mixed snow and sleet' => 'Neige et neige fondue', 'Freezing drizzle' => 'Bruine verglassant', 'Drizzle' => 'Bruine', 'Freezing rain' => 'Pluie verglassant', 'Showers' => 'Averse', 'Snow flurries' => 'Bourrasque de neige', 'Light snow showers' => 'Averse de neige lègére', 'Blowing snow' => 'Chasse neige', 'Snow' => 'Neige', 'Hail' => 'Grêle', 'Sleet' => 'Neige fondue', 'Dust' => 'Poussière', 'Foggy' => 'Brouillard', 'Smoky' => 'Fumée', 'Blustery' => 'Froid et venteux', 'Windy' => 'Venteux', 'Cold' => 'Froid', 'Cloudy' => 'Nuageux', 'Fair' => 'Ciel dégagé', 'Mixed rain and hail' => 'Pluie et grêle', 'Hot' => 'Chaud', 'Isolated thunderstorms' => 'Orages isolées', 'Scattered showers' => 'Averse éparse', 'Heavy snow' => 'Fortes chutes de neige', 'Scattered snow showers' => 'Averse de neige éparse', 'Thunderstorms' => 'Orages', 'Thundershowers' => 'Grain sous orage violents', 'Isolated thundershowers' => 'Grain sous orage isolées', 'Not available' => 'Non disponible', 'Scattered Thunderstorms' => 'Orages éparses', 'Partly Cloudy' => 'Partiellement nuageux', 'Mostly Sunny' => 'plutot ensoleillé', 'Mostly Cloudy' => 'plutot Nuageux', 'Light Rain' => 'Pluie fine', 'Clear' => 'Temps clair', 'Sunny' => 'ensoleillé', 'Rain/Wind' => 'Pluie et vent', 'Rain' => 'Pluie', 'Wind' => 'Vent', 'Partly Cloudy/Wind' => 'Partiellement nuageux avec du vent');
                $dayTranslate = array('Wed' => 'mercredi', 'Sat' => 'samedi', 'Mon' => 'lundi', 'Tue' => 'mardi', 'Thu' => 'jeudi', 'Fri' => 'vendredi', 'Sun' => 'dimanche');
                $affirmation = '';
                foreach ($weekdays as $day) {
                    if (substr($day['text'], 0, 2) == "AM") {
                        $sub_condition = substr($day['text'], 3);
                        $condition = (isset($textTranslate['' . $sub_condition]) ? $textTranslate['' . $sub_condition] : $sub_condition) . " dans la matinée";
                    } elseif (substr($day['text'], 0, 2) == "PM") {
                        $sub_condition = substr($day['text'], 3);
                        $condition = (isset($textTranslate['' . $sub_condition]) ? $textTranslate['' . $sub_condition] : $sub_condition) . " dans l'après midi";
                    } elseif (substr($day['text'], -4) == "Late") {
                        $sub_condition = substr($day['text'], 0, -5);
                        $condition = (isset($textTranslate['' . $sub_condition]) ? $textTranslate['' . $sub_condition] : $sub_condition) . " en fin de journée";
                    } else {
                        $condition = isset($textTranslate['' . $day['text']]) ? $textTranslate['' . $day['text']] : $day['text'];
                    }
                    if (isset($_['today'])) {
                        $affirmation .= 'Aujourd\'hui ' . $day['temp'] . ' degrés, ' . $condition . ', ';
                    } else {
                        $affirmation .= $dayTranslate['' . $day['day']] . ' de ' . $day['low'] . ' à ' . $day['high'] . ' degrés, ' . $condition . ', ';
                    }
                }
            } else {
                $affirmation = 'Vous devez renseigner votre ville dans les préférences de l\'interface oueb, je ne peux rien vous dire pour le moment.';
            }
            $response = array('responses' => array(array('type' => 'talk', 'sentence' => $affirmation)));
            $json = json_encode($response);
            echo $json == '[]' ? '{}' : $json;
            break;
        case 'vocalinfo_tv':
            global $_;
            libxml_use_internal_errors(true);
            $contents = file_get_contents('http://webnext.fr/epg_cache/programme-tv-rss_' . date('Y-m-d') . '.xml');
            $xml = simplexml_load_string($contents);
            $emissions = $xml->xpath('/rss/channel/item');
            $focus = array();
            $time = time();
            $date = date('m/d/Y ', $time);
            $focusedCanals = array('TF1', 'France 2', 'France 3', 'France 4', 'Canal+', 'Arte', 'France 5', 'M6');
            foreach ($emissions as $emission) {
                $item = array();
                list($item['canal'], $item['hour'], $item['title']) = explode(' | ', $emission->title);
                $itemTime = strtotime($date . $item['hour']);
                if ($itemTime >= $time - 3600 && $itemTime <= $time + 3600 && in_array($item['canal'], $focusedCanals)) {
                    if (isset($_['category']) && $_['category'] == '' . $emission->category || !isset($_['category'])) {
                        $item['category'] = '' . $emission->category;
                        $item['description'] = strip_tags('' . $emission->description);
                        $focus[$item['title'] . $item['canal']][] = $item;
                    }
                }
            }
            $affirmation = '';
            $response = array();
            foreach ($focus as $emission) {
                $nb = count($emission);
                $emission = $emission[0];
                $affirmation = array();
                $affirmation['type'] = 'talk';
                //$affirmation['style'] = 'slow';
                $affirmation['sentence'] = ($nb > 1 ? $nb . ' ' : '') . ucfirst($emission['category']) . ', ' . $emission['title'] . ' à ' . $emission['hour'] . ' sur ' . $emission['canal'];
                $response['responses'][] = $affirmation;
            }
            $json = json_encode($response);
            echo $json == '[]' ? '{}' : $json;
            break;
        case 'vocalinfo_hour':
            global $_;
            $affirmation = 'Il est ' . date('H:i');
            $response = array('responses' => array(array('type' => 'talk', 'sentence' => $affirmation)));
            $json = json_encode($response);
            echo $json == '[]' ? '{}' : $json;
            break;
        case 'vocalinfo_day':
            global $_;
            $affirmation = 'Nous sommes le ' . date('d/m/Y');
            $response = array('responses' => array(array('type' => 'talk', 'sentence' => $affirmation)));
            $json = json_encode($response);
            echo $json == '[]' ? '{}' : $json;
            break;
        case 'vocalinfo_wikipedia':
            global $_;
            $url = 'http://fr.wikipedia.org/w/api.php?action=parse&page=' . $_['word'] . '&format=json&prop=text&section=0';
            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr-FR; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
            // required by wikipedia.org server; use YOUR user agent with YOUR contact information. (otherwise your IP might get blocked)
            $c = curl_exec($ch);
            $json = json_decode($c);
            $content = $json->{'parse'}->{'text'}->{'*'};
            // get the main text content of the query (it's parsed HTML)
            $affirmation = strip_tags(str_replace('&#160;', ' ', $content));
            // '&#160;' is a space, but is not recognized by yana trying to read "160"
            $response = array('responses' => array(array('type' => 'talk', 'sentence' => $affirmation)));
            $json = json_encode($response);
            echo $json == '[]' ? '{}' : $json;
            break;
        case 'vocalinfo_mood':
            global $_;
            $possible_answers = array('parfaitement', 'ça pourrait aller mieux', 'ça roule mon pote !', 'nickel', 'pourquoi cette question ?');
            $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;
    }
}
Пример #17
0
function common_listen($command, $text, $confidence, $user)
{
    echo "\n" . 'diction de la commande : ' . $command;
    $response = array();
    Plugin::callHook("vocal_command", array(&$response, YANA_URL . '/action.php'));
    $commands = array();
    echo "\n" . 'Test de comparaison avec ' . count($response['commands']) . ' commandes';
    foreach ($response['commands'] as $cmd) {
        if ($command != $cmd['command']) {
            continue;
        }
        if (!isset($cmd['parameters'])) {
            $cmd['parameters'] = array();
        }
        if (isset($cmd['callback'])) {
            //Catch des commandes pour les plugins en format client v2
            echo "\n" . 'Commande trouvée, execution de la fonction plugin ' . $cmd['callback'];
            call_user_func($cmd['callback'], $text, $confidence, $cmd['parameters'], $user);
        } else {
            //Catch des commandes pour les plugins en format  client v1
            echo "\n" . 'Commande ancien format trouvée, execution de l\'url ' . $cmd['url'] . '&token=' . $user->getToken();
            $result = file_get_contents($cmd['url'] . '&token=' . $user->getToken());
            $result = json_decode($result, true);
            if (is_array($result)) {
                $client = new Client();
                $client->connect();
                foreach ($result['responses'] as $resp) {
                    switch ($resp['type']) {
                        case 'talk':
                            $client->talk($resp['sentence']);
                            break;
                        case 'sound':
                            $client->sound($resp['file']);
                            break;
                        case 'command':
                            $client->execute($resp['program']);
                            break;
                    }
                }
                $client->disconnect();
            }
        }
    }
}