From 352fa0a51d5310d0b4a20dd25cb09f91edb18ba7 Mon Sep 17 00:00:00 2001 From: Debug Bill Date: Mon, 25 Sep 2017 09:35:04 +0200 Subject: [PATCH] Almost ready for version 0.1.0. Just some more testing --- hook.php | 21 ++- inc/computer.class.php | 204 +++++++++++------------- inc/config.class.php | 343 +++++++++++++++++++++-------------------- inc/crontask.class.php | 191 ++++++++++++----------- inc/mdt.class.php | 106 ++++++++++++- locales/en_US.mo | Bin 3157 -> 3737 bytes locales/en_US.po | 153 +++++++++--------- locales/fr_FR.mo | Bin 3543 -> 4078 bytes locales/fr_FR.po | 154 +++++++++--------- locales/glpi2mdt.pot | 130 +++++++++------- setup.php | 4 +- 11 files changed, 733 insertions(+), 573 deletions(-) diff --git a/hook.php b/hook.php index 6c48e75..7a752f5 100644 --- a/hook.php +++ b/hook.php @@ -33,6 +33,7 @@ */ function plugin_glpi2mdt_install() { global $DB; + $dbversion = 1; // Global plugin settings if (!TableExists("glpi_plugin_glpi2mdt_parameters")) { @@ -52,7 +53,7 @@ function plugin_glpi2mdt_install() { $query = "INSERT INTO `glpi_plugin_glpi2mdt_parameters` (`id`, `parameter`, `scope`, `value_num`, `is_deleted`) - VALUES (1, 'database_version', 'global', 1, false)"; + VALUES (1, 'DBVersion', 'global', $dbversion, false)"; $DB->query($query) or die("error updating glpi_plugin_glpi2mdt_parameters ". $DB->error()); } @@ -69,7 +70,7 @@ function plugin_glpi2mdt_install() { KEY `is_in_sync` (`is_in_sync`), KEY `type` (`type`), KEY `category` (`category`) - ) ENGINE=MyISAM AUTO_INCREMENT=34 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; + ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die("error creating glpi_plugin_glpi2mdt_settings ". $DB->error()); } @@ -240,6 +241,21 @@ function plugin_glpi2mdt_install() { CronTask::Register('PluginGlpi2mdtCrontask', 'expireOSInstallFlag', 300, array('mode' => 2, 'allowmode' => 3, 'logs_lifetime' => 30, 'comment' => 'Daily task checking for updates')); + + // Update database if necessary + $DB->query("UPDATE glpi_plugin_glpi2mdt_parameters SET parameter='DBVersion' WHERE scope='global' AND parameter='database_version';"); + $result = $DB->query("SELECT sum(value_num) as version FROM glpi_plugin_glpi2mdt_parameters WHERE scope='global' AND parameter='DBVersion'"); + if ($DB->numrows($result) == 0) { + die(__("Glpi2mdt database is corrupted. Please uninstall and reinstall the plugin", 'glpi2mdt')); + } + if ($DB->numrows($result) == 1) { + $currentdbversion = $DB->fetch_array($result)['version']; + } + + // Upgrade to version 2 of the database + if ($currentdbversion == 1) { + return true; + } return true; } @@ -263,6 +279,7 @@ function plugin_glpi2mdt_uninstall() { return true; } + /** * This function is called by GLPI when an update is made to a computer * It triggers an update of MDT just in case... diff --git a/inc/computer.class.php b/inc/computer.class.php index 01fa121..5c92d5a 100644 --- a/inc/computer.class.php +++ b/inc/computer.class.php @@ -47,10 +47,18 @@ class PluginGlpi2mdtComputer extends PluginGlpi2mdtMdt { /** * This function is called from GLPI to allow the plugin to insert one or more items * inside the left menu of a Itemtype. + * + * While we're there, if in Master-Master mode, update computer data just in case */ function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { global $DB; $id = $item->getID(); + $result = $DB->query("SELECT value_char as mode FROM glpi_dev.glpi_plugin_glpi2mdt_parameters + WHERE scope='global' AND parameter='Mode';"); + $mode = $DB->fetch_array($result)['mode']; + if ($mode == 'Master') { + PluginGlpi2mdtCrontask::cronSyncMasterMaster(null, $id); + } $result = $DB->query("SELECT value FROM glpi_plugin_glpi2mdt_settings WHERE type='C' AND category='C' AND `key`='OSInstall' AND id=$id"); $row = $DB->fetch_array($result); @@ -77,11 +85,8 @@ function updateValue($post) { return false; } - // Build array of valid parameters for post variables - $result = $DB->query("SELECT column_name FROM glpi_plugin_glpi2mdt_descriptions WHERE is_deleted=false"); - while ($line = $DB->fetch_array($result)) { - $parameters[$line['column_name']] = true; - } + // Build array of valid variables for post variables + $variables = $this->globalconfig['variables']; if (isset($post['id']) and ($post['id'] > 0)) { $id = $post['id']; @@ -89,12 +94,12 @@ function updateValue($post) { // Delete all computer configuration entries $DB->queryOrDie("DELETE FROM glpi_plugin_glpi2mdt_settings WHERE id=$id and type='C'"); foreach ($post as $key=>$value) { - // only valid parameters may be inserted. The full list is in the "descriptions" database - if (isset($parameters[$key])) { + // only valid variables may be inserted. The full list is in the "descriptions" database + if (isset($variables[$key])) { $query = "INSERT INTO glpi_plugin_glpi2mdt_settings - (`id`, `category`, `type`, `key`, `value`) - VALUES ($id, 'C','C', '$key', '$value') - ON DUPLICATE KEY UPDATE value='$value'"; + (`id`, `category`, `type`, `key`, `value`, `is_in_sync`) + VALUES ($id, 'C','C', '$key', '$value', true) + ON DUPLICATE KEY UPDATE value='$value', is_in_sync=true"; $DB->queryOrDie($query, "Cannot update settings database"); } // Applications @@ -102,28 +107,29 @@ function updateValue($post) { $guid = substr($key, 4, strlen($key)-4); $apprank += 1; $query = "INSERT INTO glpi_plugin_glpi2mdt_settings - (`id`, `category`, `type`, `key`, `value`) - VALUES ($id, 'A','C', '$guid', '$apprank') - ON DUPLICATE KEY UPDATE value='$apprank'"; + (`id`, `category`, `type`, `key`, `value`, `is_in_sync`) + VALUES ($id, 'A','C', '$guid', '$apprank', true) + ON DUPLICATE KEY UPDATE value='$apprank', is_in_sync=true"; $DB->queryOrDie($query, "Cannot update application settings database"); } // Roles if ((substr($key, 0, 6) == 'Roles-') and ($value <> 'none') and ($value == 'on')) { $guid = substr($key, 6, strlen($key)-6); - $rolerank += 1; + $roles = $DB->query("SELECT role FROM glpi_plugin_glpi2mdt_roles WHERE id='$guid';"); + $role = $DB->fetch_array($roles)['role']; $query = "INSERT INTO glpi_plugin_glpi2mdt_settings - (`id`, `category`, `type`, `key`, `value`) - VALUES ($id, 'R','C', '$guid', '$rolerank') - ON DUPLICATE KEY UPDATE value='$rolerank'"; + (`id`, `category`, `type`, `key`, `value`, `is_in_sync`) + VALUES ($id, 'R','C', '$guid', '$role', true) + ON DUPLICATE KEY UPDATE value='$role', is_in_sync=true"; $DB->queryOrDie($query, "Cannot update roles settings database"); } if (($key == 'OSInstallExpire')) { $timestamp = strtotime($value); if ($timestamp > 0) { $query = "INSERT INTO glpi_plugin_glpi2mdt_settings - (`id`, `category`, `type`, `key`, `value`) - VALUES ($id, 'C','C', '$key', '$timestamp') - ON DUPLICATE KEY UPDATE value='$timestamp'"; + (`id`, `category`, `type`, `key`, `value`, `is_in_sync`) + VALUES ($id, 'C','C', '$key', '$timestamp', true) + ON DUPLICATE KEY UPDATE value='$timestamp', is_in_sync=true"; } $DB->query($query); } @@ -140,17 +146,26 @@ function updateValue($post) { */ function updateMDT($id) { global $DB; + $globalconfig = $this->globalconfig; // Only update if user has rights to do so. if (!PluginGlpi2mdtComputer::canUpdate()) { return false; } - // Build array of valid parameters - $result = $DB->query("SELECT column_name FROM glpi_plugin_glpi2mdt_descriptions WHERE is_deleted=false"); - while ($line = $DB->fetch_array($result)) { - $parameters[$line['column_name']] = true; - } + // Build array of valid variables + $variables = $this->globalconfig['variables']; + + //Get IDs to work on + $mdt = $this->getMdtIds($id); + $macs = $mdt['macs']; + $values = $mdt['values']; + $mdtids = $mdt['mdtids']; + $name = $mdt['name']; + $uuid = $mdt['uuid']; + $serial = $mdt['serial']; + $otherserial = $mdt['otherserial']; //asset tag + $nbrows = $mdt['nbrows']; // Build password according to rules if ($globalconfig['Complexity'] == 'Trivial') { @@ -161,94 +176,40 @@ function updateMDT($id) { $adminpasscomposite = $globalconfig['LocalAdmin']; } - $globalconfig = $this->globalconfig; - - // Get data for current computer - $result = $DB->query("SELECT name, uuid, serial, otherserial FROM glpi_computers WHERE id=$id AND is_deleted=false"); - $common = $DB->fetch_array($result); - - // Build list of IDs of existing records in MDT bearing same name, uuid, serial or mac adresses - // as the computer being updated (this might clean up other bogus entries and remove duplicate names - $uuid = $common['uuid']; - $name = $common['name']; - $serial = $common['serial']; - $assettag = $common['otherserial']; - - // Build list of mac addresses to search for - $result = $DB->queryOrDie("SELECT UPPER(n.mac) as mac - FROM glpi_computers c, glpi_networkports n - WHERE c.id=$id AND c.id=n.items_id AND itemtype='Computer' - AND n.instantiation_type='NetworkPortEthernet' AND n.mac<>'' - AND c.is_deleted=FALSE AND n.is_deleted=false"); - $macs="MacAddress IN ("; - unset($values); - $nblines = 0; - while ($line = $DB->fetch_array($result)) { - $mac = $line['mac']; - $macs=$macs."'".$mac."', "; - $values = $values."('$name', '$uuid', '$serial', '$assettag', '$mac'), "; - $nblines +=1; - } - // There should be one line per mac address in MDT, and at least one if no mac is provided. - if ($nblines == 0) { - $nblines = 1; - } - $macs = substr($macs, 0, -2).") "; - $values = substr($values, 0, -2)." "; - if ($macs == "MacAddress IN ()") { - $macs='false'; - $values= "('$name', '$uuid', '$serial', '$assettag', '')"; - } - // Get list of ids - $query = "SELECT ID FROM dbo.ComputerIdentity - WHERE (UUID<>'' AND UUID='$uuid') - OR (Description<>'' AND Description='$name') - OR (SerialNumber<>'' AND SerialNumber='$serial') - OR $macs"; - $result = $this->queryOrDie("$query", "Can't read IDs to delete"); - - // build a list of MDT IDs corresponding to the computer in GLPI (there can be several - // because of multiple mac addresses or duplicate names, serials.... - $ids = "ID IN ("; - while ($line = $this->fetch_array($result)) { - $ids=$ids."'".$line['ID']."', "; - } - $ids = substr($ids, 0, -2).")"; - if ($ids == "ID IN)") { - $ids="ID = ''"; - } // Check if the computer entries in MDT are the ones expected by GLPI. // If not, delete everything and recreate // If yes, depending on coupling mode, delete and recreate or simply update $query = ("SELECT ID FROM dbo.ComputerIdentity - WHERE (UUID='$uuid') AND Description='$name' AND SerialNumber='$serial' AND $macs"); + WHERE UUID='$uuid' AND Description='$name' AND SerialNumber='$serial' AND AssetTag='$otherserial' AND $macs"); $result = $this->query($query); - $nblinesactual = $this->numrows($result); - if ($nblines <> $nblinesactual) { - $this->queryOrDie("DELETE FROM dbo.ComputerIdentity WHERE $ids"); + $nbrowsactual = $this->numrows($result); + if ($nbrows <> $nbrowsactual) { + $this->queryOrDie("DELETE FROM dbo.ComputerIdentity WHERE $mdtids"); $this->queryOrDie("INSERT INTO dbo.ComputerIdentity (Description, UUID, SerialNumber, AssetTag, MacAddress) VALUES $values"); } // Delete corresponding records in side tables depending on coupling mode - if ($nblines <> $nblinesactual OR $globalconfig['Mode'] == 'Strict') { - $this->queryOrDie("DELETE FROM dbo.Settings WHERE Type='C' and $ids"); - $this->queryOrDie("DELETE FROM dbo.Settings_Applications WHERE Type='C' and $ids"); - $this->queryOrDie("DELETE FROM dbo.Settings_Administrators WHERE Type='C' and $ids"); - $this->queryOrDie("DELETE FROM dbo.Settings_Packages WHERE Type='C' and $ids"); - $this->queryOrDie("DELETE FROM dbo.Settings_Roles WHERE Type='C' and $ids"); + if (($nbrows <> $nbrowsactual) OR ($globalconfig['Mode'] == 'Strict')) { + $this->queryOrDie("DELETE FROM dbo.Settings WHERE Type='C' and $mdtids"); + $this->queryOrDie("DELETE FROM dbo.Settings_Applications WHERE Type='C' and $mdtids"); + $this->queryOrDie("DELETE FROM dbo.Settings_Administrators WHERE Type='C' and $mdtids"); + $this->queryOrDie("DELETE FROM dbo.Settings_Packages WHERE Type='C' and $mdtids"); + $this->queryOrDie("DELETE FROM dbo.Settings_Roles WHERE Type='C' and $mdtids"); } // Retreive (newly created or not) entries ids in order to add the settings. - //Name is enough as we cleaned bogus entries in the previous phase - $query = "SELECT ID FROM dbo.ComputerIdentity WHERE Description='$name'"; - $result = $this->queryOrDie($query); - $ids = "("; - - while ($row = $this->fetch_array($result)) { - $mdtid = $row['ID']; - $ids = $ids.$row['ID'].", "; - $arrayid[$row['ID']] = $row['ID']; + $mdt = $this->getMdtIds($id); + $macs = $mdt['macs']; + $mdtids = $mdt['mdtids']; + $arraymdtids = $mdt['arraymdtids']; + $name = $mdt['name']; + $uuid = $mdt['uuid']; + $serial = $mdt['serial']; + $otherserial = $mdt['otherserial']; //asset tag + $nbrows = $mdt['nbrows']; + + foreach ($arraymdtids as $mdtid) { $values = "('C', $mdtid, '$name', '$name', '$name', '$adminpasscomposite') "; // Check if settings line does exist already. Insert if not, update if yes - // (because "on duplicate" does not exist in MS-SQL + // (because "on duplicate" does not exist in MS-SQL) $exists = $this->queryOrDie("SELECT ID FROM dbo.Settings WHERE Type='C' AND ID=$mdtid;"); if ($this->numrows($exists) == 1) { $query = "UPDATE dbo.Settings SET ComputerName='$name', OSDComputerName='$name', FullName='$name', AdminPassword='$adminpasscomposite' @@ -258,17 +219,19 @@ function updateMDT($id) { } $this->queryOrDie($query); } - $ids = substr($ids, 0, -2).") "; - // Update settings with additional parameters + // Update settings with additional variables $query = "SELECT `key`, `value` FROM glpi_plugin_glpi2mdt_settings WHERE id=$id AND category='C' AND type='C';"; - $result = $DB->queryOrDie($query, "Cannot select additional parameters.
"); + $result = $DB->queryOrDie($query, "Cannot select additional variables.
"); while ($pair = $DB->fetch_array($result)) { $key = $pair['key']; $value = $pair['value']; - $query = "UPDATE dbo.Settings SET $key='$value' WHERE ID IN $ids;"; + if ($value == '*undef*') { + $value=''; + } + $query = "UPDATE dbo.Settings SET $key='$value' WHERE $mdtids;"; // Check if key is a valid field for database "settings" - if ($parameters[$key]) { + if ($variables[$key]) { $this->queryOrDie("$query"); } } @@ -278,7 +241,8 @@ function updateMDT($id) { while ($pair = $DB->fetch_array($result)) { $key = $pair['key']; $value = $pair['value']; - foreach ($arrayid as $mdtid) { + reset($arraymdtids); + foreach ($arraymdtids as $mdtid) { // GLPI2MDT does not manage ranks, so keep the existing one if any $ranks = $this->queryOrDie("SELECT Sequence FROM dbo.Settings_Applications WHERE ID=$mdtid AND type='C' AND Applications='$key';"); if ($this->numrows($ranks) == 0) { @@ -293,12 +257,16 @@ function updateMDT($id) { while ($pair = $DB->fetch_array($result)) { $key = $pair['key']; $value = $pair['value']; - foreach ($arrayid as $mdtid) { + reset($arraymdtids); + foreach ($arraymdtids as $mdtid) { // GLPI2MDT does not manage ranks, so keep the existing one if any - $ranks = $this->queryOrDie("SELECT Sequence FROM dbo.Settings_Roles WHERE ID=$mdtid AND type='C' AND Role='$key';"); + $rank = $this->queryOrDie("SELECT Sequence FROM dbo.Settings_Roles WHERE ID=$mdtid AND type='C' AND Role='$value';"); if ($this->numrows($ranks) == 0) { + // Add after existing roles in MDT, mainly for loose and master coupling modes + $next = $this->queryOrDie("SELECT ISNULL(MAX(Sequence),0)+1 as next FROM dbo.Settings_Roles WHERE ID=$mdtid AND type='C';"); + $rank = $this->fetch_array($next)['next']; $this->queryOrDie("INSERT INTO dbo.Settings_Roles (Type, ID, Sequence, Role) - VALUES ('C', '$mdtid', $value, '$key');"); + VALUES ('C', '$mdtid', '$rank', '$value');"); } } } @@ -352,6 +320,7 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtempl echo ""; $yesno['YES'] = __('YES', 'glpi2mdt'); $yesno['NO'] = __('NO', 'glpi2mdt'); + $yesno['*undef*'] = __('Default', 'glpi2mdt'); Dropdown::showFromArray("OSInstall", $yesno, array( 'value' => "$osinstall") @@ -403,7 +372,7 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtempl // Roles - $query = "SELECT id as id, role FROM glpi_plugin_glpi2mdt_roles + $query = "SELECT id, role FROM glpi_plugin_glpi2mdt_roles WHERE is_deleted=false"; $result = $DB->query($query); while ($row = $DB->fetch_assoc($result)) { @@ -422,6 +391,19 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtempl echo ''; echo ''; echo ''; + + // Plugin version check + $currentversion = PLUGIN_GLPI2MDT_VERSION; + $version = $DB->query("SELECT value_char FROM glpi_plugin_glpi2mdt_parameters WHERE parameter='LAtestVersion' AND scope='global'"); + if ($DB-numrows == 1) { + $latestversion = $DB->fetch_array($version)['value_char']; + } + if (version_compare($currentversion, $latestversion, '<')) { + echo "
"; + echo sprintf(__('A new version of plugin glpi2mdt is available: v%s', 'glpi2mdt'), $latestversion); + echo "
"; + } + echo ''; echo ''; } diff --git a/inc/config.class.php b/inc/config.class.php index bdfeb2d..cbf1915 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -38,202 +38,205 @@ class PluginGlpi2mdtConfig extends PluginGlpi2mdtMdt { /** - * The right name for this class - * - * @var string - */ + * The right name for this class + * + * @var string + */ static $rightname = 'config'; /** - * Store configuration parameters - * - * @param $key string: global parameter name to be checked against validkeys array - * - * @param $value string or number: corresponding value for the parameter - * - * @return nothing but dies if failing to write into the database + * Store configuration parameters + * + * @param $key string: global parameter name to be checked against validkeys array + * + * @param $value string or number: corresponding value for the parameter + * + * @return nothing but dies if failing to write into the database **/ function updateValue($key, $value) { global $DB; $validkeys = $this->validkeys; if ($validkeys[$key] == 'txt') { $query = "INSERT INTO glpi_plugin_glpi2mdt_parameters - (`parameter`, `scope`, `value_char`, `is_deleted`) - VALUES ('$key', 'global', '$value', false) - ON DUPLICATE KEY UPDATE value_char='$value', value_num=NULL, is_deleted=false"; + (`parameter`, `scope`, `value_char`, `is_deleted`) + VALUES ('$key', 'global', '$value', false) + ON DUPLICATE KEY UPDATE value_char='$value', value_num=NULL, is_deleted=false"; $DB->queryOrDie($query, "Database error"); } if ($validkeys[$key] == 'num' and ($value > 0 or $value == '')) { $query = "INSERT INTO glpi_plugin_glpi2mdt_parameters - (`parameter`, `scope`, `value_num`, `is_deleted`) - VALUES ('$key', 'global', '$value', false) - ON DUPLICATE KEY UPDATE value_num='$value', value_char=NULL, is_deleted=false"; + (`parameter`, `scope`, `value_num`, `is_deleted`) + VALUES ('$key', 'global', '$value', false) + ON DUPLICATE KEY UPDATE value_num='$value', value_char=NULL, is_deleted=false"; $DB->queryOrDie($query, "Database error"); } } /** - * Shows form to set plugin configuration parameters - * - * @param none - * - * @return outputs HTML form + * Shows form to set plugin configuration parameters + * + * @param none + * + * @return outputs HTML form **/ function show() { $yesno['YES'] = __('YES', 'glpi2mdt'); $yesno['NO'] = __('NO', 'glpi2mdt'); + ?> +
+ Session::getNewCSRFToken())); ?> +
+ + + + + + + + '; + echo "'; + echo ''; + } + ?> + + + + + + + + + + + + + + + + + "; + ?> + + + "; ?> - - Session::getNewCSRFToken())); ?> -
-
+ :     + + globalconfig['DBServer'].'" size="50" class="ui-autocomplete-input" + autocomplete="off" required pattern="[a-Z0-9.]" placeholder="myMDTserver.mydomain.local">    ' ?> +
+ :     + + globalconfig['DBPort'].'" size="5" class="ui-autocomplete-input" + autocomplete="off" inputmode="numeric" placeholder="1433" min="1024" max="65535" required>    ' ?> +
"; + echo __('ODBC Driver name', 'glpi2mdt'); + echo ' :    '; + echo ''; + echo '    '; + echo '
+ :     + + globalconfig['DBLogin'].'" size="50" class="ui-autocomplete-input" + autocomplete="off" required pattern="[a-Z0-9]">    ' ?> +
+ :     + + globalconfig['DBPassword'].'" size="50" class="ui-autocomplete-input" + autocomplete="off" required>    ' ?> +
+ :     + + globalconfig['DBSchema'].'" size="50" class="ui-autocomplete-input" + autocomplete="off" required pattern="[a-Z0-9]" placeholder="MDT">    ' ?> +
+ :     + + globalconfig['FileShare'].'" size="50" class="ui-autocomplete-input" + autocomplete="off" required placeholder="/mnt/smb-share/Deployment-share/Control">    ' ?> +
+ :     + + globalconfig['LocalAdmin'].'" size="50" class="ui-autocomplete-input" + autocomplete="off" required>    ' ?> +
+ "; + Dropdown::showFromArray("Complexity", array( + 'Basic' => __('Same password on all machines', 'glpi2mdt'), + 'Trivial' => __('Password is hostname', 'glpi2mdt'), + 'Unique' => __('append \'-%hostname%\' to password', 'glpi2mdt')), array( + 'value' => $this->globalconfig['Complexity']) + ); + echo "
+ "; + Dropdown::showFromArray("Mode", array( + 'Strict' => __('Strict Master-Slave', 'glpi2mdt'), + 'Loose' => __('Loose Master-Slave', 'glpi2mdt'), + 'Master' => __('Master-Master', 'glpi2mdt')), array( + 'value' => $this->globalconfig['Mode'])); + echo "
- - - - - - - '; - echo "'; - echo ''; - } - ?> - - - - - - - - - - - - - - - - - "; - ?> - - - "; - ?> - - - "; - ?> - - - '; - echo ''; - if (PluginGlpi2mdtConfig::canUpdate()) { - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
- :     - - globalconfig['DBServer'].'" size="50" class="ui-autocomplete-input" - autocomplete="off" required pattern="[a-Z0-9.]" placeholder="myMDTserver.mydomain.local">    ' ?> -
- :     - - globalconfig['DBPort'].'" size="5" class="ui-autocomplete-input" - autocomplete="off" inputmode="numeric" placeholder="1433" min="1024" max="65535" required>    ' ?> -
"; - echo __('ODBC Driver name', 'glpi2mdt'); - echo ' :    '; - echo ''; - echo '    '; - echo '
- :     - - globalconfig['DBLogin'].'" size="50" class="ui-autocomplete-input" - autocomplete="off" required pattern="[a-Z0-9]">    ' ?> -
- :     - - globalconfig['DBPassword'].'" size="50" class="ui-autocomplete-input" - autocomplete="off" required>    ' ?> -
- :     - - globalconfig['DBSchema'].'" size="50" class="ui-autocomplete-input" - autocomplete="off" required pattern="[a-Z0-9]" placeholder="MDT">    ' ?> -
- :     - - globalconfig['FileShare'].'" size="50" class="ui-autocomplete-input" - autocomplete="off" required placeholder="/mnt/smb-share/Deployment-share/Control">    ' ?> -
- :     - - globalconfig['LocalAdmin'].'" size="50" class="ui-autocomplete-input" - autocomplete="off" required>    ' ?> -
- "; - Dropdown::showFromArray("Complexity", array( - 'Basic' => __('Same password on all machines', 'glpi2mdt'), - 'Trivial' => __('Password is hostname', 'glpi2mdt'), - 'Unique' => __('append \'-%hostname%\' to password', 'glpi2mdt')), array( - 'value' => $this->globalconfig['Complexity']) - ); - echo "
- "; - Dropdown::showFromArray("Mode", array( - 'Strict' => __('Strict Master-Slave', 'glpi2mdt'), - 'Loose' => __('Loose Master-Slave', 'glpi2mdt'), - 'Master' => __('Master-Master', 'glpi2mdt')), array( - 'value' => $this->globalconfig['Mode'])); - echo "
- "; - Dropdown::showFromArray("CheckNewVersion", $yesno, - array('value' => $this->globalconfig['CheckNewVersion']) - ); - echo "
- "; - Dropdown::showFromArray("ReportUsage", $yesno, - array('value' => $this->globalconfig['ReportUsage']) - ); - echo '
'; - echo ''; - echo ''; - echo ''; - echo '
'; - echo ''; - echo ''; - echo ''; - echo '
'; - echo '
'; - echo '
'; - // Show alert if a new version is available - $currentversion = PLUGIN_GLPI2MDT_VERSION; - $latestversion = $this->globalconfig['LatestVersion']; - if (version_compare($currentversion, $latest_version, '<')) { - sprintf(__('A new version of plugin glpi2mdt is available: v%s'), $latestversion); - } - return true; + + + + "; + Dropdown::showFromArray("CheckNewVersion", $yesno, + array('value' => $this->globalconfig['CheckNewVersion']) + ); + echo ""; + ?> + + + + "; + Dropdown::showFromArray("ReportUsage", $yesno, + array('value' => $this->globalconfig['ReportUsage']) + ); + echo ''; + echo ''; + if (PluginGlpi2mdtConfig::canUpdate()) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo ''; + echo ''; + echo ''; + + // Show alert if a new version is available + $currentversion = PLUGIN_GLPI2MDT_VERSION; + $latestversion = $this->globalconfig['LatestVersion']; + if (version_compare($currentversion, $latestversion, '<')) { + echo "
"; + echo sprintf(__('A new version of plugin glpi2mdt is available: v%s', 'glpi2mdt'), $latestversion); + echo "
"; + } + return true; } } diff --git a/inc/crontask.class.php b/inc/crontask.class.php index 4a010d4..fa84de9 100644 --- a/inc/crontask.class.php +++ b/inc/crontask.class.php @@ -38,27 +38,30 @@ /** - * Glpi2mdtcrontasks class + * Glpi2mdtcrontask class **/ class PluginGlpi2mdtCronTask extends PluginGlpi2mdtMdt { /** - * Check if new version is available - * - * @param $auto boolean: check done by cron ? (if not display result) - * (default true) - * @param $messageafterredirect boolean: use message after redirect instead of display - * (default false) - * - * @return string explaining the result + * Check if new version is available + * + * @param $auto boolean: check done by cron ? (if not display result) + * (default true) + * @param $messageafterredirect boolean: use message after redirect instead of display + * (default false) + * + * @return integer if started in cron mode. Outputs HTML data otherwise + * >0 : done + * <0 : to be run again (not finished) + * 0 : nothing to be done **/ static function cronCheckGlpi2mdtUpdate($task, $cron=true, $messageafterredirect=false) { $currentversion = PLUGIN_GLPI2MDT_VERSION; global $DB; - // if (!$auto - // && !Session::haveRight('backup', Backup::CHECKUPDATE)) { - // return false; - // } + + // if (!$cron && !Session::haveRight('backup', Backup::CHECKUPDATE)) { + // return false; + // } //parse github releases (get last version number) $error = ""; @@ -74,14 +77,14 @@ static function cronCheckGlpi2mdtUpdate($task, $cron=true, $messageafterredirect $latest_version = array_pop($released_tags); // Did we get something? Maybe not if the server has no internet access... if (strlen(trim($latest_version)) == 0) { - if (!$auto) { + if ($cron) { + $task->log($error); + } else { if ($messageafterredirect) { Session::addMessageAfterRedirect($error, true, ERROR); } else { - echo "
$error
"; + return $error; } - } else { - return $error; } } else { // Build a unique ID which will differentiate platforms (dev, prod..) behind the same public IP @@ -94,6 +97,7 @@ static function cronCheckGlpi2mdtUpdate($task, $cron=true, $messageafterredirect $query = "SELECT value_char FROM glpi_plugin_glpi2mdt_parameters WHERE is_deleted=false AND scope='global' AND parameter='ReportUsage'"; if ($DB->fetch_assoc($DB->query($query))['value_char'] == 'YES') { + $CO = $globalconfig['Mode']; $AP = $DB->fetch_row($DB->query("SELECT count(*) FROM glpi_plugin_glpi2mdt_applications WHERE is_deleted=false"))[0]; $AG = $DB->fetch_row($DB->query("SELECT count(*) FROM glpi_plugin_glpi2mdt_application_groups WHERE is_deleted=false"))[0]; $TS = $DB->fetch_row($DB->query("SELECT count(*) FROM glpi_plugin_glpi2mdt_task_sequences WHERE is_deleted=false"))[0]; @@ -102,50 +106,27 @@ static function cronCheckGlpi2mdtUpdate($task, $cron=true, $messageafterredirect $MO = $DB->fetch_row($DB->query("SELECT count(*) FROM glpi_plugin_glpi2mdt_models WHERE is_deleted=false"))[0]; $PK = 0; //$DB->fetch_row($DB->query("SELECT count(*) FROM glpi_plugin_glpi2mdt_packages WHERE is_deleted=false"))[0]; $ST = $DB->fetch_row($DB->query("SELECT count(*) FROM glpi_plugin_glpi2mdt_settings"))[0]; - $gets = $gets."&AP=$AP&AG=$AG&TS=$TS&TG=$TG&RO=$RO&MO=$MO&PK=$PK&ST=$ST"; + $gets = $gets."&CO=$CO&&AP=$AP&AG=$AG&TS=$TS&TG=$TG&RO=$RO&MO=$MO&PK=$PK&ST=$ST"; } Toolbox::getURLContent("https://glpi2mdt.thauvin.org/report.php".$gets); - $newversion = sprintf(__('A new version of plugin glpi2mdt is available: v%s'), $latest_version); - $uptodate = sprintf(__('You have the latest available version of glpi2mdti: v%s'), $latest_version); - $repository = __('You will find it on GitHub.com.'); + $task->log("https://glpi2mdt.thauvin.org/report.php".$gets); $query = "INSERT INTO glpi_plugin_glpi2mdt_parameters (`parameter`, `scope`, `value_char`, `is_deleted`) VALUES ('LatestVersion', 'global', '$latest_version', false) ON DUPLICATE KEY UPDATE value_char='$latest_version', value_num=NULL, is_deleted=false"; $DB->queryOrDie($query, "Database error"); if (version_compare($currentversion, $latest_version, '<')) { - - if (!$auto) { - if ($messageafterredirect) { - Session::addMessageAfterRedirect($newversion); - Session::addMessageAfterRedirect($repository); - } else { - echo "
".$newversion."
"; - echo "
".$repository."
"; - } - - } else { - if ($messageafterredirect) { - Session::addMessageAfterRedirect($newversion); - } else { - return $newversion; - } - } - + $message = sprintf(__('A new version of plugin glpi2mdt is available: v%s'), $latest_version); } else { - if (!$auto) { - if ($messageafterredirect) { - Session::addMessageAfterRedirect($uptodate); - } else { - echo "
".$uptodate."
"; - } - + $message = sprintf(__('You have the latest available version of glpi2mdti: v%s'), $latest_version); + } + if ($cron) { + $task->log($message); + } else { + if ($messageafterredirect) { + Session::addMessageAfterRedirect($message); } else { - if ($messageafterredirect) { - Session::addMessageAfterRedirect($uptodate); - } else { - return $uptodate; - } + return $message; } } } @@ -429,15 +410,78 @@ function cronUpdateBaseconfigFromMDT($task, $cron=true) { /** * Task to synchronize data between MDT and GLPI in Master-Master mode + * Can be used atomically to update one machine, or globally by cron * * @param $task Object of CronTask class for log / stat + * @param $id; computer ID to update * * @return integer * >0 : done * <0 : to be run again (not finished) * 0 : nothing to be done */ - static function cronSyncMasterMaster($task) { + static function cronSyncMasterMaster($task, $id=0) { + global $DB; + $MDT = new PluginGlpi2mdtMdt; + $globalconfig = $MDT->globalconfig; + if ($globalconfig['Mode'] <> "Master") { + $task->log("This cron task runs only in Master-Master mode"); + return 0; + } + // Build array of valid variables + $variables = $globalconfig['variables']; + if ($id > 0) { + $mdt = $MDT->getMdtIds($id); + $mdtids = "AND c.".$mdt['mdtids']; + $arraymdtids = $mdt['arraymdtids']; + } + + //GET all computers and settings + $query="SELECT * FROM dbo.ComputerIdentity c, dbo.Settings s WHERE c.id=s.id $mdtids"; + $result = $MDT->queryOrDie($query, "Cannot retreive computers from MDT"); + if (isset($task)) { + $task->setVolume($MDT->numrows($result)); + $task->log("Computer entries found in MDT database"); + } + $correspondances = 0; + $fields = 0; + $previousid = 0; + while ($row = $MDT->fetch_array($result)) { + // Find correspondance in GLPI + $query = "SELECT c.id as id FROM glpi_computers c, glpi_networkports n + WHERE c.id=n.items_id AND n.itemtype='Computer' AND n.instantiation_type='NetworkPortEthernet' + AND c.is_deleted=FALSE AND n.is_deleted=false AND c.name = '".$row['Description']."' + AND UPPER(n.mac)='".$row['MacAddress']."' AND serial='".$row['SerialNumber']."' AND otherserial='". + $row['AssetTag']."' AND uuid='".$row['UUID']."' ORDER BY c.id"; + $glpi = $DB->queryOrDie($query, "Can't find correspondance in GLPI"); + if ($DB->numrows($glpi) == 1) { + $array = $DB->fetch_array($glpi); + $id = $array['id']; + // Mark settings that may have to be deleted only if first iteration on this computer + if ($previousid<>$id) { + $DB->query("UPDATE glpi_plugin_glpi2mdt_settings SET is_in_sync=false WHERE type='C' AND category='C' AND id=$id"); + } + $previousid = $id; + $correspondances += 1; + // Update GLPI with data from MDT + foreach ($row as $key=>$value) { + if (isset($variables[$key]) AND $value <>'' AND $value<>null) { + $DB->queryOrDie("INSERT INTO glpi_plugin_glpi2mdt_settings (ID, type, category, `key`, `value`, `is_in_sync`) + VALUES ($id, 'C', 'C', '$key', '$value', true) + ON DUPLICATE KEY UPDATE `key`='$key', value='$value', is_in_sync=true;", "Can't insert setting"); + $fields += 1; + } + } + $DB->query("DELETE FROM glpi_plugin_glpi2mdt_settings WHERE type='C' AND category='C' AND is_in_sync=false AND id=$id"); + } + } + if (isset($task)) { + $task->setVolume($correspondances); + $task->log("computers updated in GLPI"); + $task->setVolume($fields); + $task->log("settings updated in GLPI"); + return 1; + } return 0; } @@ -469,50 +513,15 @@ function cronExpireOSInstallFlag($task) { while ($row=$DB->fetch_array($result)) { $nb += 1; $id = $row['id']; - - // Get data for current computer - $query = "SELECT name, uuid, serial, otherserial FROM glpi_computers WHERE id=$id AND is_deleted=false"; - $result = $DB->query($query) or $task->log("Database error: ". $DB->error()."

