function computerState($target, $ID)
 {
     global $DB, $LANG;
     $np = new Netport();
     $pta = new PluginFusioninventoryAgents();
     echo "<br/>";
     echo "<div align='center'>";
     echo "<form method='post' name='' id=''  action=\"" . $target . "\">";
     echo "<table  class='tab_cadre_fixe'>";
     echo "<tr>";
     echo "<th colspan='2'>";
     echo $LANG['plugin_fusioninventory']["agents"][15];
     echo "</th>";
     echo "</tr>";
     $a_datas = $this->find("`device_id`='" . $ID . "'", "", "1");
     if (empty($a_datas)) {
         // Ajouter une entrée
         $this->fields['device_id'] = $ID;
         $this->fields['date_mod'] = date("Y-m-d H:i:s");
         $data['ID'] = $this->addToDB();
         $data['date_mod'] = $this->fields['date_mod'];
         $data['state'] = 0;
     } else {
         // Afficher l'état
         foreach ($a_datas as $device_id => $values) {
             $data = $a_datas[$device_id];
         }
     }
     echo "<tr class='tab_bg_1'>";
     echo "<td align='center'>";
     echo convDateTime($data['date_mod']);
     echo " : </td>";
     echo "<td align='center'>";
     switch ($data['state']) {
         case 0:
             echo $LANG['plugin_fusioninventory']["agents"][16];
             break;
         case 1:
             echo $LANG['plugin_fusioninventory']["agents"][22];
             break;
         case 2:
             echo $LANG['plugin_fusioninventory']["agents"][17];
             break;
         case 3:
             echo $LANG['plugin_fusioninventory']["agents"][18];
             break;
         case 4:
             echo $LANG['plugin_fusioninventory']["agents"][19];
             break;
         case 5:
             echo $LANG['plugin_fusioninventory']["agents"][20];
             break;
         case 6:
             echo $LANG['plugin_fusioninventory']["agents"][21];
             break;
         default:
             break;
     }
     echo "</td>";
     echo "</tr>";
     $ip = "";
     if ($data['state'] == 0 or $data['state'] == 6) {
         $a_data = $np->find("`on_device`='" . $ID . "' AND `device_type`='1'");
         foreach ($a_data as $port_id => $port) {
             echo "<tr class='tab_bg_1'>";
             echo "<td align='center'>";
             if (!($fp = fsockopen($port['ifaddr'], 62354, $errno, $errstr, 1))) {
                 echo $port['ifaddr'] . " : </td><td align='center'><b>" . $LANG['plugin_fusioninventory']["task"][9] . "</b>";
             } else {
                 echo $port['ifaddr'] . " : </td><td align='center'><b>" . $LANG['plugin_fusioninventory']["task"][8] . "</b>";
                 $ip = $port['ifaddr'];
                 fclose($fp);
             }
             echo "</td>";
             echo "</tr>";
         }
     }
     echo "<tr class='tab_bg_2'>";
     echo "<td align='center' colspan='2'>";
     $a_datasagent = $pta->find("`on_device`='" . $ID . "' AND `device_type`='1' ", "", "1");
     if (!empty($a_datasagent)) {
         foreach ($a_datasagent as $agent_id => $dataagent) {
             echo "<input type='hidden' name='agentID' value='" . $agent_id . "'/>";
         }
     }
     echo "<input type='hidden' name='ID' value='" . $ID . "'/>";
     echo "<input type='hidden' name='ip' value='" . $ip . "'/>";
     echo "<input type='submit' name='startagent' value=\"" . $LANG['plugin_fusioninventory']["task"][12] . "\" class='submit' >";
     echo "</td>";
     echo "</tr>";
     echo "</table>";
     echo "</form>";
     echo "</div>";
     $glpiroot = GLPI_ROOT . "/plugins/fusioninventory/front/";
     if (strstr($_SERVER["PHP_SELF"], "fusioninventory")) {
         $glpiroot = '../plugins/fusioninventory/front/';
     }
     if ($data['state'] > 0 and $data['state'] < 6) {
         echo "<script type='text/javascript'>\nExt.getCmp('fusioninventory_1').getUpdater().startAutoRefresh(3,'" . GLPI_ROOT . "/plugins/fusioninventory/front/agents.state.php?ID=" . $ID . "');\n      \n      </script>";
     } else {
         echo "<script type='text/javascript'>\nExt.getCmp('fusioninventory_1').getUpdater().stopAutoRefresh();\n\n      </script>";
     }
 }
