From c68121f031d015291f1bf3f90f20de865078561f Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Thu, 18 Jan 2018 18:03:20 +0100 Subject: [usb-lock-off] Added generic rule functionality. Fixed tooltip flickering. Fixed alignment when windows is very small. --- modules-available/usblockoff/lang/de/messages.json | 4 + .../usblockoff/lang/de/template-tags.json | 53 ++++-- modules-available/usblockoff/lang/en/messages.json | 4 + .../usblockoff/lang/en/template-tags.json | 53 ++++-- modules-available/usblockoff/page.inc.php | 94 +++++++++- .../usblockoff/templates/usb-add-generic-rule.html | 195 +++++++++++++++++++++ .../usblockoff/templates/usb-choose-config.html | 58 +++--- .../usblockoff/templates/usb-configuration.html | 29 ++- .../usblockoff/templates/usb-device-list.html | 5 +- 9 files changed, 439 insertions(+), 56 deletions(-) create mode 100644 modules-available/usblockoff/lang/de/messages.json create mode 100644 modules-available/usblockoff/lang/en/messages.json create mode 100644 modules-available/usblockoff/templates/usb-add-generic-rule.html (limited to 'modules-available/usblockoff') diff --git a/modules-available/usblockoff/lang/de/messages.json b/modules-available/usblockoff/lang/de/messages.json new file mode 100644 index 00000000..7ec920b2 --- /dev/null +++ b/modules-available/usblockoff/lang/de/messages.json @@ -0,0 +1,4 @@ +{ + "config-deleted": "Konfiguration erfolgreich gelöscht.", + "config-saved": "Konfiguration erfolgreich gespeichert." +} \ No newline at end of file diff --git a/modules-available/usblockoff/lang/de/template-tags.json b/modules-available/usblockoff/lang/de/template-tags.json index b17eb1fb..3614ed55 100644 --- a/modules-available/usblockoff/lang/de/template-tags.json +++ b/modules-available/usblockoff/lang/de/template-tags.json @@ -1,14 +1,43 @@ { - "lang_howToRuleLang": "Verwendung der Regel Sprache.", - "lang_device": "USB Gerät", - "lang_devices": "USB Geräte", - "lang_general": "Allgemein", - "lang_config": "Konfiguration", - "lang_config_helptext": "Erstelle eine neue Konfiguration oder wähle eine aus, um sie zu Laden und Bearbeiten zu können", - "lang_configName": "Konfigurationsname", - "lang_configName_helptext": "Name der Konfiguration", - "lang_deleteConfig": "Konfiguration Löschen", - "lang_deleteConfig_helptext": "Löscht die Konfiguration aus der Datenbank", - "lang_createNewConfig": "", - "lang_deleteConfigMessage": "Sind sie sicher, dass sie die Konfiguration Löschen wollen?" + "lang_howToRuleLang": "Verwendung der Regel Sprache.", + "lang_device": "USB Gerät", + "lang_devices": "USB Geräte", + "lang_general": "Allgemein", + "lang_config": "Konfiguration", + "lang_config_helptext": "Erstelle eine neue Konfiguration oder wähle eine aus, um sie zu Laden und Bearbeiten zu können", + "lang_configName": "Konfigurationsname", + "lang_configName_helptext": "Name der Konfiguration", + "lang_deleteConfig": "Konfiguration Löschen", + "lang_deleteConfig_helptext": "Löscht die Konfiguration aus der Datenbank", + "lang_createNewConfig": "", + "lang_deleteConfigMessage": "Sind sie sicher, dass sie die Konfiguration Löschen wollen?", + "lang_genericRule": "Generische Regel", + "lang_generalOptions": "Allgemeine Optionen", + "lang_modeOptions": "Modus Optionen", + "lang_deviceClasses": "Geräteklassen", + "lang_classes-helptext": "", + "lang_contains": "Beinhält Interface", + "lang_contains-helptext": "Erlaubt das Gerät selbst wenn es noch zusätzliche Interfaces hat", + "lang_mass-storage": "Massenspeichergeräte", + "lang_hid": "Eingabegeräte", + "lang_hub": "USB Hubs", + "lang_printer": "Drucker", + "lang_audio": "Audiogeräte", + "lang_all-devices": "Alle USB Geräte", + "lang_addRule": "Regel hinzufügen", + "lang_operator": "Operator", + "lang_operator-helptext": "", + "lang_deviceClass": "Geräteklasse", + "lang_deviceClass-helptext": "", + "lang_deviceSubClass": "Gerätesubklasse", + "lang_deviceSubClass-helptext": "", + "lang_deviceProtocol": "Geräteprotokoll", + "lang_deviceProtocol-helptext": "", + "lang_all-of": "Alle von", + "lang_one-of": "Eins von", + "lang_none-of": "Keins von", + "lang_equals": "Gleicht", + "lang_equals-ordered": "Gleicht geordnet", + "lang_saveAsNewConfig": "Als neue Konfiguration Speichern", + "lang_saveAsNewConfig-helptext": "Erstellt eine neue Konfiguration anstatt die alte zu Überschreiben." } diff --git a/modules-available/usblockoff/lang/en/messages.json b/modules-available/usblockoff/lang/en/messages.json new file mode 100644 index 00000000..894ff608 --- /dev/null +++ b/modules-available/usblockoff/lang/en/messages.json @@ -0,0 +1,4 @@ +{ + "config-deleted": "Config successfully deleted.", + "config-saved": "Config successfully saved." +} \ No newline at end of file diff --git a/modules-available/usblockoff/lang/en/template-tags.json b/modules-available/usblockoff/lang/en/template-tags.json index 20529d4a..914b844b 100644 --- a/modules-available/usblockoff/lang/en/template-tags.json +++ b/modules-available/usblockoff/lang/en/template-tags.json @@ -1,14 +1,43 @@ { - "lang_howToRuleLang": "Usage of the Rule Language.", - "lang_device": "usb device", - "lang_devices": "usb devices", - "lang_general": "General", - "lang_config": "Configuration", - "lang_config_helptext": "Create a new configuration or choose one to load and edit it", - "lang_configName": "Configuration name", - "lang_configName_helptext": "The name of the configuration", - "lang_deleteConfig": "Delete configuration", - "lang_deleteConfig_helptext": "Delets the configuration", - "lang_createNewConfig": "", - "lang_deleteConfigMessage": "Are you sure you want to delete the configuration?" + "lang_howToRuleLang": "Usage of the Rule Language.", + "lang_device": "usb device", + "lang_devices": "usb devices", + "lang_general": "General", + "lang_config": "Configuration", + "lang_config_helptext": "Create a new configuration or choose one to load and edit it", + "lang_configName": "Configuration name", + "lang_configName_helptext": "The name of the configuration", + "lang_deleteConfig": "Delete configuration", + "lang_deleteConfig_helptext": "Delets the configuration", + "lang_createNewConfig": "", + "lang_deleteConfigMessage": "Are you sure you want to delete the configuration?", + "lang_genericRule": "generic rule", + "lang_generalOptions": "General options", + "lang_modeOptions": "Mode options", + "lang_deviceClasses": "Device classes", + "lang_classes-helptext": "", + "lang_contains": "Contains interface", + "lang_contains-helptext": "If true the device is allowed if it contains the interface among others", + "lang_mass-storage": "Mass storage devices", + "lang_hid": "Human interface devices", + "lang_hub": "USB Hubs", + "lang_printer": "Printer", + "lang_audio": "Audio devices", + "lang_all-devices": "All USB devices", + "lang_addRule": "Add rule", + "lang_operator": "Operator", + "lang_operator-helptext": "", + "lang_deviceClass": "Device class", + "lang_deviceClass-helptext": "", + "lang_deviceSubClass": "Device subclass", + "lang_deviceSubClass-helptext": "", + "lang_deviceProtocol": "Device protocol", + "lang_deviceProtocol-helptext": "", + "lang_all-of": "All of", + "lang_one-of": "One of", + "lang_none-of": "None of", + "lang_equals": "Equals", + "lang_equals-ordered": "Equals ordered", + "lang_saveAsNewConfig": "Save as new config", + "lang_saveAsNewConfig-helptext": "If true a new config is created instead of overriding the old one" } diff --git a/modules-available/usblockoff/page.inc.php b/modules-available/usblockoff/page.inc.php index d33765f0..9e5664fc 100644 --- a/modules-available/usblockoff/page.inc.php +++ b/modules-available/usblockoff/page.inc.php @@ -56,11 +56,13 @@ class Page_usblockoff extends Page Database::exec("DELETE FROM `usb_configs` WHERE configid=:configid", array('configid' => $configID)); } + Message::addSuccess('config-deleted'); Util::redirect('?do=usblockoff'); } protected function updateConfig() { + $result['saveAsNewConfig'] = Request::post('saveAsNewConfig', false, 'bool'); // Add new settings in usbguard-daemon.conf here: $result['RuleFile'] = Request::post('RuleFile', '', 'string'); $result['ImplicitPolicyTarget'] = Request::post('ImplicitPolicyTarget', '', 'string'); @@ -104,7 +106,7 @@ class Page_usblockoff extends Page } // INSERT IN DB - if ($id == '0') { + if ($id == '0' || $result['saveAsNewConfig']) { $dbquery = Database::exec("INSERT INTO `usb_configs` (configname, rulesconfig, daemonconfig) VALUES (:configname, :rulesconfig, :daemonconfig)", array('configname' => $configname, 'rulesconfig' => $result['rules'], @@ -116,6 +118,7 @@ class Page_usblockoff extends Page 'rulesconfig' => $result['rules'], 'daemonconfig' => implode($newDaemonConf))); } + Message::addSuccess('config-saved'); } /** @@ -133,12 +136,13 @@ class Page_usblockoff extends Page } elseif ($action === 'loadConfig') { $id = Request::any('id', 0, 'int'); $this->ajaxConfig($id); + } elseif ($action === 'genericRuleBuilder') { + $this->ajaxGenericRuleBuilder(); } } private function ajaxConfig($id) { - $form = array(); $rulesConf = null; @@ -180,10 +184,96 @@ class Page_usblockoff extends Page )); } + private function ajaxGenericRuleBuilder() { + $settings = array(); + + // TODO: Translate Operator Action etc.. + + $setting = array(); + $setting['title'] = "Action"; + $setting['select_list'] = array(array( + 'option' => 'allow', + 'active' => true, + ), + array( + 'option' => 'block', + 'active' => false, + ), + array( + 'option' => 'reject', + 'active' => false, + )); + $setting['helptext'] = array('helptext' => Dictionary::translateFile('rule', 'abr_helptext')); + $setting['property'] = 'action'; + $setting['settingHtml'] = Render::parse('server-prop-dropdown', (array)$setting); + $settings[] = $setting; + + /* + $setting = array(); + $setting['title'] = "Operator"; + $setting['select_list'] = array( + array( + 'option' => 'all-of', + 'active' => true, + ), + array( + 'option' => 'one-of', + 'active' => false, + ), + array( + 'option' => 'none-of', + 'active' => false, + ), + array( + 'option' => 'equals', + 'active' => false, + ), + array( + 'option' => 'equals-ordered', + 'active' => false, + ) + ); + $setting['helptext'] = array('helptext' => Dictionary::translateFile('rule', 'operator_helptext')); + $setting['property'] = 'action'; + $setting['settingHtml'] = Render::parse('server-prop-dropdown', (array)$setting); + $settings[] = $setting; + */ + + /* THIS IS DONE in HTML code because server-prop-dropdown doens't have a value option for a selected + $casualMode = array(); + $setting = array(); + // $setting['helptext'] = array('helptext' => Dictionary::translateFile('rule', '')) + $setting['title'] = 'Device Class'; + $setting['select_list'] = array( + array( + 'option' => 'USB-Sticks', + 'active' => true, + ), + array( + 'option' => 'HID-Devices', + 'active' => false, + ), + array( + 'option' => 'All', + 'active' => false, + ) + ); + $setting['property'] = 'action'; + $setting['settingHtml'] = Render::parse('server-prop-dropdown', (array)$setting); + $casualMode[] = $setting;*/ + + echo Render::parse('usb-add-generic-rule', array( + 'settings' => array_values($settings), + /*'casual' => array_values($casualMode)*/ + )); + } + private function ajaxDeviceList() { $usbdevices = $this->getUsbDeviceList(); + // TODO: Translate Operator Action etc.. + $settings = array(); $setting = array(); $setting['title'] = "Action"; diff --git a/modules-available/usblockoff/templates/usb-add-generic-rule.html b/modules-available/usblockoff/templates/usb-add-generic-rule.html new file mode 100644 index 00000000..4e8339c7 --- /dev/null +++ b/modules-available/usblockoff/templates/usb-add-generic-rule.html @@ -0,0 +1,195 @@ +
+
+ + + +
+
{{lang_generalOptions}}
+
+
+ + {{#settings}} + {{{settingHtml}}} + {{/settings}} + +
+
+
+ +
+
{{lang_modeOptions}} + +
+
+
+ +
+ +
+
+
+
+ +
+
+ + + +
+
+
+ +
+
+
+
+ +
+
+ + + +
+
+
+ +
+ + + +
+
+
+ +
+
+ + \ No newline at end of file diff --git a/modules-available/usblockoff/templates/usb-choose-config.html b/modules-available/usblockoff/templates/usb-choose-config.html index 06dcf92f..0ad7213a 100644 --- a/modules-available/usblockoff/templates/usb-choose-config.html +++ b/modules-available/usblockoff/templates/usb-choose-config.html @@ -2,6 +2,7 @@ +
{{lang_general}}
@@ -14,16 +15,14 @@
-
- - -
+ +
-
- -
+
+ +
-
- - -
+ +
@@ -81,6 +92,13 @@ diff --git a/modules-available/usblockoff/templates/usb-device-list.html b/modules-available/usblockoff/templates/usb-device-list.html index a2964987..b5cc82b0 100644 --- a/modules-available/usblockoff/templates/usb-device-list.html +++ b/modules-available/usblockoff/templates/usb-device-list.html @@ -52,7 +52,7 @@
-
Rule Options
+
{{lang_ruleOptions}}
@@ -72,6 +72,9 @@ $('.settings-bs-switch').bootstrapSwitch({size: 'small'}); countSelected(); + // Add handler to the modal Button. + $('#myModalAddButton').unbind().click(addDevices); + function clickRow(tbody, uid) { $(tbody).toggleClass('selected'); countSelected(); -- cgit v1.2.3-55-g7522