Subversion-Projekte lars-tiefland.openvz_admin

Revision

Revision 91 | Revision 99 | Zur aktuellen Revision | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php
        //$Id: ip.class.php 92 2008-02-16 23:24:18Z lars $
/**
 * @author Lars Tiefland
 * @copyright 2007
 
 */


        class IP
        {
                protected $ip;
                protected $used;
                protected $dns;
                protected $gw;
                function __construct($ip=NULL, $used=0, $dns=0, $gw=0)
                {
                        global $db;
                        if(!is_null($ip))
                        {
                                $sql="SELECT * FROM ips WHERE ip='$ip'";
                                $res=$db->query($sql);
                                $row=$res->fetchRow();
                                $this->ip=$row["ip"];
                                $this->used=$row["used"];
                                $this->dns=$row["dns"];
                                $this->gw=$row["gs"];
                        }
                        else
                        {
                                $this->ip=$ip;
                                $this->used=$used;
                                $this->dns=$dns;
                                $this->gw=$gw;
                        }
                }
                
                function toArray()
                {
                        $out["ip"]=$this->ip;
                        $out["dns"]=$this->dns;
                        $out["gw"]=$this->gw;
                        $out["used"]=$this->used;
                        return $out;
                }

                static function getIP($ip_id)
                {
                        global $db;
                        $sql="SELECT * FROM ips WHERE id=$ip_id";
                        $res=$db->query($sql);
                        $row=$res->fetchRow();
                        $ip=new IP($row["ip"]);
                        return $ip->toArray();
                }
                
                static function getIPs($used=0, $dns=0, $gw=0)          
                {
                        global $db;
                        $sql="SELECT id, ip FROM ips WHERE dns=$dns AND gw=$gw";
                        $res=$db->query($sql);
                        $out[-1]="Bitte w&auml;hlen!";
                        while($row=$res->fetchRow())
                        {
                                if(!$used)
                                {
                                        $sql2="SELECT * FROM host_2_ip WHERE ip='".$row["id"]."'";
                                        $res2=$db->query($sql2);
                                        if(!$res2->numRows())
                                        {
                                                $out[$row["id"]]=$row["ip"];
                                        }
                                }
                        }
                        return $out;
                }
        }
?>