Subversion-Projekte lars-tiefland.openvz_admin

Revision

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