".$query); - $common = $DB->fetch_array($result); - - // Build list of IDs of existing records in MDT bearing same name, uuid, serial or mac adresses - // as the computer being updated (this might clean up other bogus entries and remove duplicate names - $uuid = $common['uuid']; - $name = $common['name']; - $serial = $common['serial']; - $assettag = $common['otherserial']; - - // Build list of mac addresses to search for - $result = $DB->query("SELECT UPPER(n.mac) as mac - FROM glpi_computers c, glpi_networkports n - WHERE c.id=$id AND c.id=n.items_id AND itemtype='Computer' - AND n.instantiation_type='NetworkPortEthernet' AND n.mac<>'' - AND c.is_deleted=FALSE AND n.is_deleted=false") - or $task->log("Database error: ". $DB->error()."

".$query); - $macs="MacAddress IN ("; - unset($values); - while ($line = $DB->fetch_array($result)) { - $mac = $line['mac']; - $macs=$macs."'".$mac."', "; - } - $macs = substr($macs, 0, -2).") "; - if ($macs == "MacAddress IN ()") { - $macs='false'; - } + $ids = $this->GetMdtIDs($id); // Cancel installation flag directly into MDT and MSSQL - $query = "UPDATE dbo.Settings - SET OSInstall='NO' - FROM dbo.ComputerIdentity i, dbo.Settings s - WHERE i.id=s.id AND s.type='C' - AND ((UUID<>'' AND UUID='$uuid') - OR (Description<>'' AND Description='$name') - OR (SerialNumber<>'' AND SerialNumber='$serial') - OR $macs)"; + $query = "UPDATE dbo.Settings SET OSInstall='' + FROM dbo.Settings WHERE type='C' AND ".$ids['mdtids'].";"; $MDT->query($query) or $task->log("Can't reset OSInstall flag

