Skip to content

Commit 6d17946

Browse files
author
Debug Bill
committed
First attempt at version 0.1.0
1 parent 558ecce commit 6d17946

File tree

11 files changed

+154
-143
lines changed

11 files changed

+154
-143
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [0.1.0] - 2017-09-20
5+
### Added
6+
- The plugin now uses bith mssql and odbc PHP modules making PHP7 compatible
7+
- Crontask is added in order to disable automatic install after a specific date
8+
- Crontask is added to synchronise base data from MTD to GLPI on a regular basis (applications, roles,....)
9+
- Several applications have been added.
10+
- A major bug is removed wich was probably preventing most of you from using the plugin (some platform specific configuraiton was hard coded)
11+
- TCP port configuration for DB access is now working
12+
13+
## Changed
14+
- The coupling mode now has an effect. Strict and Loose coupling are working. Master-Master still doesn't
15+
16+
## Removed
17+
- None
18+
419

520
## [0.0.1] - 2017-08-25
621
### Added

INSTALL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ That's all for now!
1818
* Go to one of your computers.
1919
* It should have at least one unique identifier availalble: Serial (might not be unique), Mac address, GUID.
2020
* Go to sub-item "auto-install" in the computer page.
21-
* Set your desired values, mainly "Automatic Install" to YES. Choose the proper task sequence and application (yes just one for now)
21+
* Set your desired values, mainly "Automatic Install" to YES. Choose the proper task sequence and application(s) and role(s) as you would from MDT's interface
2222
* Save
2323

24-
The computer is now created into MDT with those settings. Pressing F12 for PXE boot should fire the install.
24+
The computer is now created or updated in MDT with those settings. Pressing F12 for PXE boot should fire the install.
2525

2626

2727
Hope it works for you too!

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,27 @@ It is developed and tested in this environment only. If you experience problem w
3131
* MDT must be installed in a MS-SQL database accessible from the GLPI server
3232
* MDT must be fully operationnal by itself. The plugin will not fix a faulty MDT installation, it is only remote-controlling it.
3333
* (MSSQL or ODBC) and SimpleXML PHP modules must be installed
34-
* The "Control" directory in your MDT deployment share contains part of the MDT configuration (the other part is in the MS-SQL database). It needs to be mounted (read-only is OK) somewhere on your GLPI server and accessible to PHP scripts.
34+
* The "Control" directory in your MDT deployment share contains part of the MDT configuration (the other part is in the MS-SQL database). It needs to be mounted (read-only is OK) somewhere on your GLPI server and accessible to PHP scripts. Pay specific attention to files ownership and SELinux settings which can prevent proper functionning.
3535
* Fusion inventory, though not mandatory is really very very nice to have.
3636

37-
As of version 0.0.1 this plugin is just a little more than a proof of concept. I hope to improve it with time but some feedback on this
37+
Starting with version 0.1.0 this plugin is now fully functionnal and in use at our premises. I hope to improve it with time but some feedback on this
3838
version is welcome in order to direct my efforts in the right direction.
3939
Still, it works for us, in our specific environment!
4040

4141
The plugin is available in French and English, other translators welcome.
4242

4343