Exemplo n.º 2
0
 function showAgentWol($on_device, $device_type)
 {
     global $LANG;
     $np = new Netport();
     $pfia = new PluginFusioninventoryAgents();
     $count_agent_on = 0;
     $existantantip = array();
     $existantantip["127.0.0.1"] = 1;
     switch ($device_type) {
         case COMPUTER_TYPE:
             // Choisir parmi les agents qui repondent et on le SNMP d'activé
             echo "<input type='hidden' name='device' value='" . $device_type . "-" . $on_device . "' />";
             echo "<table>";
             $a_agents = $pfia->find('module_wakeonlan=1');
             foreach ($a_agents as $IDagent => $data) {
                 $a_portsList = $np->find('on_device=' . $data['on_device'] . ' AND device_type=' . $data['device_type']);
                 foreach ($a_portsList as $ID => $datapl) {
                     if (!isset($existantantip[$datapl['ifaddr']])) {
                         $existantantip[$datapl['ifaddr']] = 1;
                         if ($this->getStateAgent($datapl['ifaddr'], $IDagent)) {
                             $count_agent_on++;
                         }
                     }
                 }
             }
             echo "</table>";
             break;
     }
     if ($count_agent_on == 0) {
         echo "<tr class='tab_bg_1'>";
         echo "<td align='center' colspan='2'>";
         echo "<b>" . $LANG['plugin_fusioninventory']["task"][13] . "</b>";
         echo "</td>";
         echo "</tr>";
     }
 }
 function convertUnknownToUnknownNetwork($ID)
 {
     global $DB;
     $np = new Netport();
     $this->getFromDB($ID);
     // Get port
     $a_ports = $np->find('on_device=' . $ID . ' AND device_type="' . PLUGIN_FUSIONINVENTORY_MAC_UNKNOWN . '"');
     if (count($a_ports) == '1') {
         // Put mac and ip to unknown
         $port = current($a_ports);
         $this->fields['ifaddr'] = $port['ifaddr'];
         $this->fields['ifmac'] = $port['ifmac'];
         $this->update($this->fields);
         $np->deleteFromDB($port['ID']);
         return true;
     }
     return false;
 }
 function addWakeonlan($pxml)
 {
     $pta = new PluginFusioninventoryAgents();
     $ptt = new PluginFusioninventoryTask();
     $np = new Netport();
     $agent = $pta->InfosByKey($pxml->DEVICEID);
     $sxml_option = $this->sxml->addChild('OPTION');
     $sxml_option->addChild('NAME', 'WAKEONLAN');
     $tasks = $ptt->ListTask($agent["ID"], "WAKEONLAN");
     foreach ($tasks as $task_id => $taskInfos) {
         if ($taskInfos['device_type'] == COMPUTER_TYPE) {
             $a_portsList = $np->find('on_device=' . $taskInfos['on_device'] . ' AND device_type="' . COMPUTER_TYPE . '"');
             foreach ($a_portsList as $ID => $data) {
                 if ($data['ifaddr'] != "127.0.0.1") {
                     $sxml_param = $sxml_option->addChild('PARAM');
                     $sxml_param->addAttribute('MAC', $data['ifmac']);
                     $sxml_param->addAttribute('IP', $data['ifaddr']);
                 }
             }
         }
     }
 }