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