'common', 'name' => self::getTypeName(2) ]; $tab[] = [ 'id' => '1', 'table' => $this->getTable(), 'field' => 'id', 'name' => __('ID', 'cve'), 'massiveaction' => false, 'datatype' => 'number' ]; $tab[] = [ 'id' => '2', 'table' => 'glpi_plugin_cve_cves', 'field' => 'cve_id', 'name' => __('CVE ID', 'cve'), 'massiveaction' => false, 'datatype' => 'dropdown', 'joinparams' => [ 'jointype' => 'child', 'condition' => 'AND NEWTABLE.`id` = REFTABLE.`cves_id`' ] ]; $tab[] = [ 'id' => '3', 'table' => 'glpi_tickets', 'field' => 'name', 'name' => __('Ticket', 'cve'), 'massiveaction' => false, 'datatype' => 'dropdown', 'joinparams' => [ 'jointype' => 'child', 'condition' => 'AND NEWTABLE.`id` = REFTABLE.`tickets_id`' ] ]; $tab[] = [ 'id' => '4', 'table' => $this->getTable(), 'field' => 'creation_type', 'name' => __('Creation Type', 'cve'), 'massiveaction' => false, 'datatype' => 'specific', 'searchtype' => ['equals', 'notequals'] ]; $tab[] = [ 'id' => '5', 'table' => $this->getTable(), 'field' => 'date_creation', 'name' => __('Creation date', 'cve'), 'datatype' => 'datetime', 'massiveaction' => false ]; return $tab; } /** * Show tickets for a CVE * * @param PluginCveCve $cve CVE object * @return void */ static function showForCVE(PluginCveCve $cve) { global $DB; $ID = $cve->getField('id'); if (!$cve->can($ID, READ)) { return false; } $canedit = $cve->can($ID, UPDATE); $rand = mt_rand(); $iterator = $DB->request([ 'SELECT' => [ 'glpi_plugin_cve_tickets.*', 'glpi_tickets.name AS ticket_name', 'glpi_tickets.status AS ticket_status', 'glpi_tickets.date AS ticket_date', 'glpi_tickets.priority AS ticket_priority' ], 'FROM' => 'glpi_plugin_cve_tickets', 'LEFT JOIN' => [ 'glpi_tickets' => [ 'ON' => [ 'glpi_plugin_cve_tickets' => 'tickets_id', 'glpi_tickets' => 'id' ] ] ], 'WHERE' => [ 'glpi_plugin_cve_tickets.cves_id' => $ID ], 'ORDER' => [ 'glpi_tickets.date DESC' ] ]); $tickets = []; $used = []; foreach ($iterator as $data) { $tickets[$data['id']] = $data; $used[$data['tickets_id']] = $data['tickets_id']; } if ($canedit) { echo "
"; echo "
"; echo ""; echo ""; echo ""; echo "
" . __('Add a ticket', 'cve') . "
"; echo ""; Ticket::dropdown([ 'used' => $used, 'entity' => $cve->getEntityID(), 'entity_sons' => $cve->isRecursive(), 'displaywith' => ['id'] ]); echo ""; echo ""; echo "
"; Html::closeForm(); echo "
"; } if ($canedit && count($tickets)) { $massiveactionparams = [ 'num_displayed' => min($_SESSION['glpilist_limit'], count($tickets)), 'container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => [ 'purge' => _x('button', 'Delete permanently') ] ]; Html::showMassiveActions($massiveactionparams); } echo ""; $header_begin = ""; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit && count($tickets)) { $header_top .= ""; $header_bottom .= ""; } $header_end .= ""; $header_end .= ""; $header_end .= ""; $header_end .= ""; $header_end .= ""; $header_end .= ""; echo $header_begin . $header_top . $header_end; foreach ($tickets as $data) { echo ""; if ($canedit) { echo ""; } $ticket = new Ticket(); $ticket->getFromDB($data['tickets_id']); echo ""; // Status echo ""; // Priority echo ""; // Date echo ""; // Creation type echo ""; echo ""; } if ($header_bottom) { echo $header_begin . $header_bottom . $header_end; } echo "
" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "" . __('Ticket', 'cve') . "" . __('Status', 'cve') . "" . __('Priority', 'cve') . "" . __('Opening date', 'cve') . "" . __('Creation type', 'cve') . "
"; Html::showMassiveActionCheckBox(__CLASS__, $data['id']); echo ""; if ($ticket->can($data['tickets_id'], READ)) { echo ""; echo $data['ticket_name'] . " (" . $data['tickets_id'] . ")"; echo ""; } else { echo $data['ticket_name'] . " (" . $data['tickets_id'] . ")"; } echo ""; echo Ticket::getStatus($data['ticket_status']); echo ""; echo Ticket::getPriorityName($data['ticket_priority']); echo ""; echo Html::convDateTime($data['ticket_date']); echo ""; echo $data['creation_type'] == 'AUTO' ? __('Automatic', 'cve') : __('Manual', 'cve'); echo "
"; if ($canedit && count($tickets)) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } } /** * Show CVEs for a ticket * * @param Ticket $ticket Ticket object * @return void */ static function showForTicket(Ticket $ticket) { global $DB; $ID = $ticket->getField('id'); if (!$ticket->can($ID, READ)) { return false; } $canedit = $ticket->can($ID, UPDATE); $rand = mt_rand(); $iterator = $DB->request([ 'SELECT' => [ 'glpi_plugin_cve_tickets.*', 'glpi_plugin_cve_cves.cve_id', 'glpi_plugin_cve_cves.severity', 'glpi_plugin_cve_cves.cvss_score', 'glpi_plugin_cve_cves.status AS cve_status' ], 'FROM' => 'glpi_plugin_cve_tickets', 'LEFT JOIN' => [ 'glpi_plugin_cve_cves' => [ 'ON' => [ 'glpi_plugin_cve_tickets' => 'cves_id', 'glpi_plugin_cve_cves' => 'id' ] ] ], 'WHERE' => [ 'glpi_plugin_cve_tickets.tickets_id' => $ID ] ]); $cvetickets = []; $used = []; foreach ($iterator as $data) { $cvetickets[$data['id']] = $data; $used[$data['cves_id']] = $data['cves_id']; } if ($canedit) { echo "
"; echo ""; echo ""; echo ""; echo ""; echo "
" . __('Add a CVE', 'cve') . "
"; echo ""; $cve = new PluginCveCve(); $cve->dropdown([ 'name' => 'cves_id', 'entity' => $ticket->getEntityID(), 'used' => $used ]); echo ""; echo ""; echo "
"; Html::closeForm(); echo "
"; } if ($canedit && count($cvetickets)) { $massiveactionparams = [ 'num_displayed' => min($_SESSION['glpilist_limit'], count($cvetickets)), 'container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => [ 'purge' => _x('button', 'Delete permanently') ] ]; Html::showMassiveActions($massiveactionparams); } echo ""; $header_begin = ""; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit && count($cvetickets)) { $header_top .= ""; $header_bottom .= ""; } $header_end .= ""; $header_end .= ""; $header_end .= ""; $header_end .= ""; $header_end .= ""; $header_end .= ""; echo $header_begin . $header_top . $header_end; foreach ($cvetickets as $data) { echo ""; if ($canedit) { echo ""; } $cve = new PluginCveCve(); $cve->getFromDB($data['cves_id']); echo ""; // Severity echo ""; // CVSS Score echo ""; // Status echo ""; // Creation type echo ""; echo ""; } if ($header_bottom) { echo $header_begin . $header_bottom . $header_end; } echo "
" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "" . __('CVE ID', 'cve') . "" . __('Severity', 'cve') . "" . __('CVSS Score', 'cve') . "" . __('Status', 'cve') . "" . __('Creation Type', 'cve') . "
"; Html::showMassiveActionCheckBox(__CLASS__, $data['id']); echo ""; if ($cve->can($data['cves_id'], READ)) { echo ""; echo $data['cve_id']; echo ""; } else { echo $data['cve_id']; } echo ""; echo ""; echo $data['severity']; echo ""; echo ""; echo $data['cvss_score']; echo ""; echo ""; echo $data['cve_status']; echo ""; echo ""; echo $data['creation_type'] == 'AUTO' ? __('Automatic', 'cve') : __('Manual', 'cve'); echo "
"; if ($canedit && count($cvetickets)) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } } /** * Add events to ticket notifications * * @param array $events Events array * @return array Modified events array */ static function addEvents(&$events) { $events['cve_added'] = __('CVE linked to ticket', 'cve'); return $events; } /** * Install the plugin database schema * * @return boolean */ static function install(Migration $migration) { global $DB; $table = self::getTable(); if (!$DB->tableExists($table)) { $migration->displayMessage("Installing $table"); $query = "CREATE TABLE IF NOT EXISTS `$table` ( `id` int(11) NOT NULL AUTO_INCREMENT, `cves_id` int(11) NOT NULL, `tickets_id` int(11) NOT NULL, `creation_type` enum('AUTO','MANUAL') DEFAULT 'MANUAL', `date_creation` datetime DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `cves_id_tickets_id` (`cves_id`,`tickets_id`), KEY `cves_id` (`cves_id`), KEY `tickets_id` (`tickets_id`), KEY `creation_type` (`creation_type`), KEY `date_creation` (`date_creation`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; $DB->query($query) or die("Error creating $table " . $DB->error()); } return true; } /** * Uninstall the plugin database schema * * @return boolean */ static function uninstall(Migration $migration) { global $DB; $table = self::getTable(); if ($DB->tableExists($table)) { $migration->displayMessage("Uninstalling $table"); $migration->dropTable($table); } return true; } }