Example #1
0
include 'functions/config.php';
require_once 'functions/functions.php';
if (!check_session()) {
    header("Location: {$serviceurl}/?error=1");
    exit;
}
$vm = addslashes($_GET['vm']);
$hypervisor = addslashes($_GET['hypervisor']);
if (empty($vm) || empty($hypervisor)) {
    exit;
}
$h_reply = get_SQL_line("SELECT * FROM hypervisors WHERE id='{$hypervisor}'");
$v_reply = get_SQL_line("SELECT * FROM vms WHERE id='{$vm}'");
$source_reply = get_SQL_line("SELECT name FROM vms WHERE id='{$v_reply['4']}'");
ssh_connect($h_reply[2] . ":" . $h_reply[3]);
$source_path = str_replace("\n", "", ssh_command("sudo virsh domblklist {$source_reply['0']}|grep vda| awk '{print \$2}' ", true));
$dest_path = str_replace("\n", "", ssh_command("sudo virsh domblklist {$v_reply['1']}|grep vda| awk '{print \$2}' ", true));
$filekey = uniqid();
add_SQL_line("UPDATE vms SET filecopy='{$filekey}' WHERE id='{$vm}'");
add_SQL_line("UPDATE vms SET maintenance='true' WHERE source_volume='{$vm}'");
#destroy all runing child vms
$child_vms = get_SQL_array("SELECT name FROM vms WHERE source_volume='{$vm}'");
$x = 0;
while ($child_vms[$x]['name']) {
    ssh_command("sudo virsh destroy " . $child_vms[$x]['name'], true);
    ++$x;
}
ssh_command("sudo /usr/local/VDI/copy-file {$source_path} {$dest_path} {$filekey}", false);
header("Location: {$serviceurl}/dashboard.php");
exit;
Example #2
0
function reload_vm_info()
{
    include 'config.php';
    $x = 0;
    while ($hypervizors[$x]) {
        $tmp = explode(":", $hypervizors[$x]);
        $ip = $tmp[0];
        $port = $tmp[1];
        $sql_reply = get_SQL_line("SELECT id FROM hypervisors WHERE ip='{$ip}'");
        if (empty($sql_reply[0])) {
            add_SQL_line("INSERT INTO  hypervisors (ip,port) VALUES ('{$ip}','{$port}')");
        } else {
            add_SQL_line("UPDATE hypervisors SET ip='{$ip}', port='{$port}' WHERE id='{$sql_reply['0']}'");
        }
        $sql_reply = get_SQL_line("SELECT id FROM hypervisors WHERE ip='{$ip}'");
        $hyper_id = $sql_reply[0];
        ssh_connect($ip . ":" . $port);
        $output = ssh_command("sudo virsh list --all |tail -n +3|head -n -1|awk '{print \$2" . '" "' . "\$3}'", true);
        $vms = array();
        $output = str_replace("\n", " ", $output);
        $vms = explode(" ", $output);
        $y = 0;
        while ($vms[$y]) {
            $sql_reply = get_SQL_line("SELECT id FROM vms WHERE name='{$vms[$y]}' AND hypervisor='{$hyper_id}'");
            $state = $vms[$y + 1];
            if (empty($sql_reply[0])) {
                add_SQL_line("INSERT INTO  vms (name,hypervisor,state) VALUES ('{$vms[$y]}','{$hyper_id}','{$state}')");
            } else {
                add_SQL_line("UPDATE vms SET name='{$vms[$y]}', hypervisor='{$hyper_id}', state='{$state}' WHERE id='{$sql_reply['0']}'");
            }
            $y = $y + 2;
        }
        ++$x;
    }
}
Example #3
0
<?php

include 'functions/config.php';
require_once 'functions/functions.php';
if (!check_session()) {
    header("Location: {$serviceurl}/?error=1");
    exit;
}
$password1 = $_POST['password1'];
$password2 = $_POST['password2'];
if (!empty($password1) && !empty($password2)) {
    $id = $_SESSION['userid'];
    $cryptpw = crypt($password1);
    add_SQL_line("UPDATE users SET password='******' WHERE id='{$id}'");
}
header("Location: {$serviceurl}/reload_vm_info.php");
exit;
Example #4
0
<?php

