noVNC Error 401: No Ticket

Geron74784

New Member
Dec 12, 2022
11
0
1
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>';
    ?>
1709562001771.png1709561987765.png
 
Last edited:
Hey,

had you tried to first open it in a incognito mode?

Is it a cluster? When in a cluster try the following pvecm updatecertssystemctl restart pvedaemon systemctl restart pveproxy (this must be executed on every node)

Is there a way to reproduce so I can test is the same way as this is happening?

Best
 
  • Like
Reactions: Geron74784
I dont have a cluster, and to reproduce you can download blesta using the 30 days trial, and download the proxmox fork from here habibulilalbaab/module-proxmox, after you need to copy my code and paste into: blesta/components/modules/proxmox/views/default/tab_client_console.pdt.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!