From 277feb352658130d529dea8e5a4471fe8d1dd4a1 Mon Sep 17 00:00:00 2001 From: Progfou Date: Tue, 11 Mar 2014 17:46:09 -0400 Subject: [PATCH] =?utf8?q?Cr=C3=A9ation=20d'un=20paquet=20glpi-plugin-auf.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .gitignore | 7 + TODO | 2 +- glpi-plugin-auf/Makefile | 18 ++ glpi-plugin-auf/debian/changelog | 5 + glpi-plugin-auf/debian/compat | 1 + glpi-plugin-auf/debian/control | 16 ++ glpi-plugin-auf/debian/copyright | 23 +++ glpi-plugin-auf/debian/rules | 14 ++ glpi-plugin-auf/plugin/auf.css | 12 ++ glpi-plugin-auf/plugin/hook.php | 15 ++ glpi-plugin-auf/plugin/report.operatingsystems.php | 139 ++++++++++++++ glpi-plugin-auf/plugin/report.wip.php | 195 ++++++++++++++++++++ glpi-plugin-auf/plugin/setup.php | 57 ++++++ 13 files changed, 503 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 glpi-plugin-auf/Makefile create mode 100644 glpi-plugin-auf/debian/changelog create mode 100644 glpi-plugin-auf/debian/compat create mode 100644 glpi-plugin-auf/debian/control create mode 100644 glpi-plugin-auf/debian/copyright create mode 100755 glpi-plugin-auf/debian/rules create mode 100644 glpi-plugin-auf/plugin/auf.css create mode 100644 glpi-plugin-auf/plugin/hook.php create mode 100644 glpi-plugin-auf/plugin/report.operatingsystems.php create mode 100644 glpi-plugin-auf/plugin/report.wip.php create mode 100644 glpi-plugin-auf/plugin/setup.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c95bebf --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +/*/.tmp* +/*_*.deb +/*_*.dsc +/*_*.tar.gz +/*_*.build +/*_*.upload +/*_*.changes diff --git a/TODO b/TODO index f95d038..e5ff7d0 100644 --- a/TODO +++ b/TODO @@ -7,5 +7,5 @@ * auf-serveur-suivi - pour les choses à installer pour le suivi d'un serveur Depends: auf-git-etc, apticron | cron-apt, apt-listchanges, - logcheck, exim4 | mail-transport-agent + logcheck, exim4 | mail-transport-agent, munin-node diff --git a/glpi-plugin-auf/Makefile b/glpi-plugin-auf/Makefile new file mode 100644 index 0000000..f3f0b83 --- /dev/null +++ b/glpi-plugin-auf/Makefile @@ -0,0 +1,18 @@ +PACKAGE = $(shell dpkg-parsechangelog | sed -n 's/^Source: //p') +VERSION = $(shell dpkg-parsechangelog | sed -n 's/^Version: //p') +DIST = $(shell dpkg-parsechangelog | sed -n 's/^Distribution: //p') + +all: + +clean: + +install: + install -d -m 0755 $(DESTDIR)/usr/share/glpi/plugins + cp -a plugin $(DESTDIR)/usr/share/glpi/plugins/auf + +deb: + debuild -I.git -I*.ex -us -uc -b && \ + echo -e "\n\n==> Lancer \"sudo debi\" pour tester l'installation.\n" + +release: + debuild -I.git -I*.ex -tc -sa -us -uc && debrelease --dput wheezy-test diff --git a/glpi-plugin-auf/debian/changelog b/glpi-plugin-auf/debian/changelog new file mode 100644 index 0000000..3dee881 --- /dev/null +++ b/glpi-plugin-auf/debian/changelog @@ -0,0 +1,5 @@ +glpi-plugin-auf (0.84+1) unstable; urgency=low + + * Création du paquet Debian. + + -- Progfou Fri, 14 Feb 2014 13:33:31 -0500 diff --git a/glpi-plugin-auf/debian/compat b/glpi-plugin-auf/debian/compat new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/glpi-plugin-auf/debian/compat @@ -0,0 +1 @@ +8 diff --git a/glpi-plugin-auf/debian/control b/glpi-plugin-auf/debian/control new file mode 100644 index 0000000..a191ec8 --- /dev/null +++ b/glpi-plugin-auf/debian/control @@ -0,0 +1,16 @@ +Source: glpi-plugin-auf +Section: web +Priority: extra +Maintainer: Progfou +Build-Depends: debhelper (>= 8.0.0) +Standards-Version: 3.9.3 +Homepage: +Vcs-Git: git://git.auf.org/auf-serveur.git +Vcs-Browser: http://git.auf.org/?p=auf-serveur.git;a=summary + +Package: glpi-plugin-auf +Architecture: all +Depends: ${misc:Depends} +Recommends: glpi +Description: greffon AUF pour GLPI + Ce paquet apporte des rapports d'inventaire AUF. diff --git a/glpi-plugin-auf/debian/copyright b/glpi-plugin-auf/debian/copyright new file mode 100644 index 0000000..4c1e761 --- /dev/null +++ b/glpi-plugin-auf/debian/copyright @@ -0,0 +1,23 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: glpi-plugin-auf +Source: http://git.auf.org/?p=auf-serveur.git;a=summary + +Files: * +Copyright: 2014 Agence universitaire de la Francophonie -- www.auf.org +License: GPL-2+ + This package 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. + . + This package 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 this program. If not, see + . + On Debian systems, the complete text of the GNU General + Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". + diff --git a/glpi-plugin-auf/debian/rules b/glpi-plugin-auf/debian/rules new file mode 100755 index 0000000..e50e7cd --- /dev/null +++ b/glpi-plugin-auf/debian/rules @@ -0,0 +1,14 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +%: + dh $@ + diff --git a/glpi-plugin-auf/plugin/auf.css b/glpi-plugin-auf/plugin/auf.css new file mode 100644 index 0000000..8b163c1 --- /dev/null +++ b/glpi-plugin-auf/plugin/auf.css @@ -0,0 +1,12 @@ +/* + AUF plugin for GLPI + Copyright (C) 2014 AUF -- www.auf.org + */ + +.plugin_auf_show_details { + display: show; +} + +.plugin_auf_hide_details { + display: hide; +} diff --git a/glpi-plugin-auf/plugin/hook.php b/glpi-plugin-auf/plugin/hook.php new file mode 100644 index 0000000..1275775 --- /dev/null +++ b/glpi-plugin-auf/plugin/hook.php @@ -0,0 +1,15 @@ + diff --git a/glpi-plugin-auf/plugin/report.operatingsystems.php b/glpi-plugin-auf/plugin/report.operatingsystems.php new file mode 100644 index 0000000..b061b84 --- /dev/null +++ b/glpi-plugin-auf/plugin/report.operatingsystems.php @@ -0,0 +1,139 @@ +Systèmes d'exploitation par implantation

