/**
  * Show config menu
  */
 function showMenu()
 {
     global $CFG_GLPI;
     if (!$this->canView()) {
         return false;
     }
     echo "<div align='center'>";
     echo "<table class='tab_cadre' cellpadding='5' height='150'>";
     echo "<tr>";
     echo "<th colspan='5'>" . PluginShellcommandsShellcommand::getTypeName(2) . "</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_1' style='background-color:white;'>";
     // Add shell command
     echo "<td class='center shellcommands_menu_item'>";
     echo "<a  class='shellcommands_menu_a' href=\"./shellcommand.php\">";
     echo "<img class='shellcommands_menu_img' src='" . $CFG_GLPI["root_doc"] . "/plugins/shellcommands/pics/shellcommand.png' alt=\"" . PluginShellcommandsShellcommand::getTypeName(2) . "\">";
     echo "<br>" . PluginShellcommandsShellcommand::getTypeName(2) . "</a>";
     echo "</td>";
     // Command group
     echo "<td class='center shellcommands_menu_item'>";
     echo "<a  class='shellcommands_menu_a' href=\"./commandgroup.php\">";
     echo "<img class='shellcommands_menu_img' src='" . $CFG_GLPI["root_doc"] . "/plugins/shellcommands/pics/commandgroup.png' alt=\"" . PluginShellcommandsCommandGroup::getTypeName(2) . "\">";
     echo "<br>" . PluginShellcommandsCommandGroup::getTypeName(2) . "</a>";
     echo "</td>";
     // Advanced execution
     echo "<td class='center shellcommands_menu_item'>";
     echo "<a  class='shellcommands_menu_a' href=\"./advanced_execution.php\">";
     echo "<img class='shellcommands_menu_img' src='" . $CFG_GLPI["root_doc"] . "/plugins/shellcommands/pics/advanced_execution.png' alt=\"" . PluginShellcommandsAdvanced_Execution::getTypeName(2) . "\">";
     echo "<br>" . PluginShellcommandsAdvanced_Execution::getTypeName(2) . "</a>";
     echo "</td>";
     echo "</table></div>";
 }
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     if ($item->getType() == 'Profile' && $item->getField('interface') != 'helpdesk') {
         return PluginShellcommandsShellcommand::getTypeName(2);
     }
     return '';
 }
