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 (410 lines) | stat: -rw-r--r-- 16,376 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<?php

function remoteVPSAction($vps_node,$vps_name,$action){
	$soap_client = connectToVPSServer($vps_node);
	if($soap_client === false){
		echo "<font color=\"red\">". _("Could not connect to VPS server.") ."</font>";
		return;
	}
	switch($action){
	case "start_vps":
		$r = $soap_client->call("startVPS",array("vpsname" => "xen".$vps_name),"","","");
		break;
	case "destroy_vps":
		$r = $soap_client->call("destroyVPS",array("vpsname" => "xen".$vps_name),"","","");
		break;
	case "shutdown_vps":
		$r = $soap_client->call("shutdownVPS",array("vpsname" => "xen".$vps_name),"","","");
		break;
	case "kill_vps_disk":
		$r = $soap_client->call("killVPS",array("vpsname" => $vps_name),"","","");
		break;
	default:
		break;
	}
	$err = $soap_client->getError();
	if(!$err){
	//    echo "Result: ".print_r($r);
	}else{
		echo "Error: ".$err;
	}
}

if(isset($_REQUEST["action"]) && $_REQUEST["action"] == "set_vps_monitoring_values"){
// email_addr monitor_ping monitor_ssh monitor_http monitor_smtp monitor_pop3 monitor_imap4
	if(checkVPSAdmin($adm_login,$adm_pass,$vps_node,$vps_name) != true){
		$submit_err = _("Access not granted line ") .__LINE__. _(" file ") .__FILE__;
		$commit_flag = "no";
	}
	if(!isValidEmail($_REQUEST["email_addr"])){
		$submit_err = _("Wrong email format for the monitoring email address");
		$commit_flag = "no";
	}
	if($commit_flag == "yes"){
		if(isset($_REQUEST["monitor_ping"]) && $_REQUEST["monitor_ping"] == "yes"){
			$monitor_ping = "yes";
		}else{
			$monitor_ping = "no";
		}
		if(isset($_REQUEST["monitor_ssh"]) && $_REQUEST["monitor_ssh"] == "yes"){
			$monitor_ssh = "yes";
		}else{
			$monitor_ssh = "no";
		}
		if(isset($_REQUEST["monitor_http"]) && $_REQUEST["monitor_http"] == "yes"){
			$monitor_http = "yes";
		}else{
			$monitor_http = "no";
		}
		if(isset($_REQUEST["monitor_smtp"]) && $_REQUEST["monitor_smtp"] == "yes"){
			$monitor_smtp = "yes";
		}else{
			$monitor_smtp = "no";
		}
		if(isset($_REQUEST["monitor_pop3"]) && $_REQUEST["monitor_pop3"] == "yes"){
			$monitor_pop3 = "yes";
		}else{
			$monitor_pop3 = "no";
		}
		if(isset($_REQUEST["monitor_imap4"]) && $_REQUEST["monitor_imap4"] == "yes"){
			$monitor_imap4 = "yes";
		}else{
			$monitor_imap4 = "no";
		}
		if(isset($_REQUEST["monitor_ftp"]) && $_REQUEST["monitor_ftp"] == "yes"){
			$monitor_ftp = "yes";
		}else{
			$monitor_ftp = "no";
		}
		$q = "UPDATE $pro_mysql_vps_table SET monitoring_email='".$_REQUEST["email_addr"]."',
monitor_ping='$monitor_ping', monitor_ssh='$monitor_ssh', monitor_http='$monitor_http', monitor_smtp='$monitor_smtp', monitor_pop3='$monitor_pop3',
monitor_imap4='$monitor_imap4', monitor_ftp='$monitor_ftp' WHERE vps_xen_name='$vps_name' AND vps_server_hostname='$vps_node';";
		$r = mysql_query($q)or die("Cannot query $q line ".__LINE__." file ".__FILE__." sql said: ".mysql_error());

		updateUsingCron("gen_nagios='yes'");
	}
}

