public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/gentoaster:webui commit in: web/js/, /, web/
  2011-08-12 23:17 [gentoo-commits] proj/gentoaster:master commit in: /, web/, web/js/ Liam McLoughlin
@ 2011-07-24  2:43 ` Liam McLoughlin
  0 siblings, 0 replies; 3+ messages in thread
From: Liam McLoughlin @ 2011-07-24  2:43 UTC (permalink / raw
  To: gentoo-commits

commit:     603e8f6106dc66596b29131ac2e2b804d0e35934
Author:     Liam McLoughlin <hexxeh <AT> hexxeh <DOT> net>
AuthorDate: Sun Jul 24 00:58:03 2011 +0000
Commit:     Liam McLoughlin <hexxeh <AT> hexxeh <DOT> net>
CommitDate: Sun Jul 24 00:58:03 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoaster.git;a=commit;h=603e8f61

Changed code to be closer to Zend standard

---
 daemon.php           |    4 +-
 web/index.php        |   10 +-
 web/js/gentoaster.js |  102 ++++++++++++++++++++
 web/process.php      |   61 ++++++------
 web/status.php       |  135 +++++++++++++++-----------
 web/testdrive.php    |  256 +++++++++++++++++++++++++-------------------------
 6 files changed, 347 insertions(+), 221 deletions(-)

diff --git a/daemon.php b/daemon.php
index a25861e..6570185 100644
--- a/daemon.php
+++ b/daemon.php
@@ -3,11 +3,11 @@
     // Gentoaster build daemon worker
     // Licensed under GPL v3, see COPYING file
 
-    $configurationsPath = "/var/www/gentoaster";
+    $configurationsPath = "/var/www/gentoaster/images";
     $gentoasterPath = "/usr/share/gentoaster";
     $buildToolName = "create_image.sh";
     $wrapToolName = "wrap.sh";
-    $externalHost = "192.168.2.167";
+    $externalHost = "192.168.2.169";
     $lowPort = 5900;
     $highPort = 5999;
 

diff --git a/web/index.php b/web/index.php
index 181d07b..1fd4d7d 100644
--- a/web/index.php
+++ b/web/index.php
@@ -3,10 +3,9 @@
 
     $timezones = array();
     $zonetab = file(ZONETAB);
-    foreach ($zonetab as $buf)
-    {
-        if (substr($buf,0,1)=='#') continue;
-        $rec = preg_split('/\s+/',$buf);
+    foreach ($zonetab as $buf) {
+        if (substr($buf, 0, 1)=='#') continue;
+        $rec = preg_split('/\s+/', $buf);
         $key = $rec[2];
         $val = $rec[2];
         $c = count($rec);
@@ -15,8 +14,7 @@
         ksort($timezones);
     }
     $timezoneOption = "";
-    foreach ($timezones as $timezone => $description)
-    {
+    foreach ($timezones as $timezone => $description) {
         $timezoneOption .= "<option>".$timezone."</option>\n";
     }
 ?>

diff --git a/web/js/gentoaster.js b/web/js/gentoaster.js
new file mode 100644
index 0000000..99cd514
--- /dev/null
+++ b/web/js/gentoaster.js
@@ -0,0 +1,102 @@
+$(function(){
+	$("#wizard").formwizard({ 
+		validationEnabled: true,
+		focusFirstInput: true,
+		disableUIStyles: true,
+		//historyEnabled: true,
+		validationOptions: {
+			rules: {
+				username: {
+					minlength: 2
+				},
+				password: {
+					minlength: 5
+				},
+				confirmpassword: {
+					minlength: 5,
+					equalTo: "#user_password"
+				},
+				boot_size: {
+					min: 32
+				},
+				swap_size: {
+					min: 16
+				},
+				root_size: {
+					min: 3072
+				},
+				size: {
+					min: 4020
+				}
+			},
+			messages: {
+				username: {
+					minlength: "Your username must consist of at least 2 characters"
+				},
+				password: {
+					minlength: "Your password must be at least 5 characters long"
+				},
+				confirmpassword: {
+					minlength: "Your password must be at least 5 characters long",
+					equalTo: "Please enter the same password in both boxes"
+				},
+				boot_size: {
+					min: "Your boot partition must be at least 32MB"
+				},
+				swap_size: {
+					min: "Your swap partition must be at least 128MB"
+				},
+				root_size: {
+					min: "Your root partition must be at least 3072MB"
+				},
+				size: {
+					min: "Your disk image must be at least 4020MB"
+				}
+			}
+		}
+	});
+	
+	function partitioning_update(event, ui) {
+			if(!ui.values) {
+				ui.values = ui;
+			}
+	        $('.partitionrange').css('width', $('.ui-slider-range').css('left'));
+	        var boot_size = ui.values[0];
+	        var swap_size = ui.values[1]-ui.values[0];
+	        var root_size = $("#partitioning_split").slider( "option", "max" )-ui.values[1];
+	        var image_size = boot_size+swap_size+root_size;
+	        $("#partitioning_display").html("Disk image size: "+image_size+"MB<br>Boot partition size: "+boot_size+"MB<br>Swap partition size: "+swap_size+"MB<br>Root partition size: "+root_size+"MB");
+	        $("#partitioning_boot").attr("value", boot_size);
+	        $("#partitioning_swap").attr("value", swap_size);
+	        $("#partitioning_root").attr("value", root_size);
+	        
+	        //since it doesn't seem to redraw by itself, hacky fix!
+	        $("#partitioning_split").slider("option", "values", $("#partitioning_split").slider("option", "values"));	
+	}
+	
+	$("#partitioning_split").slider({
+	    range: true,
+	    min: 0,
+	    max: 4096,
+	    values: [128, 640],
+	    slide: partitioning_update,
+	    change: partitioning_update,
+	    create: function(event, ui) {
+	        var slider = $(event.target);
+	        var range = slider.find('.ui-slider-range');
+	        var newrange = $('<div />');
+	        newrange.appendTo(slider).addClass('ui-slider-range partitionrange').css('width', range.css('left'));
+	    }
+	});
+	
+	function update_slider() {
+		var new_size = $("#partitioning_size").val();
+		$("#partitioning_split").slider("option", "max", new_size);
+		partitioning_update(null, $("#partitioning_split").slider("option", "values"));
+	}
+
+	
+	$("#partitioning_size").change(update_slider);
+	
+	partitioning_update(null, $("#partitioning_split").slider("option", "values"));
+});
\ No newline at end of file

diff --git a/web/process.php b/web/process.php
index 1b68d03..93c5d68 100644
--- a/web/process.php
+++ b/web/process.php
@@ -1,46 +1,47 @@
 <?php
 
-	$build_id = uniqid();
-	$boot_megabytes = intval($_POST["boot_size"]);
-	$swap_megabytes = intval($_POST["swap_size"]);
-	$root_megabytes = intval($_POST["root_size"]);
-	$timezone = escapeshellarg($_POST["timezone"]);
-	$hostname = escapeshellarg($_POST["hostname"]);
-	$username =  escapeshellarg($_POST["username"]);
-	$password = escapeshellarg($_POST["password"]);
-	$root_password = escapeshellarg($_POST["rootpassword"]);
-	$packages_list = escapeshellarg($_POST["packages"]);
-	$output_format = escapeshellarg($_POST["format"]);
+    $buildID = uniqid();
+    $bootMegabytes = intval($_POST["boot_size"]);
+    $swapMegabytes = intval($_POST["swap_size"]);
+    $rootMegabytes = intval($_POST["root_size"]);
+    $timezone = escapeshellarg($_POST["timezone"]);
+    $hostname = escapeshellarg($_POST["hostname"]);
+    $username =  escapeshellarg($_POST["username"]);
+    $password = escapeshellarg($_POST["password"]);
+    $rootPassword = escapeshellarg($_POST["rootpassword"]);
+    $packagesList = escapeshellarg($_POST["packages"]);
+    $outputFormat = escapeshellarg($_POST["format"]);
 
-	$packages_list = str_replace("\r\n", " ", $packages_list);
-	$packages_list = str_replace("\n", " ", $packages_list);
+    $packagesList = str_replace("\r\n", " ", $packagesList);
+    $packagesList = str_replace("\n", " ", $packagesList);
 
-$ini_string = "[vmconfig]
+$iniString = "[vmconfig]
 
-BUILD_ID='$build_id'
-BOOT_MEGABYTES='$boot_megabytes'
-SWAP_MEGABYTES='$swap_megabytes'
-ROOT_MEGABYTES='$root_megabytes'
+BUILD_ID='$buildID'
+BOOT_MEGABYTES='$bootMegabytes'
+SWAP_MEGABYTES='$swapMegabytes'
+ROOT_MEGABYTES='$rootMegabytes'
 TIMEZONE=$timezone
 HOSTNAME=$hostname
-ROOT_PASSWORD=$root_password
+ROOT_PASSWORD=$rootPassword
 DEFAULT_USERNAME=$username
 DEFAULT_PASSWORD=$password
 USE_FLAGS=''
 PACKAGE_USE=''
 FEATURES='parallel-fetch userfetch userpriv getbinpkg'
 PACKAGE_ACCEPT_KEYWORDS=''
-PACKAGES_LIST=$packages_list
-OUTPUT_FORMAT=$output_format";
+PACKAGES_LIST=$packagesList
+OUTPUT_FORMAT=$outputFormat";
 
-	$client = new GearmanClient();
-	$client->addServer();
-	$handle = $client->doBackground("invoke_image_build", $ini_string);
+    $client = new GearmanClient();
+    $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");
-	mysql_query("INSERT INTO builds (id, handle) VALUES('".$build_id."','".$handle."')");
+    $db = mysql_connect("localhost", "gentoaster", "");
+    if(!$db) die("Could not connect to database ".mysql_error());
+    mysql_select_db("gentoaster");
+    $query = "INSERT INTO builds (id, handle) ".
+             "VALUES('".$buildID."','".$handle."')";
+    mysql_query($query);
 
-	header("Location: finished.php?uuid=".$build_id);
-?>
+    header("Location: finished.php?uuid=".$buildID);
\ No newline at end of file

diff --git a/web/status.php b/web/status.php
index 7371c16..20aacec 100644
--- a/web/status.php
+++ b/web/status.php
@@ -1,38 +1,55 @@
 <?php
 
-	$build_id = $_GET["uuid"];
-	$buildresult = "Unknown!";
-	$inprogress = false;
-	$builddone = false;
+    $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");
+    $db = mysql_connect("localhost", "gentoaster", "");
+    if (!$db) die("Could not connect to database ".mysql_error()."\n");
     mysql_select_db("gentoaster");
-    $result = mysql_query("SELECT handle FROM builds WHERE id = '".mysql_real_escape_string($build_id)."'");
-    if(mysql_num_rows($result) == 1) {
+    $query = "SELECT handle FROM builds ".
+             "WHERE id = '".mysql_real_escape_string($buildID)."'";
+    $result = mysql_query($query);
+    if (mysql_num_rows($result) == 1) {
             $handles = mysql_fetch_array($result);
             $handle = $handles[0];
             $client = new GearmanClient();
             $client->addServer();
 
             $status = $client->jobStatus($handle);
-            if($status[0]) {
-                    if($status[3] != 0) {
+            if ($status[0]) {
+                    if ($status[3] != 0) {
                             $percentage = ceil($status[2]/$status[3]*100);
-                            $buildresult = "Your build is currently running and is ".$percentage."% complete";
+                            $buildresult = "Your build is currently running".
+                                           " and is ".$percentage."% complete";
                             $inprogress = true;
                     } else {
                             $buildresult = "Task has not yet been processed";
                     }
             } else {
-                    $result = mysql_query("SELECT returncode, result FROM builds WHERE id = '".mysql_real_escape_string($build_id)."'");
+                    $cleanBuildID = mysql_real_escape_string($buildID);
+                    $query = "SELECT returncode, result FROM builds ".
+                             "WHERE id = '".$cleanBuildID."'";
+                    $result = mysql_query($query);
                     $jobres = mysql_fetch_array($result);
-                    if($jobres[0] !== NULL) {
-                    		if($jobres[0] == 0) {
-                        		$buildresult = "Your build is complete! What would you like to do now?<br /><br /><center><table><tr><td><a href=\"/gentoaster/".$build_id."/".$build_id.".tar.gz\"><img style=\"padding: 10px;\" src=\"img/icons/download.png\"></a></td><td><a href=\"testdrive.php?uuid=".$build_id."\"><img style=\"padding: 10px;\" src=\"img/icons/testdrive.png\"></a></td></tr><tr><td>Download</td><td>Testdrive</td></tr></table></center>";
-                        		$builddone = true;
+                    if ($jobres[0] !== NULL) {
+                            if ($jobres[0] == 0) {
+                                $buildresult = "Your build is complete! ".
+                                               "What would you like to do now?".
+                                               "<br /><br /><center>".
+                                               "<table><tr><td>".
+                                               "<a href=\"/gentoaster/".$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 {
-                        	    $buildresult = "Job returned with code ".$jobres[0].": ".$jobres[1];
+                                $buildresult = "Job returned with code ".$jobres[0].": ".$jobres[1];
                             }
                     } else {
                             $buildresult = "Job failed";
@@ -44,44 +61,50 @@
 
 ?>
 <html>
-	<head>
-		<title>Gentoaster</title>
-		<link rel="stylesheet" type="text/css" href="css/style.css">
-		<link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.14.custom.css">
-		<script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script>		
-		<script type="text/javascript" src="/js/jquery-ui-1.8.14.custom.min.js"></script>
-		<?php
-			if($inprogress) {
-				echo '<script>
-				  $(document).ready(function() {
-				    $("#progressbar").progressbar({ value: '.$percentage.' });
-				  });
-				</script>';
-			}
-		?>
-	</head>
-	<body>
-		<div id="container">
-			<div id="header"></div>
-			<div id="content">
-				<div id="main">
-					<div id="status" class="step">
-						<?php if(!$builddone) { ?>
-							<h1>How's things?</h1>
-						<?php } else { ?>
-							<h1>It's showtime!</h1>
-						<?php } ?>
-						<p>
-							<?php echo $buildresult; ?>
-							<div id="progressbar"></div>
-						</p>
-					</div>
-				</div>
-				<div id="navigation">
+    <head>
+        <title>Gentoaster</title>
+        <link rel="stylesheet" type="text/css" href="css/style.css">
+        <link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.14.custom.css">
+        <script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script>        
+        <script type="text/javascript" src="/js/jquery-ui-1.8.14.custom.min.js"></script>
+        <?php
+            if ($inprogress) {
+                echo '<script>
+                  $(document).ready(function() {
+                    $("#progressbar").progressbar({ value: '.$percentage.' });
+                  });
+                </script>';
+            }
+        ?>
+    </head>
+    <body>
+        <div id="container">
+            <div id="header"></div>
+            <div id="content">
+                <div id="main">
+                    <div id="status" class="step">
+                        <?php
+                            if (!$builddone) {
+                        ?>
+                            <h1>How's things?</h1>
+                        <?php
+                            } else {
+                        ?>
+                            <h1>It's showtime!</h1>
+                        <?php
+                            }
+                        ?>
+                        <p>
+                            <?php echo $buildresult; ?>
+                            <div id="progressbar"></div>
+                        </p>
+                    </div>
+                </div>
+                <div id="navigation">
 
-				</div>
-			</div>
-		</div>
-		</script>
-	</body>
+                </div>
+            </div>
+        </div>
+        </script>
+    </body>
 </html>
\ No newline at end of file

diff --git a/web/testdrive.php b/web/testdrive.php
index b6e65b8..a313f39 100644
--- a/web/testdrive.php
+++ b/web/testdrive.php
@@ -1,37 +1,39 @@
 <?php
 
-	$build_id = $_GET["uuid"];
-	$buildresult = "Unknown!";
-	$inprogress = false;
+    $buildID = $_GET["uuid"];
+    $buildresult = "Unknown!";
+    $inprogress = false;
 
-    $db = mysql_connect("localhost","gentoaster","");
-    if(!$db) die("Could not connect to database ".mysql_error()."\n");
+    $db = mysql_connect("localhost", "gentoaster", "");
+    if (!$db) die("Could not connect to database ".mysql_error()."\n");
     mysql_select_db("gentoaster");
-    $result = mysql_query("SELECT handle FROM builds WHERE id = '".mysql_real_escape_string($build_id)."'");
-    if(mysql_num_rows($result) == 1) {
+    $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);
             $handle = $handles[0];
             $client = new GearmanClient();
             $client->addServer();
 
             $status = $client->jobStatus($handle);
-            if($status[0]) {
-                    header("Location: status.php?uuid=".$build_id);
+            if ($status[0]) {
+                    header("Location: status.php?uuid=".$buildID);
             } else {
-                    $result = mysql_query("SELECT returncode, result FROM builds WHERE id = '".mysql_real_escape_string($build_id)."'");
+                    $cleanBuildID = mysql_real_escape_string($buildID);
+                    $query = "SELECT returncode, result FROM builds WHERE id = '".$cleanBuildID."'";
+                    $result = mysql_query();
                     $jobres = mysql_fetch_array($result);
-                    if($jobres[0] !== NULL) {
-                    		if($jobres[0] == 0) {
-                        		// we're built, let's do this
-								$client = new GearmanClient();
-								$client->addServer();
-								$server = $client->do("invoke_start_image", $build_id);
-								$server = unserialize($server);
+                    if ($jobres[0] !== NULL) {
+                            if ($jobres[0] == 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=".$build_id);
+                                header("Location: status.php?uuid=".$buildID);
                             }
                     } else {
-                           	header("Location: status.php?uuid=".$build_id);
+                               header("Location: status.php?uuid=".$buildID);
                     }
             }
     } else {
@@ -40,114 +42,114 @@
 
 ?>
 <html>
-	<head>
-		<title>Gentoaster</title>
-		<link rel="stylesheet" type="text/css" href="css/style.css">
-		<link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.14.custom.css">
-		<script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script>		
-		<script type="text/javascript" src="/js/jquery-ui-1.8.14.custom.min.js"></script>
+    <head>
+        <title>Gentoaster</title>
+        <link rel="stylesheet" type="text/css" href="css/style.css">
+        <link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.14.custom.css">
+        <script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script>        
+        <script type="text/javascript" src="/js/jquery-ui-1.8.14.custom.min.js"></script>
         <script type="text/javascript" src="include/vnc.js"></script>
-	</head>
-	<body>
-		<div id="container">
-			<div id="header"></div>
-			<div id="content">
-				<div id="main">
-					<div id="status" class="step">
-						<h1>Let's fire her up!</h1>
-							<center>
-					        <div id="VNC_screen">
-					            <div id="VNC_status_bar" class="VNC_status_bar" style="margin-top: -25px;">
-					                <table border=0 width="100%"><tr>
-					                    <td><div id="VNC_status" style="display: none;">Loading</div></td>
-					                    <td width="1%"><div id="VNC_buttons">
-					                        <input type=button value="Send CtrlAltDel"
-					                            id="sendCtrlAltDelButton">
-					                            </div></td>
-					                </tr></table>
-					            </div>
-					            <canvas id="VNC_canvas" width="640px" height="20px">
-					                Canvas not supported.
-					            </canvas>
-					        </div>
-					        </center>
-					
-					        <script>
-					        /*jslint white: false */
-					        /*global window, $, Util, RFB, */
-					        "use strict";
-					
-					        var rfb;
-					
-					        function passwordRequired(rfb) {
-					            var msg;
-					            msg = '<form onsubmit="return setPassword();"';
-					            msg += '  style="margin-bottom: 0px">';
-					            msg += 'Password Required: ';
-					            msg += '<input type=password size=10 id="password_input" class="VNC_status">';
-					            msg += '<\/form>';
-					            $D('VNC_status_bar').setAttribute("class", "VNC_status_warn");
-					            $D('VNC_status').innerHTML = msg;
-					        }
-					        function setPassword() {
-					            rfb.sendPassword($D('password_input').value);
-					            return false;
-					        }
-					        function sendCtrlAltDel() {
-					            rfb.sendCtrlAltDel();
-					            return false;
-					        }
-					        function updateState(rfb, state, oldstate, msg) {
-					            var s, sb, cad, level;
-					            s = $D('VNC_status');
-					            sb = $D('VNC_status_bar');
-					            cad = $D('sendCtrlAltDelButton');
-					            switch (state) {
-					                case 'failed':       level = "error";  break;
-					                case 'fatal':        level = "error";  break;
-					                case 'normal':       level = "normal"; break;
-					                case 'disconnected': level = "normal"; break;
-					                case 'loaded':       level = "normal"; break;
-					                default:             level = "warn";   break;
-					            }
-					
-					            if (state === "normal") { cad.disabled = false; }
-					            else                    { cad.disabled = true; }
-					
-					            if (typeof(msg) !== 'undefined') {
-					                sb.setAttribute("class", "VNC_status_" + level);
-					                s.innerHTML = msg;
-					            }
-					        }
-					
-					        function connect() {
-					            var host, port, password;
-					
-					            $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
-					
-					            host = "<?php echo $server[0]; ?>";
-					            port = <?php echo $server[1]; ?>;
-					            password = "";
-					
-					            rfb = new RFB({'target':       $D('VNC_canvas'),
-					                           'encrypt':      WebUtil.getQueryVar('encrypt', false),
-					                           'true_color':   WebUtil.getQueryVar('true_color', true),
-					                           'local_cursor': WebUtil.getQueryVar('cursor', true),
-					                           'shared':       WebUtil.getQueryVar('shared', true),
-					                           'updateState':  updateState,
-					                           'onPasswordRequired':  passwordRequired});
-					            rfb.connect(host, port, password);
-					        };
-					        
-					        setTimeout("connect()", 2000);
-					        </script>
-					</div>
-				</div>
-				<div id="navigation">
+    </head>
+    <body>
+        <div id="container">
+            <div id="header"></div>
+            <div id="content">
+                <div id="main">
+                    <div id="status" class="step">
+                        <h1>Let's fire her up!</h1>
+                            <center>
+                            <div id="VNC_screen">
+                                <div id="VNC_status_bar" class="VNC_status_bar" style="margin-top: -25px;">
+                                    <table border=0 width="100%"><tr>
+                                        <td><div id="VNC_status" style="display: none;">Loading</div></td>
+                                        <td width="1%"><div id="VNC_buttons">
+                                            <input type=button value="Send CtrlAltDel"
+                                                id="sendCtrlAltDelButton">
+                                                </div></td>
+                                    </tr></table>
+                                </div>
+                                <canvas id="VNC_canvas" width="640px" height="20px">
+                                    Canvas not supported.
+                                </canvas>
+                            </div>
+                            </center>
+                    
+                            <script>
+                            /*jslint white: false */
+                            /*global window, $, Util, RFB, */
+                            "use strict";
+                    
+                            var rfb;
+                    
+                            function passwordRequired(rfb) {
+                                var msg;
+                                msg = '<form onsubmit="return setPassword();"';
+                                msg += '  style="margin-bottom: 0px">';
+                                msg += 'Password Required: ';
+                                msg += '<input type=password size=10 id="password_input" class="VNC_status">';
+                                msg += '<\/form>';
+                                $D('VNC_status_bar').setAttribute("class", "VNC_status_warn");
+                                $D('VNC_status').innerHTML = msg;
+                            }
+                            function setPassword() {
+                                rfb.sendPassword($D('password_input').value);
+                                return false;
+                            }
+                            function sendCtrlAltDel() {
+                                rfb.sendCtrlAltDel();
+                                return false;
+                            }
+                            function updateState(rfb, state, oldstate, msg) {
+                                var s, sb, cad, level;
+                                s = $D('VNC_status');
+                                sb = $D('VNC_status_bar');
+                                cad = $D('sendCtrlAltDelButton');
+                                switch (state) {
+                                    case 'failed':       level = "error";  break;
+                                    case 'fatal':        level = "error";  break;
+                                    case 'normal':       level = "normal"; break;
+                                    case 'disconnected': level = "normal"; break;
+                                    case 'loaded':       level = "normal"; break;
+                                    default:             level = "warn";   break;
+                                }
+                    
+                                if (state === "normal") { cad.disabled = false; }
+                                else                    { cad.disabled = true; }
+                    
+                                if (typeof(msg) !== 'undefined') {
+                                    sb.setAttribute("class", "VNC_status_" + level);
+                                    s.innerHTML = msg;
+                                }
+                            }
+                    
+                            function connect() {
+                                var host, port, password;
+                    
+                                $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
+                    
+                                host = "<?php echo $server[0]; ?>";
+                                port = <?php echo $server[1]; ?>;
+                                password = "";
+                    
+                                rfb = new RFB({'target':       $D('VNC_canvas'),
+                                               'encrypt':      WebUtil.getQueryVar('encrypt', false),
+                                               'true_color':   WebUtil.getQueryVar('true_color', true),
+                                               'local_cursor': WebUtil.getQueryVar('cursor', true),
+                                               'shared':       WebUtil.getQueryVar('shared', true),
+                                               'updateState':  updateState,
+                                               'onPasswordRequired':  passwordRequired});
+                                rfb.connect(host, port, password);
+                            };
+                            
+                            setTimeout("connect()", 2000);
+                            </script>
+                    </div>
+                </div>
+                <div id="navigation">
 
-				</div>
-			</div>
-		</div>
-		</script>
-	</body>
+                </div>
+            </div>
+        </div>
+        </script>
+    </body>
 </html>
\ No newline at end of file



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-commits] proj/gentoaster:webui commit in: web/js/, /, web/
@ 2011-07-27 21:40 Liam McLoughlin
  0 siblings, 0 replies; 3+ messages in thread
From: Liam McLoughlin @ 2011-07-27 21:40 UTC (permalink / raw
  To: gentoo-commits

commit:     5af0df843f05f6f1650ccb63498741431bb9d58a
Author:     Liam McLoughlin <hexxeh <AT> hexxeh <DOT> net>
AuthorDate: Wed Jul 27 21:40:22 2011 +0000
Commit:     Liam McLoughlin <hexxeh <AT> hexxeh <DOT> net>
CommitDate: Wed Jul 27 21:40:22 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoaster.git;a=commit;h=5af0df84

Making everything Zend compliant again

---
 client.php                                         |    9 +-
 daemon.php                                         |   24 ++-
 status.php                                         |    9 +-
 web/config.php                                     |    5 +-
 web/finished.php                                   |   13 +-
 web/index.php                                      |  283 +++++++++++---------
 ...ui-1.8.14.custom.min.js => jquery-ui-1.8.14.js} |    0
 web/js/{jquery.form.wizard.js => jquery.wizard.js} |    0
 web/process.php                                    |   66 +++--
 web/status.php                                     |   78 ++++--
 web/testdrive.php                                  |  104 +++++---
 11 files changed, 366 insertions(+), 225 deletions(-)

diff --git a/client.php b/client.php
index 56313ae..2245f61 100644
--- a/client.php
+++ b/client.php
@@ -21,8 +21,13 @@
 
     echo "Job sent, handle was ".$handle." - hash ".$handlehash."\n";
 
-    $db = new mysqli(MYSQL_HOSTNAME, MYSQL_USERNAME,
-                     MYSQL_PASSWORD, MYSQL_DATABASE);
+    $db = new mysqli(
+        MYSQL_HOSTNAME,
+        MYSQL_USERNAME,
+        MYSQL_PASSWORD,
+        MYSQL_DATABASE
+    );
+    
     if (mysqli_connect_errno()) {
        die("Could not connect to database ".mysqli_connect_error());
     }

diff --git a/daemon.php b/daemon.php
index 5fa09b2..cac2adf 100644
--- a/daemon.php
+++ b/daemon.php
@@ -18,8 +18,13 @@
         $result = trim($result);
         echo "A job finished with return code ".$returncode.": ".$result."\n";
        
-        $db = new mysqli(MYSQL_HOSTNAME, MYSQL_USERNAME,
-                         MYSQL_PASSWORD, MYSQL_DATABASE);
+        $db = new mysqli(
+            MYSQL_HOSTNAME, 
+            MYSQL_USERNAME,
+            MYSQL_PASSWORD, 
+            MYSQL_DATABASE
+        );
+        
         if (mysqli_connect_errno()) {
            die("Could not connect to database ".mysqli_connect_error());
         }
@@ -87,7 +92,11 @@
     
                     unlink("config.ini");
     
-                    return update_result($handle, $returncode, $nonstatusOutput);
+                    return update_result(
+                        $handle, 
+                        $returncode, 
+                        $nonstatusOutput
+                    );
                 } else {
                     $error = "Configured build path is not writable";
                     return update_result($handle, -2, $error);
@@ -109,8 +118,13 @@
         $insert = false;
         $update = false;
         
-        $db = new mysqli(MYSQL_HOSTNAME, MYSQL_USERNAME,
-                         MYSQL_PASSWORD, MYSQL_DATABASE);
+        $db = new mysqli(
+            MYSQL_HOSTNAME, 
+            MYSQL_USERNAME,
+            MYSQL_PASSWORD, 
+            MYSQL_DATABASE
+        );
+        
         if (mysqli_connect_errno()) {
            die("Could not connect to database ".mysqli_connect_error());
         }

diff --git a/status.php b/status.php
index 66d55f8..2a49fd8 100644
--- a/status.php
+++ b/status.php
@@ -9,8 +9,13 @@
         die("No handle hash given\n");
     }
 
-    $db = new mysqli(MYSQL_HOSTNAME, MYSQL_USERNAME,
-                     MYSQL_PASSWORD, MYSQL_DATABASE);
+    $db = new mysqli(
+        MYSQL_HOSTNAME, 
+        MYSQL_USERNAME,
+        MYSQL_PASSWORD, 
+        MYSQL_DATABASE
+    );
+        
     if (mysqli_connect_errno()) {
        die("Could not connect to database ".mysqli_connect_error());
     }

diff --git a/web/config.php b/web/config.php
index c31e60b..1d1cb2e 100644
--- a/web/config.php
+++ b/web/config.php
@@ -9,6 +9,9 @@
     // Should we allow multiple simultaneous builds for a user?
     define("SIMULTANEOUS_BUILDS", false);
     
+    // What should we set as the default list of packages?
+    define("DEFAULT_PACKAGES", "dhcpd");
+    
     // What should we limit the virtual machine disk size to?
     define("MAX_DISK_SIZE", 16384);
     
@@ -20,5 +23,5 @@
     
     // Set the RECAPTCHA keys that should be used, if enabled
     define("RECAPTCHA_ENABLED", false);
-    define("RECAPTCHA_PUBLIC_KEY","REPLACE_ME");
+    define("RECAPTCHA_PUBLIC_KEY", "REPLACE_ME");
     define("RECAPTCHA_PRIVATE_KEY", "REPLACE_ME");
\ No newline at end of file

diff --git a/web/finished.php b/web/finished.php
index fa953c7..5d2309b 100644
--- a/web/finished.php
+++ b/web/finished.php
@@ -1,3 +1,9 @@
+<?php
+
+$buildID = filter_input(INPUT_GET, "uuid", FILTER_UNSAFE_RAW);
+$buildID = urlencode($buildID);
+
+?>
 <html>
 	<head>
 		<title>Gentoaster</title>
@@ -11,11 +17,12 @@
 					<div id="finished" class="step">
 						<h1>That's it!</h1>
 						<p>
-							That's all there is to it! We've sent your configuration down to the kitchen to be 
-							toasted, come back later to get your image.
+							That's all there is to it! We've sent your configuration down to 
+							the kitchen to be toasted, come back later to get your image.
 						</p>
 						<p>
-							You can also click <a href="status.php?uuid=<?php echo htmlspecialchars($_GET["uuid"]); ?>">here</a> to 
+							You can also click 
+							<a href="status.php?uuid=<?php echo $buildID; ?>">here</a> to 
 							view the status of your build.
 						</p>
 					</div>

diff --git a/web/index.php b/web/index.php
index a68a219..99b9cf0 100644
--- a/web/index.php
+++ b/web/index.php
@@ -5,15 +5,23 @@
         require_once "recaptcha.php";
     }
 
-    if(!SIMULTANEOUS_BUILDS) {
-            $db = new mysqli(MYSQL_HOSTNAME, MYSQL_USERNAME,
-                     MYSQL_PASSWORD, MYSQL_DATABASE);
+    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);
+            $ipaddress = filter_input(
+                INPUT_SERVER, 
+                "REMOTE_ADDR",
+                FILTER_VALIDATE_IP
+            );
                 
             $stmt = $db->prepare("SELECT id FROM builds WHERE ipaddress = ?");
             $stmt->bind_param("s", $ipaddress);
@@ -23,7 +31,8 @@
             if ($stmt->num_rows == 1) {
                     $stmt->bind_result($buildID);
                     $stmt->fetch();
-                    header("Location: status.php?uuid=".$buildID."&simultaneous=true");
+                    $url = "status.php?uuid=".$buildID."&simultaneous=true";
+                    header("Location: ".$url);
             }
             $stmt->close();
     }
@@ -50,135 +59,169 @@
     }
 ?>
 <html>
-	<head>
-		<title>Gentoaster</title>
-		<link rel="stylesheet" type="text/css" href="css/style.css">
-		<link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.14.custom.css">
-		<script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script>		
-		<script type="text/javascript" src="/js/jquery.form.js"></script>
-		<script type="text/javascript" src="/js/jquery.validate.js"></script>
-		<script type="text/javascript" src="/js/bbq.js"></script>
-		<script type="text/javascript" src="/js/jquery-ui-1.8.14.custom.min.js"></script>
-		<script type="text/javascript" src=" /js/jquery.form.wizard.js"></script>
+    <head>
+        <title>Gentoaster</title>
+        <link rel="stylesheet" type="text/css" href="css/style.css">
+        <link rel="stylesheet" type="text/css"
+          href="css/ui-lightness/jquery-ui-1.8.14.custom.css">
+        <script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script>
+        <script type="text/javascript" src="/js/jquery.form.js"></script>
+        <script type="text/javascript" src="/js/jquery.validate.js"></script>
+        <script type="text/javascript" src="/js/bbq.js"></script>
+        <script type="text/javascript" src="/js/jquery-ui-1.8.14.js"></script>
+        <script type="text/javascript" src=" /js/jquery.wizard.js"></script>
         <script type="text/javascript">
             var RecaptchaOptions = {
                 theme : 'clean'
             };
          </script>
-	</head>
-	<body>
-		<div id="container">
-			<div id="header"></div>
-			<form id="wizard" method="post" action="process.php" class="bbq">
-				<div id="content">
-					<div id="main">
-						<div id="welcome" class="step">
-							<h1>Welcome to Gentoaster!</h1>
-							<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>
+    </head>
+    <body>
+        <div id="container">
+            <div id="header"></div>
+            <form id="wizard" method="post" action="process.php" class="bbq">
+                <div id="content">
+                    <div id="main">
+                        <div id="welcome" class="step">
+                            <h1>Welcome to Gentoaster!</h1>
+                            <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>
+                            <?php
+                             echo recaptcha_get_html(RECAPTCHA_PUBLIC_KEY);
+                            ?>
+                            <br>
+                        </div>
+                        <?php
+                            }
+                        ?>
+                        <div id="locale" class="step">
+                            <h1>Locale</h1>
 
-							<label for="locale_language">Language</label><br />
-							<select id="locale_language" class="required" name="language">
-								<option>English (UK)</option>
-							</select>
-							<br>
+                            <label for="locale_language">Language</label>
+                            <br />
+                            <select id="locale_language" class="required"
+                                name="language">
+                                <option>English (UK)</option>
+                            </select>
+                            <br>
 
-							<label for="locale_keyboard">Keyboard Layout</label><br />
-							<select id="locale_keyboard" class="required" name="keyboard">
-								<option>United Kingdom</option>
-							</select>
-							<br>
+                            <label for="locale_keyboard">Keyboard Layout</label>
+                            <br />
+                            <select id="locale_keyboard" class="required"
+                                name="keyboard">
+                                <option>United Kingdom</option>
+                            </select>
+                            <br>
 
-							<label for="locale_timezone">Timezone</label><br />
-							<select id="locale_timezone" class="required" name="timezone">
-								<?php echo $timezoneOption; ?>
-							</select>
-							<br>
-						</div>
-						<div id="user" class="step">
-							<h1>User details</h1>
+                            <label for="locale_timezone">Timezone</label>
+                            <br />
+                            <select id="locale_timezone" class="required"
+                                name="timezone">
+                                <?php echo $timezoneOption; ?>
+                            </select>
+                            <br>
+                        </div>
+                        <div id="user" class="step">
+                            <h1>User details</h1>
 
-							<label for="user_username">Username</label><br />
-							<input id="user_username" class="required" type="text" name="username"><br>
+                            <label for="user_username">Username</label><br />
+                            <input id="user_username" class="required"
+                                type="text" name="username"><br>
 
-							<label for="user_password">Password</label><br />
-							<input id="user_password" class="required" type="password" name="password">
-							<input id="user_confirmpassword" class="required" type="password" name="confirmpassword"><br>
+                            <label for="user_password">Password</label><br />
+                            <input id="user_password" class="required"
+                                type="password" name="password">
+                                
+                            <input id="user_confirmpassword" class="required"
+                                type="password" name="confirmpassword"><br>
 
-							<label for="user_rootpassword">Root Password</label><br />
-							<input id="user_rootpassword" class="required" type="password" name="rootpassword">
-							<input id="user_confirmrootpassword" class="required" type="password" name="confirmrootpassword"><br>
-						</div>
-						<div id="network" class="step">
-							<h1>Network</h1>
+                            <label for="user_rootpassword">Root Password</label>
+                            <br />
+                            <input id="user_rootpassword" class="required"
+                                type="password" name="rootpassword">
+                                
+                            <input id="user_confirmrootpassword"
+                                class="required" type="password"
+                                name="confirmrootpassword"><br>
+                        </div>
+                        <div id="network" class="step">
+                            <h1>Network</h1>
 
-							<label for="network_hostname">Hostname</label><br />
-							<input id="network_hostname" class="required" type="text" name="hostname"><br>
-						</div>
-						<div id="partitioning" class="step">
-							<h1>Partitioning</h1>
+                            <label for="network_hostname">Hostname</label><br />
+                            <input id="network_hostname" class="required"
+                                type="text" name="hostname"><br>
+                        </div>
+                        <div id="partitioning" class="step">
+                            <h1>Partitioning</h1>
 
-							<label for="partitioning_size">Disk size</label><br />
-							<input id="partitioning_size" class="required" type="text" name="image_size" value="4096"><br>
+                            <label for="partitioning_size">Disk size</label>
+                            <br />
+                            <input id="partitioning_size" class="required"
+                                type="text" name="image_size" value="4096"><br>
 
-							<label for="">Split</label><br /><br />
-							<div id="partitioning_split" name="split"></div><br /><br />
-							<div id="partitioning_display">Not yet updated</div><br />
-							<input type="hidden" id="partitioning_boot" name="boot_size" value="0"><br />
-							<input type="hidden" id="partitioning_swap" name="swap_size" value="0"><br />
-							<input type="hidden" id="partitioning_root" name="root_size" value="0"><br />
-						</div>
-						<div id="packages" class="step">
-							<h1>Packages</h1>
+                            <label for="">Split</label><br /><br />
+                            <div id="partitioning_split" name="split"></div>
+                            <br /><br />
+                            <div id="partitioning_display">Not yet updated</div>
+                            <br />
+                            <input type="hidden" id="partitioning_boot"
+                                name="boot_size" value="0"><br />
+                            <input type="hidden" id="partitioning_swap"
+                                name="swap_size" value="0"><br />
+                            <input type="hidden" id="partitioning_root"
+                                name="root_size" value="0"><br />
+                        </div>
+                        <div id="packages" class="step">
+                            <h1>Packages</h1>
 
-							<label for="packages_packages">Packages list</label><br /><br />
-							<textarea id="packages_packages" name="packages" style="width: 680px; height: 330px;">dhcpcd</textarea>
-							<br>
-						</div>
-						<div id="format" class="step submit_step">
-							<h1>Image format</h1>
+                            <label for="packages_packages">Packages list</label>
+                            <br /><br />
+                            <textarea id="packages_packages" name="packages"
+                                style="width: 680px; height: 330px;"><?php 
+                                    echo DEFAULT_PACKAGES;
+                                ?></textarea>
+                            <br>
+                        </div>
+                        <div id="format" class="step submit_step">
+                            <h1>Image format</h1>
 
-							<label for="format_format">Output format</label><br />
-							<select id="format_format" class="required" name="format">
-								<option value="raw">Raw</option>
-								<option value="vmware">VirtualBox</option>
-								<option value="vbox">VMWare</option>
-							</select>
-							<br>
-						</div>
-						<div id="complete" class="step">
-							<h1>That's it!</h1>
-							<p>That's all there is to it! We've sent your configuration down to the kitchen to be 
-							cooked, and we'll email you once it's finished cooking.</p>
-						</div>
-					</div>
-					<div id="navigation">
-						<button id="forwardbutton" class="navigationbutton" type="submit">Next</button>
-						<button id="backbutton" class="navigationbutton" type="reset">Back</button>
-					</div>
-				</div>
-			</form>
-		</div>
-		<script type="text/javascript">
-    		MAX_DISK_SIZE = <?php echo MAX_DISK_SIZE; ?>;
-		</script>
-		<script type="text/javascript" src=" /js/gentoaster.js"></script>
-	</body>
+                            <label for="format_format">Output format</label>
+                            <br />
+                            <select id="format_format" class="required"
+                                name="format">
+                                <option value="raw">Raw</option>
+                                <option value="vmware">VirtualBox</option>
+                                <option value="vbox">VMWare</option>
+                            </select>
+                            <br>
+                        </div>
+                        <div id="complete" class="step">
+                            <h1>That's it!</h1>
+                            <p>That's all there is to it! We've sent your 
+                            configuration down to the kitchen to be cooked, and 
+                            we'll email you once it's finished cooking.</p>
+                        </div>
+                    </div>
+                    <div id="navigation">
+                        <button id="forwardbutton" class="navigationbutton"
+                            type="submit">Next</button>
+                        <button id="backbutton" class="navigationbutton"
+                            type="reset">Back</button>
+                    </div>
+                </div>
+            </form>
+        </div>
+        <script type="text/javascript">
+            MAX_DISK_SIZE = <?php echo MAX_DISK_SIZE; ?>;
+        </script>
+        <script type="text/javascript" src=" /js/gentoaster.js"></script>
+    </body>
 </html>

diff --git a/web/js/jquery-ui-1.8.14.custom.min.js b/web/js/jquery-ui-1.8.14.js
similarity index 100%
rename from web/js/jquery-ui-1.8.14.custom.min.js
rename to web/js/jquery-ui-1.8.14.js

diff --git a/web/js/jquery.form.wizard.js b/web/js/jquery.wizard.js
similarity index 100%
rename from web/js/jquery.form.wizard.js
rename to web/js/jquery.wizard.js

diff --git a/web/process.php b/web/process.php
index cadbf98..a005319 100644
--- a/web/process.php
+++ b/web/process.php
@@ -5,45 +5,56 @@
 
     require_once "config.php";
 
-    $ipaddress = filter_input(INPUT_SERVER, "REMOTE_ADDR",
-                              FILTER_VALIDATE_IP);
+    $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);
+        $challenge = filter_input(
+            INPUT_POST,
+            "recaptcha_challenge_field",
+            FILTER_UNSAFE_RAW
+        );
         
-        $resp = recaptcha_check_answer(RECAPTCHA_PRIVATE_KEY,
-                                       $ipaddress,
-                                       $challenge,
-                                       $response);
+        $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) {
+    function sanitize_shellarg($arg)
+    {
         return escapeshellarg($arg);
     }
-    $shellfilter = array("options" => "sanitize_shellarg");
+    $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, $shellfilter);
-    $hostname = filter_input(INPUT_POST, "hostname", FILTER_CALLBACK, $shellfilter);
-    $username =  filter_input(INPUT_POST, "username", FILTER_CALLBACK, $shellfilter);
-    $password = filter_input(INPUT_POST, "password", FILTER_CALLBACK, $shellfilter);
-    $rootPass = filter_input(INPUT_POST, "rootpassword", FILTER_CALLBACK, $shellfilter);
-    $packagesList = filter_input(INPUT_POST, "packages", FILTER_CALLBACK, $shellfilter);
-    $outputFormat = filter_input(INPUT_POST, "format", FILTER_CALLBACK, $shellfilter);
+    $timezone = filter_input(INPUT_POST, "timezone", 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);
+    $outputFormat = filter_input(INPUT_POST, "format", FILTER_CALLBACK, $sfi);
 
     $packagesList = str_replace("\r\n", " ", $packagesList);
     $packagesList = str_replace("\n", " ", $packagesList);
@@ -70,13 +81,20 @@ OUTPUT_FORMAT=$outputFormat";
     $client->addServer();
     $handle = $client->doBackground("invoke_image_build", $iniString);
 
-    $db = new mysqli(MYSQL_HOSTNAME, MYSQL_USERNAME,
-                     MYSQL_PASSWORD, MYSQL_DATABASE);
+    $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("INSERT INTO builds (id, handle, ipaddress) VALUES(?, ?, ?)");
+    $query = "INSERT INTO builds (id, handle, ipaddress) ".
+             "VALUES(?, ?, ?)";
+    $stmt = $db->prepare($query);
     $stmt->bind_param("sss", $buildID, $handle, $ipaddress);
     $stmt->execute();
     $stmt->close();

diff --git a/web/status.php b/web/status.php
index d2e8715..ab57a1e 100644
--- a/web/status.php
+++ b/web/status.php
@@ -6,19 +6,29 @@
     require_once "config.php";
 
     $buildID = filter_input(INPUT_GET, "uuid", FILTER_UNSAFE_RAW);
-    $simultaneous = filter_input(INPUT_GET, "simultaneous", FILTER_VALIDATE_BOOLEAN);
-    $buildresult = "Unknown!";
+    $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/>";
+    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);
+    $db = new mysqli(
+        MYSQL_HOSTNAME, 
+        MYSQL_USERNAME,
+        MYSQL_PASSWORD, 
+        MYSQL_DATABASE
+    );
+    
     if (mysqli_connect_errno()) {
        die("Could not connect to database ".mysqli_connect_error());
     }
@@ -38,14 +48,16 @@
             if ($status[0]) {
                     if ($status[3] != 0) {
                             $percentage = ceil($status[2]/$status[3]*100);
-                            $buildresult = "Your build is currently running".
+                            $bres = "Your build is currently running".
                                            " and is ".$percentage."% complete";
                             $inprogress = true;
                     } else {
-                            $buildresult = "Task has not yet been processed";
+                            $bres = "Task has not yet been processed";
                     }
             } else {
-                    $stmt = $db->prepare("SELECT returncode, result FROM builds WHERE id = ?");
+                    $query = "SELECT returncode, result ".
+                             "FROM builds WHERE id = ?";
+                    $stmt = $db->prepare($query);
                     $stmt->bind_param("s", $buildID);
                     $stmt->execute();
                     $stmt->bind_result($returncode, $result);
@@ -53,29 +65,36 @@
                     $stmt->close();
                     if ($returncode !== null) {
                             if ($returncode == 0) {
-                                $buildresult = "Your build is complete! ".
-                                               "What would you like to do now?".
-                                               "<br /><br /><center>".
-                                               "<table><tr><td>".
-                                               "<a href=\"/gentoaster/".$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>";
+                                $bres = "Your build is complete! ".
+                                   "What would you like to do now?".
+                                   "<br /><br /><center>".
+                                   "<table><tr><td>".
+                                   "<a href=\"/gentoaster/".
+                                   $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 {
-                                $buildresult = "Job returned with code ".$returncode.": ".$result;
+                                $bres = "Job returned with code ".
+                                        $returncode.": ".$result;
                             }
                     } else {
-                            $buildresult = "Job failed";
+                            $bres = "Job failed";
                     }
             }
     } else {
             $stmt->close();
-            $buildresult = "Invalid handle hash";
+            $bres = "Invalid handle hash";
     }
 
     $db->close();
@@ -90,9 +109,10 @@
     <head>
         <title>Gentoaster</title>
         <link rel="stylesheet" type="text/css" href="css/style.css">
-        <link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.14.custom.css">
-        <script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script>        
-        <script type="text/javascript" src="/js/jquery-ui-1.8.14.custom.min.js"></script>
+        <link rel="stylesheet" type="text/css"
+          href="css/ui-lightness/jquery-ui-1.8.14.custom.css">
+        <script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script>
+        <script type="text/javascript" src="/js/jquery-ui-1.8.14.js"></script>
         <?php
             if ($inprogress) {
                 echo '<script>
@@ -112,7 +132,7 @@
                         <h1><?php echo $titleString; ?></h1>
                         <p>
                             <?php echo $simultaneousString; ?>
-                            <?php echo $buildresult; ?>
+                            <?php echo $bres; ?>
                             <div id="progressbar"></div>
                         </p>
                     </div>

diff --git a/web/testdrive.php b/web/testdrive.php
index 3847b69..7610811 100644
--- a/web/testdrive.php
+++ b/web/testdrive.php
@@ -9,8 +9,13 @@
     $buildresult = "Unknown!";
     $inprogress = false;
 
-    $db = new mysqli(MYSQL_HOSTNAME, MYSQL_USERNAME,
-                     MYSQL_PASSWORD, MYSQL_DATABASE);
+    $db = new mysqli(
+        MYSQL_HOSTNAME, 
+        MYSQL_USERNAME,
+        MYSQL_PASSWORD, 
+        MYSQL_DATABASE
+    );
+    
     if (mysqli_connect_errno()) {
        die("Could not connect to database ".mysqli_connect_error());
     }
@@ -30,7 +35,9 @@
             if ($status[0]) {
                     header("Location: status.php?uuid=".$buildID);
             } else {
-                    $stmt = $db->prepare("SELECT returncode, result FROM builds WHERE id = ?");
+                    $query = "SELECT returncode, result ".
+                             "FROM builds WHERE id = ?";
+                    $stmt = $db->prepare($query);
                     $stmt->bind_param("s", $buildID);
                     $stmt->execute();
                     $stmt->bind_result($returncode, $result);
@@ -41,7 +48,10 @@
                                 // we're built, let's do this
                                 $client = new GearmanClient();
                                 $client->addServer();
-                                $server = $client->do("invoke_start_image", $buildID);
+                                $server = $client->do(
+                                    "invoke_start_image",
+                                    $buildID
+                                );
                                 $server = unserialize($server);
                             } else {
                                 header("Location: status.php?uuid=".$buildID);
@@ -61,9 +71,10 @@
     <head>
         <title>Gentoaster</title>
         <link rel="stylesheet" type="text/css" href="css/style.css">
-        <link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.14.custom.css">
-        <script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script>        
-        <script type="text/javascript" src="/js/jquery-ui-1.8.14.custom.min.js"></script>
+        <link rel="stylesheet" type="text/css"
+          href="css/ui-lightness/jquery-ui-1.8.14.custom.css">
+        <script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script>
+        <script type="text/javascript" src="/js/jquery-ui-1.8.14.js"></script>
         <script type="text/javascript" src="include/vnc.js"></script>
     </head>
     <body>
@@ -75,16 +86,24 @@
                         <h1>Let's fire her up!</h1>
                             <center>
                             <div id="VNC_screen">
-                                <div id="VNC_status_bar" class="VNC_status_bar" style="margin-top: -25px;">
+                                <div id="VNC_status_bar" class="VNC_status_bar"
+                                    style="margin-top: -25px;">
                                     <table border=0 width="100%"><tr>
-                                        <td><div id="VNC_status" style="display: none;">Loading</div></td>
+                                        <td>
+                                            <div id="VNC_status"
+                                                style="display: none;">
+                                                Loading
+                                            </div>
+                                        </td>
                                         <td width="1%"><div id="VNC_buttons">
-                                            <input type=button value="Send CtrlAltDel"
+                                            <input type=button
+                                                value="Send CtrlAltDel"
                                                 id="sendCtrlAltDelButton">
                                                 </div></td>
                                     </tr></table>
                                 </div>
-                                <canvas id="VNC_canvas" width="640px" height="20px">
+                                <canvas id="VNC_canvas" width="640px"
+                                    height="20px">
                                     Canvas not supported.
                                 </canvas>
                             </div>
@@ -97,21 +116,11 @@
                     
                             var rfb;
                     
-                            function passwordRequired(rfb) {
-                                var msg;
-                                msg = '<form onsubmit="return setPassword();"';
-                                msg += '  style="margin-bottom: 0px">';
-                                msg += 'Password Required: ';
-                                msg += '<input type=password size=10 id="password_input" class="VNC_status">';
-                                msg += '<\/form>';
-                                $D('VNC_status_bar').setAttribute("class", "VNC_status_warn");
-                                $D('VNC_status').innerHTML = msg;
-                            }
                             function setPassword() {
                                 rfb.sendPassword($D('password_input').value);
                                 return false;
                             }
-                            function sendCtrlAltDel() {
+                            function sendCAD() {
                                 rfb.sendCtrlAltDel();
                                 return false;
                             }
@@ -121,19 +130,35 @@
                                 sb = $D('VNC_status_bar');
                                 cad = $D('sendCtrlAltDelButton');
                                 switch (state) {
-                                    case 'failed':       level = "error";  break;
-                                    case 'fatal':        level = "error";  break;
-                                    case 'normal':       level = "normal"; break;
-                                    case 'disconnected': level = "normal"; break;
-                                    case 'loaded':       level = "normal"; break;
-                                    default:             level = "warn";   break;
+                                    case 'failed':
+                                        level = "error";
+                                        break;
+                                    case 'fatal':
+                                        level = "error";
+                                        break;
+                                    case 'normal':
+                                        level = "normal";
+                                        break;
+                                    case 'disconnected':
+                                        level = "normal";
+                                        break;
+                                    case 'loaded':
+                                        level = "normal";
+                                        break;
+                                    default:
+                                        level = "warn";
+                                        break;
                                 }
                     
-                                if (state === "normal") { cad.disabled = false; }
-                                else                    { cad.disabled = true; }
+                                if (state === "normal") {
+                                    cad.disabled = false;
+                                } else {
+                                    cad.disabled = true;
+                                }
                     
                                 if (typeof(msg) !== 'undefined') {
-                                    sb.setAttribute("class", "VNC_status_" + level);
+                                    attr = "VNC_status_" + level;
+                                    sb.setAttribute("class", attr);
                                     s.innerHTML = msg;
                                 }
                             }
@@ -141,19 +166,20 @@
                             function connect() {
                                 var host, port, password;
                     
-                                $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
+                                $D('sendCtrlAltDelButton').onclick = sendCAD;
                     
                                 host = "<?php echo $server[0]; ?>";
                                 port = <?php echo $server[1]; ?>;
                                 password = "";
                     
-                                rfb = new RFB({'target':       $D('VNC_canvas'),
-                                               'encrypt':      WebUtil.getQueryVar('encrypt', false),
-                                               'true_color':   WebUtil.getQueryVar('true_color', true),
-                                               'local_cursor': WebUtil.getQueryVar('cursor', true),
-                                               'shared':       WebUtil.getQueryVar('shared', true),
-                                               'updateState':  updateState,
-                                               'onPasswordRequired':  passwordRequired});
+                                gqv = WebUtil.getQueryVar;
+                    
+                                rfb = new RFB({'target':$D('VNC_canvas'),
+                                'encrypt': gqv('encrypt',false),
+                                'true_color': gqv('true_color',true),
+                                'local_cursor': gqv('cursor',true),
+                                'shared': gqv('shared',true),
+                                'updateState':  updateState,
                                 rfb.connect(host, port, password);
                             };
                             



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-commits] proj/gentoaster:master commit in: /, web/, web/js/
@ 2011-08-12 23:17 Liam McLoughlin
  2011-07-24  2:43 ` [gentoo-commits] proj/gentoaster:webui commit in: web/js/, /, web/ Liam McLoughlin
  0 siblings, 1 reply; 3+ messages in thread
