Commit 3a38ec5e authored by Johan Cwiklinski's avatar Johan Cwiklinski Committed by Johan Cwiklinski
Browse files

Native inventory, based on JSON schema

Schema doc: https://github.com/glpi-project/inventory_format
Can be overrided from a plugin to inventory its own types.

Based on inventory features provided from fusioninventoryplugin, and
compatible with

New uUpgraded equipement rules to handle several itemtypes, add reset capacity
Handle Phones inventories
Add entites rules

Locks management for fields and its tests:
- Fields that have been updated from GLPI must not be modified from
inventory, and inventory does not lock anything.
- An icon is displayed in main item form only, even if all item types
can be locked. Displaying on all forms would require to change each
form individually (very huge work to copy a few lines of code).
- All item types can be locked

Overridable USB and PCI vendors list

Network inventory

Support for network equipments, stacked, wireless, VLANS,
LLDP/CDP and MAC connections, hubs

Add some missing fields in network tables

Use withHistory and fix usages
Check request mime type lowercase
Rework ports display

Handle unmanaged equipments
Display hub connected equipments
Handle managements port

Connections logs
Add metrics on port bytes and errors
Exclude metrics data from glpi log system

Printers

Inventory printers from SNMP information

Handle cartridge information
Handle page counters

Refused  equipment log with rule and inventory replay

