diff --git a/web/index.php b/web/index.php index 399b34a..3209322 100644 --- a/web/index.php +++ b/web/index.php @@ -123,12 +123,12 @@ function checkmacfree($vmname,$mac,$db_handle){ //delete vms if (isset($_SESSION['username'])){ - if ((isset($_POST['deletevm']))&&(isset($_POST['deletename']))){ + if ((isset($_POST['deleteid']))&&(isset($_POST['deletename']))&&($_POST['delwhat']=="vm")){ if($_SESSION['isadmin']!=1){ echo "you are not allowed to delete vms!"; } else { $vmname = clean($_POST['deletename']); - $vmid = clean($_POST['deletevm']); + $vmid = clean($_POST['deleteid']); $sql="SELECT id FROM vms WHERE vmname='$vmname' AND id='$vmid'"; $res = $db_handle->query($sql); while ($row = $res->fetchArray(SQLITE3_ASSOC)){ @@ -138,6 +138,36 @@ if (isset($_SESSION['username'])){ } } } + } elseif ((isset($_POST['deleteid']))&&(isset($_POST['deletename']))&&($_POST['delwhat']=="user")){ + if($_SESSION['isadmin']!=1){ + echo "you are not allowed to delete users!"; + } else { + $uname = clean($_POST['deletename']); + $uid = clean($_POST['deleteid']); + $sql="SELECT id FROM users WHERE username='$uname' AND id='$uid'"; + $res = $db_handle->query($sql); + while ($row = $res->fetchArray(SQLITE3_ASSOC)){ + $sqld="DELETE FROM users WHERE id='$uid'"; + if ($db_handle->query($sqld)){ + echo "User $uname deleted!"; + } + } + } + } elseif ((isset($_POST['deleteid']))&&(isset($_POST['deletename']))&&($_POST['delwhat']=="server")){ + if($_SESSION['isadmin']!=1){ + echo "you are not allowed to delete vms!"; + } else { + $sname = clean($_POST['deletename']); + $sid = clean($_POST['deleteid']); + $sql="SELECT id FROM servers WHERE hostname='$sname' AND id='$sid'"; + $res = $db_handle->query($sql); + while ($row = $res->fetchArray(SQLITE3_ASSOC)){ + $sqld="DELETE FROM servers WHERE id='$sid'"; + if ($db_handle->query($sqld)){ + echo "Server $sname deleted!"; + } + } + } } //insert new user in db if(isset($_POST['newusername'])){ @@ -194,7 +224,7 @@ if (isset($_SESSION['username'])){ } } //insert new server in db - if(isset($_POST['newservername'])){ + if(isset($_POST['newhostname'])){ if($_SESSION['isadmin']!=1){ echo "you are not allowed to add servers!"; } else { @@ -202,7 +232,8 @@ if (isset($_SESSION['username'])){ $connectstring = clean($_POST['connectstring']); $vmdirectory = clean($_POST['vmdirectory']); $isodirectory = clean($_POST['isodirectory']); - $sqlu="INSERT INTO servers ('hostname','connectstring','vmdirectory','isodirectory') VALUES('$newservername',$connectstring','$vmdirectory','$isodirectory')"; + $sqlu="INSERT INTO servers ('hostname','connectstring','vmdirectory','isodirectory') VALUES('$newservername','$connectstring','$vmdirectory','$isodirectory')"; + //echo $sqlu; $res = $db_handle->query($sqlu); echo "success"; exit; @@ -236,7 +267,7 @@ if (isset($_SESSION['username'])){ $sqlc="("; $sqlv=" VALUES ("; foreach(array_keys($_REQUEST) as $rkey){ - if (($rkey!="mode")||($rkey!="rand")){ + if (($rkey!="mode")&&($rkey!="rand")){ if ((preg_match('/macaddr/', $rkey))&&($rvalue!="")){ $cm = checkmacfree(clean($_REQUEST['vmname']), $rvalue, $db_handle); if ($cm != "0") { @@ -340,7 +371,7 @@ if (isset($_SESSION['username'])){ echo "