From: Liam McLoughlin @ 2011-08-12 23:17 UTC (permalink / raw
  To: gentoo-commits

commit:     603e8f6106dc66596b29131ac2e2b804d0e35934
Author:     Liam McLoughlin <hexxeh <AT> hexxeh <DOT> net>
AuthorDate: Sun Jul 24 00:58:03 2011 +0000
Commit:     Liam McLoughlin <hexxeh <AT> hexxeh <DOT> net>
CommitDate: Sun Jul 24 00:58:03 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoaster.git;a=commit;h=603e8f61

Changed code to be closer to Zend standard

---
 daemon.php           |    4 +-
 web/index.php        |   10 +-
 web/js/gentoaster.js |  102 ++++++++++++++++++++
 web/process.php      |   61 ++++++------
 web/status.php       |  135 +++++++++++++++-----------
 web/testdrive.php    |  256 +++++++++++++++++++++++++-------------------------
 6 files changed, 347 insertions(+), 221 deletions(-)

diff --git a/daemon.php b/daemon.php
index a25861e..6570185 100644
--- a/daemon.php
+++ b/daemon.php
@@ -3,11 +3,11 @@
     // Gentoaster build daemon worker
     // Licensed under GPL v3, see COPYING file
 
-    $configurationsPath = "/var/www/gentoaster";
+    $configurationsPath = "/var/www/gentoaster/images";
     $gentoasterPath = "/usr/share/gentoaster";
     $buildToolName = "create_image.sh";
     $wrapToolName = "wrap.sh";
-    $externalHost = "192.168.2.167";
+    $externalHost = "192.168.2.169";
     $lowPort = 5900;
     $highPort = 5999;
 

diff --git a/web/index.php b/web/index.php
index 181d07b..1fd4d7d 100644
--- a/web/index.php
+++ b/web/index.php
@@ -3,10 +3,9 @@
 
     $timezones = array();
     $zonetab = file(ZONETAB);
-    foreach ($zonetab as $buf)
-    {
-        if (substr($buf,0,1)=='#') continue;
-        $rec = preg_split('/\s+/',$buf);
+    foreach ($zonetab as $buf) {
+        if (substr($buf, 0, 1)=='#') continue;
+        $rec = preg_split('/\s+/', $buf);
         $key = $rec[2];
         $val = $rec[2];
         $c = count($rec);
@@ -15,8 +14,7 @@
         ksort($timezones);
     }
     $timezoneOption = "";
-    foreach ($timezones as $timezone => $description)
-    {
+    foreach ($timezones as $timezone => $description) {
         $timezoneOption .= "<option>".$timezone."</option>\n";
     }
 ?>

diff --git a/web/js/gentoaster.js b/web/js/gentoaster.js
new file mode 100644
index 0000000..99cd514
--- /dev/null
+++ b/web/js/gentoaster.js
@@ -0,0 +1,102 @@
+$(function(){
+	$("#wizard").formwizard({ 
+		validationEnabled: true,
+		focusFirstInput: true,
+		disableUIStyles: true,
+		//historyEnabled: true,
+		validationOptions: {
+			rules: {
+				username: {
+					minlength: 2
+				},
+				password: {
+					minlength: 5
+				},
+				confirmpassword: {
+					minlength: 5,
+					equalTo: "#user_password"
+				},
+				boot_size: {
+					min: 32
+				},
+				swap_size: {
+					min: 16
+				},
+				root_size: {
+					min: 3072
+				},
+				size: {
+					min: 4020
+				}
+			},
+			messages: {
+				username: {
+					minlength: "Your username must consist of at least 2 characters"
+				},
+				password: {
+					minlength: "Your password must be at least 5 characters long"
+				},
+				confirmpassword: {
+					minlength: "Your password must be at least 5 characters long",
+					equalTo: "Please enter the same password in both boxes"
+				},
+				boot_size: {
+					min: "Your boot partition must be at least 32MB"
+				},
+				swap_size: {
+					min: "Your swap partition must be at least 128MB"
+				},
+				root_size: {
+					min: "Your root partition must be at least 3072MB"
+				},
+				size: {
+					min: "Your disk image must be at least 4020MB"
+				}
+			}
+		}
+	});
+	
+	function partitioning_update(event, ui) {
+			if(!ui.values) {
+				ui.values = ui;
+			}
+	        $('.partitionrange').css('width', $('.ui-slider-range').css('left'));
+	        var boot_size = ui.values[0];
+	        var swap_size = ui.values[1]-ui.values[0];
+	        var root_size = $("#partitioning_split").slider( "option", "max" )-ui.values[1];
+	        var image_size = boot_size+swap_size+root_size;
+	        $("#partitioning_display").html("Disk image size: "+image_size+"MB<br>Boot partition size: "+boot_size+"MB<br>Swap partition size: "+swap_size+"MB<br>Root partition size: "+root_size+"MB");
+	        $("#partitioning_boot").attr("value", boot_size);
+	        $("#partitioning_swap").attr("value", swap_size);
+	        $("#partitioning_root").attr("value", root_size);
+	        
+	        //since it doesn't seem to redraw by itself, hacky fix!
+	        $("#partitioning_split").slider("option", "values", $("#partitioning_split").slider("option", "values"));	
+	}
+	
+	$("#partitioning_split").slider({
+	    range: true,
+	    min: 0,
+	    max: 4096,
+	    values: [128, 640],
+	    slide: partitioning_update,
+	    change: partitioning_update,
+	    create: function(event, ui) {
+	        var slider = $(event.target);
+	        var range = slider.find('.ui-slider-range');
+	        var newrange = $('<div />');
+	        newrange.appendTo(slider).addClass('ui-slider-range partitionrange').css('width', range.css('left'));
+	    }
+	});
+	
+	function update_slider() {
+		var new_size = $("#partitioning_size").val();
+		$("#partitioning_split").slider("option", "max", new_size);
+		partitioning_update(null, $("#partitioning_split").slider("option", "values"));
+	}
+
+	
+	$("#partitioning_size").change(update_slider);
+	
+	partitioning_update(null, $("#partitioning_split").slider("option", "values"));
+});
\ No newline at end of file

diff --git a/web/process.php b/web/process.php
index 1b68d03..93c5d68 100644
--- a/web/process.php
+++ b/web/process.php
@@ -1,46 +1,47 @@
 <?php
 
-	$build_id = uniqid();
-	$boot_megabytes = intval($_POST["boot_size"]);
-	$swap_megabytes = intval($_POST["swap_size"]);
-	$root_megabytes = intval($_POST["root_size"]);
-	$timezone = escapeshellarg($_POST["timezone"]);
-	$hostname = escapeshellarg($_POST["hostname"]);
-	$username =  escapeshellarg($_POST["username"]);
-	$password = escapeshellarg($_POST["password"]);
-	$root_password = escapeshellarg($_POST["rootpassword"]);
-	$packages_list = escapeshellarg($_POST["packages"]);
-	$output_format = escapeshellarg($_POST["format"]);
+    $buildID = uniqid();
+    $bootMegabytes = intval($_POST["boot_size"]);
+    $swapMegabytes = intval($_POST["swap_size"]);
+    $rootMegabytes = intval($_POST["root_size"]);
+    $timezone = escapeshellarg($_POST["timezone"]);
+    $hostname = escapeshellarg($_POST["hostname"]);
+    $username =  escapeshellarg($_POST["username"]);
+    $password = escapeshellarg($_POST["password"]);
+    $rootPassword = escapeshellarg($_POST["rootpassword"]);
+    $packagesList = escapeshellarg($_POST["packages"]);
+    $outputFormat = escapeshellarg($_POST["format"]);
 
-	$packages_list = str_replace("\r\n", " ", $packages_list);
-	$packages_list = str_replace("\n", " ", $packages_list);
+    $packagesList = str_replace("\r\n", " ", $packagesList);
+    $packagesList = str_replace("\n", " ", $packagesList);
 
-$ini_string = "[vmconfig]
+$iniString = "[vmconfig]
 
-BUILD_ID='$build_id'
-BOOT_MEGABYTES='$boot_megabytes'
-SWAP_MEGABYTES='$swap_megabytes'
-ROOT_MEGABYTES='$root_megabytes'
+BUILD_ID='$buildID'
+BOOT_MEGABYTES='$bootMegabytes'
+SWAP_MEGABYTES='$swapMegabytes'
+ROOT_MEGABYTES='$rootMegabytes'
 TIMEZONE=$timezone
 HOSTNAME=$hostname
-ROOT_PASSWORD=$root_password
+ROOT_PASSWORD=$rootPassword
 DEFAULT_USERNAME=$username
 DEFAULT_PASSWORD=$password
 USE_FLAGS=''
 PACKAGE_USE=''
 FEATURES='parallel-fetch userfetch userpriv getbinpkg'
 PACKAGE_ACCEPT_KEYWORDS=''
-PACKAGES_LIST=$packages_list
-OUTPUT_FORMAT=$output_format";
+PACKAGES_LIST=$packagesList
+OUTPUT_FORMAT=$outputFormat";
 
-	$client = new GearmanClient();
-	$client->addServer();
-	$handle = $client->doBackground("invoke_image_build", $ini_string);
+    $client = new GearmanClient();
+    $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");
-	mysql_query("INSERT INTO builds (id, handle) VALUES('".$build_id."','".$handle."')");
+    $db = mysql_connect("localhost", "gentoaster", "");
+    if(!$db) die("Could not connect to database ".mysql_error());
+    mysql_select_db("gentoaster");
+    $query = "INSERT INTO builds (id, handle) ".
+             "VALUES('".$buildID."','".$handle."')";
+    mysql_query($query);
 
-	header("Location: finished.php?uuid=".$build_id);
-?>
+    header("Location: finished.php?uuid=".$buildID);
\ No newline at end of file

diff --git a/web/status.php b/web/status.php
index 7371c16..20aacec 100644
--- a/web/status.php
+++ b/web/status.php
@@ -1,38 +1,55 @@
 <?php
 
-	$build_id = $_GET["uuid"];
-	$buildresult = "Unknown!";
-	$inprogress = false;
-	$builddone = false;
+    $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");
+    $db = mysql_connect("localhost", "gentoaster", "");
+    if (!$db) die("Could not connect to database ".mysql_error()."\n");
     mysql_select_db("gentoaster");
-    $result = mysql_query("SELECT handle FROM builds WHERE id = '".mysql_real_escape_string($build_id)."'");
-    if(mysql_num_rows($result) == 1) {
+    $query = "SELECT handle FROM builds ".
+             "WHERE id = '".mysql_real_escape_string($buildID)."'";
+    $result = mysql_query($query);
+    if (mysql_num_rows($result) == 1) {
             $handles = mysql_fetch_array($result);
             $handle = $handles[0];
             $client = new GearmanClient();
             $client->addServer();
 
             $status = $client->jobStatus($handle);
-            if($status[0]) {
-                    if($status[3] != 0) {
+            if ($status[0]) {
+                    if ($status[3] != 0) {
                             $percentage = ceil($status[2]/$status[3]*100);
-                            $buildresult = "Your build is currently running and is ".$percentage."% complete";
+                            $buildresult = "Your build is currently running".
+                                           " and is ".$percentage."% complete";
                             $inprogress = true;
                     } else {
                             $buildresult = "Task has not yet been processed";
                     }
             } else {
-                    $result = mysql_query("SELECT returncode, result FROM builds WHERE id = '".mysql_real_escape_string($build_id)."'");
+                    $cleanBuildID = mysql_real_escape_string($buildID);
+                    $query = "SELECT returncode, result FROM builds ".
+                             "WHERE id = '".$cleanBuildID."'";
+                    $result = mysql_query($query);
                     $jobres = mysql_fetch_array($result);
-                    if($jobres[0] !== NULL) {
-                    		if($jobres[0] == 0) {
-                        		$buildresult = "Your build is complete! What would you like to do now?<br /><br /><center><table><tr><td><a href=\"/gentoaster/".$build_id."/".$build_id.".tar.gz\"><img style=\"padding: 10px;\" src=\"img/icons/download.png\"></a></td><td><a href=\"testdrive.php?uuid=".$build_id."\"><img style=\"padding: 10px;\" src=\"img/icons/testdrive.png\"></a></td></tr><tr><td>Download</td><td>Testdrive</td></tr></table></center>";
-                        		$builddone = true;
+                    if ($jobres[0] !== NULL) {
+                            if ($jobres[0] == 0) {
+                                $buildresult = "Your build is complete! ".
+                                               "What would you like to do now?".
+                                               "<br /><br /><center>".
+                                               "<table><tr><td>".
+                                               "<a href=\"/gentoaster/".$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 {
-                        	    $buildresult = "Job returned with code ".$jobres[0].": ".$jobres[1];
+                                $buildresult = "Job returned with code ".$jobres[0].": ".$jobres[1];
                             }
                     } else {
                             $buildresult = "Job failed";
@@ -44,44 +61,50 @@
 
 ?>
 <html>
-	<head>
-		<title>Gentoaster</title>
-		<link rel="stylesheet" type="text/css" href="css/style.css">
-		<link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.14.custom.css">
-		<script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script>		
-		<script type="text/javascript" src="/js/jquery-ui-1.8.14.custom.min.js"></script>
-		<?php
-			if($inprogress) {
-				echo '<script>
-				  $(document).ready(function() {
-				    $("#progressbar").progressbar({ value: '.$percentage.' });
-				  });
-				</script>';
-			}
-		?>
-	</head>
-	<body>
-		<div id="container">
-			<div id="header"></div>
-			<div id="content">
-				<div id="main">
-					<div id="status" class="step">
-						<?php if(!$builddone) { ?>
-							<h1>How's things?</h1>
-						<?php } else { ?>
-							<h1>It's showtime!</h1>
-						<?php } ?>
-						<p>
-							<?php echo $buildresult; ?>
-							<div id="progressbar"></div>
-						</p>
-					</div>
-				</div>
-				<div id="navigation">
+    <head>
+        <title>Gentoaster</title>
+        <link rel="stylesheet" type="text/css" href="css/style.css">
+        <link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.14.custom.css">
+        <script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script>        
+        <script type="text/javascript" src="/js/jquery-ui-1.8.14.custom.min.js"></script>
+        <?php
+            if ($inprogress) {
+                echo '<script>
+                  $(document).ready(function() {
+                    $("#progressbar").progressbar({ value: '.$percentage.' });
+                  });
+                </script>';
+            }
+        ?>
+    </head>
+    <body>
+        <div id="container">
+            <div id="header"></div>
+            <div id="content">
+                <div id="main">
+                    <div id="status" class="step">
+                        <?php
+                            if (!$builddone) {
+                        ?>
+                            <h1>How's things?</h1>
+                        <?php
+                            } else {
+                        ?>
+                            <h1>It's showtime!</h1>
+                        <?php
+                            }
+                        ?>
+                        <p>
+                            <?php echo $buildresult; ?>
+                            <div id="progressbar"></div>
+                        </p>
+                    </div>
+                </div>
+                <div id="navigation">
 
-				</div>
-			</div>
-		</div>
-		</script>
-	</body>
+                </div>
+            </div>
+        </div>
+        </script>
+    </body>
 </html>
\ No newline at end of file

diff --git a/web/testdrive.php b/web/testdrive.php
index b6e65b8..a313f39 100644
--- a/web/testdrive.php
+++ b/web/testdrive.php
@@ -1,37 +1,39 @@
 <?php
 
-	$build_id = $_GET["uuid"];
-	$buildresult = "Unknown!";
-	$inprogress = false;
+    $buildID = $_GET["uuid"];
+    $buildresult = "Unknown!";
+    $inprogress = false;
 
-    $db = mysql_connect("localhost","gentoaster","");
-    if(!$db) die("Could not connect to database ".mysql_error()."\n");
+    $db = mysql_connect("localhost", "gentoaster", "");
+    if (!$db) die("Could not connect to database ".mysql_error()."\n");
     mysql_select_db("gentoaster");
-    $result = mysql_query("SELECT handle FROM builds WHERE id = '".mysql_real_escape_string($build_id)."'");
-    if(mysql_num_rows($result) == 1) {
+    $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);
             $handle = $handles[0];
             $client = new GearmanClient();
             $client->addServer();
 
             $status = $client->jobStatus($handle);
-            if($status[0]) {
-                    header("Location: status.php?uuid=".$build_id);
+            if ($status[0]) {
+                    header("Location: status.php?uuid=".$buildID);
             } else {
-                    $result = mysql_query("SELECT returncode, result FROM builds WHERE id = '".mysql_real_escape_string($build_id)."'");
+                    $cleanBuildID = mysql_real_escape_string($buildID);
+                    $query = "SELECT returncode, result FROM builds WHERE id = '".$cleanBuildID."'";
+                    $result = mysql_query();
                     $jobres = mysql_fetch_array($result);
-                    if($jobres[0] !== NULL) {
-                    		if($jobres[0] == 0) {
-                        		// we're built, let's do this
-								$client = new GearmanClient();
-								$client->addServer();
-								$server = $client->do("invoke_start_image", $build_id);
-								$server = unserialize($server);
+                    if ($jobres[0] !== NULL) {
+                            if ($jobres[0] == 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=".$build_id);
+                                header("Location: status.php?uuid=".$buildID);
                             }
                     } else {
-                           	header("Location: status.php?uuid=".$build_id);
+                               header("Location: status.php?uuid=".$buildID);
                     }
             }
     } else {
@@ -40,114 +42,114 @@
 
 ?>
 <html>
-	<head>
-		<title>Gentoaster</title>
-		<link rel="stylesheet" type="text/css" href="css/style.css">
-		<link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.14.custom.css">
-		<script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script>		
-		<script type="text/javascript" src="/js/jquery-ui-1.8.14.custom.min.js"></script>
+    <head>
+        <title>Gentoaster</title>
+        <link rel="stylesheet" type="text/css" href="css/style.css">
+        <link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.14.custom.css">
+        <script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script>        
+        <script type="text/javascript" src="/js/jquery-ui-1.8.14.custom.min.js"></script>
         <script type="text/javascript" src="include/vnc.js"></script>
-	</head>
-	<body>
-		<div id="container">
-			<div id="header"></div>
-			<div id="content">
-				<div id="main">
-					<div id="status" class="step">
-						<h1>Let's fire her up!</h1>
-							<center>
-					        <div id="VNC_screen">
-					            <div id="VNC_status_bar" class="VNC_status_bar" style="margin-top: -25px;">
-					                <table border=0 width="100%"><tr>
-					                    <td><div id="VNC_status" style="display: none;">Loading</div></td>
-					                    <td width="1%"><div id="VNC_buttons">
-					                        <input type=button value="Send CtrlAltDel"
-					                            id="sendCtrlAltDelButton">
-					                            </div></td>
-					                </tr></table>
-					            </div>
-					            <canvas id="VNC_canvas" width="640px" height="20px">
-					                Canvas not supported.
-					            </canvas>
-					        </div>
-					        </center>
-					
-					        <script>
-					        /*jslint white: false */
-					        /*global window, $, Util, RFB, */
-					        "use strict";
-					
-					        var rfb;
-					
-					        function passwordRequired(rfb) {
-					            var msg;
-					            msg = '<form onsubmit="return setPassword();"';
-					            msg += '  style="margin-bottom: 0px">';
-					            msg += 'Password Required: ';
-					            msg += '<input type=password size=10 id="password_input" class="VNC_status">';
-					            msg += '<\/form>';
-					            $D('VNC_status_bar').setAttribute("class", "VNC_status_warn");
-					            $D('VNC_status').innerHTML = msg;
-					        }
-					        function setPassword() {
-					            rfb.sendPassword($D('password_input').value);
-					            return false;
-					        }
-					        function sendCtrlAltDel() {
-					            rfb.sendCtrlAltDel();
-					            return false;
-					        }
-					        function updateState(rfb, state, oldstate, msg) {
-					            var s, sb, cad, level;
-					            s = $D('VNC_status');
-					            sb = $D('VNC_status_bar');
-					            cad = $D('sendCtrlAltDelButton');
-					            switch (state) {
-					                case 'failed':       level = "error";  break;
-					                case 'fatal':        level = "error";  break;
-					                case 'normal':       level = "normal"; break;
-					                case 'disconnected': level = "normal"; break;
-					                case 'loaded':       level = "normal"; break;
-					                default:             level = "warn";   break;
-					            }
-					
-					            if (state === "normal") { cad.disabled = false; }
-					            else                    { cad.disabled = true; }
-					
-					            if (typeof(msg) !== 'undefined') {
-					                sb.setAttribute("class", "VNC_status_" + level);
-					                s.innerHTML = msg;
-					            }
-					        }
-					
-					        function connect() {
-					            var host, port, password;
-					
-					            $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
-					
-					            host = "<?php echo $server[0]; ?>";
-					            port = <?php echo $server[1]; ?>;
-					            password = "";
-					
-					            rfb = new RFB({'target':       $D('VNC_canvas'),
-					                           'encrypt':      WebUtil.getQueryVar('encrypt', false),
-					                           'true_color':   WebUtil.getQueryVar('true_color', true),
-					                           'local_cursor': WebUtil.getQueryVar('cursor', true),
-					                           'shared':       WebUtil.getQueryVar('shared', true),
-					                           'updateState':  updateState,
-					                           'onPasswordRequired':  passwordRequired});
-					            rfb.connect(host, port, password);
-					        };
-					        
-					        setTimeout("connect()", 2000);
-					        </script>
-					</div>
-				</div>
-				<div id="navigation">
+    </head>
+    <body>
+        <div id="container">
+            <div id="header"></div>
+            <div id="content">
+                <div id="main">
+                    <div id="status" class="step">
+                        <h1>Let's fire her up!</h1>
+                            <center>
+                            <div id="VNC_screen">
+                                <div id="VNC_status_bar" class="VNC_status_bar" style="margin-top: -25px;">
+                                    <table border=0 width="100%"><tr>
+                                        <td><div id="VNC_status" style="display: none;">Loading</div></td>
+                                        <td width="1%"><div id="VNC_buttons">
+                                            <input type=button value="Send CtrlAltDel"
+                                                id="sendCtrlAltDelButton">
+                                                </div></td>
+                                    </tr></table>
+                                </div>
+                                <canvas id="VNC_canvas" width="640px" height="20px">
+                                    Canvas not supported.
+                                </canvas>
+                            </div>
+                            </center>
+                    
+                            <script>
+                            /*jslint white: false */
+                            /*global window, $, Util, RFB, */
+                            "use strict";
+                    
+                            var rfb;
+                    
+                            function passwordRequired(rfb) {
+                                var msg;
+                                msg = '<form onsubmit="return setPassword();"';
+                                msg += '  style="margin-bottom: 0px">';
+                                msg += 'Password Required: ';
+                                msg += '<input type=password size=10 id="password_input" class="VNC_status">';
+                                msg += '<\/form>';
+                                $D('VNC_status_bar').setAttribute("class", "VNC_status_warn");
+                                $D('VNC_status').innerHTML = msg;
+                            }
+                            function setPassword() {
+                                rfb.sendPassword($D('password_input').value);
+                                return false;
+                            }
+                            function sendCtrlAltDel() {
+                                rfb.sendCtrlAltDel();
+                                return false;
+                            }
+                            function updateState(rfb, state, oldstate, msg) {
+                                var s, sb, cad, level;
+                                s = $D('VNC_status');
+                                sb = $D('VNC_status_bar');
+                                cad = $D('sendCtrlAltDelButton');
+                                switch (state) {
+                                    case 'failed':       level = "error";  break;
+                                    case 'fatal':        level = "error";  break;
+                                    case 'normal':       level = "normal"; break;
+                                    case 'disconnected': level = "normal"; break;
+                                    case 'loaded':       level = "normal"; break;
+                                    default:             level = "warn";   break;
+                                }
+                    
+                                if (state === "normal") { cad.disabled = false; }
+                                else                    { cad.disabled = true; }
+                    
+                                if (typeof(msg) !== 'undefined') {
+                                    sb.setAttribute("class", "VNC_status_" + level);
+                                    s.innerHTML = msg;
+                                }
+                            }
+                    
+                            function connect() {
+                                var host, port, password;
+                    
+                                $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
+                    
+                                host = "<?php echo $server[0]; ?>";
+                                port = <?php echo $server[1]; ?>;
+                                password = "";
+                    
+                                rfb = new RFB({'target':       $D('VNC_canvas'),
+                                               'encrypt':      WebUtil.getQueryVar('encrypt', false),
+                                               'true_color':   WebUtil.getQueryVar('true_color', true),
+                                               'local_cursor': WebUtil.getQueryVar('cursor', true),
+                                               'shared':       WebUtil.getQueryVar('shared', true),
+                                               'updateState':  updateState,
+                                               'onPasswordRequired':  passwordRequired});
+                                rfb.connect(host, port, password);
+                            };
+                            
+                            setTimeout("connect()", 2000);
+                            </script>
+                    </div>
+                </div>
+                <div id="navigation">
 
-				</div>
-			</div>
-		</div>
-		</script>
-	</body>
+                </div>
+            </div>
+        </div>
+        </script>
+    </body>
 </html>
\ No newline at end of file



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-08-12 23:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-12 23:17 [gentoo-commits] proj/gentoaster:master commit in: /, web/, web/js/ Liam McLoughlin
2011-07-24  2:43 ` [gentoo-commits] proj/gentoaster:webui commit in: web/js/, /, web/ Liam McLoughlin
  -- strict thread matches above, loose matches on Subject: below --
2011-07-27 21:40 Liam McLoughlin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox