aboutsummaryrefslogtreecommitdiff
blob: 93c5d68e3b2436b82daf0d3e616664d6569c0fe4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

    $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"]);

    $packagesList = str_replace("\r\n", " ", $packagesList);
    $packagesList = str_replace("\n", " ", $packagesList);

$iniString = "[vmconfig]

BUILD_ID='$buildID'
BOOT_MEGABYTES='$bootMegabytes'
SWAP_MEGABYTES='$swapMegabytes'
ROOT_MEGABYTES='$rootMegabytes'
TIMEZONE=$timezone
HOSTNAME=$hostname
ROOT_PASSWORD=$rootPassword
DEFAULT_USERNAME=$username
DEFAULT_PASSWORD=$password
USE_FLAGS=''
PACKAGE_USE=''
FEATURES='parallel-fetch userfetch userpriv getbinpkg'
PACKAGE_ACCEPT_KEYWORDS=''
PACKAGES_LIST=$packagesList
OUTPUT_FORMAT=$outputFormat";

    $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");
    $query = "INSERT INTO builds (id, handle) ".
             "VALUES('".$buildID."','".$handle."')";
    mysql_query($query);

    header("Location: finished.php?uuid=".$buildID);