include 'functions/config.php';
require_once 'functions/functions.php';
if (!check_session()) {
    header("Location: {$serviceurl}/?error=1");
    exit;
}
$vm = addslashes($_GET['vm']);
$hypervisor = addslashes($_GET['hypervisor']);
$action = addslashes($_GET['action']);
if (empty($vm)) {
    header("Location: {$serviceurl}/dashboard.php");
    exit;
}
if ($action == "mass_on") {
    add_SQL_line("UPDATE vms SET snapshot='true' WHERE source_volume='{$vm}'");
}
if ($action == "mass_off") {
    add_SQL_line("UPDATE vms SET snapshot='false' WHERE source_volume='{$vm}'");
}
if ($action == "single") {
    $snapshot = get_SQL_line("SELECT snapshot FROM vms WHERE id='{$vm}'");
    if ($snapshot[0] == "true") {
        add_SQL_line("UPDATE vms SET snapshot='false' WHERE id='{$vm}'");
    } else {
        add_SQL_line("UPDATE vms SET snapshot='true' WHERE id='{$vm}'");
    }
}
header("Location: {$serviceurl}/dashboard.php");
exit;
Example #5
0
<?php

include "functions/config.php";
require_once "functions/functions.php";
$username = addslashes($_POST['username']);
$password = addslashes($_POST['password']);
$sql_reply = get_SQL_line("SELECT id,password FROM users WHERE username LIKE '{$username}'");
if (hash_equals($sql_reply[1], crypt($password, $sql_reply[1]))) {
    //echo "Password verified!";
    session_start();
    $_SESSION['logged'] = 'yes';
    $_SESSION['userid'] = $sql_reply[0];
    $ip = $_SERVER['REMOTE_ADDR'];
    $data = date("Y.m.d H:i:s");
    add_SQL_line("UPDATE users SET lastlogin='******', ip='{$ip}' WHERE id='{$sql_reply['0']}'");
    header("Location: {$serviceurl}/reload_vm_info.php");
    exit;
} else {
    header("Location: {$serviceurl}/?error=1");
    exit;
}
Example #6
0
include 'functions/config.php';
require_once 'functions/functions.php';
if (!check_session()) {
    header("Location: {$serviceurl}/?error=1");
    exit;
}
$vm = addslashes($_GET['vm']);
$hypervisor = addslashes($_GET['hypervisor']);
if (empty($vm) || empty($hypervisor)) {
    exit;
}
$h_reply = get_SQL_line("SELECT * FROM hypervisors WHERE id='{$hypervisor}'");
$v_reply = get_SQL_line("SELECT * FROM vms WHERE id='{$vm}'");
ssh_connect($h_reply[2] . ":" . $h_reply[3]);
#$filekey= uniqid();
#add_SQL_line("UPDATE vms SET filecopy='$filekey' WHERE id='$vm'");
add_SQL_line("UPDATE vms SET maintenance='true' WHERE source_volume='{$vm}'");
add_SQL_line("UPDATE vms SET snapshot='false' WHERE source_volume='{$vm}'");
$source_path = str_replace("\n", "", ssh_command("sudo virsh domblklist " . $v_reply[1] . "|grep vda| awk '{print \$2}' ", true));
#destroy all runing child vms
$child_vms = get_SQL_array("SELECT name FROM vms WHERE source_volume='{$vm}'");
$x = 0;
while ($child_vms[$x]['name']) {
    ssh_command("sudo virsh destroy " . $child_vms[$x]['name'], true);
    $dest_path = str_replace("\n", "", ssh_command("sudo virsh domblklist " . $child_vms[$x]['name'] . "|grep vda| awk '{print \$2}' ", true));
    ssh_command("sudo qemu-img create -f qcow2 -b {$source_path} {$dest_path}", true);
    ssh_command("sudo virsh start " . $child_vms[$x]['name'], true);
    ++$x;
}
header("Location: {$serviceurl}/reload_vm_info.php");
exit;
Example #7
0
<?php

include 'functions/config.php';
require_once 'functions/functions.php';
if (!check_session()) {
    header("Location: {$serviceurl}/?error=1");
    exit;
}
$vm = addslashes($_POST['vm']);
$hypervisor = addslashes($_POST['hypervisor']);
$snapshot = addslashes($_POST['snapshot']);
$snapshot = str_replace("on", "true", $snapshot);
$shapshot = str_replace("off", "false", $snapshot);
if (empty($snapshot)) {
    $snapshot = "false";
}
$source_volume = addslashes($_POST['source_volume']);
$machine_type = addslashes($_POST['machine_type']);
if ($machine_type == "simplemachine" || $machine_type == "sourcemachine") {
    $sourcevolume = "";
}
if (empty($vm) && empty($hypervisor)) {
    header("Location: {$serviceurl}/dashboard.php");
    exit;
}
add_SQL_line("UPDATE vms SET snapshot='{$snapshot}',source_volume='{$source_volume}',machine_type='{$machine_type}' WHERE id='{$vm}'");
header("Location: {$serviceurl}/dashboard.php");
exit;
Example #8
0
<?php

