Subversion-Projekte lars-tiefland.openvz_admin

Revision

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

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