glpi / hook.php @ 0e0753c8
History | View | Annotate | Download (3.63 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 |
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 |
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 |
public function delete($computer) |
59 |
{ |
60 |
$this->unmonitor($computer->fields["name"]); |
61 |
} |
62 |
|
63 |
public function update($computer) |
64 |
{ |
65 |
global $PLUGIN_HOOKS; |
66 |
if (isset($computer->oldvalues["name"])) { |
67 |
$this->unmonitor($computer->oldvalues["name"]); |
68 |
} |
69 |
|
70 |
$this->add($computer); |
71 |
} |
72 |
|
73 |
public function unmonitor($host) |
74 |
{ |
75 |
$dirs = array($this->confdir, "hosts", "managed", $host . ".xml"); |
76 |
unlink(implode(DIRECTORY_SEPARATOR, $dirs)); |
77 |
} |
78 |
|
79 |
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 |
} |
108 |
|
109 |
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 |
|
118 |
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 |
} |
127 |
} |