PHP - Proxmox NOVNC Api

Apr 11, 2020
13
0
21
Hey,

ich habe folgendes Probleme. Ich habe via PHP von der API "/api2/json/nodes/{node}/qemu/{vmid}/vncproxy" einen Token bekommen, diesen setzte ich auch bei "/api2/json/nodes/{node}/qemu/{vmid}/vncwebsocket" ein. So als Nächstes trickse ich ein bisschen, und zwar rufe ich dann auf dem Proxmox Host eine HTML Datei auf und setzte dann den Cookie "PVEAuthCookie" mit dem NOVNC Token, jedoch wirft mir Proxmox trotzdem einen 401 Error zurück.

PHP:
$vncproxy = $virtualMachine->postVncProxy([
            'websocket' => true,
        ])['data'];
        $websock = $virtualMachine->getVncWebsocket([
            'vncticket' => $vncproxy['ticket'],
            'port' => $vncproxy['port'],
        ])['data'];
$vncSocket = 'https://******.cloud/novnc/cnovnc.html?token='$vncproxy['ticket'].'&console=qemu&node='.$nodeName.'&vmid='.$vmId;
Und ja die URL ist korrekt usw. es normal, wenn ich das über das Webinterface geht es auch.
So und auf dem Server die HTML Datei macht Folgendes:
HTML:
load: function (callback) {
            var token = WebUtil.getQueryVar('token', null);
            if (token) {
                WebUtil.createCookie('PVEAuthCookie', token, 1);
            }
            var error = WebUtil.getQueryVar('error', null);
            if (error && error !== undefined && error !== null) {
                UI.updateState(null, 'failed', 'loaded',
                        error);
                return;
            }
            consoleType = "kvm";
            var controller = "novnc=1";
            window.location = "../?console=" + consoleType + "&" + controller + "&vmid=" + WebUtil.getQueryVar('vmid') + "&vmname=" + WebUtil.getQueryVar('vmid') + "&node=" + WebUtil.getQueryVar('node') + "";
        },

Der Cookie wird korrekt gesetzt, es scheint mir aber so als ob der Token der im Cookie ist, falsch ist.

Das wird mir ausgegeben, wenn ich das Ergebnis halt, ausgeben lasse ^^ unten ist die URL die zu der HTML Datei führt.
Screenshot_417.png

Das gibt mir die NOVNC Konsole aus:
Screenshot_418.png

Vielen Dank für die Hilfe schonmal im Voraus!
 
$params = [ 'password' => $node_pass, 'username' => $node_user, 'realm' => $node_method ];
$ticket = $proxmox->create( "/access/ticket", $params )->getResponse();
$pve_ticket = urlencode( $ticket[ 'data' ][ 'ticket' ] );

$link = "https://$node_host:$node_port/novnc/vnc.html?console=shell&xtermjs=1&node=$node_name&token=$pve_ticket";
 
"PVEAuthCookie" mit dem NOVNC Token
das PVEAuthCookie ist nicht der novnc token sondern eben das PVEAuthCookie, das 'Ticket' vom user für pve. ohne dem geht das ganze nicht
 
Hey,

danke, aber den gleichen Gedanken dann verfolgen wir auch ^^, wir wollen nicht für jeden User eine Proxmox User anlegen, sondern dem nur für diese Session bzw. jedem Aufruf der NoVNC eine einmalige NoVNC berechtigung geben.
 
Wir erstellen zu jeder VM, den User mit der Berichtigung zur VM, so klappt Novnc ohne Probleme.
 
wir haben uns daher bisher dazu entschieden, unseren Kunden nur SPICE anzubieten, das funktioniert über unseren reverseProxy sehr gut...
einziger Nachteil, der Kunde muss den SPICE Client installiert haben....

Quick & Dirty
PHP:
$proxmox = new Proxmox($credentials);
$vncProxy=$proxmox->create('/nodes/'.$node.'/qemu/'.$vmid.'/spiceproxy',[])['data'];


    $text="[virt-viewer]\n
            host-subject=".$vncProxy['host-subject']."\n
            toggle-fullscreen=".$vncProxy['toggle-fullscreen']."\n
            password=".$vncProxy['password']."\n
            secure-attention=".$vncProxy['secure-attention']."\n
            type=".$vncProxy['type']."\n
            proxy=http://".$host.":3128\n
            title=".$vncProxy['title']."\n
            release-cursor=".$vncProxy['release-cursor']."\n
            delete-this-file=1\n
            ca=".$vncProxy['ca']."\n
            tls-port=".$vncProxy['tls-port']."\n
            host=".$vncProxy['host']."";
    
    
    
    header("Content-Disposition:inline;filename=spice.vv");
    header("Content-type:application/spice");
    echo $text;
 
Last edited:

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!