From 67899ed609576e40235ca0ab2662035fd1aecd63 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Wed, 28 Mar 2018 18:37:20 +0200 Subject: [usb-lock-off] Added some array_exist_key to prevent invalid index errors. Splitted ID in Vendor and Product showing with names. --- modules-available/usblockoff/lang/de/rule.json | 2 + modules-available/usblockoff/lang/en/rule.json | 2 + modules-available/usblockoff/page.inc.php | 78 ++++++++++++++++++++------ 3 files changed, 66 insertions(+), 16 deletions(-) (limited to 'modules-available') diff --git a/modules-available/usblockoff/lang/de/rule.json b/modules-available/usblockoff/lang/de/rule.json index c0f462df..bb6752ad 100644 --- a/modules-available/usblockoff/lang/de/rule.json +++ b/modules-available/usblockoff/lang/de/rule.json @@ -7,6 +7,8 @@ "vid_helptext": "Die eindeutige ID des Herstellers.", "pid": "Produkt ID", "pid_helptext": "Die Herstellerspezifische ID des Produktes.", + "vendor": "Hersteller", + "product": "Produkt", "serial": "Seriennummer", "serial_helptext": "Seriennummer des USB-Geräts.", "name": "Name", diff --git a/modules-available/usblockoff/lang/en/rule.json b/modules-available/usblockoff/lang/en/rule.json index 07f92227..53682563 100644 --- a/modules-available/usblockoff/lang/en/rule.json +++ b/modules-available/usblockoff/lang/en/rule.json @@ -7,6 +7,8 @@ "vid_helptext": "The unique ID of the vendor.", "pid": "Product ID", "pid_helptext": "The vendor specific ID of the product.", + "vendor": "Vendor", + "product": "Product", "serial": "Serialnumber", "serial_helptext": "Serialnumber of the USB-device.", "name": "Name", diff --git a/modules-available/usblockoff/page.inc.php b/modules-available/usblockoff/page.inc.php index b667e1c8..0f29ef91 100644 --- a/modules-available/usblockoff/page.inc.php +++ b/modules-available/usblockoff/page.inc.php @@ -83,8 +83,14 @@ class Page_usblockoff extends Page foreach ($attributes as $att) { // SPECIAL CASE: PID AND VID needs to put together to VID:PID = ID if (substr($att['prop'], 5) === "vid") { + if (!array_key_exists('id', $a)) { + $a['id'] = ""; + } $a['id'] = $att['value'] . ':' . $a['id']; } else if (substr($att['prop'], 5) === "pid") { + if (!array_key_exists('id', $a)) { + $a['id'] = ""; + } $a['id'] = $a['id'] . $att['value']; } else { $a[substr($att['prop'], 5)] = $att['value']; @@ -257,13 +263,21 @@ class Page_usblockoff extends Page $attr['property'] = 'vid'; $attr['helptext'] = Dictionary::translateFile('rule', "vid_helptext"); - - $attr['select_list'][] = array( - 'option' => $idList[$vid]['name'], - 'active' => true, - 'value' => $vid, - ); - + if (array_key_exists($vid, $idList)) { + $attr['select_list'][] = array( + 'option' => $idList[$vid]['name'], + 'active' => true, + 'value' => $vid, + ); + } else { + $attr['inputtype'] = 'text'; + $attr['value'] = $vid; + $attr['select_list'][] = array( + 'option' => "unknown", + 'active' => true, + 'value' => $vid, + ); + } $attributesHtml = Render::parse('server-prop-dropdown', (array)$attr); $attributes[] = array( 'attributesHtml' => $attributesHtml @@ -275,13 +289,19 @@ class Page_usblockoff extends Page $attr['property'] = 'pid'; $attr['helptext'] = Dictionary::translateFile('rule', "pid_helptext"); - - $attr['select_list'][] = array( - 'option' => $idList[$vid]['products'][$pid], - 'active' => true, - 'value' => $pid, - ); - + if (array_key_exists($pid, $idList)) { + $attr['select_list'][] = array( + 'option' => $idList[$vid]['products'][$pid], + 'active' => true, + 'value' => $pid, + ); + } else { + $attr['select_list'][] = array( + 'option' => "unknown", + 'active' => true, + 'value' => $pid, + ); + } $attributesHtml = Render::parse('server-prop-dropdown', (array)$attr); } else { $attr['inputtype'] = 'text'; @@ -350,12 +370,13 @@ class Page_usblockoff extends Page $sortProductName[] = $v; $sortProductId[] = $k; } - + // TODO: SORT_FLAG_CASE array_multisort($sortProductName, SORT_ASC, $sortProductId, SORT_ASC, $tmp, $keys2); $usblist[$key]['products'] = array_combine($keys2, $tmp); } $keys = array_keys($usblist); + // TODO: SORT_FLAG_CASE array_multisort($sortVendorName, SORT_ASC, $sortVendorId, SORT_ASC, $usblist, $keys); return json_encode(array_combine($keys, $usblist), JSON_HEX_APOS); } @@ -521,12 +542,37 @@ class Page_usblockoff extends Page while ($entry = $dbq->fetch(PDO::FETCH_ASSOC)) { if ($entry['prop'] == "target") { $rule['target'] = $entry['value']; + } else if ($entry['prop'] == "id") { + $idList = json_decode($this->getIDList(), true); + $id = explode(":", $entry['value']); + + if (array_key_exists($id[0], $idList)) { + $vendor = $idList[$id[0]]['name']; + $attributes = []; + $attributes['prop'] = Dictionary::translateFile('rule', 'vendor'); + $attributes['value'] = $vendor; + $rule['attributes'][] = $attributes; + + if (array_key_exists($id[1], $idList[$id[0]]['products'])) { + $product = $idList[$id[0]]['products'][$id[1]]; + $attributes = []; + $attributes['prop'] = Dictionary::translateFile('rule', 'product'); + $attributes['value'] = $product; + $rule['attributes'][] = $attributes; + } + } else { + $attributes = []; + $attributes['prop'] = $entry['prop']; + $attributes['value'] = $entry['value']; + $rule['attributes'][] = $attributes; + } + } else { $attributes = []; $attributes['prop'] = $entry['prop']; $attributes['value'] = $entry['value']; - if(sizeof($rule['attributes']) >= 3) { + if(sizeof($rule['attributes']) >= 5) { $rule['hasoverload'] = true; $rule['num_overload'] += 1; $rule['attributes_overload'] .= $attributes['prop'] . ': ' . $attributes['value'] . "
"; -- cgit v1.2.3-55-g7522