/** * w3esxi_adminshutdown() * * @param mixed $params * @return */ function w3esxi_adminshutdown($params) { //Check Server is disabled? $serverid = $params['serverid']; $result = mysql_query("SELECT disabled FROM tblservers WHERE id = '{$serverid}'"); $row = mysql_fetch_assoc($result); $disabled = $row['disabled']; if ($disabled) { return "<strong>Server is disabled.<strong>"; } $result = null; $response = null; if ($params['moduletype'] == 'w3esxi') { $user = $params['serverusername']; $pass = $params['serverpassword']; $host = $params['serverip']; $vmid = w3e_getVMID($params); $force = w3e_getSettings('force_admin_commands'); $expireDate = w3e_getLastCommandExpireDate($params['serviceid']); if ($force || !$expireDate || $expireDate < time()) { if ($vmid != null) { $vmware = new VMware(); $vmware->setServerConfig($host, $user, $pass); $response = $vmware->shutdownOS($vmid); } else { $response = false; } if ($response) { w3e_insertLog('shutdwonos', $params['serviceid'], $vmid, 'admin'); $result = 'success'; } else { $result = "Cannot Shutdown OS of VPS"; } } else { $expireDate = abs(time() - $expireDate); $result = "Your request is already sent. You should wait {$expireDate} seconds"; } } return $result; }
private function getVMIDlist($serverIdArr) { $servers = $this->getAllServers(false, $serverIdArr); if (!$servers || !count($servers)) { $this->setErrors('There is no active server to get vmid list', 'ERROR'); header('Location: ' . W3E_MOD_LINK . '&view=quick'); exit; } $error = false; $option = null; foreach ($servers as $s) { $sid = $s['id']; $name = $s['servername']; $user = $s['username']; $pass = decrypt($s['password']); $host = $s['ipaddress']; $option .= '<optgroup label="' . $name . '">'; $vmware = new VMware(); $vmware->setServerConfig($host, $user, $pass); $list = $vmware->getAllVmInfo(); if (!$list || !count($list)) { $this->setErrors("Cannot get vmid list from server {$name} ({$host})", 'ERROR'); $error = true; continue; } foreach ($list as $vm) { $option .= "<option value=\"{$sid}_{$vm['vmid']}\">{$vm['vmid']} - {$vm['name']}</option>\n"; } $option .= '</optgroup>'; } if (!$option) { $this->setErrors('Cannot get vmid list from servers', 'ERROR'); header('Location: ' . W3E_MOD_LINK . '&view=quick'); exit; } return $option; }