".$query."

".$MDT->dberror()); // Do the same now on GLPI database $query = "DELETE FROM glpi_plugin_glpi2mdt_settings WHERE type='C' AND category='C' - AND id=$id AND (`key`='OSInstall' OR `key`='OSInstallExpire');"; + AND id=$id AND ((`key`='OSInstall' AND values='YES') OR `key`='OSInstallExpire');"; $DB->query($query) or $task->log("Database error: ". $DB->error()."

".$query); } $task->log('record(s) expired'); diff --git a/inc/mdt.class.php b/inc/mdt.class.php index 9232991..b495b99 100644 --- a/inc/mdt.class.php +++ b/inc/mdt.class.php @@ -40,6 +40,7 @@ class PluginGlpi2mdtMdt extends CommonDBTM { // Post parameters valid for configuration form and their expected content protected $validkeys=array( + 'DBVersion' => 'txt', 'DBDriver' =>'txt', 'DBServer' => 'txt', 'DBLogin' => 'txt', @@ -51,7 +52,8 @@ class PluginGlpi2mdtMdt extends CommonDBTM { 'LocalAdmin' => 'txt', 'Complexity' => 'txt', 'CheckNewVersion' => 'txt', - 'ReportUsage' => 'txt' + 'ReportUsage' => 'txt', + 'LatestVersion' => 'txt' ); protected $globalconfig; protected $DBLink, $DBModule; @@ -80,6 +82,14 @@ function __construct() { } } } + + // Build array of valid variables + $result = $DB->query("SELECT column_name FROM glpi_plugin_glpi2mdt_descriptions WHERE is_deleted=false"); + while ($line = $DB->fetch_array($result)) { + $this->globalconfig['variables'][$line['column_name']] = true; + } + + // Shortcut variables $DBServer = $this->globalconfig['DBServer']; $DBPort = $this->globalconfig['DBPort']; $DBSchema = $this->globalconfig['DBSchema']; @@ -87,6 +97,12 @@ function __construct() { $DBPassword = $this->globalconfig['DBPassword']; $DBDriver = $this->globalconfig['DBDriver']; + // Plugin version check + $currentversion = PLUGIN_GLPI2MDT_VERSION; + if (version_compare($currentversion, $this->globalconfig['LatestVersion'], '<')) { + $this->globalconfig['newversion'] = sprintf(__('A new version of plugin glpi2mdt is available: v%s'), $latest_version); + } + // Connection to MSSQL using ODBC PHP module if (extension_loaded('odbc')) { $this->DBModule = 'odbc'; @@ -100,6 +116,7 @@ function __construct() { mssql_select_db($DBSchema, $MDT); } } + $this->DBLink = $DBLink; } @@ -237,4 +254,91 @@ function free_result($result) { return odbc_free_result($result); } } + + /** + * This function returns the list of computer IDs in MDT + * corresponding to one computer ID in GLPI (because a computer in GLPI can have 0 to N mac addresses + * when MDT has a 1 to 1 relationship on this item + * + * @param computer ID in GLPI + * + * @return array with three elements: macs, values, ids + * macs string, list of mac addresses ready to be included in a WHERE clause + * values string, list ready to be used in a "INSERT VALUES" clause + * ids string, list of IDs ready to be included in a WHERE clause + **/ + function getMdtIds(Computer $id) { + global $DB; + + // Get data for current computer + $query = "SELECT name, uuid, serial, otherserial FROM glpi_computers WHERE id=$id AND is_deleted=false"; + $result = $DB->query($query) or $task->log("Database error: ". $DB->error()."

".$query); + $common = $DB->fetch_array($result); + $uuid = $common['uuid']; + $name = $common['name']; + $serial = $common['serial']; + $otherserial = $common['otherserial']; // Asset Tag + + // Build list of mac addresses to search for + $result = $DB->query("SELECT UPPER(n.mac) as mac + FROM glpi_computers c, glpi_networkports n + WHERE c.id=$id AND c.id=n.items_id AND itemtype='Computer' + AND n.instantiation_type='NetworkPortEthernet' AND n.mac<>'' + AND c.is_deleted=FALSE AND n.is_deleted=false"); + $macs="MacAddress IN ("; + unset($values); + $nbrows = 0; + while ($line = $DB->fetch_array($result)) { + $mac = $line['mac']; + $macs=$macs."'".$mac."', "; + $values = $values."('$name', '$uuid', '$serial', '$otherserial', '$mac'), "; + $nbrows += 1; + } + // There should be one record per mac address in MDT, and at least one if no mac is provided. + if ($nbrows == 0) { + $nbrows = 1; + } + // $macs is a list of mac addresses ready to be included in a WHERE clause + $macs = substr($macs, 0, -2).") "; + + //$values is a list ready to be used in a "INSERT VALUES" clause + $values = substr($values, 0, -2)." "; + if ($macs == "MacAddress IN ()") { + // When no mac address is defined, don't match on MacAddress in WHERE clause. + $macs="MacAddress=''"; + $values= "('$name', '$uuid', '$serial', '$assettag', '')"; + } + + // Build list of IDs of existing records in MDT bearing same name, uuid, serial or mac adresses + // as the computer being updated (this might clean up other bogus entries and remove duplicate names) + // There can be several because of multiple mac addresses or duplicate names, serials.... + $query = "SELECT ID FROM dbo.ComputerIdentity + WHERE (UUID<>'' AND UUID='$uuid') + OR (Description<>'' AND Description='$name') + OR (SerialNumber<>'' AND SerialNumber='$serial') + OR (AssetTag<>'' AND AssetTag='$otherserial') + OR (MacAddress<>'' AND $macs);"; + $result = $this->queryOrDie("$query", "Can't read IDs"); + + $mdtids = "ID IN ("; + while ($line = $this->fetch_array($result)) { + $mtdid = $line['ID']; + $mdtids=$mdtids."'".$mtdid."', "; + $arraymdtids[$mtdid] = $mtdid; + } + $mdtids = substr($mdtids, 0, -2).")"; + if ($mdtids == "ID IN)") { + $mdtids="ID = ''"; + } + $mdt['macs'] = $macs; + $mdt['values'] = $values; + $mdt['mdtids'] = $mdtids; + $mdt['arraymdtids'] = $arraymdtids; + $mdt['name'] = $name; + $mdt['uuid'] = $uuid; + $mdt['serial'] = $serial; + $mdt['otherserial'] = $otherserial; //asset tag + $mdt['nbrows'] = $nbrows; + return $mdt; + } } diff --git a/locales/en_US.mo b/locales/en_US.mo index 1fe9f6b98e2bbbb1094e8da900363b48a8b29861..869a454930090bd1c4633d035d1c0e000da345f2 100644 GIT binary patch literal 3737 zcmeH|&x;&I6vs>R!#L3xOnl_4-iBUR0L53A$SnI2%aP-3HW{8J-dk{NRC2^ss2n= zbyvOjzOSl&*|YUMfii~rAnM0A2{8j6-hv0p#8x53!DHZUpr3Ocycg|r;34n>@J{dx zkiZ|oJ>bQhJGKdNH`@DhR=``(u7MAMb#Mo`0^R{ya2|XeEP>yFY}ciHd}_N851{=l zcq{0GJbxeD5556bz|TN@A})Yz&#&O^;6?Cea0`ss4Q>Z{{kOK};pS%*Ve0??U@~kk|PgWPknw4}x2;2#0nUBybeubr+m&5;02KVzLazK&dk4qIVV7vCh8#jwG3h@ zVL-O~Wsr4v6J#BJ0$GP`NCqCC2U&;HAnRa3j^8UF>+mkfI-CbNe!qci&mSPi=Mu;| z>_mfg*ahztix9z$LrgC{0ESA_!-1c{D}wK`!~os z?A(>*(XBfZ+S1VFGW<=g3CRq zY(M)nC>$TQk;|hQQrpV-&psm5sWzkF5Gohmqihdr&T(U(*iJ47P&o&}hGbuQzC7crD)onqn2I9bYfFm{&`4}Z^V(SH`)MP9Q74&yk9 zta3}V=qolh(Rpx4YL{X)XxX01gD>WFI}9QOkIh&-u{a2D8qN|esk4a(3n&QP#8=n( zIt9j@^$GFMKBv$<)5aX0^`!5?KsF!kR8r+qIhR0pye|B9#e%0-_**3w!nX8Dx&fje zNn=*S7{gcTL>Pj|S8JYK&&T0ikB~a9iu`arP|(-(WUTO}wsGi_3lG~ijQInoi)RSi z>e5&hJ568qmBrA?tm#F8?~lI*}JDykr|>uF|3Dh{NEQzKQe6e4Ry6Ir(r zBf?h0UZ6m>d!9~5;Z8Hl>ZYG>}nh|%6O%M7o8>5_xP;J-#cBKT5{?QXLgECG^+La(dQed zYJ~-)iPMUuHoim-RcYFnoZ79PO!^S>$-(jVw9R@-VcdP{aJni!*4+dt;k1+ts#Mcm zY>OThm$60QZ_~m+GeX6lwUMco%d4xaCCh7h9ko_Mrk4k^mn~*6<)ag0M~{@1esQ^3 z9x2r4>$T0ejFl>d83Y`;;tGwya89_8 zxJnaeJiB3dmD05eIG1ASJ9A+im?~+U>}ZGD7{~Evb=1+Z-CWI9Of1u_;B|H?{DJY1*qX!|0(4tG1E_>*rhw|_u zC>{kdC^{_a#poau9)yB25DEfMiid(uqTBbkGl38L&S&0nnD=>qGcL7$OXYtiy#=HC z7*`lGF|#q;D&s({m7CS#>&OjkWWJ3V+{ZdBViN1T&4zZcuw6{!7fj(Fyo^DWS%Gvr zQHg%1n_AYl15Om_Z_J?2b`@zqYDYIB@1r`OihPc0bRM;{x2Q%oP>Fs-CHgnIe!V74 z^fq$I9$;P%e8Pz$eSwN}1+~+!s0Q{?J3U54dV-4d47G3~2pdabj(I;S(Wj{AI8>uc zs6;oBP;4t8f8DUn1x31pTIdIACr7AAPcV%|)HjhPza|_*5-pVyq@Pl0aYd|B!)mru z6G{!VF_d(--oHw5tD{SrM5T^Z+M(h~Gt{g~i>u){Lk;&adKqd~rRG(7|2+()tj7OW z2PauZa*#t8qlKY=zw@P6!na~Wjz+_d+|oz~oQcPmB WugBbD@8P*ShRfVwJnJUn!~X#P*jcRr diff --git a/locales/en_US.po b/locales/en_US.po index 78516d7..45e4032 100644 --- a/locales/en_US.po +++ b/locales/en_US.po @@ -18,86 +18,76 @@ msgstr "" "Language: en_US\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -#: inc/mdt.class.php:137 -msgid "Testing connection using PHP module" +#: hook.php:249 +msgid "" +"Glpi2mdt database is corrupted. Please uninstall and reinstall the plugin" msgstr "" +"Glpi2mdt database is corrupted. Please uninstall and reinstall the plugin" + +#: setup.php:101 +msgid "Incompatible PHP Installation. Requires module mssql or module odbc" +msgstr "Incompatible PHP Installation. Requires module mssql or module odbc" + +#: setup.php:106 +msgid "Incompatible PHP Installation. Requires module" +msgstr "Incompatible PHP Installation. Requires module" + +#: setup.php:125 +msgid "Installed / not configured" +msgstr "Installed / not configured" + +#: inc/crontask.class.php:179 inc/crontask.class.php:216 +#: inc/crontask.class.php:262 inc/crontask.class.php:308 +#: inc/crontask.class.php:349 inc/crontask.class.php:395 +msgid "lines loaded into table" +msgstr "line(s) loaded into table" + +#: inc/crontask.class.php:187 inc/crontask.class.php:271 +#: inc/crontask.class.php:319 inc/crontask.class.php:358 +#: inc/crontask.class.php:406 +msgid "lines deleted from table" +msgstr "line's) deleted from table" + +#: inc/crontask.class.php:540 +msgid "Glpi2mdt Plugin" +msgstr "Glpi2mdt Plugin" -#: inc/mdt.class.php:141 +#: inc/mdt.class.php:154 +msgid "Testing connection using PHP module" +msgstr "Testing connection using PHP module" + +#: inc/mdt.class.php:158 msgid "Database login OK!" msgstr "Database login OK!" -#: inc/mdt.class.php:151 inc/config.class.php:140 +#: inc/mdt.class.php:168 inc/config.class.php:140 msgid "Schema" msgstr "Schema" -#: inc/mdt.class.php:151 +#: inc/mdt.class.php:168 msgid "contains" -msgstr "" +msgstr "contains" -#: inc/mdt.class.php:151 +#: inc/mdt.class.php:168 msgid "tables" -msgstr "" +msgstr "tables" -#: inc/mdt.class.php:155 +#: inc/mdt.class.php:172 msgid "Could not count tables in schema" -msgstr "" +msgstr "Could not count tables in schema" -#: inc/mdt.class.php:160 +#: inc/mdt.class.php:177 msgid "Database login KO!" msgstr "Database login KO!" -#: inc/computer.class.php:58 inc/computer.class.php:60 -msgid "Auto Install" -msgstr "Auto Install" - -#: inc/computer.class.php:347 -msgid "Automatic installation" -msgstr "Automatic installation" - -#: inc/computer.class.php:351 -msgid "Enable automatic installation" -msgstr "Enable automatic installation" - -#: inc/computer.class.php:353 inc/config.class.php:86 +#: inc/config.class.php:86 inc/computer.class.php:321 msgid "YES" msgstr "Yes" -#: inc/computer.class.php:354 inc/config.class.php:87 +#: inc/config.class.php:87 inc/computer.class.php:322 msgid "NO" msgstr "No" -#: inc/computer.class.php:363 -msgid "Reset after (empty for permanent):" -msgstr "Reset after (empty for permanent):" - -#: inc/computer.class.php:373 -msgid "Task sequence" -msgstr "Task sequence" - -#: inc/computer.class.php:402 -msgid "Applications" -msgstr "Applications" - -#: inc/computer.class.php:414 -msgid "Roles" -msgstr "Roles" - -#: inc/crontask.class.php:198 inc/crontask.class.php:235 -#: inc/crontask.class.php:281 inc/crontask.class.php:327 -#: inc/crontask.class.php:368 inc/crontask.class.php:414 -msgid "lines loaded into table" -msgstr "line(s) loaded into table" - -#: inc/crontask.class.php:206 inc/crontask.class.php:290 -#: inc/crontask.class.php:338 inc/crontask.class.php:377 -#: inc/crontask.class.php:425 -msgid "lines deleted from table" -msgstr "line's) deleted from table" - -#: inc/crontask.class.php:531 -msgid "Glpi2mdt Plugin" -msgstr "Glpi2mdt Plugin" - #: inc/config.class.php:95 msgid "Database server name" msgstr "Database server name" @@ -182,6 +172,43 @@ msgstr "Test connection" msgid "Initialise data" msgstr "Initialise data" +#: inc/config.class.php:236 inc/computer.class.php:403 +#, php-format +msgid "A new version of plugin glpi2mdt is available: v%s" +msgstr "A new version of plugin glpi2mdt is available: v%s" + +#: inc/computer.class.php:66 inc/computer.class.php:68 +msgid "Auto Install" +msgstr "Auto Install" + +#: inc/computer.class.php:315 +msgid "Automatic installation" +msgstr "Automatic installation" + +#: inc/computer.class.php:319 +msgid "Enable automatic installation" +msgstr "Enable automatic installation" + +#: inc/computer.class.php:323 +msgid "Default" +msgstr "Default" + +#: inc/computer.class.php:332 +msgid "Reset after (empty for permanent):" +msgstr "Reset after (empty for permanent):" + +#: inc/computer.class.php:342 +msgid "Task sequence" +msgstr "Task sequence" + +#: inc/computer.class.php:371 +msgid "Applications" +msgstr "Applications" + +#: inc/computer.class.php:383 +msgid "Roles" +msgstr "Roles" + #: front/computer.form.php:36 msgid "Features" msgstr "Features" @@ -189,15 +216,3 @@ msgstr "Features" #: front/config.form.php:36 msgid "Setup" msgstr "Setup" - -#: setup.php:101 -msgid "Incompatible PHP Installation. Requires module mssql or module odbc" -msgstr "Incompatible PHP Installation. Requires module mssql or module odbc" - -#: setup.php:106 -msgid "Incompatible PHP Installation. Requires module" -msgstr "Incompatible PHP Installation. Requires module" - -#: setup.php:125 -msgid "Installed / not configured" -msgstr "Installed / not configured" diff --git a/locales/fr_FR.mo b/locales/fr_FR.mo index 41315b633142793177ed90d562a81fe0a5e34cc6..2f7efeed054b73860d38ef3f538f9e7344e4220f 100644 GIT binary patch delta 1554 zcmZY8Ply~v6vy$(&Nw?+T@&M34E-@e~2!lZhf(c%Rh?ga2!CCMS2uOr@5DyYjJV-!-xrly$GrbYCpyt!nGgbB8 ztD4JGzt41k+*bX_(4M5hGFrF&iiQ~p}%^n`6`Qjkf@pasSIqt_3*uaaZ!2T+~U#uB(FXI*5j4^71 z4$k0vxD(GIQ_K&jfPTVByoO`!Zz_bbl@~Qs0NYUuS$qMX!Uyq9)Iz6G0iQvVGhZQV znf3Df3wS%@Z&4flj7sPad{Chl%zv9!l zkBjgUc2V;$ppN1Ss*-=>1Gts+=dp=<@Kt09^BL;yd@)J=wZVWFD#<0(8C^!!Fu&m( z{)rx^ZyhcCKB_WbVgt{k7QTX1*<3}YnCqyGYHXq-okkr^6BXEtTXg%u8BWwk(8kZSs?Dj;PyMkg+F4_!^ApB+ApE~?J{zwNQ|#qj)hFwl9cWGcH_ zgRaV`sUj+unr=MzX?W3eNzJ15?hV^XO^(_$E{;Xs9*fhcxfhpl7QqwPklSDB@mH z-L<@TW9cy9r$OelM=NQ!i!^s(!@e9ly)1m>vpk4n8~D(+-Nqe?mz>LT8%9~0_-G@&-qrf4h5f5(l4W{l zLq}|@MAo*-s!WcxNN&(4yLUEs>&t__(#w05iRTU<2<$K`W`>FPgFe%EzEM$as&rYk xa1DFVwOf&X5DxlTnIxOJ+_ne(f5(I}I-0fTCsr!M)FbEf-iMQW$45b#e*j?B`Gf!f delta 1011 zcmXZbJ!n%=7{>7@>5ZmMG`4E|h?=&>ei$egLS;4nd*d5)p-hOL3|n;Ls@|IH@3J5X3?KKezWK=lpU`F87@GJtsekTZP)Eo?t~p znRbLWn~=`oW|EG0*&$`|RqPwgGyaGr{D$3_3#1&!~A6L^gAQfvbU7;m7T|Bg-|=-RH-AbLZicm^-vHJn2~ zzk#l73u`XTZ@%7BHX%J(liW0$u?8}c0C8|@wM_aF}635PEc6<06K_rY<9=8f*Av4`m2bP~N; zhpXmr`G;vv&PSk%JHlmhMlPq%wm|dW(c#P;MVhPS(m8yY!kOT9_$#P}*HdSk?@|lN ga3Ve0yq{i8gg3iZ!ct}-T+5tqUd>iJ!pFI>|2gbdz5oCK diff --git a/locales/fr_FR.po b/locales/fr_FR.po index 536ad2e..c8fb45c 100644 --- a/locales/fr_FR.po +++ b/locales/fr_FR.po @@ -18,86 +18,78 @@ msgstr "" "Language: fr\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" -#: inc/mdt.class.php:137 +#: hook.php:249 +msgid "" +"Glpi2mdt database is corrupted. Please uninstall and reinstall the plugin" +msgstr "" +"La base de données de glpi2mdt est corrompue. Merci de désinstaller et " +"réinstaller le plugin" + +#: setup.php:101 +msgid "Incompatible PHP Installation. Requires module mssql or module odbc" +msgstr "" +"Configuration PHP incompatible. Un module PHP MSSQL ou ODBC est nécessaire" + +#: setup.php:106 +msgid "Incompatible PHP Installation. Requires module" +msgstr "Installation de PHP incompatible. Nécessite le module" + +#: setup.php:125 +msgid "Installed / not configured" +msgstr "Installé / Non configuré" + +#: inc/crontask.class.php:179 inc/crontask.class.php:216 +#: inc/crontask.class.php:262 inc/crontask.class.php:308 +#: inc/crontask.class.php:349 inc/crontask.class.php:395 +msgid "lines loaded into table" +msgstr "ligne(s) chargée(s) dans la table" + +#: inc/crontask.class.php:187 inc/crontask.class.php:271 +#: inc/crontask.class.php:319 inc/crontask.class.php:358 +#: inc/crontask.class.php:406 +msgid "lines deleted from table" +msgstr "ligne(s) supprimée(s) de la table" + +#: inc/crontask.class.php:540 +msgid "Glpi2mdt Plugin" +msgstr "Plugin Glpi2mdt" + +#: inc/mdt.class.php:154 msgid "Testing connection using PHP module" msgstr "Test de la connexion avec le module PHP" -#: inc/mdt.class.php:141 +#: inc/mdt.class.php:158 msgid "Database login OK!" msgstr "Connexion à la base réussie!" -#: inc/mdt.class.php:151 inc/config.class.php:140 +#: inc/mdt.class.php:168 inc/config.class.php:140 msgid "Schema" msgstr "Schéma" -#: inc/mdt.class.php:151 +#: inc/mdt.class.php:168 msgid "contains" -msgstr "" +msgstr "contient" -#: inc/mdt.class.php:151 +#: inc/mdt.class.php:168 msgid "tables" -msgstr "" +msgstr "tables" -#: inc/mdt.class.php:155 +#: inc/mdt.class.php:172 msgid "Could not count tables in schema" -msgstr "" +msgstr "Impossible de compter les tables du schéma" -#: inc/mdt.class.php:160 +#: inc/mdt.class.php:177 msgid "Database login KO!" msgstr "Echec de connexion à la base!" -#: inc/computer.class.php:58 inc/computer.class.php:60 -msgid "Auto Install" -msgstr "Install auto" - -#: inc/computer.class.php:347 -msgid "Automatic installation" -msgstr "Installation automatique" - -#: inc/computer.class.php:351 -msgid "Enable automatic installation" -msgstr "Activer l'installation automatique" - -#: inc/computer.class.php:353 inc/config.class.php:86 +#: inc/config.class.php:86 inc/computer.class.php:321 msgid "YES" msgstr "Oui" -#: inc/computer.class.php:354 inc/config.class.php:87 +#: inc/config.class.php:87 inc/computer.class.php:322 msgid "NO" msgstr "Non" -#: inc/computer.class.php:363 -msgid "Reset after (empty for permanent):" -msgstr "Annuler après (vide pour jamais)" - -#: inc/computer.class.php:373 -msgid "Task sequence" -msgstr "Séquence de tâches" - -#: inc/computer.class.php:402 -msgid "Applications" -msgstr "Applications" - -#: inc/computer.class.php:414 -msgid "Roles" -msgstr "Rôles" - -#: inc/crontask.class.php:198 inc/crontask.class.php:235 -#: inc/crontask.class.php:281 inc/crontask.class.php:327 -#: inc/crontask.class.php:368 inc/crontask.class.php:414 -msgid "lines loaded into table" -msgstr "ligne(s) chargée(s) dans la table" - -#: inc/crontask.class.php:206 inc/crontask.class.php:290 -#: inc/crontask.class.php:338 inc/crontask.class.php:377 -#: inc/crontask.class.php:425 -msgid "lines deleted from table" -msgstr "ligne(s) supprimée(s) de la table" - -#: inc/crontask.class.php:531 -msgid "Glpi2mdt Plugin" -msgstr "Plugin Glpi2mdt" - #: inc/config.class.php:95 msgid "Database server name" msgstr "Nom DNS du serveur de base de données" @@ -184,6 +176,43 @@ msgstr "Tester la connexion" msgid "Initialise data" msgstr "Initialiser les données" +#: inc/config.class.php:236 inc/computer.class.php:403 +#, php-format +msgid "A new version of plugin glpi2mdt is available: v%s" +msgstr "Une nouvelle version du plugin glpi2mdt est disponible: v%s" + +#: inc/computer.class.php:66 inc/computer.class.php:68 +msgid "Auto Install" +msgstr "Install auto" + +#: inc/computer.class.php:315 +msgid "Automatic installation" +msgstr "Installation automatique" + +#: inc/computer.class.php:319 +msgid "Enable automatic installation" +msgstr "Activer l'installation automatique" + +#: inc/computer.class.php:323 +msgid "Default" +msgstr "Défault" + +#: inc/computer.class.php:332 +msgid "Reset after (empty for permanent):" +msgstr "Annuler après (vide pour jamais)" + +#: inc/computer.class.php:342 +msgid "Task sequence" +msgstr "Séquence de tâches" + +#: inc/computer.class.php:371 +msgid "Applications" +msgstr "Applications" + +#: inc/computer.class.php:383 +msgid "Roles" +msgstr "Rôles" + #: front/computer.form.php:36 msgid "Features" msgstr "Fonctions" @@ -191,16 +220,3 @@ msgstr "Fonctions" #: front/config.form.php:36 msgid "Setup" msgstr "Configuration" - -#: setup.php:101 -msgid "Incompatible PHP Installation. Requires module mssql or module odbc" -msgstr "" -"Configuration PHP incompatible. Un module PHP MSSQL ou ODBC est nécessaire" - -#: setup.php:106 -msgid "Incompatible PHP Installation. Requires module" -msgstr "Installation de PHP incompatible. Nécessite le module" - -#: setup.php:125 -msgid "Installed / not configured" -msgstr "Installé / Non configuré" diff --git a/locales/glpi2mdt.pot b/locales/glpi2mdt.pot index dc810a1..ad8c336 100644 --- a/locales/glpi2mdt.pot +++ b/locales/glpi2mdt.pot @@ -19,84 +19,73 @@ msgstr "" -#: inc/mdt.class.php:137 -msgid "Testing connection using PHP module" -msgstr "" - -#: inc/mdt.class.php:141 -msgid "Database login OK!" -msgstr "" - -#: inc/mdt.class.php:151 inc/config.class.php:140 -msgid "Schema" -msgstr "" - -#: inc/mdt.class.php:151 -msgid "contains" +#: hook.php:249 +msgid "" +"Glpi2mdt database is corrupted. Please uninstall and reinstall the plugin" msgstr "" -#: inc/mdt.class.php:151 -msgid "tables" +#: setup.php:101 +msgid "Incompatible PHP Installation. Requires module mssql or module odbc" msgstr "" -#: inc/mdt.class.php:155 -msgid "Could not count tables in schema" +#: setup.php:106 +msgid "Incompatible PHP Installation. Requires module" msgstr "" -#: inc/mdt.class.php:160 -msgid "Database login KO!" +#: setup.php:125 +msgid "Installed / not configured" msgstr "" -#: inc/computer.class.php:58 inc/computer.class.php:60 -msgid "Auto Install" +#: inc/crontask.class.php:179 inc/crontask.class.php:216 +#: inc/crontask.class.php:262 inc/crontask.class.php:308 +#: inc/crontask.class.php:349 inc/crontask.class.php:395 +msgid "lines loaded into table" msgstr "" -#: inc/computer.class.php:347 -msgid "Automatic installation" +#: inc/crontask.class.php:187 inc/crontask.class.php:271 +#: inc/crontask.class.php:319 inc/crontask.class.php:358 +#: inc/crontask.class.php:406 +msgid "lines deleted from table" msgstr "" -#: inc/computer.class.php:351 -msgid "Enable automatic installation" +#: inc/crontask.class.php:540 +msgid "Glpi2mdt Plugin" msgstr "" -#: inc/computer.class.php:353 inc/config.class.php:86 -msgid "YES" +#: inc/mdt.class.php:154 +msgid "Testing connection using PHP module" msgstr "" -#: inc/computer.class.php:354 inc/config.class.php:87 -msgid "NO" +#: inc/mdt.class.php:158 +msgid "Database login OK!" msgstr "" -#: inc/computer.class.php:363 -msgid "Reset after (empty for permanent):" +#: inc/mdt.class.php:168 inc/config.class.php:140 +msgid "Schema" msgstr "" -#: inc/computer.class.php:373 -msgid "Task sequence" +#: inc/mdt.class.php:168 +msgid "contains" msgstr "" -#: inc/computer.class.php:402 -msgid "Applications" +#: inc/mdt.class.php:168 +msgid "tables" msgstr "" -#: inc/computer.class.php:414 -msgid "Roles" +#: inc/mdt.class.php:172 +msgid "Could not count tables in schema" msgstr "" -#: inc/crontask.class.php:198 inc/crontask.class.php:235 -#: inc/crontask.class.php:281 inc/crontask.class.php:327 -#: inc/crontask.class.php:368 inc/crontask.class.php:414 -msgid "lines loaded into table" +#: inc/mdt.class.php:177 +msgid "Database login KO!" msgstr "" -#: inc/crontask.class.php:206 inc/crontask.class.php:290 -#: inc/crontask.class.php:338 inc/crontask.class.php:377 -#: inc/crontask.class.php:425 -msgid "lines deleted from table" +#: inc/config.class.php:86 inc/computer.class.php:321 +msgid "YES" msgstr "" -#: inc/crontask.class.php:531 -msgid "Glpi2mdt Plugin" +#: inc/config.class.php:87 inc/computer.class.php:322 +msgid "NO" msgstr "" #: inc/config.class.php:95 @@ -183,22 +172,47 @@ msgstr "" msgid "Initialise data" msgstr "" -#: front/computer.form.php:36 -msgid "Features" +#: inc/config.class.php:236 inc/computer.class.php:403 +#, php-format +msgid "A new version of plugin glpi2mdt is available: v%s" msgstr "" -#: front/config.form.php:36 -msgid "Setup" +#: inc/computer.class.php:66 inc/computer.class.php:68 +msgid "Auto Install" msgstr "" -#: setup.php:101 -msgid "Incompatible PHP Installation. Requires module mssql or module odbc" +#: inc/computer.class.php:315 +msgid "Automatic installation" msgstr "" -#: setup.php:106 -msgid "Incompatible PHP Installation. Requires module" +#: inc/computer.class.php:319 +msgid "Enable automatic installation" msgstr "" -#: setup.php:125 -msgid "Installed / not configured" +#: inc/computer.class.php:323 +msgid "Default" +msgstr "" + +#: inc/computer.class.php:332 +msgid "Reset after (empty for permanent):" +msgstr "" + +#: inc/computer.class.php:342 +msgid "Task sequence" +msgstr "" + +#: inc/computer.class.php:371 +msgid "Applications" +msgstr "" + +#: inc/computer.class.php:383 +msgid "Roles" +msgstr "" + +#: front/computer.form.php:36 +msgid "Features" +msgstr "" + +#: front/config.form.php:36 +msgid "Setup" msgstr "" diff --git a/setup.php b/setup.php index e1baec5..6bc2b91 100644 --- a/setup.php +++ b/setup.php @@ -98,12 +98,12 @@ function plugin_glpi2mdt_check_prerequisites() { // The plugin needs to access the MSSQL MDT database, PHP modules needed if (!extension_loaded("mssql") and !extension_loaded("odbc")) { - echo _('Incompatible PHP Installation. Requires module mssql or module odbc'); + echo __('Incompatible PHP Installation. Requires module mssql or module odbc', 'glpi2mdt'); return false; } // The plugin needs to process some XML files from the MDT deployment share, PHP module needed if (!extension_loaded("simpleXML")) { - echo _('Incompatible PHP Installation. Requires module'). " simpleXML"; + echo __('Incompatible PHP Installation. Requires module', 'glpi2mdt'). " simpleXML"; return false; } return true;