glpi / src / plugins / vigilo / inc / menu.class.php @ c413e820
History | View | Annotate | Download (4.11 KB)
1 |
<?php
|
---|---|
2 |
|
3 |
class PluginVigiloMenu extends CommonGLPI |
4 |
{ |
5 |
const TIMEOUT = 30; |
6 |
|
7 |
/**
|
8 |
* Name of the type
|
9 |
*
|
10 |
* @param $nb integer number of item in the type (default 0)
|
11 |
**/
|
12 |
public static function getTypeName($nb = 0) |
13 |
{ |
14 |
return 'Vigilo'; |
15 |
} |
16 |
|
17 |
public static function canView() |
18 |
{ |
19 |
return Session::haveRight("config", UPDATE); |
20 |
} |
21 |
|
22 |
public static function canCreate() |
23 |
{ |
24 |
return false; |
25 |
} |
26 |
|
27 |
public static function getMenuName() |
28 |
{ |
29 |
return static::getTypeName(); |
30 |
} |
31 |
|
32 |
public static function getAdditionalMenuOptions() |
33 |
{ |
34 |
return array(); |
35 |
} |
36 |
|
37 |
public static function getAdditionalMenuContent() |
38 |
{ |
39 |
return array(); |
40 |
} |
41 |
|
42 |
public static function displayMenu($res, $pipes) |
43 |
{ |
44 |
global $DB; |
45 |
|
46 |
$disabled = ''; |
47 |
if (!is_resource($res)) { |
48 |
$disabled = 'disabled'; |
49 |
} |
50 |
|
51 |
echo <<<HTML |
52 |
<h1>Vigilo</h1><form method="post" action="?itemtype=vigilo">
|
53 |
<textarea readonly='readonly' $disabled id='vigilo_deploy' style='display: block; width: 99%; height: 380px'>
|
54 |
HTML;
|
55 |
|
56 |
$needs_deploy = false; |
57 |
$query = <<<SQL |
58 |
SELECT `value`
|
59 |
FROM `glpi_plugin_vigilo_config`
|
60 |
WHERE `key` = 'needs_deploy';
|
61 |
SQL;
|
62 |
|
63 |
$result = $DB->query($query); |
64 |
if ($result) { |
65 |
$needs_deploy = (int) $DB->result($result, 0, "value"); |
66 |
} |
67 |
|
68 |
if (is_resource($res)) { |
69 |
ini_set("max_execution_time", 0); |
70 |
ignore_user_abort(true);
|
71 |
set_time_limit(0); |
72 |
|
73 |
do {
|
74 |
$read = $exc = $pipes; |
75 |
$write = array(); |
76 |
|
77 |
$nb = stream_select($read, $write, $exc, static::TIMEOUT, 0); |
78 |
|
79 |
// Error
|
80 |
if ($nb === false) { |
81 |
echo "UNKNOWN ERROR\n"; |
82 |
break;
|
83 |
} |
84 |
|
85 |
// Timeout
|
86 |
if ($nb === 0) { |
87 |
echo "ERROR: command timed out!\n"; |
88 |
break;
|
89 |
} |
90 |
if (count($exc)) { |
91 |
echo "UNKNOWN ERROR\n"; |
92 |
break;
|
93 |
} |
94 |
|
95 |
foreach ($read as $stream) { |
96 |
echo htmlspecialchars(fread($stream, 1024), ENT_HTML5 | ENT_QUOTES, "utf-8"); |
97 |
}; |
98 |
|
99 |
flush();
|
100 |
if (feof($pipes[1])) { |
101 |
break;
|
102 |
} |
103 |
} while (1); |
104 |
|
105 |
$info = proc_get_status($res); |
106 |
if ($info === false) { |
107 |
echo "ERROR: could not determine process status\n"; |
108 |
$info = array('exitcode' => null); |
109 |
} else {
|
110 |
if ($info["signaled"]) { |
111 |
echo "Command terminated by signal ${info['termsig']}\n"; |
112 |
} |
113 |
if ($info["stopped"]) { |
114 |
echo "Command stopped by signal ${info['stopsig']}\n"; |
115 |
} |
116 |
echo "Command exited with return code ${info['exitcode']}\n"; |
117 |
} |
118 |
proc_close($res);
|
119 |
|
120 |
if (isset($info['exitcode']) && 0 === $info['exitcode']) { |
121 |
$query = "UPDATE `glpi_plugin_vigilo_config` SET `value` = 0 WHERE `key` = 'needs_deploy';"; |
122 |
$DB->query($query); |
123 |
} |
124 |
} elseif ($needs_deploy) { |
125 |
echo "Cliquez sur « Déployer la configuration » pour appliquer les modifications en attente."; |
126 |
} else {
|
127 |
echo "La configuration est à jour."; |
128 |
} |
129 |
|
130 |
$force = empty($_POST['force']) ? '' : 'checked'; |
131 |
$debug = empty($_POST['debug']) ? '' : 'checked'; |
132 |
echo <<<HTML |
133 |
</textarea>
|
134 |
|
135 |
<button type="submit" name="deploy" value="1">Déployer la configuration</button>
|
136 |
|
137 |
<label for="debug"><input name="debug" id="debug" value="1" type="checkbox" $debug
|
138 |
title="Affiche les informations de diagnostic et de progression de Vigilo"
|
139 |
/> Afficher les informations de débogage</label>
|
140 |
|
141 |
<label for="force"><input name="force" id="force" value="1" type="checkbox" $force
|
142 |
title="Force un déploiement complet plutôt qu'un déploiement en mode incrémental"
|
143 |
/> Regénérer tous les fichiers</label>
|
144 |
HTML;
|
145 |
Html::closeForm();
|
146 |
} |
147 |
} |