vnc applet does not work properly at remote location

hamed

Member
Sep 6, 2010
36
0
6
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.

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>
 
The problem solved.
I was testing with Windows 7 - Chrome 18 & Firefox 10.
The problem was that the VNC page has to contain the following javascript function to let the applet work properly:

Code:
PVE_vnc_console_event = function(appletid, action, err) {
}
 
hi guys!i try hammed example but it prints me only the information not open the vnc page.
Could you help me? i don't know where i put the function.
Thanks!

Edit:
Now it works...i've tried it locally on my 127.0.0.1:8081 web server...why vnc try to connect to my local port 5900?
 
Last edited by a moderator:
The problem solved.
I was testing with Windows 7 - Chrome 18 & Firefox 10.
The problem was that the VNC page has to contain the following javascript function to let the applet work properly:

Code:
PVE_vnc_console_event = function(appletid, action, err) {
}

where or should i say what line is that on to make this work?
 
I have a VNC solution for KVM if anyone's interested.

In the conf file, /etc/pve/nodes/node/qemu-server/vm.conf, add this line

args: -vnc 0.0.0.0:100,password

:100 makes the port 6000.

Then create a PHP script with the API to set the VNC password every time it starts.

Code:
print_r($pve2->post("/nodes/box1/qemu/".$vmid."/status/start", array()));			
print_r($pve2->post("/nodes/box1/qemu/".$vmid."/monitor", array('command'=>'set_password vnc Mypassword')));
 

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!