glpi / src / plugins / vigilo / inc / menu.class.php @ 420b5990
History | View | Annotate | Download (4.11 KB)
1 | efcf5ecf | Francois POIROTTE | <?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 | 077e4de7 | Francois POIROTTE | public static function getTypeName($nb = 0) |
13 | { |
||
14 | efcf5ecf | Francois POIROTTE | return 'Vigilo'; |
15 | } |
||
16 | |||
17 | 077e4de7 | Francois POIROTTE | public static function canView() |
18 | { |
||
19 | cf9d65ba | Francois POIROTTE | return Session::haveRight("config", UPDATE); |
20 | efcf5ecf | Francois POIROTTE | } |
21 | |||
22 | 077e4de7 | Francois POIROTTE | public static function canCreate() |
23 | { |
||
24 | efcf5ecf | Francois POIROTTE | return false; |
25 | } |
||
26 | |||
27 | 077e4de7 | Francois POIROTTE | public static function getMenuName() |
28 | { |
||
29 | 166be9d2 | Francois POIROTTE | return static::getTypeName(); |
30 | efcf5ecf | Francois POIROTTE | } |
31 | |||
32 | 077e4de7 | Francois POIROTTE | public static function getAdditionalMenuOptions() |
33 | { |
||
34 | efcf5ecf | Francois POIROTTE | return array(); |
35 | } |
||
36 | |||
37 | 077e4de7 | Francois POIROTTE | public static function getAdditionalMenuContent() |
38 | { |
||
39 | efcf5ecf | Francois POIROTTE | return array(); |
40 | } |
||
41 | |||
42 | 077e4de7 | Francois POIROTTE | public static function displayMenu($res, $pipes) |
43 | { |
||
44 | 166be9d2 | Francois POIROTTE | 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 | efcf5ecf | Francois POIROTTE | |
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 | 077e4de7 | Francois POIROTTE | if ($nb === false) { |
81 | efcf5ecf | Francois POIROTTE | 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 | 077e4de7 | Francois POIROTTE | foreach ($read as $stream) { |
96 | efcf5ecf | Francois POIROTTE | echo htmlspecialchars(fread($stream, 1024), ENT_HTML5 | ENT_QUOTES, "utf-8"); |
97 | a5c9df40 | Thibault Louet | }; |
98 | 0e0753c8 | Romain CHOLLET | |
99 | efcf5ecf | Francois POIROTTE | flush();
|
100 | 077e4de7 | Francois POIROTTE | if (feof($pipes[1])) { |
101 | break;
|
||
102 | a5c9df40 | Thibault Louet | } |
103 | efcf5ecf | Francois POIROTTE | } while (1); |
104 | |||
105 | $info = proc_get_status($res); |
||
106 | if ($info === false) { |
||
107 | echo "ERROR: could not determine process status\n"; |
||
108 | 166be9d2 | Francois POIROTTE | $info = array('exitcode' => null); |
109 | efcf5ecf | Francois POIROTTE | } else {
|
110 | 077e4de7 | Francois POIROTTE | if ($info["signaled"]) { |
111 | efcf5ecf | Francois POIROTTE | echo "Command terminated by signal ${info['termsig']}\n"; |
112 | 077e4de7 | Francois POIROTTE | } |
113 | if ($info["stopped"]) { |
||
114 | efcf5ecf | Francois POIROTTE | echo "Command stopped by signal ${info['stopsig']}\n"; |
115 | 077e4de7 | Francois POIROTTE | } |
116 | efcf5ecf | Francois POIROTTE | echo "Command exited with return code ${info['exitcode']}\n"; |
117 | } |
||
118 | proc_close($res);
|
||
119 | 166be9d2 | Francois POIROTTE | |
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 | efcf5ecf | Francois POIROTTE | } |
129 | |||
130 | 19eadf52 | Francois POIROTTE | $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 | efcf5ecf | Francois POIROTTE | Html::closeForm();
|
146 | } |
||
147 | } |