Пример #1
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 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>";
     }
 }
 function importToken($p_xml)
 {
     $this->setXML($p_xml);
     if (isset($this->sxml->DEVICEID) and isset($this->sxml->TOKEN)) {
         $pta = new PluginFusioninventoryAgents();
         $a_agent = $pta->find("`key`='" . $this->sxml->DEVICEID . "'", "", "1");
         if (empty($a_agent)) {
             $a_input = array();
             $a_input['token'] = $this->sxml->TOKEN;
             $a_input['name'] = $this->sxml->DEVICEID;
             $a_input['key'] = $this->sxml->DEVICEID;
             $pta->add($a_input);
             return 2;
         } else {
             foreach ($a_agent as $id_agent => $dataInfos) {
                 $input = array();
                 $input['ID'] = $id_agent;
                 $input['token'] = $this->sxml->TOKEN;
                 $pta->update($input);
             }
         }
     }
     return 1;
 }