Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

glpi / src / inc / menu.class.php @ 077e4de7

History | View | Annotate | Download (2.66 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 true;
20
    }
21

    
22
    public static function canCreate()
23
    {
24
        return false;
25
    }
26

    
27
    public static function getMenuName()
28
    {
29
        return self::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
    public static function displayMenu($res, $pipes)
43
    {
44
        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
                if ($nb === false) {
60
                    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
                foreach ($read as $stream) {
75
                    echo htmlspecialchars(fread($stream, 1024), ENT_HTML5 | ENT_QUOTES, "utf-8");
76
                };
77

    
78
                flush();
79
                if (feof($pipes[1])) {
80
                    break;
81
                }
82
            } 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
                if ($info["signaled"]) {
89
                    echo "Command terminated by signal ${info['termsig']}\n";
90
                }
91
                if ($info["stopped"]) {
92
                    echo "Command stopped by signal ${info['stopsig']}\n";
93
                }
94
                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
}