From 603e8f6106dc66596b29131ac2e2b804d0e35934 Mon Sep 17 00:00:00 2001 From: Liam McLoughlin Date: Sun, 24 Jul 2011 01:58:03 +0100 Subject: 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(-) create mode 100644 web/js/gentoaster.js 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 .= "\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
Boot partition size: "+boot_size+"MB
Swap partition size: "+swap_size+"MB
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 = $('
'); + 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 @@ 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 @@ 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?

DownloadTestdrive
"; - $builddone = true; + if ($jobres[0] !== NULL) { + if ($jobres[0] == 0) { + $buildresult = "Your build is complete! ". + "What would you like to do now?". + "

". + "". + "". + "
". + "". + "". + "". + "". + "". + "
DownloadTestdrive
"; + $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 @@ ?> - - Gentoaster - - - - - - $(document).ready(function() { - $("#progressbar").progressbar({ value: '.$percentage.' }); - }); - '; - } - ?> - - -
- -
-
-
- -

How's things?

- -

It's showtime!

- -

- -

-

-
-
- +
+
+ + \ 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 @@ 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 @@ ?> - - Gentoaster - - - - + + Gentoaster + + + + - - -
- -
-
-
-

Let's fire her up!

-
-
-
- - - -
- -
-
- - Canvas not supported. - -
-
- - -
-
- +
+
+ + \ No newline at end of file -- cgit v1.2.3-65-gdbad