if(isset($_REQUEST["action"]) && ($_REQUEST["action"] == "shutdown_vps" || $_REQUEST["action"] == "destroy_vps" || $_REQUEST["action"] == "start_vps")){
	if(checkVPSAdmin($adm_login,$adm_pass,$vps_node,$vps_name) == true){
		$q = "SELECT * FROM $pro_mysql_vps_table WHERE vps_xen_name='$vps_name' AND vps_server_hostname='$vps_node' AND locked='no';";
		$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){
			$submit_err = _("Access not granted (VPS is locked), line ") .__LINE__. _(" file ") .__FILE__;
		}
		remoteVPSAction($vps_node,$vps_name,$_REQUEST["action"]);
	}else{
		$submit_err = _("Access not granted line ") .__LINE__. _(" file ") .__FILE__;
	}
}
if(isset($_REQUEST["action"]) && ($_REQUEST["action"] == "set_ip_reverse_dns")){
	if(checkVPSAdmin($adm_login,$adm_pass,$vps_node,$vps_name) == true){
		if(!isIP($_REQUEST["ip_addr"])){
			$submit_err = _("This is not a correct IP line ") .__LINE__. _(" file ") .__FILE__;
		}else{
			if(!isHostnameOrIP($_REQUEST["rdns"])){
				$submit_err = _("This is not a correct hostname or IP line ") .__LINE__. _(" file ") .__FILE__;
			}else{
				$q = "SELECT * FROM $pro_mysql_vps_ip_table WHERE ip_addr='".$_REQUEST["ip_addr"]."' AND vps_xen_name='$vps_name' AND vps_server_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){
					$submit_err = _("Access not granted line ") .__LINE__. _(" file ") .__FILE__;
				}else{
					$q = "UPDATE $pro_mysql_vps_ip_table SET rdns_addr='".$_REQUEST["rdns"]."',rdns_regen='yes' WHERE ip_addr='".$_REQUEST["ip_addr"]."';";
					$r = mysql_query($q)or die("Cannot query $q line ".__LINE__." file ".__FILE__." sql said: ".mysql_error());
					$q = "SELECT $pro_mysql_ip_pool_table.zone_type
					FROM $pro_mysql_vps_ip_table,$pro_mysql_ip_pool_table
					WHERE $pro_mysql_vps_ip_table.ip_addr='".$_REQUEST["ip_addr"]."'
					AND $pro_mysql_ip_pool_table.id=$pro_mysql_vps_ip_table.ip_pool_id;";
					$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){
						$submit_err = _("Could not find the corresponding IP pool");
					}else{
						$a = mysql_fetch_array($r);
						if($a["zone_type"] == "support_ticket"){
							$submit_err = _("This IP pool can't be changed automatically, because our upstream network provider doesn't support it. Please open a support ticket to request this RDNS request.");
						}
					}
					updateUsingCron("gen_named='yes',gen_reverse='yes',reload_named='yes'");
				}
			}
		}
	}else{
		$submit_err = _("Access not granted line ") .__LINE__. _(" file ") .__FILE__;
	}
}

if(isset($_REQUEST["action"]) && $_REQUEST["action"] == "change_xm_console_ssh_passwd"){
	if(!isDTCPassword($_REQUEST["new_password"])){
		$submit_err = _("The password you have submited is not a valid password") ;
		$commit_flag = "no";
	}
	if(checkVPSAdmin($adm_login,$adm_pass,$vps_node,$vps_name) != true){
		$submit_err = _("Access not granted line ") .__LINE__. _(" file ") .__FILE__;
		$commit_flag = "no";
	}
	if($commit_flag == "yes"){
		$soap_client = connectToVPSServer($vps_node);
		if($soap_client === false){
			echo "<font color=\"red\">". _("Could not connect to VPS server.") ."</font>";
			return;
		}
		$r = $soap_client->call("changeVPSxmPassword",array("vpsname" => "xen".$vps_name,"password" => $_REQUEST["new_password"]),"","","");
		$err = $soap_client->getError();
		if(!$err){
		}else{
			echo _("Error: ") .$err;
		}
	}
}

