glpi / src / plugins / vigilo / inc / menu.class.php @ b2feaa03
History | View | Annotate | Download (4.58 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 | 411a1293 | Francois POIROTTE | protected static function escape($s) |
43 | { |
||
44 | return htmlspecialchars($s, ENT_XML1 | ENT_QUOTES, "utf-8"); |
||
45 | } |
||
46 | |||
47 | 077e4de7 | Francois POIROTTE | public static function displayMenu($res, $pipes) |
48 | { |
||
49 | 166be9d2 | Francois POIROTTE | global $DB; |
50 | |||
51 | $disabled = ''; |
||
52 | if (!is_resource($res)) { |
||
53 | $disabled = 'disabled'; |
||
54 | } |
||
55 | |||
56 | echo <<<HTML |
||
57 | a651e78d | Francois POIROTTE | <h1>Vigilo NMS</h1><form method="post" action="?itemtype=vigilo">
|
58 | 166be9d2 | Francois POIROTTE | <textarea readonly='readonly' $disabled id='vigilo_deploy' style='display: block; width: 99%; height: 380px'>
|
59 | HTML;
|
||
60 | |||
61 | $needs_deploy = false; |
||
62 | $query = <<<SQL |
||
63 | SELECT `value`
|
||
64 | FROM `glpi_plugin_vigilo_config`
|
||
65 | WHERE `key` = 'needs_deploy';
|
||
66 | SQL;
|
||
67 | |||
68 | $result = $DB->query($query); |
||
69 | if ($result) { |
||
70 | $needs_deploy = (int) $DB->result($result, 0, "value"); |
||
71 | } |
||
72 | efcf5ecf | Francois POIROTTE | |
73 | if (is_resource($res)) { |
||
74 | ini_set("max_execution_time", 0); |
||
75 | ignore_user_abort(true);
|
||
76 | set_time_limit(0); |
||
77 | |||
78 | do {
|
||
79 | $read = $exc = $pipes; |
||
80 | $write = array(); |
||
81 | |||
82 | $nb = stream_select($read, $write, $exc, static::TIMEOUT, 0); |
||
83 | |||
84 | // Error
|
||
85 | 077e4de7 | Francois POIROTTE | if ($nb === false) { |
86 | efcf5ecf | Francois POIROTTE | echo "UNKNOWN ERROR\n"; |
87 | break;
|
||
88 | } |
||
89 | |||
90 | // Timeout
|
||
91 | if ($nb === 0) { |
||
92 | echo "ERROR: command timed out!\n"; |
||
93 | break;
|
||
94 | } |
||
95 | if (count($exc)) { |
||
96 | echo "UNKNOWN ERROR\n"; |
||
97 | break;
|
||
98 | } |
||
99 | |||
100 | 077e4de7 | Francois POIROTTE | foreach ($read as $stream) { |
101 | efcf5ecf | Francois POIROTTE | echo htmlspecialchars(fread($stream, 1024), ENT_HTML5 | ENT_QUOTES, "utf-8"); |
102 | a5c9df40 | Thibault Louet | }; |
103 | 0e0753c8 | Romain CHOLLET | |
104 | efcf5ecf | Francois POIROTTE | flush();
|
105 | 077e4de7 | Francois POIROTTE | if (feof($pipes[1])) { |
106 | break;
|
||
107 | a5c9df40 | Thibault Louet | } |
108 | efcf5ecf | Francois POIROTTE | } while (1); |
109 | |||
110 | $info = proc_get_status($res); |
||
111 | if ($info === false) { |
||
112 | echo "ERROR: could not determine process status\n"; |
||
113 | 166be9d2 | Francois POIROTTE | $info = array('exitcode' => null); |
114 | efcf5ecf | Francois POIROTTE | } else {
|
115 | 077e4de7 | Francois POIROTTE | if ($info["signaled"]) { |
116 | efcf5ecf | Francois POIROTTE | echo "Command terminated by signal ${info['termsig']}\n"; |
117 | 077e4de7 | Francois POIROTTE | } |
118 | if ($info["stopped"]) { |
||
119 | efcf5ecf | Francois POIROTTE | echo "Command stopped by signal ${info['stopsig']}\n"; |
120 | 077e4de7 | Francois POIROTTE | } |
121 | efcf5ecf | Francois POIROTTE | echo "Command exited with return code ${info['exitcode']}\n"; |
122 | } |
||
123 | proc_close($res);
|
||
124 | 166be9d2 | Francois POIROTTE | |
125 | if (isset($info['exitcode']) && 0 === $info['exitcode']) { |
||
126 | $query = "UPDATE `glpi_plugin_vigilo_config` SET `value` = 0 WHERE `key` = 'needs_deploy';"; |
||
127 | $DB->query($query); |
||
128 | } |
||
129 | } elseif ($needs_deploy) { |
||
130 | 945f4815 | Francois POIROTTE | echo __('Click on "Deploy the configuration" to apply changes.', "vigilo"); |
131 | 166be9d2 | Francois POIROTTE | } else {
|
132 | 945f4815 | Francois POIROTTE | echo __("The configuration is already up-to-date.", "vigilo"); |
133 | efcf5ecf | Francois POIROTTE | } |
134 | |||
135 | 19eadf52 | Francois POIROTTE | $force = empty($_POST['force']) ? '' : 'checked'; |
136 | $debug = empty($_POST['debug']) ? '' : 'checked'; |
||
137 | 411a1293 | Francois POIROTTE | $debug_title = htmlspecialchars( |
138 | __("Display debug and progress information for Vigilo", "vigilo"), |
||
139 | ENT_XML1 | ENT_QUOTES, |
||
140 | "utf-8"
|
||
141 | ); |
||
142 | $debug_label = self::escape(__("Display debug information", "vigilo")); |
||
143 | $force_title = self::escape(__("Force a full deployment rather than an incremental one", "vigilo")); |
||
144 | $force_label = self::escape(__("Regenerate all files", "vigilo")); |
||
145 | $deploy_title = self::escape(__("Deploy the configuration", "vigilo")); |
||
146 | 19eadf52 | Francois POIROTTE | echo <<<HTML |
147 | </textarea>
|
||
148 |
|
||
149 | 945f4815 | Francois POIROTTE | <button type="submit" name="deploy" value="1">$deploy_title</button>
|
150 | 19eadf52 | Francois POIROTTE |
|
151 | 411a1293 | Francois POIROTTE | <label for="debug"><input name="debug" id="debug" value="1"
|
152 | type="checkbox" $debug title="$debug_title"/> $debug_label</label>
|
||
153 | 19eadf52 | Francois POIROTTE |
|
154 | 411a1293 | Francois POIROTTE | <label for="force"><input name="force" id="force" value="1"
|
155 | type="checkbox" $force title="$force_title"/> $force_label</label>
|
||
156 | 19eadf52 | Francois POIROTTE | HTML;
|
157 | efcf5ecf | Francois POIROTTE | Html::closeForm();
|
158 | } |
||
159 | } |