xref: /haiku/3rdparty/mmu_man/onlinedemo/haiku.php (revision b9068dbf95e05818c251ab36f8cb1d8619d2c9be)
1<?php
2
3/*
4 * haiku.php - an online Haiku demo using qemu and vnc.
5 * Copyright 2007, Francois Revol, revol@free.fr.
6 */
7
8// parts inspired by the Free Live OS Zoo
9// http://www.oszoo.org/wiki/index.php/Free_Live_OS_Zoo
10
11// name of the page
12define("PAGE_TITLE", "Haiku Online Demo");
13
14
15// relative path to the vnc java applet jar
16// you must *copy* (apache doesn't seem to like symlinks) it there.
17
18// on debian, apt-get install vnc-java will put them in
19// /usr/share/vnc-java
20//define("VNCJAVA_PATH", "vnc-java");
21//define("VNCJAR", "vncviewer.jar");
22//define("VNCCLASS", "vncviewer.class");
23
24// to use the tightvnc applet instead (supports > 8bpp):
25// on debian, apt-get install tightvnc-java will put them in
26// /usr/share/tightvnc-java
27define("VNCJAVA_PATH", "tightvnc-java");
28define("VNCJAR", "VncViewer.jar");
29define("VNCCLASS", "VncViewer.class");
30
31// maximum count of qemu instances.
32define("MAX_QEMUS", 2);
33
34// size of the java applet, must match the default resolution of the image.
35//define("APPLET_WIDTH", "800");
36//define("APPLET_HEIGHT", "600");
37define("APPLET_WIDTH", "1024");
38define("APPLET_HEIGHT", "768");
39// vnc protocol base port.
40define("VNCPORTBASE", 5900);
41
42// base port for audio streams
43//define("AUDIOPORTBASE", 8080);
44define("AUDIOPORTBASE", (VNCPORTBASE + MAX_QEMUS));
45
46// base port for serial output
47//define("SERIALPORTBASE", 9000);
48define("SERIALPORTBASE", (VNCPORTBASE + MAX_QEMUS * 2));
49
50// timeout before the demo session is killed, as argument to /bin/sleep
51define("SESSION_TIMEOUT", "20m");
52
53// path to qemu binary
54define("QEMU_BASE", "/usr/local");
55define("QEMU_BIN", QEMU_BASE . "/bin/qemu");
56define("QEMU_KEYMAPS", QEMU_BASE . "/share/qemu/keymaps");
57// default arguments: no network, emulate tablet, readonly image file.
58define("QEMU_ARGS", ""
59	."-daemonize " /* detach from stdin */
60	."-localtime " /* not UTC */
61	."-name '" . PAGE_TITLE . "' "
62	."-monitor /dev/null "
63	."-serial none "
64	."-parallel none "
65	." -net none "
66	."-usbdevice wacom-tablet "
67	."-vga vmware "
68	."-snapshot");
69
70// absolute path to the image.
71define("QEMU_IMAGE_PATH","/home/revol/haiku/trunk/generated.x86/haiku.image");
72// qemu 0.8.2 needs "", qemu 0.9.1 needs ":"
73define("QEMU_VNC_PREFIX", ":");
74
75// name of session and pid files in /tmp
76define("QEMU_SESSFILE_TMPL", "qemu-haiku-session-");
77define("QEMU_PIDFILE_TMPL", "qemu-haiku-pid-");
78// name of session variable holding the qemu slot; not yet used correctly
79define("QEMU_IDX_VAR", "QEMU_HAIKU_SESSION_VAR");
80
81
82// uncomment if you want to pass your Sonix webcam device through
83// migth need to update VID:PID
84//define("QEMU_USB_PASSTHROUGH", "-usbdevice host:0c45:6005");
85
86
87define("BGCOLOR", "#336698");
88
89
90$vnckeymap = "en-us";
91
92$cpucount = 1;
93
94// statics
95//$count = $_SESSION['compteur'];
96//$count = $GLOBALS['compteur'];
97$closing = 0;
98$do_kill = 0;
99$do_run = 0;
100
101function out($str)
102{
103	echo "<div class=\"haiku_online_out\">$str</div>\n";
104	ob_flush();
105	flush();
106}
107
108function dbg($str)
109{
110	echo "<div class=\"haiku_online_debug\">$str</div>\n";
111	ob_flush();
112	flush();
113}
114
115function err($str)
116{
117	echo "<div class=\"haiku_online_error\">$str</div>\n";
118	ob_flush();
119	flush();
120}
121
122function make_qemu_sessionfile_name($idx)
123{
124	return "/tmp/" . QEMU_SESSFILE_TMPL . $idx;
125}
126
127function make_qemu_pidfile_name($idx)
128{
129	return "/tmp/" . QEMU_PIDFILE_TMPL . $idx;
130}
131
132function find_qemu_slot()
133{
134	for ($idx = 0; $idx < MAX_QEMUS; $idx++) {
135		$pidfile = make_qemu_pidfile_name($idx);
136		$sessfile = make_qemu_sessionfile_name($idx);
137		dbg("checking \"$pidfile\", \"$sessfile\"...");
138		if (!file_exists($pidfile) && !file_exists($sessfile)) {
139			file_put_contents($sessfile, session_id());
140			$sid = file_get_contents($sessfile);
141			if ($sid != session_id())
142				continue;
143			$_SESSION[QEMU_IDX_VAR] = $idx;
144			return $idx;
145		}
146	}
147	return -1;
148}
149
150function total_qemu_slots()
151{
152	return MAX_QEMUS;
153}
154
155
156function available_qemu_slots()
157{
158	$count = 0;
159	for ($idx = 0; $idx < MAX_QEMUS; $idx++) {
160		$pidfile = make_qemu_pidfile_name($idx);
161		$sessfile = make_qemu_sessionfile_name($idx);
162		//dbg("checking \"$pidfile\", \"$sessfile\"...");
163		if (!file_exists($pidfile) && !file_exists($sessfile))
164			$count++;
165	}
166	return $count;
167}
168
169function qemu_slot()
170{
171	return $_SESSION[QEMU_IDX_VAR];
172}
173
174function audio_port()
175{
176	return AUDIOPORTBASE + qemu_slot();
177}
178
179function vnc_display()
180{
181	return qemu_slot();
182}
183
184function vnc_addr()
185{
186	return $_SERVER['HTTP_HOST'];
187}
188
189function vnc_port()
190{
191	return VNCPORTBASE + vnc_display();
192}
193
194function vnc_addr_display()
195{
196	return vnc_addr() . ":" . vnc_display();
197}
198
199function vnc_url()
200{
201	return "vnc://" . vnc_addr_display();
202}
203
204function is_my_session_valid()
205{
206	if (!isset($_SESSION[QEMU_IDX_VAR]))
207		return 0;
208	$idx = $_SESSION[QEMU_IDX_VAR];
209	$sessfile = make_qemu_sessionfile_name($idx);
210	if (!file_exists($sessfile))
211		return 0;
212	$qemusession=file_get_contents($sessfile);
213	// has expired
214	if ($qemusession != session_id()) {
215		return 0;
216	}
217	return 1;
218}
219
220
221function list_keymaps()
222{
223	$bads = array('.', '..', 'common', 'modifiers');
224	$keymaps = scandir(QEMU_KEYMAPS);
225	foreach ($keymaps as $key => $map) {
226		if (in_array($map, $bads))
227			unset($keymaps[$key]);
228	}
229	return $keymaps;
230}
231
232
233function in_keymaps($keymap)
234{
235	$keymaps = list_keymaps();
236
237	if ($keymap == "")
238		return false;
239	if (in_array($keymap, $keymaps))
240		return true;
241
242	return false;
243}
244
245
246function probe_keymap()
247{
248	global $vnckeymap;
249	if (is_string($_GET['keymap']) && in_keymaps($_GET['keymap']))
250	{
251		$vnckeymap = $_GET['keymap'];
252		dbg("Overriden keymap '" . $vnckeymap . "' in arguments.");
253		return;
254	}
255	// if the browser advertised a prefered lang...
256	if (!isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]))
257		return;
258	$langs = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
259	$langs = ereg_replace(";q=[^,]*", "", $langs);
260	$langs = str_replace(" ", "", $langs);
261	$langs = split(",", $langs);
262	//print_r($langs);
263	//print_r($keymaps);
264	foreach($langs as $lang)
265	{
266		if (in_keymaps($lang))
267		{
268			$vnckeymap = $lang;
269			dbg("Detected keymap '" . $vnckeymap .
270			    "' from browser headers.");
271			return;
272		}
273	}
274}
275
276
277function probe_options_form()
278{
279	global $cpucount;
280	$cpucount = 1;
281	if (isset($_GET['cpucount']))
282		$cpucount = (int)$_GET['cpucount'];
283	$cpucount = max(min($cpucount, 8), 1);
284	//dbg("cpucount $cpucount");
285	$cpucount = 1; // force for now
286}
287
288
289function output_options_form()
290{
291	global $vnckeymap;
292	$idx = qemu_slot();
293	echo "<form method=\"get\" action=\"" . $_SERVER['PHP_SELF'] . "\">";
294	echo "<table border=\"0\" class=\"haiku_online_form\">\n";
295
296	$keymaps = list_keymaps();
297	echo "<tr>\n<td align=\"right\">\n";
298	echo "Select your keymap:";
299	echo "</td>\n<td>\n";
300	echo "<select name=\"keymap\">";
301	foreach ($keymaps as $keymap) {
302		echo "<option value=\"$keymap\" ";
303		if ($keymap == $vnckeymap)
304			echo "selected=\"selected\" ";
305		echo ">$keymap</option>";
306		//echo "<option name=\"keymap\" ";
307		//echo "value=\"$keymap\">" . locale_get_display_name($keymap);
308		//echo "</option>";
309	}
310	echo "</select>";
311	echo "</td>\n</tr>\n";
312
313
314	$modes = array("1024x768"/*, "800x600"*/);
315	echo "<tr ";
316	if (count($modes) < 2)
317		echo "class=\"haiku_online_disabled\"";
318	echo ">\n";
319	echo "<td align=\"right\">\n";
320	echo "Select display size:";
321	echo "</td>\n<td>\n";
322	echo "<select name=\"videomode\" ";
323	if (count($modes) < 2)
324		echo "disabled=\"disabled\"";
325	echo ">";
326	foreach ($modes as $mode) {
327		echo "<option value=\"$mode\" ";
328		if ($mode == $videomode)
329			echo "selected=\"selected\" ";
330		echo ">$mode</option>";
331	}
332	echo "</select>";
333	echo "</td>\n</tr>\n";
334
335
336	$maxcpus = 8;
337	echo "<tr ";
338	if (!$enable_cpus)
339		echo "class=\"haiku_online_disabled\"";
340	echo ">\n";
341	echo "<td align=\"right\">\n";
342	echo "Select cpu count:";
343	echo "</td>\n<td>\n";
344	echo "<select name=\"cpucount\" ";
345	if (!$enable_cpus)
346		echo "disabled=\"disabled\"";
347	echo ">";
348	for ($ncpu = 1; $ncpu <= $maxcpus; $ncpu++) {
349		echo "<option value=\"$ncpu\" ";
350		if ($ncpu == 1)
351			echo "selected=\"selected\" ";
352		echo ">$ncpu</option>";
353	}
354	echo "</select>";
355	echo "</td>\n</tr>\n";
356
357
358	$enable_sound = 0;
359	echo "<tr ";
360	if (!$enable_sound)
361		echo "class=\"haiku_online_disabled\"";
362	echo ">\n";
363	echo "<td align=\"right\">\n";
364	echo "Check to enable sound:";
365	echo "</td>\n<td>\n";
366	echo "<input type=\"checkbox\" name=\"sound\" id=\"sound_cb\" ";
367	echo "value=\"1\" ";
368	if ($enable_sound) {
369		echo "checked=\"checked\" /";
370	} else
371		echo "disabled=\"disabled\" /";
372	echo "><label for=\"sound_cb\">Sound</label>";
373	echo "</td>\n</tr>\n";
374
375	$enable_serial = 1;
376	echo "<tr ";
377	if (!$enable_serial)
378		echo "class=\"haiku_online_disabled\"";
379	echo ">\n";
380	echo "<td align=\"right\">\n";
381	echo "Check to enable serial output:";
382	echo "</td>\n<td>\n";
383	echo "<input type=\"checkbox\" name=\"serial\" id=\"serial_cb\" ";
384	echo "value=\"1\" "/*"disabled "*/;
385	if ($enable_serial) {
386		//echo "checked ";
387	}
388	echo "/><label for=\"serial_cb\">Serial</label>";
389	echo "</td>\n</tr>\n";
390
391	if (defined("QEMU_USB_PASSTHROUGH")) {
392
393		$enable_webcam = 1;
394		echo "<tr ";
395		if (!$enable_webcam)
396			echo "class=\"haiku_online_disabled\"";
397		echo ">\n";
398		echo "<td align=\"right\">\n";
399		echo "Check to enable webcam:";
400		echo "</td>\n<td>\n";
401		echo "<input type=\"checkbox\" name=\"webcam\" id=\"webcam_cb\" ";
402		echo "value=\"1\" "/*"disabled "*/;
403		if ($enable_webcam) {
404			//echo "checked ";
405		}
406		echo "/><label for=\"webcam_cb\">Webcam</label>";
407		echo "</td>\n</tr>\n";
408	}
409	/*
410	echo "<tr>\n<td align=\"right\">\n";
411	//out("Click here to enable sound:");
412	echo "</td>\n<td>\n";
413	echo "</td>\n</tr>\n";
414
415	echo "<tr>\n<td align=\"right\">\n";
416	//out("Click here to enable sound:");
417	echo "</td>\n<td>\n";
418	echo "</td>\n</tr>\n";
419	*/
420
421	echo "<tr>\n<td align=\"right\">\n";
422	echo "Click here to start the session:";
423	echo "</td>\n<td>\n";
424	echo "<input type=\"submit\" name=\"run\" ";
425	echo "value=\"Start!\" />";
426	echo "</td>\n</tr>\n";
427
428	echo "</table>\n";
429	echo "</form>\n";
430	out("NOTE: You will need a Java-enabled browser to display the VNC " .
431	    "Applet needed by this demo.");
432	out("You can however use instead an external <a " .
433	    "href=\"http://fr.wikipedia.org/wiki/Virtual_Network_Computing\"" .
434	    ">VNC viewer</a>.");
435	ob_flush();
436	flush();
437}
438
439function output_kill_form()
440{
441	echo "<form method=\"get\" action=\"" . $_SERVER['PHP_SELF'] . "\">";
442	echo "<table border=\"0\" class=\"haiku_online_form\">\n";
443	echo "<tr>\n";
444	echo "<td>\n";
445	echo "Click here to kill the session:";
446	echo "</td>\n";
447	echo "<td>\n";
448	echo "<input type=\"submit\" name=\"kill\" ";
449	echo "value=\"Terminate\"/>";
450	echo "</td>\n";
451	echo "</tr>\n";
452	echo "</table>\n";
453	echo "</form>\n";
454	ob_flush();
455	flush();
456}
457
458
459function start_qemu()
460{
461	global $vnckeymap;
462	global $cpucount;
463	$idx = find_qemu_slot();
464	if ($idx < 0) {
465		err("No available qemu slot, please try later.");
466		return $idx;
467	}
468	$pidfile = make_qemu_pidfile_name($idx);
469	$cmd = QEMU_BIN . " " . QEMU_ARGS;
470	if ($cpucount > 1)
471		$cmd .= " -smp " . $cpucount;
472	if (isset($_GET['serial'])) {
473		$cmd .= " -serial telnet::";
474		$cmd .= (SERIALPORTBASE + qemu_slot());
475		$cmd .= ",server,nowait,nodelay";
476	}
477	if (isset($_GET['webcam']) && defined("QEMU_USB_PASSTHROUGH")) {
478		$cmd .= " " . QEMU_USB_PASSTHROUGH;
479	}
480	$cmd .= " -k " . $vnckeymap .
481		" -vnc " . QEMU_VNC_PREFIX . vnc_display() .
482		" -pidfile " . $pidfile .
483		" " . QEMU_IMAGE_PATH;
484
485	if (file_exists($pidfile))
486		unlink($pidfile);
487	dbg("Starting <tt>" . $cmd . "</tt>...");
488
489	$descriptorspec = array(
490	//       0 => array("pipe", "r"),   // stdin
491	//       1 => array("pipe", "w"),  // stdout
492	//       2 => array("pipe", "w")   // stderr
493	);
494	//$cmd="/bin/ls";
495	//passthru($cmd, $ret);
496	//dbg("ret=$ret");
497	$cmd .= " &";
498	$process = proc_open($cmd, $descriptorspec, $pipes);
499	sleep(1);
500	proc_close($process);
501
502	dbg("Started QEMU.");
503	$sessfile = make_qemu_sessionfile_name($idx);
504	$cmd = "(PID=`cat " . $pidfile . "`; " .
505	  "sleep " . SESSION_TIMEOUT . "; " .
506	  "kill -9 \$PID && " .
507	  "rm " . $pidfile . " " . $sessfile . ") &";
508
509	$process = proc_open($cmd, $descriptorspec, $wkpipes);
510	sleep(1);
511	proc_close($process);
512
513	dbg("Started timed kill.");
514	dbg("Ready for a " . SESSION_TIMEOUT . " session.");
515}
516
517function stop_qemu()
518{
519	$qemuidx = qemu_slot();
520	$pidfile = make_qemu_pidfile_name($qemuidx);
521	if (file_exists($pidfile)) {
522		$pid = file_get_contents($pidfile);
523		//out("PID:" . $pid);
524		system("/bin/kill -TERM " . $pid);
525		unlink($pidfile);
526	}
527	$sessionfile = make_qemu_sessionfile_name($qemuidx);
528	if (file_exists($sessionfile)) {
529		unlink($sessionfile);
530	}
531	unset($_SESSION[QEMU_IDX_VAR]);
532
533	out("reloading...");
534	sleep(1);
535	echo "<script>\n";
536	echo "<!--\n";
537	echo "window.location = \"" . $_SERVER['PHP_SELF'] . "\";\n";
538	echo "//--></script>\n";
539	out("Click <a href=\"" . $_SERVER['PHP_SELF'] .
540	    "\">here</a> to reload the page.");
541}
542
543function output_vnc_info()
544{
545	out("You can use an external VNC client at " .
546	    "<a href=\"vnc://" . vnc_addr_display() . "\">" .
547	    "vnc://" . vnc_addr_display() . "</a> " .
548	    "or open <a href=\"" . $_SERVER['PHP_SELF'] . "?getfile=vncinfo&slot=" . vnc_display() . "\">this file</a>, " .
549	    "or enter <tt>" . vnc_addr_display() . "</tt> in your " .
550	    "<a href=\"http://fr.wikipedia.org/wiki/Virtual_Network_" .
551	    "Computing\"" .
552	    ">VNC viewer</a>.");
553	//echo "<br />\n";
554}
555
556function output_vnc_info_file()
557{
558	if (!is_my_session_valid())
559		die("Bad request");
560
561	header("Content-type: application/x-vnc");
562	header('Content-Disposition: attachment; filename="onlinedemo.vnc"');
563
564	echo "[connection]\n";
565	echo "host=" . vnc_addr() . "\n";
566	echo "port=" . vnc_display() . "\n";
567	//echo "password=XXX\n";
568	//echo "[options]\n";
569	// cf. http://www.realvnc.com/pipermail/vnc-list/1999-December/011086.html
570	// cf. http://www.tek-tips.com/viewthread.cfm?qid=1173303&page=1
571	//echo "\n";
572}
573
574function output_audio_player_code($external_only=false)
575{
576	if (true)
577		return;
578
579	$port = audio_port();
580	$url = "http://" . $_SERVER['HTTP_HOST'] . ":$port/";
581	$icy = "icy://" . $_SERVER['HTTP_HOST'] . ":$port/";
582	if (!$external_only) {
583		echo "<embed src=\"$url\" type=\"audio/mpeg\" ";
584		echo "autoplay=\"true\" width=\"300\" height=\"50\" ";
585		echo "controller=\"true\" align=\"right\">";
586	}
587	out("You can use an external audio play at " .
588	    "<a href=\"$url\">$url</a> or <a href=\"$icy\">$icy</a>, or use " .
589	    "<a href=\"" . $_SERVER['PHP_SELF'] . "?getfile=audiopls\">this playlist</a>.");
590}
591
592function output_audio_player_file()
593{
594	if (!is_my_session_valid())
595		die("Bad request");
596
597	header("Content-type: audio/x-mpegurl");
598	//header("Content-type: text/plain");
599	//header('Content-Disposition: attachment; filename="onlinedemo.m3u"');
600
601	$port = audio_port();
602	$url = "http://" . $_SERVER['HTTP_HOST'] . ":$port/";
603
604	//echo "#EXTM3U\n";
605	//echo "#EXTINF:0," . PAGE_TITLE . "\n";
606	echo "$url\n";
607	//echo "\n";
608}
609
610function output_applet_code($external_only=false)
611{
612	$w = APPLET_WIDTH;
613	$h = APPLET_HEIGHT;
614	$port = vnc_port();
615	$vncjpath = VNCJAVA_PATH;
616	$jar = VNCJAR;
617	$class = VNCCLASS;
618	if ($external_only)
619		return;
620	echo "<a name=\"haiku_online_applet\"></a>";
621	echo "<center>";
622	echo "<applet code=$class codebase=\"$vncjpath/\" ";
623	echo "archive=\"$vncjpath/$jar\" width=$w height=$h ";
624	echo "bgcolor=\"#336698\">\n";
625	//not needed
626	//echo "<param name=\"HOST\" value=\"$HTTP_HOST\">\n";
627	echo "<param name=\"PORT\" value=\"$port\">\n";
628	echo "<param name=\"PASSWORD\" value=\"\">\n";
629	//echo "<param name=\"share desktop\" value=\"no\" />";
630	echo "<param name=\"background-color\" value=\"#336698\">\n";
631	echo "<param name=\"foreground-color\" value=\"#ffffff\">\n";
632	//echo "<param name=\"background\" value=\"#336698\">\n";
633	//echo "<param name=\"foreground\" value=\"#ffffff\">\n";
634	echo "There should be a java applet here... ";
635	echo "make sure you have a JVM and it's enabled!<br />\n";
636	echo "If you do not have Java you can use an external VNC ";
637	echo "client as described above.\n";
638
639	echo "</applet>\n";
640	echo "</center>";
641	ob_flush();
642	flush();
643	// scroll to the top of the applet
644	echo "<script>\n";
645	echo "<!--\n";
646	echo "window.location.hash = \"haiku_online_applet\";";
647	echo "//--></script>\n";
648	ob_flush();
649	flush();
650}
651
652function output_serial_output_code($external_only=false)
653{
654	if (!isset($_GET['serial']))
655		return;
656
657	$url = "telnet://" . $_SERVER['HTTP_HOST'] . ":";
658	$url .= (SERIALPORTBASE + qemu_slot()) . "/";
659	out("You can get serial output at <a href=\"$url\">$url</a>");
660	return;
661
662	// not really http...
663	$url = "http://" . $_SERVER['HTTP_HOST'] . ":";
664	$url .= (SERIALPORTBASE + qemu_slot()) . "/";
665	echo "<center>";
666	echo "<iframe src=\"$url/\" type=\"text/plain\" width=\"100%\" ";
667	echo "height=\"200\"></iframe>";
668	echo "</center>";
669
670}
671
672
673session_start();
674
675// parse args
676
677// output redirections...
678if (isset($_GET['getfile'])) {
679	switch ($_GET['getfile']) {
680	case "vncinfo":
681		output_vnc_info_file();
682		break;
683	case "audiopls":
684		output_audio_player_file();
685		break;
686	default:
687		die("Bad request");
688	}
689	die();
690}
691
692if (isset($_GET['close']))
693	$closing = 1;
694
695if (isset($_GET['kill']))
696	$do_kill = 1;
697
698if (isset($_GET['run']))
699	$do_run = 1;
700
701if (isset($_GET['frame'])) {}
702
703
704//echo "do_run: " . $do_run . "<br>\n";
705//echo "do_kill: " . $do_kill . "<br>\n";
706
707?>
708<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
709<head>
710<meta name="robots" content="noindex, nofollow, noarchive" />
711<title><?php echo PAGE_TITLE; ?></title>
712<link rel="shortcut icon" href="http://www.haiku-os.org/themes/shijin/favicon.ico" type="image/x-icon" />
713<style type="text/css">
714<!--
715 /* basic style */
716body { background-color: <?php echo BGCOLOR; ?>; }
717a:link { color:orange; }
718a:visited { color:darkorange; }
719a:hover { color:pink; }
720.haiku_online_form { color: white; }
721.haiku_online_disabled { color: grey; }
722.haiku_online_out { color: white; }
723.haiku_online_debug { color: orange; }
724.haiku_online_error { color: red; font-weight: bold; }
725.haiku_online_applet { background-color: <?php echo BGCOLOR; ?>; }
726-->
727</style>
728<script type="text/javascript">
729function onPageUnload() {
730	//window.open("<?php echo $_SERVER["SCRIPT_NAME"] . "?close"; ?>", "closing", "width=100,height=30,location=no,menubar=no,toolbar=no,scrollbars=no");
731}
732</script>
733</head>
734<?php
735
736
737if ($closing == 1)
738	echo "<body>";
739else
740	echo "<body onunload=\"onPageUnload();\">";
741
742
743out("<div style=\"text-align:right;\">Available displays: " .
744    available_qemu_slots() . "/" . total_qemu_slots() .
745    "</div>");
746
747
748probe_keymap();
749probe_options_form();
750
751dbg("Checking if session is running...");
752
753$qemuidx = -1;
754
755if (is_my_session_valid()) {
756	dbg("Session running.");
757	$qemuidx = qemu_slot();
758	if ($do_kill) {
759		dbg("closing...");
760		stop_qemu();
761	}
762} else if (!$do_kill && $do_run) {
763	dbg("Need to start qemu.");
764
765	$qemuidx = start_qemu();
766	//out("Waiting for vnc server...");
767	//sleep(5);
768}
769
770
771if ($qemuidx >= 0 && !$do_kill) {
772	output_kill_form();
773	output_serial_output_code();
774	output_audio_player_code();
775	output_vnc_info();
776	out("Waiting for vnc server...");
777	sleep(1);
778	output_applet_code();
779} else {
780	output_options_form();
781}
782
783//phpinfo();
784
785?>
786
787</body>
788</html>
789