Subversion-Projekte lars-tiefland.openvz_admin

Revision

Revision 134 | Revision 162 | Zur aktuellen Revision | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php

        //$Id: hn.class.php 139 2008-07-19 19:28:55Z lars $
        /**
         * @author Lars Tiefland
         * @copyright 2008
         * @package     openvzadmin
         * @filesource
         **/
         
        /**
         * 
         * defines methos and properties for Hardwarenodes
         * 
         * @author Lars Tiefland
         * @copyright 2008
         * @package     openvzadmin
         **/
        class HN
        {
                protected $id;
                protected $ip;
                protected $name;
                protected $ve_start;
                protected $ve_end;
                protected $status;
                
                function __construct($ip=NULL,$name="",$ve_start="101",$ve_end="199")
                {
                        global $db;
                        if(!is_null($ip))
                        {
                                $sql="SELECT * FROM hardwarenodes WHERE ip='$ip'";
                                $res=$db->query($sql);
                                $row=$res->fetchRow();
                                $this->id=$row["id"];
                                $this->ip=$row["ip"];
                                $this->name=$row["h_name"];
                                $this->ve_start=$row["ve_start"];
                                $this->ve_end=$row["ve_end"];
                                $this->status=$this->getStatus();
                        }
                        else
                        {
                                $this->id=0;
                                $this->ip=$ip;
                                $this->name=$name;
                                $this->ve_start=$ve_start;
                                $this->ve_end=$ve_end;
                                $this->status="online";
                        }
                }
                
                function toArray()
                {
                        $out["id"]=$this->id;
                        $out["ip"]=$this->ip;
                        $out["name"]=$this->name;
                        $out["ve_start"]=$this->ve_start;
                        $out["ve_end"]=$this->ve_end;
                        $out["status"]=$this->status;
                        return $out;
                }

                static function getHN($hn_id=1)
                {
                        global $db;
                        $sql="SELECT * FROM hardwarenodes WHERE id=$hn_id";
                        $res=$db->query($sql);
                        $row=$res->fetchRow();
                        $hn=new HN($row["ip"]);
                        return $hn->toArray();
                }
                
                static function getHNs()                
                {
                        global $db;
                        $sql="SELECT id, h_name FROM hardwarenodes";
                        $res=$db->query($sql);
                        $out[-1]="Bitte w&auml;hlen!";
                        while($row=$res->fetchRow())
                        {
                                $out[$row["id"]]=$row["h_name"];
                        }
                        return $out;
                }
                
                function getStatus()
                {
                        $cmd="ping $this->name -c1";
                        exec($cmd, $out, $ret);
                        if($ret)
                        {
                                $status="offline";
                        }
                        else
                        {
                                $status="online";
                        }
                        return $status;
                }
        }
?>