Proxmox vs. VNC Viewer

R

razorback

Guest
Hi guys!!!
Thanks to proxmox team for their amazing work!!!
I'm trying to connect a vnc vm viewer in the browser without open proxmox page directly!
I've found a good script by hamed and try it.
Window is open but when i connect to server i get: Error could not parse certificate ....... Empty input
But i'm sure to pass the certificate to the applet.
I'll paste some code:
Code:
<html>
<head>
</head>
<body>
<?php
// Authenticate
$url='https://192.168.1.2:8006/api2/json/access/ticket';
$fields_string="username=user&password=pwtest&realm=pam";
$result=getUrl($url,$fields_string);


if (!$result)
{
    die("Error");
}
$CSRFPreventionToken=$result->{"CSRFPreventionToken"};
$ticket=$result->{"ticket"};
// Received Ticket & CSRFPreventationToken


// Get VNC Proxy
$url='https://192.168.1.2:8006/api2/json/nodes/node1/qemu/100/vncproxy';
$fields_string="";
$cert=$result->{"cert"};
$port=$result->{"port"};
$username=$result->{"user"};
$ticket=$result->{"ticket"};
$cert = str_replace("\n","|",$cert);
// Received VNC Proxy


echo "Port: ".$port."<br />";
echo "Cert: ".$cert."<br />";
echo "Username: ".$username."<br />";
echo "ticket: ".$ticket."<br />";


echo "<applet width=\"100%\" height=\"100%\" border=\"false\" archive=\"https://192.168.1.2:8006/vncterm/VncViewer.jar\" code=\"com.tigervnc.vncviewer.VncViewer\" style=\"width: 720px; height: 426px;\">";
?>
    <param value="<?php echo $cert;>" name="PVECert">
    <param value="<?php echo $port;>" name="PORT"> 
    <param value="No" name="Show Controls">
    <param value="No" name="Offer Relogin"> 
    <param value="<?php echo $username;>" name="USERNAME">
    <param value="<?php echo $tickect;>" name="password">
</APPLET>
<?php




function getUrl($url,$fields_string,$cookie="",$CSRFPreventionToken="")
{
    $ch = curl_init($url);


    //set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POST,1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
    curl_setopt($ch, CURLOPT_HEADER      ,0);  // DO NOT RETURN HTTP HEADERS
    curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);  // RETURN THE CONTENTS OF THE CALL
    curl_setopt($ch, CURLOPT_HTTPHEADER  ,array("CSRFPreventionToken: $CSRFPreventionToken","Cookie: $cookie"));
    //execute post
    $result = curl_exec($ch);
    if(curl_exec($ch) === false) {
        echo 'Curl error: ' . curl_error($ch);
    }
    
    //close connection
    curl_close($ch);
    
    $i=strpos($result,"{");
    if ($i!==false) {
        $result=substr($result,$i);
    }
    
    $result=json_decode($result);
    if ($result->{"data"}==null) {
        return false;
    }
    
    return $result->{"data"};
}
?>
</body>
</html>

Please anyone can help me???
Thanks guys!
 
Last edited by a moderator:
You need to replace newline inside the certificate with '|'. I do the following in javascript:

cert = cert.replace(/\n/g, "|");

But it seems you already do that. What value do you pass exactly? (Please post the output of 'echo "Cert: ...')
 
Last edited:
I am not sure if filed names are case sensitive - but I use capital letters:

name="PASSWORD"
 
i tried to update scritp withou capital letter and get the same problem.
Erase FF cache and everything works fine.
IT is a really mistery sometimes!!
Thanks for your help dietmar!
Hope that help someone too!!!!
 

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!