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; } }
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; } }