Display error when already in transaction
Link to import rules collections from config
Order rules by ranking
Enhance blacklists and add new defaults
parent aece01f8
......@@ -2,11 +2,11 @@
"php-core-extensions": [
"core", "standard",
"ctype", "date", "fileinfo", "filter", "iconv", "json", "pcre", "reflection", "session", "simplexml", "spl", "xml",
"ctype", "dom", "date", "fileinfo", "filter", "iconv", "json", "libxml", "pcre", "reflection", "session", "simplexml", "spl", "xml",
"curl", "gd", "intl", "mbstring", "mysqli", "zlib",
"apcu", "exif", "ldap", "pcntl", "xmlrpc"
"apcu", "exif", "ldap", "pcntl", "xmlrpc", "zip"
],
"symbol-whitelist": [
"// PHP symbols",
......@@ -15,11 +15,21 @@
"static", "self", "parent",
"array", "bool", "callable", "float", "int", "iterable", "object", "string", "void",
"// Missing constant in Alpine Linux",
"GLOB_BRACE",
"// GLPI config classes",
"DB", "DBSlave",
"// GLPI base constants (they are not detected as they are dynamically declared)",
"GLPI_AJAX_DASHBOARD", "GLPI_CALDAV_IMPORT_STATE", "GLPI_CACHE_DIR", "GLPI_CRON_DIR", "GLPI_CSRF_EXPIRES", "GLPI_CSRF_MAX_TOKENS", "GLPI_USE_IDOR_CHECK", "GLPI_IDOR_EXPIRES", "GLPI_DEMO_MODE", "GLPI_DISABLE_ONLY_FULL_GROUP_BY_SQL_MODE", "GLPI_DOC_DIR", "GLPI_DUMP_DIR", "GLPI_FORCE_EMPTY_SQL_MODE", "GLPI_GRAPH_DIR", "GLPI_INSTALL_MODE", "GLPI_LOCAL_I18N_DIR", "GLPI_LOCK_DIR", "GLPI_LOG_DIR", "GLPI_MARKETPLACE_DIR", "GLPI_MARKETPLACE_PLUGINS_API_URI", "GLPI_MARKETPLACE_PRERELEASES", "GLPI_NETWORK_REGISTRATION_API_URL", "GLPI_NETWORK_MAIL", "GLPI_NETWORK_SERVICES", "GLPI_PICTURE_DIR", "GLPI_PLUGIN_DOC_DIR", "GLPI_RSS_DIR", "GLPI_SESSION_DIR", "GLPI_TELEMETRY_URI", "GLPI_TMP_DIR", "GLPI_UPLOAD_DIR", "GLPI_USE_CSRF_CHECK", "GLPI_USER_AGENT_EXTRA_COMMENTS",
"GLPI_AJAX_DASHBOARD", "GLPI_CALDAV_IMPORT_STATE", "GLPI_CACHE_DIR", "GLPI_CRON_DIR", "GLPI_CSRF_EXPIRES",
"GLPI_CSRF_MAX_TOKENS", "GLPI_DEMO_MODE", "GLPI_DISABLE_ONLY_FULL_GROUP_BY_SQL_MODE", "GLPI_DOC_DIR",
"GLPI_DUMP_DIR", "GLPI_FORCE_EMPTY_SQL_MODE", "GLPI_GRAPH_DIR", "GLPI_IDOR_EXPIRES", "GLPI_INSTALL_MODE",
"GLPI_INVENTORY_DIR", "GLPI_LOCAL_I18N_DIR", "GLPI_LOCK_DIR", "GLPI_LOG_DIR", "GLPI_MARKETPLACE_DIR",
"GLPI_MARKETPLACE_PLUGINS_API_URI", "GLPI_MARKETPLACE_PRERELEASES", "GLPI_NETWORK_REGISTRATION_API_URL",
"GLPI_NETWORK_MAIL", "GLPI_NETWORK_SERVICES", "GLPI_PICTURE_DIR", "GLPI_PLUGIN_DOC_DIR", "GLPI_RSS_DIR",
"GLPI_SESSION_DIR", "GLPI_TELEMETRY_URI", "GLPI_TMP_DIR", "GLPI_UPLOAD_DIR", "GLPI_USE_CSRF_CHECK",
"GLPI_USE_IDOR_CHECK", "GLPI_USER_AGENT_EXTRA_COMMENTS",
"// GLPI optionnal constants",
"GLPI_FORCE_MAIL", "GLPI_LOG_LVL",
......@@ -47,7 +57,10 @@
"CAS_VERSION_2_0", "phpCAS",
"// paragonie/sodium_compat library",
"sodium_crypto_aead_chacha20poly1305_ietf_keygen", "SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES", "sodium_crypto_aead_xchacha20poly1305_ietf_encrypt", "sodium_crypto_aead_xchacha20poly1305_ietf_decrypt"
"sodium_crypto_aead_chacha20poly1305_ietf_keygen", "SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES", "sodium_crypto_aead_xchacha20poly1305_ietf_encrypt", "sodium_crypto_aead_xchacha20poly1305_ietf_decrypt",
"//xhprof",
"XHPROF_FLAGS_NO_BUILTINS", "XHPROF_FLAGS_CPU", "XHPROF_FLAGS_MEMORY"
],
"scan-files": [
"ajax/**/*.php",
......
......@@ -34,4 +34,5 @@ phpunit.xml
.package.hash
/public/build/
/public/lib/
/tests/web/error.log
\ No newline at end of file
/tests/web/error.log
/inventory-vendors/*.json
\ No newline at end of file
......@@ -24,6 +24,7 @@ The present file will list all changes made to the project; according to the
#### Deprecated
- Usage of `GLPI_FORCE_EMPTY_SQL_MODE` constant
- `RuleImportComputer` and `RuleImportComputerCollection`
#### Removed
- `Update::declareOldItems()`
......
<?php
/**
* ---------------------------------------------------------------------
* GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2015-2021 Teclib' and contributors.
*
* http://glpi-project.org
*
* based on GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2003-2014 by the INDEPNET Development Team.
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* GLPI 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.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GLPI. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
*/
$AJAX_INCLUDE = 1;
include ('../inc/includes.php');
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();
if (isset($_REQUEST['action']) && isset($_REQUEST['id'])) {
$agent = new Agent();
if (!$agent->getFromDB($_REQUEST['id'])) {
Toolbox::logWarning('Unable to load agent #' . $_REQUEST['id']);
return;
};
$answer = [];
switch ($_REQUEST['action']) {
case Agent::ACTION_INVENTORY:
$answer = $agent->requestInventory();
break;
case Agent::ACTION_STATUS:
$answer = $agent->requestStatus();
break;
}
echo json_encode($answer);
}
......@@ -25,6 +25,7 @@
"ext-zlib": "*",
"blueimp/jquery-file-upload": "^10.2",
"elvanto/litemoji": "^3.0.1",
"glpi-project/inventory_format": "^1.0",
"guzzlehttp/guzzle": "^7.2",
"guzzlehttp/psr7": "^1.6",
"htmlawed/htmlawed": "^1.2",
......@@ -96,11 +97,13 @@
"lint": "parallel-lint --exclude files --exclude marketplace --exclude plugins --exclude vendor --exclude tools/vendor .",
"post-install-cmd": [
"@php -r \"file_put_contents('.composer.hash', sha1_file('composer.lock'));\"",
"patch -f -p1 -d vendor/tecnickcom/tcpdf/ < tools/tcpdf-php8-compat.patch || echo 'Error applying patch, deprecation warnings related to TCPDF lib may pollute logs'"
"patch -f -p1 -d vendor/tecnickcom/tcpdf/ < tools/tcpdf-php8-compat.patch || echo 'Error applying patch, deprecation warnings related to TCPDF lib may pollute logs'",
"@php -f vendor/bin/build_hw_jsons"
],
"post-update-cmd": [
"@php -r \"file_put_contents('.composer.hash', sha1_file('composer.lock'));\"",
"patch -f -p1 -d vendor/tecnickcom/tcpdf/ < tools/tcpdf-php8-compat.patch || echo 'Error applying patch, deprecation warnings related to TCPDF lib may pollute logs'"
"patch -f -p1 -d vendor/tecnickcom/tcpdf/ < tools/tcpdf-php8-compat.patch || echo 'Error applying patch, deprecation warnings related to TCPDF lib may pollute logs'",
"@php -f vendor/bin/build_hw_jsons"
]
},
"repositories": {
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "b36fc12f53f8f51cec2f788bd891ecb2",
"content-hash": "b2c0a02a0c10dc0f0660c8ad2c2f87ce",
"packages": [
{
"name": "blueimp/jquery-file-upload",
......@@ -205,6 +205,66 @@
},
"time": "2020-11-27T05:08:33+00:00"
},
{
"name": "glpi-project/inventory_format",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/glpi-project/inventory_format.git",
"reference": "5dac802b85fd6c7f32c2685c2e6a70499e075cda"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/glpi-project/inventory_format/zipball/5dac802b85fd6c7f32c2685c2e6a70499e075cda",
"reference": "5dac802b85fd6c7f32c2685c2e6a70499e075cda",
"shasum": ""
},
"require": {
"seld/jsonlint": "^1.7",
"swaggest/json-schema": "^0.12.31"
},
"require-dev": {
"atoum/atoum": "^4.0",
"squizlabs/php_codesniffer": "^3.5"
},
"bin": [
"bin/convert",
"bin/build_hw_jsons"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"files": [
"lib/php/Converter.php",
"lib/php/FilesToJSON.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-2.0-or-later"
],
"authors": [
{
"name": "Teclib'",
"email": "glpi@teclib.com",
"homepage": "https://teclib.com"
}
],
"description": "GLPI Inventory format lib",
"keywords": [
"automatic inventory",
"glpi"
],
"support": {
"issues": "https://github.com/glpi-project/inventory_format/issues",
"source": "https://github.com/glpi-project/inventory_format"
},
"time": "2021-01-18T14:15:58+00:00"
},
{
"name": "guzzlehttp/guzzle",
"version": "7.2.0",
......@@ -2647,6 +2707,54 @@
},
"time": "2020-12-03T16:26:19+00:00"
},
{
"name": "phplang/scope-exit",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/phplang/scope-exit.git",
"reference": "239b73abe89f9414aa85a7ca075ec9445629192b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phplang/scope-exit/zipball/239b73abe89f9414aa85a7ca075ec9445629192b",
"reference": "239b73abe89f9414aa85a7ca075ec9445629192b",
"shasum": ""
},
"require-dev": {
"phpunit/phpunit": "*"
},
"type": "library",
"autoload": {
"psr-4": {
"PhpLang\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD"
],
"authors": [
{
"name": "Sara Golemon",
"email": "pollita@php.net",
"homepage": "https://twitter.com/SaraMG",
"role": "Developer"
}
],
"description": "Emulation of SCOPE_EXIT construct from C++",
"homepage": "https://github.com/phplang/scope-exit",
"keywords": [
"cleanup",
"exit",
"scope"
],
"support": {
"issues": "https://github.com/phplang/scope-exit/issues",
"source": "https://github.com/phplang/scope-exit/tree/master"
},
"time": "2016-09-17T00:15:18+00:00"
},
{
"name": "phpmailer/phpmailer",
"version": "v6.2.0",
......@@ -3866,6 +3974,69 @@
],
"time": "2020-11-30T07:59:04+00:00"
},
{
"name": "seld/jsonlint",
"version": "1.8.3",
"source": {
"type": "git",
"url": "https://github.com/Seldaek/jsonlint.git",
"reference": "9ad6ce79c342fbd44df10ea95511a1b24dee5b57"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/9ad6ce79c342fbd44df10ea95511a1b24dee5b57",
"reference": "9ad6ce79c342fbd44df10ea95511a1b24dee5b57",
"shasum": ""
},
"require": {
"php": "^5.3 || ^7.0 || ^8.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0"
},
"bin": [
"bin/jsonlint"
],
"type": "library",
"autoload": {
"psr-4": {
"Seld\\JsonLint\\": "src/Seld/JsonLint/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jordi Boggiano",
"email": "j.boggiano@seld.be",
"homepage": "http://seld.be"
}
],
"description": "JSON Linter",
"keywords": [
"json",
"linter",
"parser",
"validator"
],
"support": {
"issues": "https://github.com/Seldaek/jsonlint/issues",
"source": "https://github.com/Seldaek/jsonlint/tree/1.8.3"
},
"funding": [
{
"url": "https://github.com/Seldaek",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/seld/jsonlint",
"type": "tidelift"
}
],
"time": "2020-11-11T09:19:24+00:00"
},
{
"name": "simplepie/simplepie",
"version": "1.5.6",
......@@ -3937,6 +4108,98 @@
},
"time": "2020-10-14T07:17:22+00:00"
},
{
"name": "swaggest/json-diff",
"version": "v3.8.1",
"source": {
"type": "git",
"url": "https://github.com/swaggest/json-diff.git",
"reference": "d2184358c5ef5ecaa1f6b4c2bce175fac2d25670"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/swaggest/json-diff/zipball/d2184358c5ef5ecaa1f6b4c2bce175fac2d25670",
"reference": "d2184358c5ef5ecaa1f6b4c2bce175fac2d25670",
"shasum": ""
},
"require": {
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^4.8.23"
},
"type": "library",
"autoload": {
"psr-4": {
"Swaggest\\JsonDiff\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Viacheslav Poturaev",
"email": "vearutop@gmail.com"
}
],
"description": "JSON diff/rearrange/patch/pointer library for PHP",
"support": {
"issues": "https://github.com/swaggest/json-diff/issues",
"source": "https://github.com/swaggest/json-diff/tree/v3.8.1"
},
"time": "2020-09-25T17:47:07+00:00"
},
{
"name": "swaggest/json-schema",
"version": "v0.12.31",
"source": {
"type": "git",
"url": "https://github.com/swaggest/php-json-schema.git",
"reference": "a4adcdbb38f38a19d3f1801150822172cf1c4853"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/swaggest/php-json-schema/zipball/a4adcdbb38f38a19d3f1801150822172cf1c4853",
"reference": "a4adcdbb38f38a19d3f1801150822172cf1c4853",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-mbstring": "*",
"php": ">=5.4",
"phplang/scope-exit": "^1.0",
"swaggest/json-diff": "^3.5.1"
},
"require-dev": {
"phpunit/php-code-coverage": "2.2.4",
"phpunit/phpunit": "4.8.35"
},
"type": "library",
"autoload": {
"psr-4": {
"Swaggest\\JsonSchema\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Viacheslav Poturaev",
"email": "vearutop@gmail.com"
}
],
"description": "High definition PHP structures with JSON-schema based validation",
"support": {
"email": "vearutop@gmail.com",
"issues": "https://github.com/swaggest/php-json-schema/issues",
"source": "https://github.com/swaggest/php-json-schema/tree/v0.12.31"
},
"time": "2020-09-21T09:31:21+00:00"
},
{
"name": "symfony/console",
"version": "v4.4.18",
......
......@@ -7013,6 +7013,13 @@ div.progress {
}
/* /Styles for update page */
.lockedfield i.fa-lock {
float: right;
font-size: 1em;
color: grey;
font-weight: 900;
}
/* Flex horizontal forms */
.horizontal-form {
margin-left: 20px;
......@@ -7099,3 +7106,70 @@ div.progress {
}
}
.netport {
td {
&.green {
background-color: green;
color: white;
}
&.red {
background-color: red;
color: white;
}
&.orange {
background-color: orange;
color: white;
}
}
&.trunk {
background-color: MediumAquamarine;
}
&.hub {
background-color: LightSalmon;
}
&.cotrunk {
background-color: silver;
}
&.aggregated,
.aggregated {
background-color: teal;
color: white;
padding-left: 2em;
a {
color: white;
}
}
.hub {
border: 1px grey solid;
margin: 0 .5em 0 .5em;
div {
padding: .2em .5em;
border-bottom: 1px grey solid;
&:last-of-type {
border-bottom: none;
}
}
}
}
.legend {
width: 100%;
td.netport {
text-align: center;
width: 25%;
}
}
.dashboard.printer_barchart .g-chart .chart {
flex:none;
height: 500px;
}
Vous pouvez effacer ce fichier sans dommages.
You can safely remove this file.
<?php
/**
* ---------------------------------------------------------------------
* GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2015-2021 Teclib' and contributors.
*
* http://glpi-project.org
*
* based on GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2003-2014 by the INDEPNET Development Team.
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* GLPI 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.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GLPI. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
*/
use Glpi\Event;
include ('../inc/includes.php');
Session::checkRight("config", READ);
if (!isset($_GET["id"])) {
$_GET["id"] = "";
}
if (!isset($_GET["withtemplate"])) {
$_GET["withtemplate"] = "";
}
$agent = new Agent();
//Add a new agent
if (isset($_POST["add"])) {
$agent->check(-1, CREATE, $_POST);
if ($newID = $agent->add($_POST)) {
Event::log($newID, "agents", 4, "inventory",
sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"]));
if ($_SESSION['glpibackcreated']) {
Html::redirect($agent->getLinkURL());
}
}
Html::back();
// delete an agent
} else if (isset($_POST["delete"])) {
$agent->check($_POST['id'], DELETE);
$ok = $agent->delete($_POST);
if ($ok) {
Event::log($_POST["id"], "agents", 4, "inventory",
//TRANS: %s is the user login
sprintf(__('%s deletes an item'), $_SESSION["glpiname"]));
}
$agent->redirectToList();
} else if (isset($_POST["restore"])) {
$agent->check($_POST['id'], DELETE);
if ($agent->restore($_POST)) {
Event::log($_POST["id"], "agents", 4, "inventory",
//TRANS: %s is the user login
sprintf(__('%s restores an item'), $_SESSION["glpiname"]));
}
$agent->redirectToList();
} else if (isset($_POST["purge"])) {
$agent->check($_POST['id'], PURGE);
if ($agent->delete($_POST, 1)) {
Event::log($_POST["id"], "agents", 4, "inventory",
//TRANS: %s is the user login
sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
}
$agent->redirectToList();
//update an agent
} else if (isset($_POST["update"])) {
$agent->check($_POST['id'], UPDATE);
$agent->update($_POST);
Event::log($_POST["id"], "agents", 4, "inventory",
//TRANS: %s is the user login