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