if(isset($_REQUEST["action"]) && $_REQUEST["action"] == "change_xm_console_ssh_key"){
	if(checkVPSAdmin($adm_login,$adm_pass,$vps_node,$vps_name) != true){
		$submit_err = _("Access not granted line ") .__LINE__. _(" file ") .__FILE__;
		$commit_flag = "no";
	}
	if( !isSSHKey($_REQUEST["new_key"])){
		$commit_flag = "no";
		$submit_err = "Need to add the code for checking ssh key string validity.";
	}
	if($commit_flag == "yes"){
		$soap_client = connectToVPSServer($vps_node);
		if($soap_client === false){
			echo "<font color=\"red\">". _("Could not connect to VPS server.") ."</font>";
			return;
		}
		$r = $soap_client->call("changeVPSsshKey",array("vpsname" => "xen".$vps_name,"keystring" => $_REQUEST["new_key"]),"","","");
		$err = $soap_client->getError();
		if(!$err){
		}else{
			echo "Error: ".$err;
		}
	}
}

if(isset($_REQUEST["action"]) && $_REQUEST["action"] == "fsck_vps"){
	if(checkVPSAdmin($adm_login,$adm_pass,$vps_node,$vps_name) != true){
		$submit_err = _("Access not granted line ") .__LINE__. _(" file ") .__FILE__;
		$commit_flag = "no";
	}
	if($commit_flag == "yes"){
		$soap_client = connectToVPSServer($vps_node);
		if($soap_client === false){
			echo "<font color=\"red\">". _("Could not connect to VPS server.") ."</font>";
			return;
		}
		$r = $soap_client->call("fsckVPSpartition",array("vpsname" => "xen".$vps_name),"","","");
	}
}

if(isset($_REQUEST["action"]) && $_REQUEST["action"] == "reinstall_os"){
	if(checkVPSAdmin($adm_login,$adm_pass,$vps_node,$vps_name) != true){
		$submit_err = _("Access not granted line ") .__LINE__. _(" file ") .__FILE__;
		$commit_flag = "no";
	}
	// Os name checking is now more relaxed as this is customizable by the dtc-xen server
	if(!isFtpLogin($_REQUEST["os_type"])){
		$submit_err = "OS type is not corret ".__LINE__." file ".__FILE__;
		$commit_flag = "no";
	}
	if(!isDTCPassword($_REQUEST["root_password"])){
		$submit_err = "Root password is not a valid password";
		$commit_flag = "no";
	}
	$q = "SELECT * FROM $pro_mysql_vps_table WHERE vps_xen_name='$vps_name' AND vps_server_hostname='$vps_node';";
	$r = mysql_query($q)or die("Cannot execute query \"$q\" ! line: ".__LINE__." file: ".__FILE__." sql said: ".mysql_error());
	$n = mysql_num_rows($r);
	if($n != 1){
		$commit_flag = "no";
		$submit_err = _("Cannot get VPS information line ") .__LINE__. _(" file ") .__FILE__;
	}
	$ze_vps = mysql_fetch_array($r);

	// Get all IP addresses
	$q = "SELECT * FROM $pro_mysql_vps_ip_table WHERE vps_xen_name='$vps_name' AND vps_server_hostname='$vps_node' AND available='no';";
	$r = mysql_query($q)or die("Cannot execute query \"$q\" ! line: ".__LINE__." file: ".__FILE__." sql said: ".mysql_error());
	$n = mysql_num_rows($r);
	if($n < 1){
		$commit_flag = "no";
		$submit_err = _("Cannot get VPS IP addresses information line ") .__LINE__. _(" file ") .__FILE__;
	}
	$NICS = "";
	for($i=0;$i<$n;$i++){
		$iparray = mysql_fetch_array($r);
		$vps_ip = $iparray["ip_addr"];
		$pool_id = $iparray["ip_pool_id"];
		$q2 = "SELECT * FROM $pro_mysql_ip_pool_table WHERE id='$pool_id';";
		$r2 = mysql_query($q2)or die("Cannot execute query \"".$q2."\" ! line: ".__LINE__." file: ".__FILE__." sql said: ".mysql_error());
		$n2 = mysql_num_rows($r2);
		if($n2 != 1){
			$commit_flag = "no";
			$submit_err = _("Cannot get VPS IP pool addresses information line ") .__LINE__. _(" file ") .__FILE__;
		}else{
			$a2 = mysql_fetch_array($r2);
			$nic = $vps_ip . "," . $a2["netmask"] . "," . $a2["broadcast"];
			if($i == 0){
				$gateway = $a2["gateway"];
				$dns = $a2["dns"];
				$NICS = $nic;
			}else{
				$NICS .= "+".$nic;
			}
		}
	}

	if($commit_flag == "yes"){
		$soap_client = connectToVPSServer($vps_node);
		if($soap_client === false){
			echo "<font color=\"red\">". _("Could not connect to VPS server.") ."</font>";
			return;
		}

		$q = "UPDATE $pro_mysql_vps_table SET operatingsystem='".$_REQUEST["os_type"]."' WHERE vps_xen_name='$vps_name' AND vps_server_hostname='$vps_node';";
		$r = mysql_query($q)or die("Cannot execute query \"$q\" ! line: ".__LINE__." file: ".__FILE__." sql said: ".mysql_error());
		if($_REQUEST["os_type"] != "netbsd"){
			if (isVPSNodeLVMEnabled($vps_node) == "no"){
				$image_type = "vbd";	
			}else{
				$image_type = "lvm";
			}
			// On this one we pass only "XX" and not "xenXX" as parameter !
			$r = $soap_client->call("reinstallVPSos",array(
				"vpsname" => $vps_name,
				"ostype" => $_REQUEST["os_type"],
				"ramsize" => $ze_vps["ramsize"],
				"password" => $_REQUEST["root_password"],
				"nics" => $NICS,
				"gateway" => $gateway,
				"dns" => $dns),"","","");
		}
	}
}

