Hi, I'm trying to fix a fork of Blesta for Proxmox "habibulilalbaab/module-proxmox" but on the page to view noVNC I don't understand why it gives me Error 401: No ticket, and I keep trying to open that url gives me error "401: Permission denied - invalid csrf token, even if I refresh the page, it only works if I access the url directly, I think it is related to cookies, but I don't understand why, bc they have already been set in line 38, this is the affected code.
Code:
<h4><?php $this->_('Proxmox.tab_client_console.heading_console');?></h4>
<?php
$ticketUrl = 'https://'.$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.":8006/?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 '<iframe src="'.$url_vnc.'" frameborder="0" scrolling="no" width="100%" height="600px" allow="fullscreen"></iframe>';
?>
Last edited: