aboutsummaryrefslogtreecommitdiff
blob: 43827b9e55ba0425dd795fa53a313873dc67d7c2 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php

    // Gentoaster web interface config processor
    // Licensed under GPL v3, see COPYING file

    require_once "config.php";

    if (RECAPTCHA_ENABLED) {
        require_once "recaptcha.php";
    
        $resp = recaptcha_check_answer(RECAPTCHA_PRIVATE_KEY,
                                    $_SERVER["REMOTE_ADDR"],
                                    $_POST["recaptcha_challenge_field"],
                                    $_POST["recaptcha_response_field"]);
                                    
        if (!$resp->is_valid) {
            die("CAPTCHA was incorrect");
        }
    }

    $buildID = uniqid();
    $bootMegabytes = intval($_POST["boot_size"]);
    $swapMegabytes = intval($_POST["swap_size"]);
    $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(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD);
    if (!$db) {
       die("Could not connect to database ".mysql_error());
    }
    mysql_select_db(MYSQL_DATABASE);
    $query = "INSERT INTO builds (id, handle) ".
             "VALUES('".$buildID."','".$handle."')";
    mysql_query($query);

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