if( isset($_REQUEST["action"]) && $_REQUEST["action"] == "change_xenhvm_boot_iso"){
	if(checkVPSAdmin($adm_login,$adm_pass,$vps_node,$vps_name) != true){
		$submit_err = _("Access not granted line ") .__LINE__. _(" file ") .__FILE__;
		$commit_flag = "no";
	}
	$soap_client = connectToVPSServer($vps_node);
	if($soap_client === false){
		$submit_err = _("Could not connect to VPS server.");
		$commit_flag = "no";
	}
	if( $commit_flag == "yes" && $_REQUEST["xenhvm_iso"] != "hdd"){
		$r = $soap_client->call("reportInstalledIso",array("vpsname" => "xen".$vps_name),"","","");
		$err = $soap_client->getError();
                if($err){
                	$submit_err = _("Could not get installed ISO files.");
                	$commit_flag = "no";
		}else{
			if( ! in_array($_REQUEST["xenhvm_iso"],$r)){
				$submit_err = _("The ISO file is not in the server.");
				$commit_flag = "no";
			}
		}
	}
	if( $_REQUEST["vnc_console_activate"] == "no" || !isDTCPassword( $_REQUEST["vnc_console_pass"])){
		$vnc_console_pass = "no_vnc";
	}else{
		$vnc_console_pass = $_REQUEST["vnc_console_pass"];
	}
	if( !isDTCPassword( $_REQUEST["vnc_console_pass"]) && $_REQUEST["vnc_console_activate"] == "yes"){
		echo "<font color=\"yes\">" . _("Warning: incorrect password format, DTC will disable VNC console.");
	}
	if( $commit_flag == "yes"){
		$q = "UPDATE $pro_mysql_vps_table SET vncpassword='".mysql_real_escape_string($vnc_console_pass)."',howtoboot='".mysql_real_escape_string($_REQUEST["xenhvm_iso"])."' WHERE vps_xen_name='$vps_name' AND vps_server_hostname='$vps_node';";
		$r = mysql_query($q)or die("Cannot execute query \"$q\" ! line: ".__LINE__." file: ".__FILE__." sql said: ".mysql_error());
		$q = "SELECT * FROM $pro_mysql_vps_table WHERE vps_xen_name='$vps_name' AND vps_server_hostname='$vps_node';";
		$r = mysql_query($q)or die("Cannot execute query \"$q\" ! line: ".__LINE__." file: ".__FILE__." sql said: ".mysql_error());
		$n = mysql_num_rows($r);
		if($n != 1){
			$commit_flag = "no";
			$submit_err = _("Could not fetch the VPS data.");
		}else{
			$a = mysql_fetch_array($r);
			$q = "SELECT * FROM $pro_mysql_vps_ip_table WHERE vps_server_hostname='" . $a["vps_server_hostname"]. "' AND vps_xen_name='" .$a["vps_xen_name"]. "';";
			$r = mysql_query($q)or die("Cannot execute query \"$q\" ! line: ".__LINE__." file: ".__FILE__." sql said: ".mysql_error());
			$n_ip = mysql_num_rows($r);
			$ips = "";
			for($i=0;$i<$n_ip;$i++){
				if($i != 0){
					$ips .= " ";
				}
				$a2 = mysql_fetch_array($r);
				$ips .= $a2["ip_addr"];
			}
			// echo "Now calling writeXenHVMconf with" . "xen".$vps_name . " " . $a["ramsize"] . " '$ips' ". $_REQUEST["vnc_console_pass"] . " " . $_REQUEST["xenhvm_iso"];
			$r = $soap_client->call("writeXenHVMconf",array(
					"vpsname" => $vps_name,
					"ramsize" => $a["ramsize"],
					"allipaddrs" => $ips,
					"vncpassword" => $vnc_console_pass,
					"howtoboot" => $_REQUEST["xenhvm_iso"]),
					"","","");
		}
	}
}