4444
## TODOs
45-
* Manage groups (this is mainly UI interface stuff, the code can already handle it. My main question is how many applications are avalaible on average MDT servers? Our has only 5, but in a previous company we had hundreds. The gui would not be the same....)
46-
* Handle roles, models, packages in the same way applications are handled (but are you using those features in MDT)?
45+
* Manage ranks in applications (this is mainly UI interface stuff, the code can already handle it. My main question is "is it really needded? We don't as we don't have dependencies between applications (and no so many applications to install anyway).
46+
* Handle models, packages in the same way applications are handled (but are you using those features in MDT)? Models are an issue because of a limitatio in Fusion Inventory. It may be aleviated with GLPI 9.2.x. More to come...
4747
* Automate some actions based on information available in GLPI and not managed by MDT (location, entity....)
4848
* Be multi-MDT-server, multi-deployment-share, multi-domain aware. Currently the plugin is not domain aware and is connected to only one MDT database. This raises quite a few questions as to how it should work then.
49-
* Several coupling modes are proposed in the config page.... but only one is really implemented. There too I wonder what user want. For me the "Strict Master-Slave is fine" as I want everything to be done in GLPI.
49+
* Several coupling modes are proposed in the config page.... The strict and loose coupling are there, master-master is not for the time being. Is ithis mode desirable anyway? For me the "Strict Master-Slave is fine" as I want everything to be done in GLPI. Feedback is welcome.
5050
* Fix Bugs!!!!! There most probably are many, this is the first release.
5151

5252

5353
Please test and send feedback if you (dis)like my work.
5454

55+
For more information, please consult the Wiki on gitHub
56+
5557

inc/computer.class.php

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ function updateMDT($id) {
152152
$parameters[$line['column_name']] = true;
153153
}
154154

155+
// Build password according to rules
156+
if ($globalconfig['Complexity'] == 'Trivial') {
157+
$adminpasscomposite = $name;
158+
} else if ($globalconfig['Complexity'] == 'Unique') {
159+
$adminpasscomposite = $globalconfig['LocalAdmin'].'-'.$name;
160+
} else { // Default case, Basic
161+
$adminpasscomposite = $globalconfig['LocalAdmin'];
162+
}
163+
155164
$globalconfig = $this->globalconfig;
156165

157166
// Get data for current computer
@@ -209,9 +218,9 @@ function updateMDT($id) {
209218
$ids="ID = ''";
210219
}
211220
// Check if the computer entries in MDT are the ones expected by GLPI.
212-
// If no, delete everything and recreate
221+
// If not, delete everything and recreate
213222
// If yes, depending on coupling mode, delete and recreate or simply update
214-
$query = ("SELECT FROM dbo.ComputerIdentity
223+
$query = ("SELECT ID FROM dbo.ComputerIdentity
215224
WHERE (UUID='$uuid') AND Description='$name' AND SerialNumber='$serial' AND $macs");
216225
$result = $this->query($query);
217226
$nblinesactual = $this->numrows($result);
@@ -220,7 +229,7 @@ function updateMDT($id) {
220229
$this->queryOrDie("INSERT INTO dbo.ComputerIdentity (Description, UUID, SerialNumber, AssetTag, MacAddress) VALUES $values");
221230
}
222231
// Delete corresponding records in side tables depending on coupling mode
223-
if ($nblines <> $nblinesactual OR $mode == 'strict') {
232+
if ($nblines <> $nblinesactual OR $globalconfig['Mode'] == 'Strict') {
224233
$this->queryOrDie("DELETE FROM dbo.Settings WHERE Type='C' and $ids");
225234
$this->queryOrDie("DELETE FROM dbo.Settings_Applications WHERE Type='C' and $ids");
226235
$this->queryOrDie("DELETE FROM dbo.Settings_Administrators WHERE Type='C' and $ids");
@@ -232,55 +241,65 @@ function updateMDT($id) {
232241
$query = "SELECT ID FROM dbo.ComputerIdentity WHERE Description='$name'";
233242
$result = $this->queryOrDie($query);
234243
$ids = "(";
235-
$values = '';
236244

237245
while ($row = $this->fetch_array($result)) {
238246
$mdtid = $row['ID'];
239-
$ids = $ids.$mdtid.", ";
240-
$values = $values."('C', $mdtid, '$name', '$name', '$name', '$adminpasscomposite'), ";
247+
$ids = $ids.$row['ID'].", ";
241248
$arrayid[$row['ID']] = $row['ID'];
249+
$values = "('C', $mdtid, '$name', '$name', '$name', '$adminpasscomposite') ";
250+
// Check if settings line does exist already. Insert if not, update if yes
251+
// (because "on duplicate" does not exist in MS-SQL
252+
$exists = $this->queryOrDie("SELECT ID FROM dbo.Settings WHERE Type='C' AND ID=$mdtid;");
253+
if ($this->numrows($exists) == 1) {
254+
$query = "UPDATE dbo.Settings SET ComputerName='$name', OSDComputerName='$name', FullName='$name', AdminPassword='$adminpasscomposite'
255+
WHERE Type='C' and ID=$mdtid";
256+
} else {
257+
$query = "INSERT INTO dbo.Settings (Type, ID, ComputerName, OSDComputerName, FullName, AdminPassword) VALUES $values;";
258+
}
259+
$this->queryOrDie($query);
242260
}
243261
$ids = substr($ids, 0, -2).") ";
244-
$values = substr($values, 0, -2);
245-
246-
// Build password according to rules
247-
if ($globalconfig['Complexity'] == 'Trivial') {
248-
$adminpasscomposite = $name;
249-
} else if ($globalconfig['Complexity'] == 'Unique') {
250-
$adminpasscomposite = $globalconfig['LocalAdmin'].'-'.$name;
251-
} else { // Default case, Basic
252-
$adminpasscomposite = $globalconfig['LocalAdmin'];
253-
}
254-
255-
$query = "INSERT INTO dbo.Settings (Type, ID, ComputerName, OSDComputerName, FullName, AdminPassword) VALUES $values";
256-
$this->queryOrDie($query);
257262

258263
// Update settings with additional parameters
259264
$query = "SELECT `key`, `value` FROM glpi_plugin_glpi2mdt_settings WHERE id=$id AND category='C' AND type='C';";
260-
$result = $DB->query($query)
261-
or die("Cannot select additional parameters.<br>". $query."<br><br>".$DB->error());
265+
$result = $DB->queryOrDie($query, "Cannot select additional parameters.<br>");
262266
while ($pair = $DB->fetch_array($result)) {
263267
$key = $pair['key'];
264268
$value = $pair['value'];
265269
$query = "UPDATE dbo.Settings SET $key='$value' WHERE ID IN $ids;";
266-
if ($parameter[$key]) {
270+
// Check if key is a valid field for database "settings"
271+
if ($parameters[$key]) {
267272
$this->queryOrDie("$query");
268273
}
269274
}
270-
271275
// Update applications table
272276
$query = "SELECT `key`, `value` FROM glpi_plugin_glpi2mdt_settings WHERE id=$id AND category='A' AND type='C';";
273-
$result = $DB->query($query)
274-
or die("Cannot select additional applications.<br>". $query."<br><br>".$DB->error());
275-
$query = "DELETE FROM dbo.Settings_Applications WHERE type='C' AND ID='$id'";
276-
$this->queryOrDie("$query");
277+
$result = $DB->queryOrDie($query, "Cannot select additional applications.");
277278
while ($pair = $DB->fetch_array($result)) {
278279
$key = $pair['key'];
279280
$value = $pair['value'];
280281
foreach ($arrayid as $mdtid) {
281-
$query = "INSERT INTO dbo.Settings_Applications (Type, ID, Sequence, Applications)
282-
VALUES ('C', '$mdtid', $value, '$key');";
283-
$this->queryOrDie("$query");
282+
// GLPI2MDT does not manage ranks, so keep the existing one if any
283+
$ranks = $this->queryOrDie("SELECT Sequence FROM dbo.Settings_Applications WHERE ID=$mdtid AND type='C' AND Applications='$key';");
284+
if ($this->numrows($ranks) == 0) {
285+
$this->queryOrDie("INSERT INTO dbo.Settings_Applications (Type, ID, Sequence, Applications)
286+
VALUES ('C', '$mdtid', $value, '$key');");
287+
}
288+
}
289+
}
290+
// Update Roles table
291+
$query = "SELECT `key`, `value` FROM glpi_plugin_glpi2mdt_settings WHERE id=$id AND category='R' AND type='C';";
292+
$result = $DB->queryOrDie($query, "Cannot select additional roles.");
293+
while ($pair = $DB->fetch_array($result)) {
294+
$key = $pair['key'];
295+
$value = $pair['value'];
296+
foreach ($arrayid as $mdtid) {
297+
// GLPI2MDT does not manage ranks, so keep the existing one if any
298+
$ranks = $this->queryOrDie("SELECT Sequence FROM dbo.Settings_Roles WHERE ID=$mdtid AND type='C' AND Role='$key';");
299+
if ($this->numrows($ranks) == 0) {
300+
$this->queryOrDie("INSERT INTO dbo.Settings_Roles (Type, ID, Sequence, Role)
301+
VALUES ('C', '$mdtid', $value, '$key');");
302+
}
284303
}
285304
}
286305
}
@@ -408,18 +427,6 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtempl
408427
}
409428
return true;
410429
}
411-
/**
412-
* This function is called by GLPI when an update is made to a computer
413-
*
414-
* @param GLPI object ID, here a computer
415-
* @param Expire: will only reset "OSInstall flag set to true and coupling mode is not "strict master slave"
416-
* @return string type for the cron list page
417-
*/
418-
function update_item(computer $item) {
419-
Session::addMessageAfterRedirect("Glpi2mdt after update hook", true);
420-
print_f($item);
421-
die("Here we are");
422-
}
423430
}
424431

425432

inc/mdt.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function __construct() {
9494

9595
// Conection to MSSQL using native MSSQL PHP module available until PHP 5.6
9696
} else if (extension_loaded('mssql')) {
97-
$DBModule = 'mssql';
97+
$this->DBModule = 'mssql';
9898
$DBLink = mssql_connect($DBServer.":".$DBPort, $DBLogin, $DBPassword);
9999
if ($DBLink) {
100100
mssql_select_db($DBSchema, $MDT);
@@ -148,11 +148,11 @@ function showTestConnection() {
148148
$nb = reset($this->fetch_array($result));
149149
if ($nb > 0) {
150150
echo "<font color='green'>";
151-
echo __(" Schema ", 'glpi2mdt').$dbschema.__(" contains ", 'glpi2mdt').$nb.__(" tables ", 'glpi2mdt');
151+
echo __("Schema", 'glpi2mdt')." ".$dbschema." ".__("contains", 'glpi2mdt')." ".$nb." ".__("tables", 'glpi2mdt').".";
152152
echo "</font><br>";
153153
} else {
154154
echo "<h1><font color='red'>";
155-
echo __("Could not count tables in schema ", 'glpi2mdt').$this->DBSchema;
155+
echo __("Could not count tables in schema", 'glpi2mdt')." ".$this->DBSchema;
156156
echo "</font></h1><br>";
157157
}
158158
} else {

locales/en_US.mo

-196 Bytes
Binary file not shown.

locales/en_US.po

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,67 +18,67 @@ msgstr ""
1818
"Language: en_US\n"
1919
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
2020

21-
#: inc/mdt.class.php:138
21+
#: inc/mdt.class.php:137
2222
msgid "Testing connection using PHP module"
2323
msgstr ""
2424

25-
#: inc/mdt.class.php:142
25+
#: inc/mdt.class.php:141
2626
msgid "Database login OK!"
2727
msgstr "Database login OK!"
2828

29-
#: inc/mdt.class.php:152
30-
msgid " Schema "
29+
#: inc/mdt.class.php:151 inc/config.class.php:140
30+
msgid "Schema"
3131
msgstr "Schema"
3232

33-
#: inc/mdt.class.php:152
34-
msgid " contains "
35-
msgstr " contains "
33+
#: inc/mdt.class.php:151
34+
msgid "contains"
35+
msgstr ""
3636

37-
#: inc/mdt.class.php:152
38-
msgid " tables "
39-
msgstr " tables "
37+
#: inc/mdt.class.php:151
38+
msgid "tables"
39+
msgstr ""
4040

41-
#: inc/mdt.class.php:156
42-
msgid "Could not count tables in schema "
43-
msgstr "Could not count tables in schema "
41+
#: inc/mdt.class.php:155
42+
msgid "Could not count tables in schema"
43+
msgstr ""
4444

45-
#: inc/mdt.class.php:162
45+
#: inc/mdt.class.php:160
4646
msgid "Database login KO!"
4747
msgstr "Database login KO!"
4848

49-
#: inc/computer.class.php:58 inc/computer.class.php:61
49+
#: inc/computer.class.php:58 inc/computer.class.php:60
5050
msgid "Auto Install"
5151
msgstr "Auto Install"
5252

53-
#: inc/computer.class.php:317
53+
#: inc/computer.class.php:340
5454
msgid "Automatic installation"
5555
msgstr "Automatic installation"
5656

57-
#: inc/computer.class.php:321
57+
#: inc/computer.class.php:344
5858
msgid "Enable automatic installation"
5959
msgstr "Enable automatic installation"
6060

61-
#: inc/computer.class.php:323 inc/config.class.php:86
61+
#: inc/computer.class.php:346 inc/config.class.php:86
6262
msgid "YES"
6363
msgstr "Yes"
6464

65-
#: inc/computer.class.php:324 inc/config.class.php:87
65+
#: inc/computer.class.php:347 inc/config.class.php:87
6666
msgid "NO"
6767
msgstr "No"
6868

69-
#: inc/computer.class.php:333
69+
#: inc/computer.class.php:356
7070
msgid "Reset after (empty for permanent):"
7171
msgstr "Reset after (empty for permanent):"
7272

73-
#: inc/computer.class.php:343
73+
#: inc/computer.class.php:366
7474
msgid "Task sequence"
7575
msgstr "Task sequence"
7676

77-
#: inc/computer.class.php:372
77+
#: inc/computer.class.php:395
7878
msgid "Applications"
7979
msgstr "Applications"
8080

81-
#: inc/computer.class.php:384
81+
#: inc/computer.class.php:407
8282
msgid "Roles"
8383
msgstr "Roles"
8484

@@ -118,10 +118,6 @@ msgstr "Login"
118118
msgid "Password"
119119
msgstr "Password"
120120

121-
#: inc/config.class.php:140
122-
msgid "Schema"
123-
msgstr "Schema"
124-
125121
#: inc/config.class.php:148
126122
msgid "Local path to deployment share control directory"
127123
msgstr "Local path to deployment share control directory"
@@ -194,14 +190,14 @@ msgstr "Features"
194190
msgid "Setup"
195191
msgstr "Setup"
196192

197-
#: setup.php:102
193+
#: setup.php:101
198194
msgid "Incompatible PHP Installation. Requires module mssql or module odbc"
199195
msgstr "Incompatible PHP Installation. Requires module mssql or module odbc"
200196

201-
#: setup.php:107
197+
#: setup.php:106
202198
msgid "Incompatible PHP Installation. Requires module"
203199
msgstr "Incompatible PHP Installation. Requires module"
204200

205-
#: setup.php:126
201+
#: setup.php:125
206202
msgid "Installed / not configured"
207203
msgstr "Installed / not configured"

locales/fr_FR.mo

49 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)