aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiam McLoughlin <hexxeh@hexxeh.net>2011-08-12 23:16:06 +0100
committerLiam McLoughlin <hexxeh@hexxeh.net>2011-08-13 00:16:37 +0100
commitd4335ebfcfed221a37d14958c31b9152187b3b69 (patch)
tree197cb1d310e535e956b10a1a2c5b115eb46ac8bd
parentIf the kernel config is out of date, try to use defaults to stop the build fr... (diff)
downloadgentoaster-d4335ebfcfed221a37d14958c31b9152187b3b69.tar.gz
gentoaster-d4335ebfcfed221a37d14958c31b9152187b3b69.tar.bz2
gentoaster-d4335ebfcfed221a37d14958c31b9152187b3b69.zip
WebUI refactor, added testdrive memory configuration option
-rw-r--r--config.php3
-rwxr-xr-xcreate_image.sh2
-rw-r--r--daemon.php2
-rw-r--r--ui/ajax.php72
-rw-r--r--ui/index.php88
-rw-r--r--ui/process.php109
-rw-r--r--ui/recaptcha.php (renamed from web/recaptcha.php)0
-rw-r--r--ui/status.php107
-rw-r--r--ui/testdrive.php69
-rw-r--r--web/ajax.php72
-rw-r--r--web/index.php88
-rw-r--r--web/process.php111
-rw-r--r--web/status.php107
-rw-r--r--web/testdrive.php69
-rwxr-xr-xwrap.sh13
15 files changed, 466 insertions, 446 deletions
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 @@
+<?php
+
+ // Gentoaster web interface AJAX remote
+ // Licensed under GPL v3, see COPYING file
+
+ require_once "config.php";
+
+ $buildID = filter_input(INPUT_GET, "uuid", FILTER_UNSAFE_RAW);
+
+
+ $db = new mysqli(
+ MYSQL_HOSTNAME,
+ MYSQL_USERNAME,
+ MYSQL_PASSWORD,
+ MYSQL_DATABASE
+ );
+
+ if (mysqli_connect_errno()) {
+ die("Could not connect to database ".mysqli_connect_error());
+ }
+
+ $stmt = $db->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 @@
+<?php
+ require_once "config.php";
+
+ if (RECAPTCHA_ENABLED) {
+ require_once GENTOASTER_PATH."/ui/recaptcha.php";
+ }
+
+ if (!SIMULTANEOUS_BUILDS) {
+ $db = new mysqli(
+ MYSQL_HOSTNAME,
+ MYSQL_USERNAME,
+ MYSQL_PASSWORD,
+ MYSQL_DATABASE
+ );
+
+ if (mysqli_connect_errno()) {
+ die("Could not connect to database ".mysqli_connect_error());
+ }
+
+ $ipaddress = filter_input(
+ INPUT_SERVER,
+ "REMOTE_ADDR",
+ FILTER_VALIDATE_IP
+ );
+
+ $query = "SELECT id, handle ".
+ "FROM builds WHERE ipaddress = ?";
+ $stmt = $db->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 .= "<option";
+ if ($timezone == DEFAULT_TIMEZONE) {
+ $timezoneOption .= " selected";
+ }
+ $timezoneOption .= ">".$timezone."</option>\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 .= "<option value=\"".$layoutCode."\"";
+ if ($layoutCode == DEFAULT_KEYBOARD) {
+ $keyboardOption .= " selected";
+ }
+ $keyboardOption .= ">".trim($layoutName)."</option>\n";
+ }
+?> \ No newline at end of file
diff --git a/ui/process.php b/ui/process.php
new file mode 100644
index 0000000..29dd296
--- /dev/null
+++ b/ui/process.php
@@ -0,0 +1,109 @@
+<?php
+
+ // Gentoaster web interface config processor
+ // Licensed under GPL v3, see COPYING file
+
+ require_once "config.php";
+
+ $ipaddress = filter_input(
+ INPUT_SERVER,
+ "REMOTE_ADDR",
+ FILTER_VALIDATE_IP
+ );
+
+ if (RECAPTCHA_ENABLED) {
+ require_once GENTOASTER_PATH."/ui/recaptcha.php";
+
+ $challenge = filter_input(
+ INPUT_POST,
+ "recaptcha_challenge_field",
+ FILTER_UNSAFE_RAW
+ );
+
+ $response = filter_input(
+ INPUT_POST,
+ "recaptcha_response_field",
+ FILTER_UNSAFE_RAW
+ );
+
+ $resp = recaptcha_check_answer(
+ RECAPTCHA_PRIVATE_KEY,
+ $ipaddress,
+ $challenge,
+ $response
+ );
+
+ if (!$resp->is_valid) {
+ die("CAPTCHA was incorrect");
+ }
+ }
+
+ function sanitize_shellarg($arg)
+ {
+ $arg = str_replace("\r\n", " ", $arg);
+ $arg = str_replace("\n", " ", $arg);
+ return escapeshellarg($arg);
+ }
+ $sfi = array("options" => "sanitize_shellarg");
+
+ $buildID = uniqid();
+ $bootMegabytes = filter_input(INPUT_POST, "boot_size", FILTER_VALIDATE_INT);
+ $swapMegabytes = filter_input(INPUT_POST, "swap_size", FILTER_VALIDATE_INT);
+ $rootMegabytes = filter_input(INPUT_POST, "root_size", FILTER_VALIDATE_INT);
+ $timezone = filter_input(INPUT_POST, "timezone", FILTER_CALLBACK, $sfi);
+ $keyboard = filter_input(INPUT_POST, "keyboard", FILTER_CALLBACK, $sfi);
+ $hostname = filter_input(INPUT_POST, "hostname", FILTER_CALLBACK, $sfi);
+ $username = filter_input(INPUT_POST, "username", FILTER_CALLBACK, $sfi);
+ $password = filter_input(INPUT_POST, "password", FILTER_CALLBACK, $sfi);
+ $rootPass = filter_input(INPUT_POST, "rootpassword", FILTER_CALLBACK, $sfi);
+ $packagesList = filter_input(INPUT_POST, "packages", FILTER_CALLBACK, $sfi);
+ $use = filter_input(INPUT_POST, "use", FILTER_CALLBACK, $sfi);
+ $puse = filter_input(INPUT_POST, "puse", FILTER_CALLBACK, $sfi);
+ $features = filter_input(INPUT_POST, "features", FILTER_CALLBACK, $sfi);
+ $keywords = filter_input(INPUT_POST, "keywords", FILTER_CALLBACK, $sfi);
+ $outputFormat = filter_input(INPUT_POST, "format", FILTER_CALLBACK, $sfi);
+ $email = filter_input(INPUT_POST, "email", FILTER_VALIDATE_EMAIL);
+
+$iniString = "[vmconfig]
+
+BUILD_ID='$buildID'
+BOOT_MEGABYTES='$bootMegabytes'
+SWAP_MEGABYTES='$swapMegabytes'
+ROOT_MEGABYTES='$rootMegabytes'
+TIMEZONE=$timezone
+KEYBOARD=$keyboard
+HOSTNAME=$hostname
+ROOT_PASSWORD=$rootPass
+DEFAULT_USERNAME=$username
+DEFAULT_PASSWORD=$password
+USE_FLAGS=$use
+PACKAGE_USE=$puse
+FEATURES=$features
+PACKAGE_ACCEPT_KEYWORDS=$keywords
+PACKAGES_LIST=$packagesList
+OUTPUT_FORMAT=$outputFormat";
+
+ $client = new GearmanClient();
+ $client->addServer();
+ $handle = $client->doBackground("invoke_image_build", $iniString);
+
+ $db = new mysqli(
+ MYSQL_HOSTNAME,
+ MYSQL_USERNAME,
+ MYSQL_PASSWORD,
+ MYSQL_DATABASE
+ );
+
+ if (mysqli_connect_errno()) {
+ die("Could not connect to database ".mysqli_connect_error());
+ }
+
+ $query = "INSERT INTO builds (id, handle, ipaddress, email) ".
+ "VALUES(?, ?, ?, ?)";
+ $stmt = $db->prepare($query);
+ $stmt->bind_param("ssss", $buildID, $handle, $ipaddress, $email);
+ $stmt->execute();
+ $stmt->close();
+ $db->close();
+
+ header("Location: finished.php?uuid=".$buildID); \ No newline at end of file
diff --git a/web/recaptcha.php b/ui/recaptcha.php
index 32c4f4d..32c4f4d 100644
--- a/web/recaptcha.php
+++ b/ui/recaptcha.php
diff --git a/ui/status.php b/ui/status.php
new file mode 100644
index 0000000..5b10483
--- /dev/null
+++ b/ui/status.php
@@ -0,0 +1,107 @@
+<?php
+
+ // Gentoaster web interface status
+ // Licensed under GPL v3, see COPYING file
+
+ require_once "config.php";
+
+ $buildID = filter_input(INPUT_GET, "uuid", FILTER_UNSAFE_RAW);
+ $simultaneous = filter_input(
+ INPUT_GET,
+ "simultaneous",
+ FILTER_VALIDATE_BOOLEAN
+ );
+ $bres = "Unknown!";
+ $inprogress = false;
+ $builddone = false;
+ $simultaneousString = "";
+
+ if ($simultaneous && !SIMULTANEOUS_BUILDS) {
+ $simultaneousString = "You were redirected to this page because you ".
+ "already have a build in progress. Simultaneous ".
+ "builds are disabled on this server.<br/><br/>";
+ }
+
+ $db = new mysqli(
+ MYSQL_HOSTNAME,
+ MYSQL_USERNAME,
+ MYSQL_PASSWORD,
+ MYSQL_DATABASE
+ );
+
+ if (mysqli_connect_errno()) {
+ die("Could not connect to database ".mysqli_connect_error());
+ }
+
+ $stmt = $db->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) {
+ $percentage = ceil($status[2]/$status[3]*100);
+ $bres = "Your build is currently running".
+ " and is <span id=\"percent\">".$percentage."</span>% complete";
+ $inprogress = true;
+ } else {
+ $bres = "Task has not yet been processed";
+ }
+ } 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) {
+ $bres = "Your build is complete! ".
+ "What would you like to do now?".
+ "<br /><br /><center>".
+ "<table><tr><td>".
+ "<a href=\"".IMAGES_URL."/".
+ $buildID."/".$buildID.
+ ".tar.gz\">".
+ "<img style=\"padding: 10px;\" ".
+ "src=\"img/icons/download.png\">".
+ "</a></td><td>".
+ "<a href=\"testdrive.php?uuid=".
+ $buildID."\">".
+ "<img style=\"padding: 10px;\" ".
+ "src=\"img/icons/testdrive.png\">".
+ "</a></td></tr>".
+ "<tr><td>Download</td>".
+ "<td>Testdrive</td></tr>".
+ "</table></center>";
+ $builddone = true;
+ } else {
+ $bres = "Job returned with code ".
+ $returncode.": ".$result;
+ }
+ } else {
+ $bres = "Job failed";
+ }
+ }
+ } else {
+ $stmt->close();
+ $bres = "Invalid handle hash";
+ }
+
+ $db->close();
+
+ if (!$builddone) {
+ $titleString = "How's things?";
+ } else {
+ $titleString = "It's showtime!";
+ }
+?> \ No newline at end of file
diff --git a/ui/testdrive.php b/ui/testdrive.php
new file mode 100644
index 0000000..be4c514
--- /dev/null
+++ b/ui/testdrive.php
@@ -0,0 +1,69 @@
+<?php
+
+ // Gentoaster web interface framebuffer testdrive
+ // Licensed under GPL v3, see COPYING file
+
+ require_once "config.php";
+
+ $buildID = filter_input(INPUT_GET, "uuid", FILTER_UNSAFE_RAW);
+ $buildresult = "Unknown!";
+ $inprogress = false;
+
+ $db = new mysqli(
+ MYSQL_HOSTNAME,
+ MYSQL_USERNAME,
+ MYSQL_PASSWORD,
+ MYSQL_DATABASE
+ );
+
+ if (mysqli_connect_errno()) {
+ die("Could not connect to database ".mysqli_connect_error());
+ }
+
+ $stmt = $db->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]) {
+ header("Location: status.php?uuid=".$buildID);
+ } 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) {
+ // we're built, let's do this
+ $client = new GearmanClient();
+ $client->addServer();
+ $server = $client->do(
+ "invoke_start_image",
+ $buildID
+ );
+ $server = unserialize($server);
+ } else {
+ header("Location: status.php?uuid=".$buildID);
+ }
+ } else {
+ header("Location: status.php?uuid=".$buildID);
+ }
+ }
+ } else {
+ $stmt->close();
+ die("Invalid handle hash");
+ }
+
+ $db->close();
+?> \ No newline at end of file
diff --git a/web/ajax.php b/web/ajax.php
index 105c893..0b11359 100644
--- a/web/ajax.php
+++ b/web/ajax.php
@@ -1,72 +1,4 @@
<?php
-
- // Gentoaster web interface AJAX remote
- // Licensed under GPL v3, see COPYING file
-
- require_once "config.php";
-
- $buildID = filter_input(INPUT_GET, "uuid", FILTER_UNSAFE_RAW);
-
-
- $db = new mysqli(
- MYSQL_HOSTNAME,
- MYSQL_USERNAME,
- MYSQL_PASSWORD,
- MYSQL_DATABASE
- );
-
- if (mysqli_connect_errno()) {
- die("Could not connect to database ".mysqli_connect_error());
- }
-
- $stmt = $db->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);
+ require_once "config.php";
+ require_once GENTOASTER_PATH."/ui/ajax.php";
?> \ No newline at end of file
diff --git a/web/index.php b/web/index.php
index 6bb2f9f..aa17151 100644
--- a/web/index.php
+++ b/web/index.php
@@ -1,90 +1,6 @@
<?php
- require_once "config.php";
-
- if (RECAPTCHA_ENABLED) {
- require_once "recaptcha.php";
- }
-
- if (!SIMULTANEOUS_BUILDS) {
- $db = new mysqli(
- MYSQL_HOSTNAME,
- MYSQL_USERNAME,
- MYSQL_PASSWORD,
- MYSQL_DATABASE
- );
-
- if (mysqli_connect_errno()) {
- die("Could not connect to database ".mysqli_connect_error());
- }
-
- $ipaddress = filter_input(
- INPUT_SERVER,
- "REMOTE_ADDR",
- FILTER_VALIDATE_IP
- );
-
- $query = "SELECT id, handle ".
- "FROM builds WHERE ipaddress = ?";
- $stmt = $db->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 .= "<option";
- if ($timezone == DEFAULT_TIMEZONE) {
- $timezoneOption .= " selected";
- }
- $timezoneOption .= ">".$timezone."</option>\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 .= "<option value=\"".$layoutCode."\"";
- if ($layoutCode == DEFAULT_KEYBOARD) {
- $keyboardOption .= " selected";
- }
- $keyboardOption .= ">".trim($layoutName)."</option>\n";
- }
+ require_once "config.php";
+ require_once GENTOASTER_PATH."/ui/index.php";
?>
<html>
<head>
diff --git a/web/process.php b/web/process.php
index de8ea90..0105475 100644
--- a/web/process.php
+++ b/web/process.php
@@ -1,109 +1,4 @@
<?php
-
- // Gentoaster web interface config processor
- // Licensed under GPL v3, see COPYING file
-
- require_once "config.php";
-
- $ipaddress = filter_input(
- INPUT_SERVER,
- "REMOTE_ADDR",
- FILTER_VALIDATE_IP
- );
-
- if (RECAPTCHA_ENABLED) {
- require_once "recaptcha.php";
-
- $challenge = filter_input(
- INPUT_POST,
- "recaptcha_challenge_field",
- FILTER_UNSAFE_RAW
- );
-
- $response = filter_input(
- INPUT_POST,
- "recaptcha_response_field",
- FILTER_UNSAFE_RAW
- );
-
- $resp = recaptcha_check_answer(
- RECAPTCHA_PRIVATE_KEY,
- $ipaddress,
- $challenge,
- $response
- );
-
- if (!$resp->is_valid) {
- die("CAPTCHA was incorrect");
- }
- }
-
- function sanitize_shellarg($arg)
- {
- $arg = str_replace("\r\n", " ", $arg);
- $arg = str_replace("\n", " ", $arg);
- return escapeshellarg($arg);
- }
- $sfi = array("options" => "sanitize_shellarg");
-
- $buildID = uniqid();
- $bootMegabytes = filter_input(INPUT_POST, "boot_size", FILTER_VALIDATE_INT);
- $swapMegabytes = filter_input(INPUT_POST, "swap_size", FILTER_VALIDATE_INT);
- $rootMegabytes = filter_input(INPUT_POST, "root_size", FILTER_VALIDATE_INT);
- $timezone = filter_input(INPUT_POST, "timezone", FILTER_CALLBACK, $sfi);
- $keyboard = filter_input(INPUT_POST, "keyboard", FILTER_CALLBACK, $sfi);
- $hostname = filter_input(INPUT_POST, "hostname", FILTER_CALLBACK, $sfi);
- $username = filter_input(INPUT_POST, "username", FILTER_CALLBACK, $sfi);
- $password = filter_input(INPUT_POST, "password", FILTER_CALLBACK, $sfi);
- $rootPass = filter_input(INPUT_POST, "rootpassword", FILTER_CALLBACK, $sfi);
- $packagesList = filter_input(INPUT_POST, "packages", FILTER_CALLBACK, $sfi);
- $use = filter_input(INPUT_POST, "use", FILTER_CALLBACK, $sfi);
- $puse = filter_input(INPUT_POST, "puse", FILTER_CALLBACK, $sfi);
- $features = filter_input(INPUT_POST, "features", FILTER_CALLBACK, $sfi);
- $keywords = filter_input(INPUT_POST, "keywords", FILTER_CALLBACK, $sfi);
- $outputFormat = filter_input(INPUT_POST, "format", FILTER_CALLBACK, $sfi);
- $email = filter_input(INPUT_POST, "email", FILTER_VALIDATE_EMAIL);
-
-$iniString = "[vmconfig]
-
-BUILD_ID='$buildID'
-BOOT_MEGABYTES='$bootMegabytes'
-SWAP_MEGABYTES='$swapMegabytes'
-ROOT_MEGABYTES='$rootMegabytes'
-TIMEZONE=$timezone
-KEYBOARD=$keyboard
-HOSTNAME=$hostname
-ROOT_PASSWORD=$rootPass
-DEFAULT_USERNAME=$username
-DEFAULT_PASSWORD=$password
-USE_FLAGS=$use
-PACKAGE_USE=$puse
-FEATURES=$features
-PACKAGE_ACCEPT_KEYWORDS=$keywords
-PACKAGES_LIST=$packagesList
-OUTPUT_FORMAT=$outputFormat";
-
- $client = new GearmanClient();
- $client->addServer();
- $handle = $client->doBackground("invoke_image_build", $iniString);
-
- $db = new mysqli(
- MYSQL_HOSTNAME,
- MYSQL_USERNAME,
- MYSQL_PASSWORD,
- MYSQL_DATABASE
- );
-
- if (mysqli_connect_errno()) {
- die("Could not connect to database ".mysqli_connect_error());
- }
-
- $query = "INSERT INTO builds (id, handle, ipaddress, email) ".
- "VALUES(?, ?, ?, ?)";
- $stmt = $db->prepare($query);
- $stmt->bind_param("ssss", $buildID, $handle, $ipaddress, $email);
- $stmt->execute();
- $stmt->close();
- $db->close();
-
- header("Location: finished.php?uuid=".$buildID); \ No newline at end of file
+ require_once "config.php";
+ require_once GENTOASTER_PATH."/ui/process.php";
+?> \ No newline at end of file
diff --git a/web/status.php b/web/status.php
index bde0ad2..676b528 100644
--- a/web/status.php
+++ b/web/status.php
@@ -1,109 +1,6 @@
<?php
-
- // Gentoaster web interface finished stage
- // Licensed under GPL v3, see COPYING file
-
- require_once "config.php";
-
- $buildID = filter_input(INPUT_GET, "uuid", FILTER_UNSAFE_RAW);
- $simultaneous = filter_input(
- INPUT_GET,
- "simultaneous",
- FILTER_VALIDATE_BOOLEAN
- );
- $bres = "Unknown!";
- $inprogress = false;
- $builddone = false;
- $simultaneousString = "";
-
- if ($simultaneous && !SIMULTANEOUS_BUILDS) {
- $simultaneousString = "You were redirected to this page because you ".
- "already have a build in progress. Simultaneous ".
- "builds are disabled on this server.<br/><br/>";
- }
-
- $db = new mysqli(
- MYSQL_HOSTNAME,
- MYSQL_USERNAME,
- MYSQL_PASSWORD,
- MYSQL_DATABASE
- );
-
- if (mysqli_connect_errno()) {
- die("Could not connect to database ".mysqli_connect_error());
- }
-
- $stmt = $db->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) {
- $percentage = ceil($status[2]/$status[3]*100);
- $bres = "Your build is currently running".
- " and is <span id=\"percent\">".$percentage."</span>% complete";
- $inprogress = true;
- } else {
- $bres = "Task has not yet been processed";
- }
- } 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) {
- $bres = "Your build is complete! ".
- "What would you like to do now?".
- "<br /><br /><center>".
- "<table><tr><td>".
- "<a href=\"".IMAGES_URL."/".
- $buildID."/".$buildID.
- ".tar.gz\">".
- "<img style=\"padding: 10px;\" ".
- "src=\"img/icons/download.png\">".
- "</a></td><td>".
- "<a href=\"testdrive.php?uuid=".
- $buildID."\">".
- "<img style=\"padding: 10px;\" ".
- "src=\"img/icons/testdrive.png\">".
- "</a></td></tr>".
- "<tr><td>Download</td>".
- "<td>Testdrive</td></tr>".
- "</table></center>";
- $builddone = true;
- } else {
- $bres = "Job returned with code ".
- $returncode.": ".$result;
- }
- } else {
- $bres = "Job failed";
- }
- }
- } else {
- $stmt->close();
- $bres = "Invalid handle hash";
- }
-
- $db->close();
-
- if (!$builddone) {
- $titleString = "How's things?";
- } else {
- $titleString = "It's showtime!";
- }
+ require_once "config.php";
+ require_once GENTOASTER_PATH."/ui/status.php";
?>
<html>
<head>
diff --git a/web/testdrive.php b/web/testdrive.php
index a141af5..4c17bdd 100644
--- a/web/testdrive.php
+++ b/web/testdrive.php
@@ -1,71 +1,6 @@
<?php
-
- // Gentoaster web interface testdrive
- // Licensed under GPL v3, see COPYING file
-
- require_once "config.php";
-
- $buildID = filter_input(INPUT_GET, "uuid", FILTER_UNSAFE_RAW);
- $buildresult = "Unknown!";
- $inprogress = false;
-
- $db = new mysqli(
- MYSQL_HOSTNAME,
- MYSQL_USERNAME,
- MYSQL_PASSWORD,
- MYSQL_DATABASE
- );
-
- if (mysqli_connect_errno()) {
- die("Could not connect to database ".mysqli_connect_error());
- }
-
- $stmt = $db->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]) {
- header("Location: status.php?uuid=".$buildID);
- } 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) {
- // we're built, let's do this
- $client = new GearmanClient();
- $client->addServer();
- $server = $client->do(
- "invoke_start_image",
- $buildID
- );
- $server = unserialize($server);
- } else {
- header("Location: status.php?uuid=".$buildID);
- }
- } else {
- header("Location: status.php?uuid=".$buildID);
- }
- }
- } else {
- $stmt->close();
- die("Invalid handle hash");
- }
-
- $db->close();
+ require_once "config.php";
+ require_once GENTOASTER_PATH."/ui/testdrive.php";
?>
<html>
<head>
diff --git a/wrap.sh b/wrap.sh
index 9a2cc65..8b5da72 100755
--- a/wrap.sh
+++ b/wrap.sh
@@ -1,11 +1,8 @@
#!/bin/bash
-# this is a dirty hack that will be disappearing soon
-# just saves me restarting the daemon every time i want to change something
-
cd /usr/share/websockify
-MEMORY=512
-DISP=$(( ${2}-5900 ))
-DISP2=$(( ${2}+1000 ))
-qemu -hda $1 -m ${MEMORY} -net nic -net user -vnc :$DISP -usbdevice tablet &
-websockify -D ${DISP2} 127.0.0.1:${2}
+MEMORY=${3}
+VNCDISPLAY=$(( ${2}-5900 ))
+RPORT=$(( ${2}+1000 ))
+qemu -hda $1 -m ${MEMORY} -net nic -net user -vnc :$VNCDISPLAY -usbdevice tablet &
+websockify -D ${RPORT} 127.0.0.1:${2}