コード例 #1
0
ファイル: copy_disk.php プロジェクト: BillTheBest/kvm-vdi
<?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']);
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");
コード例 #2
0
ファイル: power.php プロジェクト: BillTheBest/kvm-vdi
if ($action == "mass_on" || $action == "mass_off" || $action == "mass_destroy") {
    $child_vms = get_SQL_array("SELECT name FROM vms WHERE source_volume='{$vm}'");
    $x = 0;
    while ($child_vms[$x]['name']) {
        if ($action == "mass_on") {
            ssh_command("sudo virsh start " . $child_vms[$x]['name'], true);
        }
        if ($action == "mass_off") {
            ssh_command("sudo virsh shutdown " . $child_vms[$x]['name'], true);
        }
        if ($action == "mass_destroy") {
            ssh_command("sudo virsh destroy " . $child_vms[$x]['name'], true);
        }
        ++$x;
    }
}
if ($action == "single") {
    $v_reply = get_SQL_line("SELECT name FROM vms WHERE id='{$vm}'");
    $state = addslashes($_GET['state']);
    if ($state == "up") {
        ssh_command("sudo virsh start " . $v_reply[0], true);
    }
    if ($state == "down") {
        ssh_command("sudo virsh shutdown " . $v_reply[0], true);
    }
    if ($state == "destroy") {
        ssh_command("sudo virsh destroy " . $v_reply[0], true);
    }
}
header("Location: {$serviceurl}/reload_vm_info.php");
exit;
コード例 #3
0
ファイル: login.php プロジェクト: BillTheBest/kvm-vdi
<?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;
}
コード例 #4
0
ファイル: functions.php プロジェクト: BillTheBest/kvm-vdi
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;
    }
}
コード例 #5
0
ファイル: snapshot.php プロジェクト: BillTheBest/kvm-vdi
<?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;
コード例 #6
0
ファイル: client.php プロジェクト: BillTheBest/kvm-vdi
        $machine_rdp_address = $xml->client[$x]->{'machine-rdp-address'};
        $machine_rdp_address = str_replace("\n", "", $machine_rdp_address);
        $pool = $xml->client[$x]->{'pool'};
        $pool = str_replace("\n", "", $pool);
    }
    ++$x;
}
if ($protocol == "RDP") {
    $json_reply = json_encode(array('status' => "OK", 'protocol' => $protocol, 'address' => $machine_rdp_address));
}
if ($protocol == "vmView") {
    $json_reply = json_encode(array('status' => "OK", 'protocol' => $protocol, 'address' => $vmView_server, 'pool' => $pool));
}
if ($protocol == "SPICE") {
    $vm = get_SQL_line("SELECT hypervisor,maintenance FROM vms WHERE name='{$machine_name}'");
    $h_reply = get_SQL_line("SELECT * FROM hypervisors WHERE id='{$vm['0']}'");
    if ($vm[1] == "true") {
        echo json_encode(array('status' => "MAINTENANCE"));
        exit;
    }
    ssh_connect($h_reply[2] . ":" . $h_reply[3]);
    $status = ssh_command("sudo virsh domdisplay " . $machine_name, true);
    $status = str_replace("spice://", "", $status);
    $status = str_replace("\n", "", $status);
    $status = str_replace("localhost", $h_reply[2], $status);
    if (empty($status)) {
        $status = 'BOOTUP';
        ssh_command("sudo virsh start " . $machine_name, true);
        reload_vm_info();
    }
    if ($status == "BOOTUP") {
コード例 #7
0
ファイル: maintenance.php プロジェクト: BillTheBest/kvm-vdi
<?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;
コード例 #8
0
ファイル: create_vm.php プロジェクト: BillTheBest/kvm-vdi
    }
}
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;
コード例 #9
0
ファイル: backend.php プロジェクト: BillTheBest/kvm-vdi
<?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];
    }
}