Hi,
I want to create a remote VNC login page.
My script authenticates with API2 and receives TICKET and etc successfuly. Then calls vncproxy and receives vnc login info without any problem.
The problem is with the java applet that its screen is blank and displays nothing WHILST I can connect to VNC using a desktop version of TigerVNC.
I want to create a remote VNC login page.
My script authenticates with API2 and receives TICKET and etc successfuly. Then calls vncproxy and receives vnc login info without any problem.
The problem is with the java applet that its screen is blank and displays nothing WHILST I can connect to VNC using a desktop version of TigerVNC.
Code:
<html>
<body>
<?php
// Authenticate
$url='https://192.168.1.78:8006/api2/json/access/ticket';
$fields_string="username=root&password=temppassword&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.78:8006/api2/json/nodes/c43/qemu/4318/vncproxy';
$fields_string="";
$result=getUrl($url,$fields_string,"PVEAuthCookie=".$ticket,$CSRFPreventionToken);
$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.78:8006/vncterm/VncViewer.jar\" code=\"com.tigervnc.vncviewer.VncViewer\" style=\"width: 720px; height: 426px;\">";
?>
<param value="<?=$cert?>" name="PVECert">
<param value="<?=$port?>" name="PORT">
<param value="No" name="Show Controls">
<param value="No" name="Offer Relogin">
<param value="<?=$username?>" name="USERNAME">
<param value="<?=$ticket?>" 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>