Пример #3
0
 function showForm($ID, $options = array())
 {
     if (!Session::haveRight("profile", "r")) {
         return false;
     }
     $prof = new Profile();
     if ($ID) {
         $this->getFromDBByProfile($ID);
         $prof->getFromDB($ID);
     }
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_2'>";
     echo "<th colspan='2' class='center b'>" . self::getTypeName() . " " . $prof->fields["name"] . "</th>";
     echo "<td>" . PluginShellcommandsShellcommand::getTypeName(2) . ":</td><td>";
     Profile::dropdownNoneReadWrite("shellcommands", $this->fields["shellcommands"], 1, 1, 1);
     echo "</td>";
     echo "</tr>";
     echo "<input type='hidden' name='id' value=" . $this->fields["id"] . ">";
     $options['candel'] = false;
     $this->showFormButtons($options);
 }
    $command->check(-1, UPDATE, $_POST);
    $newID = $command->add($_POST);
    Html::back();
} else {
    if (isset($_POST["update"])) {
        $command->check($_POST['id'], UPDATE);
        $command->update($_POST);
        Html::back();
    } else {
        if (isset($_POST["additem"])) {
            if (!empty($_POST['itemtype'])) {
                if ($command->canCreate()) {
                    $command_item->addItem($_POST["plugin_shellcommands_shellcommands_id"], $_POST['itemtype']);
                }
            }
            Html::back();
        } else {
            if (isset($_POST["deleteitem"])) {
                if ($command->canCreate()) {
                    $command_item->delete(array('id' => $_POST["id"]));
                }
                Html::back();
            } else {
                $command->checkGlobal(READ);
                Html::header(PluginShellcommandsShellcommand::getTypeName(2), '', "tools", "pluginshellcommandsshellcommand", "shellcommand");
                $command->display(array('id' => $_GET["id"]));
                Html::footer();
            }
        }
    }
}
 /**
  * Show shellcommands associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated shellcommands must be displayed
  * @param $withtemplate    (default '')
  * */
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!self::canView()) {
         return false;
     }
     if (!$item->can($item->fields['id'], READ)) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $width = 200;
     $canedit = $item->canadditem('PluginShellcommandsShellcommand');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_plugin_shellcommands_shellcommands_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_shellcommands_shellcommands`.`name` AS assocName,\n                       `glpi_plugin_shellcommands_shellcommands`.*\n                FROM `glpi_plugin_shellcommands_shellcommands_items`\n                LEFT JOIN `glpi_plugin_shellcommands_shellcommands`\n                 ON (`glpi_plugin_shellcommands_shellcommands_items`.`plugin_shellcommands_shellcommands_id`=`glpi_plugin_shellcommands_shellcommands`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_shellcommands_shellcommands`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_shellcommands_shellcommands_items`.`itemtype` = '" . $item->getType() . "' \n                  AND !`glpi_plugin_shellcommands_shellcommands`.`is_deleted`";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_shellcommands_shellcommands", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $shells = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $shells[$data['assocID']] = $data;
         }
     }
     echo "<div class='spaced'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     echo "<th>" . __('Associated Commands', 'shellcommands') . "</th>";
     echo "</tr>";
     if ($number) {
         Session::initNavigateListItems('PluginShellcommandsShellcommand', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         $selectCommandName[0] = Dropdown::EMPTY_VALUE;
         //         $countCommand = self::countForItem($item, array('type' => 'ALL'));
         foreach ($shells as $data) {
             //            if(isset($countCommand[$data['link'].$data['id']]))
             $selectCommandName[$data['link'] . '-' . $data['id']] = $data['assocName'];
         }
         echo "<tr class='tab_bg_2'>\n               <td class='center'>" . PluginShellcommandsShellcommand::getTypeName(1) . " ";
         $randSelect = Dropdown::showFromArray("name", $selectCommandName, array('width' => $width));
         echo "<span id='command_name{$randSelect}'></span></td>";
         echo "</tr>";
         Ajax::updateItemOnSelectEvent("dropdown_name{$randSelect}", "command_name{$randSelect}", $CFG_GLPI["root_doc"] . "/plugins/shellcommands/ajax/dropdownCommandValue.php", array('idtable' => $item->getType(), 'width' => $width, 'value' => '__VALUE__', 'itemID' => $ID, 'countItem' => 1, 'itemtype' => $item->getType(), 'toupdate' => 'shellcommand_result', 'command_type' => 'PluginShellcommandsShellcommand', 'myname' => "command_name"));
     }
     echo "</table>";
     echo "</div>";
     echo "<div class='spaced' id='shellcommand_result'></div>";
 }
Пример #6
0
 Shellcommands plugin for GLPI
 Copyright (C) 2003-2011 by the Shellcommands Development Team.

 https://forge.indepnet.net/projects/shellcommands
 -------------------------------------------------------------------------

 LICENSE

 This file is part of Shellcommands.

 Shellcommands is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 Shellcommands is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with shellcommands. If not, see <http://www.gnu.org/licenses/>.
 --------------------------------------------------------------------------
*/
include '../../../inc/includes.php';
Html::popHeader(PluginShellcommandsShellcommand::getTypeName(2));
$command = new PluginShellcommandsShellcommand();
$command_item = new PluginShellcommandsShellcommand_Item();
$command->checkGlobal("r");
PluginShellcommandsShellcommand_Item::lauchCommand($_GET);
Html::popFooter();
 /**
  * Function list items
  * 
  * @global type $CFG_GLPI
  * @param type $ID
  * @param type $data
  * @param type $canedit
  * @param type $rand
  */
 private function listItems($data, $canedit)
 {
     global $CFG_GLPI;
     $rand = mt_rand();
     $numrows = count($data);
     $target = Toolbox::getItemTypeFormURL('PluginShellcommandsCommandGroup_Item');
     echo "<div class='center'>";
     if ($canedit) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('item' => __CLASS__, 'container' => 'mass' . __CLASS__ . $rand, 'num_displayed' => $numrows);
         Html::showMassiveActions($massiveactionparams);
     }
     //      Html::printAjaxPager(self::getTypeName(2), $start, countElementsInTable($this->getTable()));
     echo "<table class='tab_cadre_fixehov'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th width='10'>";
     if ($canedit) {
         echo Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         Html::closeForm();
     }
     echo "</th>";
     echo "<th>" . PluginShellcommandsShellcommand::getTypeName(2) . "</th>";
     echo "<th>" . _n('Type', 'Types', 1) . "</th>";
     echo "<th colspan='2'>" . __('Order', 'shellcommands') . "</th>";
     echo "</tr>";
     $shellcommand = new PluginShellcommandsShellcommand();
     $shellcommand_item = new PluginShellcommandsShellcommand_Item();
     $i = 0;
     foreach ($data as $field) {
         echo "<tr class='tab_bg_2'>";
         echo "<td width='10'>";
         if ($canedit) {
             Html::showMassiveActionCheckBox(__CLASS__, $field['id']);
         }
         echo "</td>";
         // Command
         $shellcommand->getFromDB($field['plugin_shellcommands_shellcommands_id']);
         $itemtypes = $shellcommand_item->getShellCommandItemtypes($field['plugin_shellcommands_shellcommands_id']);
         echo "<td>" . $shellcommand->getLink() . "</td>";
         echo "<td>";
         if (!empty($itemtypes)) {
             echo implode("<br>", $itemtypes);
         }
         echo "</td>";
         // Change order
         if ($i != 0) {
             echo "<td class='center middle'>";
             echo "<form method='post' action='{$target}'>";
             echo "<input type='hidden' name='id' value='" . $field["id"] . "'>";
             echo "<input type='image' name='up' value=\"" . __s('Bring up') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/puce-up2.png' alt=\"" . __s('Bring up') . "\"  title=\"" . __s('Bring up') . "\">";
             Html::closeForm();
             echo "</td>";
         } else {
             echo "<td>&nbsp;</td>\n";
         }
         if ($i != $numrows - 1) {
             echo "<td class='center middle'>";
             echo "<form method='post' action='{$target}'>";
             echo "<input type='hidden' name='id' value='" . $field["id"] . "'>";
             echo "<input type='image' name='down' value=\"" . __s('Bring down') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/puce-down2.png' alt=\"" . __s('Bring down') . "\" title=\"" . __s('Bring down') . "\">";
             Html::closeForm();
             echo "</td>";
         } else {
             echo "<td>&nbsp;</td>\n";
         }
         echo "</tr>";
         $i++;
     }
     if ($canedit) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</table>";
     echo "</div>";
 }
 /**
  * Custom fonction to process shellcommand massive action
  **/
 function doMassiveAction(MassiveAction $ma, array $ids)
 {
     if (!empty($ids)) {
         $input = $ma->getInput();
         $itemtype = $ma->getItemType(false);
         $commands_id = $input['command'];
         switch ($ma->getAction()) {
             case 'generate':
                 $shellcommands_item = new PluginShellcommandsShellcommand_Item();
                 $shellcommands = new PluginShellcommandsShellcommand();
                 $item = getItemForItemtype($itemtype);
                 echo "<div class='center'>";
                 echo "<table class='tab_cadre_fixe center'>";
                 echo "<tr class='tab_bg_1'>";
                 echo "<th colspan='4'>" . PluginShellcommandsShellcommand::getTypeName(2) . "</th>";
                 echo "</tr>";
                 foreach ($ids as $key => $items_id) {
                     if (!$shellcommands_item->getFromDBbyShellCommandsAndItem($commands_id, $itemtype)) {
                         continue;
                     }
                     $shellcommands->getFromDB($commands_id);
                     $item->getFromDB($items_id);
                     $targetParam = PluginShellcommandsShellcommand_Item::resolveLinkOfCommand($shellcommands->getID(), $item);
                     // Exec command on each targets : stop on first success
                     $selectedTarget = null;
                     if ($targetParam !== false) {
                         foreach ($targetParam as $target) {
                             list($error, $message) = PluginShellcommandsShellcommand_Item::execCommand($shellcommands->getID(), $target);
                             if (!$error) {
                                 $selectedTarget = $target;
                                 break;
                             }
                         }
                     }
                     echo "<tr class='tab_bg_1 shellcommands_result_line'>";
                     echo "<td class='center' colspan='4'>" . __($item->getType()) . ' : ' . $item->getLink() . " - " . $selectedTarget . "</td>";
                     echo "</tr>";
                     PluginShellcommandsShellcommand::displayCommandResult($shellcommands, $selectedTarget, $message, $error);
                 }
                 echo "</table>";
                 echo "</div>";
                 break;
         }
     }
 }