1e8fc4975SFrançois Revol<?php 2e8fc4975SFrançois Revol 3e8fc4975SFrançois Revol/* 4e8fc4975SFrançois Revol * haiku.php - an online Haiku demo using qemu and vnc. 5cf02b29eSFrançois Revol * 6*ac078a5bSFrançois Revol * Copyright 2007-2011, Francois Revol, revol@free.fr. 7cf02b29eSFrançois Revol * Distributed under the terms of the MIT License. 8e8fc4975SFrançois Revol */ 9e8fc4975SFrançois Revol 10664c8b6dSFrançois Revol// parts inspired by the Free Live OS Zoo 11664c8b6dSFrançois Revol// http://www.oszoo.org/wiki/index.php/Free_Live_OS_Zoo 12664c8b6dSFrançois Revol 134cf03112SFrançois Revol 144cf03112SFrançois Revol// include local configuration that possibly overrides defines below. 154cf03112SFrançois Revolif (file_exists('haiku.conf.php')) 164cf03112SFrançois Revol include('haiku.conf.php'); 174cf03112SFrançois Revol 184cf03112SFrançois Revol 1998d26da2SFrançois Revol// name of the page 2098d26da2SFrançois Revoldefine("PAGE_TITLE", "Haiku Online Demo"); 2198d26da2SFrançois Revol 22664c8b6dSFrançois Revol 23e8fc4975SFrançois Revol// relative path to the vnc java applet jar 24e8fc4975SFrançois Revol// you must *copy* (apache doesn't seem to like symlinks) it there. 25e8fc4975SFrançois Revol 26e8fc4975SFrançois Revol// on debian, apt-get install vnc-java will put them in 27e8fc4975SFrançois Revol// /usr/share/vnc-java 28e8fc4975SFrançois Revol//define("VNCJAVA_PATH", "vnc-java"); 29e8fc4975SFrançois Revol//define("VNCJAR", "vncviewer.jar"); 30e8fc4975SFrançois Revol//define("VNCCLASS", "vncviewer.class"); 31e8fc4975SFrançois Revol 32e8fc4975SFrançois Revol// to use the tightvnc applet instead (supports > 8bpp): 33e8fc4975SFrançois Revol// on debian, apt-get install tightvnc-java will put them in 34e8fc4975SFrançois Revol// /usr/share/tightvnc-java 35*ac078a5bSFrançois Revol// else you can get it from http://www.tightvnc.com/download-old.php : 36*ac078a5bSFrançois Revol// wget http://www.tightvnc.com/download/1.3.10/tightvnc-1.3.10_javabin.zip 37*ac078a5bSFrançois Revol// (you will have to move the VncViewer.jar file around) 38e8fc4975SFrançois Revoldefine("VNCJAVA_PATH", "tightvnc-java"); 39e8fc4975SFrançois Revoldefine("VNCJAR", "VncViewer.jar"); 40e8fc4975SFrançois Revoldefine("VNCCLASS", "VncViewer.class"); 41e8fc4975SFrançois Revol 42cf02b29eSFrançois Revol// do not show applet controls 43cf02b29eSFrançois Revoldefine("VNC_HIDE_CONTROLS", true); 44cf02b29eSFrançois Revol 45cf02b29eSFrançois Revol// generate and use (plain text) passwords 46cf02b29eSFrançois Revol// NOT IMPLEMENTED 47cf02b29eSFrançois Revol//define("VNC_USE_PASS", true); 48cf02b29eSFrançois Revol 49e8fc4975SFrançois Revol// maximum count of qemu instances. 5091054f1dSFrançois Revoldefine("MAX_QEMUS", 2); 51e8fc4975SFrançois Revol 52e8fc4975SFrançois Revol// size of the java applet, must match the default resolution of the image. 5352a7cf96SFrançois Revol//define("APPLET_WIDTH", "800"); 5452a7cf96SFrançois Revol//define("APPLET_HEIGHT", "600"); 5552a7cf96SFrançois Revoldefine("APPLET_WIDTH", "1024"); 5652a7cf96SFrançois Revoldefine("APPLET_HEIGHT", "768"); 57e8fc4975SFrançois Revol// vnc protocol base port. 58e8fc4975SFrançois Revoldefine("VNCPORTBASE", 5900); 59e8fc4975SFrançois Revol 60664c8b6dSFrançois Revol// base port for audio streams 61f0cbfcafSFrançois Revol//define("AUDIOPORTBASE", 8080); 62f0cbfcafSFrançois Revoldefine("AUDIOPORTBASE", (VNCPORTBASE + MAX_QEMUS)); 63f0cbfcafSFrançois Revol 64*ac078a5bSFrançois Revol// if audio is enabled 65*ac078a5bSFrançois Revoldefine("AUDIOENABLED", false); 66*ac078a5bSFrançois Revol 67f0cbfcafSFrançois Revol// base port for serial output 68f0cbfcafSFrançois Revol//define("SERIALPORTBASE", 9000); 69f0cbfcafSFrançois Revoldefine("SERIALPORTBASE", (VNCPORTBASE + MAX_QEMUS * 2)); 70664c8b6dSFrançois Revol 71e8fc4975SFrançois Revol// timeout before the demo session is killed, as argument to /bin/sleep 724720c31bSFrançois Revoldefine("SESSION_TIMEOUT", "20m"); 73e8fc4975SFrançois Revol 74e8fc4975SFrançois Revol// path to qemu binary 75c6f50a6aSFrançois Revoldefine("QEMU_BASE", "/usr/local"); 76c6f50a6aSFrançois Revoldefine("QEMU_BIN", QEMU_BASE . "/bin/qemu"); 77c6f50a6aSFrançois Revoldefine("QEMU_KEYMAPS", QEMU_BASE . "/share/qemu/keymaps"); 78e8fc4975SFrançois Revol// default arguments: no network, emulate tablet, readonly image file. 794720c31bSFrançois Revoldefine("QEMU_ARGS", "" 80d2bef01cSFrançois Revol ."-daemonize " /* detach from stdin */ 81d2bef01cSFrançois Revol ."-localtime " /* not UTC */ 824cf03112SFrançois Revol ."-name '" . addslashes(PAGE_TITLE) . "' " 83*ac078a5bSFrançois Revol ."-monitor null " /* disable the monitor */ 844720c31bSFrançois Revol ."-serial none " 854720c31bSFrançois Revol ."-parallel none " 864720c31bSFrançois Revol ."-net none " 874720c31bSFrançois Revol ."-usbdevice wacom-tablet " 88bea66afaSFrançois Revol //."-vga vmware " 894720c31bSFrançois Revol ."-snapshot "); 90d2bef01cSFrançois Revol 91e8fc4975SFrançois Revol// absolute path to the image. 924cf03112SFrançois Revoldefine("QEMU_IMAGE_PATH", "/home/revol/haiku.image"); 934cf03112SFrançois Revol// BAD: let's one download the image 944cf03112SFrançois Revol//define("QEMU_IMAGE_PATH", dirname($_SERVER['SCRIPT_FILENAME']) . "/haiku.image"); 95b12110c5SFrançois Revol 96*ac078a5bSFrançois Revol// max number of cpus for the VM, no more than 8 97b12110c5SFrançois Revoldefine("QEMU_MAX_CPUS", 1); 98b12110c5SFrançois Revol 998ad2eabaSFrançois Revol// qemu 0.8.2 needs "", qemu 0.9.1 needs ":" 1008ad2eabaSFrançois Revoldefine("QEMU_VNC_PREFIX", ":"); 101e8fc4975SFrançois Revol 102e8fc4975SFrançois Revol// name of session and pid files in /tmp 103e8fc4975SFrançois Revoldefine("QEMU_SESSFILE_TMPL", "qemu-haiku-session-"); 104e8fc4975SFrançois Revoldefine("QEMU_PIDFILE_TMPL", "qemu-haiku-pid-"); 105*ac078a5bSFrançois Revoldefine("QEMU_LOGFILE_TMPL", "qemu-haiku-log-"); 106e8fc4975SFrançois Revol// name of session variable holding the qemu slot; not yet used correctly 107e8fc4975SFrançois Revoldefine("QEMU_IDX_VAR", "QEMU_HAIKU_SESSION_VAR"); 108e8fc4975SFrançois Revol 109f0cbfcafSFrançois Revol 110f0cbfcafSFrançois Revol// uncomment if you want to pass your Sonix webcam device through 111f0cbfcafSFrançois Revol// migth need to update VID:PID 1124cf03112SFrançois Revol// doesnt really work yet 113f0cbfcafSFrançois Revol//define("QEMU_USB_PASSTHROUGH", "-usbdevice host:0c45:6005"); 114f0cbfcafSFrançois Revol 115f0cbfcafSFrançois Revol 1164720c31bSFrançois Revoldefine("BGCOLOR", "#336698"); 1174720c31bSFrançois Revol 118f0cbfcafSFrançois Revol 1194cf03112SFrançois Revol 1204cf03112SFrançois Revol 1214720c31bSFrançois Revol$vnckeymap = "en-us"; 1224720c31bSFrançois Revol 123f0cbfcafSFrançois Revol$cpucount = 1; 124f0cbfcafSFrançois Revol 1254720c31bSFrançois Revol// statics 12698d26da2SFrançois Revol//$count = $_SESSION['compteur']; 1274720c31bSFrançois Revol//$count = $GLOBALS['compteur']; 1284720c31bSFrançois Revol$closing = 0; 1294720c31bSFrançois Revol$do_kill = 0; 1304720c31bSFrançois Revol$do_run = 0; 1314720c31bSFrançois Revol 1324720c31bSFrançois Revolfunction out($str) 1334720c31bSFrançois Revol{ 1344720c31bSFrançois Revol echo "<div class=\"haiku_online_out\">$str</div>\n"; 1354720c31bSFrançois Revol ob_flush(); 1364720c31bSFrançois Revol flush(); 1374720c31bSFrançois Revol} 1384720c31bSFrançois Revol 139e8fc4975SFrançois Revolfunction dbg($str) 140e8fc4975SFrançois Revol{ 1414720c31bSFrançois Revol echo "<div class=\"haiku_online_debug\">$str</div>\n"; 1424720c31bSFrançois Revol ob_flush(); 1434720c31bSFrançois Revol flush(); 144e8fc4975SFrançois Revol} 145e8fc4975SFrançois Revol 146e8fc4975SFrançois Revolfunction err($str) 147e8fc4975SFrançois Revol{ 1484720c31bSFrançois Revol echo "<div class=\"haiku_online_error\">$str</div>\n"; 1494720c31bSFrançois Revol ob_flush(); 1504720c31bSFrançois Revol flush(); 151e8fc4975SFrançois Revol} 152e8fc4975SFrançois Revol 153e8fc4975SFrançois Revolfunction make_qemu_sessionfile_name($idx) 154e8fc4975SFrançois Revol{ 155e8fc4975SFrançois Revol return "/tmp/" . QEMU_SESSFILE_TMPL . $idx; 156e8fc4975SFrançois Revol} 157e8fc4975SFrançois Revol 158e8fc4975SFrançois Revolfunction make_qemu_pidfile_name($idx) 159e8fc4975SFrançois Revol{ 160e8fc4975SFrançois Revol return "/tmp/" . QEMU_PIDFILE_TMPL . $idx; 161e8fc4975SFrançois Revol} 162e8fc4975SFrançois Revol 163*ac078a5bSFrançois Revolfunction make_qemu_logfile_name($idx) 164*ac078a5bSFrançois Revol{ 165*ac078a5bSFrançois Revol return "/tmp/" . QEMU_LOGFILE_TMPL . $idx; 166*ac078a5bSFrançois Revol} 167*ac078a5bSFrançois Revol 168e8fc4975SFrançois Revolfunction find_qemu_slot() 169e8fc4975SFrançois Revol{ 170e8fc4975SFrançois Revol for ($idx = 0; $idx < MAX_QEMUS; $idx++) { 171e8fc4975SFrançois Revol $pidfile = make_qemu_pidfile_name($idx); 172e8fc4975SFrançois Revol $sessfile = make_qemu_sessionfile_name($idx); 173e8fc4975SFrançois Revol dbg("checking \"$pidfile\", \"$sessfile\"..."); 174e8fc4975SFrançois Revol if (!file_exists($pidfile) && !file_exists($sessfile)) { 175e8fc4975SFrançois Revol file_put_contents($sessfile, session_id()); 176e8fc4975SFrançois Revol $sid = file_get_contents($sessfile); 177e8fc4975SFrançois Revol if ($sid != session_id()) 178e8fc4975SFrançois Revol continue; 179e8fc4975SFrançois Revol $_SESSION[QEMU_IDX_VAR] = $idx; 180e8fc4975SFrançois Revol return $idx; 181e8fc4975SFrançois Revol } 182e8fc4975SFrançois Revol } 183e8fc4975SFrançois Revol return -1; 184e8fc4975SFrançois Revol} 185e8fc4975SFrançois Revol 1864720c31bSFrançois Revolfunction total_qemu_slots() 1874720c31bSFrançois Revol{ 1884720c31bSFrançois Revol return MAX_QEMUS; 1894720c31bSFrançois Revol} 1904720c31bSFrançois Revol 1914720c31bSFrançois Revol 1924720c31bSFrançois Revolfunction available_qemu_slots() 1934720c31bSFrançois Revol{ 1944720c31bSFrançois Revol $count = 0; 1954720c31bSFrançois Revol for ($idx = 0; $idx < MAX_QEMUS; $idx++) { 1964720c31bSFrançois Revol $pidfile = make_qemu_pidfile_name($idx); 1974720c31bSFrançois Revol $sessfile = make_qemu_sessionfile_name($idx); 1984720c31bSFrançois Revol //dbg("checking \"$pidfile\", \"$sessfile\"..."); 1994720c31bSFrançois Revol if (!file_exists($pidfile) && !file_exists($sessfile)) 2004720c31bSFrançois Revol $count++; 2014720c31bSFrançois Revol } 2024720c31bSFrançois Revol return $count; 2034720c31bSFrançois Revol} 2044720c31bSFrançois Revol 205e8fc4975SFrançois Revolfunction qemu_slot() 206e8fc4975SFrançois Revol{ 207e8fc4975SFrançois Revol return $_SESSION[QEMU_IDX_VAR]; 208e8fc4975SFrançois Revol} 209e8fc4975SFrançois Revol 210664c8b6dSFrançois Revolfunction audio_port() 211664c8b6dSFrançois Revol{ 212664c8b6dSFrançois Revol return AUDIOPORTBASE + qemu_slot(); 213664c8b6dSFrançois Revol} 214664c8b6dSFrançois Revol 215e8fc4975SFrançois Revolfunction vnc_display() 216e8fc4975SFrançois Revol{ 217e8fc4975SFrançois Revol return qemu_slot(); 218e8fc4975SFrançois Revol} 219e8fc4975SFrançois Revol 22098d26da2SFrançois Revolfunction vnc_addr() 22198d26da2SFrançois Revol{ 22298d26da2SFrançois Revol return $_SERVER['HTTP_HOST']; 22398d26da2SFrançois Revol} 22498d26da2SFrançois Revol 225e8fc4975SFrançois Revolfunction vnc_port() 226e8fc4975SFrançois Revol{ 227e8fc4975SFrançois Revol return VNCPORTBASE + vnc_display(); 228e8fc4975SFrançois Revol} 229e8fc4975SFrançois Revol 2304720c31bSFrançois Revolfunction vnc_addr_display() 2314720c31bSFrançois Revol{ 23298d26da2SFrançois Revol return vnc_addr() . ":" . vnc_display(); 2334720c31bSFrançois Revol} 2344720c31bSFrançois Revol 2354720c31bSFrançois Revolfunction vnc_url() 2364720c31bSFrançois Revol{ 2374720c31bSFrançois Revol return "vnc://" . vnc_addr_display(); 2384720c31bSFrançois Revol} 2394720c31bSFrançois Revol 240e8fc4975SFrançois Revolfunction is_my_session_valid() 241e8fc4975SFrançois Revol{ 242e8fc4975SFrançois Revol if (!isset($_SESSION[QEMU_IDX_VAR])) 243e8fc4975SFrançois Revol return 0; 244e8fc4975SFrançois Revol $idx = $_SESSION[QEMU_IDX_VAR]; 245e8fc4975SFrançois Revol $sessfile = make_qemu_sessionfile_name($idx); 246e8fc4975SFrançois Revol if (!file_exists($sessfile)) 247e8fc4975SFrançois Revol return 0; 248e8fc4975SFrançois Revol $qemusession=file_get_contents($sessfile); 249e8fc4975SFrançois Revol // has expired 250e8fc4975SFrançois Revol if ($qemusession != session_id()) { 251e8fc4975SFrançois Revol return 0; 252e8fc4975SFrançois Revol } 253e8fc4975SFrançois Revol return 1; 254e8fc4975SFrançois Revol} 255e8fc4975SFrançois Revol 256e8fc4975SFrançois Revol 2574720c31bSFrançois Revolfunction list_keymaps() 2584720c31bSFrançois Revol{ 2594720c31bSFrançois Revol $bads = array('.', '..', 'common', 'modifiers'); 2604720c31bSFrançois Revol $keymaps = scandir(QEMU_KEYMAPS); 2614720c31bSFrançois Revol foreach ($keymaps as $key => $map) { 2624720c31bSFrançois Revol if (in_array($map, $bads)) 2634720c31bSFrançois Revol unset($keymaps[$key]); 2644720c31bSFrançois Revol } 2654720c31bSFrançois Revol return $keymaps; 2664720c31bSFrançois Revol} 2674720c31bSFrançois Revol 2684720c31bSFrançois Revol 2694720c31bSFrançois Revolfunction in_keymaps($keymap) 2704720c31bSFrançois Revol{ 2714720c31bSFrançois Revol $keymaps = list_keymaps(); 2724720c31bSFrançois Revol 2734720c31bSFrançois Revol if ($keymap == "") 2744720c31bSFrançois Revol return false; 2754720c31bSFrançois Revol if (in_array($keymap, $keymaps)) 2764720c31bSFrançois Revol return true; 2774720c31bSFrançois Revol 2784720c31bSFrançois Revol return false; 2794720c31bSFrançois Revol} 280c6f50a6aSFrançois Revol 281c6f50a6aSFrançois Revol 282c6f50a6aSFrançois Revolfunction probe_keymap() 283c6f50a6aSFrançois Revol{ 284c6f50a6aSFrançois Revol global $vnckeymap; 2854720c31bSFrançois Revol if (is_string($_GET['keymap']) && in_keymaps($_GET['keymap'])) 2864720c31bSFrançois Revol { 2874720c31bSFrançois Revol $vnckeymap = $_GET['keymap']; 2884720c31bSFrançois Revol dbg("Overriden keymap '" . $vnckeymap . "' in arguments."); 2894720c31bSFrançois Revol return; 2904720c31bSFrançois Revol } 291c6f50a6aSFrançois Revol // if the browser advertised a prefered lang... 292c6f50a6aSFrançois Revol if (!isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) 293c6f50a6aSFrançois Revol return; 294c6f50a6aSFrançois Revol $langs = $_SERVER["HTTP_ACCEPT_LANGUAGE"]; 295c6f50a6aSFrançois Revol $langs = ereg_replace(";q=[^,]*", "", $langs); 296c6f50a6aSFrançois Revol $langs = str_replace(" ", "", $langs); 297c6f50a6aSFrançois Revol $langs = split(",", $langs); 298c6f50a6aSFrançois Revol //print_r($langs); 299c6f50a6aSFrançois Revol //print_r($keymaps); 300c6f50a6aSFrançois Revol foreach($langs as $lang) 301c6f50a6aSFrançois Revol { 302dfc8a217SFrançois Revol if (!in_keymaps($lang)) 303dfc8a217SFrançois Revol $lang = ereg_replace("-.*", "", $lang); 3044720c31bSFrançois Revol if (in_keymaps($lang)) 305c6f50a6aSFrançois Revol { 3064720c31bSFrançois Revol $vnckeymap = $lang; 307664c8b6dSFrançois Revol dbg("Detected keymap '" . $vnckeymap . 308664c8b6dSFrançois Revol "' from browser headers."); 309c6f50a6aSFrançois Revol return; 310c6f50a6aSFrançois Revol } 311c6f50a6aSFrançois Revol } 312c6f50a6aSFrançois Revol} 3134720c31bSFrançois Revol 3144720c31bSFrançois Revol 315f0cbfcafSFrançois Revolfunction probe_options_form() 316f0cbfcafSFrançois Revol{ 317f0cbfcafSFrançois Revol global $cpucount; 318f0cbfcafSFrançois Revol $cpucount = 1; 319f0cbfcafSFrançois Revol if (isset($_GET['cpucount'])) 320f0cbfcafSFrançois Revol $cpucount = (int)$_GET['cpucount']; 321b12110c5SFrançois Revol $cpucount = max(min($cpucount, QEMU_MAX_CPUS), 1); 322f0cbfcafSFrançois Revol //dbg("cpucount $cpucount"); 323f0cbfcafSFrançois Revol} 324f0cbfcafSFrançois Revol 325f0cbfcafSFrançois Revol 3264720c31bSFrançois Revolfunction output_options_form() 3274720c31bSFrançois Revol{ 3284720c31bSFrançois Revol global $vnckeymap; 3294720c31bSFrançois Revol $idx = qemu_slot(); 3304720c31bSFrançois Revol echo "<form method=\"get\" action=\"" . $_SERVER['PHP_SELF'] . "\">"; 3314720c31bSFrançois Revol echo "<table border=\"0\" class=\"haiku_online_form\">\n"; 332d2bef01cSFrançois Revol 333f0cbfcafSFrançois Revol $keymaps = list_keymaps(); 334d2bef01cSFrançois Revol echo "<tr>\n<td align=\"right\">\n"; 3354720c31bSFrançois Revol echo "Select your keymap:"; 336d2bef01cSFrançois Revol echo "</td>\n<td>\n"; 3374720c31bSFrançois Revol echo "<select name=\"keymap\">"; 3384720c31bSFrançois Revol foreach ($keymaps as $keymap) { 339f0cbfcafSFrançois Revol echo "<option value=\"$keymap\" "; 3404720c31bSFrançois Revol if ($keymap == $vnckeymap) 341f0cbfcafSFrançois Revol echo "selected=\"selected\" "; 3424720c31bSFrançois Revol echo ">$keymap</option>"; 3434720c31bSFrançois Revol //echo "<option name=\"keymap\" "; 3444720c31bSFrançois Revol //echo "value=\"$keymap\">" . locale_get_display_name($keymap); 3454720c31bSFrançois Revol //echo "</option>"; 3464720c31bSFrançois Revol } 3474720c31bSFrançois Revol echo "</select>"; 348d2bef01cSFrançois Revol echo "</td>\n</tr>\n"; 3494720c31bSFrançois Revol 350f0cbfcafSFrançois Revol 3514720c31bSFrançois Revol $modes = array("1024x768"/*, "800x600"*/); 3524720c31bSFrançois Revol echo "<tr "; 3534720c31bSFrançois Revol if (count($modes) < 2) 3544720c31bSFrançois Revol echo "class=\"haiku_online_disabled\""; 3554720c31bSFrançois Revol echo ">\n"; 3564720c31bSFrançois Revol echo "<td align=\"right\">\n"; 3574720c31bSFrançois Revol echo "Select display size:"; 358d2bef01cSFrançois Revol echo "</td>\n<td>\n"; 3594720c31bSFrançois Revol echo "<select name=\"videomode\" "; 3604720c31bSFrançois Revol if (count($modes) < 2) 361f0cbfcafSFrançois Revol echo "disabled=\"disabled\""; 3624720c31bSFrançois Revol echo ">"; 3634720c31bSFrançois Revol foreach ($modes as $mode) { 364f0cbfcafSFrançois Revol echo "<option value=\"$mode\" "; 3654720c31bSFrançois Revol if ($mode == $videomode) 366f0cbfcafSFrançois Revol echo "selected=\"selected\" "; 3674720c31bSFrançois Revol echo ">$mode</option>"; 3684720c31bSFrançois Revol } 3694720c31bSFrançois Revol echo "</select>"; 370d2bef01cSFrançois Revol echo "</td>\n</tr>\n"; 3714720c31bSFrançois Revol 372f0cbfcafSFrançois Revol 373f0cbfcafSFrançois Revol echo "<tr "; 374b12110c5SFrançois Revol if (QEMU_MAX_CPUS < 2) 375f0cbfcafSFrançois Revol echo "class=\"haiku_online_disabled\""; 376f0cbfcafSFrançois Revol echo ">\n"; 377f0cbfcafSFrançois Revol echo "<td align=\"right\">\n"; 378f0cbfcafSFrançois Revol echo "Select cpu count:"; 379f0cbfcafSFrançois Revol echo "</td>\n<td>\n"; 380f0cbfcafSFrançois Revol echo "<select name=\"cpucount\" "; 381b12110c5SFrançois Revol if (QEMU_MAX_CPUS < 2) 382f0cbfcafSFrançois Revol echo "disabled=\"disabled\""; 383f0cbfcafSFrançois Revol echo ">"; 384b12110c5SFrançois Revol for ($ncpu = 1; $ncpu <= QEMU_MAX_CPUS; $ncpu++) { 385f0cbfcafSFrançois Revol echo "<option value=\"$ncpu\" "; 386f0cbfcafSFrançois Revol if ($ncpu == 1) 387f0cbfcafSFrançois Revol echo "selected=\"selected\" "; 388f0cbfcafSFrançois Revol echo ">$ncpu</option>"; 389f0cbfcafSFrançois Revol } 390f0cbfcafSFrançois Revol echo "</select>"; 391f0cbfcafSFrançois Revol echo "</td>\n</tr>\n"; 392f0cbfcafSFrançois Revol 393f0cbfcafSFrançois Revol 3944720c31bSFrançois Revol echo "<tr "; 395*ac078a5bSFrançois Revol if (!AUDIOENABLED) 3964720c31bSFrançois Revol echo "class=\"haiku_online_disabled\""; 3974720c31bSFrançois Revol echo ">\n"; 3984720c31bSFrançois Revol echo "<td align=\"right\">\n"; 399d2bef01cSFrançois Revol echo "Check to enable sound:"; 400d2bef01cSFrançois Revol echo "</td>\n<td>\n"; 401d2bef01cSFrançois Revol echo "<input type=\"checkbox\" name=\"sound\" id=\"sound_cb\" "; 402f0cbfcafSFrançois Revol echo "value=\"1\" "; 403*ac078a5bSFrançois Revol if (AUDIOENABLED) { 404c3159d4aSFrançois Revol //echo "checked=\"checked\" /"; 405f0cbfcafSFrançois Revol } else 406f0cbfcafSFrançois Revol echo "disabled=\"disabled\" /"; 40791054f1dSFrançois Revol echo "><label for=\"sound_cb\">Sound</label>"; 408d2bef01cSFrançois Revol echo "</td>\n</tr>\n"; 409d2bef01cSFrançois Revol 410f0cbfcafSFrançois Revol $enable_serial = 1; 411f0cbfcafSFrançois Revol echo "<tr "; 412f0cbfcafSFrançois Revol if (!$enable_serial) 413f0cbfcafSFrançois Revol echo "class=\"haiku_online_disabled\""; 414f0cbfcafSFrançois Revol echo ">\n"; 415f0cbfcafSFrançois Revol echo "<td align=\"right\">\n"; 416f0cbfcafSFrançois Revol echo "Check to enable serial output:"; 417f0cbfcafSFrançois Revol echo "</td>\n<td>\n"; 418f0cbfcafSFrançois Revol echo "<input type=\"checkbox\" name=\"serial\" id=\"serial_cb\" "; 419f0cbfcafSFrançois Revol echo "value=\"1\" "/*"disabled "*/; 420f0cbfcafSFrançois Revol if ($enable_serial) { 421f0cbfcafSFrançois Revol //echo "checked "; 42291054f1dSFrançois Revol } 42391054f1dSFrançois Revol echo "/><label for=\"serial_cb\">Serial</label>"; 424f0cbfcafSFrançois Revol echo "</td>\n</tr>\n"; 425f0cbfcafSFrançois Revol 426f0cbfcafSFrançois Revol if (defined("QEMU_USB_PASSTHROUGH")) { 427f0cbfcafSFrançois Revol 428f0cbfcafSFrançois Revol $enable_webcam = 1; 429f0cbfcafSFrançois Revol echo "<tr "; 430f0cbfcafSFrançois Revol if (!$enable_webcam) 431f0cbfcafSFrançois Revol echo "class=\"haiku_online_disabled\""; 432f0cbfcafSFrançois Revol echo ">\n"; 433f0cbfcafSFrançois Revol echo "<td align=\"right\">\n"; 434f0cbfcafSFrançois Revol echo "Check to enable webcam:"; 435f0cbfcafSFrançois Revol echo "</td>\n<td>\n"; 436f0cbfcafSFrançois Revol echo "<input type=\"checkbox\" name=\"webcam\" id=\"webcam_cb\" "; 437f0cbfcafSFrançois Revol echo "value=\"1\" "/*"disabled "*/; 438f0cbfcafSFrançois Revol if ($enable_webcam) { 439f0cbfcafSFrançois Revol //echo "checked "; 44091054f1dSFrançois Revol } 44191054f1dSFrançois Revol echo "/><label for=\"webcam_cb\">Webcam</label>"; 442f0cbfcafSFrançois Revol echo "</td>\n</tr>\n"; 443f0cbfcafSFrançois Revol } 444d2bef01cSFrançois Revol /* 445d2bef01cSFrançois Revol echo "<tr>\n<td align=\"right\">\n"; 4464720c31bSFrançois Revol //out("Click here to enable sound:"); 447d2bef01cSFrançois Revol echo "</td>\n<td>\n"; 448d2bef01cSFrançois Revol echo "</td>\n</tr>\n"; 449d2bef01cSFrançois Revol 450d2bef01cSFrançois Revol echo "<tr>\n<td align=\"right\">\n"; 451d2bef01cSFrançois Revol //out("Click here to enable sound:"); 452d2bef01cSFrançois Revol echo "</td>\n<td>\n"; 453d2bef01cSFrançois Revol echo "</td>\n</tr>\n"; 454d2bef01cSFrançois Revol */ 455d2bef01cSFrançois Revol 456d2bef01cSFrançois Revol echo "<tr>\n<td align=\"right\">\n"; 4574720c31bSFrançois Revol echo "Click here to start the session:"; 458d2bef01cSFrançois Revol echo "</td>\n<td>\n"; 4594720c31bSFrançois Revol echo "<input type=\"submit\" name=\"run\" "; 4604720c31bSFrançois Revol echo "value=\"Start!\" />"; 461d2bef01cSFrançois Revol echo "</td>\n</tr>\n"; 462d2bef01cSFrançois Revol 4634720c31bSFrançois Revol echo "</table>\n"; 4644720c31bSFrançois Revol echo "</form>\n"; 465664c8b6dSFrançois Revol out("NOTE: You will need a Java-enabled browser to display the VNC " . 466*ac078a5bSFrançois Revol "Applet used by this demo. " . 467*ac078a5bSFrançois Revol "You can however use instead an external <a " . 4684720c31bSFrançois Revol "href=\"http://fr.wikipedia.org/wiki/Virtual_Network_Computing\"" . 4694720c31bSFrançois Revol ">VNC viewer</a>."); 4704720c31bSFrançois Revol ob_flush(); 4714720c31bSFrançois Revol flush(); 4724720c31bSFrançois Revol} 4734720c31bSFrançois Revol 4744720c31bSFrançois Revolfunction output_kill_form() 4754720c31bSFrançois Revol{ 4764720c31bSFrançois Revol echo "<form method=\"get\" action=\"" . $_SERVER['PHP_SELF'] . "\">"; 4774720c31bSFrançois Revol echo "<table border=\"0\" class=\"haiku_online_form\">\n"; 4784720c31bSFrançois Revol echo "<tr>\n"; 4794720c31bSFrançois Revol echo "<td>\n"; 4804720c31bSFrançois Revol echo "Click here to kill the session:"; 4814720c31bSFrançois Revol echo "</td>\n"; 4824720c31bSFrançois Revol echo "<td>\n"; 4834720c31bSFrançois Revol echo "<input type=\"submit\" name=\"kill\" "; 4844720c31bSFrançois Revol echo "value=\"Terminate\"/>"; 4854720c31bSFrançois Revol echo "</td>\n"; 4864720c31bSFrançois Revol echo "</tr>\n"; 4874720c31bSFrançois Revol echo "</table>\n"; 4884720c31bSFrançois Revol echo "</form>\n"; 4894720c31bSFrançois Revol ob_flush(); 4904720c31bSFrançois Revol flush(); 491c6f50a6aSFrançois Revol} 492c6f50a6aSFrançois Revol 493c6f50a6aSFrançois Revol 494e8fc4975SFrançois Revolfunction start_qemu() 495e8fc4975SFrançois Revol{ 496c6f50a6aSFrançois Revol global $vnckeymap; 497f0cbfcafSFrançois Revol global $cpucount; 498e8fc4975SFrançois Revol $idx = find_qemu_slot(); 499e8fc4975SFrançois Revol if ($idx < 0) { 500e8fc4975SFrançois Revol err("No available qemu slot, please try later."); 501e8fc4975SFrançois Revol return $idx; 502e8fc4975SFrançois Revol } 503e8fc4975SFrançois Revol $pidfile = make_qemu_pidfile_name($idx); 504*ac078a5bSFrançois Revol $logfile = make_qemu_logfile_name($idx); 505c3159d4aSFrançois Revol $cmd = ''; 506c3159d4aSFrançois Revol if (isset($_GET['sound'])) { 507c3159d4aSFrançois Revol $cmd .= "QEMU_AUDIO_DRV=twolame "; 508c3159d4aSFrançois Revol //$cmd .= "QEMU_TWOLAME_SAMPLES=" . 4096 . " "; 509c3159d4aSFrançois Revol $cmd .= "QEMU_TWOLAME_PORT=" . audio_port() . " "; 510c3159d4aSFrançois Revol } 511c3159d4aSFrançois Revol $cmd .= QEMU_BIN . " " . QEMU_ARGS; 512f0cbfcafSFrançois Revol if ($cpucount > 1) 513f0cbfcafSFrançois Revol $cmd .= " -smp " . $cpucount; 514c3159d4aSFrançois Revol if (isset($_GET['sound'])) { 515c3159d4aSFrançois Revol $cmd .= " -soundhw hda"; 516c3159d4aSFrançois Revol } 517f0cbfcafSFrançois Revol if (isset($_GET['serial'])) { 518f0cbfcafSFrançois Revol $cmd .= " -serial telnet::"; 519f0cbfcafSFrançois Revol $cmd .= (SERIALPORTBASE + qemu_slot()); 520f0cbfcafSFrançois Revol $cmd .= ",server,nowait,nodelay"; 521f0cbfcafSFrançois Revol } 522f0cbfcafSFrançois Revol if (isset($_GET['webcam']) && defined("QEMU_USB_PASSTHROUGH")) { 523f0cbfcafSFrançois Revol $cmd .= " " . QEMU_USB_PASSTHROUGH; 524f0cbfcafSFrançois Revol } 525f0cbfcafSFrançois Revol $cmd .= " -k " . $vnckeymap . 526664c8b6dSFrançois Revol " -vnc " . QEMU_VNC_PREFIX . vnc_display() . 527664c8b6dSFrançois Revol " -pidfile " . $pidfile . 528664c8b6dSFrançois Revol " " . QEMU_IMAGE_PATH; 529*ac078a5bSFrançois Revol //$cmd .= " || echo $? && echo done )"; 530*ac078a5bSFrançois Revol // redirect output to log file 531*ac078a5bSFrançois Revol //$cmd .= " >$logfile 2>&1"; 532e8fc4975SFrançois Revol 533e8fc4975SFrançois Revol if (file_exists($pidfile)) 534e8fc4975SFrançois Revol unlink($pidfile); 535e8fc4975SFrançois Revol dbg("Starting <tt>" . $cmd . "</tt>..."); 536e8fc4975SFrançois Revol 537e8fc4975SFrançois Revol $descriptorspec = array( 538e8fc4975SFrançois Revol // 0 => array("pipe", "r"), // stdin 539e8fc4975SFrançois Revol // 1 => array("pipe", "w"), // stdout 540e8fc4975SFrançois Revol // 2 => array("pipe", "w") // stderr 541e8fc4975SFrançois Revol ); 542e8fc4975SFrançois Revol //$cmd="/bin/ls"; 543e8fc4975SFrançois Revol //passthru($cmd, $ret); 544e8fc4975SFrançois Revol //dbg("ret=$ret"); 545e8fc4975SFrançois Revol $cmd .= " &"; 546e8fc4975SFrançois Revol $process = proc_open($cmd, $descriptorspec, $pipes); 547e8fc4975SFrançois Revol sleep(1); 548e8fc4975SFrançois Revol proc_close($process); 549e8fc4975SFrançois Revol 550e8fc4975SFrançois Revol dbg("Started QEMU."); 551e8fc4975SFrançois Revol $sessfile = make_qemu_sessionfile_name($idx); 552664c8b6dSFrançois Revol $cmd = "(PID=`cat " . $pidfile . "`; " . 553664c8b6dSFrançois Revol "sleep " . SESSION_TIMEOUT . "; " . 554664c8b6dSFrançois Revol "kill -9 \$PID && " . 555664c8b6dSFrançois Revol "rm " . $pidfile . " " . $sessfile . ") &"; 556e8fc4975SFrançois Revol 557e8fc4975SFrançois Revol $process = proc_open($cmd, $descriptorspec, $wkpipes); 558e8fc4975SFrançois Revol sleep(1); 559e8fc4975SFrançois Revol proc_close($process); 560e8fc4975SFrançois Revol 561e8fc4975SFrançois Revol dbg("Started timed kill."); 562e8fc4975SFrançois Revol dbg("Ready for a " . SESSION_TIMEOUT . " session."); 563e8fc4975SFrançois Revol} 564e8fc4975SFrançois Revol 5654720c31bSFrançois Revolfunction stop_qemu() 5664720c31bSFrançois Revol{ 5674720c31bSFrançois Revol $qemuidx = qemu_slot(); 5684720c31bSFrançois Revol $pidfile = make_qemu_pidfile_name($qemuidx); 5694720c31bSFrançois Revol if (file_exists($pidfile)) { 5704720c31bSFrançois Revol $pid = file_get_contents($pidfile); 5714720c31bSFrançois Revol //out("PID:" . $pid); 5724720c31bSFrançois Revol system("/bin/kill -TERM " . $pid); 5734720c31bSFrançois Revol unlink($pidfile); 5744720c31bSFrançois Revol } 5754720c31bSFrançois Revol $sessionfile = make_qemu_sessionfile_name($qemuidx); 5764720c31bSFrançois Revol if (file_exists($sessionfile)) { 5774720c31bSFrançois Revol unlink($sessionfile); 5784720c31bSFrançois Revol } 5794720c31bSFrançois Revol unset($_SESSION[QEMU_IDX_VAR]); 5804720c31bSFrançois Revol 5814720c31bSFrançois Revol out("reloading..."); 5824720c31bSFrançois Revol sleep(1); 5834720c31bSFrançois Revol echo "<script>\n"; 5844720c31bSFrançois Revol echo "<!--\n"; 5854720c31bSFrançois Revol echo "window.location = \"" . $_SERVER['PHP_SELF'] . "\";\n"; 5864720c31bSFrançois Revol echo "//--></script>\n"; 5874720c31bSFrançois Revol out("Click <a href=\"" . $_SERVER['PHP_SELF'] . 5884720c31bSFrançois Revol "\">here</a> to reload the page."); 5894720c31bSFrançois Revol} 5904720c31bSFrançois Revol 5914720c31bSFrançois Revolfunction output_vnc_info() 5924720c31bSFrançois Revol{ 593664c8b6dSFrançois Revol out("You can use an external VNC client at " . 594664c8b6dSFrançois Revol "<a href=\"vnc://" . vnc_addr_display() . "\">" . 595664c8b6dSFrançois Revol "vnc://" . vnc_addr_display() . "</a> " . 59698d26da2SFrançois Revol "or open <a href=\"" . $_SERVER['PHP_SELF'] . "?getfile=vncinfo&slot=" . vnc_display() . "\">this file</a>, " . 5974720c31bSFrançois Revol "or enter <tt>" . vnc_addr_display() . "</tt> in your " . 598664c8b6dSFrançois Revol "<a href=\"http://fr.wikipedia.org/wiki/Virtual_Network_" . 599664c8b6dSFrançois Revol "Computing\"" . 600f0cbfcafSFrançois Revol ">VNC viewer</a>."); 601f0cbfcafSFrançois Revol //echo "<br />\n"; 6024720c31bSFrançois Revol} 603e8fc4975SFrançois Revol 60498d26da2SFrançois Revolfunction output_vnc_info_file() 60598d26da2SFrançois Revol{ 60698d26da2SFrançois Revol if (!is_my_session_valid()) 60798d26da2SFrançois Revol die("Bad request"); 60898d26da2SFrançois Revol 609c3159d4aSFrançois Revol header("Pragma: public"); 610c3159d4aSFrançois Revol header("Expires: 0"); 611c3159d4aSFrançois Revol header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 61298d26da2SFrançois Revol header("Content-type: application/x-vnc"); 61398d26da2SFrançois Revol header('Content-Disposition: attachment; filename="onlinedemo.vnc"'); 61498d26da2SFrançois Revol 61598d26da2SFrançois Revol echo "[connection]\n"; 61698d26da2SFrançois Revol echo "host=" . vnc_addr() . "\n"; 61798d26da2SFrançois Revol echo "port=" . vnc_display() . "\n"; 618cf02b29eSFrançois Revol if (defined('VNC_USE_PASS') && VNC_USE_PASS) 619cf02b29eSFrançois Revol echo "password=" . $_SESSION['VNC_PASS'] . "\n"; 62098d26da2SFrançois Revol //echo "[options]\n"; 62198d26da2SFrançois Revol // cf. http://www.realvnc.com/pipermail/vnc-list/1999-December/011086.html 62298d26da2SFrançois Revol // cf. http://www.tek-tips.com/viewthread.cfm?qid=1173303&page=1 62398d26da2SFrançois Revol //echo "\n"; 62498d26da2SFrançois Revol} 62598d26da2SFrançois Revol 626664c8b6dSFrançois Revolfunction output_audio_player_code($external_only=false) 627664c8b6dSFrançois Revol{ 628c3159d4aSFrançois Revol if (!isset($_GET['sound'])) 629664c8b6dSFrançois Revol return; 630664c8b6dSFrançois Revol 631664c8b6dSFrançois Revol $port = audio_port(); 632664c8b6dSFrançois Revol $url = "http://" . $_SERVER['HTTP_HOST'] . ":$port/"; 633664c8b6dSFrançois Revol $icy = "icy://" . $_SERVER['HTTP_HOST'] . ":$port/"; 634c3159d4aSFrançois Revol $use_html5 = true; 635c3159d4aSFrançois Revol 636664c8b6dSFrançois Revol if (!$external_only) { 637c3159d4aSFrançois Revol if ($use_html5) { 638c3159d4aSFrançois Revol echo "<audio autoplay=\"autoplay\" autobuffer=\"autobuffer\" controls=\"controls\">"; 639c3159d4aSFrançois Revol echo "<source src=\"" . $url . "\" type=\"audio/mpeg\" />"; 640c3159d4aSFrançois Revol } 641c3159d4aSFrançois Revol if (!$use_html5) { 642f1177f36SFrançois Revol echo "<object type=\"audio/mpeg\" width=\"300\" height=\"50\">"; 643c3159d4aSFrançois Revol echo "<param name=\"src\" value=\"" . $url . "\" />"; 644c3159d4aSFrançois Revol echo "<param name=\"controller\" value=\"true\" />"; 645c3159d4aSFrançois Revol echo "<param name=\"controls\" value=\"controlPanel\" />"; 646c3159d4aSFrançois Revol echo "<param name=\"autoplay\" value=\"true\" />"; 647c3159d4aSFrançois Revol echo "<param name=\"autostart\" value=\"1\" />"; 648c3159d4aSFrançois Revol 649664c8b6dSFrançois Revol echo "<embed src=\"$url\" type=\"audio/mpeg\" "; 650664c8b6dSFrançois Revol echo "autoplay=\"true\" width=\"300\" height=\"50\" "; 651c3159d4aSFrançois Revol echo "controller=\"true\" align=\"right\" hidden=\"false\"></embed>"; 652c3159d4aSFrançois Revol 653c3159d4aSFrançois Revol echo "</object>"; 654c3159d4aSFrançois Revol } 655c3159d4aSFrançois Revol if ($use_html5) { 656c3159d4aSFrançois Revol echo "</audio>"; 657c3159d4aSFrançois Revol } 658664c8b6dSFrançois Revol } 659664c8b6dSFrançois Revol out("You can use an external audio play at " . 660c3159d4aSFrançois Revol "<a href=\"$url\">$url</a> or <a href=\"$icy\">$icy</a>, or use one of the playlists: " . 661c3159d4aSFrançois Revol "<a href=\"" . $_SERVER['PHP_SELF'] . "?getfile=audiom3u\">[M3U]</a> " . 662c3159d4aSFrançois Revol "<a href=\"" . $_SERVER['PHP_SELF'] . "?getfile=audiopls\">[PLS]</a>"); 66398d26da2SFrançois Revol} 66498d26da2SFrançois Revol 665c3159d4aSFrançois Revolfunction output_audio_player_file_m3u() 66698d26da2SFrançois Revol{ 66798d26da2SFrançois Revol if (!is_my_session_valid()) 66898d26da2SFrançois Revol die("Bad request"); 66998d26da2SFrançois Revol 670c3159d4aSFrançois Revol header("Pragma: public"); 671c3159d4aSFrançois Revol header("Expires: 0"); 672c3159d4aSFrançois Revol header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 67398d26da2SFrançois Revol header("Content-type: audio/x-mpegurl"); 67498d26da2SFrançois Revol //header("Content-type: text/plain"); 675c3159d4aSFrançois Revol header('Content-Disposition: attachment; filename="onlinedemo.m3u"'); 67698d26da2SFrançois Revol 67798d26da2SFrançois Revol $port = audio_port(); 67898d26da2SFrançois Revol $url = "http://" . $_SERVER['HTTP_HOST'] . ":$port/"; 67998d26da2SFrançois Revol 680c3159d4aSFrançois Revol // cf. http://hanna.pyxidis.org/tech/m3u.html 681c3159d4aSFrançois Revol echo "#EXTM3U\n"; 682c3159d4aSFrançois Revol echo "#EXTINF:0," . PAGE_TITLE . "\n"; 68398d26da2SFrançois Revol echo "$url\n"; 68498d26da2SFrançois Revol //echo "\n"; 685664c8b6dSFrançois Revol} 686664c8b6dSFrançois Revol 687c3159d4aSFrançois Revolfunction output_audio_player_file_pls() 688c3159d4aSFrançois Revol{ 689c3159d4aSFrançois Revol if (!is_my_session_valid()) 690c3159d4aSFrançois Revol die("Bad request"); 691c3159d4aSFrançois Revol 692c3159d4aSFrançois Revol header("Pragma: public"); 693c3159d4aSFrançois Revol header("Expires: 0"); 694c3159d4aSFrançois Revol header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 695c3159d4aSFrançois Revol header("Content-type: audio/x-scpls"); 696c3159d4aSFrançois Revol //header("Content-type: text/plain"); 697c3159d4aSFrançois Revol header('Content-Disposition: attachment; filename="onlinedemo.pls"'); 698c3159d4aSFrançois Revol 699c3159d4aSFrançois Revol $port = audio_port(); 700c3159d4aSFrançois Revol $url = "http://" . $_SERVER['HTTP_HOST'] . ":$port/"; 701c3159d4aSFrançois Revol 702c3159d4aSFrançois Revol echo "[playlist]\n"; 703c3159d4aSFrançois Revol echo "numberofentries=1\n"; 704c3159d4aSFrançois Revol echo "File1=$url\n"; 705c3159d4aSFrançois Revol echo "Title1=" . PAGE_TITLE . "\n"; 706c3159d4aSFrançois Revol echo "Length1=-1\n"; 707c3159d4aSFrançois Revol echo "version=2\n"; 708c3159d4aSFrançois Revol //echo "\n"; 709c3159d4aSFrançois Revol} 710c3159d4aSFrançois Revol 711664c8b6dSFrançois Revolfunction output_applet_code($external_only=false) 712e8fc4975SFrançois Revol{ 713e8fc4975SFrançois Revol $w = APPLET_WIDTH; 714e8fc4975SFrançois Revol $h = APPLET_HEIGHT; 715e8fc4975SFrançois Revol $port = vnc_port(); 716e8fc4975SFrançois Revol $vncjpath = VNCJAVA_PATH; 717e8fc4975SFrançois Revol $jar = VNCJAR; 718e8fc4975SFrançois Revol $class = VNCCLASS; 719664c8b6dSFrançois Revol if ($external_only) 720664c8b6dSFrançois Revol return; 721*ac078a5bSFrançois Revol if (!VNC_HIDE_CONTROLS) 722*ac078a5bSFrançois Revol $h += 32; 723f0cbfcafSFrançois Revol echo "<a name=\"haiku_online_applet\"></a>"; 7244720c31bSFrançois Revol echo "<center>"; 7254720c31bSFrançois Revol echo "<applet code=$class codebase=\"$vncjpath/\" "; 7264720c31bSFrançois Revol echo "archive=\"$vncjpath/$jar\" width=$w height=$h "; 7274720c31bSFrançois Revol echo "bgcolor=\"#336698\">\n"; 7284720c31bSFrançois Revol //not needed 7294720c31bSFrançois Revol //echo "<param name=\"HOST\" value=\"$HTTP_HOST\">\n"; 7304720c31bSFrançois Revol echo "<param name=\"PORT\" value=\"$port\">\n"; 731cf02b29eSFrançois Revol $pass = ''; 732cf02b29eSFrançois Revol if (defined('VNC_USE_PASS') && VNC_USE_PASS) 733cf02b29eSFrançois Revol $pass = $_SESSION['VNC_PASS']; 734cf02b29eSFrançois Revol echo "<param name=\"PASSWORD\" value=\"" . $pass . "\">\n"; 735*ac078a5bSFrançois Revol if (VNC_HIDE_CONTROLS) 736cf02b29eSFrançois Revol echo "<param name=\"Show controls\" value=\"No\">\n"; 7374720c31bSFrançois Revol //echo "<param name=\"share desktop\" value=\"no\" />"; 7384720c31bSFrançois Revol echo "<param name=\"background-color\" value=\"#336698\">\n"; 7394720c31bSFrançois Revol echo "<param name=\"foreground-color\" value=\"#ffffff\">\n"; 7404720c31bSFrançois Revol //echo "<param name=\"background\" value=\"#336698\">\n"; 7414720c31bSFrançois Revol //echo "<param name=\"foreground\" value=\"#ffffff\">\n"; 7424720c31bSFrançois Revol echo "There should be a java applet here... "; 7434720c31bSFrançois Revol echo "make sure you have a JVM and it's enabled!<br />\n"; 7444720c31bSFrançois Revol echo "If you do not have Java you can use an external VNC "; 7454720c31bSFrançois Revol echo "client as described above.\n"; 7464720c31bSFrançois Revol 7474720c31bSFrançois Revol echo "</applet>\n"; 7484720c31bSFrançois Revol echo "</center>"; 7494720c31bSFrançois Revol ob_flush(); 7504720c31bSFrançois Revol flush(); 7514720c31bSFrançois Revol // scroll to the top of the applet 7524720c31bSFrançois Revol echo "<script>\n"; 7534720c31bSFrançois Revol echo "<!--\n"; 7544cf03112SFrançois Revol echo "scrollToAnchor(\"haiku_online_applet\");"; 7554720c31bSFrançois Revol echo "//--></script>\n"; 7564720c31bSFrançois Revol ob_flush(); 7574720c31bSFrançois Revol flush(); 758e8fc4975SFrançois Revol} 759e8fc4975SFrançois Revol 760f0cbfcafSFrançois Revolfunction output_serial_output_code($external_only=false) 761f0cbfcafSFrançois Revol{ 762f0cbfcafSFrançois Revol if (!isset($_GET['serial'])) 763f0cbfcafSFrançois Revol return; 764f0cbfcafSFrançois Revol 765f0cbfcafSFrançois Revol $url = "telnet://" . $_SERVER['HTTP_HOST'] . ":"; 766f0cbfcafSFrançois Revol $url .= (SERIALPORTBASE + qemu_slot()) . "/"; 767f0cbfcafSFrançois Revol out("You can get serial output at <a href=\"$url\">$url</a>"); 768f0cbfcafSFrançois Revol return; 769f0cbfcafSFrançois Revol 770f0cbfcafSFrançois Revol // not really http... 771f0cbfcafSFrançois Revol $url = "http://" . $_SERVER['HTTP_HOST'] . ":"; 772f0cbfcafSFrançois Revol $url .= (SERIALPORTBASE + qemu_slot()) . "/"; 773f0cbfcafSFrançois Revol echo "<center>"; 774f0cbfcafSFrançois Revol echo "<iframe src=\"$url/\" type=\"text/plain\" width=\"100%\" "; 775f0cbfcafSFrançois Revol echo "height=\"200\"></iframe>"; 776f0cbfcafSFrançois Revol echo "</center>"; 777f0cbfcafSFrançois Revol 778f0cbfcafSFrançois Revol} 779f0cbfcafSFrançois Revol 78098d26da2SFrançois Revol 78198d26da2SFrançois Revolsession_start(); 78298d26da2SFrançois Revol 78398d26da2SFrançois Revol// parse args 78498d26da2SFrançois Revol 78598d26da2SFrançois Revol// output redirections... 78698d26da2SFrançois Revolif (isset($_GET['getfile'])) { 78798d26da2SFrançois Revol switch ($_GET['getfile']) { 78898d26da2SFrançois Revol case "vncinfo": 78998d26da2SFrançois Revol output_vnc_info_file(); 79098d26da2SFrançois Revol break; 791c3159d4aSFrançois Revol case "audiom3u": 792c3159d4aSFrançois Revol output_audio_player_file_m3u(); 793c3159d4aSFrançois Revol break; 79498d26da2SFrançois Revol case "audiopls": 795c3159d4aSFrançois Revol output_audio_player_file_pls(); 79698d26da2SFrançois Revol break; 79798d26da2SFrançois Revol default: 79898d26da2SFrançois Revol die("Bad request"); 79998d26da2SFrançois Revol } 80098d26da2SFrançois Revol die(); 80198d26da2SFrançois Revol} 80298d26da2SFrançois Revol 80398d26da2SFrançois Revolif (isset($_GET['close'])) 80498d26da2SFrançois Revol $closing = 1; 80598d26da2SFrançois Revol 80698d26da2SFrançois Revolif (isset($_GET['kill'])) 80798d26da2SFrançois Revol $do_kill = 1; 80898d26da2SFrançois Revol 80998d26da2SFrançois Revolif (isset($_GET['run'])) 81098d26da2SFrançois Revol $do_run = 1; 81198d26da2SFrançois Revol 81298d26da2SFrançois Revolif (isset($_GET['frame'])) {} 81398d26da2SFrançois Revol 81498d26da2SFrançois Revol 81598d26da2SFrançois Revol//echo "do_run: " . $do_run . "<br>\n"; 81698d26da2SFrançois Revol//echo "do_kill: " . $do_kill . "<br>\n"; 81798d26da2SFrançois Revol 81898d26da2SFrançois Revol?> 81998d26da2SFrançois Revol<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 82098d26da2SFrançois Revol<head> 82198d26da2SFrançois Revol<meta name="robots" content="noindex, nofollow, noarchive" /> 82298d26da2SFrançois Revol<title><?php echo PAGE_TITLE; ?></title> 823c3159d4aSFrançois Revol<link rel="shortcut icon" href="http://www.haiku-os.org/sites/haiku-os.org/themes/shijin/favicon.ico" type="image/x-icon" /> 82498d26da2SFrançois Revol<style type="text/css"> 82598d26da2SFrançois Revol<!-- 82698d26da2SFrançois Revol /* basic style */ 82798d26da2SFrançois Revolbody { background-color: <?php echo BGCOLOR; ?>; } 82898d26da2SFrançois Revola:link { color:orange; } 82998d26da2SFrançois Revola:visited { color:darkorange; } 83098d26da2SFrançois Revola:hover { color:pink; } 83198d26da2SFrançois Revol.haiku_online_form { color: white; } 83298d26da2SFrançois Revol.haiku_online_disabled { color: grey; } 83398d26da2SFrançois Revol.haiku_online_out { color: white; } 83498d26da2SFrançois Revol.haiku_online_debug { color: orange; } 83598d26da2SFrançois Revol.haiku_online_error { color: red; font-weight: bold; } 83698d26da2SFrançois Revol.haiku_online_applet { background-color: <?php echo BGCOLOR; ?>; } 83798d26da2SFrançois Revol--> 83898d26da2SFrançois Revol</style> 83998d26da2SFrançois Revol<script type="text/javascript"> 84098d26da2SFrançois Revolfunction onPageUnload() { 84198d26da2SFrançois Revol //window.open("<?php echo $_SERVER["SCRIPT_NAME"] . "?close"; ?>", "closing", "width=100,height=30,location=no,menubar=no,toolbar=no,scrollbars=no"); 84298d26da2SFrançois Revol} 8434cf03112SFrançois Revol 8444cf03112SFrançois Revolfunction scrollToAnchor(anchor) { 8454cf03112SFrançois Revol var a = document.anchors[anchor]; 8464cf03112SFrançois Revol if (a) { 8474cf03112SFrançois Revol if (a.scrollIntoView) 8484cf03112SFrançois Revol a.scrollIntoView(true); 8494cf03112SFrançois Revol else if (a.focus) 8504cf03112SFrançois Revol a.focus(); 8514cf03112SFrançois Revol } else 8524cf03112SFrançois Revol window.location.hash = anchor; 8534cf03112SFrançois Revol} 85498d26da2SFrançois Revol</script> 85598d26da2SFrançois Revol</head> 85698d26da2SFrançois Revol<?php 85798d26da2SFrançois Revol 85898d26da2SFrançois Revol 85998d26da2SFrançois Revolif ($closing == 1) 86098d26da2SFrançois Revol echo "<body>"; 86198d26da2SFrançois Revolelse 86298d26da2SFrançois Revol echo "<body onunload=\"onPageUnload();\">"; 86398d26da2SFrançois Revol 86498d26da2SFrançois Revol 865f0cbfcafSFrançois Revolout("<div style=\"text-align:right;\">Available displays: " . 8664720c31bSFrançois Revol available_qemu_slots() . "/" . total_qemu_slots() . 8674720c31bSFrançois Revol "</div>"); 8684720c31bSFrançois Revol 8694720c31bSFrançois Revol 8704720c31bSFrançois Revolprobe_keymap(); 871f0cbfcafSFrançois Revolprobe_options_form(); 8724720c31bSFrançois Revol 873e8fc4975SFrançois Revoldbg("Checking if session is running..."); 874e8fc4975SFrançois Revol 8754720c31bSFrançois Revol$qemuidx = -1; 876c6f50a6aSFrançois Revol 877e8fc4975SFrançois Revolif (is_my_session_valid()) { 8784720c31bSFrançois Revol dbg("Session running."); 879e8fc4975SFrançois Revol $qemuidx = qemu_slot(); 8804720c31bSFrançois Revol if ($do_kill) { 881e8fc4975SFrançois Revol dbg("closing..."); 8824720c31bSFrançois Revol stop_qemu(); 883e8fc4975SFrançois Revol } 8844720c31bSFrançois Revol} else if (!$do_kill && $do_run) { 8854720c31bSFrançois Revol dbg("Need to start qemu."); 8864720c31bSFrançois Revol 8874720c31bSFrançois Revol $qemuidx = start_qemu(); 888f0cbfcafSFrançois Revol //out("Waiting for vnc server..."); 889f0cbfcafSFrançois Revol //sleep(5); 8904720c31bSFrançois Revol} 8914720c31bSFrançois Revol 8924720c31bSFrançois Revol 8934720c31bSFrançois Revolif ($qemuidx >= 0 && !$do_kill) { 8944720c31bSFrançois Revol output_kill_form(); 895f0cbfcafSFrançois Revol output_serial_output_code(); 896664c8b6dSFrançois Revol output_audio_player_code(); 8974720c31bSFrançois Revol output_vnc_info(); 898f0cbfcafSFrançois Revol out("Waiting for vnc server..."); 899f0cbfcafSFrançois Revol sleep(1); 9004720c31bSFrançois Revol output_applet_code(); 9014720c31bSFrançois Revol} else { 9024720c31bSFrançois Revol output_options_form(); 903e8fc4975SFrançois Revol} 904e8fc4975SFrançois Revol 905d2bef01cSFrançois Revol//phpinfo(); 906e8fc4975SFrançois Revol 907e8fc4975SFrançois Revol?> 908e8fc4975SFrançois Revol 909e8fc4975SFrançois Revol</body> 910e8fc4975SFrançois Revol</html> 911