Benutzung von noVNC aus einem anderen Panel (EXTERN)

Nexus633

New Member
Mar 1, 2021
3
0
1
32
Hallo liebe Community,
ich bin seit Tagen dabei in meinem PHP Projekt die novnc Console zum laufen zu bekommen.
Ich habe vanilla novnc sowie die von Proxmox mitgelieferte novnc version probiert.

Ich Nutze folgendes PHP Projekt um mit der API zu komunizieren:

cv4pve-api-php

Folgendes Probiere ich:
PHP:
$vnc = $client->getNodes()->get($vserverinfo["node"])->getQemu()->get($vserverinfo["vmid"])->getVncproxy()->vncproxy(false, true)->getResponse()["data"];
$client->getNodes()->get($vserverinfo["node"])->getQemu()->get($vserverinfo["vmid"])->getVncwebsocket()->vncwebsocket($vnc["port"], $vnc["ticket"]);

//1 Beispiel
echo '
<div class="container" >
    <iframe src="mytekbase/admin/modules/RootServer/lib/novnc/vnc.html?host='.$vserverinfo["host"].'&encrypted=1&port='.$vserverinfo["port"].'&password='.$vnc["password"].'&path=api2/json/nodes/'.$vserverinfo["node"].'/qemu/'.$vserverinfo["vmid"].'/vncwebsocket?vncticket='.$vnc["ticket"].'&port='.$vnc["port"].'" frameborder="0" scrolling="no" width="1024px" height="100%"></iframe>
</div>

//2 Beispiel
<div class="container" >
    <iframe src="https://'.$vserverinfo["host"].':'.$vserverinfo["port"].'/?console=kvm&novnc=1&vmid='.$vserverinfo["vmid"].'&vmname='.$vserverinfo["name"].'&node='.$vserverinfo["node"].'&resize=on&vncticket='.$vnc["ticket"].'&password='.$vnc["password"].'" frameborder="0" scrolling="no" width="1024px" height="100%"></iframe>
</div>';

Beim 1 Beispiel bekomme ich Failed to connect to server
Beim 2 Beispiel bekomme ich 401 no Ticket

Nunja fürs 2te Beispiel habe ich mir dann gedacht - da es ja funktioniert wenn ich im Proxmox eingeloggt bin - Den Cookie einfach zu setzen.
Das habe ich mit dem VNCTicket probiert und mit dem Ticket den ich beim Login erhalte... Beides Funktioniert nicht.


Nun meine frage: Wie komme ich von Ausserhalb auf die Konsole drauf. Ich entwickel ein Modul für Tekbase. Demnach möchte ich meinen Kunden die Möglichkeit bieten über ihren Kundenbereich, die Konsole zu verwenden.

Hat eventuell jemand eine lösung für mich ?
 
Last edited:
Hey,

you could use an API token [1], here is a short example of how the JS code could look like. (the code here was not tested, but it should work something like this)
JavaScript:
var myIframe = document.querySelector('#myIframe');

populateIframe(myIframe);

function populateIframe(iframe) {
  var xhr = new XMLHttpRequest();
  xhr.open('GET', '<URL>');
  xhr.onreadystatechange = handler;
  headers.forEach(function(header) {
    xhr.setRequestHeader('Authorization', 'PVEAPIToken=<USER>@<REALM>!tokenid=<UUID>');
  });
  xhr.send();

  function handler() {
    if (this.readyState === this.DONE) {
      if (this.status === 200) {
        iframe.src = URL.createObjectURL(this.response);
      } else {
        console.error('Request failed', this);
      }
    }
  }
}

[1] https://pve.proxmox.com/pve-docs/pve-admin-guide.html#pveum_tokens
 
Hey,

you could use an API token [1], here is a short example of how the JS code could look like. (the code here was not tested, but it should work something like this)
JavaScript:
var myIframe = document.querySelector('#myIframe');

populateIframe(myIframe);

function populateIframe(iframe) {
  var xhr = new XMLHttpRequest();
  xhr.open('GET', '<URL>');
  xhr.onreadystatechange = handler;
  headers.forEach(function(header) {
    xhr.setRequestHeader('Authorization', 'PVEAPIToken=<USER>@<REALM>!tokenid=<UUID>');
  });
  xhr.send();

  function handler() {
    if (this.readyState === this.DONE) {
      if (this.status === 200) {
        iframe.src = URL.createObjectURL(this.response);
      } else {
        console.error('Request failed', this);
      }
    }
  }
}

[1] https://pve.proxmox.com/pve-docs/pve-admin-guide.html#pveum_tokens


Thanks, unfortunately that doesn't work either. With your script I get an "Access-Control-Allow-Origin" error. Then I tried the APIToken and set it as a header and cookie ... I get ERROR 401: No Ticket ... I don't understand that. No matter how I do it, I just don't get this console!
 
Thanks, unfortunately that doesn't work either. With your script I get an "Access-Control-Allow-Origin" error. Then I tried the APIToken and set it as a header and cookie ... I get ERROR 401: No Ticket ... I don't understand that. No matter how I do it, I just don't get this console!
hey,
falls du chrome verwendest kannst du mal das addon "allow cors:access-control-allow-origin" probieren. das hat bei mir zumindest bei anderen projekten geholfen bei denen ich den fehler hatte, wobei ich dir nicht sagen kann was genau das macht :confused: soweit ich das verstanden habe ist das problem das du eine seite aufrufst die javascript von einer anderen domain ausführen will, aber bin leider echt ein noob was das angeht
 

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!