Subversion-Projekte lars-tiefland.openvz_admin

Revision

Revision 168 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
169 lars 1
<?php
78 lars 2
 
162 lars 3
    //$Id: hn.class.php 169 2011-07-10 19:12:37Z lars $
4
    /**
5
     * @author Lars Tiefland
6
     * @copyright 2008
165 lars 7
     * @package    openvzadmin
162 lars 8
     * @filesource
9
     **/
81 lars 10
 
162 lars 11
    /**
12
     *
13
     * defines methos and properties for Hardwarenodes
14
     *
15
     * @author Lars Tiefland
16
     * @copyright 2008
165 lars 17
     * @package    openvzadmin
162 lars 18
     **/
19
    class HN
20
    {
21
        protected $id;
22
        protected $ip;
23
        protected $name;
24
        protected $ve_start;
25
        protected $ve_end;
26
        protected $status;
27
 
28
        function __construct( $ip = null, $name = "", $ve_start = "101", $ve_end =
29
            "199" )
30
        {
31
            global $db;
32
            if ( ! is_null( $ip ) )
33
            {
34
                $sql = "SELECT * FROM hardwarenodes WHERE ip='$ip'";
35
                $res = $db->query( $sql );
36
                $row = $res->fetchRow();
37
                $this->id = $row["id"];
38
                $this->ip = $row["ip"];
39
                $this->name = $row["h_name"];
40
                $this->ve_start = $row["ve_start"];
41
                $this->ve_end = $row["ve_end"];
42
                $this->status = $this->getStatus();
43
            }
44
            else
45
            {
46
                $this->id = 0;
47
                $this->ip = $ip;
48
                $this->name = $name;
49
                $this->ve_start = $ve_start;
50
                $this->ve_end = $ve_end;
51
                $this->status = "online";
52
            }
53
        }
54
 
55
        function toArray()
56
        {
57
            $out["id"] = $this->id;
58
            $out["ip"] = $this->ip;
59
            $out["name"] = $this->name;
60
            $out["ve_start"] = $this->ve_start;
61
            $out["ve_end"] = $this->ve_end;
62
            $out["status"] = $this->status;
63
            return $out;
64
        }
65
 
66
        static function getHN( $hn_id = 1 )
67
        {
68
            global $db;
69
            $sql = "SELECT * FROM hardwarenodes WHERE id=$hn_id";
70
            $res = $db->query( $sql );
71
            $row = $res->fetchRow();
72
            $hn = new HN( $row["ip"] );
73
            return $hn->toArray();
74
        }
75
 
76
        static function getHNs()
77
        {
78
            global $db;
79
            $sql = "SELECT id, h_name FROM hardwarenodes";
80
            $res = $db->query( $sql );
81
            $out[-1] = "Bitte w&auml;hlen!";
82
            while ( $row = $res->fetchRow() )
83
            {
84
                $out[$row["id"]] = $row["h_name"];
85
            }
86
            return $out;
87
        }
88
 
89
        function getStatus()
90
        {
91
            $cmd = "ping $this->name -c1";
92
            exec( $cmd, $out, $ret );
93
            if ( $ret )
94
            {
95
                $status = "offline";
96
            }
97
            else
98
            {
99
                $status = "online";
100
            }
101
            return $status;
102
        }
103
    }
78 lars 104
?>