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:
Please anyone can help me???
Thanks 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: