Revision 18eae138
[#1575] Imprimantes déclarées dans glpi suivies dans vigilo
Change-Id: I3b2bc6d08317802cd474def5fd90d6658c3c9d35
Reviewed-on: https://vigilo-dev.si.c-s.fr/review/2332
Reviewed-by: Francois POIROTTE <francois.poirotte@c-s.fr>
Tested-by: Francois POIROTTE <francois.poirotte@c-s.fr>
hook.php | ||
---|---|---|
11 | 11 |
$this->confdir = $confdir; |
12 | 12 |
} |
13 | 13 |
|
14 |
public function updateGroups()
|
|
14 |
public function saveHost($host, $dir_type)
|
|
15 | 15 |
{ |
16 |
$host = new VigiloLocation(); |
|
17 |
$dirs = array($this->confdir, "groups", "managed"); |
|
16 |
$dirs = array($this->confdir, $dir_type, "managed"); |
|
18 | 17 |
$confdir = implode(DIRECTORY_SEPARATOR, $dirs); |
19 |
$file = $confdir . DIRECTORY_SEPARATOR . "groups.xml";
|
|
18 |
$file = $confdir . DIRECTORY_SEPARATOR . $host->getName() . ".xml";
|
|
20 | 19 |
|
21 |
mkdir($confdir, 0770, true); |
|
22 |
$acc = ""; |
|
23 |
foreach ($dirs as $dir) { |
|
24 |
$acc .= DIRECTORY_SEPARATOR . $dir; |
|
25 |
chgrp($acc, "vigiconf"); |
|
20 |
if (!file_exists($confdir)) { |
|
21 |
mkdir($confdir, 0770, true); |
|
26 | 22 |
} |
27 | 23 |
|
28 | 24 |
$res = file_put_contents($file, $host, LOCK_EX); |
... | ... | |
32 | 28 |
} |
33 | 29 |
} |
34 | 30 |
|
31 |
public function updateGroups() |
|
32 |
{ |
|
33 |
$host = new VigiloLocation(); |
|
34 |
$this->saveHost($host, "groups"); |
|
35 |
} |
|
36 |
|
|
35 | 37 |
public function addComputer($computer) |
36 | 38 |
{ |
37 | 39 |
if ($computer->getField("is_template")==0) { |
... | ... | |
49 | 51 |
SET is_dynamic = ' 1 |
50 | 52 |
' WHERE id = " . $computer->getField("id") . ";"; |
51 | 53 |
$DB->queryOrDie($query, "update vigilo_template field"); |
52 |
$host = new VigiloHost($computer); |
|
53 |
$dirs = array($this->confdir, "hosts", "managed"); |
|
54 |
$confdir = implode(DIRECTORY_SEPARATOR, $dirs); |
|
55 |
$file = $confdir . DIRECTORY_SEPARATOR . $host->getName() . ".xml"; |
|
56 |
|
|
57 |
if (!file_exists($confdir)) { |
|
58 |
mkdir($confdir, 0770, true); |
|
59 |
} |
|
60 | 54 |
|
61 |
$res = file_put_contents($file, $host, LOCK_EX); |
|
62 |
if ($res !== false) { |
|
63 |
chgrp($file, "vigiconf"); |
|
64 |
chmod($file, 0660); |
|
65 |
} |
|
55 |
$host = new VigiloHost($computer); |
|
56 |
$this->saveHost($host, "hosts"); |
|
66 | 57 |
} |
67 | 58 |
} |
68 | 59 |
|
... | ... | |
71 | 62 |
if ($networkequipment->getField("is_template")==0) { |
72 | 63 |
global $DB; |
73 | 64 |
|
74 |
$host = new VigiloNetworkEquipment($networkequipment);
|
|
75 |
$dirs = array($this->confdir, "hosts", "managed");
|
|
76 |
$confdir = implode(DIRECTORY_SEPARATOR, $dirs);
|
|
77 |
$file = $confdir . DIRECTORY_SEPARATOR . $host->getName() . ".xml";
|
|
65 |
$host = new VigiloNetworkEquipment($networkequipment); |
|
66 |
$this->saveHost($host, "hosts");
|
|
67 |
}
|
|
68 |
}
|
|
78 | 69 |
|
79 |
if (!file_exists($confdir)) { |
|
80 |
mkdir($confdir, 0770, true); |
|
81 |
} |
|
70 |
public function addPrinter($printer) |
|
71 |
{ |
|
72 |
if ($printer->getField("is_template")==0) { |
|
73 |
global $DB; |
|
82 | 74 |
|
83 |
$res = file_put_contents($file, $host, LOCK_EX); |
|
84 |
if ($res !== false) { |
|
85 |
chgrp($file, "vigiconf"); |
|
86 |
chmod($file, 0660); |
|
87 |
} |
|
75 |
$host = new VigiloPrinter($printer); |
|
76 |
$this->saveHost($host, "hosts"); |
|
88 | 77 |
} |
89 | 78 |
} |
90 | 79 |
|
... | ... | |
113 | 102 |
$this->addNetworkEquipment($networkEquipment); |
114 | 103 |
} |
115 | 104 |
|
105 |
public function updatePrinter($printer) |
|
106 |
{ |
|
107 |
$this->update($printer); |
|
108 |
$this->addPrinter($printer); |
|
109 |
} |
|
110 |
|
|
116 | 111 |
public function unmonitor($host) |
117 | 112 |
{ |
118 | 113 |
$dirs = array($this->confdir, "hosts", "managed", $host . ".xml"); |
119 |
unlink(implode(DIRECTORY_SEPARATOR, $dirs)); |
|
114 |
$filename = implode(DIRECTORY_SEPARATOR, $dirs); |
|
115 |
if (file_exists($filename)) |
|
116 |
{ |
|
117 |
unlink($filename); |
|
118 |
} |
|
120 | 119 |
} |
121 | 120 |
|
122 | 121 |
public function manageComputerSoftwareVersion($computer_software_version) |
... | ... | |
181 | 180 |
$ne->getFromDB($id); |
182 | 181 |
$this->updateNetworkEquipment($ne); |
183 | 182 |
} |
183 |
else if ($itemtype === 'Printer') { |
|
184 |
$printer=new Printer(); |
|
185 |
$printer->getFromDB($id); |
|
186 |
$this->updatePrinter($printer); |
|
187 |
} |
|
184 | 188 |
} |
185 | 189 |
|
186 | 190 |
public function plugin_vigilo_getAddSearchOptions($itemtype) |
Also available in: Unified diff