Skip to content

Commit

Permalink
Close #145 - Move avconfig details to stateavdetails
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin Hamon committed Dec 14, 2016
1 parent f9ecfa1 commit c1bd5b0
Show file tree
Hide file tree
Showing 5 changed files with 265 additions and 8 deletions.
46 changes: 46 additions & 0 deletions front/stateavdetail.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
Copyright (C) 2016 Teclib'
Copyright (C) 2010-2016 by the FusionInventory Development Team.
This file is part of Armadito Plugin for GLPI.
Armadito Plugin for GLPI is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Armadito Plugin for GLPI 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Armadito Plugin for GLPI. If not, see <http://www.gnu.org/licenses/>.
**/

include("../../../inc/includes.php");

Session::checkRight('plugin_armadito_stateavdetail', READ);

$avdetails = new PluginArmaditoStateAVDetail();

Html::header(__('Armadito', 'armadito'), $_SERVER["PHP_SELF"], "plugins", "pluginarmaditomenu", "avdetail");

PluginArmaditoMenu::displayMenu("mini");

if (isset($_GET["id"])) {
$avdetails->display(array(
"id" => $_GET["id"]
));
}
else
{
$avdetails->showErrorMessage();
}

Html::footer();

?>
1 change: 1 addition & 0 deletions inc/profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function getRightsGeneral()
$rights['Jobs'] = new PluginArmaditoProfileRights('plugin_armadito_jobs', 'PluginArmaditoJob');
$rights['States'] = new PluginArmaditoProfileRights('plugin_armadito_states', 'PluginArmaditoState');
$rights['StateUpdateDetails'] = new PluginArmaditoProfileRights('plugin_armadito_stateupdatedetail', 'PluginArmaditoStateUpdateDetail');
$rights['StateAVDetails'] = new PluginArmaditoProfileRights('plugin_armadito_stateavdetail', 'PluginArmaditoStateAVDetail');
$rights['Alerts'] = new PluginArmaditoProfileRights('plugin_armadito_alerts', 'PluginArmaditoAlert');
$rights['Scans'] = new PluginArmaditoProfileRights('plugin_armadito_scans', 'PluginArmaditoScan');
$rights['Antiviruses'] = new PluginArmaditoProfileRights('plugin_armadito_antiviruses', 'PluginArmaditoAntivirus');
Expand Down
36 changes: 28 additions & 8 deletions inc/state.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class PluginArmaditoState extends PluginArmaditoCommonDBTM
protected $agent;
protected $obj;
protected $antivirus;
protected $avdetails;
protected $stateupdatedetails_id;
protected $stateavdetails_id;

