From d4335ebfcfed221a37d14958c31b9152187b3b69 Mon Sep 17 00:00:00 2001 From: Liam McLoughlin Date: Fri, 12 Aug 2011 23:16:06 +0100 Subject: WebUI refactor, added testdrive memory configuration option --- config.php | 3 + create_image.sh | 2 +- daemon.php | 2 +- ui/ajax.php | 72 ++++++++++++++ ui/index.php | 88 +++++++++++++++++ ui/process.php | 109 +++++++++++++++++++++ ui/recaptcha.php | 277 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ui/status.php | 107 +++++++++++++++++++++ ui/testdrive.php | 69 ++++++++++++++ web/ajax.php | 72 +------------- web/index.php | 88 +---------------- web/process.php | 111 +--------------------- web/recaptcha.php | 277 ------------------------------------------------------ web/status.php | 107 +-------------------- web/testdrive.php | 69 +------------- wrap.sh | 13 +-- 16 files changed, 743 insertions(+), 723 deletions(-) create mode 100644 ui/ajax.php create mode 100644 ui/index.php create mode 100644 ui/process.php create mode 100644 ui/recaptcha.php create mode 100644 ui/status.php create mode 100644 ui/testdrive.php delete mode 100644 web/recaptcha.php diff --git a/config.php b/config.php index 96b5728..2e4021a 100644 --- a/config.php +++ b/config.php @@ -27,6 +27,9 @@ // Set the externally accessible IP/host of this machine define("EXTERNAL_HOST", "192.168.2.169"); + + // How much memory (in megabytes) should each testdrive instance have? + define("TESTDRIVE_MEMORY", "512"); // Set the port range that should be used for testdrives define("LOW_PORT", 5900); diff --git a/create_image.sh b/create_image.sh index f83c1e3..c3ec7d1 100755 --- a/create_image.sh +++ b/create_image.sh @@ -232,7 +232,7 @@ else cp ${TOOL_RES_PATH}/kernelconfig usr/src/linux/.config || handle_error "Error copying kernel config" echo "Building kernel" &>> ${LOG_FILE} - yes "" | linux32 chroot . make -C /usr/src/linux oldconfig &>> ${LOG_FILE} || handle_error "Error configuring kernel" + yes "" | linux32 chroot . make -C /usr/src/linux oldconfig &>> ${LOG_FILE} linux32 chroot . make -C /usr/src/linux -j${NUM_JOBS} &>> ${LOG_FILE} || handle_error "Error building kernel" echo "Installing kernel" &>> ${LOG_FILE} diff --git a/daemon.php b/daemon.php index 4041317..60c1616 100644 --- a/daemon.php +++ b/daemon.php @@ -212,7 +212,7 @@ if (!$running || $update) { $cmd = GENTOASTER_PATH."/".WRAP_TOOL_NAME." ". CONFIGURATIONS_PATH."/".$buildID."/".$buildID.".image ". - $port." &"; + $port." ".TESTDRIVE_MEMORY."&"; $handle = proc_open($cmd, array(), $foo); $status = proc_get_status($handle); $pid = $status["pid"]; diff --git a/ui/ajax.php b/ui/ajax.php new file mode 100644 index 0000000..105c893 --- /dev/null +++ b/ui/ajax.php @@ -0,0 +1,72 @@ +prepare("SELECT handle FROM builds WHERE id = ?"); + $stmt->bind_param("s", $buildID); + $stmt->execute(); + $stmt->store_result(); + if ($stmt->num_rows == 1) { + $stmt->bind_result($handle); + $stmt->fetch(); + $stmt->close(); + $client = new GearmanClient(); + $client->addServer(); + + $status = $client->jobStatus($handle); + if ($status[0]) { + if ($status[3] != 0) { + // in progress + $ret = array("status" => 1, "num" => $status[2], "den" => $status[3]); + } else { + // not yet processed + $ret = array("status" => 2); + } + } else { + $query = "SELECT returncode, result ". + "FROM builds WHERE id = ?"; + $stmt = $db->prepare($query); + $stmt->bind_param("s", $buildID); + $stmt->execute(); + $stmt->bind_result($returncode, $result); + $stmt->fetch(); + $stmt->close(); + if ($returncode !== null) { + if ($returncode == 0) { + // finished + $ret = array("status" => 0); + } else { + // returned with non-zero status code + $ret = array("status" => 3); + } + } else { + // failed + $ret = array("status" => 4); + } + } + } else { + // job not found + $ret = array("status" => -1); + } + + $db->close(); + + echo json_encode($ret); +?> \ No newline at end of file diff --git a/ui/index.php b/ui/index.php new file mode 100644 index 0000000..59cd061 --- /dev/null +++ b/ui/index.php @@ -0,0 +1,88 @@ +prepare($query); + $stmt->bind_param("s", $ipaddress); + $stmt->execute(); + $stmt->store_result(); + + if ($stmt->num_rows == 1) { + $stmt->bind_result($buildID, $handle); + $stmt->fetch(); + $client = new GearmanClient(); + $client->addServer(); + $status = $client->jobStatus($handle); + if ($status[0]) { + $url = "status.php?uuid=".$buildID."&simultaneous=true"; + header("Location: ".$url); + } + } + $stmt->close(); + } + + $timezones = array(); + $zonetab = file(ZONETAB); + foreach ($zonetab as $buf) { + if (substr($buf, 0, 1)=='#') { + continue; + } + $rec = preg_split('/\s+/', $buf); + $key = $rec[2]; + $val = $rec[2]; + $c = count($rec); + for ($i=3;$i<$c;$i++) { + $val.= ' '.$rec[$i]; + } + $timezones[$key] = $val; + ksort($timezones); + } + $timezoneOption = ""; + foreach ($timezones as $timezone => $description) { + $timezoneOption .= "\n"; + } + $layoutLines = file(GENTOASTER_PATH."/res/keyboard.lst"); + $keyboardOption = ""; + $layouts = array(); + + foreach($layoutLines as $layout) { + $layoutdata = explode("\t", $layout); + $layouts[$layoutdata[0]] = $layoutdata[1]; + } + asort($layouts); + + foreach($layouts as $layoutCode => $layoutName) { + $keyboardOption .= "