Subversion-Projekte lars-tiefland.openvz_admin

Revision

Revision 165 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
168 lars 1
<?phpphp
162 lars 2
    //$Id: ip.class.php 168 2011-07-10 19:11:02Z lars $
3
    /**
4
     * @author Lars Tiefland
5
     * @copyright 2007
165 lars 6
     * @package    openvz_admin
162 lars 7
     **/
8
    class IP
9
    {
10
        protected $ip;
11
        protected $hn;
12
        protected $dns;
13
        protected $gw;
14
        function __construct( $ip = null, $hn = 0, $dns = 0, $gw = 0 )
15
        {
16
            global $db;
17
            if ( ! is_null( $ip ) )
18
            {
19
                $sql = "SELECT * FROM ips WHERE ip='$ip'";
20
                $res = $db->query( $sql );
21
                $row = $res->fetchRow();
22
                $this->ip = $row["ip"];
23
                $this->hn = $row["hn"];
24
                $this->dns = $row["dns"];
25
                $this->gw = $row["gs"];
26
            }
27
            else
28
            {
29
                $this->ip = $ip;
30
                $this->hn = $hn;
31
                $this->dns = $dns;
32
                $this->gw = $gw;
33
            }
34
        }
26 lars 35
 
162 lars 36
        function toArray()
37
        {
38
            $out["ip"] = $this->ip;
39
            $out["dns"] = $this->dns;
40
            $out["gw"] = $this->gw;
41
            $out["hn"] = $this->hn;
42
            return $out;
43
        }
44
 
45
        static function getIP( $ip_id )
46
        {
47
            global $db;
48
            $sql = "SELECT * FROM ips WHERE id=$ip_id";
49
            $res = $db->query( $sql );
50
            $row = $res->fetchRow();
51
            $ip = new IP( $row["ip"] );
52
            return $ip->toArray();
53
        }
54
 
55
        static function getIPs( $hn = 1, $used = 0, $dns = 0, $gw = 0 )
56
        {
57
            global $db;
58
            $sql = "SELECT id, ip FROM ips WHERE dns=$dns AND gw=$gw AND hn=$hn";
59
            $res = $db->query( $sql );
60
            $out[-1] = "Bitte w&auml;hlen!";
61
            while ( $row = $res->fetchRow() )
62
            {
63
                if ( ! $used )
64
                {
65
                    $sql2 = "SELECT * FROM host_2_ip WHERE ip='" . $row["id"] .
66
                        "'";
67
                    $res2 = $db->query( $sql2 );
68
                    if ( ! $res2->numRows() )
69
                    {
70
                        $out[$row["id"]] = $row["ip"];
71
                    }
72
                }
73
            }
74
            return $out;
75
        }
76
    }
26 lars 77
?>