glpi / inc / menu.class.php @ bef4271a
History | View | Annotate | Download (2.62 KB)
1 |
<?php
|
---|---|
2 |
|
3 |
if (!defined('GLPI_ROOT')) { |
4 |
die("Sorry. You can't access directly to this file"); |
5 |
} |
6 |
|
7 |
|
8 |
class PluginVigiloMenu extends CommonGLPI |
9 |
{ |
10 |
const TIMEOUT = 30; |
11 |
|
12 |
/**
|
13 |
* Name of the type
|
14 |
*
|
15 |
* @param $nb integer number of item in the type (default 0)
|
16 |
**/
|
17 |
static function getTypeName($nb=0) { |
18 |
return 'Vigilo'; |
19 |
} |
20 |
|
21 |
static function canView() { |
22 |
return true; |
23 |
} |
24 |
|
25 |
static function canCreate() { |
26 |
return false; |
27 |
} |
28 |
|
29 |
static function getMenuName() { |
30 |
return self::getTypeName(); |
31 |
} |
32 |
|
33 |
static function getAdditionalMenuOptions() { |
34 |
return array(); |
35 |
} |
36 |
|
37 |
static function getAdditionalMenuContent() { |
38 |
return array(); |
39 |
} |
40 |
|
41 |
static function displayMenu($res, $pipes) { |
42 |
echo '<h1>Vigilo</h1><form method="post" action="?itemtype=vigilo">'; |
43 |
|
44 |
if (is_resource($res)) { |
45 |
ini_set("max_execution_time", 0); |
46 |
ignore_user_abort(true);
|
47 |
set_time_limit(0); |
48 |
|
49 |
echo '<textarea readonly="readonly" id="vigilo_deploy" style="display: block; width: 99%; height: 280px">'; |
50 |
do {
|
51 |
$read = $exc = $pipes; |
52 |
$write = array(); |
53 |
|
54 |
$nb = stream_select($read, $write, $exc, static::TIMEOUT, 0); |
55 |
|
56 |
// Error
|
57 |
if ($nb === FALSE) { |
58 |
echo "UNKNOWN ERROR\n"; |
59 |
break;
|
60 |
} |
61 |
|
62 |
// Timeout
|
63 |
if ($nb === 0) { |
64 |
echo "ERROR: command timed out!\n"; |
65 |
break;
|
66 |
} |
67 |
|
68 |
if (count($exc)) { |
69 |
echo "UNKNOWN ERROR\n"; |
70 |
break;
|
71 |
} |
72 |
|
73 |
foreach ($read as $stream) |
74 |
echo htmlspecialchars(fread($stream, 1024), ENT_HTML5 | ENT_QUOTES, "utf-8"); |
75 |
ob_flush(); |
76 |
flush();
|
77 |
|
78 |
if (feof($pipes[1])) |
79 |
break;
|
80 |
} while (1); |
81 |
|
82 |
$info = proc_get_status($res); |
83 |
if ($info === false) { |
84 |
echo "ERROR: could not determine process status\n"; |
85 |
} else {
|
86 |
if ($info["signaled"]) |
87 |
echo "Command terminated by signal ${info['termsig']}\n"; |
88 |
if ($info["stopped"]) |
89 |
echo "Command stopped by signal ${info['stopsig']}\n"; |
90 |
echo "Command exited with return code ${info['exitcode']}\n"; |
91 |
} |
92 |
|
93 |
proc_close($res);
|
94 |
echo '</textarea>'; |
95 |
} |
96 |
|
97 |
echo '<button type="submit" name="deploy" value="1">Deploy</button>'; |
98 |
Html::closeForm();
|
99 |
} |
100 |
} |