From dd711a1bb4f92cc8e8ab9ca192f43917ae4883d5 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Thu, 28 Dec 2017 17:47:56 +0100 Subject: [usb-lock-off] API device delete function now works with the new db struct. --- modules-available/usblockoff/api.inc.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'modules-available') diff --git a/modules-available/usblockoff/api.inc.php b/modules-available/usblockoff/api.inc.php index 708303a8..9467d67b 100644 --- a/modules-available/usblockoff/api.inc.php +++ b/modules-available/usblockoff/api.inc.php @@ -38,8 +38,9 @@ function HandleParameters() ); newDevice($id, $serial, $hwProps, $deviceProps); } elseif ($getAction == "deletedevice") { + $id = Request::get('id', '', 'string'); $serial = Request::get('serial', '', 'string'); - deleteDevice($serial); + deleteDevice($id, $serial); } } @@ -70,7 +71,8 @@ function newDevice($id, $serial, $hwProps, $deviceProps) // Add the hwid -> serial in the usblockoff_hw table if not already existent. $dbquery2 = Database::queryFirst("Select * FROM `usblockoff_hw` WHERE hwid=:hwid AND serial=:serial", array( 'hwid' => $hwid, - 'serial' => $serial)); + 'serial' => $serial + )); if (empty($dbquery2)) { Database::exec("INSERT INTO `usblockoff_hw` (hwid, serial) VALUES (:hwid, :serial)", array( @@ -163,8 +165,19 @@ function newDevice($id, $serial, $name, $ip, $ruleInformation) * * @param string $serial USB-Device serial number. */ -// TODO: Edit for the new db struct. -function deleteDevice($serial) +function deleteDevice($id, $serial) { - $dbquery = Database::exec("DELETE FROM `usb_devices` WHERE serial=:serial", array('serial' => $serial)); + // For the Old db struct + //Database::exec("DELETE FROM `usb_devices` WHERE serial=:serial", array('serial' => $serial)); + + $hw = Database::queryFirst("SELECT * FROM `statistic_hw` WHERE hwname=:id", array('id' => $id)); + if($hw['hwtype'] === DeviceType::USB) { + Database::exec("DELETE FROM `usblockoff_hw` WHERE hwid=:hwid AND serial=:serial", array( + 'hwid' => $hw['hwid'], + 'serial' => $serial)); + echo "Successfully deleted."; + } else { + echo "Type is not a USB device"; + } + } -- cgit v1.2.3-55-g7522