noVNC console via PHP API

Im trying use dynamicaly adding html form for authorization with "target" -> iframe, but no have luck
LQ2K7EVsOqQl2j.jpg
Have good authorization, but no have cookie
 
Last edited:
It's not working for me. It will only works when root user logged in
I tried to set raw cookie with server address as domain parameter but it don't works too.

Really how i can have a noVNC access using ticket generated by vncProxy and vncWebsocket? I tried several ways but can't find
 
now i replace body of "pve2_api.class.php" at your link body, no effect :)
strange, very strage..

Hello ,Have you finished the problem? I met the same problem . But I cannot find a true answer.

Code:
 $proxmox = $this->__construct();

        $vncproxy=$proxmox->create('/nodes/proxmox/qemu/101/vncproxy');

        $vncport = $vncproxy['data']['port'];

        $vncticket = $vncproxy['data']['ticket'];

        $params = [
            'port' => $vncport,
            'name' => $vncticket,
        ];

        $vncwebsocket=$proxmox->get('/nodes/proxmox/qemu/101/vncwebsocket',$params);

   
        print "https://kanaka.github.io/noVNC/noVNC/vnc_auto.html?host=$ip&port=443&password=$password&encrypt=1&true_color=1&shared=1&view_only=0&path=" . urlencode("api2/json/nodes/proxmox/qemu/101/vncwebsocket?port=$vncport&vncticket=$vncticket") . "";
And I inout the url on the Chrome, but have error "Server disconnected (code: 1006)" too.
If you have any suggestion ,Please give me some answer ,Thank you very much
 
You can access the noVNC console via it's address:
Code:
  [URL="https://your.proxmoxve.server:8006/?console=kvm&novnc=1&vmid=100&node=somenode"]
https://your.proxmoxve.server:8006/?console=kvm&novnc=1&vmid=100&node=somenode[/URL]
change the vmid and the node GET parameters to your needs. But you need to respect the authentification security measures Proxmox VE has.

I actually changed a little bit of the PHP API from https://github.com/CpuID/pve2-api-php-client ( i hope you use this ^^)

I added the following function in pve2-api-php-client/pve2_api.class.php . You'll need it because the noVNC frontend checks if you have the valid permissions through the "PVEAuthCookie", and to set it outside of the API would be a bigger hassle as the login_ticket is protected in the API.
Code:
public function setCookie()
{
    setcookie("PVEAuthCookie",$this->login_ticket['ticket']);
}

And here is some example code of including the noVNC console, attetion you need to create a user which has the VM.Console permission for the vms you would like to show., e.g the role "PVEVMUser" has it. And the user, AFAIK, must be logged in through the pam realm, which means it must be an real user on your proxmox system. I created a "vnc" dummy user on my proxmox server (use the command line tool "adduser"), then gave him the PVEVMUser role through the PVE Web Interface (naturally, you could do it also with the api).

But look at the code yourself, it's really simple. Only the setup from the user and so on is a bit complicated.
Code:
<?php
require("pve2-api-php-client/pve2_api.class.php");

# use pam here, my test user is vnc with, naturally, a strong password ;)
$pve2 = new PVE2_API("pve", "vnc", "pam", "12345");

?>
<html>
<head>
     <title>noVNC extern test</title>
</head>
<body>

<?php

if ($pve2->login())
{
    $pve2->setCookie(); # this is the function I added to the php API client

?>
<iframe  src="https://192.168.122.6:8006/?console=kvm&novnc=1&vmid=100&node=pve" frameborder="0" scrolling="no" width="1024px" height="100%"></iframe>

<?php
   # print("logged in");
}
else
{
    print("Login to Proxmox Host failed.\n");
    exit;
}
?>
</body>
</html>

It's a bit messy, so when you have further questions, feel free to ask. Or when you came up with a cleaner way, please let me know it.

Hello ,I am a coder noob. Could you please give me some suggestions? My project used the PHP API from https://github.com/zzantares/proxmoxve .But I cannot find a right way to set the ticket. I have wasted a large amount time but in vain.
 
Is there a solution for this problem? I am also getting no ticket error 401 for both of the already presented possibilities. My current code looks like this:
PHP:
        $vnc = $this->proxmox->api->post('/nodes/'.$this->proxmox->node.'/'.$this->virtualizationType.'/'.$this->vmID.'/vncproxy', array());
        $this->proxmox->api->get('/nodes/'.$this->proxmox->node.'/'.$this->virtualizationType.'/'.$this->vmID.'/vncwebsocket', array('vncticket' => $vnc['ticket'], 'port' => $vnc['port']));
        setrawcookie('PVEAuthCookie', $vnc['ticket'], 0, '/', $this->proxmox->host);
        setrawcookie('PVEAuthCookie', $vnc['ticket'], 0, '/');

Any ideas how to fix that?

Edit: If i login first into the proxmox webinterface, it works... (I am using google chrome btw)
Edit2: This code above does not change anything. I only must login to proxmox webinterface and then open the console embed with <iframe> as the example above show. The problem is that I dont want the users of the webapplication logging in to the proxmox webinterface.
 
Last edited:
Same problem here.

It works fine when the user is logged into the proxmox web ui console. But when it's not the api login code doesn't seem to retrieve the correct ticket.

Is there a way to manually set the ticket in the request? So that the vnc can work? It's been almost a week that I have been trying to solve this problem.

Please help!
 
大家好!现在调试正常吗?我的消息仍然显示“登录Proxmox主机失败”,我使用PVE6.0。谢谢!
 
Hello everyone! Is the debugging normal now? My message still says "Login to Proxmox Host failed", I use PVE6.0. Thanks!
 

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!