glpi / src / plugins / vigilo / inc / menu.class.php @ f1634ea8
History | View | Annotate | Download (4.58 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 |
protected static function escape($s) |
43 |
{ |
44 |
return htmlspecialchars($s, ENT_XML1 | ENT_QUOTES, "utf-8"); |
45 |
} |
46 |
|
47 |
public static function displayMenu($res, $pipes) |
48 |
{ |
49 |
global $DB; |
50 |
|
51 |
$disabled = ''; |
52 |
if (!is_resource($res)) { |
53 |
$disabled = 'disabled'; |
54 |
} |
55 |
|
56 |
echo <<<HTML |
57 |
<h1>Vigilo NMS</h1><form method="post" action="?itemtype=vigilo">
|
58 |
<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 |
|
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 |
if ($nb === false) { |
86 |
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 |
foreach ($read as $stream) { |
101 |
echo htmlspecialchars(fread($stream, 1024), ENT_HTML5 | ENT_QUOTES, "utf-8"); |
102 |
}; |
103 |
|
104 |
flush();
|
105 |
if (feof($pipes[1])) { |
106 |
break;
|
107 |
} |
108 |
} while (1); |
109 |
|
110 |
$info = proc_get_status($res); |
111 |
if ($info === false) { |
112 |
echo "ERROR: could not determine process status\n"; |
113 |
$info = array('exitcode' => null); |
114 |
} else {
|
115 |
if ($info["signaled"]) { |
116 |
echo "Command terminated by signal ${info['termsig']}\n"; |
117 |
} |
118 |
if ($info["stopped"]) { |
119 |
echo "Command stopped by signal ${info['stopsig']}\n"; |
120 |
} |
121 |
echo "Command exited with return code ${info['exitcode']}\n"; |
122 |
} |
123 |
proc_close($res);
|
124 |
|
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 |
echo __('Click on "Deploy the configuration" to apply changes.', "vigilo"); |
131 |
} else {
|
132 |
echo __("The configuration is already up-to-date.", "vigilo"); |
133 |
} |
134 |
|
135 |
$force = empty($_POST['force']) ? '' : 'checked'; |
136 |
$debug = empty($_POST['debug']) ? '' : 'checked'; |
137 |
$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 |
echo <<<HTML |
147 |
</textarea>
|
148 |
|
149 |
<button type="submit" name="deploy" value="1">$deploy_title</button>
|
150 |
|
151 |
<label for="debug"><input name="debug" id="debug" value="1"
|
152 |
type="checkbox" $debug title="$debug_title"/> $debug_label</label>
|
153 |
|
154 |
<label for="force"><input name="force" id="force" value="1"
|
155 |
type="checkbox" $force title="$force_title"/> $force_label</label>
|
156 |
HTML;
|
157 |
Html::closeForm();
|
158 |
} |
159 |
} |