File: vps.php

package info (click to toggle)
dtc 0.35.5-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 18,824 kB
  • sloc: php: 50,739; sh: 8,596; makefile: 572; perl: 148; xml: 25
file content (164 lines) | stat: -rw-r--r-- 4,255 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php

function checkVPSAdmin($adm_login,$adm_pass,$vps_node,$vps_name){
	global $pro_mysql_vps_table;
	checkLoginPass($adm_login,$adm_pass);
	$q = "SELECT * FROM $pro_mysql_vps_table WHERE owner='$adm_login' AND vps_server_hostname='".mysql_real_escape_string($vps_node)."' AND vps_xen_name='".mysql_real_escape_string($vps_name)."';";
	$r = mysql_query($q)or die("Cannot query \"$q\" line ".__LINE__." file ".__FILE__." sql said: ".mysql_error());
	$n = mysql_num_rows($r);
	if($n == 1){
		return true;
	}else{
		return false;
	}
}

function connectToVPSServer($vps_node){
	global $pro_mysql_vps_server_table;
	$q = "SELECT * FROM $pro_mysql_vps_server_table WHERE hostname='$vps_node';";
	$r = mysql_query($q)or die("Cannot query \"$q\" line ".__LINE__." file ".__FILE__." sql said: ".mysql_error());
	$n = mysql_num_rows($r);
	if($n != 1){
		die("Cannot find hostname $vps_node of VPS server line ".__LINE__." file ".__FILE__);
	}
	$a = mysql_fetch_array($r);
	$port = 8089;
	$soap_client = new nusoap_client("https://$vps_node:$port/");
	$err = $soap_client->getError();
	if($err){
		echo "Error: ".$err;
		return false;
	}

	$soap_client->setCredentials($a["soap_login"], $a["soap_pass"]);
	$err = $soap_client->getError();
	if($err){
		echo "Error: ".$err;
		return false;
	}
	return $soap_client;
}

function isVPSNodeLVMEnabled($vps_node){
	global $pro_mysql_vps_server_table;
	$q = "SELECT * FROM $pro_mysql_vps_server_table WHERE hostname='$vps_node';";
	$r = mysql_query($q)or die("Cannot query \"$q\" line ".__LINE__." file ".__FILE__." sql said: ".mysql_error());
	$n = mysql_num_rows($r);
	if($n != 1){
		die("Cannot find hostname of VPS server line ".__LINE__." file ".__FILE__);
	}
	$a = mysql_fetch_array($r);
	if (isset($a["lvmenable"])){
		return $a["lvmenable"];
	}else{
		// default to yes
		return "yes";
	}
}

function getVPSIso($vps_node,$vps_name,$soap_client){
	global $vps_soap_err;
	$r = $soap_client->call("reportInstalledIso",array("vpsname" => "xen".$vps_name),"","","");
	$err = $soap_client->getError();
	if($err){
		$vps_soap_err = _("Could not get installed .iso files. Error: ").$err;
	}
	return $r;
}

function getVPSInfo($vps_node,$vps_name,$soap_client){
	global $vps_soap_err;
	$r = $soap_client->call("getVPSState",array("vpsname" => "xen".$vps_name),"","","");
	$err = $soap_client->getError();
	if($err){
		$vps_soap_err = _("Could not get virtual machine info. Error: ").$err;
		return false;
	}else{
		$out = array();
		// To see what's happening, just do a print_r($r); and you will see...
		// This type of result is seen on Xen 2
		//echo "<pre>"; print_r($r); echo "</pre>";
		if($r == "Not running"){
			$vps_soap_err = "VPS server reported VPS not running";
			return false;
		}
		if($r == "fsck" || $r == "mkos"){
			return $r;
		}
		if(isset($r["Result"])){
			$out["xen_type"] = 2;
			$rez = $r["Result"];
		// This one on Xen 3
		}else{
			$out["xen_type"] = 3;
			$rez = $r;
		}
		$n = sizeof($rez);
		for($i=0;$i<$n;$i++){
			$a = $rez[$i];
			if(is_array($a)){
				switch($a[0]){
				case "id":
					$out["id"] = $a[1];
					break;
				case "domid":
					$out["id"] = $a[1];
					break;
				case "name":
					$out["name"] = $a[1];
					break;
				case "memory":
					$out["memory"] = $a[1];
					break;
				case "maxmem":
					$out["maxmem"] = $a[1];
					break;
				case "state":
					$out["state"] = $a[1];
					break;
				case "cpu":
					$out["cpu"] = $a[1];
					break;
				case "vcpus":
					$out["cpu"] = $a[1];
					break;
				case "up_time":
					$out["up_time"] = $a[1];
					break;
				case "start_time":
					$out["start_time"] = $a[1];
					break;
				default:
					break;
				}
			}
		}
		return $out;
	}
}

function getInstallableOS($soap_client){
	global $vps_soap_err;
	$r = $soap_client->call("getInstallableOS",array(),"","","");
	$err = $soap_client->getError();
	if($err){
		$vps_soap_err = "Could not get installable OS data. Error: ".$err;
		return false;
	}else{
		return $r;
	}
}

function getInstallableAPP($soap_client){
	global $vps_soap_err;
	$r = $soap_client->call("getInstallableAPP",array(),"","","");
	$err = $soap_client->getError();
	if($err){
		$vps_soap_err = "Could not get installable APP data. Error: ".$err;
		return false;
	}else{
		return $r;
	}
}

?>