/** * Actually executes the Shellcommand * * @param integer $commandId ID of the command to execute * @param string $targetParam Target of the command * * @return string Execution output, bool(false) in case of error */ static function execCommand($commandId, $targetParam) { $output = null; $execOuput = array(); $error = 1; $command = new PluginShellcommandsShellcommand(); $commandFound = $command->getFromDB($commandId); // Lauch command if ($commandFound) { if ($command->fields['name'] === self::WOL_COMMAND_NAME) { $command_item = new PluginShellcommandsShellcommand_Item(); ob_start(); $command_item->sendMagicPacket($targetParam); $output = ob_get_clean(); } else { if (($commandToExec = self::getCommandLine($commandId, $targetParam)) !== null) { exec($commandToExec . " 2>&1", $execOuput, $error); } } } // Format output message foreach ($execOuput as $currentOutputLine) { if (!is_array($currentOutputLine)) { $output .= Toolbox::encodeInUtf8($currentOutputLine) . PHP_EOL; } } return array($error, $output); }
$cmd = count($ouput); echo " <font color=blue>"; for ($i = 0; $i < $cmd; $i++) { echo Toolbox::encodeInUtf8($ouput[$i]) . "<br>"; } echo "</font>"; echo "</p>" . $command; } } else { if ($plugin_shellcommands_shellcommands_id == "Wake on Lan") { if ($itemtype != 'NetworkEquipement') { if (count($ipmac) > 0) { foreach ($ipmac as $key => $val) { if (!empty($data2["mac"])) { echo "<p><b>{$plugin_shellcommands_shellcommands_id} -> " . $val['host'] . " (" . $val['mac'] . ")</b></p>"; $command = $command_item->sendMagicPacket($val['mac'], $val['ip'], $val['netmask']); } } } } else { $host = $item->getField('mac'); echo "<p><b>{$plugin_shellcommands_shellcommands_id} -> " . $host . "</b></p>"; $command = $command_item->sendMagicPacket($host); } } else { echo "<p><b>{$plugin_shellcommands_shellcommands_id} -> " . $host . "</b></p>"; $command = $path . " " . $parameters . " " . $host; $ouput[] = null; exec($command, $ouput); $cmd = count($ouput); echo " <font color=blue>";
static function lauchCommand($values) { $host = $values['value']; $id = $values['plugin_shellcommands_shellcommands_id']; $command = new PluginShellcommandsShellcommand(); $command_item = new PluginShellcommandsShellcommand_Item(); $command->getFromDBbyName($id); $path = Dropdown::getDropdownName("glpi_plugin_shellcommands_shellcommandpaths", $command->fields["plugin_shellcommands_shellcommandpaths_id"]); $parameters = $command->fields["parameters"]; echo "<div align='center'>"; echo "<table class='tab_cadrehov' cellpadding='5'>"; echo "<tr><th>" . __('Command', 'shellcommands'); echo "</th></tr>"; echo "<tr class='tab_bg_2'><td>"; echo "<p><b>{$id} -> " . $host . "</b><br>"; if ($id == "Wake on Lan") { $command = $command_item->sendMagicPacket($host); } else { $command = $path . " " . $parameters . " " . $host; } $ouput[] = null; if ($id != "Wake on Lan") { exec($command, $ouput); $cmd = count($ouput); echo "<font color=blue>"; for ($i = 0; $i < $cmd; $i++) { echo Toolbox::encodeInUtf8($ouput[$i]) . "<br>"; } echo "</font>"; echo "</p>" . $command; } echo "</td></tr></table></div>"; }