if(isset($_REQUEST["action"]) && $_REQUEST["action"] == "change_bsd_kernel_type"){
	if(checkVPSAdmin($adm_login,$adm_pass,$vps_node,$vps_name) != true){
		$submit_err = _("Access not granted line ") .__LINE__. _(" file ") .__FILE__;
		$commit_flag = "no";
	}
	switch($_REQUEST["bsdkernel"]){
	case "normal":
	case "install":
		break;
	default:
		$submit_err = _("BSD kernel type is not correct line ") .__LINE__. _(" file ") .__FILE__;
		$commit_flag = "no";
		break;
	}

	$q = "SELECT * FROM $pro_mysql_vps_table WHERE vps_xen_name='$vps_name' AND vps_server_hostname='$vps_node';";
	$r = mysql_query($q)or die("Cannot execute query \"$q\" ! line: ".__LINE__." file: ".__FILE__." sql said: ".mysql_error());
	$n = mysql_num_rows($r);
	if($n != 1){
		$commit_flag = "no";
		$submit_err = _("Cannot get VPS information line ") .__LINE__. _(" file ") .__FILE__;
	}
	$ze_vps = mysql_fetch_array($r);

	// Get all IP addresses
	$q = "SELECT * FROM $pro_mysql_vps_ip_table WHERE vps_xen_name='$vps_name' AND vps_server_hostname='$vps_node' AND available='no';";
	$r = mysql_query($q)or die("Cannot execute query \"$q\" ! line: ".__LINE__." file: ".__FILE__." sql said: ".mysql_error());
	$n = mysql_num_rows($r);
	if($n < 1){
		$commit_flag = "no";
		$submit_err = _("Cannot get VPS IP addresses information line ") .__LINE__. _(" file ") .__FILE__;
	}
	$vps_all_ips = "";
	for($i=0;$i<$n;$i++){
		$iparray = mysql_fetch_array($r);
		if($i == 0){
			$ze_vps_ip = $iparray;
		}else{
			$vps_all_ips .= " ";
		}
		$vps_all_ips .= $iparray["ip_addr"];
	}

	if($commit_flag == "yes"){
		$soap_client = connectToVPSServer($vps_node);
		if($soap_client === false){
			echo "<font color=\"red\">". _("Could not connect to VPS server.") ."</font>";
			return;
		}
		$q = "UPDATE $pro_mysql_vps_table SET bsdkernel='".$_REQUEST["bsdkernel"]."' WHERE vps_xen_name='$vps_name' AND vps_server_hostname='$vps_node';";
		$r = mysql_query($q)or die("Cannot execute query \"$q\" ! line: ".__LINE__." file: ".__FILE__." sql said: ".mysql_error());
		$r = $soap_client->call("changeBSDkernel",array(
			"vpsname" => $vps_name,
			"ramsize" => $ze_vps["ramsize"],
			"kerneltype" => $_REQUEST["bsdkernel"],
			"allipaddrs" => $vps_all_ips),"","","");
	}
}

?>