diff options
author | Liam McLoughlin <hexxeh@hexxeh.net> | 2011-07-27 21:04:32 +0100 |
---|---|---|
committer | Liam McLoughlin <hexxeh@hexxeh.net> | 2011-07-27 21:04:32 +0100 |
commit | e27028f91f5fb2149054adbb89d14177f0e6f3db (patch) | |
tree | b4a1c0729fbb92237fd6e25434b93b8b761c7e5e /web | |
parent | Moved to using mysqli and prepared statements (diff) | |
download | gentoaster-e27028f91f5fb2149054adbb89d14177f0e6f3db.tar.gz gentoaster-e27028f91f5fb2149054adbb89d14177f0e6f3db.tar.bz2 gentoaster-e27028f91f5fb2149054adbb89d14177f0e6f3db.zip |
Added simultaneous build settings
Diffstat (limited to 'web')
-rw-r--r-- | web/config.php | 3 | ||||
-rw-r--r-- | web/index.php | 23 | ||||
-rw-r--r-- | web/process.php | 2 | ||||
-rw-r--r-- | web/status.php | 9 | ||||
-rw-r--r-- | web/testdrive.php | 2 |
5 files changed, 37 insertions, 2 deletions
diff --git a/web/config.php b/web/config.php index 30d6aa4..c31e60b 100644 --- a/web/config.php +++ b/web/config.php @@ -6,6 +6,9 @@ // Path to the zonetab file define("ZONETAB", "/usr/share/zoneinfo/zone.tab"); + // Should we allow multiple simultaneous builds for a user? + define("SIMULTANEOUS_BUILDS", false); + // What should we limit the virtual machine disk size to? define("MAX_DISK_SIZE", 16384); diff --git a/web/index.php b/web/index.php index 6b6abec..a68a219 100644 --- a/web/index.php +++ b/web/index.php @@ -5,6 +5,29 @@ 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); + + $stmt = $db->prepare("SELECT id FROM builds WHERE ipaddress = ?"); + $stmt->bind_param("s", $ipaddress); + $stmt->execute(); + $stmt->store_result(); + + if ($stmt->num_rows == 1) { + $stmt->bind_result($buildID); + $stmt->fetch(); + header("Location: status.php?uuid=".$buildID."&simultaneous=true"); + } + $stmt->close(); + } + $timezones = array(); $zonetab = file(ZONETAB); foreach ($zonetab as $buf) { diff --git a/web/process.php b/web/process.php index 238e843..9ba055b 100644 --- a/web/process.php +++ b/web/process.php @@ -9,7 +9,7 @@ require_once "recaptcha.php"; $remoteAddress = filter_input(INPUT_SERVER, - "remote_addr", + "REMOTE_ADDR", FILTER_VALIDATE_IP); $challenge = filter_input(INPUT_POST, "recaptcha_challenge_field", diff --git a/web/status.php b/web/status.php index 719afe6..d2e8715 100644 --- a/web/status.php +++ b/web/status.php @@ -6,9 +6,16 @@ require_once "config.php"; $buildID = filter_input(INPUT_GET, "uuid", FILTER_UNSAFE_RAW); + $simultaneous = filter_input(INPUT_GET, "simultaneous", FILTER_VALIDATE_BOOLEAN); $buildresult = "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); @@ -19,6 +26,7 @@ $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(); @@ -103,6 +111,7 @@ <div id="status" class="step"> <h1><?php echo $titleString; ?></h1> <p> + <?php echo $simultaneousString; ?> <?php echo $buildresult; ?> <div id="progressbar"></div> </p> diff --git a/web/testdrive.php b/web/testdrive.php index 8f3c718..3847b69 100644 --- a/web/testdrive.php +++ b/web/testdrive.php @@ -18,7 +18,7 @@ $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(); |