|
|
|
|
@@ -27,9 +27,11 @@ if (file_exists('../modules/addons/pvewhmcs/proxmox.php'))
|
|
|
|
|
else
|
|
|
|
|
require_once(ROOTDIR.'/modules/addons/pvewhmcs/proxmox.php');
|
|
|
|
|
|
|
|
|
|
// Import SQL Connectivity (WHMCS)
|
|
|
|
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
|
|
|
|
|
|
|
|
|
global $guest ;
|
|
|
|
|
// Prepare to source Guest type
|
|
|
|
|
global $guest;
|
|
|
|
|
|
|
|
|
|
// WHMCS CONFIG > SERVICES/PRODUCTS > Their Service > Tab #3 (Plan/Pool)
|
|
|
|
|
function pvewhmcs_ConfigOptions() {
|
|
|
|
|
@@ -45,15 +47,16 @@ function pvewhmcs_ConfigOptions() {
|
|
|
|
|
foreach (Capsule::table('mod_pvewhmcs_ip_pools')->get() as $ippool) {
|
|
|
|
|
$ippools[$ippool->id]=$ippool->title ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
$proxmox=new PVE2_API($server->ipaddress, $server->username, "pam", get_server_pass_from_whmcs($server->password));
|
|
|
|
|
$proxmox = new PVE2_API($server->ipaddress, $server->username, "pam", get_server_pass_from_whmcs($server->password));
|
|
|
|
|
if ($proxmox->login()) {
|
|
|
|
|
# Get first node name.
|
|
|
|
|
$nodes = $proxmox->get_node_list();
|
|
|
|
|
$first_node = $nodes[0];
|
|
|
|
|
unset($nodes);
|
|
|
|
|
|
|
|
|
|
$storage_contents=$proxmox->get('/nodes/'.$first_node.'/storage/local/content') ;
|
|
|
|
|
$storage_contents = $proxmox->get('/nodes/'.$first_node.'/storage/local/content') ;
|
|
|
|
|
|
|
|
|
|
foreach ($storage_contents as $storage_content) {
|
|
|
|
|
if ($storage_content['content']=='vztmpl') {
|
|
|
|
|
@@ -62,6 +65,7 @@ function pvewhmcs_ConfigOptions() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// OPTIONS FOR THE QEMU/LXC PACKAGE; ties WHMCS PRODUCT to MODULE PLAN/POOL
|
|
|
|
|
// Ref: https://developers.whmcs.com/provisioning-modules/config-options/
|
|
|
|
|
// SQL/Param: configoption1 configoption2
|
|
|
|
|
@@ -76,10 +80,11 @@ function pvewhmcs_ConfigOptions() {
|
|
|
|
|
"FriendlyName" => "IP Pool",
|
|
|
|
|
"Type" => "dropdown",
|
|
|
|
|
'Options'=> $ippools,
|
|
|
|
|
"Description" => "Pool to assign VM IP from."
|
|
|
|
|
"Description" => "IPv4 : Allocation Pool"
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Deliver the options back into WHMCS
|
|
|
|
|
return $configarray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -90,31 +95,35 @@ function pvewhmcs_CreateAccount($params) {
|
|
|
|
|
throw new Exception("PVEWHMCS Error: Missing Config. Service/Product WHMCS Config not saved (Plan/Pool not assigned to WHMCS Service type). Check Support/Health tab in Module Config for info. Quick and easy fix.");
|
|
|
|
|
}
|
|
|
|
|
if (empty($params['configoption1'])) {
|
|
|
|
|
throw new Exception("PVEWHMCS Error: Missing Config. Service/Product WHMCS Config not saved (Plan/Pool not assigned to WHMCS Service type). Check Support/Health tab in Module Config for info. Quick and easy fix.");
|
|
|
|
|
throw new Exception("PVEWHMCS Error: Missing Config. Service/Product WHMCS Config not saved (Plan/Pool not assigned to WHMCS Service type). Check Support/Health tab in Module Config for info. Quick and easy fix.");
|
|
|
|
|
}
|
|
|
|
|
if (empty($params['configoption2'])) {
|
|
|
|
|
throw new Exception("PVEWHMCS Error: Missing Config. Service/Product WHMCS Config not saved (Plan/Pool not assigned to WHMCS Service type). Check Support/Health tab in Module Config for info. Quick and easy fix.");
|
|
|
|
|
throw new Exception("PVEWHMCS Error: Missing Config. Service/Product WHMCS Config not saved (Plan/Pool not assigned to WHMCS Service type). Check Support/Health tab in Module Config for info. Quick and easy fix.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Retrieve Plan from table
|
|
|
|
|
// Retrieve Plan from table
|
|
|
|
|
$plan = Capsule::table('mod_pvewhmcs_plans')->where('id', '=', $params['configoption1'])->get()[0];
|
|
|
|
|
|
|
|
|
|
// PVE Host - Connection Info
|
|
|
|
|
$serverip = $params["serverip"];
|
|
|
|
|
$serverusername = $params["serverusername"];
|
|
|
|
|
$serverpassword = $params["serverpassword"];
|
|
|
|
|
|
|
|
|
|
// Prepare the service config array
|
|
|
|
|
$vm_settings = array();
|
|
|
|
|
|
|
|
|
|
// Select an IP address from pool
|
|
|
|
|
// Select an IP Address from Pool
|
|
|
|
|
$ip = Capsule::select('select ipaddress,mask,gateway from mod_pvewhmcs_ip_addresses i INNER JOIN mod_pvewhmcs_ip_pools p on (i.pool_id=p.id and p.id=' . $params['configoption2'] . ') where i.ipaddress not in(select ipaddress from mod_pvewhmcs_vms) limit 1')[0];
|
|
|
|
|
|
|
|
|
|
// CREATE IF QEMU/KVM
|
|
|
|
|
////////////////////////
|
|
|
|
|
// CREATE IF QEMU/KVM //
|
|
|
|
|
////////////////////////
|
|
|
|
|
if (!empty($params['customfields']['KVMTemplate'])) {
|
|
|
|
|
// file_put_contents('d:\log.txt', $params['customfields']['KVMTemplate']);
|
|
|
|
|
|
|
|
|
|
$proxmox = new PVE2_API($serverip, $serverusername, "pam", $serverpassword);
|
|
|
|
|
if ($proxmox->login()) {
|
|
|
|
|
// Get first node name.
|
|
|
|
|
// Get first node name.
|
|
|
|
|
$nodes = $proxmox->get_node_list();
|
|
|
|
|
$first_node = $nodes[0];
|
|
|
|
|
unset($nodes);
|
|
|
|
|
@@ -143,6 +152,7 @@ function pvewhmcs_CreateAccount($params) {
|
|
|
|
|
'subnetmask' => $ip->mask,
|
|
|
|
|
'gateway' => $ip->gateway,
|
|
|
|
|
'created' => date("Y-m-d H:i:s"),
|
|
|
|
|
'v6prefix' => $plan->ipv6,
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
// ISSUE #32 relates - amend post-clone to ensure excludes-disk amendments are all done, too.
|
|
|
|
|
@@ -153,7 +163,7 @@ function pvewhmcs_CreateAccount($params) {
|
|
|
|
|
$cloned_tweaks['cpu'] = $plan->cpuemu;
|
|
|
|
|
$cloned_tweaks['kvm'] = $plan->kvm;
|
|
|
|
|
$cloned_tweaks['onboot'] = $plan->onboot;
|
|
|
|
|
$amendment = $proxmox->post('/nodes/' . $first_node . '/qemu/' . $vm_settings['newid'] . '/config'. $cloned_tweaks);
|
|
|
|
|
$amendment = $proxmox->post('/nodes/' . $first_node . '/qemu/' . $vm_settings['newid'] . '/config', $cloned_tweaks);
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
if (is_array($response) && isset($response['data']['errors'])) {
|
|
|
|
|
@@ -168,28 +178,81 @@ function pvewhmcs_CreateAccount($params) {
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception("Proxmox Error: PVE API login failed. Please check your credentials.");
|
|
|
|
|
}
|
|
|
|
|
// PREPARE SETTINGS FOR QEMU/LXC EVENTUALITIES
|
|
|
|
|
// PREPARE SETTINGS FOR QEMU/LXC EVENTUALITIES
|
|
|
|
|
} else {
|
|
|
|
|
$vm_settings['vmid'] = $params["serviceid"];
|
|
|
|
|
if ($plan->vmtype == 'lxc') {
|
|
|
|
|
/////////////////////////////
|
|
|
|
|
// Process LXC preparation //
|
|
|
|
|
/////////////////////////////
|
|
|
|
|
$vm_settings['ostemplate'] = $plan->storage . ':vztmpl/' . $params['customfields']['Template'];
|
|
|
|
|
$vm_settings['swap'] = $plan->swap;
|
|
|
|
|
$vm_settings['rootfs'] = $plan->storage . ':' . $plan->disk;
|
|
|
|
|
$vm_settings['bwlimit'] = $plan->diskio;
|
|
|
|
|
$vm_settings['net0'] = 'name=eth0,bridge=' . $plan->bridge . $plan->vmbr . ',ip=' . $ip->ipaddress . '/' . mask2cidr($ip->mask) . ',gw=' . $ip->gateway;
|
|
|
|
|
if (!empty($plan->ipv6) && $plan->ipv6 != '0') {
|
|
|
|
|
// Standard prep for the 2nd int.
|
|
|
|
|
$vm_settings['net1'] = 'name=eth1,bridge=' . $plan->bridge . $plan->vmbr;
|
|
|
|
|
// Handling different IPv6 configs
|
|
|
|
|
switch ($plan->ipv6) {
|
|
|
|
|
case 'auto':
|
|
|
|
|
// Passes 'auto' directly, triggering SLAAC
|
|
|
|
|
$vm_settings['net1'] .= ',ip6=auto';
|
|
|
|
|
break;
|
|
|
|
|
case 'dhcp':
|
|
|
|
|
// Passes 'dhcp' directly
|
|
|
|
|
$vm_settings['net1'] .= ',ip6=dhcp';
|
|
|
|
|
break;
|
|
|
|
|
case 'prefix':
|
|
|
|
|
// Placeholder for future development - currently does nothing
|
|
|
|
|
// TODO: Handle 'prefix' case once prefix allocation logic is developed
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// Handle any unexpected IPv6 settings - logging, etc
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// VLAN tag, only for v6
|
|
|
|
|
if(!empty($plan->vlanid)){
|
|
|
|
|
$vm_settings['net1'] .= ',trunk=' . $plan->vlanid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// VLAN tag, only for v4
|
|
|
|
|
if(!empty($plan->vlanid)){
|
|
|
|
|
$vm_settings['net0'] .= ',trunk=' . $plan->vlanid;
|
|
|
|
|
}
|
|
|
|
|
$vm_settings['nameserver'] = '1.1.1.1';
|
|
|
|
|
$vm_settings['nameserver'] = '76.76.2.0 76.76.10.0';
|
|
|
|
|
$vm_settings['onboot'] = $plan->onboot;
|
|
|
|
|
$vm_settings['password'] = $params['customfields']['Password'];
|
|
|
|
|
} else {
|
|
|
|
|
//////////////////////////////
|
|
|
|
|
// Process QEMU preparation //
|
|
|
|
|
//////////////////////////////
|
|
|
|
|
$vm_settings['ostype'] = $plan->ostype;
|
|
|
|
|
$vm_settings['sockets'] = $plan->cpus;
|
|
|
|
|
$vm_settings['cores'] = $plan->cores;
|
|
|
|
|
$vm_settings['cpu'] = $plan->cpuemu;
|
|
|
|
|
$vm_settings['ipconfig0'] = 'ip=' . $ip->ipaddress . '/' . mask2cidr($ip->mask) . ',gw=' . $ip->gateway;
|
|
|
|
|
$vm_settings['nameserver'] = '1.1.1.1';
|
|
|
|
|
if (!empty($plan->ipv6) && $plan->ipv6 != '0') {
|
|
|
|
|
// Handling different IPv6 configs
|
|
|
|
|
switch ($plan->ipv6) {
|
|
|
|
|
case 'auto':
|
|
|
|
|
// Passes 'auto' directly, triggering SLAAC
|
|
|
|
|
$vm_settings['ipconfig1'] = 'ip6=auto';
|
|
|
|
|
break;
|
|
|
|
|
case 'dhcp':
|
|
|
|
|
// Passes 'dhcp' directly
|
|
|
|
|
$vm_settings['ipconfig1'] = 'ip6=dhcp';
|
|
|
|
|
break;
|
|
|
|
|
case 'prefix':
|
|
|
|
|
// Placeholder for future development - currently does nothing
|
|
|
|
|
// TODO: Handle 'prefix' case once prefix allocation logic is developed
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// Handle any unexpected IPv6 settings - logging, etc
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$vm_settings['nameserver'] = '76.76.2.0 76.76.10.0';
|
|
|
|
|
$vm_settings['kvm'] = $plan->kvm;
|
|
|
|
|
$vm_settings['onboot'] = $plan->onboot;
|
|
|
|
|
|
|
|
|
|
@@ -198,13 +261,14 @@ function pvewhmcs_CreateAccount($params) {
|
|
|
|
|
$vm_settings[$plan->disktype . '0'] .= ',cache=' . $plan->diskcache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Assign ISO File
|
|
|
|
|
// Assign ISO File
|
|
|
|
|
if (isset($params['customfields']['ISO'])) {
|
|
|
|
|
$vm_settings['ide2'] = 'local:iso/' . $params['customfields']['ISO'] . ',media=cdrom';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Network settings */
|
|
|
|
|
/* Network Specifics - Bridge, Rate & Trunk/VLAN */
|
|
|
|
|
if ($plan->netmode != 'none') {
|
|
|
|
|
// Perform the additions for IPv4 (net0/ipconfig0)
|
|
|
|
|
$vm_settings['net0'] = $plan->netmodel;
|
|
|
|
|
if ($plan->netmode == 'bridge') {
|
|
|
|
|
$vm_settings['net0'] .= ',bridge=' . $plan->bridge . $plan->vmbr;
|
|
|
|
|
@@ -216,6 +280,20 @@ function pvewhmcs_CreateAccount($params) {
|
|
|
|
|
if (!empty($plan->vlanid)) {
|
|
|
|
|
$vm_settings['net0'] .= ',trunk=' . $plan->vlanid;
|
|
|
|
|
}
|
|
|
|
|
// Check if ipconfig1 exists, and then do the same for net1 if so
|
|
|
|
|
if (isset($vm_settings['ipconfig1'])) {
|
|
|
|
|
$vm_settings['net1'] = $plan->netmodel;
|
|
|
|
|
if ($plan->netmode == 'bridge') {
|
|
|
|
|
$vm_settings['net1'] .= ',bridge=' . $plan->bridge . $plan->vmbr;
|
|
|
|
|
}
|
|
|
|
|
$vm_settings['net1'] .= ',firewall=' . $plan->firewall;
|
|
|
|
|
if (!empty($plan->netrate)) {
|
|
|
|
|
$vm_settings['net1'] .= ',rate=' . $plan->netrate;
|
|
|
|
|
}
|
|
|
|
|
if (!empty($plan->vlanid)) {
|
|
|
|
|
$vm_settings['net1'] .= ',trunk=' . $plan->vlanid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* end of network settings */
|
|
|
|
|
}
|
|
|
|
|
@@ -224,12 +302,14 @@ function pvewhmcs_CreateAccount($params) {
|
|
|
|
|
$vm_settings['cpulimit'] = $plan->cpulimit;
|
|
|
|
|
$vm_settings['memory'] = $plan->memory;
|
|
|
|
|
|
|
|
|
|
// CREATION: Attempt to create the QEMU/LXC instance on Proxmox VE via API
|
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
|
// CREATION: Attempt to Create Guest via PVE2 API //
|
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
|
try {
|
|
|
|
|
$proxmox = new PVE2_API($serverip, $serverusername, "pam", $serverpassword);
|
|
|
|
|
|
|
|
|
|
if ($proxmox->login()) {
|
|
|
|
|
// Get first node name.
|
|
|
|
|
// Get first node name.
|
|
|
|
|
$nodes = $proxmox->get_node_list();
|
|
|
|
|
$first_node = $nodes[0];
|
|
|
|
|
unset($nodes);
|
|
|
|
|
@@ -263,6 +343,7 @@ function pvewhmcs_CreateAccount($params) {
|
|
|
|
|
'subnetmask' => $ip->mask,
|
|
|
|
|
'gateway' => $ip->gateway,
|
|
|
|
|
'created' => date("Y-m-d H:i:s"),
|
|
|
|
|
'v6prefix' => $plan->ipv6,
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
return true;
|
|
|
|
|
@@ -280,8 +361,8 @@ function pvewhmcs_CreateAccount($params) {
|
|
|
|
|
throw new Exception("Proxmox Error: PVE API login failed. Please check your credentials.");
|
|
|
|
|
}
|
|
|
|
|
} catch (PVE2_Exception $e) {
|
|
|
|
|
// Record the error in WHMCS's module log.
|
|
|
|
|
if (Capsule::table('mod_pvewhmcs')->where('id', '1')->value('debug_mode') == 1) {
|
|
|
|
|
// Record the error in WHMCS's module log.
|
|
|
|
|
if (Capsule::table('mod_pvewhmcs')->where('id', '1')->value('debug_mode') == 1) {
|
|
|
|
|
logModuleCall(
|
|
|
|
|
'pvewhmcs',
|
|
|
|
|
__FUNCTION__,
|
|
|
|
|
@@ -297,32 +378,36 @@ function pvewhmcs_CreateAccount($params) {
|
|
|
|
|
|
|
|
|
|
// PVE API FUNCTION, ADMIN: Test Connection with Proxmox node
|
|
|
|
|
function pvewhmcs_TestConnection(array $params) {
|
|
|
|
|
$success = true; // Assume success by default
|
|
|
|
|
try {
|
|
|
|
|
// Call the service's connection test function.
|
|
|
|
|
$serverip = $params["serverip"];
|
|
|
|
|
$serverusername = $params["serverusername"];
|
|
|
|
|
$serverpassword = $params["serverpassword"];
|
|
|
|
|
$proxmox = new PVE2_API($serverip, $serverusername, "pam", $serverpassword);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// Call the service's connection test function.
|
|
|
|
|
$serverip = $params["serverip"];
|
|
|
|
|
$serverusername = $params["serverusername"];
|
|
|
|
|
$serverpassword = $params["serverpassword"];
|
|
|
|
|
$proxmox = new PVE2_API($serverip, $serverusername, "pam", $serverpassword);
|
|
|
|
|
|
|
|
|
|
if (!$proxmox->login()) {
|
|
|
|
|
$success = false; // Set success to false if login fails
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
// Record the error in WHMCS's module log, if debug mode is enabled.
|
|
|
|
|
if (Capsule::table('mod_pvewhmcs')->where('id', '1')->value('debug_mode') == 1) {
|
|
|
|
|
logModuleCall(
|
|
|
|
|
'pvewhmcs',
|
|
|
|
|
__FUNCTION__,
|
|
|
|
|
$params,
|
|
|
|
|
$e->getMessage() . $e->getTraceAsString()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
$success = $e->getMessage(); // Set the error message as the success value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return array('success' => $success); // Return either true or the error
|
|
|
|
|
// Set success if login succeeded
|
|
|
|
|
if ($proxmox->login()) {
|
|
|
|
|
$success = true;
|
|
|
|
|
$errorMsg = '';
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
// Record the error in WHMCS's module log
|
|
|
|
|
logModuleCall(
|
|
|
|
|
'pvewhmcs',
|
|
|
|
|
__FUNCTION__,
|
|
|
|
|
$params,
|
|
|
|
|
$e->getMessage(),
|
|
|
|
|
$e->getTraceAsString()
|
|
|
|
|
);
|
|
|
|
|
// Set the error message as a failure
|
|
|
|
|
$success = false;
|
|
|
|
|
$errorMsg = $e->getMessage();
|
|
|
|
|
}
|
|
|
|
|
// Return success or error, and info
|
|
|
|
|
return array(
|
|
|
|
|
'success' => $success,
|
|
|
|
|
'error' => $errorMsg,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PVE API FUNCTION, ADMIN: Suspend a Service on the hypervisor
|
|
|
|
|
@@ -331,7 +416,7 @@ function pvewhmcs_SuspendAccount(array $params) {
|
|
|
|
|
$serverusername = $params["serverusername"];
|
|
|
|
|
$serverpassword = $params["serverpassword"];
|
|
|
|
|
|
|
|
|
|
$proxmox=new PVE2_API($serverip, $serverusername, "pam", $serverpassword);
|
|
|
|
|
$proxmox = new PVE2_API($serverip, $serverusername, "pam", $serverpassword);
|
|
|
|
|
if ($proxmox->login()) {
|
|
|
|
|
# Get first node name.
|
|
|
|
|
$nodes = $proxmox->get_node_list();
|
|
|
|
|
@@ -353,11 +438,11 @@ function pvewhmcs_SuspendAccount(array $params) {
|
|
|
|
|
}
|
|
|
|
|
// Return success only if no errors returned by PVE
|
|
|
|
|
if (isset($response) && !isset($response['errors'])) {
|
|
|
|
|
return "success";
|
|
|
|
|
return "success";
|
|
|
|
|
} else {
|
|
|
|
|
// Handle the case where there are errors
|
|
|
|
|
$response_message = isset($response['errors']) ? json_encode($response['errors']) : "Unknown Error, consider using Debug Mode.";
|
|
|
|
|
return "Error performing action. " . $response_message;
|
|
|
|
|
// Handle the case where there are errors
|
|
|
|
|
$response_message = isset($response['errors']) ? json_encode($response['errors']) : "Unknown Error, consider using Debug Mode.";
|
|
|
|
|
return "Error performing action. " . $response_message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -367,7 +452,7 @@ function pvewhmcs_UnsuspendAccount(array $params) {
|
|
|
|
|
$serverusername = $params["serverusername"];
|
|
|
|
|
$serverpassword = $params["serverpassword"];
|
|
|
|
|
|
|
|
|
|
$proxmox=new PVE2_API($serverip, $serverusername, "pam", $serverpassword);
|
|
|
|
|
$proxmox = new PVE2_API($serverip, $serverusername, "pam", $serverpassword);
|
|
|
|
|
if ($proxmox->login()) {
|
|
|
|
|
# Get first node name.
|
|
|
|
|
$nodes = $proxmox->get_node_list();
|
|
|
|
|
@@ -389,11 +474,11 @@ function pvewhmcs_UnsuspendAccount(array $params) {
|
|
|
|
|
}
|
|
|
|
|
// Return success only if no errors returned by PVE
|
|
|
|
|
if (isset($response) && !isset($response['errors'])) {
|
|
|
|
|
return "success";
|
|
|
|
|
return "success";
|
|
|
|
|
} else {
|
|
|
|
|
// Handle the case where there are errors
|
|
|
|
|
$response_message = isset($response['errors']) ? json_encode($response['errors']) : "Unknown Error, consider using Debug Mode.";
|
|
|
|
|
return "Error performing action. " . $response_message;
|
|
|
|
|
// Handle the case where there are errors
|
|
|
|
|
$response_message = isset($response['errors']) ? json_encode($response['errors']) : "Unknown Error, consider using Debug Mode.";
|
|
|
|
|
return "Error performing action. " . $response_message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -403,7 +488,7 @@ function pvewhmcs_TerminateAccount(array $params) {
|
|
|
|
|
$serverusername = $params["serverusername"];
|
|
|
|
|
$serverpassword = $params["serverpassword"];
|
|
|
|
|
|
|
|
|
|
$proxmox=new PVE2_API($serverip, $serverusername, "pam", $serverpassword);
|
|
|
|
|
$proxmox = new PVE2_API($serverip, $serverusername, "pam", $serverpassword);
|
|
|
|
|
if ($proxmox->login()){
|
|
|
|
|
# Get first node name.
|
|
|
|
|
$nodes = $proxmox->get_node_list();
|
|
|
|
|
@@ -431,23 +516,25 @@ class hash_encryption {
|
|
|
|
|
* @var string
|
|
|
|
|
**/
|
|
|
|
|
var $hash_key;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* String length of hashed values using the current algorithm
|
|
|
|
|
* @var int
|
|
|
|
|
**/
|
|
|
|
|
var $hash_lenth;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Switch base64 enconding on / off
|
|
|
|
|
* @var bool true = use base64, false = binary output / input
|
|
|
|
|
**/
|
|
|
|
|
var $base64;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Secret value added to randomize output and protect the user provided key
|
|
|
|
|
* @var string Change this value to add more randomness to your encryption
|
|
|
|
|
**/
|
|
|
|
|
var $salt = 'Change this to any secret value you like. "d41d8cd98f00b204e9800998ecf8427e" might be a good example.';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor method
|
|
|
|
|
*
|
|
|
|
|
@@ -617,7 +704,7 @@ class hash_encryption {
|
|
|
|
|
// GENERAL FUNCTION: Server PW from WHMCS DB
|
|
|
|
|
function get_server_pass_from_whmcs($enc_pass){
|
|
|
|
|
global $cc_encryption_hash;
|
|
|
|
|
// Include WHMCS database configuration file
|
|
|
|
|
// Include WHMCS database configuration file
|
|
|
|
|
include_once(dirname(dirname(dirname(dirname(__FILE__)))).'/configuration.php');
|
|
|
|
|
$key1 = md5 (md5 ($cc_encryption_hash));
|
|
|
|
|
$key2 = md5 ($cc_encryption_hash);
|
|
|
|
|
@@ -664,11 +751,11 @@ function pvewhmcs_ClientArea($params) {
|
|
|
|
|
$serverusername = $pveserver->username;
|
|
|
|
|
|
|
|
|
|
$api_data = array(
|
|
|
|
|
'password2' => $pveserver->password,
|
|
|
|
|
'password2' => $pveserver->password,
|
|
|
|
|
);
|
|
|
|
|
$serverpassword = localAPI('DecryptPassword', $api_data);
|
|
|
|
|
|
|
|
|
|
$proxmox=new PVE2_API($serverip, $serverusername, "pam", $serverpassword['password']);
|
|
|
|
|
$proxmox = new PVE2_API($serverip, $serverusername, "pam", $serverpassword['password']);
|
|
|
|
|
if ($proxmox->login()) {
|
|
|
|
|
//$proxmox->setCookie();
|
|
|
|
|
# Get first node name.
|
|
|
|
|
@@ -677,7 +764,7 @@ function pvewhmcs_ClientArea($params) {
|
|
|
|
|
unset($nodes);
|
|
|
|
|
|
|
|
|
|
# Get and set VM variables
|
|
|
|
|
$vm_config=$proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/config') ;
|
|
|
|
|
$vm_config = $proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/config') ;
|
|
|
|
|
$cluster_resources = $proxmox->get('/cluster/resources');
|
|
|
|
|
$vm_status = null;
|
|
|
|
|
|
|
|
|
|
@@ -710,131 +797,132 @@ function pvewhmcs_ClientArea($params) {
|
|
|
|
|
$vm_status['memusepercent'] = intval($vm_status['mem'] * 100 / $vm_status['maxmem']);
|
|
|
|
|
|
|
|
|
|
if ($guest->vtype == 'lxc') {
|
|
|
|
|
$ct_specific=$proxmox->get('/nodes/'.$first_node.'/lxc/'.$params['serviceid'] .'/status/current') ;
|
|
|
|
|
$ct_specific = $proxmox->get('/nodes/'.$first_node.'/lxc/'.$params['serviceid'] .'/status/current') ;
|
|
|
|
|
$vm_status['swapusepercent'] = intval($ct_specific['swap'] * 100 / $ct_specific['maxswap']);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Handle the VM not found in the cluster resources (Optional)
|
|
|
|
|
// Handle the VM not found in the cluster resources (Optional)
|
|
|
|
|
echo "VM/CT not found in Cluster Resources.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Max CPU usage Yearly
|
|
|
|
|
$rrd_params = '?timeframe=year&ds=cpu&cf=AVERAGE';
|
|
|
|
|
$vm_rrd=$proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] . '/rrd' . $rrd_params) ;
|
|
|
|
|
$vm_rrd['image']=utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['cpu']['year']=base64_encode($vm_rrd['image']);
|
|
|
|
|
$vm_rrd = $proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] . '/rrd' . $rrd_params) ;
|
|
|
|
|
$vm_rrd['image'] = utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['cpu']['year'] = base64_encode($vm_rrd['image']);
|
|
|
|
|
|
|
|
|
|
// Max CPU usage monthly
|
|
|
|
|
$rrd_params = '?timeframe=month&ds=cpu&cf=AVERAGE';
|
|
|
|
|
$vm_rrd=$proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image']=utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['cpu']['month']=base64_encode($vm_rrd['image']);
|
|
|
|
|
$vm_rrd = $proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image'] = utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['cpu']['month'] = base64_encode($vm_rrd['image']);
|
|
|
|
|
|
|
|
|
|
// Max CPU usage weekly
|
|
|
|
|
$rrd_params = '?timeframe=week&ds=cpu&cf=AVERAGE';
|
|
|
|
|
$vm_rrd=$proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image']=utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['cpu']['week']=base64_encode($vm_rrd['image']);
|
|
|
|
|
$vm_rrd = $proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image'] = utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['cpu']['week'] = base64_encode($vm_rrd['image']);
|
|
|
|
|
|
|
|
|
|
// Max CPU usage daily
|
|
|
|
|
$rrd_params = '?timeframe=day&ds=cpu&cf=AVERAGE';
|
|
|
|
|
$vm_rrd=$proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image']=utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['cpu']['day']=base64_encode($vm_rrd['image']);
|
|
|
|
|
$vm_rrd = $proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image'] = utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['cpu']['day'] = base64_encode($vm_rrd['image']);
|
|
|
|
|
|
|
|
|
|
// Max memory Yearly
|
|
|
|
|
$rrd_params = '?timeframe=year&ds=maxmem&cf=AVERAGE';
|
|
|
|
|
$vm_rrd=$proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image']=utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['maxmem']['year']=base64_encode($vm_rrd['image']);
|
|
|
|
|
$vm_rrd = $proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image'] = utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['maxmem']['year'] = base64_encode($vm_rrd['image']);
|
|
|
|
|
|
|
|
|
|
// Max memory monthly
|
|
|
|
|
$rrd_params = '?timeframe=month&ds=maxmem&cf=AVERAGE';
|
|
|
|
|
$vm_rrd=$proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image']=utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['maxmem']['month']=base64_encode($vm_rrd['image']);
|
|
|
|
|
$vm_rrd = $proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image'] = utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['maxmem']['month'] = base64_encode($vm_rrd['image']);
|
|
|
|
|
|
|
|
|
|
// Max memory weekly
|
|
|
|
|
$rrd_params = '?timeframe=week&ds=maxmem&cf=AVERAGE';
|
|
|
|
|
$vm_rrd=$proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image']=utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['maxmem']['week']=base64_encode($vm_rrd['image']);
|
|
|
|
|
$vm_rrd = $proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image'] = utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['maxmem']['week'] = base64_encode($vm_rrd['image']);
|
|
|
|
|
|
|
|
|
|
// Max memory daily
|
|
|
|
|
$rrd_params = '?timeframe=day&ds=maxmem&cf=AVERAGE';
|
|
|
|
|
$vm_rrd=$proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image']=utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['maxmem']['day']=base64_encode($vm_rrd['image']);
|
|
|
|
|
$vm_rrd = $proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image'] = utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['maxmem']['day'] = base64_encode($vm_rrd['image']);
|
|
|
|
|
|
|
|
|
|
// Network rate Yearly
|
|
|
|
|
$rrd_params = '?timeframe=year&ds=netin,netout&cf=AVERAGE';
|
|
|
|
|
$vm_rrd=$proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image']=utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['netinout']['year']=base64_encode($vm_rrd['image']);
|
|
|
|
|
$vm_rrd = $proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image'] = utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['netinout']['year'] = base64_encode($vm_rrd['image']);
|
|
|
|
|
|
|
|
|
|
// Network rate monthly
|
|
|
|
|
$rrd_params = '?timeframe=month&ds=netin,netout&cf=AVERAGE';
|
|
|
|
|
$vm_rrd=$proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image']=utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['netinout']['month']=base64_encode($vm_rrd['image']);
|
|
|
|
|
$vm_rrd = $proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image'] = utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['netinout']['month'] = base64_encode($vm_rrd['image']);
|
|
|
|
|
|
|
|
|
|
// Network rate weekly
|
|
|
|
|
$rrd_params = '?timeframe=week&ds=netin,netout&cf=AVERAGE';
|
|
|
|
|
$vm_rrd=$proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image']=utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['netinout']['week']=base64_encode($vm_rrd['image']);
|
|
|
|
|
$vm_rrd = $proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image'] = utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['netinout']['week'] = base64_encode($vm_rrd['image']);
|
|
|
|
|
|
|
|
|
|
// Network rate daily
|
|
|
|
|
$rrd_params = '?timeframe=day&ds=netin,netout&cf=AVERAGE';
|
|
|
|
|
$vm_rrd=$proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image']=utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['netinout']['day']=base64_encode($vm_rrd['image']);
|
|
|
|
|
$vm_rrd = $proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image'] = utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['netinout']['day'] = base64_encode($vm_rrd['image']);
|
|
|
|
|
|
|
|
|
|
// Max IO Yearly
|
|
|
|
|
$rrd_params = '?timeframe=year&ds=diskread,diskwrite&cf=AVERAGE';
|
|
|
|
|
$vm_rrd=$proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image']=utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['diskrw']['year']=base64_encode($vm_rrd['image']);
|
|
|
|
|
$vm_rrd = $proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image'] = utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['diskrw']['year'] = base64_encode($vm_rrd['image']);
|
|
|
|
|
|
|
|
|
|
// Max IO monthly
|
|
|
|
|
$rrd_params = '?timeframe=month&ds=diskread,diskwrite&cf=AVERAGE';
|
|
|
|
|
$vm_rrd=$proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image']=utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['diskrw']['month']=base64_encode($vm_rrd['image']);
|
|
|
|
|
$vm_rrd = $proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image'] = utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['diskrw']['month'] = base64_encode($vm_rrd['image']);
|
|
|
|
|
|
|
|
|
|
// Max IO weekly
|
|
|
|
|
$rrd_params = '?timeframe=week&ds=diskread,diskwrite&cf=AVERAGE';
|
|
|
|
|
$vm_rrd=$proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image']=utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['diskrw']['week']=base64_encode($vm_rrd['image']);
|
|
|
|
|
$vm_rrd = $proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image'] = utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['diskrw']['week'] = base64_encode($vm_rrd['image']);
|
|
|
|
|
|
|
|
|
|
// Max IO daily
|
|
|
|
|
$rrd_params = '?timeframe=day&ds=diskread,diskwrite&cf=AVERAGE';
|
|
|
|
|
$vm_rrd=$proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image']=utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['diskrw']['day']=base64_encode($vm_rrd['image']);
|
|
|
|
|
$vm_rrd = $proxmox->get('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/rrd'.$rrd_params) ;
|
|
|
|
|
$vm_rrd['image'] = utf8_decode($vm_rrd['image']) ;
|
|
|
|
|
$vm_statistics['diskrw']['day'] = base64_encode($vm_rrd['image']);
|
|
|
|
|
|
|
|
|
|
unset($vm_rrd) ;
|
|
|
|
|
|
|
|
|
|
$vm_config['vtype']=$guest->vtype ;
|
|
|
|
|
$vm_config['ipv4']=$guest->ipaddress ;
|
|
|
|
|
$vm_config['netmask4']=$guest->subnetmask ;
|
|
|
|
|
$vm_config['gateway4']=$guest->gateway ;
|
|
|
|
|
$vm_config['created']=$guest->created ;
|
|
|
|
|
$vm_config['vtype'] = $guest->vtype ;
|
|
|
|
|
$vm_config['ipv4'] = $guest->ipaddress ;
|
|
|
|
|
$vm_config['netmask4'] = $guest->subnetmask ;
|
|
|
|
|
$vm_config['gateway4'] = $guest->gateway ;
|
|
|
|
|
$vm_config['created'] = $guest->created ;
|
|
|
|
|
$vm_config['v6prefix'] = $guest->v6prefix ;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo '<center><strong>Unable to contact Hypervisor - aborting!<br>Please contact Tech Support.</strong></center>';
|
|
|
|
|
die;
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return array(
|
|
|
|
|
'templatefile' => 'clientarea',
|
|
|
|
|
'vars' => array(
|
|
|
|
|
'params' => $params,
|
|
|
|
|
'vm_config'=>$vm_config,
|
|
|
|
|
'vm_status'=>$vm_status,
|
|
|
|
|
'vm_statistics'=>$vm_statistics,
|
|
|
|
|
'vm_vncproxy'=>$vm_vncproxy,
|
|
|
|
|
'vm_config' => $vm_config,
|
|
|
|
|
'vm_status' => $vm_status,
|
|
|
|
|
'vm_statistics' => $vm_statistics,
|
|
|
|
|
'vm_vncproxy' => $vm_vncproxy,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
@@ -850,19 +938,21 @@ function pvewhmcs_noVNC($params) {
|
|
|
|
|
if (strlen(Capsule::table('mod_pvewhmcs')->where('id', '1')->value('vnc_secret'))<15) {
|
|
|
|
|
throw new Exception("PVEWHMCS Error: VNC Secret in Module Config either not set or not long enough. Recommend 20+ characters for security.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get login credentials then make the Proxmox connection attempt.
|
|
|
|
|
$serverip = $params["serverip"];
|
|
|
|
|
$serverusername = 'vnc';
|
|
|
|
|
$serverpassword = Capsule::table('mod_pvewhmcs')->where('id', '1')->value('vnc_secret');
|
|
|
|
|
$proxmox=new PVE2_API($serverip, $serverusername, "pve", $serverpassword);
|
|
|
|
|
|
|
|
|
|
$proxmox = new PVE2_API($serverip, $serverusername, "pve", $serverpassword);
|
|
|
|
|
if ($proxmox->login()) {
|
|
|
|
|
# Get first node name.
|
|
|
|
|
// Get first node name
|
|
|
|
|
$nodes = $proxmox->get_node_list();
|
|
|
|
|
$first_node = $nodes[0];
|
|
|
|
|
unset($nodes);
|
|
|
|
|
$guest=Capsule::table('mod_pvewhmcs_vms')->where('id','=',$params['serviceid'])->get()[0] ;
|
|
|
|
|
$vm_vncproxy=$proxmox->post('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/vncproxy', array( 'websocket' => '1' )) ;
|
|
|
|
|
|
|
|
|
|
// Early prep work
|
|
|
|
|
$guest = Capsule::table('mod_pvewhmcs_vms')->where('id','=',$params['serviceid'])->get()[0] ;
|
|
|
|
|
$vm_vncproxy = $proxmox->post('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/vncproxy', array( 'websocket' => '1' )) ;
|
|
|
|
|
// Get both tickets prepared
|
|
|
|
|
$pveticket = $proxmox->getTicket();
|
|
|
|
|
$vncticket = $vm_vncproxy['ticket'];
|
|
|
|
|
@@ -871,10 +961,10 @@ function pvewhmcs_noVNC($params) {
|
|
|
|
|
// Construct the noVNC Router URL with the path already prepared now
|
|
|
|
|
$url = '/modules/servers/pvewhmcs/novnc_router.php?host=' . $serverip . '&pveticket=' . urlencode($pveticket) . '&path=' . urlencode($path) . '&vncticket=' . urlencode($vncticket);
|
|
|
|
|
// Build and deliver the noVNC Router hyperlink for access
|
|
|
|
|
$vncreply='<center><strong>Console (noVNC) prepared for usage. <a href="'.$url.'" target="_blanK">Click here</a> to open the noVNC window.</strong></center>' ;
|
|
|
|
|
$vncreply = '<center><strong>Console (noVNC) prepared for usage. <a href="'.$url.'" target="_blanK">Click here</a> to open the noVNC window.</strong></center>' ;
|
|
|
|
|
return $vncreply;
|
|
|
|
|
} else {
|
|
|
|
|
$vncreply='Failed to prepare noVNC. Please contact Technical Support.';
|
|
|
|
|
$vncreply = 'Failed to prepare noVNC. Please contact Technical Support.';
|
|
|
|
|
return $vncreply;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -885,19 +975,21 @@ function pvewhmcs_SPICE($params) {
|
|
|
|
|
if (strlen(Capsule::table('mod_pvewhmcs')->where('id', '1')->value('vnc_secret'))<15) {
|
|
|
|
|
throw new Exception("PVEWHMCS Error: VNC Secret in Module Config either not set or not long enough. Recommend 20+ characters for security.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get login credentials then make the Proxmox connection attempt.
|
|
|
|
|
$serverip = $params["serverip"];
|
|
|
|
|
$serverusername = 'vnc';
|
|
|
|
|
$serverpassword = Capsule::table('mod_pvewhmcs')->where('id', '1')->value('vnc_secret');
|
|
|
|
|
$proxmox=new PVE2_API($serverip, $serverusername, "pve", $serverpassword);
|
|
|
|
|
|
|
|
|
|
$proxmox = new PVE2_API($serverip, $serverusername, "pve", $serverpassword);
|
|
|
|
|
if ($proxmox->login()) {
|
|
|
|
|
# Get first node name.
|
|
|
|
|
// Get first node name
|
|
|
|
|
$nodes = $proxmox->get_node_list();
|
|
|
|
|
$first_node = $nodes[0];
|
|
|
|
|
unset($nodes);
|
|
|
|
|
$guest=Capsule::table('mod_pvewhmcs_vms')->where('id','=',$params['serviceid'])->get()[0] ;
|
|
|
|
|
$vm_vncproxy=$proxmox->post('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/vncproxy', array( 'websocket' => '1' )) ;
|
|
|
|
|
|
|
|
|
|
// Early prep work
|
|
|
|
|
$guest = Capsule::table('mod_pvewhmcs_vms')->where('id','=',$params['serviceid'])->get()[0] ;
|
|
|
|
|
$vm_vncproxy = $proxmox->post('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/vncproxy', array( 'websocket' => '1' )) ;
|
|
|
|
|
// Get both tickets prepared
|
|
|
|
|
$pveticket = $proxmox->getTicket();
|
|
|
|
|
$vncticket = $vm_vncproxy['ticket'];
|
|
|
|
|
@@ -906,10 +998,10 @@ function pvewhmcs_SPICE($params) {
|
|
|
|
|
// Construct the SPICE Router URL with the path already prepared now
|
|
|
|
|
$url = '/modules/servers/pvewhmcs/spice_router.php?host=' . $serverip . '&pveticket=' . urlencode($pveticket) . '&path=' . urlencode($path) . '&vncticket=' . urlencode($vncticket);
|
|
|
|
|
// Build and deliver the SPICE Router hyperlink for access
|
|
|
|
|
$vncreply='<center><strong>Console (SPICE) prepared for usage. <a href="'.$url.'" target="_blanK">Click here</a> to open the noVNC window.</strong></center>' ;
|
|
|
|
|
$vncreply = '<center><strong>Console (SPICE) prepared for usage. <a href="'.$url.'" target="_blanK">Click here</a> to open the noVNC window.</strong></center>' ;
|
|
|
|
|
return $vncreply;
|
|
|
|
|
} else {
|
|
|
|
|
$vncreply='Failed to prepare SPICE. Please contact Technical Support.';
|
|
|
|
|
$vncreply = 'Failed to prepare SPICE. Please contact Technical Support.';
|
|
|
|
|
return $vncreply;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -924,31 +1016,30 @@ function pvewhmcs_javaVNC($params){
|
|
|
|
|
$serverip = $params["serverip"];
|
|
|
|
|
$serverusername = 'vnc';
|
|
|
|
|
$serverpassword = Capsule::table('mod_pvewhmcs')->where('id', '1')->value('vnc_secret');
|
|
|
|
|
$proxmox=new PVE2_API($serverip, $serverusername, "pve", $serverpassword);
|
|
|
|
|
$proxmox = new PVE2_API($serverip, $serverusername, "pve", $serverpassword);
|
|
|
|
|
if ($proxmox->login()) {
|
|
|
|
|
# Get first node name.
|
|
|
|
|
// Get first node name
|
|
|
|
|
$nodes = $proxmox->get_node_list();
|
|
|
|
|
$first_node = $nodes[0];
|
|
|
|
|
unset($nodes);
|
|
|
|
|
|
|
|
|
|
$guest=Capsule::table('mod_pvewhmcs_vms')->where('id','=',$params['serviceid'])->get()[0] ;
|
|
|
|
|
|
|
|
|
|
// Early prep work
|
|
|
|
|
$guest = Capsule::table('mod_pvewhmcs_vms')->where('id','=',$params['serviceid'])->get()[0] ;
|
|
|
|
|
$vncparams = array();
|
|
|
|
|
$vm_vncproxy=$proxmox->post('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/vncproxy', $vncparams) ;
|
|
|
|
|
|
|
|
|
|
$javaVNCparams=array() ;
|
|
|
|
|
$javaVNCparams[0]=$serverip ;
|
|
|
|
|
$javaVNCparams[1]=str_replace("\n","|",$vm_vncproxy['cert']) ;
|
|
|
|
|
$javaVNCparams[2]=$vm_vncproxy['port'] ;
|
|
|
|
|
$javaVNCparams[3]=$vm_vncproxy['user'] ;
|
|
|
|
|
$javaVNCparams[4]=$vm_vncproxy['ticket'] ;
|
|
|
|
|
|
|
|
|
|
$url='./modules/servers/pvewhmcs/tigervnc.php?'.http_build_query($javaVNCparams).'' ;
|
|
|
|
|
$vncreply='<center><strong>Console (TigerVNC) prepared for usage. <a href="'.$url.'" target="_blanK">Click here</a> to open the TigerVNC window.</strong></center>' ;
|
|
|
|
|
$vm_vncproxy = $proxmox->post('/nodes/'.$first_node.'/'.$guest->vtype.'/'.$params['serviceid'] .'/vncproxy', $vncparams) ;
|
|
|
|
|
// Java-specific params
|
|
|
|
|
$javaVNCparams = array() ;
|
|
|
|
|
$javaVNCparams[0] = $serverip ;
|
|
|
|
|
$javaVNCparams[1] = str_replace("\n","|",$vm_vncproxy['cert']) ;
|
|
|
|
|
$javaVNCparams[2] = $vm_vncproxy['port'] ;
|
|
|
|
|
$javaVNCparams[3] = $vm_vncproxy['user'] ;
|
|
|
|
|
$javaVNCparams[4] = $vm_vncproxy['ticket'] ;
|
|
|
|
|
// URL preparation to deliver in hyperlink message
|
|
|
|
|
$url = './modules/servers/pvewhmcs/tigervnc.php?'.http_build_query($javaVNCparams).'' ;
|
|
|
|
|
$vncreply = '<center><strong>Console (TigerVNC) prepared for usage. <a href="'.$url.'" target="_blanK">Click here</a> to open the TigerVNC window.</strong></center>' ;
|
|
|
|
|
// echo '<script>window.open("modules/servers/pvewhmcs/tigervnc.php?'.http_build_query($javaVNCparams).'","VNC","location=0,toolbar=0,menubar=0,scrollbars=1,resizable=1,width=802,height=624")</script>';
|
|
|
|
|
return $vncreply;
|
|
|
|
|
} else {
|
|
|
|
|
$vncreply='Failed to prepare TigerVNC. Please contact Technical Support.';
|
|
|
|
|
$vncreply = 'Failed to prepare TigerVNC. Please contact Technical Support.';
|
|
|
|
|
return $vncreply;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -956,23 +1047,22 @@ function pvewhmcs_javaVNC($params){
|
|
|
|
|
// PVE API FUNCTION, CLIENT/ADMIN: Start the VM/CT
|
|
|
|
|
function pvewhmcs_vmStart($params) {
|
|
|
|
|
// Gather access credentials for PVE, as these are no longer passed for Client Area
|
|
|
|
|
$pveservice=Capsule::table('tblhosting')->find($params['serviceid']) ;
|
|
|
|
|
$pveserver=Capsule::table('tblservers')->where('id','=',$pveservice->server)->get()[0] ;
|
|
|
|
|
|
|
|
|
|
$pveservice = Capsule::table('tblhosting')->find($params['serviceid']) ;
|
|
|
|
|
$pveserver = Capsule::table('tblservers')->where('id','=',$pveservice->server)->get()[0] ;
|
|
|
|
|
$serverip = $pveserver->ipaddress;
|
|
|
|
|
$serverusername = $pveserver->username;
|
|
|
|
|
|
|
|
|
|
$api_data = array(
|
|
|
|
|
'password2' => $pveserver->password,
|
|
|
|
|
'password2' => $pveserver->password,
|
|
|
|
|
);
|
|
|
|
|
$serverpassword = localAPI('DecryptPassword', $api_data);
|
|
|
|
|
$proxmox=new PVE2_API($serverip, $serverusername, "pam", $serverpassword['password']);
|
|
|
|
|
$proxmox = new PVE2_API($serverip, $serverusername, "pam", $serverpassword['password']);
|
|
|
|
|
if ($proxmox->login()) {
|
|
|
|
|
# Get first node name.
|
|
|
|
|
$nodes = $proxmox->get_node_list();
|
|
|
|
|
$first_node = $nodes[0];
|
|
|
|
|
unset($nodes);
|
|
|
|
|
$guest=Capsule::table('mod_pvewhmcs_vms')->where('id','=',$params['serviceid'])->get()[0] ;
|
|
|
|
|
$guest = Capsule::table('mod_pvewhmcs_vms')->where('id','=',$params['serviceid'])->get()[0] ;
|
|
|
|
|
$pve_cmdparam = array();
|
|
|
|
|
$logrequest = '/nodes/' . $first_node . '/' . $guest->vtype . '/' . $params['serviceid'] . '/status/start';
|
|
|
|
|
$response = $proxmox->post('/nodes/' . $first_node . '/' . $guest->vtype . '/' . $params['serviceid'] . '/status/start' , $pve_cmdparam);
|
|
|
|
|
@@ -988,34 +1078,33 @@ function pvewhmcs_vmStart($params) {
|
|
|
|
|
}
|
|
|
|
|
// Return success only if no errors returned by PVE
|
|
|
|
|
if (isset($response) && !isset($response['errors'])) {
|
|
|
|
|
return "success";
|
|
|
|
|
return "success";
|
|
|
|
|
} else {
|
|
|
|
|
// Handle the case where there are errors
|
|
|
|
|
$response_message = isset($response['errors']) ? json_encode($response['errors']) : "Unknown Error, consider using Debug Mode.";
|
|
|
|
|
return "Error performing action. " . $response_message;
|
|
|
|
|
// Handle the case where there are errors
|
|
|
|
|
$response_message = isset($response['errors']) ? json_encode($response['errors']) : "Unknown Error, consider using Debug Mode.";
|
|
|
|
|
return "Error performing action. " . $response_message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PVE API FUNCTION, CLIENT/ADMIN: Reboot the VM/CT
|
|
|
|
|
function pvewhmcs_vmReboot($params) {
|
|
|
|
|
// Gather access credentials for PVE, as these are no longer passed for Client Area
|
|
|
|
|
$pveservice=Capsule::table('tblhosting')->find($params['serviceid']) ;
|
|
|
|
|
$pveserver=Capsule::table('tblservers')->where('id','=',$pveservice->server)->get()[0] ;
|
|
|
|
|
|
|
|
|
|
$pveservice = Capsule::table('tblhosting')->find($params['serviceid']) ;
|
|
|
|
|
$pveserver = Capsule::table('tblservers')->where('id','=',$pveservice->server)->get()[0] ;
|
|
|
|
|
$serverip = $pveserver->ipaddress;
|
|
|
|
|
$serverusername = $pveserver->username;
|
|
|
|
|
|
|
|
|
|
$api_data = array(
|
|
|
|
|
'password2' => $pveserver->password,
|
|
|
|
|
'password2' => $pveserver->password,
|
|
|
|
|
);
|
|
|
|
|
$serverpassword = localAPI('DecryptPassword', $api_data);
|
|
|
|
|
$proxmox=new PVE2_API($serverip, $serverusername, "pam", $serverpassword['password']);
|
|
|
|
|
$proxmox = new PVE2_API($serverip, $serverusername, "pam", $serverpassword['password']);
|
|
|
|
|
if ($proxmox->login()) {
|
|
|
|
|
# Get first node name.
|
|
|
|
|
$nodes = $proxmox->get_node_list();
|
|
|
|
|
$first_node = $nodes[0];
|
|
|
|
|
unset($nodes);
|
|
|
|
|
$guest=Capsule::table('mod_pvewhmcs_vms')->where('id','=',$params['serviceid'])->get()[0] ;
|
|
|
|
|
$guest = Capsule::table('mod_pvewhmcs_vms')->where('id','=',$params['serviceid'])->get()[0] ;
|
|
|
|
|
$pve_cmdparam = array();
|
|
|
|
|
// $pve_cmdparam['timeout'] = '60';
|
|
|
|
|
$logrequest = '/nodes/' . $first_node . '/' . $guest->vtype . '/' . $params['serviceid'] . '/status/reboot';
|
|
|
|
|
@@ -1032,34 +1121,34 @@ function pvewhmcs_vmReboot($params) {
|
|
|
|
|
}
|
|
|
|
|
// Return success only if no errors returned by PVE
|
|
|
|
|
if (isset($response) && !isset($response['errors'])) {
|
|
|
|
|
return "success";
|
|
|
|
|
return "success";
|
|
|
|
|
} else {
|
|
|
|
|
// Handle the case where there are errors
|
|
|
|
|
$response_message = isset($response['errors']) ? json_encode($response['errors']) : "Unknown Error, consider using Debug Mode.";
|
|
|
|
|
return "Error performing action. " . $response_message;
|
|
|
|
|
// Handle the case where there are errors
|
|
|
|
|
$response_message = isset($response['errors']) ? json_encode($response['errors']) : "Unknown Error, consider using Debug Mode.";
|
|
|
|
|
return "Error performing action. " . $response_message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PVE API FUNCTION, CLIENT/ADMIN: Shutdown the VM/CT
|
|
|
|
|
function pvewhmcs_vmShutdown($params) {
|
|
|
|
|
// Gather access credentials for PVE, as these are no longer passed for Client Area
|
|
|
|
|
$pveservice=Capsule::table('tblhosting')->find($params['serviceid']) ;
|
|
|
|
|
$pveserver=Capsule::table('tblservers')->where('id','=',$pveservice->server)->get()[0] ;
|
|
|
|
|
$pveservice = Capsule::table('tblhosting')->find($params['serviceid']) ;
|
|
|
|
|
$pveserver = Capsule::table('tblservers')->where('id','=',$pveservice->server)->get()[0] ;
|
|
|
|
|
|
|
|
|
|
$serverip = $pveserver->ipaddress;
|
|
|
|
|
$serverusername = $pveserver->username;
|
|
|
|
|
|
|
|
|
|
$api_data = array(
|
|
|
|
|
'password2' => $pveserver->password,
|
|
|
|
|
'password2' => $pveserver->password,
|
|
|
|
|
);
|
|
|
|
|
$serverpassword = localAPI('DecryptPassword', $api_data);
|
|
|
|
|
$proxmox=new PVE2_API($serverip, $serverusername, "pam", $serverpassword['password']);
|
|
|
|
|
$proxmox = new PVE2_API($serverip, $serverusername, "pam", $serverpassword['password']);
|
|
|
|
|
if ($proxmox->login()) {
|
|
|
|
|
# Get first node name.
|
|
|
|
|
$nodes = $proxmox->get_node_list();
|
|
|
|
|
$first_node = $nodes[0];
|
|
|
|
|
unset($nodes);
|
|
|
|
|
$guest=Capsule::table('mod_pvewhmcs_vms')->where('id','=',$params['serviceid'])->get()[0] ;
|
|
|
|
|
$guest = Capsule::table('mod_pvewhmcs_vms')->where('id','=',$params['serviceid'])->get()[0] ;
|
|
|
|
|
$pve_cmdparam = array();
|
|
|
|
|
// $pve_cmdparam['timeout'] = '60';
|
|
|
|
|
$logrequest = '/nodes/' . $first_node . '/' . $guest->vtype . '/' . $params['serviceid'] . '/status/shutdown';
|
|
|
|
|
@@ -1076,34 +1165,33 @@ function pvewhmcs_vmShutdown($params) {
|
|
|
|
|
}
|
|
|
|
|
// Return success only if no errors returned by PVE
|
|
|
|
|
if (isset($response) && !isset($response['errors'])) {
|
|
|
|
|
return "success";
|
|
|
|
|
return "success";
|
|
|
|
|
} else {
|
|
|
|
|
// Handle the case where there are errors
|
|
|
|
|
$response_message = isset($response['errors']) ? json_encode($response['errors']) : "Unknown Error, consider using Debug Mode.";
|
|
|
|
|
return "Error performing action. " . $response_message;
|
|
|
|
|
// Handle the case where there are errors
|
|
|
|
|
$response_message = isset($response['errors']) ? json_encode($response['errors']) : "Unknown Error, consider using Debug Mode.";
|
|
|
|
|
return "Error performing action. " . $response_message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PVE API FUNCTION, CLIENT/ADMIN: Stop the VM/CT
|
|
|
|
|
function pvewhmcs_vmStop($params) {
|
|
|
|
|
// Gather access credentials for PVE, as these are no longer passed for Client Area
|
|
|
|
|
$pveservice=Capsule::table('tblhosting')->find($params['serviceid']) ;
|
|
|
|
|
$pveserver=Capsule::table('tblservers')->where('id','=',$pveservice->server)->get()[0] ;
|
|
|
|
|
|
|
|
|
|
$pveservice = Capsule::table('tblhosting')->find($params['serviceid']) ;
|
|
|
|
|
$pveserver = Capsule::table('tblservers')->where('id','=',$pveservice->server)->get()[0] ;
|
|
|
|
|
$serverip = $pveserver->ipaddress;
|
|
|
|
|
$serverusername = $pveserver->username;
|
|
|
|
|
|
|
|
|
|
$api_data = array(
|
|
|
|
|
'password2' => $pveserver->password,
|
|
|
|
|
'password2' => $pveserver->password,
|
|
|
|
|
);
|
|
|
|
|
$serverpassword = localAPI('DecryptPassword', $api_data);
|
|
|
|
|
$proxmox=new PVE2_API($serverip, $serverusername, "pam", $serverpassword['password']);
|
|
|
|
|
$proxmox = new PVE2_API($serverip, $serverusername, "pam", $serverpassword['password']);
|
|
|
|
|
if ($proxmox->login()) {
|
|
|
|
|
# Get first node name.
|
|
|
|
|
$nodes = $proxmox->get_node_list();
|
|
|
|
|
$first_node = $nodes[0];
|
|
|
|
|
unset($nodes);
|
|
|
|
|
$guest=Capsule::table('mod_pvewhmcs_vms')->where('id','=',$params['serviceid'])->get()[0] ;
|
|
|
|
|
$guest = Capsule::table('mod_pvewhmcs_vms')->where('id','=',$params['serviceid'])->get()[0] ;
|
|
|
|
|
$pve_cmdparam = array();
|
|
|
|
|
// $pve_cmdparam['timeout'] = '60';
|
|
|
|
|
$logrequest = '/nodes/' . $first_node . '/' . $guest->vtype . '/' . $params['serviceid'] . '/status/stop';
|
|
|
|
|
@@ -1120,11 +1208,11 @@ function pvewhmcs_vmStop($params) {
|
|
|
|
|
}
|
|
|
|
|
// Return success only if no errors returned by PVE
|
|
|
|
|
if (isset($response) && !isset($response['errors'])) {
|
|
|
|
|
return "success";
|
|
|
|
|
return "success";
|
|
|
|
|
} else {
|
|
|
|
|
// Handle the case where there are errors
|
|
|
|
|
$response_message = isset($response['errors']) ? json_encode($response['errors']) : "Unknown Error, consider using Debug Mode.";
|
|
|
|
|
return "Error performing action. " . $response_message;
|
|
|
|
|
// Handle the case where there are errors
|
|
|
|
|
$response_message = isset($response['errors']) ? json_encode($response['errors']) : "Unknown Error, consider using Debug Mode.";
|
|
|
|
|
return "Error performing action. " . $response_message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|