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