aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client.php14
-rw-r--r--daemon.php164
-rw-r--r--status.php20
-rw-r--r--web/config.php12
-rw-r--r--web/index.php28
-rw-r--r--web/process.php26
-rw-r--r--web/recaptcha.php277
-rw-r--r--web/status.php15
-rw-r--r--web/testdrive.php15
9 files changed, 462 insertions, 109 deletions
diff --git a/client.php b/client.php
index ce4bc1f..e2284b4 100644
--- a/client.php
+++ b/client.php
@@ -3,7 +3,11 @@
// Gentoaster build daemon client
// Licensed under GPL v3, see COPYING file
- if(!isset($argv[1])) die("No config file provided\n");
+ require_once "config.php";
+
+ if (!isset($argv[1])) {
+ die("No config file provided\n");
+ }
$client= new GearmanClient();
$client->addServer();
@@ -17,9 +21,11 @@
echo "Job sent, handle was ".$handle." - hash ".$handlehash."\n";
- $db = mysql_connect("localhost", "gentoaster", "");
- if(!$db) die("Could not connect to database ".mysql_error());
- mysql_select_db("gentoaster");
+ $db = mysql_connect(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD);
+ if (!$db) {
+ die("Could not connect to database ".mysql_error());
+ }
+ mysql_select_db(MYSQL_DATABASE);
$query = "INSERT INTO builds (id, handle)".
." VALUES('".$handlehash."','".$handle."')";
mysql_query($query);
diff --git a/daemon.php b/daemon.php
index 6570185..1936864 100644
--- a/daemon.php
+++ b/daemon.php
@@ -3,31 +3,25 @@
// Gentoaster build daemon worker
// Licensed under GPL v3, see COPYING file
- $configurationsPath = "/var/www/gentoaster/images";
- $gentoasterPath = "/usr/share/gentoaster";
- $buildToolName = "create_image.sh";
- $wrapToolName = "wrap.sh";
- $externalHost = "192.168.2.169";
- $lowPort = 5900;
- $highPort = 5999;
-
- // DO NOT EDIT BELOW THIS LINE
-
- $progressMagic = 23;
+ require_once "config.php";
$worker = new GearmanWorker();
$worker->addServer();
$worker->addFunction("invoke_image_build", "image_build");
$worker->addFunction("invoke_start_image", "start_image");
- while ($worker->work());
+ while ($worker->work()) {
+ // Do nothing!
+ };
function update_result($handle, $returncode, $result)
{
$result = trim($result);
echo "A job finished with return code ".$returncode.": ".$result."\n";
- $db = mysql_connect("localhost", "gentoaster", "");
- if(!$db) die("Could not connect to database ".mysql_error());
- mysql_select_db("gentoaster");
+ $db = mysql_connect(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD);
+ if (!$db) {
+ die("Could not connect to database ".mysql_error());
+ }
+ mysql_select_db(MYSQL_DATABASE);
$result = mysql_real_escape_string($result);
$query = "UPDATE builds".
" SET result = '".$result."', returncode = '".$returncode.
@@ -36,19 +30,19 @@
return serialize(array($returncode, $result));
}
- function check_pid($pid)
- {
- $cmd = "ps $pid";
- exec($cmd, $output, $result);
- if(count($output) >= 2){
- return true;
- }
- return false;
- }
+ function check_pid($pid)
+ {
+ $cmd = "ps $pid";
+ exec($cmd, $output, $result);
+ if (count($output) >= 2) {
+ return true;
+ }
+ return false;
+ }
function image_build($job)
{
- global $configurationsPath, $gentoasterPath, $buildToolName, $progressMagic;
+ $progressMagic = 23;
$handle = $job->handle();
$handlehash = md5($handle);
@@ -58,17 +52,17 @@
$configurationString = $job->workload();
$configurationArray = parse_ini_string($configurationString);
- if ($configurationArray !== FALSE) {
+ if ($configurationArray !== false) {
if (isset($configurationArray["BUILD_ID"])) {
$buildID = $configurationArray["BUILD_ID"];
- $buildPath = $configurationsPath."/".$buildID;
+ $buildPath = CONFIGURATIONS_PATH."/".$buildID;
@mkdir($buildPath, 0777, true);
if (is_writable($buildPath)) {
chdir($buildPath);
file_put_contents("config.ini", $configurationString);
$toolArgs = "--config config.ini --compress";
- $cmd = $gentoasterPath."/".$buildToolName." ".$toolArgs;
+ $cmd = GENTOASTER_PATH."/".BUILD_TOOL_NAME." ".$toolArgs;
$processHandle = popen($cmd." 2>&1", "r");
$nonstatusOutput = "";
@@ -104,83 +98,83 @@
function start_image($job)
{
- global $configurationsPath, $gentoasterPath, $wrapToolName;
- global $externalHost, $lowPort, $highPort;
-
$buildID = $job->workload();
$running = false;
$insert = false;
$update = false;
- $db = mysql_connect("localhost", "gentoaster", "");
- if(!$db) die("Could not connect to database ".mysql_error());
- mysql_select_db("gentoaster");
+ $db = mysql_connect(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD);
+ if (!$db) {
+ die("Could not connect to database ".mysql_error());
+ }
+ mysql_select_db(MYSQL_DATABASE);
$query = "SELECT port FROM ports ORDER BY port DESC LIMIT 1";
$result = mysql_query($query);
- if(mysql_num_rows($result) == 0) {
- // no ports! assign a new one
- $port = $lowPort;
- $insert = true;
- echo "No ports! Assigning ".$port."\n";
+ if (mysql_num_rows($result) == 0) {
+ // no ports! assign a new one
+ $port = LOW_PORT;
+ $insert = true;
+ echo "No ports! Assigning ".$port."\n";
} else {
- // we have a port! let's check if our vm has one
- $ports = mysql_fetch_array($result);
- $lastport = $ports[0];
- $query = "SELECT port, pid FROM ports WHERE id = '".$buildID."'";
- $result = mysql_query($query);
- if (mysql_num_rows($result) == 0) {
- // vm doesn't have one, assign one!
- $port = $lastport+1;
- if ($port > $highPort) {
- $port = $lowPort;
- }
- $insert = true;
- echo "Assigning new port ".$port."\n";
- } else {
- // vm already has one, return it
- $ports = mysql_fetch_array($result);
- $port = $ports[0];
- $pid = $ports[1];
- $running = true;
- if(!check_pid($pid)) {
- $running = false;
- $update = true;
- echo "VM is not running, PID ".$pid." is dead!\n";
- } else {
- echo "VM is running on PID ".$pid."\n";
- }
- echo "VM already has port ".$port."\n";
- }
+ // we have a port! let's check if our vm has one
+ $ports = mysql_fetch_array($result);
+ $lastport = $ports[0];
+ $query = "SELECT port, pid FROM ports WHERE id = '".$buildID."'";
+ $result = mysql_query($query);
+ if (mysql_num_rows($result) == 0) {
+ // vm doesn't have one, assign one!
+ $port = $lastport+1;
+ if ($port > HIGH_PORT) {
+ $port = LOW_PORT;
+ }
+ $insert = true;
+ echo "Assigning new port ".$port."\n";
+ } else {
+ // vm already has one, return it
+ $ports = mysql_fetch_array($result);
+ $port = $ports[0];
+ $pid = $ports[1];
+ $running = true;
+ if (!check_pid($pid)) {
+ $running = false;
+ $update = true;
+ echo "VM is not running, PID ".$pid." is dead!\n";
+ } else {
+ echo "VM is running on PID ".$pid."\n";
+ }
+ echo "VM already has port ".$port."\n";
+ }
}
if (!$running || $update) {
- $cmd = $gentoasterPath."/".$wrapToolName." ".
- $configurationsPath."/".$buildID."/".$buildID.".image ".
- $port." &";
- $handle = proc_open($cmd, array(), $foo);
- $status = proc_get_status($handle);
- $pid = $status["pid"];
- echo "New process spawned with PID ".$pid."\n";
- proc_close($handle);
+ $cmd = GENTOASTER_PATH."/".WRAP_TOOL_NAME." ".
+ CONFIGURATIONS_PATH."/".$buildID."/".$buildID.".image ".
+ $port." &";
+ $handle = proc_open($cmd, array(), $foo);
+ $status = proc_get_status($handle);
+ $pid = $status["pid"];
+ echo "New process spawned with PID ".$pid."\n";
+ proc_close($handle);
}
// qemu pid is two up
+ // hacky? works for now though
$pid = $pid + 2;
if ($insert) {
- $query = "DELETE FROM ports WHERE port = ".$port;
- $result = mysql_query($query);
- $query = "INSERT INTO ports (id, port, pid) VALUES('".mysql_real_escape_string($buildID)."', ".$port.", ".$pid.")";
- $result = mysql_query($query);
- echo "Doing insert!\n";
- } elseif($update) {
- $query = "UPDATE ports SET pid = ".$pid." WHERE id = '".$buildID."'";
- $result = mysql_query($query);
- echo "Doing update\n";
+ $query = "DELETE FROM ports WHERE port = ".$port;
+ $result = mysql_query($query);
+ $query = "INSERT INTO ports (id, port, pid) VALUES('".mysql_real_escape_string($buildID)."', ".$port.", ".$pid.")";
+ $result = mysql_query($query);
+ echo "Doing insert!\n";
+ } elseif ($update) {
+ $query = "UPDATE ports SET pid = ".$pid." WHERE id = '".$buildID."'";
+ $result = mysql_query($query);
+ echo "Doing update\n";
}
$port = $port+1000;
- return serialize(array($externalHost, $port));
+ return serialize(array(EXTERNAL_HOST, $port));
}
diff --git a/status.php b/status.php
index a69bc35..48f4dff 100644
--- a/status.php
+++ b/status.php
@@ -1,8 +1,18 @@
<?php
- if (!isset($argv[1])) die("No handle hash given\n");
- $db = mysql_connect("localhost", "gentoaster", "");
- if (!$db) die("Could not connect to database ".mysql_error()."\n");
- mysql_select_db("gentoaster");
+
+ // Gentoaster build daemon status
+ // Licensed under GPL v3, see COPYING file
+
+ require_once "config.php";
+
+ if (!isset($argv[1])) {
+ die("No handle hash given\n");
+ }
+ $db = mysql_connect(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD);
+ if (!$db) {
+ die("Could not connect to database ".mysql_error()."\n");
+ }
+ mysql_select_db(MYSQL_DATABASE);
$query = "SELECT handle FROM builds ".
"WHERE id = '".mysql_real_escape_string($argv[1])."'";
$result = mysql_query($query);
@@ -26,7 +36,7 @@
"WHERE id = '".mysql_real_escape_string($argv[1])."'";
$result = mysql_query($query);
$jobres = mysql_fetch_array($result);
- if ($jobres[0] !== NULL) {
+ if ($jobres[0] !== null) {
echo "Job returned with code ".$jobres[0].": ".$jobres[1]."\n";
} else {
echo "Job failed\n";
diff --git a/web/config.php b/web/config.php
index 7e0058a..6d5735c 100644
--- a/web/config.php
+++ b/web/config.php
@@ -3,9 +3,19 @@
// Gentoaster web interface settings
// Licensed under GPL v3, see COPYING file
+ // Path to the zonetab file
define("ZONETAB", "/usr/share/zoneinfo/zone.tab");
+ // What should we limit the virtual machine disk size to?
+ define("MAX_DISK_SIZE", 16384);
+
+ // Set the MySQL access details that should be used
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 RECAPTCHA keys that should be used, if enabled
+ define("RECAPTCHA_ENABLED", true);
+ define("RECAPTCHA_PUBLIC_KEY","REPLACE_ME");
+ define("RECAPTCHA_PRIVATE_KEY", "REPLACE_ME"); \ No newline at end of file
diff --git a/web/index.php b/web/index.php
index 1fd4d7d..43be192 100644
--- a/web/index.php
+++ b/web/index.php
@@ -1,15 +1,23 @@
<?php
- define("ZONETAB", "/usr/share/zoneinfo/zone.tab");
+ require_once "config.php";
+
+ if (RECAPTCHA_ENABLED) {
+ require_once "recaptcha.php";
+ }
$timezones = array();
$zonetab = file(ZONETAB);
foreach ($zonetab as $buf) {
- if (substr($buf, 0, 1)=='#') continue;
+ 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];
+ for ($i=3;$i<$c;$i++) {
+ $val.= ' '.$rec[$i];
+ }
$timezones[$key] = $val;
ksort($timezones);
}
@@ -41,6 +49,20 @@
<p>This wizard will guide you through the creation of your own personalised
Gentoo virtual machine image.</p>
</div>
+ <?php
+ if (RECAPTCHA_ENABLED) {
+ ?>
+ <div id="human" class="step">
+ <h1>Verification</h1>
+
+ <?php
+ echo recaptcha_get_html(RECAPTCHA_PUBLIC_KEY);
+ ?>
+ <br>
+ </div>
+ <?php
+ }
+ ?>
<div id="locale" class="step">
<h1>Locale</h1>
diff --git a/web/process.php b/web/process.php
index 93c5d68..43827b9 100644
--- a/web/process.php
+++ b/web/process.php
@@ -1,5 +1,23 @@
<?php
+ // Gentoaster web interface config processor
+ // Licensed under GPL v3, see COPYING file
+
+ require_once "config.php";
+
+ if (RECAPTCHA_ENABLED) {
+ require_once "recaptcha.php";
+
+ $resp = recaptcha_check_answer(RECAPTCHA_PRIVATE_KEY,
+ $_SERVER["REMOTE_ADDR"],
+ $_POST["recaptcha_challenge_field"],
+ $_POST["recaptcha_response_field"]);
+
+ if (!$resp->is_valid) {
+ die("CAPTCHA was incorrect");
+ }
+ }
+
$buildID = uniqid();
$bootMegabytes = intval($_POST["boot_size"]);
$swapMegabytes = intval($_POST["swap_size"]);
@@ -37,9 +55,11 @@ OUTPUT_FORMAT=$outputFormat";
$client->addServer();
$handle = $client->doBackground("invoke_image_build", $iniString);
- $db = mysql_connect("localhost", "gentoaster", "");
- if(!$db) die("Could not connect to database ".mysql_error());
- mysql_select_db("gentoaster");
+ $db = mysql_connect(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD);
+ if (!$db) {
+ die("Could not connect to database ".mysql_error());
+ }
+ mysql_select_db(MYSQL_DATABASE);
$query = "INSERT INTO builds (id, handle) ".
"VALUES('".$buildID."','".$handle."')";
mysql_query($query);
diff --git a/web/recaptcha.php b/web/recaptcha.php
new file mode 100644
index 0000000..32c4f4d
--- /dev/null
+++ b/web/recaptcha.php
@@ -0,0 +1,277 @@
+<?php
+/*
+ * This is a PHP library that handles calling reCAPTCHA.
+ * - Documentation and latest version
+ * http://recaptcha.net/plugins/php/
+ * - Get a reCAPTCHA API Key
+ * https://www.google.com/recaptcha/admin/create
+ * - Discussion group
+ * http://groups.google.com/group/recaptcha
+ *
+ * Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
+ * AUTHORS:
+ * Mike Crawford
+ * Ben Maurer
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+/**
+ * The reCAPTCHA server URL's
+ */
+define("RECAPTCHA_API_SERVER", "http://www.google.com/recaptcha/api");
+define("RECAPTCHA_API_SECURE_SERVER", "https://www.google.com/recaptcha/api");
+define("RECAPTCHA_VERIFY_SERVER", "www.google.com");
+
+/**
+ * Encodes the given data into a query string format
+ * @param $data - array of string elements to be encoded
+ * @return string - encoded request
+ */
+function _recaptcha_qsencode ($data) {
+ $req = "";
+ foreach ( $data as $key => $value )
+ $req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
+
+ // Cut the last '&'
+ $req=substr($req,0,strlen($req)-1);
+ return $req;
+}
+
+
+
+/**
+ * Submits an HTTP POST to a reCAPTCHA server
+ * @param string $host
+ * @param string $path
+ * @param array $data
+ * @param int port
+ * @return array response
+ */
+function _recaptcha_http_post($host, $path, $data, $port = 80) {
+
+ $req = _recaptcha_qsencode ($data);
+
+ $http_request = "POST $path HTTP/1.0\r\n";
+ $http_request .= "Host: $host\r\n";
+ $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
+ $http_request .= "Content-Length: " . strlen($req) . "\r\n";
+ $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
+ $http_request .= "\r\n";
+ $http_request .= $req;
+
+ $response = '';
+ if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
+ die ('Could not open socket');
+ }
+
+ fwrite($fs, $http_request);
+
+ while ( !feof($fs) )
+ $response .= fgets($fs, 1160); // One TCP-IP packet
+ fclose($fs);
+ $response = explode("\r\n\r\n", $response, 2);
+
+ return $response;
+}
+
+
+
+/**
+ * Gets the challenge HTML (javascript and non-javascript version).
+ * This is called from the browser, and the resulting reCAPTCHA HTML widget
+ * is embedded within the HTML form it was called from.
+ * @param string $pubkey A public key for reCAPTCHA
+ * @param string $error The error given by reCAPTCHA (optional, default is null)
+ * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false)
+
+ * @return string - The HTML to be embedded in the user's form.
+ */
+function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
+{
+ if ($pubkey == null || $pubkey == '') {
+ die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
+ }
+
+ if ($use_ssl) {
+ $server = RECAPTCHA_API_SECURE_SERVER;
+ } else {
+ $server = RECAPTCHA_API_SERVER;
+ }
+
+ $errorpart = "";
+ if ($error) {
+ $errorpart = "&amp;error=" . $error;
+ }
+ return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script>
+
+ <noscript>
+ <iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/>
+ <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
+ <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
+ </noscript>';
+}
+
+
+
+
+/**
+ * A ReCaptchaResponse is returned from recaptcha_check_answer()
+ */
+class ReCaptchaResponse {
+ var $is_valid;
+ var $error;
+}
+
+
+/**
+ * Calls an HTTP POST function to verify if the user's guess was correct
+ * @param string $privkey
+ * @param string $remoteip
+ * @param string $challenge
+ * @param string $response
+ * @param array $extra_params an array of extra variables to post to the server
+ * @return ReCaptchaResponse
+ */
+function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
+{
+ if ($privkey == null || $privkey == '') {
+ die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
+ }
+
+ if ($remoteip == null || $remoteip == '') {
+ die ("For security reasons, you must pass the remote ip to reCAPTCHA");
+ }
+
+
+
+ //discard spam submissions
+ if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
+ $recaptcha_response = new ReCaptchaResponse();
+ $recaptcha_response->is_valid = false;
+ $recaptcha_response->error = 'incorrect-captcha-sol';
+ return $recaptcha_response;
+ }
+
+ $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
+ array (
+ 'privatekey' => $privkey,
+ 'remoteip' => $remoteip,
+ 'challenge' => $challenge,
+ 'response' => $response
+ ) + $extra_params
+ );
+
+ $answers = explode ("\n", $response [1]);
+ $recaptcha_response = new ReCaptchaResponse();
+
+ if (trim ($answers [0]) == 'true') {
+ $recaptcha_response->is_valid = true;
+ }
+ else {
+ $recaptcha_response->is_valid = false;
+ $recaptcha_response->error = $answers [1];
+ }
+ return $recaptcha_response;
+
+}
+
+/**
+ * gets a URL where the user can sign up for reCAPTCHA. If your application
+ * has a configuration page where you enter a key, you should provide a link
+ * using this function.
+ * @param string $domain The domain where the page is hosted
+ * @param string $appname The name of your application
+ */
+function recaptcha_get_signup_url ($domain = null, $appname = null) {
+ return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname));
+}
+
+function _recaptcha_aes_pad($val) {
+ $block_size = 16;
+ $numpad = $block_size - (strlen ($val) % $block_size);
+ return str_pad($val, strlen ($val) + $numpad, chr($numpad));
+}
+
+/* Mailhide related code */
+
+function _recaptcha_aes_encrypt($val,$ky) {
+ if (! function_exists ("mcrypt_encrypt")) {
+ die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
+ }
+ $mode=MCRYPT_MODE_CBC;
+ $enc=MCRYPT_RIJNDAEL_128;
+ $val=_recaptcha_aes_pad($val);
+ return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
+}
+
+
+function _recaptcha_mailhide_urlbase64 ($x) {
+ return strtr(base64_encode ($x), '+/', '-_');
+}
+
+/* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
+function recaptcha_mailhide_url($pubkey, $privkey, $email) {
+ if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) {
+ die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " .
+ "you can do so at <a href='http://www.google.com/recaptcha/mailhide/apikey'>http://www.google.com/recaptcha/mailhide/apikey</a>");
+ }
+
+
+ $ky = pack('H*', $privkey);
+ $cryptmail = _recaptcha_aes_encrypt ($email, $ky);
+
+ return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
+}
+
+/**
+ * gets the parts of the email to expose to the user.
+ * eg, given johndoe@example,com return ["john", "example.com"].
+ * the email is then displayed as john...@example.com
+ */
+function _recaptcha_mailhide_email_parts ($email) {
+ $arr = preg_split("/@/", $email );
+
+ if (strlen ($arr[0]) <= 4) {
+ $arr[0] = substr ($arr[0], 0, 1);
+ } else if (strlen ($arr[0]) <= 6) {
+ $arr[0] = substr ($arr[0], 0, 3);
+ } else {
+ $arr[0] = substr ($arr[0], 0, 4);
+ }
+ return $arr;
+}
+
+/**
+ * Gets html to display an email address given a public an private key.
+ * to get a key, go to:
+ *
+ * http://www.google.com/recaptcha/mailhide/apikey
+ */
+function recaptcha_mailhide_html($pubkey, $privkey, $email) {
+ $emailparts = _recaptcha_mailhide_email_parts ($email);
+ $url = recaptcha_mailhide_url ($pubkey, $privkey, $email);
+
+ return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) .
+ "' onclick=\"window.open('" . htmlentities ($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities ($emailparts [1]);
+
+}
+
+
+?>
diff --git a/web/status.php b/web/status.php
index 20aacec..86e7e0e 100644
--- a/web/status.php
+++ b/web/status.php
@@ -1,13 +1,20 @@
<?php
+ // Gentoaster web interface finished stage
+ // Licensed under GPL v3, see COPYING file
+
+ require_once "config.php";
+
$buildID = $_GET["uuid"];
$buildresult = "Unknown!";
$inprogress = false;
$builddone = false;
- $db = mysql_connect("localhost", "gentoaster", "");
- if (!$db) die("Could not connect to database ".mysql_error()."\n");
- mysql_select_db("gentoaster");
+ $db = mysql_connect(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD);
+ if (!$db) {
+ die("Could not connect to database ".mysql_error()."\n");
+ }
+ mysql_select_db(MYSQL_DATABASE);
$query = "SELECT handle FROM builds ".
"WHERE id = '".mysql_real_escape_string($buildID)."'";
$result = mysql_query($query);
@@ -33,7 +40,7 @@
"WHERE id = '".$cleanBuildID."'";
$result = mysql_query($query);
$jobres = mysql_fetch_array($result);
- if ($jobres[0] !== NULL) {
+ if ($jobres[0] !== null) {
if ($jobres[0] == 0) {
$buildresult = "Your build is complete! ".
"What would you like to do now?".
diff --git a/web/testdrive.php b/web/testdrive.php
index a313f39..066dd4c 100644
--- a/web/testdrive.php
+++ b/web/testdrive.php
@@ -1,12 +1,19 @@
<?php
+ // Gentoaster web interface testdrive
+ // Licensed under GPL v3, see COPYING file
+
+ require_once "config.php";
+
$buildID = $_GET["uuid"];
$buildresult = "Unknown!";
$inprogress = false;
- $db = mysql_connect("localhost", "gentoaster", "");
- if (!$db) die("Could not connect to database ".mysql_error()."\n");
- mysql_select_db("gentoaster");
+ $db = mysql_connect(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD);
+ if (!$db) {
+ die("Could not connect to database ".mysql_error()."\n");
+ }
+ mysql_select_db(MYSQL_DATABASE);
$result = mysql_query("SELECT handle FROM builds WHERE id = '".mysql_real_escape_string($buildID)."'");
if (mysql_num_rows($result) == 1) {
$handles = mysql_fetch_array($result);
@@ -22,7 +29,7 @@
$query = "SELECT returncode, result FROM builds WHERE id = '".$cleanBuildID."'";
$result = mysql_query();
$jobres = mysql_fetch_array($result);
- if ($jobres[0] !== NULL) {
+ if ($jobres[0] !== null) {
if ($jobres[0] == 0) {
// we're built, let's do this
$client = new GearmanClient();