glpi / hook.php @ 2ef80588
History | View | Annotate | Download (3.98 KB)
1 |
<?php
|
---|---|
2 |
|
3 |
require __DIR__ . DIRECTORY_SEPARATOR .'autoloader.php'; |
4 |
class VigiloHooks |
5 |
{ |
6 |
private $confdir; |
7 |
|
8 |
public function __construct($confdir = "/etc/vigilo/vigiconf/conf.d") |
9 |
{ |
10 |
spl_autoload_register('vigilo_autoloader');
|
11 |
$this->confdir = $confdir; |
12 |
} |
13 |
|
14 |
public function updateGroups() |
15 |
{ |
16 |
$host = new VigiloLocation(); |
17 |
$dirs = array($this->confdir, "groups", "managed"); |
18 |
$confdir = implode(DIRECTORY_SEPARATOR, $dirs); |
19 |
$file = $confdir . DIRECTORY_SEPARATOR . "groups.xml"; |
20 |
|
21 |
if (!file_exists($confdir)) { |
22 |
mkdir($confdir, 0770, true); |
23 |
} |
24 |
|
25 |
$acc = ""; |
26 |
foreach ($dirs as $dir) { |
27 |
$acc .= DIRECTORY_SEPARATOR . $dir; |
28 |
chgrp($acc, "vigiconf"); |
29 |
} |
30 |
|
31 |
$res = file_put_contents($file, $host, LOCK_EX); |
32 |
if ($res !== false) { |
33 |
chgrp($file, "vigiconf"); |
34 |
chmod($file, 0660); |
35 |
} |
36 |
} |
37 |
|
38 |
public function add($computer) |
39 |
{ |
40 |
if ($computer->getField("is_template")==0) { |
41 |
$host = new VigiloHost($computer); |
42 |
$dirs = array($this->confdir, "hosts", "managed"); |
43 |
$confdir = implode(DIRECTORY_SEPARATOR, $dirs); |
44 |
$file = $confdir . DIRECTORY_SEPARATOR . $host->getName() . ".xml"; |
45 |
|
46 |
if (!file_exists($confdir)) { |
47 |
mkdir($confdir, 0770, true); |
48 |
} |
49 |
$acc = ""; |
50 |
foreach ($dirs as $dir) { |
51 |
$acc .= DIRECTORY_SEPARATOR . $dir; |
52 |
chgrp($acc, "vigiconf"); |
53 |
} |
54 |
|
55 |
$res = file_put_contents($file, $host, LOCK_EX); |
56 |
if ($res !== false) { |
57 |
chgrp($file, "vigiconf"); |
58 |
chmod($file, 0660); |
59 |
} |
60 |
} |
61 |
} |
62 |
|
63 |
public function delete($computer) |
64 |
{ |
65 |
$this->unmonitor($computer->fields["name"]); |
66 |
} |
67 |
|
68 |
public function update($computer) |
69 |
{ |
70 |
global $PLUGIN_HOOKS; |
71 |
if (isset($computer->oldvalues["name"])) { |
72 |
$this->unmonitor($computer->oldvalues["name"]); |
73 |
} |
74 |
|
75 |
$this->add($computer); |
76 |
} |
77 |
|
78 |
public function unmonitor($host) |
79 |
{ |
80 |
$dirs = array($this->confdir, "hosts", "managed", $host . ".xml"); |
81 |
unlink(implode(DIRECTORY_SEPARATOR, $dirs)); |
82 |
} |
83 |
|
84 |
public function manageComputerSoftwareVersion($computer_software_version) |
85 |
{ |
86 |
global $DB; |
87 |
$computer=new Computer(); |
88 |
$computer->getFromDB($computer_software_version->getField("computers_id")); |
89 |
$this->update($computer); |
90 |
} |
91 |
|
92 |
public function manageSoftwares($software) |
93 |
{ |
94 |
global $DB; |
95 |
$softwareVer=new SoftwareVersion(); |
96 |
$idSoftwareVersion=$softwareVer->find('softwares_id=' . $software->getID()); |
97 |
foreach ($idSoftwareVersion as $idVersion) { |
98 |
if ($idVersion['id']) { |
99 |
$computerVer=new Computer_SoftwareVersion(); |
100 |
$goodField='softwareversions_id=' . $idVersion['id']; |
101 |
$updateComp=$computerVer->find($goodField); |
102 |
foreach ($updateComp as $idComputer) { |
103 |
if ($idComputer['computers_id'] != -1) { |
104 |
$computer=new Computer(); |
105 |
$computer->getFromDB($idComputer['computers_id']); |
106 |
$this->update($computer); |
107 |
} |
108 |
} |
109 |
} |
110 |
} |
111 |
} |
112 |
|
113 |
public function manageDisks($disk) |
114 |
{ |
115 |
global $DB; |
116 |
$id=$disk->getField('computers_id'); |
117 |
$computer=new Computer(); |
118 |
$computer->getFromDB($id); |
119 |
$this->update($computer); |
120 |
} |
121 |
|
122 |
public function manageAddresses($address) |
123 |
{ |
124 |
global $DB; |
125 |
$id=$address->getField('mainitems_id'); |
126 |
$comp=new Computer(); |
127 |
$comp->getFromDB($id); |
128 |
$this->update($comp); |
129 |
} |
130 |
|
131 |
public function manageNetworks($network) |
132 |
{ |
133 |
global $DB; |
134 |
$id=$network->getField('items_id'); |
135 |
$comp=new Computer(); |
136 |
$comp->getFromDB($id); |
137 |
$this->update($comp); |
138 |
} |
139 |
} |