"; +echo ""; +echo ""; +$green_grand_total = 0; +$yellow_grand_total = 0; +$red_grand_total = 0; +$blue_grand_total = 0; +$grand_total = 0; + +# parcours des régions +$query = "SELECT id,name,completename FROM glpi_entities WHERE (id=0 OR entities_id=0)"; +$query .= " ".getEntitiesRestrictRequest("AND", "glpi_entities"); +$region_result = $DB->query($query); +while ($region_data = $DB->fetch_assoc($region_result)) { + $region_id = $region_data['id']; + if ($region_id != 0) { + $region_name = getTreeLeafValueName("glpi_entities", $region_id); + } else { + $region_name = "AUF (non classé)"; + } + echo ""; + + $green_total = 0; + $yellow_total = 0; + $red_total = 0; + $blue_total = 0; + $region_total = 0; + +# operating systems per computer +$query = "SELECT COUNT(c.id) AS count, e.name AS ename, + (CASE WHEN o.name REGEXP '^Debian ' THEN SUBSTRING_INDEX(REPLACE(o.name,' GNU/Linux',''),'.',1) + WHEN o.name REGEXP '^Ubuntu ' THEN SUBSTRING_INDEX(REPLACE(o.name,' LTS',''),'.',2) + WHEN o.name REGEXP '^Microsoft ' THEN REPLACE(o.name,'Microsoft ','') + WHEN o.name REGEXP '^Mac ' THEN REPLACE(o.name,'Mac ','') + ELSE o.name END) AS oname + FROM `$table_item` c + LEFT JOIN glpi_computers_items i ON (i.itemtype = 'Computer' AND i.items_id = c.id) + LEFT JOIN glpi_entities e ON (c.entities_id = e.id) + LEFT JOIN glpi_operatingsystems o ON (c.operatingsystems_id = o.id) + WHERE c.is_deleted = '0' AND c.is_template = '0' + ".getEntitiesRestrictRequest("AND", "c"); +if ($region_id != 0) { + $query .= " AND ".getRealQueryForTreeItem("glpi_entities", $region_id, "e.id"); +} else { + $query .= " AND e.id = '0'"; +} +$query .= " GROUP BY 2,3 ORDER BY 2,3"; +$result = $DB->query($query); +while ($data=$DB->fetch_assoc($result)) { + if (empty($data['ename'])) { + $data['ename'] = "(indéterminé)"; + } + if (empty($data['oname'])) { + $data['oname'] = "(indéterminé)"; + } + if (($data['oname'] == 'Debian 7') || ($data['oname'] == 'Ubuntu 12.04')) { + $oname_plus = ''; + $green_total += $data['count']; + } elseif (($data['oname'] == 'Debian 6') || ($data['oname'] == 'Ubuntu 10.04')) { + $oname_plus = ''; + $yellow_total += $data['count']; + } elseif ((substr($data['oname'],0,7) == 'Windows') || (substr($data['oname'],strlen($data['oname'])-4,4) == 'OS X')) { + $oname_plus = ''; + $blue_total += $data['count']; + } else { + $oname_plus = ''; + $red_total += $data['count']; + } + echo ""; + echo ""; + echo ""; + echo ""; + $region_total += $data['count']; +} + +$green_svg = ''; +$yellow_svg = ''; +$red_svg = ''; +$blue_svg = ''; +echo ""; +echo ""; +echo ""; + +$green_grand_total += $green_total; +$yellow_grand_total += $yellow_total; +$red_grand_total += $red_total; +$blue_grand_total += $blue_total; +$grand_total += $region_total; +} // fin des régions + +echo ""; + +# total operating systems +$query = "SELECT COUNT(*) FROM `".$table_item."` + LEFT JOIN `glpi_computers_items` + ON (`glpi_computers_items`.`itemtype` = '".$itemtype."' + AND `glpi_computers_items`.`items_id` = `".$table_item."`.`id`) + WHERE `".$table_item."`.`is_deleted` = '0' + AND `".$table_item."`.`is_template` = '0' ". + getEntitiesRestrictRequest("AND", $table_item); +$result = $DB->query($query); +$total = $DB->result($result, 0, 0); + +$green_svg = ''; +$yellow_svg = ''; +$red_svg = ''; +$blue_svg = ''; +echo ""; +echo ""; +echo ""; + +echo "
ImplantationSystème d'exploitationQuantité
$region_name
  ".$data['ename']."".$oname_plus." ".$data['oname']."".$data['count']."
  Sous-total".$green_svg.$yellow_svg.$red_svg.$blue_svg."$region_total
 
