summaryrefslogtreecommitdiffstats
path: root/modules-available
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available')
-rw-r--r--modules-available/statistics/inc/devicetype.inc.php1
-rw-r--r--modules-available/usblockoff/api.inc.php129
-rw-r--r--modules-available/usblockoff/config.json4
-rw-r--r--modules-available/usblockoff/inc/default-configs/rules.conf0
-rw-r--r--modules-available/usblockoff/inc/default-configs/usbguard-daemon.conf160
-rw-r--r--modules-available/usblockoff/install.inc.php66
-rw-r--r--modules-available/usblockoff/lang/de/messages.json4
-rw-r--r--modules-available/usblockoff/lang/de/module.json4
-rw-r--r--modules-available/usblockoff/lang/de/rule.json19
-rw-r--r--modules-available/usblockoff/lang/de/template-tags.json51
-rw-r--r--modules-available/usblockoff/lang/en/messages.json4
-rw-r--r--modules-available/usblockoff/lang/en/module.json4
-rw-r--r--modules-available/usblockoff/lang/en/rule.json19
-rw-r--r--modules-available/usblockoff/lang/en/template-tags.json51
-rw-r--r--modules-available/usblockoff/page.inc.php339
-rw-r--r--modules-available/usblockoff/templates/server-prop-bool.html16
-rw-r--r--modules-available/usblockoff/templates/server-prop-dropdown.html19
-rw-r--r--modules-available/usblockoff/templates/server-prop-generic.html16
-rw-r--r--modules-available/usblockoff/templates/usb-add-generic-rule.html195
-rw-r--r--modules-available/usblockoff/templates/usb-configuration-table.html70
-rw-r--r--modules-available/usblockoff/templates/usb-daemon-config.html26
-rw-r--r--modules-available/usblockoff/templates/usb-device-list.html169
-rw-r--r--modules-available/usblockoff/templates/usb-edit-config.html68
-rw-r--r--modules-available/usblockoff/templates/usb-rules-config.html105
24 files changed, 1539 insertions, 0 deletions
diff --git a/modules-available/statistics/inc/devicetype.inc.php b/modules-available/statistics/inc/devicetype.inc.php
index 41ee237d..571d6d2c 100644
--- a/modules-available/statistics/inc/devicetype.inc.php
+++ b/modules-available/statistics/inc/devicetype.inc.php
@@ -3,4 +3,5 @@
class DeviceType
{
const SCREEN = 'SCREEN';
+ const USB = 'USB';
}
diff --git a/modules-available/usblockoff/api.inc.php b/modules-available/usblockoff/api.inc.php
new file mode 100644
index 00000000..6a5e4a7d
--- /dev/null
+++ b/modules-available/usblockoff/api.inc.php
@@ -0,0 +1,129 @@
+<?php
+
+HandleParameters();
+
+function HandleParameters()
+{
+ $getAction = Request::get('action', 0, 'string');
+ if ($getAction == "newdevice") {
+ $id = Request::get('id', '', 'string');
+ $serial = Request::get('serial', '', 'sting');
+ $name = Request::get('name', '', 'string');
+ $ip = Request::get('ip', 0, 'string');
+ $client = Database::queryFirst("SELECT m.machineuuid AS 'muid', m.currentuser AS 'user' FROM machine AS m WHERE m.clientip=:ip", array('ip' => $ip));
+
+ // TODO: product and vendor id necessary? It's already in the hwname part.
+ list($vid, $pid) = explode(':', $id);
+ $hwProps = array(
+ 'vendorid' => $vid,
+ 'productid' => $pid,
+ 'name' => $name,
+ 'with-interface' => Request::get('with-interface', '', 'string')
+ );
+ // TODO: WITH INTERFACE in the HW table?! Should be equal for every device but not guaranteed (ODROID).
+ $deviceProps = array(
+ 'hash' => Request::get('hash', '', 'string'),
+ 'parent-hash' => Request::get('parent-hash', '', 'string'),
+ 'via-port' => Request::get('via-port', '', 'string'),
+ 'interface-policy' => Request::get('interface-policy', '', 'string'),
+ 'machineuuid' => $client['muid'],
+ 'user' => $client['user'],
+ 'lastseen' => time()
+ );
+ newDevice($id, $serial, $hwProps, $deviceProps);
+ } elseif ($getAction == "deletedevice") {
+ $id = Request::get('id', '', 'string');
+ $serial = Request::get('serial', '', 'string');
+ deleteDevice($id, $serial);
+ }
+}
+
+/**
+ * Adds a new USB-Device to the db.
+ *
+ * @param string $id USB-Device id.
+ * @param string $serial USB-Device serial number.
+ * @param string $name USB-Device name.
+ */
+function newDevice($id, $serial, $hwProps, $deviceProps)
+{
+ // Add or Update the usb device in the statistic_hw table.
+ $hwid = (int)Database::insertIgnore('statistic_hw', 'hwid', array(
+ 'hwtype' => DeviceType::USB,
+ 'hwname' => $id));
+ // TODO: Is it okay to use the id (vendor:product) as hwname to identify a usb device?
+
+ // Add all the global prop values to the statistics_hw_prop table.
+ // productid, vendorid, name, interfaces
+ // TODO:
+ addHwProps('statistic_hw_prop', $hwid, $hwProps);
+
+ // 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
+ ));
+
+ if (empty($dbquery2)) {
+ Database::exec("INSERT INTO `usblockoff_hw` (hwid, serial) VALUES (:hwid, :serial)", array(
+ 'hwid' => $hwid,
+ '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);
+ echo "Successfully added";
+ } else {
+ echo "No specific props were added. Device has no serial number";
+ }
+}
+
+function addHwProps($table, $hwid, $propArray) {
+ foreach ($propArray as $prop => $value) {
+ if (empty($value)) {
+ continue;
+ }
+ Database::exec("INSERT INTO " . $table . " (hwid, prop, value) VALUES (:hwid, :prop, :value) ON DUPLICATE KEY UPDATE value=:value", array(
+ 'hwid' => $hwid,
+ 'prop' => $prop,
+ 'value' => $value
+ ));
+ }
+}
+
+function addUSBHwProps($table, $hwid, $serial, $propArray) {
+ foreach ($propArray as $prop => $value) {
+ if (empty($value)) {
+ continue;
+ }
+ Database::exec("INSERT INTO " . $table . " (hwid, serial, prop, value) VALUES (:hwid, :serial, :prop, :value) ON DUPLICATE KEY UPDATE value=:value", array(
+ 'hwid' => $hwid,
+ 'serial' => $serial,
+ 'prop' => $prop,
+ 'value' => $value
+ ));
+ }
+}
+
+/**
+ * Deletes a device from the db given a serial number.
+ *
+ * @param string $serial USB-Device serial number.
+ */
+function deleteDevice($id, $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";
+ }
+}
diff --git a/modules-available/usblockoff/config.json b/modules-available/usblockoff/config.json
new file mode 100644
index 00000000..12049689
--- /dev/null
+++ b/modules-available/usblockoff/config.json
@@ -0,0 +1,4 @@
+{
+ "category":"main.beta",
+ "dependencies": ["bootstrap_switch", "bootstrap_dialog", "statistics", "permissionmanager"]
+}
diff --git a/modules-available/usblockoff/inc/default-configs/rules.conf b/modules-available/usblockoff/inc/default-configs/rules.conf
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/modules-available/usblockoff/inc/default-configs/rules.conf
diff --git a/modules-available/usblockoff/inc/default-configs/usbguard-daemon.conf b/modules-available/usblockoff/inc/default-configs/usbguard-daemon.conf
new file mode 100644
index 00000000..44f2d66c
--- /dev/null
+++ b/modules-available/usblockoff/inc/default-configs/usbguard-daemon.conf
@@ -0,0 +1,160 @@
+#
+# Rule set file path.
+#
+# The USBGuard daemon will use this file to load the policy
+# rule set from it and to write new rules received via the
+# IPC interface.
+#
+# RuleFile=/path/to/rules.conf
+#
+RuleFile=/usr/local/etc/usbguard/rules.conf
+
+#
+# Implicit policy target.
+#
+# How to treat devices that don't match any rule in the
+# policy. One of:
+#
+# * allow - authorize the device
+# * block - block the device
+# * reject - remove the device
+#
+ImplicitPolicyTarget=allow
+
+#
+# Present device policy.
+#
+# How to treat devices that are already connected when the
+# daemon starts. One of:
+#
+# * allow - authorize every present device
+# * block - deauthorize every present device
+# * reject - remove every present device
+# * keep - just sync the internal state and leave it
+# * apply-policy - evaluate the ruleset for every present
+# device
+#
+PresentDevicePolicy=apply-policy
+
+#
+# Present controller policy.
+#
+# How to treat USB controllers that are already connected
+# when the daemon starts. One of:
+#
+# * allow - authorize every present device
+# * block - deauthorize every present device
+# * reject - remove every present device
+# * keep - just sync the internal state and leave it
+# * apply-policy - evaluate the ruleset for every present
+# device
+#
+PresentControllerPolicy=keep
+
+#
+# Inserted device policy.
+#
+# How to treat USB devices that are already connected
+# *after* the daemon starts. One of:
+#
+# * block - deauthorize every present device
+# * reject - remove every present device
+# * apply-policy - evaluate the ruleset for every present
+# device
+#
+InsertedDevicePolicy=apply-policy
+
+#
+# Restore controller device state.
+#
+# The USBGuard daemon modifies some attributes of controller
+# devices like the default authorization state of new child device
+# instances. Using this setting, you can controll whether the
+# daemon will try to restore the attribute values to the state
+# before modificaton on shutdown.
+#
+# SECURITY CONSIDERATIONS: If set to true, the USB authorization
+# policy could be bypassed by performing some sort of attack on the
+# daemon (via a local exploit or via a USB device) to make it shutdown
+# and restore to the operating-system default state (known to be permissive).
+#
+RestoreControllerDeviceState=false
+
+#
+# Device manager backend
+#
+# Which device manager backend implementation to use. One of:
+#
+# * uevent - Netlink based implementation which uses sysfs to scan for present
+# devices and an uevent netlink socket for receiving USB device
+# related events.
+# * dummy - A dummy device manager which simulates several devices and device
+# events. Useful for testing.
+#
+DeviceManagerBackend=uevent
+
+#!!! WARNING: It's good practice to set at least one of the !!!
+#!!! two options bellow. If none of them are set, !!!
+#!!! the daemon will accept IPC connections from !!!
+#!!! anyone, thus allowing anyone to modify the !!!
+#!!! rule set and (de)authorize USB devices. !!!
+
+#
+# Users allowed to use the IPC interface.
+#
+# A space delimited list of usernames that the daemon will
+# accept IPC connections from.
+#
+# IPCAllowedUsers=username1 username2 ...
+#
+IPCAllowedUsers=root
+
+#
+# Groups allowed to use the IPC interface.
+#
+# A space delimited list of groupnames that the daemon will
+# accept IPC connections from.
+#
+# IPCAllowedGroups=groupname1 groupname2 ...
+#
+IPCAllowedGroups=
+
+#
+# IPC access control definition files path.
+#
+# The files at this location will be interpreted by the daemon
+# as access control definition files. The (base)name of a file
+# should be in the form:
+#
+# [user][:<group>]
+#
+# and should contain lines in the form:
+#
+# <section>=[privilege] ...
+#
+# This way each file defines who is able to connect to the IPC
+# bus and what privileges he has.
+#
+IPCAccessControlFiles=/usr/local/etc/usbguard/IPCAccessControl.d/
+
+#
+# Generate device specific rules including the "via-port"
+# attribute.
+#
+# This option modifies the behavior of the allowDevice
+# action. When instructed to generate a permanent rule,
+# the action can generate a port specific rule. Because
+# some systems have unstable port numbering, the generated
+# rule might not match the device after rebooting the system.
+#
+# If set to false, the generated rule will still contain
+# the "parent-hash" attribute which also defines an association
+# to the parent device. See usbguard-rules.conf(5) for more
+# details.
+#
+DeviceRulesWithPort=false
+
+#
+# USBGuard audit events log file path.
+#
+AuditFilePath=/usr/local/var/log/usbguard/usbguard-audit.log
diff --git a/modules-available/usblockoff/install.inc.php b/modules-available/usblockoff/install.inc.php
new file mode 100644
index 00000000..967771d1
--- /dev/null
+++ b/modules-available/usblockoff/install.inc.php
@@ -0,0 +1,66 @@
+<?php
+
+$res = array();
+/*
+$t1 = $res[] = tableCreate('usb_devices', '
+ `uid` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ `id` varchar(50),
+ `serial` varchar(512) NOT NULL DEFAULT 0,
+ `name` varchar(1024) CHARACTER SET ascii DEFAULT NULL,
+ `machineuuid` char(36) CHARACTER SET ascii DEFAULT NULL,
+ `time` INT(11) NOT NULL DEFAULT 0,
+ `user` varchar(8),
+ `ruleInformation` varchar(1024),
+ PRIMARY KEY (`uid`)
+');
+*/
+
+$t1 = $res[] = tableCreate('usblockoff_hw', '
+ `hwid` INT(10) UNSIGNED NOT NULL ,
+ `serial` VARCHAR(128),
+ PRIMARY KEY (`hwid`, `serial`)
+');
+
+$t2 = $res[] = tableCreate('usblockoff_hw_prop', '
+ `hwid` INT(10) UNSIGNED NOT NULL ,
+ `serial` VARCHAR(128),
+ `prop` CHAR(16),
+ `value` VARCHAR(500),
+ PRIMARY KEY (`hwid`, `serial`, `prop`)
+');
+
+// TODO: ADD CONSTRAINT
+
+$res[] = tableCreate('usb_configs', '
+ `configid` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+ `configname` VARCHAR(200) NOT NULL,
+ `rulesconfig` BLOB,
+ `daemonconfig` BLOB,
+ PRIMARY KEY (`configid`)
+');
+
+//$ret = Database::exec("DROP TABLE `usb_devices`");
+//$ret = Database::exec("DROP TABLE `usblockoff_hw`");
+//$ret = Database::exec("DROP TABLE `usblockoff_hw_prop`");
+
+if ($t1 === UPDATE_DONE || $t2 === UPDATE_DONE) {
+ $ret = Database::exec('ALTER TABLE `usblockoff_hw`
+ ADD CONSTRAINT `usblockoff_hw_ibfk_1` FOREIGN KEY (`hwid`) REFERENCES `statistic_hw` (`hwid`) ON DELETE CASCADE');
+ if ($ret === false) {
+ finalResponse(UPDATE_FAILED, 'Adding constraints to usblockoff_hw failed: ' . Database::lastError());
+ }
+
+ $ret = Database::exec('ALTER TABLE `usblockoff_hw_prop`
+ ADD CONSTRAINT `usblockoff_hw__prop_ibfk_1` FOREIGN KEY (`hwid`, `serial`) REFERENCES `usblockoff_hw` (`hwid`, `serial`) ON DELETE CASCADE');
+ if ($ret === false) {
+ finalResponse(UPDATE_FAILED, 'Adding constraints to usblockoff_hw_prop failed: ' . Database::lastError());
+ }
+ $res[] = UPDATE_DONE;
+}
+
+
+if (in_array(UPDATE_DONE, $res)) {
+ finalResponse(UPDATE_DONE, 'Table created successfully');
+}
+
+finalResponse(UPDATE_NOOP, 'Everything already up to date');
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/module.json b/modules-available/usblockoff/lang/de/module.json
new file mode 100644
index 00000000..bfde75fe
--- /dev/null
+++ b/modules-available/usblockoff/lang/de/module.json
@@ -0,0 +1,4 @@
+{
+ "module_name": "USB Lock-Off",
+ "page_title": "USB Lock-Off"
+}
diff --git a/modules-available/usblockoff/lang/de/rule.json b/modules-available/usblockoff/lang/de/rule.json
new file mode 100644
index 00000000..0af86c37
--- /dev/null
+++ b/modules-available/usblockoff/lang/de/rule.json
@@ -0,0 +1,19 @@
+{
+ "abr_helptext": "allow: Autorisiert das Gerät.\u000Dblock: Blockiert das Gerät.\u000Dreject: Entfernt das Gerät aus dem System.",
+ "id": "ID",
+ "id_helptext": "ID des USB-Geräts.",
+ "serial": "Seriennummer",
+ "serial_helptext": "Seriennummer des USB-Geräts.",
+ "name": "Name",
+ "name_helptext": "Name des USB-Geräts.",
+ "hash": "Hashwert",
+ "hash_helptext": "Hashwert des USB-Geräts. Von USBGuard mittels sodium oder gcrypt berechnet.",
+ "parent-hash": "Parent-Hashwert",
+ "parent-hash_helptext": "Hashwert des Client an dem das USB-Gerät angeschlossen wurde.",
+ "via-port": "Erlaubte Ports",
+ "via-port_helptext": "USB-Port(s), an welche das USB-Gerät angeschlossen werden kann.",
+ "with-interface": "Interfaces",
+ "with-interface_helptext": "Die Interfaces, welches das USB-Gerät besitzt.",
+ "interface-policy": "Interface Police",
+ "interface-policy_helptext": "Per-Interface Authorisierung."
+}
diff --git a/modules-available/usblockoff/lang/de/template-tags.json b/modules-available/usblockoff/lang/de/template-tags.json
new file mode 100644
index 00000000..16466922
--- /dev/null
+++ b/modules-available/usblockoff/lang/de/template-tags.json
@@ -0,0 +1,51 @@
+{
+ "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": "<Neue Konfiguration erstellen>",
+ "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.",
+ "lang_add-generic-rule": "Generische Regel hinzufügen",
+ "lang_device-list": "Geräte Liste",
+ "lang_rulesConfig": "Regel Konfiguration",
+ "lang_daemonConfig": "Daemon Konfiguration",
+ "lang_assignMenu": "Zuweisungsmenü",
+ "lang_serverName": "Servername",
+ "lang_configuration": "Konfiguration",
+ "lang_usb-lock-off": "USB Lock-Off"
+}
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/module.json b/modules-available/usblockoff/lang/en/module.json
new file mode 100644
index 00000000..bfde75fe
--- /dev/null
+++ b/modules-available/usblockoff/lang/en/module.json
@@ -0,0 +1,4 @@
+{
+ "module_name": "USB Lock-Off",
+ "page_title": "USB Lock-Off"
+}
diff --git a/modules-available/usblockoff/lang/en/rule.json b/modules-available/usblockoff/lang/en/rule.json
new file mode 100644
index 00000000..d2e7b8ca
--- /dev/null
+++ b/modules-available/usblockoff/lang/en/rule.json
@@ -0,0 +1,19 @@
+{
+ "abr_helptext": "allow: authorize the device.\u000Dblock: block the device.\u000DReject: remove the device from the system.",
+ "id": "ID",
+ "id_helptext": "ID of the USB-device.",
+ "serial": "Serialnumber",
+ "serial_helptext": "Serialnumber of the USB-device.",
+ "name": "Name",
+ "name_helptext": "Name of the USB-device.",
+ "hash": "Hash value",
+ "hash_helptext": "Hash value of the USB-device. Calculated via USBGuard through sodium or gcrypt.",
+ "parent-hash": "Parent-hash value",
+ "parent-hash_helptext": "Hash value of the Client the USB-device was connected.",
+ "via-port": "Via port",
+ "via-port_helptext": "Accepted USB-port(s) for the USB-device.",
+ "with-interface": "Interfaces",
+ "with-interface_helptext": "Interfaces of the USB-device.",
+ "interface-policy": "interface-policy",
+ "interface-policy_helptext": "Per-interface authorisation."
+}
diff --git a/modules-available/usblockoff/lang/en/template-tags.json b/modules-available/usblockoff/lang/en/template-tags.json
new file mode 100644
index 00000000..bfa52caf
--- /dev/null
+++ b/modules-available/usblockoff/lang/en/template-tags.json
@@ -0,0 +1,51 @@
+{
+ "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": "<create new configuration>",
+ "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",
+ "lang_add-generic-rule": "Add generic rule",
+ "lang_device-list": "Device list",
+ "lang_rulesConfig": "Rules config",
+ "lang_daemonConfig": "Daemon config",
+ "lang_assignMenu": "Assign menu",
+ "lang_serverName": "Server name",
+ "lang_configuration": "Configuration",
+ "lang_usb-lock-off": "USB lock off"
+}
diff --git a/modules-available/usblockoff/page.inc.php b/modules-available/usblockoff/page.inc.php
new file mode 100644
index 00000000..5e1b27b4
--- /dev/null
+++ b/modules-available/usblockoff/page.inc.php
@@ -0,0 +1,339 @@
+<?php
+$glob3 = 'globale Variable 3';
+$name = 'testname';
+$logedIn = true;
+
+class Page_usblockoff extends Page
+{
+
+ /**
+ * Called before any page rendering happens - early hook to check parameters etc.
+ */
+ protected function doPreprocess()
+ {
+ User::load();
+
+ if (!User::isLoggedIn()) {
+ Message::addError('main.no-permission');
+ Util::redirect('?do=Main'); // does not return
+ }
+
+ $this->action = Request::any('action');
+
+ if ($this->action === 'updateConfig') {
+ $this->updateConfig();
+ } elseif ($this->action === 'deleteConfig') {
+ $this->deleteConfig();
+ }
+ }
+
+ /**
+ * Menu etc. has already been generated, now it's time to generate page content.
+ */
+ protected function doRender()
+ {
+ $show = Request::get("show", "config-table");
+ if ($show === "config-table") {
+ $this->loadConfigChooser();
+ } else if ($show === "edit-config") {
+ $configid = Request::get("configid", "");
+ $configName = Database::queryFirst("SELECT configname FROM `usb_configs` WHERE configid=:id", array(
+ 'id' => $configid
+ ));
+
+ $rulesConfigHtml = $this->loadRulesConfig($configid);
+ $daemonConfigHtml = $this->loadDaemonConfig($configid);
+
+ Render::addTemplate('usb-edit-config', array(
+ 'configid' => $configid,
+ 'configName' => $configName['configname'],
+ 'rulesConfigHtml' => $rulesConfigHtml,
+ 'daemonConfigHtml' => $daemonConfigHtml
+ ));
+ }
+ }
+
+ protected function loadConfigChooser()
+ {
+ $dbquery = Database::simpleQuery("SELECT configid, configname FROM `usb_configs`");
+ $configs = array();
+ while ($dbentry = $dbquery->fetch(PDO::FETCH_ASSOC)) {
+ $config['config_id'] = $dbentry['configid'];
+ $config['config_name'] = $dbentry['configname'];
+ $configs[] = $config;
+ }
+ Render::addTemplate('usb-configuration-table', array('config_list' => array_values($configs)));
+ }
+
+ protected function deleteConfig()
+ {
+ $configID = Request::any('id', 0, 'int');
+
+ if ($configID != 0) {
+ 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');
+ $result['PresentDevicePolicy'] = Request::post('PresentDevicePolicy', '', 'string');
+ $result['PresentControllerPolicy'] = Request::post('PresentControllerPolicy', '', 'string');
+ $result['InsertedDevicePolicy'] = Request::post('InsertedDevicePolicy', '', 'string');
+ $result['RestoreControllerDeviceState'] = Request::post('RestoreControllerDeviceState', '', 'string');
+ $result['DeviceManagerBackend'] = Request::post('DeviceManagerBackend', '', 'string');
+ $result['IPCAllowedUsers'] = Request::post('IPCAllowedUsers', '', 'string');
+ $result['IPCAllowedGroups'] = Request::post('IPCAllowedGroups', '', 'string');
+ $result['IPCAccessControlFiles'] = Request::post('IPCAccessControlFiles', '', 'string');
+ $result['DeviceRulesWithPort'] = Request::post('DeviceRulesWithPort', '', 'string');
+ $result['AuditFilePath'] = Request::post('AuditFilePath', '', 'string');
+ $result['rules'] = Request::post('rules', '', 'string');
+
+ $id = Request::post('id', 0, 'int');
+ $configname = Request::post('configName', '', 'string');
+ $dbquery = Database::queryFirst("SELECT * FROM `usb_configs` WHERE configid=:id", array('id' => $id));
+
+ // Load daemon.conf from db else load default
+ if ($dbquery !== false) {
+ $daemonConf = explode("\r\n", $dbquery['daemonconfig']);
+ } else {
+ $currentdir = getcwd();
+ $file = $currentdir . '/modules/usblockoff/inc/default-configs/usbguard-daemon.conf';
+ $daemonConf = file($file);
+ }
+ $newDaemonConf = array();
+
+ foreach ($daemonConf as $line) {
+ $t_line = trim($line, "\r\n");
+ if ($t_line == '' || $t_line[0] == '#') {
+ $newDaemonConf[] = $line . "\r\n";
+ continue;
+ } else {
+ $splitstr = explode('=', $line);
+
+ $splitstr[1] = $result[$splitstr[0]];
+ $newDaemonConf[] = implode('=', $splitstr) . "\r\n";
+ }
+ }
+
+ // INSERT IN DB
+ 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'],
+ 'daemonconfig' => implode($newDaemonConf)));
+ } else {
+ $dbquery = Database::exec("UPDATE `usb_configs` SET configname=:configname, rulesconfig=:rulesconfig, daemonconfig=:daemonconfig WHERE configid=:configid",
+ array('configid' => $id,
+ 'configname' => $configname,
+ 'rulesconfig' => $result['rules'],
+ 'daemonconfig' => implode($newDaemonConf)));
+ }
+ Message::addSuccess('config-saved');
+ }
+
+ private function loadRulesConfig($id) {
+ $rulesConf = null;
+
+ if ($id == 0) {
+ $currentdir = getcwd();
+
+ $rulesConf = file_get_contents($currentdir . '/modules/usblockoff/inc/default-configs/rules.conf');
+ } else {
+ $dbquery = Database::queryFirst("SELECT * FROM `usb_configs` WHERE configid=:id", array('id' => $id));
+ $rulesConf = $dbquery['rulesconfig'];
+ }
+
+ return Render::parse('usb-rules-config', array(
+ 'rules' => $rulesConf,
+ ));
+ }
+
+ private function loadDaemonConfig($id)
+ {
+ $form = array();
+ $rulesConf = null;
+
+ if ($id == 0) {
+ $currentdir = getcwd();
+
+ $daemonConf = file($currentdir . '/modules/usblockoff/inc/default-configs/usbguard-daemon.conf');
+ } else {
+ $dbquery = Database::queryFirst("SELECT * FROM `usb_configs` WHERE configid=:id", array('id' => $id));
+ $daemonConf = explode("\r\n", $dbquery['daemonconfig']);
+ }
+
+ $element = array();
+ $hlptxt = '';
+
+ foreach ($daemonConf as $line) {
+ $t_line = trim($line, "\r\n");
+ if ($t_line == '#' || $t_line == '' || strpos($t_line, '#!!!') !== false) {
+ continue;
+ } elseif ($t_line[0] == '#') {
+ $ttxt = trim($line, "#");
+ $hlptxt .= $ttxt . '<br>';
+ } else {
+ $splitstr = explode('=', $t_line);
+ $element['name'] = $splitstr[0];
+ $element['value'] = $splitstr[1];
+ $element['helptext'] = $hlptxt;
+
+ $form[] = $element;
+ $hlptxt = '';
+ }
+ }
+
+ return Render::parse('usb-daemon-config', array(
+ 'list' => array_values($form),
+ ));
+ }
+
+ /**
+ * AJAX
+ */
+ protected function doAjax()
+ {
+ User::load();
+ if (!User::isLoggedIn()) {
+ die('Unauthorized');
+ }
+ $action = Request::any('action');
+ if ($action === 'deviceList') {
+ $this->ajaxDeviceList();
+ } elseif ($action === 'genericRuleBuilder') {
+ $this->ajaxGenericRuleBuilder();
+ }
+ }
+
+
+
+ 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;
+
+ echo Render::parse('usb-add-generic-rule', array(
+ 'settings' => array_values($settings),
+ ));
+ }
+
+ private function ajaxDeviceList()
+ {
+ $usbdevices = $this->getUsbDeviceList();
+
+ // TODO: Translate Operator Action etc..
+
+ $settings = array();
+ $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;
+
+ $ruleValues = array('id' => true,
+ 'serial' => true,
+ 'name' => true,
+ 'hash' => false,
+ 'parent-hash' => false,
+ 'via-port' => false,
+ 'with-interface' => false,
+ 'interface-policy' => false);
+ foreach ($ruleValues as $key => $value) {
+ $settings[] = array(
+ 'settingHtml' => Render::parse('server-prop-bool', array('title' => Dictionary::translateFile('rule', $key),
+ 'helptext' => array('helptext' => Dictionary::translateFile('rule', $key . "_helptext")),
+ 'property' => $key,
+ 'currentvalue' => $value)),
+ );
+ }
+ echo Render::parse('usb-device-list', array(
+ 'list' => array_values($usbdevices),
+ 'settings' => array_values($settings)
+ ));
+ }
+
+ private function getUsbDeviceList() {
+ $usbdevices = array();
+
+ // TODO: Per USB Device 3 querys are executed.. better build a more complex sql query?
+ $uid = 0;
+ $dbquery = Database::simpleQuery("SELECT * FROM `usblockoff_hw`");
+ while ($entry = $dbquery->fetch(PDO::FETCH_ASSOC)) {
+
+ $device = array();
+
+ // Get all props from the hw table.
+ $dbquery2 = Database::simpleQuery("SELECT * FROM `statistic_hw_prop` WHERE hwid=:hwid", array(
+ 'hwid' => $entry['hwid']
+ ));
+
+ while ($prop = $dbquery2->fetch(PDO::FETCH_ASSOC)) {
+ $device[$prop['prop']] = $prop['value'];
+ }
+
+ // Get all props from the device table.
+ $dbquery3 = Database::simpleQuery("SELECT * FROM `usblockoff_hw_prop` WHERE hwid=:hwid AND serial=:serial", array(
+ 'hwid' => $entry['hwid'],
+ 'serial' => $entry['serial']
+ ));
+
+ while ($prop = $dbquery3->fetch(PDO::FETCH_ASSOC)) {
+ $device[$prop['prop']] = $prop['value'];
+ }
+ if (!empty($device['machineuuid'])) {
+ $locationquery = Database::queryFirst("SELECT l.locationname AS 'name', m.clientip AS 'ip' FROM machine AS m JOIN location AS l ON l.locationid=m.locationid
+ WHERE m.machineuuid=:machineuuid", array('machineuuid' => $entry['machineuuid']));
+ $device['clientip'] = $locationquery['ip'];
+ $device['location'] = $locationquery['name'];
+ }
+
+ $device['uid'] = ++$uid;
+ $device['id'] = $device['vendorid'] . ":" . $device['productid'];
+ $device['serial'] = $entry['serial'];
+ $device['date'] = date('d.m.Y', $device['lastseen']);
+ $device['time'] = date('G:i', $device['lastseen']);
+ $usbdevices[] = $device;
+ }
+
+ return $usbdevices;
+ }
+}
diff --git a/modules-available/usblockoff/templates/server-prop-bool.html b/modules-available/usblockoff/templates/server-prop-bool.html
new file mode 100644
index 00000000..de7c990a
--- /dev/null
+++ b/modules-available/usblockoff/templates/server-prop-bool.html
@@ -0,0 +1,16 @@
+<div class="list-group-item">
+ <div class="row">
+ <div class="col-md-3"><label for="prop-{{property}}">{{title}}</label></div>
+ <div class="col-md-7">
+ <input class="settings-bs-switch" id="prop-{{property}}" type="checkbox" name="prop-{{property}}" value="1"
+ {{#currentvalue}}checked{{/currentvalue}}>
+ </div>
+ <div class="col-md-2">
+ {{#helptext}}
+ <a class="btn btn-default" title="{{helptext}}">
+ <span class="glyphicon glyphicon-question-sign"></span>
+ </a>
+ {{/helptext}}
+ </div>
+ </div>
+</div> \ No newline at end of file
diff --git a/modules-available/usblockoff/templates/server-prop-dropdown.html b/modules-available/usblockoff/templates/server-prop-dropdown.html
new file mode 100644
index 00000000..337c40aa
--- /dev/null
+++ b/modules-available/usblockoff/templates/server-prop-dropdown.html
@@ -0,0 +1,19 @@
+<div class="list-group-item">
+ <div class="row">
+ <div class="col-md-3"><label for="prop-{{property}}">{{title}}</label></div>
+ <div class="col-md-7">
+ <select class="form-control" id="prop-{{property}}" name="prop-{{property}}">
+ {{#select_list}}
+ <option {{#active}}selected{{/active}}>{{option}}</option>
+ {{/select_list}}
+ </select>
+ </div>
+ <div class="col-md-2">
+ {{#helptext}}
+ <a class="btn btn-default" title="{{helptext}}">
+ <span class="glyphicon glyphicon-question-sign"></span>
+ </a>
+ {{/helptext}}
+ </div>
+ </div>
+</div> \ No newline at end of file
diff --git a/modules-available/usblockoff/templates/server-prop-generic.html b/modules-available/usblockoff/templates/server-prop-generic.html
new file mode 100644
index 00000000..3c06585e
--- /dev/null
+++ b/modules-available/usblockoff/templates/server-prop-generic.html
@@ -0,0 +1,16 @@
+<div class="list-group-item">
+ <div class="row">
+ <div class="col-md-3"><label for="prop-{{property}}">{{title}}</label></div>
+ <div class="col-md-7">
+ <input class="form-control" id="prop-{{property}}" type="{{inputtype}}" name="prop-{{property}}"
+ value="{{currentvalue}}">
+ </div>
+ <div class="col-md-2">
+ {{#helptext}}
+ <a class="btn btn-default" title="{{helptext}}">
+ <span class="glyphicon glyphicon-question-sign"></span>
+ </a>
+ {{/helptext}}
+ </div>
+ </div>
+</div> \ No newline at end of file
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..07729db4
--- /dev/null
+++ b/modules-available/usblockoff/templates/usb-add-generic-rule.html
@@ -0,0 +1,195 @@
+<div>
+ <form method="post" action="?do=usblockoff" id="addGenericRuleForm">
+ <input type="hidden" name="token" value="{{token}}">
+ <input type="hidden" name="action" value="addGenericRule">
+
+ <div class="panel panel-default">
+ <div class="panel-heading">{{lang_generalOptions}}</div>
+ <div class="panel-body">
+ <div class="list-group">
+
+ {{#settings}}
+ {{{settingHtml}}}
+ {{/settings}}
+
+ </div>
+ </div>
+ </div>
+
+ <div class="panel panel-default">
+ <div class="panel-heading">{{lang_modeOptions}}
+ <input class="settings-bs-switch" id="expert_Switch" type="checkbox" name="expert_Switch"
+ data-on-text="Expert" data-off-text="Casual" data-size="small">
+ </div>
+ <div class="panel-body">
+ <div class="list-group">
+
+ <div id="casualMode">
+
+ <div class="list-group-item">
+ <div class="row">
+ <div class="col-md-3"><label>{{lang_deviceClasses}}</label></div>
+ <div class="col-md-7">
+ <select class="form-control" id="casual_selected">
+ <option value="08:*:*" selected>{{lang_mass-storage}}</option>
+ <option value="03:*:*">{{lang_hid}}</option>
+ <option value="09:*:*">{{lang_hub}}</option>
+ <option value="07:*:*">{{lang_printer}}</option>
+ <option value="01:*:*">{{lang_audio}}</option>
+ <option value="*:*:*">{{lang_all-devices}}</option>
+ </select>
+ </div>
+ <div class="col-md-2">
+ <a class="btn btn-default" title="{{lang_classes-helptext}}">
+ <span class="glyphicon glyphicon-question-sign"></span>
+ </a>
+ </div>
+ </div>
+ </div>
+
+ <div class="list-group-item">
+ <div class="row">
+ <div class="col-md-3"><label>{{lang_contains}}</label></div>
+ <div class="col-md-7">
+ <input class="settings-bs-switch" id="contains" type="checkbox" value="1" checked
+ data-size="small">
+ </div>
+ <div class="col-md-2">
+ <a class="btn btn-default" title="{{lang_contains-helptext}}">
+ <span class="glyphicon glyphicon-question-sign"></span>
+ </a>
+ </div>
+ </div>
+ </div>
+
+ </div>
+
+ <div id="expertMode" style="display: none;">
+
+ <div class="list-group-item">
+ <div class="row">
+ <div class="col-md-3"><label>{{lang_operator}}</label></div>
+ <div class="col-md-7">
+ <select class="form-control" id="expert_selected">
+ <option value="all-of">{{lang_all-of}}</option>
+ <option value="one-of">{{lang_one-of}}</option>
+ <option value="none-of">{{lang_none-of}}</option>
+ <option value="equals" selected>{{lang_equals}}</option>
+ <option value="equals-ordered">{{lang_equals-ordered}}</option>
+ </select>
+ </div>
+ <div class="col-md-2">
+ <a class="btn btn-default" title="{{lang_operator-helptext}}">
+ <span class="glyphicon glyphicon-question-sign"></span>
+ </a>
+ </div>
+ </div>
+ </div>
+
+ <div class="list-group-item">
+ <div class="row">
+ <div class="col-md-3"><label>{{lang_deviceClass}}</label></div>
+ <div class="col-md-7">
+ <input class="form-control" type="input" id="input_deviceClass"
+ value="">
+ </div>
+ <div class="col-md-2">
+ <a class="btn btn-default" title="{{lang_deviceClass-helptext}}">
+ <span class="glyphicon glyphicon-question-sign"></span>
+ </a>
+ </div>
+ </div>
+ </div>
+
+ <div class="list-group-item">
+ <div class="row">
+ <div class="col-md-3"><label>{{lang_deviceSubClass}}</label></div>
+ <div class="col-md-7">
+ <input class="form-control" type="input" id="input_deviceSubClass"
+ value="">
+ </div>
+ <div class="col-md-2">
+ <a class="btn btn-default" title="{{lang_deviceSubClass-helptext}}">
+ <span class="glyphicon glyphicon-question-sign"></span>
+ </a>
+ </div>
+ </div>
+ </div>
+
+ <div class="list-group-item">
+ <div class="row">
+ <div class="col-md-3"><label>{{lang_deviceProtocol}}</label></div>
+ <div class="col-md-7">
+ <input class="form-control" type="input" id="input_deviceProtocol"
+ value="">
+ </div>
+ <div class="col-md-2">
+ <a class="btn btn-default" title="{{lang_deviceProtocol-helptext}}">
+ <span class="glyphicon glyphicon-question-sign"></span>
+ </a>
+ </div>
+ </div>
+ </div>
+
+ </div>
+
+ </div>
+ </div>
+ </div>
+
+ </form>
+</div>
+
+<script type="text/javascript">
+ $('a.btn[title]').tooltip({placement: "auto", html: true});
+
+ var contains = true;
+ var c = $('#contains');
+ c.bootstrapSwitch();
+ c.on('switchChange.bootstrapSwitch', function(event, state) {
+ contains = state;
+ });
+
+ var s = $('#expert_Switch');
+ var mode = "casual";
+ s.bootstrapSwitch();
+ s.parent().parent().addClass('pull-right');
+ s.parent().parent().css("margin", "-5px");
+
+ s.on('switchChange.bootstrapSwitch', function(event, state) {
+ if (state) {
+ // Expert mode.
+ $('#casualMode').hide();
+ $('#expertMode').show();
+ mode = "expert";
+ } else {
+ // Casual mode.
+ $('#expertMode').hide();
+ $('#casualMode').show();
+ mode = "casual";
+ }
+ });
+
+ // Add handler to the modal Button.
+ $('#myModalAddButton').unbind().click(addRule);
+ $('#myModalAddButtonText').text('{{lang_addRule}}');
+
+ function addRule() {
+ if ($('#rules').val() != "") {
+ $('#rules').val($('#rules').val() + "\r\n");
+ }
+ if (mode == "casual") {
+ if (contains) {
+ $('#rules').val($('#rules').val() + $('#prop-action').val() + ' with-interface one-of' + ' { ' +
+ $('#casual_selected option:selected').val() + ' }');
+ } else {
+ $('#rules').val($('#rules').val() + $('#prop-action').val() + ' with-interface ' + $('#casual_selected option:selected').val());
+ }
+ } else {
+ $('#rules').val($('#rules').val() + $('#prop-action').val() + ' with-interface ' + $('#expert_selected option:selected').val()
+ + ' { ' + $("#input_deviceClass").val() + ":" + $("#input_deviceSubClass").val() + ":"
+ + $('#input_deviceProtocol').val() + ' }');
+ }
+ $('#myModal').modal('hide');
+ }
+</script> \ No newline at end of file
diff --git a/modules-available/usblockoff/templates/usb-configuration-table.html b/modules-available/usblockoff/templates/usb-configuration-table.html
new file mode 100644
index 00000000..eb3a8839
--- /dev/null
+++ b/modules-available/usblockoff/templates/usb-configuration-table.html
@@ -0,0 +1,70 @@
+<div class="container-fluid">
+ <div class="row">
+ <div class="col-md-12">
+ <div class="page-header">
+ <h1>{{lang_usb-lock-off}}</h1>
+ </div>
+ </div>
+ </div>
+ <div class="row">
+ <div class="col-md-12">
+ <table id="configurationTable" class="table table-condensed table-hover stupidtable">
+ <thead>
+ <tr>
+ <th data-sort="string">{{lang_serverName}}</th>
+ <th>{{lang_ruleInfoTODO}}</th>
+ <th>{{lang_edit}}</th>
+ <th>{{lang_delete}}</th>
+ </tr>
+ </thead>
+ <tbody>
+ {{#config_list}}
+ <tr>
+ <td data-sort-value="{{config_name}}">{{config_name}}</td>
+ <td>TODO: Show Rule information here</td>
+ <td>
+ <a class="btn btn-xs btn-info" href="?do=usblockoff&amp;show=edit-config&amp;configid={{config_id}}">
+ <span class="glyphicon glyphicon-edit"></span>
+ </a>
+ </td>
+ <td>
+ <a class="btn btn-xs btn-danger" onclick="deleteConfig(event, {{config_id}});">
+ <span class="glyphicon glyphicon-trash"></span>
+ </a>
+ </td>
+ </tr>
+ {{/config_list}}
+ </tbody>
+ </table>
+ <div class="buttonbar text-right">
+ <a class="btn btn-success" href="?do=usblockoff&amp;show=edit-config&amp;configid=new-default">
+ <span class="glyphicon glyphicon-plus"></span>
+ {{lang_configuration}}
+ </a>
+ </div>
+ </div>
+ </div>
+</div>
+
+<script>
+ function deleteConfig(event, id) {
+ event.preventDefault();
+
+ BootstrapDialog.confirm({
+ title: '{{lang_delete}}',
+ message: '{{lang_deleteConfigMessage}}',
+ type: BootstrapDialog.TYPE_DANGER, // <-- Default value is BootstrapDialog.TYPE_PRIMARY
+ closable: false, // <-- Default value is false
+ draggable: false, // <-- Default value is false
+ btnCancelLabel: '{{lang_cancel}}', // <-- Default value is 'Cancel',
+ btnOKLabel: '<span class="glyphicon glyphicon-trash"></span> {{lang_delete}}', // <-- Default value is 'OK',
+ btnOKClass: 'btn-danger', // <-- If you didn't specify it, dialog type will be used,
+ callback: function (result) {
+ if (result) {
+ url = "?do=usblockoff&action=deleteConfig&id=" + id;
+ window.location = url;
+ }
+ }
+ });
+ }
+</script> \ No newline at end of file
diff --git a/modules-available/usblockoff/templates/usb-daemon-config.html b/modules-available/usblockoff/templates/usb-daemon-config.html
new file mode 100644
index 00000000..be8c903c
--- /dev/null
+++ b/modules-available/usblockoff/templates/usb-daemon-config.html
@@ -0,0 +1,26 @@
+<div class="panel panel-default">
+ <div class="panel-heading">usbugard-daemon.conf</div>
+ <div class="panel-body">
+ <div class="list-group">
+
+ {{#list}}
+ <div class="list-group-item">
+ <div class="row">
+ <div class="col-sm-3">
+ <label>{{name}}</label>
+ </div>
+ <div class="col-sm-7">
+ <input class="form-control" name="{{name}}" id="{{name}}" value="{{value}}">
+ </div>
+ <div class="col-sm-2">
+ <a class="btn btn-default" title="{{helptext}}">
+ <span class="glyphicon glyphicon-question-sign"></span>
+ </a>
+ </div>
+ </div>
+ </div>
+ {{/list}}
+
+ </div>
+ </div>
+</div> \ No newline at end of file
diff --git a/modules-available/usblockoff/templates/usb-device-list.html b/modules-available/usblockoff/templates/usb-device-list.html
new file mode 100644
index 00000000..a7c9afed
--- /dev/null
+++ b/modules-available/usblockoff/templates/usb-device-list.html
@@ -0,0 +1,169 @@
+<div>
+ <form method="post" action="?do=usblockoff" id="addDevicesForm">
+ <input type="hidden" name="token" value="{{token}}">
+ <input type="hidden" name="action" value="addDevices">
+
+ <div class="input-group" id="search">
+ <span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
+ <input type="text" id="myInput" class="form-control" onkeyup="search()" placeholder="Search for .."
+ style="font-size: 16px;"/>
+ <span class="input-group-addon" style="width:0px; padding-left:0px; padding-right:0px; border:none;"></span>
+ <select class="form-control" id="searchFor" style="font-size: 16px;" onchange="search()">
+ <option value="0" select>Name</option>
+ <option value="1">Date / Time</option>
+ <option value="2">User Information</option>
+ <option value="3">USB Information</option>
+ <option value="4">Rules Information</option>
+ </select>
+ </div>
+
+ <div style="max-height: 800px; overflow-x: auto;">
+ <table class="table table-hover" id="myTable">
+ <thead>
+ <tr>
+ <th width="1" style="text-align: center;">Name</th>
+ <th width="1" style="text-align: center;">Time</th>
+ <th width="1">User Info</th>
+ <th width="1">USB Info</th>
+ <th width="1">Rule Info</th>
+ </tr>
+ </thead>
+ {{#list}}
+ <input type="hidden" id="{{uid}}-prop-name" value="{{name}}">
+ <input type="hidden" id="{{uid}}-prop-id" value="{{id}}">
+ <input type="hidden" id="{{uid}}-prop-serial" value="{{serial}}">
+ <input type="hidden" id="{{uid}}-prop-via-port" value="{{via-port}}">
+ <input type="hidden" id="{{uid}}-prop-hash" value="{{hash}}">
+ <input type="hidden" id="{{uid}}-prop-parent-hash" value="{{parent-hash}}">
+ <input type="hidden" id="{{uid}}-prop-with-interface" value="{{with-interface}}">
+
+ <tbody onclick="clickRow(this, {{uid}});" id="{{uid}}">
+ <tr>
+ <td nowrap align="center" style="vertical-align: middle;"><label>{{name}}</label></td>
+ <td nowrap align="center" style="vertical-align: middle;">{{time}}<br>{{date}}</td>
+ <td nowrap><font size="0">User: {{user}}<br>Location: {{location}}<br>Client: {{clientip}}</font></td>
+ <td nowrap><font size="0">id: {{id}}<br>Serial: {{serial}}<br>via-port: {{via-port}}</font></td>
+ <td nowrap><font size="0">hash: {{hash}}<br>parent-hash: {{parent-hash}}<br>with-interface:
+ {{with-interface}}</font></td>
+ </tr>
+ </tbody>
+ {{/list}}
+ </table>
+ </div>
+
+ <div class="panel panel-default">
+ <div class="panel-heading">{{lang_ruleOptions}}</div>
+ <div class="panel-body">
+ <div class="list-group">
+ <div id="settingsDIV">
+ {{#settings}}
+ {{{settingHtml}}}
+ {{/settings}}
+ </div>
+ </div>
+ </div>
+ </div>
+
+ </form>
+</div>
+
+<script type="text/javascript">
+ $('a.btn[title]').tooltip();
+ $('.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();
+ }
+
+ function countSelected() {
+ var numSelected = $('.selected').length;
+ if (numSelected == 0) {
+ $('#myModalAddButton').prop('disabled', true);
+ } else {
+ $('#myModalAddButton').prop('disabled', false);
+ }
+ if (numSelected == 1) {
+ $('#myModalAddButtonText').text(' ' + numSelected + ' {{lang_device}}');
+ } else {
+ $('#myModalAddButtonText').text(' ' + numSelected + ' {{lang_devices}}');
+ }
+ }
+
+ function search() {
+ var searchForIndex = $('#searchFor').val();
+ // Declare variables
+ var input, filter, table, tr, td, i;
+ input = document.getElementById("myInput");
+ filter = input.value.toUpperCase();
+ table = document.getElementById("myTable");
+ tr = table.getElementsByTagName("tr");
+
+ // Loop through all table rows, and hide those who don't match the search query
+ for (i = 0; i < tr.length; i++) {
+ td = tr[i].getElementsByTagName("td")[searchForIndex];
+ if (td) {
+ if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
+ tr[i].style.display = "";
+ } else {
+ tr[i].style.display = "none";
+ }
+ }
+ }
+ }
+
+ function addDevices() {
+ $('.selected').each(function () {
+ var rule = $('#prop-action').val();
+ var selected = $(this);
+ $('#settingsDIV .settings-bs-switch').each(function () {
+ if ($(this).is(":checked")) {
+ var settingname = $(this).attr('name').substring(5);
+ var info = $('#' + $(selected).attr('id') + '-' + $(this).attr('name'));
+
+ if (settingname == 'id' || settingname == 'with-interface') {
+ rule += ' ' + settingname + ' ' + info.val();
+ } else {
+ rule += ' ' + settingname + ' "' + info.val() + '"';
+ }
+ }
+ });
+ if ($('#rules').val() != "") {
+ $('#rules').val($('#rules').val() + "\r\n");
+ }
+ $('#rules').val($('#rules').val() + rule);
+ });
+ $('#myModal').modal('toggle');
+ }
+
+</script>
+
+<style type='text/css'>
+ .selected {
+ background-color: #F5F5F5;
+ }
+
+ #myTable {
+ border-collapse: collapse; /* Collapse borders */
+ width: 100%; /* Full-width */
+ border: 1px solid #ddd; /* Add a grey border */
+ }
+
+ #myTable th, #myTable td {
+ padding: 12px; /* Add padding */
+ }
+
+ #myTable tr {
+ /* Add a bottom border to all table rows */
+ border-bottom: 1px solid #ddd;
+ }
+
+ #myTable tr.header, #myTable tr:hover {
+ /* Add a grey background color to the table header and on hover */
+ background-color: #f1f1f1;
+ }
+</style>
diff --git a/modules-available/usblockoff/templates/usb-edit-config.html b/modules-available/usblockoff/templates/usb-edit-config.html
new file mode 100644
index 00000000..fc7aabfb
--- /dev/null
+++ b/modules-available/usblockoff/templates/usb-edit-config.html
@@ -0,0 +1,68 @@
+<form method="post" action="?do=usblockoff" id="configForm">
+ <input type="hidden" name="token" value="{{token}}">
+ <input type="hidden" name="action" id="formAction" value="updateConfig">
+ <input type="hidden" name="id" value="{{configid}}" id="configID">
+
+ <div class="panel panel-default">
+ <div class="panel-heading">{{lang_general}}</div>
+ <div class="panel-body">
+ <div class="list-group">
+
+ <div class="list-group-item">
+ <div class="row">
+ <div class="col-sm-3">
+ <label>{{lang_configName}}</label>
+ </div>
+ <div class="col-sm-7">
+ <input required class="form-control" name="configName" id="configName" value="{{configName}}">
+ </div>
+ <div class="col-sm-2">
+ <a class="btn btn-default" title="{{lang_configName_helptext}}">
+ <span class="glyphicon glyphicon-question-sign"></span>
+ </a>
+ </div>
+ </div>
+ </div>
+
+ </div>
+ </div>
+ </div>
+
+ <ul class="nav nav-tabs">
+ <li class="active"><a data-toggle="tab" href="#rulesConfigMenu">{{lang_rulesConfig}}</a></li>
+ <li><a data-toggle="tab" href="#deamonConfigMenu">{{lang_daemonConfig}}</a></li>
+ <li><a data-toggle="tab" href="#assignMenu">{{lang_assignMenu}}</a></li>
+ </ul>
+
+ <div class="tab-content">
+ <div id="rulesConfigMenu" class="tab-pane fade in active">
+ <div id="rulesConfigDIV">
+ {{{rulesConfigHtml}}}
+ </div>
+ </div>
+ <div id="deamonConfigMenu" class="tab-pane fade">
+ <div id="daemonConfigDIV">
+ {{{daemonConfigHtml}}
+ </div>
+ </div>
+ <div id="assignMenu" class="tab-pane fade">
+ <h3>Work in progress ...</h3>
+ <p>Todo: Implement this.</p>
+ <p>Or not.</p>
+ <p>¯\_(ツ)_/¯</p>
+ </div>
+ </div>
+
+ <div class="pull-right">
+ <!-- TODO: Reset Button should't call loadConfig instead do not reset the select input... but how? -->
+ <button class="btn btn-warning" type="reset" onclick="loadConfig($('#select_config'));">
+ <!-- TODO: Add discardChanges to the main-> globalVariables -->
+ <span class="glyphicon glyphicon-refresh"></span> {{lang_discardChanges}}
+ </button>
+ <a href="?do=usblockoff" class="btn btn-default">Cancel</a>
+ <button type="submit" id="configFormButton" class="btn btn-primary">
+ <span class="glyphicon glyphicon-floppy-disk"></span> {{lang_save}}
+ </button>
+ </div>
+
+</form>
diff --git a/modules-available/usblockoff/templates/usb-rules-config.html b/modules-available/usblockoff/templates/usb-rules-config.html
new file mode 100644
index 00000000..3827dc03
--- /dev/null
+++ b/modules-available/usblockoff/templates/usb-rules-config.html
@@ -0,0 +1,105 @@
+<div class="panel panel-default">
+ <div class="panel-heading">rules.conf
+ <input class="settings-bs-switch" id="rules_expert_Switch" type="checkbox" name="rules_expert_Switch"
+ data-on-text="Expert" data-off-text="Casual" data-size="small">
+ </div>
+
+ <div class="panel-body" id="casualRules">
+ <div class="list-group">
+
+ <!-- TEST_AREA -->
+
+ <div>
+ Work in progress ...
+ </div>
+
+ <!-- /TEST_AREA -->
+
+ </div>
+ </div>
+
+ <div class="panel-body" id="expertRules" style="display: none;">
+ <div class="list-group">
+
+ <div class="form-group">
+ <textarea class="form-control" rows="10" name="rules" id="rules">{{rules}}</textarea>
+ </div>
+
+ <div class="pull-right">
+ <a class="btn btn-default" title="{{lang_howToRuleLang}}"
+ href="https://usbguard.github.io/documentation/rule-language.html"
+ style="margin-right: -1px;" target="_blank">
+ <span class="glyphicon glyphicon-question-sign"></span>
+ </a>
+ <a class="btn btn-success" onclick="loadAddGenericRuleModal();"
+ style="margin-right: 3px; float: none;">
+ <span class="glyphicon glyphicon-plus"></span>
+ <span>{{lang_genericRule}}</span>
+ </a>
+ <a class="btn btn-success" style="float: right;" onclick="loadAddDeviceModal();">
+ <span style="margin-right: 5px;" class="glyphicon glyphicon-plus"></span>
+ <span>{{lang_devices}}</span>
+ </a>
+ </div>
+ </div></div>
+</div>
+
+<div class="modal fade" id="myModal" tabindex="-1" role="dialog">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header" id="myModalHeader"></div>
+ <div class="modal-body" id="myModalBody"></div>
+ <div class="modal-footer">
+ <a class="btn btn-default" data-dismiss="modal">{{lang_cancel}}</a>
+ <button id="myModalAddButton" class="btn btn-success" type="button">
+ <span style="margin-right: 5px;" class="glyphicon glyphicon-plus"></span>
+ <span id="myModalAddButtonText"></span>
+ </button>
+ </div>
+ </div>
+ </div>
+</div>
+
+<script type="text/javascript">
+ document.addEventListener("DOMContentLoaded", function(event) {
+ $('a.btn[title]').tooltip({placement: "auto", html: true});
+
+ var s = $('#rules_expert_Switch');
+ var mode = "casual";
+ s.bootstrapSwitch();
+ s.parent().parent().addClass('pull-right');
+ s.parent().parent().css("margin", "-5px");
+
+ s.on('switchChange.bootstrapSwitch', function(event, state) {
+ if (state) {
+ // Expert mode.
+ $('#casualRules').hide();
+ $('#expertRules').show();
+ mode = "expert";
+ } else {
+ // Casual mode.
+ $('#expertRules').hide();
+ $('#casualRules').show();
+ mode = "casual";
+ }
+ });
+ });
+
+ function loadAddDeviceModal() {
+ $('#myModalHeader').text("{{lang_device-list}}").css("font-weight", "Bold");
+ $('#myModalAddButton').attr("form", "addDevicesForm");
+ $('#myModal .modal-dialog').css('width', '60%');
+ $('#myModal .modal-dialog').css('min-width', '60%');
+ $('#myModal').modal('show');
+ $('#myModalBody').load("?do=usblockoff&action=deviceList");
+ }
+
+ function loadAddGenericRuleModal() {
+ $('#myModalHeader').text("{{lang_add-generic-rule}}").css("font-weight", "Bold");
+ $('#myModalAddButton').attr("form", "addGenericRuleForm");
+ $('#myModal .modal-dialog').css('width', '60%');
+ $('#myModal .modal-dialog').css('min-width', '60%');
+ $('#myModal').modal('show');
+ $('#myModalBody').load("?do=usblockoff&action=genericRuleBuilder");
+ }
+</script> \ No newline at end of file