xref: /haiku/3rdparty/mmu_man/onlinedemo/haiku.php (revision b12110c5db38dcce61747f31192bb2f5681e27cc)
1e8fc4975SFrançois Revol<?php
2e8fc4975SFrançois Revol
3e8fc4975SFrançois Revol/*
4e8fc4975SFrançois Revol * haiku.php - an online Haiku demo using qemu and vnc.
5e8fc4975SFrançois Revol * Copyright 2007, Francois Revol, revol@free.fr.
6e8fc4975SFrançois Revol */
7e8fc4975SFrançois Revol
8664c8b6dSFrançois Revol// parts inspired by the Free Live OS Zoo
9664c8b6dSFrançois Revol// http://www.oszoo.org/wiki/index.php/Free_Live_OS_Zoo
10664c8b6dSFrançois Revol
114cf03112SFrançois Revol
124cf03112SFrançois Revol// include local configuration that possibly overrides defines below.
134cf03112SFrançois Revolif (file_exists('haiku.conf.php'))
144cf03112SFrançois Revol	include('haiku.conf.php');
154cf03112SFrançois Revol
164cf03112SFrançois Revol
1798d26da2SFrançois Revol// name of the page
1898d26da2SFrançois Revoldefine("PAGE_TITLE", "Haiku Online Demo");
1998d26da2SFrançois Revol
20664c8b6dSFrançois Revol
21e8fc4975SFrançois Revol// relative path to the vnc java applet jar
22e8fc4975SFrançois Revol// you must *copy* (apache doesn't seem to like symlinks) it there.
23e8fc4975SFrançois Revol
24e8fc4975SFrançois Revol// on debian, apt-get install vnc-java will put them in
25e8fc4975SFrançois Revol// /usr/share/vnc-java
26e8fc4975SFrançois Revol//define("VNCJAVA_PATH", "vnc-java");
27e8fc4975SFrançois Revol//define("VNCJAR", "vncviewer.jar");
28e8fc4975SFrançois Revol//define("VNCCLASS", "vncviewer.class");
29e8fc4975SFrançois Revol
30e8fc4975SFrançois Revol// to use the tightvnc applet instead (supports > 8bpp):
31e8fc4975SFrançois Revol// on debian, apt-get install tightvnc-java will put them in
32e8fc4975SFrançois Revol// /usr/share/tightvnc-java
33e8fc4975SFrançois Revoldefine("VNCJAVA_PATH", "tightvnc-java");
34e8fc4975SFrançois Revoldefine("VNCJAR", "VncViewer.jar");
35e8fc4975SFrançois Revoldefine("VNCCLASS", "VncViewer.class");
36e8fc4975SFrançois Revol
37e8fc4975SFrançois Revol// maximum count of qemu instances.
3891054f1dSFrançois Revoldefine("MAX_QEMUS", 2);
39e8fc4975SFrançois Revol
40e8fc4975SFrançois Revol// size of the java applet, must match the default resolution of the image.
4152a7cf96SFrançois Revol//define("APPLET_WIDTH", "800");
4252a7cf96SFrançois Revol//define("APPLET_HEIGHT", "600");
4352a7cf96SFrançois Revoldefine("APPLET_WIDTH", "1024");
4452a7cf96SFrançois Revoldefine("APPLET_HEIGHT", "768");
45e8fc4975SFrançois Revol// vnc protocol base port.
46e8fc4975SFrançois Revoldefine("VNCPORTBASE", 5900);
47e8fc4975SFrançois Revol
48664c8b6dSFrançois Revol// base port for audio streams
49f0cbfcafSFrançois Revol//define("AUDIOPORTBASE", 8080);
50f0cbfcafSFrançois Revoldefine("AUDIOPORTBASE", (VNCPORTBASE + MAX_QEMUS));
51f0cbfcafSFrançois Revol
52f0cbfcafSFrançois Revol// base port for serial output
53f0cbfcafSFrançois Revol//define("SERIALPORTBASE", 9000);
54f0cbfcafSFrançois Revoldefine("SERIALPORTBASE", (VNCPORTBASE + MAX_QEMUS * 2));
55664c8b6dSFrançois Revol
56e8fc4975SFrançois Revol// timeout before the demo session is killed, as argument to /bin/sleep
574720c31bSFrançois Revoldefine("SESSION_TIMEOUT", "20m");
58e8fc4975SFrançois Revol
59e8fc4975SFrançois Revol// path to qemu binary
60c6f50a6aSFrançois Revoldefine("QEMU_BASE", "/usr/local");
61c6f50a6aSFrançois Revoldefine("QEMU_BIN", QEMU_BASE . "/bin/qemu");
62c6f50a6aSFrançois Revoldefine("QEMU_KEYMAPS", QEMU_BASE . "/share/qemu/keymaps");
63e8fc4975SFrançois Revol// default arguments: no network, emulate tablet, readonly image file.
644720c31bSFrançois Revoldefine("QEMU_ARGS", ""
65d2bef01cSFrançois Revol	."-daemonize " /* detach from stdin */
66d2bef01cSFrançois Revol	."-localtime " /* not UTC */
674cf03112SFrançois Revol	."-name '" . addslashes(PAGE_TITLE) . "' "
684720c31bSFrançois Revol	."-monitor /dev/null "
694720c31bSFrançois Revol	."-serial none "
704720c31bSFrançois Revol	."-parallel none "
714720c31bSFrançois Revol	."-net none "
724720c31bSFrançois Revol	."-usbdevice wacom-tablet "
734720c31bSFrançois Revol	."-vga vmware "
744720c31bSFrançois Revol	."-snapshot ");
75d2bef01cSFrançois Revol
76e8fc4975SFrançois Revol// absolute path to the image.
774cf03112SFrançois Revoldefine("QEMU_IMAGE_PATH", "/home/revol/haiku.image");
784cf03112SFrançois Revol// BAD: let's one download the image
794cf03112SFrançois Revol//define("QEMU_IMAGE_PATH", dirname($_SERVER['SCRIPT_FILENAME']) . "/haiku.image");
80*b12110c5SFrançois Revol
81*b12110c5SFrançois Revol// max number of cpus for the VM, not more than 8
82*b12110c5SFrançois Revoldefine("QEMU_MAX_CPUS", 1);
83*b12110c5SFrançois Revol
848ad2eabaSFrançois Revol// qemu 0.8.2 needs "", qemu 0.9.1 needs ":"
858ad2eabaSFrançois Revoldefine("QEMU_VNC_PREFIX", ":");
86e8fc4975SFrançois Revol
87e8fc4975SFrançois Revol// name of session and pid files in /tmp
88e8fc4975SFrançois Revoldefine("QEMU_SESSFILE_TMPL", "qemu-haiku-session-");
89e8fc4975SFrançois Revoldefine("QEMU_PIDFILE_TMPL", "qemu-haiku-pid-");
90e8fc4975SFrançois Revol// name of session variable holding the qemu slot; not yet used correctly
91e8fc4975SFrançois Revoldefine("QEMU_IDX_VAR", "QEMU_HAIKU_SESSION_VAR");
92e8fc4975SFrançois Revol
93f0cbfcafSFrançois Revol
94f0cbfcafSFrançois Revol// uncomment if you want to pass your Sonix webcam device through
95f0cbfcafSFrançois Revol// migth need to update VID:PID
964cf03112SFrançois Revol// doesnt really work yet
97f0cbfcafSFrançois Revol//define("QEMU_USB_PASSTHROUGH", "-usbdevice host:0c45:6005");
98f0cbfcafSFrançois Revol
99f0cbfcafSFrançois Revol
1004720c31bSFrançois Revoldefine("BGCOLOR", "#336698");
1014720c31bSFrançois Revol
102f0cbfcafSFrançois Revol
1034cf03112SFrançois Revol
1044cf03112SFrançois Revol
1054720c31bSFrançois Revol$vnckeymap = "en-us";
1064720c31bSFrançois Revol
107f0cbfcafSFrançois Revol$cpucount = 1;
108f0cbfcafSFrançois Revol
1094720c31bSFrançois Revol// statics
11098d26da2SFrançois Revol//$count = $_SESSION['compteur'];
1114720c31bSFrançois Revol//$count = $GLOBALS['compteur'];
1124720c31bSFrançois Revol$closing = 0;
1134720c31bSFrançois Revol$do_kill = 0;
1144720c31bSFrançois Revol$do_run = 0;
1154720c31bSFrançois Revol
1164720c31bSFrançois Revolfunction out($str)
1174720c31bSFrançois Revol{
1184720c31bSFrançois Revol	echo "<div class=\"haiku_online_out\">$str</div>\n";
1194720c31bSFrançois Revol	ob_flush();
1204720c31bSFrançois Revol	flush();
1214720c31bSFrançois Revol}
1224720c31bSFrançois Revol
123e8fc4975SFrançois Revolfunction dbg($str)
124e8fc4975SFrançois Revol{
1254720c31bSFrançois Revol	echo "<div class=\"haiku_online_debug\">$str</div>\n";
1264720c31bSFrançois Revol	ob_flush();
1274720c31bSFrançois Revol	flush();
128e8fc4975SFrançois Revol}
129e8fc4975SFrançois Revol
130e8fc4975SFrançois Revolfunction err($str)
131e8fc4975SFrançois Revol{
1324720c31bSFrançois Revol	echo "<div class=\"haiku_online_error\">$str</div>\n";
1334720c31bSFrançois Revol	ob_flush();
1344720c31bSFrançois Revol	flush();
135e8fc4975SFrançois Revol}
136e8fc4975SFrançois Revol
137e8fc4975SFrançois Revolfunction make_qemu_sessionfile_name($idx)
138e8fc4975SFrançois Revol{
139e8fc4975SFrançois Revol	return "/tmp/" . QEMU_SESSFILE_TMPL . $idx;
140e8fc4975SFrançois Revol}
141e8fc4975SFrançois Revol
142e8fc4975SFrançois Revolfunction make_qemu_pidfile_name($idx)
143e8fc4975SFrançois Revol{
144e8fc4975SFrançois Revol	return "/tmp/" . QEMU_PIDFILE_TMPL . $idx;
145e8fc4975SFrançois Revol}
146e8fc4975SFrançois Revol
147e8fc4975SFrançois Revolfunction find_qemu_slot()
148e8fc4975SFrançois Revol{
149e8fc4975SFrançois Revol	for ($idx = 0; $idx < MAX_QEMUS; $idx++) {
150e8fc4975SFrançois Revol		$pidfile = make_qemu_pidfile_name($idx);
151e8fc4975SFrançois Revol		$sessfile = make_qemu_sessionfile_name($idx);
152e8fc4975SFrançois Revol		dbg("checking \"$pidfile\", \"$sessfile\"...");
153e8fc4975SFrançois Revol		if (!file_exists($pidfile) && !file_exists($sessfile)) {
154e8fc4975SFrançois Revol			file_put_contents($sessfile, session_id());
155e8fc4975SFrançois Revol			$sid = file_get_contents($sessfile);
156e8fc4975SFrançois Revol			if ($sid != session_id())
157e8fc4975SFrançois Revol				continue;
158e8fc4975SFrançois Revol			$_SESSION[QEMU_IDX_VAR] = $idx;
159e8fc4975SFrançois Revol			return $idx;
160e8fc4975SFrançois Revol		}
161e8fc4975SFrançois Revol	}
162e8fc4975SFrançois Revol	return -1;
163e8fc4975SFrançois Revol}
164e8fc4975SFrançois Revol
1654720c31bSFrançois Revolfunction total_qemu_slots()
1664720c31bSFrançois Revol{
1674720c31bSFrançois Revol	return MAX_QEMUS;
1684720c31bSFrançois Revol}
1694720c31bSFrançois Revol
1704720c31bSFrançois Revol
1714720c31bSFrançois Revolfunction available_qemu_slots()
1724720c31bSFrançois Revol{
1734720c31bSFrançois Revol	$count = 0;
1744720c31bSFrançois Revol	for ($idx = 0; $idx < MAX_QEMUS; $idx++) {
1754720c31bSFrançois Revol		$pidfile = make_qemu_pidfile_name($idx);
1764720c31bSFrançois Revol		$sessfile = make_qemu_sessionfile_name($idx);
1774720c31bSFrançois Revol		//dbg("checking \"$pidfile\", \"$sessfile\"...");
1784720c31bSFrançois Revol		if (!file_exists($pidfile) && !file_exists($sessfile))
1794720c31bSFrançois Revol			$count++;
1804720c31bSFrançois Revol	}
1814720c31bSFrançois Revol	return $count;
1824720c31bSFrançois Revol}
1834720c31bSFrançois Revol
184e8fc4975SFrançois Revolfunction qemu_slot()
185e8fc4975SFrançois Revol{
186e8fc4975SFrançois Revol	return $_SESSION[QEMU_IDX_VAR];
187e8fc4975SFrançois Revol}
188e8fc4975SFrançois Revol
189664c8b6dSFrançois Revolfunction audio_port()
190664c8b6dSFrançois Revol{
191664c8b6dSFrançois Revol	return AUDIOPORTBASE + qemu_slot();
192664c8b6dSFrançois Revol}
193664c8b6dSFrançois Revol
194e8fc4975SFrançois Revolfunction vnc_display()
195e8fc4975SFrançois Revol{
196e8fc4975SFrançois Revol	return qemu_slot();
197e8fc4975SFrançois Revol}
198e8fc4975SFrançois Revol
19998d26da2SFrançois Revolfunction vnc_addr()
20098d26da2SFrançois Revol{
20198d26da2SFrançois Revol	return $_SERVER['HTTP_HOST'];
20298d26da2SFrançois Revol}
20398d26da2SFrançois Revol
204e8fc4975SFrançois Revolfunction vnc_port()
205e8fc4975SFrançois Revol{
206e8fc4975SFrançois Revol	return VNCPORTBASE + vnc_display();
207e8fc4975SFrançois Revol}
208e8fc4975SFrançois Revol
2094720c31bSFrançois Revolfunction vnc_addr_display()
2104720c31bSFrançois Revol{
21198d26da2SFrançois Revol	return vnc_addr() . ":" . vnc_display();
2124720c31bSFrançois Revol}
2134720c31bSFrançois Revol
2144720c31bSFrançois Revolfunction vnc_url()
2154720c31bSFrançois Revol{
2164720c31bSFrançois Revol	return "vnc://" . vnc_addr_display();
2174720c31bSFrançois Revol}
2184720c31bSFrançois Revol
219e8fc4975SFrançois Revolfunction is_my_session_valid()
220e8fc4975SFrançois Revol{
221e8fc4975SFrançois Revol	if (!isset($_SESSION[QEMU_IDX_VAR]))
222e8fc4975SFrançois Revol		return 0;
223e8fc4975SFrançois Revol	$idx = $_SESSION[QEMU_IDX_VAR];
224e8fc4975SFrançois Revol	$sessfile = make_qemu_sessionfile_name($idx);
225e8fc4975SFrançois Revol	if (!file_exists($sessfile))
226e8fc4975SFrançois Revol		return 0;
227e8fc4975SFrançois Revol	$qemusession=file_get_contents($sessfile);
228e8fc4975SFrançois Revol	// has expired
229e8fc4975SFrançois Revol	if ($qemusession != session_id()) {
230e8fc4975SFrançois Revol		return 0;
231e8fc4975SFrançois Revol	}
232e8fc4975SFrançois Revol	return 1;
233e8fc4975SFrançois Revol}
234e8fc4975SFrançois Revol
235e8fc4975SFrançois Revol
2364720c31bSFrançois Revolfunction list_keymaps()
2374720c31bSFrançois Revol{
2384720c31bSFrançois Revol	$bads = array('.', '..', 'common', 'modifiers');
2394720c31bSFrançois Revol	$keymaps = scandir(QEMU_KEYMAPS);
2404720c31bSFrançois Revol	foreach ($keymaps as $key => $map) {
2414720c31bSFrançois Revol		if (in_array($map, $bads))
2424720c31bSFrançois Revol			unset($keymaps[$key]);
2434720c31bSFrançois Revol	}
2444720c31bSFrançois Revol	return $keymaps;
2454720c31bSFrançois Revol}
2464720c31bSFrançois Revol
2474720c31bSFrançois Revol
2484720c31bSFrançois Revolfunction in_keymaps($keymap)
2494720c31bSFrançois Revol{
2504720c31bSFrançois Revol	$keymaps = list_keymaps();
2514720c31bSFrançois Revol
2524720c31bSFrançois Revol	if ($keymap == "")
2534720c31bSFrançois Revol		return false;
2544720c31bSFrançois Revol	if (in_array($keymap, $keymaps))
2554720c31bSFrançois Revol		return true;
2564720c31bSFrançois Revol
2574720c31bSFrançois Revol	return false;
2584720c31bSFrançois Revol}
259c6f50a6aSFrançois Revol
260c6f50a6aSFrançois Revol
261c6f50a6aSFrançois Revolfunction probe_keymap()
262c6f50a6aSFrançois Revol{
263c6f50a6aSFrançois Revol	global $vnckeymap;
2644720c31bSFrançois Revol	if (is_string($_GET['keymap']) && in_keymaps($_GET['keymap']))
2654720c31bSFrançois Revol	{
2664720c31bSFrançois Revol		$vnckeymap = $_GET['keymap'];
2674720c31bSFrançois Revol		dbg("Overriden keymap '" . $vnckeymap . "' in arguments.");
2684720c31bSFrançois Revol		return;
2694720c31bSFrançois Revol	}
270c6f50a6aSFrançois Revol	// if the browser advertised a prefered lang...
271c6f50a6aSFrançois Revol	if (!isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]))
272c6f50a6aSFrançois Revol		return;
273c6f50a6aSFrançois Revol	$langs = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
274c6f50a6aSFrançois Revol	$langs = ereg_replace(";q=[^,]*", "", $langs);
275c6f50a6aSFrançois Revol	$langs = str_replace(" ", "", $langs);
276c6f50a6aSFrançois Revol	$langs = split(",", $langs);
277c6f50a6aSFrançois Revol	//print_r($langs);
278c6f50a6aSFrançois Revol	//print_r($keymaps);
279c6f50a6aSFrançois Revol	foreach($langs as $lang)
280c6f50a6aSFrançois Revol	{
2814720c31bSFrançois Revol		if (in_keymaps($lang))
282c6f50a6aSFrançois Revol		{
2834720c31bSFrançois Revol			$vnckeymap = $lang;
284664c8b6dSFrançois Revol			dbg("Detected keymap '" . $vnckeymap .
285664c8b6dSFrançois Revol			    "' from browser headers.");
286c6f50a6aSFrançois Revol			return;
287c6f50a6aSFrançois Revol		}
288c6f50a6aSFrançois Revol	}
289c6f50a6aSFrançois Revol}
2904720c31bSFrançois Revol
2914720c31bSFrançois Revol
292f0cbfcafSFrançois Revolfunction probe_options_form()
293f0cbfcafSFrançois Revol{
294f0cbfcafSFrançois Revol	global $cpucount;
295f0cbfcafSFrançois Revol	$cpucount = 1;
296f0cbfcafSFrançois Revol	if (isset($_GET['cpucount']))
297f0cbfcafSFrançois Revol		$cpucount = (int)$_GET['cpucount'];
298*b12110c5SFrançois Revol	$cpucount = max(min($cpucount, QEMU_MAX_CPUS), 1);
299f0cbfcafSFrançois Revol	//dbg("cpucount $cpucount");
300f0cbfcafSFrançois Revol}
301f0cbfcafSFrançois Revol
302f0cbfcafSFrançois Revol
3034720c31bSFrançois Revolfunction output_options_form()
3044720c31bSFrançois Revol{
3054720c31bSFrançois Revol	global $vnckeymap;
3064720c31bSFrançois Revol	$idx = qemu_slot();
3074720c31bSFrançois Revol	echo "<form method=\"get\" action=\"" . $_SERVER['PHP_SELF'] . "\">";
3084720c31bSFrançois Revol	echo "<table border=\"0\" class=\"haiku_online_form\">\n";
309d2bef01cSFrançois Revol
310f0cbfcafSFrançois Revol	$keymaps = list_keymaps();
311d2bef01cSFrançois Revol	echo "<tr>\n<td align=\"right\">\n";
3124720c31bSFrançois Revol	echo "Select your keymap:";
313d2bef01cSFrançois Revol	echo "</td>\n<td>\n";
3144720c31bSFrançois Revol	echo "<select name=\"keymap\">";
3154720c31bSFrançois Revol	foreach ($keymaps as $keymap) {
316f0cbfcafSFrançois Revol		echo "<option value=\"$keymap\" ";
3174720c31bSFrançois Revol		if ($keymap == $vnckeymap)
318f0cbfcafSFrançois Revol			echo "selected=\"selected\" ";
3194720c31bSFrançois Revol		echo ">$keymap</option>";
3204720c31bSFrançois Revol		//echo "<option name=\"keymap\" ";
3214720c31bSFrançois Revol		//echo "value=\"$keymap\">" . locale_get_display_name($keymap);
3224720c31bSFrançois Revol		//echo "</option>";
3234720c31bSFrançois Revol	}
3244720c31bSFrançois Revol	echo "</select>";
325d2bef01cSFrançois Revol	echo "</td>\n</tr>\n";
3264720c31bSFrançois Revol
327f0cbfcafSFrançois Revol
3284720c31bSFrançois Revol	$modes = array("1024x768"/*, "800x600"*/);
3294720c31bSFrançois Revol	echo "<tr ";
3304720c31bSFrançois Revol	if (count($modes) < 2)
3314720c31bSFrançois Revol		echo "class=\"haiku_online_disabled\"";
3324720c31bSFrançois Revol	echo ">\n";
3334720c31bSFrançois Revol	echo "<td align=\"right\">\n";
3344720c31bSFrançois Revol	echo "Select display size:";
335d2bef01cSFrançois Revol	echo "</td>\n<td>\n";
3364720c31bSFrançois Revol	echo "<select name=\"videomode\" ";
3374720c31bSFrançois Revol	if (count($modes) < 2)
338f0cbfcafSFrançois Revol		echo "disabled=\"disabled\"";
3394720c31bSFrançois Revol	echo ">";
3404720c31bSFrançois Revol	foreach ($modes as $mode) {
341f0cbfcafSFrançois Revol		echo "<option value=\"$mode\" ";
3424720c31bSFrançois Revol		if ($mode == $videomode)
343f0cbfcafSFrançois Revol			echo "selected=\"selected\" ";
3444720c31bSFrançois Revol		echo ">$mode</option>";
3454720c31bSFrançois Revol	}
3464720c31bSFrançois Revol	echo "</select>";
347d2bef01cSFrançois Revol	echo "</td>\n</tr>\n";
3484720c31bSFrançois Revol
349f0cbfcafSFrançois Revol
350f0cbfcafSFrançois Revol	echo "<tr ";
351*b12110c5SFrançois Revol	if (QEMU_MAX_CPUS < 2)
352f0cbfcafSFrançois Revol		echo "class=\"haiku_online_disabled\"";
353f0cbfcafSFrançois Revol	echo ">\n";
354f0cbfcafSFrançois Revol	echo "<td align=\"right\">\n";
355f0cbfcafSFrançois Revol	echo "Select cpu count:";
356f0cbfcafSFrançois Revol	echo "</td>\n<td>\n";
357f0cbfcafSFrançois Revol	echo "<select name=\"cpucount\" ";
358*b12110c5SFrançois Revol	if (QEMU_MAX_CPUS < 2)
359f0cbfcafSFrançois Revol		echo "disabled=\"disabled\"";
360f0cbfcafSFrançois Revol	echo ">";
361*b12110c5SFrançois Revol	for ($ncpu = 1; $ncpu <= QEMU_MAX_CPUS; $ncpu++) {
362f0cbfcafSFrançois Revol		echo "<option value=\"$ncpu\" ";
363f0cbfcafSFrançois Revol		if ($ncpu == 1)
364f0cbfcafSFrançois Revol			echo "selected=\"selected\" ";
365f0cbfcafSFrançois Revol		echo ">$ncpu</option>";
366f0cbfcafSFrançois Revol	}
367f0cbfcafSFrançois Revol	echo "</select>";
368f0cbfcafSFrançois Revol	echo "</td>\n</tr>\n";
369f0cbfcafSFrançois Revol
370f0cbfcafSFrançois Revol
371f0cbfcafSFrançois Revol	$enable_sound = 0;
3724720c31bSFrançois Revol	echo "<tr ";
3734720c31bSFrançois Revol	if (!$enable_sound)
3744720c31bSFrançois Revol		echo "class=\"haiku_online_disabled\"";
3754720c31bSFrançois Revol	echo ">\n";
3764720c31bSFrançois Revol	echo "<td align=\"right\">\n";
377d2bef01cSFrançois Revol	echo "Check to enable sound:";
378d2bef01cSFrançois Revol	echo "</td>\n<td>\n";
379d2bef01cSFrançois Revol	echo "<input type=\"checkbox\" name=\"sound\" id=\"sound_cb\" ";
380f0cbfcafSFrançois Revol	echo "value=\"1\" ";
381664c8b6dSFrançois Revol	if ($enable_sound) {
38291054f1dSFrançois Revol		echo "checked=\"checked\" /";
383f0cbfcafSFrançois Revol	} else
384f0cbfcafSFrançois Revol		echo "disabled=\"disabled\" /";
38591054f1dSFrançois Revol	echo "><label for=\"sound_cb\">Sound</label>";
386d2bef01cSFrançois Revol	echo "</td>\n</tr>\n";
387d2bef01cSFrançois Revol
388f0cbfcafSFrançois Revol	$enable_serial = 1;
389f0cbfcafSFrançois Revol	echo "<tr ";
390f0cbfcafSFrançois Revol	if (!$enable_serial)
391f0cbfcafSFrançois Revol		echo "class=\"haiku_online_disabled\"";
392f0cbfcafSFrançois Revol	echo ">\n";
393f0cbfcafSFrançois Revol	echo "<td align=\"right\">\n";
394f0cbfcafSFrançois Revol	echo "Check to enable serial output:";
395f0cbfcafSFrançois Revol	echo "</td>\n<td>\n";
396f0cbfcafSFrançois Revol	echo "<input type=\"checkbox\" name=\"serial\" id=\"serial_cb\" ";
397f0cbfcafSFrançois Revol	echo "value=\"1\" "/*"disabled "*/;
398f0cbfcafSFrançois Revol	if ($enable_serial) {
399f0cbfcafSFrançois Revol		//echo "checked ";
40091054f1dSFrançois Revol	}
40191054f1dSFrançois Revol	echo "/><label for=\"serial_cb\">Serial</label>";
402f0cbfcafSFrançois Revol	echo "</td>\n</tr>\n";
403f0cbfcafSFrançois Revol
404f0cbfcafSFrançois Revol	if (defined("QEMU_USB_PASSTHROUGH")) {
405f0cbfcafSFrançois Revol
406f0cbfcafSFrançois Revol		$enable_webcam = 1;
407f0cbfcafSFrançois Revol		echo "<tr ";
408f0cbfcafSFrançois Revol		if (!$enable_webcam)
409f0cbfcafSFrançois Revol			echo "class=\"haiku_online_disabled\"";
410f0cbfcafSFrançois Revol		echo ">\n";
411f0cbfcafSFrançois Revol		echo "<td align=\"right\">\n";
412f0cbfcafSFrançois Revol		echo "Check to enable webcam:";
413f0cbfcafSFrançois Revol		echo "</td>\n<td>\n";
414f0cbfcafSFrançois Revol		echo "<input type=\"checkbox\" name=\"webcam\" id=\"webcam_cb\" ";
415f0cbfcafSFrançois Revol		echo "value=\"1\" "/*"disabled "*/;
416f0cbfcafSFrançois Revol		if ($enable_webcam) {
417f0cbfcafSFrançois Revol			//echo "checked ";
41891054f1dSFrançois Revol		}
41991054f1dSFrançois Revol		echo "/><label for=\"webcam_cb\">Webcam</label>";
420f0cbfcafSFrançois Revol		echo "</td>\n</tr>\n";
421f0cbfcafSFrançois Revol	}
422d2bef01cSFrançois Revol	/*
423d2bef01cSFrançois Revol	echo "<tr>\n<td align=\"right\">\n";
4244720c31bSFrançois Revol	//out("Click here to enable sound:");
425d2bef01cSFrançois Revol	echo "</td>\n<td>\n";
426d2bef01cSFrançois Revol	echo "</td>\n</tr>\n";
427d2bef01cSFrançois Revol
428d2bef01cSFrançois Revol	echo "<tr>\n<td align=\"right\">\n";
429d2bef01cSFrançois Revol	//out("Click here to enable sound:");
430d2bef01cSFrançois Revol	echo "</td>\n<td>\n";
431d2bef01cSFrançois Revol	echo "</td>\n</tr>\n";
432d2bef01cSFrançois Revol	*/
433d2bef01cSFrançois Revol
434d2bef01cSFrançois Revol	echo "<tr>\n<td align=\"right\">\n";
4354720c31bSFrançois Revol	echo "Click here to start the session:";
436d2bef01cSFrançois Revol	echo "</td>\n<td>\n";
4374720c31bSFrançois Revol	echo "<input type=\"submit\" name=\"run\" ";
4384720c31bSFrançois Revol	echo "value=\"Start!\" />";
439d2bef01cSFrançois Revol	echo "</td>\n</tr>\n";
440d2bef01cSFrançois Revol
4414720c31bSFrançois Revol	echo "</table>\n";
4424720c31bSFrançois Revol	echo "</form>\n";
443664c8b6dSFrançois Revol	out("NOTE: You will need a Java-enabled browser to display the VNC " .
444664c8b6dSFrançois Revol	    "Applet needed by this demo.");
4454720c31bSFrançois Revol	out("You can however use instead an external <a " .
4464720c31bSFrançois Revol	    "href=\"http://fr.wikipedia.org/wiki/Virtual_Network_Computing\"" .
4474720c31bSFrançois Revol	    ">VNC viewer</a>.");
4484720c31bSFrançois Revol	ob_flush();
4494720c31bSFrançois Revol	flush();
4504720c31bSFrançois Revol}
4514720c31bSFrançois Revol
4524720c31bSFrançois Revolfunction output_kill_form()
4534720c31bSFrançois Revol{
4544720c31bSFrançois Revol	echo "<form method=\"get\" action=\"" . $_SERVER['PHP_SELF'] . "\">";
4554720c31bSFrançois Revol	echo "<table border=\"0\" class=\"haiku_online_form\">\n";
4564720c31bSFrançois Revol	echo "<tr>\n";
4574720c31bSFrançois Revol	echo "<td>\n";
4584720c31bSFrançois Revol	echo "Click here to kill the session:";
4594720c31bSFrançois Revol	echo "</td>\n";
4604720c31bSFrançois Revol	echo "<td>\n";
4614720c31bSFrançois Revol	echo "<input type=\"submit\" name=\"kill\" ";
4624720c31bSFrançois Revol	echo "value=\"Terminate\"/>";
4634720c31bSFrançois Revol	echo "</td>\n";
4644720c31bSFrançois Revol	echo "</tr>\n";
4654720c31bSFrançois Revol	echo "</table>\n";
4664720c31bSFrançois Revol	echo "</form>\n";
4674720c31bSFrançois Revol	ob_flush();
4684720c31bSFrançois Revol	flush();
469c6f50a6aSFrançois Revol}
470c6f50a6aSFrançois Revol
471c6f50a6aSFrançois Revol
472e8fc4975SFrançois Revolfunction start_qemu()
473e8fc4975SFrançois Revol{
474c6f50a6aSFrançois Revol	global $vnckeymap;
475f0cbfcafSFrançois Revol	global $cpucount;
476e8fc4975SFrançois Revol	$idx = find_qemu_slot();
477e8fc4975SFrançois Revol	if ($idx < 0) {
478e8fc4975SFrançois Revol		err("No available qemu slot, please try later.");
479e8fc4975SFrançois Revol		return $idx;
480e8fc4975SFrançois Revol	}
481e8fc4975SFrançois Revol	$pidfile = make_qemu_pidfile_name($idx);
482f0cbfcafSFrançois Revol	$cmd = QEMU_BIN . " " . QEMU_ARGS;
483f0cbfcafSFrançois Revol	if ($cpucount > 1)
484f0cbfcafSFrançois Revol		$cmd .= " -smp " . $cpucount;
485f0cbfcafSFrançois Revol	if (isset($_GET['serial'])) {
486f0cbfcafSFrançois Revol		$cmd .= " -serial telnet::";
487f0cbfcafSFrançois Revol		$cmd .= (SERIALPORTBASE + qemu_slot());
488f0cbfcafSFrançois Revol		$cmd .= ",server,nowait,nodelay";
489f0cbfcafSFrançois Revol	}
490f0cbfcafSFrançois Revol	if (isset($_GET['webcam']) && defined("QEMU_USB_PASSTHROUGH")) {
491f0cbfcafSFrançois Revol		$cmd .= " " . QEMU_USB_PASSTHROUGH;
492f0cbfcafSFrançois Revol	}
493f0cbfcafSFrançois Revol	$cmd .= " -k " . $vnckeymap .
494664c8b6dSFrançois Revol		" -vnc " . QEMU_VNC_PREFIX . vnc_display() .
495664c8b6dSFrançois Revol		" -pidfile " . $pidfile .
496664c8b6dSFrançois Revol		" " . QEMU_IMAGE_PATH;
497e8fc4975SFrançois Revol
498e8fc4975SFrançois Revol	if (file_exists($pidfile))
499e8fc4975SFrançois Revol		unlink($pidfile);
500e8fc4975SFrançois Revol	dbg("Starting <tt>" . $cmd . "</tt>...");
501e8fc4975SFrançois Revol
502e8fc4975SFrançois Revol	$descriptorspec = array(
503e8fc4975SFrançois Revol	//       0 => array("pipe", "r"),   // stdin
504e8fc4975SFrançois Revol	//       1 => array("pipe", "w"),  // stdout
505e8fc4975SFrançois Revol	//       2 => array("pipe", "w")   // stderr
506e8fc4975SFrançois Revol	);
507e8fc4975SFrançois Revol	//$cmd="/bin/ls";
508e8fc4975SFrançois Revol	//passthru($cmd, $ret);
509e8fc4975SFrançois Revol	//dbg("ret=$ret");
510e8fc4975SFrançois Revol	$cmd .= " &";
511e8fc4975SFrançois Revol	$process = proc_open($cmd, $descriptorspec, $pipes);
512e8fc4975SFrançois Revol	sleep(1);
513e8fc4975SFrançois Revol	proc_close($process);
514e8fc4975SFrançois Revol
515e8fc4975SFrançois Revol	dbg("Started QEMU.");
516e8fc4975SFrançois Revol	$sessfile = make_qemu_sessionfile_name($idx);
517664c8b6dSFrançois Revol	$cmd = "(PID=`cat " . $pidfile . "`; " .
518664c8b6dSFrançois Revol	  "sleep " . SESSION_TIMEOUT . "; " .
519664c8b6dSFrançois Revol	  "kill -9 \$PID && " .
520664c8b6dSFrançois Revol	  "rm " . $pidfile . " " . $sessfile . ") &";
521e8fc4975SFrançois Revol
522e8fc4975SFrançois Revol	$process = proc_open($cmd, $descriptorspec, $wkpipes);
523e8fc4975SFrançois Revol	sleep(1);
524e8fc4975SFrançois Revol	proc_close($process);
525e8fc4975SFrançois Revol
526e8fc4975SFrançois Revol	dbg("Started timed kill.");
527e8fc4975SFrançois Revol	dbg("Ready for a " . SESSION_TIMEOUT . " session.");
528e8fc4975SFrançois Revol}
529e8fc4975SFrançois Revol
5304720c31bSFrançois Revolfunction stop_qemu()
5314720c31bSFrançois Revol{
5324720c31bSFrançois Revol	$qemuidx = qemu_slot();
5334720c31bSFrançois Revol	$pidfile = make_qemu_pidfile_name($qemuidx);
5344720c31bSFrançois Revol	if (file_exists($pidfile)) {
5354720c31bSFrançois Revol		$pid = file_get_contents($pidfile);
5364720c31bSFrançois Revol		//out("PID:" . $pid);
5374720c31bSFrançois Revol		system("/bin/kill -TERM " . $pid);
5384720c31bSFrançois Revol		unlink($pidfile);
5394720c31bSFrançois Revol	}
5404720c31bSFrançois Revol	$sessionfile = make_qemu_sessionfile_name($qemuidx);
5414720c31bSFrançois Revol	if (file_exists($sessionfile)) {
5424720c31bSFrançois Revol		unlink($sessionfile);
5434720c31bSFrançois Revol	}
5444720c31bSFrançois Revol	unset($_SESSION[QEMU_IDX_VAR]);
5454720c31bSFrançois Revol
5464720c31bSFrançois Revol	out("reloading...");
5474720c31bSFrançois Revol	sleep(1);
5484720c31bSFrançois Revol	echo "<script>\n";
5494720c31bSFrançois Revol	echo "<!--\n";
5504720c31bSFrançois Revol	echo "window.location = \"" . $_SERVER['PHP_SELF'] . "\";\n";
5514720c31bSFrançois Revol	echo "//--></script>\n";
5524720c31bSFrançois Revol	out("Click <a href=\"" . $_SERVER['PHP_SELF'] .
5534720c31bSFrançois Revol	    "\">here</a> to reload the page.");
5544720c31bSFrançois Revol}
5554720c31bSFrançois Revol
5564720c31bSFrançois Revolfunction output_vnc_info()
5574720c31bSFrançois Revol{
558664c8b6dSFrançois Revol	out("You can use an external VNC client at " .
559664c8b6dSFrançois Revol	    "<a href=\"vnc://" . vnc_addr_display() . "\">" .
560664c8b6dSFrançois Revol	    "vnc://" . vnc_addr_display() . "</a> " .
56198d26da2SFrançois Revol	    "or open <a href=\"" . $_SERVER['PHP_SELF'] . "?getfile=vncinfo&slot=" . vnc_display() . "\">this file</a>, " .
5624720c31bSFrançois Revol	    "or enter <tt>" . vnc_addr_display() . "</tt> in your " .
563664c8b6dSFrançois Revol	    "<a href=\"http://fr.wikipedia.org/wiki/Virtual_Network_" .
564664c8b6dSFrançois Revol	    "Computing\"" .
565f0cbfcafSFrançois Revol	    ">VNC viewer</a>.");
566f0cbfcafSFrançois Revol	//echo "<br />\n";
5674720c31bSFrançois Revol}
568e8fc4975SFrançois Revol
56998d26da2SFrançois Revolfunction output_vnc_info_file()
57098d26da2SFrançois Revol{
57198d26da2SFrançois Revol	if (!is_my_session_valid())
57298d26da2SFrançois Revol		die("Bad request");
57398d26da2SFrançois Revol
57498d26da2SFrançois Revol	header("Content-type: application/x-vnc");
57598d26da2SFrançois Revol	header('Content-Disposition: attachment; filename="onlinedemo.vnc"');
57698d26da2SFrançois Revol
57798d26da2SFrançois Revol	echo "[connection]\n";
57898d26da2SFrançois Revol	echo "host=" . vnc_addr() . "\n";
57998d26da2SFrançois Revol	echo "port=" . vnc_display() . "\n";
58098d26da2SFrançois Revol	//echo "password=XXX\n";
58198d26da2SFrançois Revol	//echo "[options]\n";
58298d26da2SFrançois Revol	// cf. http://www.realvnc.com/pipermail/vnc-list/1999-December/011086.html
58398d26da2SFrançois Revol	// cf. http://www.tek-tips.com/viewthread.cfm?qid=1173303&page=1
58498d26da2SFrançois Revol	//echo "\n";
58598d26da2SFrançois Revol}
58698d26da2SFrançois Revol
587664c8b6dSFrançois Revolfunction output_audio_player_code($external_only=false)
588664c8b6dSFrançois Revol{
589664c8b6dSFrançois Revol	if (true)
590664c8b6dSFrançois Revol		return;
591664c8b6dSFrançois Revol
592664c8b6dSFrançois Revol	$port = audio_port();
593664c8b6dSFrançois Revol	$url = "http://" . $_SERVER['HTTP_HOST'] . ":$port/";
594664c8b6dSFrançois Revol	$icy = "icy://" . $_SERVER['HTTP_HOST'] . ":$port/";
595664c8b6dSFrançois Revol	if (!$external_only) {
596664c8b6dSFrançois Revol		echo "<embed src=\"$url\" type=\"audio/mpeg\" ";
597664c8b6dSFrançois Revol		echo "autoplay=\"true\" width=\"300\" height=\"50\" ";
598664c8b6dSFrançois Revol		echo "controller=\"true\" align=\"right\">";
599664c8b6dSFrançois Revol	}
600664c8b6dSFrançois Revol	out("You can use an external audio play at " .
60198d26da2SFrançois Revol	    "<a href=\"$url\">$url</a> or <a href=\"$icy\">$icy</a>, or use " .
60298d26da2SFrançois Revol	    "<a href=\"" . $_SERVER['PHP_SELF'] . "?getfile=audiopls\">this playlist</a>.");
60398d26da2SFrançois Revol}
60498d26da2SFrançois Revol
60598d26da2SFrançois Revolfunction output_audio_player_file()
60698d26da2SFrançois Revol{
60798d26da2SFrançois Revol	if (!is_my_session_valid())
60898d26da2SFrançois Revol		die("Bad request");
60998d26da2SFrançois Revol
61098d26da2SFrançois Revol	header("Content-type: audio/x-mpegurl");
61198d26da2SFrançois Revol	//header("Content-type: text/plain");
61298d26da2SFrançois Revol	//header('Content-Disposition: attachment; filename="onlinedemo.m3u"');
61398d26da2SFrançois Revol
61498d26da2SFrançois Revol	$port = audio_port();
61598d26da2SFrançois Revol	$url = "http://" . $_SERVER['HTTP_HOST'] . ":$port/";
61698d26da2SFrançois Revol
61798d26da2SFrançois Revol	//echo "#EXTM3U\n";
61898d26da2SFrançois Revol	//echo "#EXTINF:0," . PAGE_TITLE . "\n";
61998d26da2SFrançois Revol	echo "$url\n";
62098d26da2SFrançois Revol	//echo "\n";
621664c8b6dSFrançois Revol}
622664c8b6dSFrançois Revol
623664c8b6dSFrançois Revolfunction output_applet_code($external_only=false)
624e8fc4975SFrançois Revol{
625e8fc4975SFrançois Revol	$w = APPLET_WIDTH;
626e8fc4975SFrançois Revol	$h = APPLET_HEIGHT;
627e8fc4975SFrançois Revol	$port = vnc_port();
628e8fc4975SFrançois Revol	$vncjpath = VNCJAVA_PATH;
629e8fc4975SFrançois Revol	$jar = VNCJAR;
630e8fc4975SFrançois Revol	$class = VNCCLASS;
631664c8b6dSFrançois Revol	if ($external_only)
632664c8b6dSFrançois Revol		return;
633f0cbfcafSFrançois Revol	echo "<a name=\"haiku_online_applet\"></a>";
6344720c31bSFrançois Revol	echo "<center>";
6354720c31bSFrançois Revol	echo "<applet code=$class codebase=\"$vncjpath/\" ";
6364720c31bSFrançois Revol	echo "archive=\"$vncjpath/$jar\" width=$w height=$h ";
6374720c31bSFrançois Revol	echo "bgcolor=\"#336698\">\n";
6384720c31bSFrançois Revol	//not needed
6394720c31bSFrançois Revol	//echo "<param name=\"HOST\" value=\"$HTTP_HOST\">\n";
6404720c31bSFrançois Revol	echo "<param name=\"PORT\" value=\"$port\">\n";
6414720c31bSFrançois Revol	echo "<param name=\"PASSWORD\" value=\"\">\n";
6424720c31bSFrançois Revol	//echo "<param name=\"share desktop\" value=\"no\" />";
6434720c31bSFrançois Revol	echo "<param name=\"background-color\" value=\"#336698\">\n";
6444720c31bSFrançois Revol	echo "<param name=\"foreground-color\" value=\"#ffffff\">\n";
6454720c31bSFrançois Revol	//echo "<param name=\"background\" value=\"#336698\">\n";
6464720c31bSFrançois Revol	//echo "<param name=\"foreground\" value=\"#ffffff\">\n";
6474720c31bSFrançois Revol	echo "There should be a java applet here... ";
6484720c31bSFrançois Revol	echo "make sure you have a JVM and it's enabled!<br />\n";
6494720c31bSFrançois Revol	echo "If you do not have Java you can use an external VNC ";
6504720c31bSFrançois Revol	echo "client as described above.\n";
6514720c31bSFrançois Revol
6524720c31bSFrançois Revol	echo "</applet>\n";
6534720c31bSFrançois Revol	echo "</center>";
6544720c31bSFrançois Revol	ob_flush();
6554720c31bSFrançois Revol	flush();
6564720c31bSFrançois Revol	// scroll to the top of the applet
6574720c31bSFrançois Revol	echo "<script>\n";
6584720c31bSFrançois Revol	echo "<!--\n";
6594cf03112SFrançois Revol	echo "scrollToAnchor(\"haiku_online_applet\");";
6604720c31bSFrançois Revol	echo "//--></script>\n";
6614720c31bSFrançois Revol	ob_flush();
6624720c31bSFrançois Revol	flush();
663e8fc4975SFrançois Revol}
664e8fc4975SFrançois Revol
665f0cbfcafSFrançois Revolfunction output_serial_output_code($external_only=false)
666f0cbfcafSFrançois Revol{
667f0cbfcafSFrançois Revol	if (!isset($_GET['serial']))
668f0cbfcafSFrançois Revol		return;
669f0cbfcafSFrançois Revol
670f0cbfcafSFrançois Revol	$url = "telnet://" . $_SERVER['HTTP_HOST'] . ":";
671f0cbfcafSFrançois Revol	$url .= (SERIALPORTBASE + qemu_slot()) . "/";
672f0cbfcafSFrançois Revol	out("You can get serial output at <a href=\"$url\">$url</a>");
673f0cbfcafSFrançois Revol	return;
674f0cbfcafSFrançois Revol
675f0cbfcafSFrançois Revol	// not really http...
676f0cbfcafSFrançois Revol	$url = "http://" . $_SERVER['HTTP_HOST'] . ":";
677f0cbfcafSFrançois Revol	$url .= (SERIALPORTBASE + qemu_slot()) . "/";
678f0cbfcafSFrançois Revol	echo "<center>";
679f0cbfcafSFrançois Revol	echo "<iframe src=\"$url/\" type=\"text/plain\" width=\"100%\" ";
680f0cbfcafSFrançois Revol	echo "height=\"200\"></iframe>";
681f0cbfcafSFrançois Revol	echo "</center>";
682f0cbfcafSFrançois Revol
683f0cbfcafSFrançois Revol}
684f0cbfcafSFrançois Revol
68598d26da2SFrançois Revol
68698d26da2SFrançois Revolsession_start();
68798d26da2SFrançois Revol
68898d26da2SFrançois Revol// parse args
68998d26da2SFrançois Revol
69098d26da2SFrançois Revol// output redirections...
69198d26da2SFrançois Revolif (isset($_GET['getfile'])) {
69298d26da2SFrançois Revol	switch ($_GET['getfile']) {
69398d26da2SFrançois Revol	case "vncinfo":
69498d26da2SFrançois Revol		output_vnc_info_file();
69598d26da2SFrançois Revol		break;
69698d26da2SFrançois Revol	case "audiopls":
69798d26da2SFrançois Revol		output_audio_player_file();
69898d26da2SFrançois Revol		break;
69998d26da2SFrançois Revol	default:
70098d26da2SFrançois Revol		die("Bad request");
70198d26da2SFrançois Revol	}
70298d26da2SFrançois Revol	die();
70398d26da2SFrançois Revol}
70498d26da2SFrançois Revol
70598d26da2SFrançois Revolif (isset($_GET['close']))
70698d26da2SFrançois Revol	$closing = 1;
70798d26da2SFrançois Revol
70898d26da2SFrançois Revolif (isset($_GET['kill']))
70998d26da2SFrançois Revol	$do_kill = 1;
71098d26da2SFrançois Revol
71198d26da2SFrançois Revolif (isset($_GET['run']))
71298d26da2SFrançois Revol	$do_run = 1;
71398d26da2SFrançois Revol
71498d26da2SFrançois Revolif (isset($_GET['frame'])) {}
71598d26da2SFrançois Revol
71698d26da2SFrançois Revol
71798d26da2SFrançois Revol//echo "do_run: " . $do_run . "<br>\n";
71898d26da2SFrançois Revol//echo "do_kill: " . $do_kill . "<br>\n";
71998d26da2SFrançois Revol
72098d26da2SFrançois Revol?>
72198d26da2SFrançois Revol<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
72298d26da2SFrançois Revol<head>
72398d26da2SFrançois Revol<meta name="robots" content="noindex, nofollow, noarchive" />
72498d26da2SFrançois Revol<title><?php echo PAGE_TITLE; ?></title>
72598d26da2SFrançois Revol<link rel="shortcut icon" href="http://www.haiku-os.org/themes/shijin/favicon.ico" type="image/x-icon" />
72698d26da2SFrançois Revol<style type="text/css">
72798d26da2SFrançois Revol<!--
72898d26da2SFrançois Revol /* basic style */
72998d26da2SFrançois Revolbody { background-color: <?php echo BGCOLOR; ?>; }
73098d26da2SFrançois Revola:link { color:orange; }
73198d26da2SFrançois Revola:visited { color:darkorange; }
73298d26da2SFrançois Revola:hover { color:pink; }
73398d26da2SFrançois Revol.haiku_online_form { color: white; }
73498d26da2SFrançois Revol.haiku_online_disabled { color: grey; }
73598d26da2SFrançois Revol.haiku_online_out { color: white; }
73698d26da2SFrançois Revol.haiku_online_debug { color: orange; }
73798d26da2SFrançois Revol.haiku_online_error { color: red; font-weight: bold; }
73898d26da2SFrançois Revol.haiku_online_applet { background-color: <?php echo BGCOLOR; ?>; }
73998d26da2SFrançois Revol-->
74098d26da2SFrançois Revol</style>
74198d26da2SFrançois Revol<script type="text/javascript">
74298d26da2SFrançois Revolfunction onPageUnload() {
74398d26da2SFrançois Revol	//window.open("<?php echo $_SERVER["SCRIPT_NAME"] . "?close"; ?>", "closing", "width=100,height=30,location=no,menubar=no,toolbar=no,scrollbars=no");
74498d26da2SFrançois Revol}
7454cf03112SFrançois Revol
7464cf03112SFrançois Revolfunction scrollToAnchor(anchor) {
7474cf03112SFrançois Revol  var a = document.anchors[anchor];
7484cf03112SFrançois Revol  if (a) {
7494cf03112SFrançois Revol    if (a.scrollIntoView)
7504cf03112SFrançois Revol      a.scrollIntoView(true);
7514cf03112SFrançois Revol    else if (a.focus)
7524cf03112SFrançois Revol      a.focus();
7534cf03112SFrançois Revol  } else
7544cf03112SFrançois Revol    window.location.hash = anchor;
7554cf03112SFrançois Revol}
75698d26da2SFrançois Revol</script>
75798d26da2SFrançois Revol</head>
75898d26da2SFrançois Revol<?php
75998d26da2SFrançois Revol
76098d26da2SFrançois Revol
76198d26da2SFrançois Revolif ($closing == 1)
76298d26da2SFrançois Revol	echo "<body>";
76398d26da2SFrançois Revolelse
76498d26da2SFrançois Revol	echo "<body onunload=\"onPageUnload();\">";
76598d26da2SFrançois Revol
76698d26da2SFrançois Revol
767f0cbfcafSFrançois Revolout("<div style=\"text-align:right;\">Available displays: " .
7684720c31bSFrançois Revol    available_qemu_slots() . "/" . total_qemu_slots() .
7694720c31bSFrançois Revol    "</div>");
7704720c31bSFrançois Revol
7714720c31bSFrançois Revol
7724720c31bSFrançois Revolprobe_keymap();
773f0cbfcafSFrançois Revolprobe_options_form();
7744720c31bSFrançois Revol
775e8fc4975SFrançois Revoldbg("Checking if session is running...");
776e8fc4975SFrançois Revol
7774720c31bSFrançois Revol$qemuidx = -1;
778c6f50a6aSFrançois Revol
779e8fc4975SFrançois Revolif (is_my_session_valid()) {
7804720c31bSFrançois Revol	dbg("Session running.");
781e8fc4975SFrançois Revol	$qemuidx = qemu_slot();
7824720c31bSFrançois Revol	if ($do_kill) {
783e8fc4975SFrançois Revol		dbg("closing...");
7844720c31bSFrançois Revol		stop_qemu();
785e8fc4975SFrançois Revol	}
7864720c31bSFrançois Revol} else if (!$do_kill && $do_run) {
7874720c31bSFrançois Revol	dbg("Need to start qemu.");
7884720c31bSFrançois Revol
7894720c31bSFrançois Revol	$qemuidx = start_qemu();
790f0cbfcafSFrançois Revol	//out("Waiting for vnc server...");
791f0cbfcafSFrançois Revol	//sleep(5);
7924720c31bSFrançois Revol}
7934720c31bSFrançois Revol
7944720c31bSFrançois Revol
7954720c31bSFrançois Revolif ($qemuidx >= 0 && !$do_kill) {
7964720c31bSFrançois Revol	output_kill_form();
797f0cbfcafSFrançois Revol	output_serial_output_code();
798664c8b6dSFrançois Revol	output_audio_player_code();
7994720c31bSFrançois Revol	output_vnc_info();
800f0cbfcafSFrançois Revol	out("Waiting for vnc server...");
801f0cbfcafSFrançois Revol	sleep(1);
8024720c31bSFrançois Revol	output_applet_code();
8034720c31bSFrançois Revol} else {
8044720c31bSFrançois Revol	output_options_form();
805e8fc4975SFrançois Revol}
806e8fc4975SFrançois Revol
807d2bef01cSFrançois Revol//phpinfo();
808e8fc4975SFrançois Revol
809e8fc4975SFrançois Revol?>
810e8fc4975SFrançois Revol
811e8fc4975SFrançois Revol</body>
812e8fc4975SFrançois Revol</html>
813