aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.php12
-rw-r--r--daemon.php28
-rw-r--r--web/index.php12
-rw-r--r--web/process.php7
4 files changed, 55 insertions, 4 deletions
diff --git a/config.php b/config.php
index 760c1e2..c1807fa 100644
--- a/config.php
+++ b/config.php
@@ -3,6 +3,9 @@
// Gentoaster build daemon settings
// Licensed under GPL v3, see COPYING file
+ // Set the publically viewable URL for this Gentoaster instance
+ define("GENTOASTER_URL", "http://192.168.2.169");
+
// Set the path that completed images should be stored at
define("CONFIGURATIONS_PATH", "/var/www/gentoaster/images");
@@ -26,4 +29,11 @@
define("MYSQL_HOSTNAME", "localhost");
define("MYSQL_USERNAME", "gentoaster");
define("MYSQL_PASSWORD", "");
- define("MYSQL_DATABASE", "gentoaster"); \ No newline at end of file
+ define("MYSQL_DATABASE", "gentoaster");
+
+ // Set the SMTP details that should be used for notifications
+ define("SMTP_ENABLED", false);
+ define("SMTP_HOST", "");
+ define("SMTP_USERNAME", "");
+ define("SMTP_PASSWORD", "");
+ define("SMTP_EMAIL", ""); \ No newline at end of file
diff --git a/daemon.php b/daemon.php
index 65d7d2b..4041317 100644
--- a/daemon.php
+++ b/daemon.php
@@ -4,6 +4,7 @@
// Licensed under GPL v3, see COPYING file
require_once "config.php";
+ require_once "Mail.php";
$worker = new GearmanWorker();
$worker->addServer();
@@ -36,6 +37,33 @@
$stmt->bind_param("sds", $result, $returncode, $handle);
$stmt->execute();
$stmt->close();
+
+ $query = "SELECT id, email FROM builds WHERE handle = ?";
+ $stmt = $db->prepare($query);
+ $stmt->bind_param("s", $handle);
+ $stmt->execute();
+ $stmt->bind_result($buildID, $email);
+ $stmt->fetch();
+
+ if($email != null) {
+ $headers = array('From' => SMTP_EMAIL,
+ 'To' => $email,
+ 'Subject' => "Your Gentoaster build has completed");
+
+ $smtp = Mail::factory('smtp',
+ array ('host' => SMTP_HOST,
+ 'auth' => true,
+ 'username' => SMTP_USERNAME,
+ 'password' => SMTP_PASSWORD));
+
+ $body = "Your Gentoaster build has finished.\n\n"
+ ."You can view the results at ".GENTOASTER_URL
+ ."/status.php?uuid=".$buildID;
+
+ $mail = $smtp->send($email, $headers, $body);
+ }
+
+ $stmt->close();
$db->close();
return serialize(array($returncode, $result));
diff --git a/web/index.php b/web/index.php
index dcaae6b..f46af2b 100644
--- a/web/index.php
+++ b/web/index.php
@@ -1,5 +1,6 @@
<?php
require_once "config.php";
+ require_once GENTOASTER_PATH."/config.php";
if (RECAPTCHA_ENABLED) {
require_once "recaptcha.php";
@@ -116,6 +117,17 @@
of your own personalised Gentoo virtual machine
image.</p>
</div>
+ <?php if(SMTP_ENABLED) { ?>
+ <div id="notifications" class="step">
+ <h1>Notifications</h1>
+ Want us to email you when your image has finished toasting?
+ Pop your email in here. If you don't want an email, simply
+ leave this field blank.<br /><br />
+ <label for="notifications_email">E-Mail</label>
+ <br />
+ <input type="text" name="email" id="notifications_email">
+ </div>
+ <?php } ?>
<?php
if (RECAPTCHA_ENABLED) {
?>
diff --git a/web/process.php b/web/process.php
index c590bee..de8ea90 100644
--- a/web/process.php
+++ b/web/process.php
@@ -62,6 +62,7 @@
$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]
@@ -97,10 +98,10 @@ OUTPUT_FORMAT=$outputFormat";
die("Could not connect to database ".mysqli_connect_error());
}
- $query = "INSERT INTO builds (id, handle, ipaddress) ".
- "VALUES(?, ?, ?)";
+ $query = "INSERT INTO builds (id, handle, ipaddress, email) ".
+ "VALUES(?, ?, ?, ?)";
$stmt = $db->prepare($query);
- $stmt->bind_param("sss", $buildID, $handle, $ipaddress);
+ $stmt->bind_param("ssss", $buildID, $handle, $ipaddress, $email);
$stmt->execute();
$stmt->close();
$db->close();