Total général".$green_svg.$yellow_svg.$red_svg.$blue_svg."$total
"; + +Html::footer(); +?> diff --git a/glpi-plugin-auf/plugin/report.wip.php b/glpi-plugin-auf/plugin/report.wip.php new file mode 100644 index 0000000..e0bffd7 --- /dev/null +++ b/glpi-plugin-auf/plugin/report.wip.php @@ -0,0 +1,195 @@ +WIP (rapport en cours de développement)

"; +echo ""; + +echo ""; +$green_grand_total = 0; +$yellow_grand_total = 0; +$red_grand_total = 0; +$blue_grand_total = 0; +$grand_total = 0; + +# parcours des régions +$query = "SELECT id,name,completename FROM glpi_entities WHERE (id=0 OR entities_id=0)"; +$query .= " ".getEntitiesRestrictRequest("AND", "glpi_entities"); +$region_result = $DB->query($query); +while ($region_data = $DB->fetch_assoc($region_result)) { + $region_id = $region_data['id']; + if ($region_id != 0) { + $region_name = getTreeLeafValueName("glpi_entities", $region_id); + } else { + $region_name = "AUF (non classé)"; + } + echo ""; +# foreach (getSonsOf("glpi_entities", $data['id']) as $id) { +# echo ""; +# } +#} + $green_total = 0; + $yellow_total = 0; + $red_total = 0; + $blue_total = 0; + $region_total = 0; + +# operating systems per computer +$query = "SELECT COUNT(c.id) AS count, e.name AS ename, + (CASE WHEN o.name REGEXP '^Debian' THEN SUBSTRING_INDEX(REPLACE(o.name,' GNU/Linux',''),'.',1) + WHEN o.name REGEXP '^Ubuntu' THEN SUBSTRING_INDEX(REPLACE(o.name,' LTS',''),'.',2) + ELSE o.name END) AS oname + FROM `$table_item` c + LEFT JOIN glpi_computers_items i ON (i.itemtype = 'Computer' AND i.items_id = c.id) + LEFT JOIN glpi_entities e ON (c.entities_id = e.id) + LEFT JOIN glpi_operatingsystems o ON (c.operatingsystems_id = o.id) + WHERE c.is_deleted = '0' AND c.is_template = '0' + ".getEntitiesRestrictRequest("AND", "c"); +if ($region_id != 0) { + $query .= " AND ".getRealQueryForTreeItem("glpi_entities", $region_id, "e.id"); +} else { + $query .= " AND e.id = '0'"; +} +$query .= " GROUP BY 2,3 ORDER BY 2,3"; +$result = $DB->query($query); +while ($data=$DB->fetch_assoc($result)) { + if (empty($data['ename'])) { + $data['ename'] = "(indéterminé)"; + } + if (empty($data['oname'])) { + $data['oname'] = "(indéterminé)"; + } + if (($data['oname'] == 'Debian 7') || ($data['oname'] == 'Ubuntu 12.04')) { + $oname_plus = ''; + $green_total += $data['count']; + } elseif (($data['oname'] == 'Debian 6') || ($data['oname'] == 'Ubuntu 10.04')) { + $oname_plus = ''; + $yellow_total += $data['count']; + } elseif ((substr($data['oname'],0,9) == 'Microsoft') || (substr($data['oname'],strlen($data['oname'])-4,4) == 'OS X')) { + $oname_plus = ''; + $blue_total += $data['count']; + } else { + $oname_plus = ''; + $red_total += $data['count']; + } + echo ""; + echo ""; + echo ""; + echo ""; + $region_total += $data['count']; +} + +$green_svg = ''; +$yellow_svg = ''; +$red_svg = ''; +$blue_svg = ''; +echo ""; +echo ""; +echo ""; + +$green_grand_total += $green_total; +$yellow_grand_total += $yellow_total; +$red_grand_total += $red_total; +$blue_grand_total += $blue_total; +$grand_total += $region_total; +} // fin des régions + +echo ""; + +# total operating systems +$query = "SELECT COUNT(*) FROM `".$table_item."` + LEFT JOIN `glpi_computers_items` + ON (`glpi_computers_items`.`itemtype` = '".$itemtype."' + AND `glpi_computers_items`.`items_id` = `".$table_item."`.`id`) + WHERE `".$table_item."`.`is_deleted` = '0' + AND `".$table_item."`.`is_template` = '0' ". + getEntitiesRestrictRequest("AND", $table_item); +$result = $DB->query($query); +$total = $DB->result($result, 0, 0); + +$green_svg = ''; +$yellow_svg = ''; +$red_svg = ''; +$blue_svg = ''; +echo ""; +echo ""; +echo ""; + + +/* requête last updated computers +$query = "SELECT `last_fusioninventory_update`, `computers_id` + FROM `glpi_plugin_fusioninventory_inventorycomputercomputers` + LEFT JOIN `glpi_computers` ON `computers_id`=`glpi_computers`.`id` +WHERE ((NOW() > ADDDATE(last_fusioninventory_update, INTERVAL ".$nbdays." DAY) + OR last_fusioninventory_update IS NULL) + ".$state_sql.")".getEntitiesRestrictRequest("AND", "glpi_computers")." + ORDER BY last_fusioninventory_update DESC"; +$result = $DB->query($query); + +echo "
ImplantationSystèmes d'exploitationQtt
$region_name
  ".getTreeValueCompleteName("glpi_entities", $id)."
  ".$data['ename']."".$oname_plus." ".$data['oname']."".$data['count']."
  Sous-total".$green_svg.$yellow_svg.$red_svg.$blue_svg."$region_total
 
