<?php require_once "class.php"; closeAll();
function processRequests($db) { if (array_key_exists('window', $_REQUEST)) { // All windows related commands must start with window=. $windownumber = $_REQUEST['window']; if ($windownumber != 'vncwin') { // This is the normal case. // Special handling is needed when called with window=vncwin, see below. $window = $windownumber - 1; // TODO: $win_id und $windowname können vermutlich zusammengefasst werden. $win_id = $db->getWindowIDBySection($windownumber); $windowlist = windowList(); if (count($windowlist) == 0) { trace("no window found for command"); $windowname = false; $windowhex = 0; } else { // TODO: improve test whether window exists. $windowname = $windowlist[$window]; $windowhex = hexdec($windowname); } } if ($windowname && array_key_exists('key', $_REQUEST)) { $key = $_REQUEST['key']; trace("key '{$key}' in window '{$windownumber}'"); wmShow($windowname); // activateControls($windowhex); // displayCommand("xdotool windowfocus $windowhex key $key"); // trying mousemove and click for better vnc control displayCommand("xdotool mousemove --window {$windowhex} 100 100 " . "key {$key}"); } if ($windowname && array_key_exists('keydown', $_REQUEST)) { // TODO: keydown is currently mapped to key because we had problems // with sticking keys (no keyup seen). This should be fixed by a // better event handling. $key = $_REQUEST['keydown']; trace("keydown '{$key}' in window '{$windownumber}'"); wmShow($windowname); // activateControls($windowhex); // displayCommand("xdotool windowfocus $windowhex key $key"); // trying mousemove and click for better vnc control displayCommand("xdotool mousemove --window {$windowhex} 100 100 " . "key {$key}"); //~ displayCommand("xdotool windowfocus $windowhex keydown $key"); } if ($windowname && array_key_exists('keyup', $_REQUEST)) { // TODO: keyup is currently ignored, see comment above. $key = $_REQUEST['keyup']; trace("keyup '{$key}' in window '{$windownumber}'"); // activateControls($windowhex); //~ wmShow($windowname); //~ displayCommand("xdotool windowfocus $windowhex keyup $key"); } if (array_key_exists('delete', $_REQUEST)) { $delete = str_replace(" ", "\\ ", addslashes($_REQUEST['delete'])); trace("delete={$delete}, close window {$windownumber}"); if (file_exists($delete)) { trace("+++ DELETE FILE FROM WEBINTERFACE +++"); unlink($delete); } elseif ($delete == "VNC") { trace("+++ DELETE VNC Client FROM DAEMON +++"); // call via daemon: ?window=vncwin&delete=VNC&vncid=123 trace("vnc delete in control"); $win_id = $_REQUEST['vncid']; // = hexWindow in database, but not on screen trace("VNC cia Daemon ... id={$win_id}"); } elseif (strstr($delete, "http")) { trace("+++ DELETE Browserwindow +++"); } elseif (preg_match('/(^\\w{3,}@\\w{1,})/', $delete)) { trace("+++ DELETE VNC Client FROM WEBINTERFACE +++"); // call via webinterface $win_id = $db->querySingle("SELECT win_id FROM window WHERE file='{$delete}' AND handler='vnc'"); trace("DELETE VNC Window with ID={$win_id} FROM Database ::\n SELECT win_id FROM window WHERE file='{$delete}' AND handler='vnc'"); } else { trace("Unhandled delete for '{$delete}'"); } wmClose($win_id); $db->deleteWindow($win_id); } if (array_key_exists('closeOrphans', $_REQUEST)) { // win_ids in db $windows_in_db = $db->getWindows(); $db_ids = array(); if (count($windows_in_db) > 0) { foreach ($windows_in_db as $win) { array_push($db_ids, $win['win_id']); } } // win_ids on screen $screen_ids = windowListOnScreen(); // orphaned windows $orphan_ids = array_diff($screen_ids, $db_ids); if (count($orphan_ids) > 0) { // close windows on screen not existing in database foreach ($orphan_ids as $id) { wmClose($id); } } } if (array_key_exists('toggle', $_REQUEST)) { // Change window state from visible to invisible and vice versa. $state = $db->getState_Window($win_id); trace("toggle window {$windownumber}, id={$win_id}, state={$state}"); if ($state == "active") { wmHide($win_id); $db->setState_Window($win_id, "inactive"); } else { wmShow($win_id); $db->setState_Window($win_id, "active"); } } } elseif (array_key_exists('layout', $_REQUEST)) { setLayout($_REQUEST['layout']); } elseif (array_key_exists('logout', $_REQUEST)) { doLogout($_REQUEST['logout']); } elseif (array_key_exists('newVncWindow', $_REQUEST)) { // TODO: Better write new code for VNC window. addNewWindow($db, unserialize(urldecode($_REQUEST['newVncWindow']))); } elseif (array_key_exists('newWindow', $_REQUEST)) { createNewWindow($db, unserialize(urldecode($_REQUEST['newWindow']))); } if (array_key_exists('switchWindows', $_REQUEST)) { $before = $_REQUEST['before']; $after = $_REQUEST['after']; trace("switching {$before} and {$after}"); // exchange section $win_id1 = $db->getWindowIDBySection($before); $win_id2 = $db->getWindowIDBySection($after); $db->updateWindow($win_id1, 'section', $after); $db->updateWindow($win_id2, 'section', $before); trace("++updating database {$win_id1} section={$after}"); trace("++updating database {$win_id2} section={$before}"); // Update display (no layout change). setLayout(null); } if (array_key_exists('openURL', $_REQUEST)) { $openURL = $_REQUEST['openURL']; trace("openURL {$openURL}"); $dt = new DateTime(); $date = $dt->format('Y-m-d H:i:s'); $window = array("id" => "", "win_id" => "", "section" => "", "state" => "", "file" => $openURL, "handler" => "/usr/bin/nohup /usr/bin/dwb", "userid" => "", "date" => $date); createNewWindow($db, $window); } // TODO: chef if query redundant? if (array_key_exists('closeAll', $_REQUEST)) { $close = $_REQUEST['closeAll']; trace("close all windows {$close}"); closeAll(); } }