#!/usr/local/bin/perl
# index.cgi
# Display the vnc applet
require '../web-lib.pl';
use Socket;
&init_config();
&header($text{'index_title'}, "", undef, &get_product_name() eq 'webmin', 1);
print "
\n";
if ($config{'program'}) {
# Check if Xvnc is installed
if (!&has_command("Xvnc")) {
&error_exit(&text('index_ecmd', "Xvnc"));
}
# Pick a free VNC number
for($num=1; $num<1000; $num++) {
$port = 5900+$num;
last;
# XXX need to test
}
# Generate a password using vncpasswd
# XXX
# Start Xvnc in a background process, and kill it after one client
if (!fork()) {
close(STDIN);
close(STDOUT);
local $pid = open(VNC, "Xvnc :$num 2>&1 |");
while() {
if (/Client\s+(\S+)\s+gone/i) {
kill(TERM, $pid);
last;
}
}
close(VNC);
exit;
}
# Run the specified program, using the selected display
$ENV{'DISPLAY'} = "localhost:$num";
system("$config{'program'} >/dev/null 2>&1 $text{'index_warn'}",
"
\n";
}
print "
\n";
print "$text{'index_credits'}\n";
print "
\n";
&footer("/", $text{'index'});
sub connect_timeout
{
}
sub error_exit
{
print "",@_,"
\n";
print "
\n";
&footer("/", $text{'index'});
exit;
}