Total général".$green_svg.$yellow_svg.$red_svg.$blue_svg."$total
"; + +echo ""; +echo ""; +echo ""; + +echo ""; +echo ""; +echo ""; +echo ""; +echo ""; +echo ""; + +while ($data=$DB->fetch_array($result)) { + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; +} +*/ + +echo "
".__('Number of items')." : ".$DB->numrows($result)."
".__('Name')."".__('Last inventory')."".__('Serial Number')."".__('Inventory number')."
"; + $computer->getFromDB($data['computers_id']); + echo $computer->getLink(1); + echo "".Html::convDateTime($data['last_fusioninventory_update'])."".$computer->fields['serial']."".$computer->fields['otherserial']."
"; + +/* +echo ' + + + + '; +echo ' + + + Hello World + From Embedded SVG! + + '; +*/ + +Html::footer(); + +?> diff --git a/glpi-plugin-auf/plugin/setup.php b/glpi-plugin-auf/plugin/setup.php new file mode 100644 index 0000000..829e1b4 --- /dev/null +++ b/glpi-plugin-auf/plugin/setup.php @@ -0,0 +1,57 @@ +isActivated('auf')) { // check if plugin is active + if (Session::getLoginUserID()) { + $PLUGIN_HOOKS['add_css']['auf'] = "auf.css"; + } + if (isset($_SESSION["glpiname"])) { + $report_list = array(); + if (Session::haveRight("computer", "r")) { + $report_list["report.operatingsystems.php"] = "Systèmes d'exploitation par implantation"; + $report_list["report.wip.php"] = 'WIP (rapport en cours de développement)'; + } + $PLUGIN_HOOKS['reports']['auf'] = $report_list; + } + } +} + +// Get the name and the version of the plugin - Needed +function plugin_version_auf() { + return array( + 'name' => 'AUF', + 'version' => '0.1.0', + 'author' => 'Jean Christophe André', + 'license' => 'GPLv2+', + 'homepage' => 'http://git.auf.org/?p=glpi', + 'minGlpiVersion' => '0.84');// For compatibility / no install in version < 0.80 +} + +// Optional : check prerequisites before install : may print errors or add to message after redirect +function plugin_auf_check_prerequisites() { + if (version_compare(GLPI_VERSION,'0.84','lt') || version_compare(GLPI_VERSION,'0.85','ge')) { + _e('This plugin requires GLPI >= 0.84', 'auf'); + return FALSE; + } + return TRUE; +} + +// Uninstall process for plugin : need to return true if succeeded : may display messages or add to message after redirect +function plugin_auf_check_config() { + return TRUE; +} + +function plugin_auf_haveRight($module,$right) { + return TRUE; +} +?> -- 1.7.10.4