From 102e47026dcacfa58c877b86e176356ff0931478 Mon Sep 17 00:00:00 2001 From: nativemad Date: Wed, 24 Oct 2018 14:49:05 +0200 Subject: [PATCH] autostart delete tmp files --- nlvmi | 7 +++++++ web/index.php | 16 +++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/nlvmi b/nlvmi index b0c4ff7..197e202 100755 --- a/nlvmi +++ b/nlvmi @@ -300,6 +300,13 @@ if [ $# -gt 0 ]; then elif [ $1 == "checkvm" ]; then if [ -z $2 ]; then echo "checkvm needs two arguments"; fi 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 if [ -z $2 ]; then echo "start needs a vmname!"; exit 1; fi VMFOUND="no" diff --git a/web/index.php b/web/index.php index 5934639..66e5a35 100644 --- a/web/index.php +++ b/web/index.php @@ -141,7 +141,7 @@ if (isset($_SESSION['username'])){ } else { $vmname = clean($_POST['deletename']); $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); while ($row = $res->fetchArray(SQLITE3_ASSOC)){ $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'"; if ($db_handle->query($sqld)){ echo "VM $vmname deleted!"; @@ -301,13 +308,13 @@ if (isset($_SESSION['username'])){ $pres = $db_handle->query($psql); $prioa = $pres->fetchArray(SQLITE3_ASSOC); $prio = $prioa['prio'] + 1; - $mode="newvm"; $sqls="INSERT INTO vms "; $sqlc="("; $sqlv=" VALUES ("; foreach(array_keys($_REQUEST) as $rkey){ if (($rkey!="mode")&&($rkey!="rand")){ + $rvalue = clean($_REQUEST[$rkey]); if ((preg_match('/macaddr/', $rkey))&&($rvalue!="")){ $cm = checkmacfree(clean($_REQUEST['vmname']), $rvalue, $db_handle); if ($cm != "0") { @@ -322,7 +329,6 @@ if (isset($_SESSION['username'])){ $rvalue = "0"; } } - $rvalue = clean($_REQUEST[$rkey]); if ($rvalue == "x86_64"){ $rvalue = "qemu-system-x86_64"; } elseif ((preg_match('/no drive/', $rvalue))||($rvalue == "no cdrom")){ @@ -336,8 +342,8 @@ if (isset($_SESSION['username'])){ $sqlv.=" '$prio')"; $sql = "$sqls$sqlc$sqlv"; $res = $db_handle->exec($sql); - echo "success"; - exit; + echo "success"; + exit; } elseif ($_REQUEST['mode']=="editvm"){ $sql="UPDATE vms SET "; $autostartfound = "0";