static function getTypeName($nb = 0)
{
Expand All @@ -42,12 +44,17 @@ static function getTypeName($nb = 0)

function initFromJson($jobj)
{
$this->setAgentFromJson($jobj);
$this->avdetails = new PluginArmaditoStateAVDetail();
$this->avdetails->initFromJson($jobj);

$this->agentid = $jobj->agent_id;
$this->agent = $this->avdetails->getAgent();
$this->antivirus = $this->agent->getAntivirus();
$this->setObj($jobj->task->obj);

$this->setUpdateStateObj($jobj->task->obj->dbinfo);
}

function setObj($obj)
function setUpdateStateObj($obj)
{
$this->obj = new StdClass;
$this->obj->service_status = $this->setValueOrDefault($obj, "service_status", "string");
Expand Down Expand Up @@ -107,12 +114,16 @@ function getSearchOptions()
$items['Antivirus'] = new PluginArmaditoSearchitemlink('fullname', 'glpi_plugin_armadito_antiviruses', 'PluginArmaditoAntivirus');
$items['Antivirus Service'] = new PluginArmaditoSearchtext('service_status', $this->getTable());
$items['Update Details'] = new PluginArmaditoSearchitemlink('id', 'glpi_plugin_armadito_stateupdatedetails', 'PluginArmaditoStateUpdateDetail');
$items['AV Details'] = new PluginArmaditoSearchitemlink('id', 'glpi_plugin_armadito_stateavdetails', 'PluginArmaditoStateAVDetail');

return $search_options->get($items);
}

function run()
{
$this->avdetails->run();
$this->stateavdetails_id = $this->getTableIdForAgentId("glpi_plugin_armadito_stateavdetails");

if (!empty($this->obj->modules)) {
$this->insertOrUpdateStateModules();
}
Expand Down Expand Up @@ -162,15 +173,22 @@ function getTableIdForAgentId($table)
$query = "SELECT id FROM `" . $table . "`
WHERE `plugin_armadito_agents_id`='" . $this->agentid . "'";

if($table == 'glpi_plugin_armadito_stateavdetails') {
$query .= " AND `type`='hasAVConfig'";
}

$ret = $DB->query($query);

if (!$ret) {
throw new InvalidArgumentException(sprintf('Error getTableIdForAgentId : %s', $DB->error()));
}

PluginArmaditoLog::Debug($query);

if ($DB->numrows($ret) > 0) {
$data = $DB->fetch_assoc($ret);
$tableid = $data["id"];
PluginArmaditoLog::Debug("Found tableid =".$tableid);
}

return $tableid;
Expand Down Expand Up @@ -210,17 +228,19 @@ function updateState()

function setCommonQueryParams()
{
$params["plugin_armadito_antiviruses_id"]["type"] = "i";
$params["plugin_armadito_stateavdetails_id"]["type"] = "i";
$params["plugin_armadito_stateupdatedetails_id"]["type"] = "i";
$params["update_status"]["type"] = "s";
$params["last_update"]["type"] = "s";
$params["service_status"]["type"] = "s";
$params["plugin_armadito_agents_id"]["type"] = "i";
$params["plugin_armadito_antiviruses_id"]["type"] = "i";
$params["update_status"]["type"] = "s";
$params["last_update"]["type"] = "s";
$params["service_status"]["type"] = "s";
$params["plugin_armadito_agents_id"]["type"] = "i";
return $params;
}

function setCommonQueryValues($dbmanager, $query)
{
$dbmanager->setQueryValue($query, "plugin_armadito_stateavdetails_id", $this->stateavdetails_id);
$dbmanager->setQueryValue($query, "plugin_armadito_stateupdatedetails_id", $this->stateupdatedetails_id);
$dbmanager->setQueryValue($query, "plugin_armadito_antiviruses_id", $this->antivirus->getId());
$dbmanager->setQueryValue($query, "update_status", $this->obj->global_status);
Expand Down
178 changes: 178 additions & 0 deletions inc/stateavdetail.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<?php

/*
Copyright (C) 2016 Teclib'
This file is part of Armadito Plugin for GLPI.
Armadito Plugin for GLPI is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Armadito Plugin for GLPI 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Armadito Plugin for GLPI. If not, see <http://www.gnu.org/licenses/>.
**/

include_once("toolbox.class.php");

if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
}

class PluginArmaditoStateAVDetail extends PluginArmaditoEAVCommonDBTM
{
protected $id;
protected $agentid;
protected $agent;
protected $entries;
protected $antivirus;

static function getTypeName($nb = 0)
{
return __('State AV Details', 'armadito');
}

function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
{
if ($item->getType() == 'PluginArmaditoStateAVDetail') {
return __('Antiviruses\' configurations', 'armadito');
}
return '';
}

static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
{
if ($item->getType() == 'PluginArmaditoStateAVDetail') {
$paAVConfig = new self();
$paAVConfig->showForm($item->fields["plugin_armadito_agents_id"]);
}

return TRUE;
}

function getAgent()
{
return $this->agent;
}

function getId()
{
return $this->id;
}

function initFromJson($jobj)
{
$this->setAgentFromJson($jobj);
$this->antivirus = $this->agent->getAntivirus();
$this->entries = $jobj->task->obj->avdetails;
}

function run()
{
$i = 0;
foreach ($this->entries as $entry)
{
$i++;

PluginArmaditoLog::Verbose("[".$i."] ".$entry->{'attr'}."=".$entry->{'value'});

$is_agentrow_indb = $this->isValueForAgentInDB($entry->{'attr'}, $this->agentid);
$is_baserow_indb = $this->isValueForAgentInDB($entry->{'attr'}, 0);
$is_baserow_equal = $this->isValueEqualForAgentInDB($entry->{'attr'}, $entry->{'value'}, 0);

if($is_baserow_equal) {
$this->rmValueFromDB($entry->{'attr'}, $entry->{'value'}, $this->agentid);
continue;
}

if($is_agentrow_indb) {
$this->updateValueInDB($entry->{'attr'}, $entry->{'value'}, $this->agentid);
continue;
}

if ($is_baserow_indb) {
$this->addOrUpdateValueForAgent($entry->{'attr'}, $entry->{'value'}, $this->agentid);
} else {
$this->insertValueInDB($entry->{'attr'}, $entry->{'value'}, 0);
}
}

$this->addOrUpdateValueForAgent("hasAVConfig", 1, $this->agentid);

$this->id = PluginArmaditoDbToolbox::getLastInsertedId();
PluginArmaditoToolbox::validateInt($this->id);
}

function showForm($id, $options = array())
{
PluginArmaditoToolbox::validateInt($id);
$agent_id = $this->fields["plugin_armadito_agents_id"];

echo "<table class='tab_cadre_fixe'>";
echo "<tr>";
echo "<th >" . __('Type', 'armadito') . "</th>";
echo "<th >" . __('Value', 'armadito') . "</th>";
echo "</tr>";

$this->showEntriesForAgent($agent_id);
$this->showEntriesForAgent(0);

echo "</table>";
}


function showEntriesForAgent($agent_id)
{
$agent_entries = $this->findEntries($agent_id);
$table_header = "Configuration specific to agent n° ". htmlspecialchars($agent_id);

if($agent_id == 0) {
$table_header = "Common configuration";
}

echo "<tr class='tab_bg_1'>";
echo "<th colspan='2' >".$table_header."</th>";
echo "</tr>";

foreach ($agent_entries as $data) {
echo "<tr class='tab_bg_1'>";
echo "<td align='center'>" . htmlspecialchars($data["type"]) . "</td>";
echo "<td align='center'>" . htmlspecialchars($data["value"]) . "</td>";
echo "</tr>";
}
}


function findEntries($agent_id)
{
global $DB;

$query = "SELECT id, value, type FROM `glpi_plugin_armadito_stateavdetails`
WHERE `plugin_armadito_agents_id`='" . $agent_id . "'";

$data = array();
if ($result = $DB->query($query)) {
if($DB->numrows($result)) {
while ($line = $DB->fetch_assoc($result)) {
$data[$line['id']] = $line;
}
}
}

return $data;
}

function showErrorMessage()
{
echo "<div style='text-align: center;'><br><b>No id provided.</b><br></div>";
}

}
?>
12 changes: 12 additions & 0 deletions install/mysql/plugin_armadito-empty.sql
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ CREATE TABLE `glpi_plugin_armadito_states` (
`plugin_armadito_antiviruses_id` int(11) NOT NULL,
`service_status` varchar(255) DEFAULT NULL,
`plugin_armadito_stateupdatedetails_id` int(11) NOT NULL,
`plugin_armadito_stateavdetails_id` int(11) NOT NULL,
`is_deleted` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `is_deleted` (`is_deleted`),
Expand All @@ -102,6 +103,17 @@ CREATE TABLE `glpi_plugin_armadito_stateupdatedetails` (
UNIQUE KEY `couple module_agent_id` (`module_name`,`plugin_armadito_agents_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;

DROP TABLE IF EXISTS `glpi_plugin_armadito_stateavdetails`;

CREATE TABLE `glpi_plugin_armadito_stateavdetails` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`type` varchar(255) DEFAULT NULL,
`value` varchar(255) DEFAULT NULL,
`plugin_armadito_agents_id` int(11) NOT NULL,
`plugin_armadito_antiviruses_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;

DROP TABLE IF EXISTS `glpi_plugin_armadito_jobs`;

CREATE TABLE `glpi_plugin_armadito_jobs` (
Expand Down

0 comments on commit c1bd5b0

Please sign in to comment.