glpi / src / inc / menu.class.php @ ad6689da
History | View | Annotate | Download (2.66 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 | efcf5ecf | Francois POIROTTE | return true; |
20 | } |
||
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 | efcf5ecf | Francois POIROTTE | return self::getTypeName(); |
30 | } |
||
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 | efcf5ecf | Francois POIROTTE | echo '<h1>Vigilo</h1><form method="post" action="?itemtype=vigilo">'; |
45 | |||
46 | if (is_resource($res)) { |
||
47 | ini_set("max_execution_time", 0); |
||
48 | ignore_user_abort(true);
|
||
49 | set_time_limit(0); |
||
50 | |||
51 | echo '<textarea readonly="readonly" id="vigilo_deploy" style="display: block; width: 99%; height: 280px">'; |
||
52 | do {
|
||
53 | $read = $exc = $pipes; |
||
54 | $write = array(); |
||
55 | |||
56 | $nb = stream_select($read, $write, $exc, static::TIMEOUT, 0); |
||
57 | |||
58 | // Error
|
||
59 | 077e4de7 | Francois POIROTTE | if ($nb === false) { |
60 | efcf5ecf | Francois POIROTTE | echo "UNKNOWN ERROR\n"; |
61 | break;
|
||
62 | } |
||
63 | |||
64 | // Timeout
|
||
65 | if ($nb === 0) { |
||
66 | echo "ERROR: command timed out!\n"; |
||
67 | break;
|
||
68 | } |
||
69 | if (count($exc)) { |
||
70 | echo "UNKNOWN ERROR\n"; |
||
71 | break;
|
||
72 | } |
||
73 | |||
74 | 077e4de7 | Francois POIROTTE | foreach ($read as $stream) { |
75 | efcf5ecf | Francois POIROTTE | echo htmlspecialchars(fread($stream, 1024), ENT_HTML5 | ENT_QUOTES, "utf-8"); |
76 | a5c9df40 | Thibault Louet | }; |
77 | 0e0753c8 | Romain CHOLLET | |
78 | efcf5ecf | Francois POIROTTE | flush();
|
79 | 077e4de7 | Francois POIROTTE | if (feof($pipes[1])) { |
80 | break;
|
||
81 | a5c9df40 | Thibault Louet | } |
82 | efcf5ecf | Francois POIROTTE | } while (1); |
83 | |||
84 | $info = proc_get_status($res); |
||
85 | if ($info === false) { |
||
86 | echo "ERROR: could not determine process status\n"; |
||
87 | } else {
|
||
88 | 077e4de7 | Francois POIROTTE | if ($info["signaled"]) { |
89 | efcf5ecf | Francois POIROTTE | echo "Command terminated by signal ${info['termsig']}\n"; |
90 | 077e4de7 | Francois POIROTTE | } |
91 | if ($info["stopped"]) { |
||
92 | efcf5ecf | Francois POIROTTE | echo "Command stopped by signal ${info['stopsig']}\n"; |
93 | 077e4de7 | Francois POIROTTE | } |
94 | efcf5ecf | Francois POIROTTE | echo "Command exited with return code ${info['exitcode']}\n"; |
95 | } |
||
96 | |||
97 | proc_close($res);
|
||
98 | echo '</textarea>'; |
||
99 | } |
||
100 | |||
101 | echo '<button type="submit" name="deploy" value="1">Deploy</button>'; |
||
102 | Html::closeForm();
|
||
103 | } |
||
104 | } |