diff --git a/apis/proxmox_api.php b/apis/proxmox_api.php index 7d0d28e..4e46410 100644 --- a/apis/proxmox_api.php +++ b/apis/proxmox_api.php @@ -75,7 +75,7 @@ public function __construct($user, $password, $host, $port = 8006) $this->login(); } - + public function login() { $res = $this->submit('access/ticket', [ diff --git a/proxmox.php b/proxmox.php index 2f9d640..c65c9f6 100644 --- a/proxmox.php +++ b/proxmox.php @@ -1881,6 +1881,8 @@ public function tabClientConsole($package, $service, array $get = null, array $p */ private function consoleTab($package, $service, $client = false) { + // Get the service fields + $service_fields = $this->serviceFieldsToObject($service->fields); $template = ($client ? 'tab_client_console' : 'tab_console'); $this->view = new View($template, 'default'); // Load the helpers required for this view @@ -1924,6 +1926,7 @@ private function consoleTab($package, $service, $client = false) $this->view->set('console', (object)$session); $this->view->setDefaultView('components' . DS . 'modules' . DS . 'proxmox' . DS); + $this->view->set('service_fields', $this->serviceFieldsToObject($service->fields)); return $this->view; } diff --git a/views/default/tab_client_console.pdt b/views/default/tab_client_console.pdt index b9ab94e..285f730 100644 --- a/views/default/tab_client_console.pdt +++ b/views/default/tab_client_console.pdt @@ -1,24 +1,47 @@

_('Proxmox.tab_client_console.heading_console');?>

-
- - - - - - - - - - - - - - - - - - - -
_('Proxmox.tab_client_console.vnc_ip');?>vnc_ip) ? $this->Html->safe($console->vnc_ip) : null);?>
_('Proxmox.tab_client_console.vnc_port');?>vnc_port) ? $this->Html->safe($console->vnc_port) : null);?>
_('Proxmox.tab_client_console.vnc_user');?>vnc_user) ? $this->Html->safe($console->vnc_user) : null);?>
_('Proxmox.tab_client_console.vnc_password');?>vnc_password) ? $this->Html->safe($console->vnc_password) : null);?>
-
\ No newline at end of file + vnc_ip.'/api2/json/access/ticket'; + + $postData = array( + 'username' => $service_fields->proxmox_username.'@pve', + 'password' => $service_fields->password, + ); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $ticketUrl); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $response = curl_exec($ch); + curl_close($ch); + + $ticketData = json_decode($response, true); + + function getMainDomain($subdomain) { + $urlParts = parse_url($subdomain); + + // Memeriksa apakah parse_url berhasil dan mengandung bagian host + if ($urlParts && isset($urlParts['host'])) { + $hostParts = explode('.', $urlParts['host']); + + // Memeriksa apakah ada setidaknya dua bagian pada domain (misal: example.com) + if (count($hostParts) >= 2) { + // Mengambil dua bagian terakhir untuk mendapatkan domain utama + $mainDomain = $hostParts[count($hostParts) - 2] . '.' . $hostParts[count($hostParts) - 1]; + return $mainDomain; + } + } + + return null; // Mengembalikan null jika tidak dapat menemukan domain utama + } + setcookie("PVEAuthCookie",$ticketData['data']['ticket'], 0, "/", '.'.getMainDomain('https://'.$_SERVER['HTTP_HOST']) ); + + if($service_fields->proxmox_type == 'qemu'){ + $vmType = 'kvm'; + }else{ + $vmType = 'lxc'; + } + $url_vnc = "https://".$console->vnc_ip."/?console=".$vmType."&novnc=1&node=".$service_fields->proxmox_node."&resize=1&vmid=".$service_fields->proxmox_vserver_id."&path=api2/json/nodes/".$service_fields->proxmox_node."/".$service_fields->proxmox_type."/".$service_fields->proxmox_vserver_id."/vncwebsocket/port/".$console->vnc_port."/vncticket/".$console->vnc_password; + echo ''; + ?> \ No newline at end of file diff --git a/views/default/tab_console.pdt b/views/default/tab_console.pdt index aba195e..8bcb35c 100644 --- a/views/default/tab_console.pdt +++ b/views/default/tab_console.pdt @@ -3,12 +3,51 @@

_('Proxmox.tab_console.heading_console');?>

- + vnc_ip.'/api2/json/access/ticket'; + + $postData = array( + 'username' => $service_fields->proxmox_username.'@pve', + 'password' => $service_fields->password, + ); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $ticketUrl); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $response = curl_exec($ch); + curl_close($ch); + + $ticketData = json_decode($response, true); + + function getMainDomain($subdomain) { + $urlParts = parse_url($subdomain); + + // Memeriksa apakah parse_url berhasil dan mengandung bagian host + if ($urlParts && isset($urlParts['host'])) { + $hostParts = explode('.', $urlParts['host']); + + // Memeriksa apakah ada setidaknya dua bagian pada domain (misal: example.com) + if (count($hostParts) >= 2) { + // Mengambil dua bagian terakhir untuk mendapatkan domain utama + $mainDomain = $hostParts[count($hostParts) - 2] . '.' . $hostParts[count($hostParts) - 1]; + return $mainDomain; + } + } + + return null; // Mengembalikan null jika tidak dapat menemukan domain utama + } + setcookie("PVEAuthCookie",$ticketData['data']['ticket'], 0, "/", '.'.getMainDomain('https://'.$_SERVER['HTTP_HOST']) ); + + if($service_fields->proxmox_type == 'qemu'){ + $vmType = 'kvm'; + }else{ + $vmType = 'lxc'; + } + $url_vnc = "https://".$console->vnc_ip."/?console=".$vmType."&novnc=1&node=".$service_fields->proxmox_node."&resize=1&vmid=".$service_fields->proxmox_vserver_id."&path=api2/json/nodes/".$service_fields->proxmox_node."/".$service_fields->proxmox_type."/".$service_fields->proxmox_vserver_id."/vncwebsocket/port/".$console->vnc_port."/vncticket/".$console->vnc_password; + echo ''; + ?>