From 28975976602155feb5ac7a7c21307dc834681865 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Thu, 28 Dec 2017 16:28:09 +0100 Subject: [usb-lock-off] Specific usb props only added if the usb device have a serial number. --- modules-available/usblockoff/api.inc.php | 33 ++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/modules-available/usblockoff/api.inc.php b/modules-available/usblockoff/api.inc.php index 318f21a1..708303a8 100644 --- a/modules-available/usblockoff/api.inc.php +++ b/modules-available/usblockoff/api.inc.php @@ -64,23 +64,28 @@ function newDevice($id, $serial, $hwProps, $deviceProps) // TODO: addHwProps('statistic_hw_prop', $hwid, $hwProps); - // 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)); - - if (empty($dbquery2)) { - Database::exec("INSERT INTO `usblockoff_hw` (hwid, serial) VALUES (:hwid, :serial)", array( + // Only when the device has a serial number add the specific hw props. + // TODO: !!! Are there data transfer devices without a serial number? !!! + if (!empty($serial)) { + // 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)); - // Add all the prop values to the usblockoff_hw_prop table. - // PROP: serial, machineuuid, time, user, ruleInformation, Port, hash, interface-policy - addUSBHwProps('usblockoff_hw_prop', $hwid, $serial, $deviceProps); + if (empty($dbquery2)) { + Database::exec("INSERT INTO `usblockoff_hw` (hwid, serial) VALUES (:hwid, :serial)", array( + 'hwid' => $hwid, + 'serial' => $serial + )); + } - echo "Successfully added"; + // Add all the prop values to the usblockoff_hw_prop table. + // PROP: serial, machineuuid, time, user, ruleInformation, Port, hash, interface-policy + addUSBHwProps('usblockoff_hw_prop', $hwid, $serial, $deviceProps); + echo "Successfully added"; + } else { + echo "No specific props were added. Device has no serial number"; + } } function addHwProps($table, $hwid, $propArray) { -- cgit v1.2.3-55-g7522