Beispiel #1
0
 function canCreateItem()
 {
     // Check the parent
     return Session::haveRecursiveAccessToEntity($this->getField('entities_id'));
 }
 /**
  * Check right on an item
  *
  * @param $ID            ID of the item (-1 if new item)
  * @param $right         Right to check : r / w / recursive / READ / UPDATE / DELETE
  * @param &$input  array of input data (used for adding item) (default NULL)
  *
  * @return boolean
  **/
 function can($ID, $right, array &$input = NULL)
 {
     // Clean ID :
     $ID = Toolbox::cleanInteger($ID);
     // Create process
     if ($this->isNewID($ID)) {
         if (!isset($this->fields['id'])) {
             // Only once
             $this->getEmpty();
         }
         if (is_array($input)) {
             $input = $this->addNeededInfoToInput($input);
             // Copy input field to allow getEntityID() to work
             // from entites_id field or from parent item ref
             foreach ($input as $key => $val) {
                 if (isset($this->fields[$key])) {
                     $this->fields[$key] = $val;
                 }
             }
             // Store to be available for others functions
             $this->input = $input;
         }
         if ($this->isPrivate() && $this->fields['users_id'] === Session::getLoginUserID()) {
             return true;
         }
         //       if (!static::canCreate()) echo 'ii';
         //       if (!$this->canCreateItem()) echo 'jj';
         return static::canCreate() && $this->canCreateItem();
     }
     // else : Get item if not already loaded
     if (!isset($this->fields['id']) || $this->fields['id'] != $ID) {
         // Item not found : no right
         if (!$this->getFromDB($ID)) {
             return false;
         }
     }
     switch ($right) {
         case READ:
             // Personnal item
             if ($this->isPrivate() && $this->fields['users_id'] === Session::getLoginUserID()) {
                 return true;
             }
             return static::canView() && $this->canViewItem();
         case UPDATE:
             // Personnal item
             if ($this->isPrivate() && $this->fields['users_id'] === Session::getLoginUserID()) {
                 return true;
             }
             return static::canUpdate() && $this->canUpdateItem();
         case DELETE:
             // Personnal item
             if ($this->isPrivate() && $this->fields['users_id'] === Session::getLoginUserID()) {
                 return true;
             }
             return static::canDelete() && $this->canDeleteItem();
         case PURGE:
             // Personnal item
             if ($this->isPrivate() && $this->fields['users_id'] === Session::getLoginUserID()) {
                 return true;
             }
             return static::canPurge() && $this->canPurgeItem();
         case CREATE:
             // Personnal item
             if ($this->isPrivate() && $this->fields['users_id'] === Session::getLoginUserID()) {
                 return true;
             }
             return static::canCreate() && $this->canCreateItem();
         case 'recursive':
             if ($this->isEntityAssign() && $this->maybeRecursive()) {
                 if (static::canCreate() && Session::haveAccessToEntity($this->getEntityID())) {
                     // Can make recursive if recursive access to entity
                     return Session::haveRecursiveAccessToEntity($this->getEntityID());
                 }
             }
             break;
     }
     return false;
 }
 /**
  * @param $target
  * @param int $plugin_ocsinventoryng_ocsservers_id
  */
 function showProcesses($target, $plugin_ocsinventoryng_ocsservers_id = 0)
 {
     global $DB, $CFG_GLPI;
     $canedit = Session::haveRight("plugin_ocsinventoryng", UPDATE);
     $config = new PluginOcsinventoryngConfig();
     $config->getFromDB(1);
     $minfreq = 9999;
     //$task    = new CronTask();
     //if ($task->getFromDBbyName('PluginOcsinventoryngThread', 'CleanOldThreads')) {
     //First of all, deleted old processes
     //   $this->deleteOldProcesses($task->fields['param']);
     //   if ($task->fields['param'] > 0) {
     //      $minfreq=$task->fields['param'];
     //   }
     //}
     $imported_number = new PluginOcsinventoryngMiniStat();
     $synchronized_number = new PluginOcsinventoryngMiniStat();
     $linked_number = new PluginOcsinventoryngMiniStat();
     $failed_number = new PluginOcsinventoryngMiniStat();
     $notupdated_number = new PluginOcsinventoryngMiniStat();
     $notunique_number = new PluginOcsinventoryngMiniStat();
     $linkedrefused_number = new PluginOcsinventoryngMiniStat();
     $process_time = new PluginOcsinventoryngMiniStat();
     $sql = "SELECT `id`, `processid`, SUM(`total_number_machines`) AS total_machines,\n                     `plugin_ocsinventoryng_ocsservers_id`, `status`, COUNT(*) AS threads_number,\n                     MIN(`start_time`) AS starting_date, MAX(`end_time`) AS ending_date,\n                     TIMESTAMPDIFF(SECOND,MIN(start_time),MAX(end_time)) AS duree,\n                     SUM(`imported_machines_number`) AS imported_machines,\n                     SUM(`synchronized_machines_number`) AS synchronized_machines,\n                     SUM(`linked_machines_number`) AS linked_machines,\n                     SUM(`failed_rules_machines_number`) AS failed_rules_machines,\n                     SUM(`notupdated_machines_number`) AS notupdated_machines,\n                     SUM(`not_unique_machines_number`) AS not_unique_machines_number,\n                     SUM(`link_refused_machines_number`) AS link_refused_machines_number,\n                     `end_time` >= DATE_ADD(NOW(), INTERVAL - " . $minfreq . " HOUR) AS DoStat\n              FROM `" . $this->getTable() . "` ";
     if ($plugin_ocsinventoryng_ocsservers_id > 0) {
         $sql .= "WHERE `plugin_ocsinventoryng_ocsservers_id` = " . $plugin_ocsinventoryng_ocsservers_id . "";
     }
     $sql .= " GROUP BY `processid`\n              ORDER BY `id` DESC\n              LIMIT 50";
     $result = $DB->query($sql);
     echo "<div class='center'>";
     echo "<form name='processes' id='processes' action='{$target}' method='post'>";
     echo "<table class='tab_cadrehov'>";
     echo "<tr><th colspan='16'>" . __('Processes execution of automatic actions', 'ocsinventoryng');
     if (Session::haveRecursiveAccessToEntity(0)) {
         echo "&nbsp;<a href='thread.php?plugin_ocsinventoryng_ocsservers_id=0'>(" . __('See all servers', 'ocsinventoryng') . ")</a>";
     }
     echo "</th></tr>";
     echo "<tr>";
     echo "<th>&nbsp;</th>";
     echo "<th>&nbsp;</th>";
     echo "<th>" . __('Status') . "</th>";
     echo "<th>" . __('Number of threads', 'ocsinventoryng') . "</th>";
     echo "<th>" . __('Beginning date of execution', 'ocsinventoryng') . "</th>";
     echo "<th>" . __('Ending date of execution', 'ocsinventoryng') . "</th>";
     echo "<th>" . __('Computers imported by automatic actions', 'ocsinventoryng') . "</th>";
     echo "<th>" . __('Computers synchronized', 'ocsinventoryng') . "</th>";
     echo "<th>" . __('Computers linked', 'ocsinventoryng') . "</th>";
     echo "<th>" . __('Computers not imported by automatic actions', 'ocsinventoryng') . "</th>";
     echo "<th>" . __('Computers not updated', 'ocsinventoryng') . "</th>";
     echo "<th>" . __('Computers not unique', 'ocsinventoryng') . "</th>";
     echo "<th>" . __('Computers refused', 'ocsinventoryng') . "</th>";
     echo "<th>" . __('Process time execution', 'ocsinventoryng') . "</th>";
     echo "<th>" . __('Server') . "</th>";
     echo "<th>&nbsp;</th>";
     echo "</th></tr>\n";
     if ($DB->numrows($result)) {
         while ($thread = $DB->fetch_array($result)) {
             if ($config->fields["is_displayempty"] || $thread["status"] != PLUGIN_OCSINVENTORYNG_STATE_FINISHED || !$config->fields["is_displayempty"] && $thread["total_machines"] > 0 && $thread["status"] == PLUGIN_OCSINVENTORYNG_STATE_FINISHED) {
                 if ($thread["DoStat"] && $thread["status"] == PLUGIN_OCSINVENTORYNG_STATE_FINISHED) {
                     $imported_number->AddValue($thread["imported_machines"]);
                     $synchronized_number->AddValue($thread["synchronized_machines"]);
                     $linked_number->AddValue($thread["linked_machines"]);
                     $failed_number->AddValue($thread["failed_rules_machines"]);
                     $notupdated_number->AddValue($thread["notupdated_machines"]);
                     $notunique_number->AddValue($thread["not_unique_machines_number"]);
                     $linkedrefused_number->AddValue($thread["link_refused_machines_number"]);
                     $process_time->AddValue($thread["duree"]);
                 } else {
                     if ($imported_number->GetCount() > 0) {
                         $this->showshowStat($minfreq, $imported_number, $synchronized_number, $linked_number, $failed_number, $notupdated_number, $notunique_number, $linkedrefused_number, $process_time);
                         $imported_number->Reset();
                     }
                 }
                 echo "<tr class='tab_bg_1'>";
                 echo "<td width='10'>";
                 if ($canedit) {
                     echo "<input type='checkbox' name='item[" . $thread["processid"] . "]' value='1'>";
                 } else {
                     echo "&nbsp;";
                 }
                 echo "</td>";
                 echo "<td class='center'>";
                 echo "<a href=\"./thread.form.php?pid=" . $thread["processid"] . "\">" . $thread["processid"] . "</a></td>";
                 echo "<td class='center'>";
                 $this->displayProcessStatusIcon($this->getProcessStatus($thread["processid"]));
                 echo "</td>";
                 echo "<td class='center'>" . $thread["threads_number"] . "</td>";
                 echo "<td class='center'>" . Html::convDateTime($thread["starting_date"]) . "</td>";
                 echo "<td class='center'>" . Html::convDateTime($thread["ending_date"]) . "</td>";
                 echo "<td class='center'>" . $thread["imported_machines"] . "</td>";
                 echo "<td class='center'>" . $thread["synchronized_machines"] . "</td>";
                 echo "<td class='center'>" . $thread["linked_machines"] . "</td>";
                 echo "<td class='center'>" . $thread["failed_rules_machines"] . "</td>";
                 echo "<td class='center'>" . $thread["notupdated_machines"] . "</td>";
                 echo "<td class='center'>" . $thread["not_unique_machines_number"] . "</td>";
                 echo "<td class='center'>" . $thread["link_refused_machines_number"] . "</td>";
                 echo "<td class='center'>";
                 if ($thread["status"] == PLUGIN_OCSINVENTORYNG_STATE_FINISHED) {
                     echo $this->timestampToStringShort($thread["duree"]);
                 } else {
                     echo Dropdown::EMPTY_VALUE;
                 }
                 echo "</td>";
                 echo "<td class='center'>";
                 if ($thread["plugin_ocsinventoryng_ocsservers_id"] != -1) {
                     $ocsConfig = PluginOcsinventoryngOcsServer::getConfig($thread["plugin_ocsinventoryng_ocsservers_id"]);
                     echo "<a href=\"ocsserver.form.php?id=" . $ocsConfig["id"] . "\">" . $ocsConfig["name"] . "</a>";
                 } else {
                     _e('All servers', 'ocsinventoryng');
                 }
                 echo "</td>";
                 echo "<td class='center'>";
                 echo "<a href=\"detail.php?criteria[0][field]=5&" . "criteria[0][searchtype]=contains&criteria[0][value]=^" . $thread["processid"] . '$">' . "<img  src='" . $CFG_GLPI["root_doc"] . "/pics/rdv.png'</a></td>";
                 echo "</tr>\n";
             }
         }
     }
     if ($imported_number->GetCount() > 0) {
         $this->showshowStat($minfreq, $imported_number, $synchronized_number, $linked_number, $failed_number, $notupdated_number, $notunique_number, $linkedrefused_number, $process_time);
     }
     echo "</table>";
     if ($canedit) {
         Html::openArrowMassives("processes");
         Html::closeArrowMassives(array("delete_processes" => _x('button', 'Delete permanently')));
     }
     Html::closeForm();
 }
Beispiel #4
0
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.

Ocsinventoryng plugin 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 ocsinventoryng. If not, see <http://www.gnu.org/licenses/>.
-------------------------------------------------------------------------- */
include '../../../inc/includes.php';
Session::checkRight("plugin_ocsinventoryng", UPDATE);
$thread = new PluginOcsinventoryngThread();
if (Session::haveRecursiveAccessToEntity(0)) {
    Html::header(__('Processes execution of automatic actions', 'ocsinventoryng'), '', "tools", "pluginocsinventoryngmenu", "thread");
    if (isset($_POST["delete_processes"])) {
        //checkRight("ocsng", "w");
        if (count($_POST["item"])) {
            foreach ($_POST["item"] as $key => $val) {
                $thread->deleteThreadsByProcessId($key);
            }
        }
        Html::back();
    } else {
        $thread->showProcesses($_SERVER["PHP_SELF"]);
    }
    Html::footer();
} else {
    $thread->redirectToList();