autostart delete tmp files

This commit is contained in:
nativemad 2018-10-24 14:49:05 +02:00
parent daabc3d8a0
commit 102e47026d
2 changed files with 18 additions and 5 deletions

7
nlvmi
View File

@ -300,6 +300,13 @@ if [ $# -gt 0 ]; then
elif [ $1 == "checkvm" ]; then elif [ $1 == "checkvm" ]; then
if [ -z $2 ]; then echo "checkvm needs two arguments"; fi if [ -z $2 ]; then echo "checkvm needs two arguments"; fi
checkvm $2 checkvm $2
elif [ $1 == "delautostart" ]; then
if [ $2 == "local" ]; then
rm /home/nlvmi/start*-$3.tmp
rm /home/nlvmi/start*-$3.tmp.sha512
else
su nlvmi -c "ssh $2 \"rm /home/nlvmi/start*-$3.tmp; rm /home/nlvmi/start*-$3.tmp.sha512\""
fi
elif [ $1 == "start" ]; then elif [ $1 == "start" ]; then
if [ -z $2 ]; then echo "start needs a vmname!"; exit 1; fi if [ -z $2 ]; then echo "start needs a vmname!"; exit 1; fi
VMFOUND="no" VMFOUND="no"

View File

@ -141,7 +141,7 @@ if (isset($_SESSION['username'])){
} else { } else {
$vmname = clean($_POST['deletename']); $vmname = clean($_POST['deletename']);
$vmid = clean($_POST['deleteid']); $vmid = clean($_POST['deleteid']);
$sql="SELECT id,prio FROM vms WHERE vmname='$vmname' AND id='$vmid'"; $sql="SELECT vms.id AS vid,prio,hostname,connectstring,autostart FROM vms LEFT JOIN servers ON vms.server = servers.hostname WHERE vmname='$vmname' AND vid='$vmid'";
$res = $db_handle->query($sql); $res = $db_handle->query($sql);
while ($row = $res->fetchArray(SQLITE3_ASSOC)){ while ($row = $res->fetchArray(SQLITE3_ASSOC)){
$prio = $row['prio']; $prio = $row['prio'];
@ -163,6 +163,13 @@ if (isset($_SESSION['username'])){
} }
} }
} }
if ($row['autostart'] == "1"){
if ($row['connectstring'] == ""){
$shellout = shell_exec("/usr/bin/nlvmi delautostart local $vmname");
} else {
$shellout = shell_exec("/usr/bin/nlvmi delautostart $row[connectstring] $vmname");
}
}
$sqld="DELETE FROM vms WHERE id='$vmid'"; $sqld="DELETE FROM vms WHERE id='$vmid'";
if ($db_handle->query($sqld)){ if ($db_handle->query($sqld)){
echo "VM $vmname deleted!"; echo "VM $vmname deleted!";
@ -301,13 +308,13 @@ if (isset($_SESSION['username'])){
$pres = $db_handle->query($psql); $pres = $db_handle->query($psql);
$prioa = $pres->fetchArray(SQLITE3_ASSOC); $prioa = $pres->fetchArray(SQLITE3_ASSOC);
$prio = $prioa['prio'] + 1; $prio = $prioa['prio'] + 1;
$mode="newvm"; $mode="newvm";
$sqls="INSERT INTO vms "; $sqls="INSERT INTO vms ";
$sqlc="("; $sqlc="(";
$sqlv=" VALUES ("; $sqlv=" VALUES (";
foreach(array_keys($_REQUEST) as $rkey){ foreach(array_keys($_REQUEST) as $rkey){
if (($rkey!="mode")&&($rkey!="rand")){ if (($rkey!="mode")&&($rkey!="rand")){
$rvalue = clean($_REQUEST[$rkey]);
if ((preg_match('/macaddr/', $rkey))&&($rvalue!="")){ if ((preg_match('/macaddr/', $rkey))&&($rvalue!="")){
$cm = checkmacfree(clean($_REQUEST['vmname']), $rvalue, $db_handle); $cm = checkmacfree(clean($_REQUEST['vmname']), $rvalue, $db_handle);
if ($cm != "0") { if ($cm != "0") {
@ -322,7 +329,6 @@ if (isset($_SESSION['username'])){
$rvalue = "0"; $rvalue = "0";
} }
} }
$rvalue = clean($_REQUEST[$rkey]);
if ($rvalue == "x86_64"){ if ($rvalue == "x86_64"){
$rvalue = "qemu-system-x86_64"; $rvalue = "qemu-system-x86_64";
} elseif ((preg_match('/no drive/', $rvalue))||($rvalue == "no cdrom")){ } elseif ((preg_match('/no drive/', $rvalue))||($rvalue == "no cdrom")){