include 'functions/config.php';
require_once 'functions/functions.php';
if (!check_session()) {
    header("Location: {$serviceurl}/?error=1");
    exit;
}
$sourcevm = addslashes($_GET['source']);
$action = addslashes($_GET['action']);
if (empty($sourcevm)) {
    header("Location: {$serviceurl}/dashboard.php");
    exit;
}
if ($action == "single") {
    $maintenance = get_SQL_line("SELECT maintenance FROM vms WHERE id='{$sourcevm}'");
    if ($maintenance[0] == "true") {
        add_SQL_line("UPDATE vms SET maintenance='false' WHERE id='{$sourcevm}'");
    } else {
        add_SQL_line("UPDATE vms SET maintenance='true' WHERE id='{$sourcevm}'");
    }
}
if ($action == "mass_on") {
    add_SQL_line("UPDATE vms SET maintenance='true' WHERE source_volume='{$sourcevm}'");
}
if ($action == "mass_off") {
    add_SQL_line("UPDATE vms SET maintenance='false' WHERE source_volume='{$sourcevm}'");
}
header("Location: {$serviceurl}/dashboard.php");
exit;
Example #9
0
    }
}
if ($machine_type == 'initialmachine') {
    $name = $machinename;
    $disk = $source_drivepath . '/' . $name . "-" . uniqid() . ".qcow2";
    $vm_cmd = "sudo virt-install --name=" . $name . " --disk path=" . $disk . ",format=qcow2,bus=virtio,cache=none --soundhw=ac97 --vcpus=" . $numcpu . ",cores=" . $numcore . " --ram=" . $numram . " --network bridge=" . $network . ",model=virtio --os-type=" . $os_type . " --os-variant=" . $os_version . " --graphics spice,listen=0.0.0.0 --redirdev usb,type=spicevmc --video qxl --import --noreboot";
    $drive_cmd = "sudo qemu-img create -f qcow2 -o size=1G " . $disk;
    ssh_command($drive_cmd, true);
    ssh_command($vm_cmd, true);
    add_SQL_line("INSERT INTO  vms (name,hypervisor,machine_type,source_volume) VALUES ('{$name}','{$hypervisor}','{$machine_type}','{$source_volume}')");
    $v_reply = get_SQL_line("SELECT id FROM vms WHERE name='{$name}'");
    header("Location: {$serviceurl}/copy_disk.php?vm=" . $v_reply[0]);
    exit;
}
if ($machine_type == 'vdimachine') {
    $source_reply = get_SQL_line("SELECT name FROM vms WHERE id='{$source_volume}'");
    $source_disk = str_replace("\n", "", ssh_command("sudo virsh domblklist {$source_reply['0']}|grep vda| awk '{print \$2}' ", true));
    $x = 0;
    while ($x < $machinecount) {
        $name = $machinename . sprintf("%0" . strlen($machinecount) . "s", $x + 1);
        $disk = $source_drivepath . '/' . $name . "-" . uniqid() . ".qcow2";
        $vm_cmd = "sudo virt-install --name=" . $name . " --disk path=" . $disk . ",format=qcow2,bus=virtio,cache=none --soundhw=ac97 --vcpus=" . $numcpu . ",cores=" . $numcore . " --ram=" . $numram . " --network bridge=" . $network . ",model=virtio --os-type=" . $os_type . " --os-variant=" . $os_version . " --graphics spice,listen=0.0.0.0 --redirdev usb,type=spicevmc --video qxl --noreboot --import";
        $drive_cmd = "sudo qemu-img create -f qcow2 -b " . $source_disk . " " . $disk;
        ssh_command($drive_cmd, true);
        ssh_command($vm_cmd, true);
        add_SQL_line("INSERT INTO  vms (name,hypervisor,machine_type,source_volume) VALUES ('{$name}','{$hypervisor}','{$machine_type}','{$source_volume}')");
        ++$x;
    }
}
header("Location: {$serviceurl}/reload_vm_info.php");
exit;
Example #10
0
<?php

include "functions/config.php";
require_once 'functions/functions.php';
$pass = $_POST['pass'];
if ($pass == $backend_pass) {
    $tmpname = $_POST['tmpname'];
    $data = $_POST['data'];
    $vm = $_POST['vm'];
    if (!empty($tmpname) && !empty($data)) {
        file_put_contents("tmp/" . $tmpname . ".txt", $data);
        if ($data == 100) {
            sleep(4);
            add_SQL_line("UPDATE vms SET filecopy='' WHERE filecopy='{$tmpname}'");
        }
    }
    if (!empty($vm)) {
        $v_reply = get_SQL_line("SELECT snapshot FROM vms WHERE name='{$vm}'");
        echo $v_reply[0];
    }
}