diff options
Diffstat (limited to 'modules-available/usblockoff/api.inc.php')
-rw-r--r-- | modules-available/usblockoff/api.inc.php | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/modules-available/usblockoff/api.inc.php b/modules-available/usblockoff/api.inc.php index 6a5e4a7d..67f805f5 100644 --- a/modules-available/usblockoff/api.inc.php +++ b/modules-available/usblockoff/api.inc.php @@ -35,6 +35,9 @@ function HandleParameters() $id = Request::get('id', '', 'string'); $serial = Request::get('serial', '', 'string'); deleteDevice($id, $serial); + } elseif ($getAction == "getrule") { + $configid = Request::get('configid', '0', 'int'); + getRule($configid); } } @@ -83,6 +86,42 @@ function newDevice($id, $serial, $hwProps, $deviceProps) } } +function getRule($configid) { + // Get the config from the db. + $config = Database::queryFirst("SELECT * FROM `usb_configs` WHERE configid=:configid", array( + "configid" => $configid + )); + $idList = array(); + $rules = array(); + // For each $id get the rule information and build the rule. + foreach (json_decode($config['rulesconfig']) as $id) { + $idList[] = $id; + + // TODO: Make more efficient with one query instead of one per id. + + $dbquery = Database::simpleQuery("SELECT * FROM `usb_rule_prop` WHERE ruleid=:id", array( + "id" => $id + )); + $rule = ""; + while ($attribute = $dbquery->fetch(PDO::FETCH_ASSOC)) { + if ($attribute['prop'] == "target") { + $rule = $attribute['value'] . $rule; + } else { + if ($attribute['prop'] == "serial" || $attribute['prop'] == "name" || $attribute['prop'] == "hash" || + $attribute['prop'] == "parent-hash" || $attribute['prop'] == "via-port") { + $rule = $rule . " " . $attribute['prop'] . " \"" . $attribute['value'] . "\""; + } else { + $rule = $rule . " " . $attribute['prop'] . " " . $attribute['value']; + } + } + } + $rules[] = $rule; + } + + // Return the completed rules.conf. + echo implode("\n", $rules); +} + function addHwProps($table, $hwid, $propArray) { foreach ($propArray as $prop => $value) { if (empty($value)) { |