From 186515ab545a70ea8ec3e38b062a89138f9f5a0a Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Tue, 12 Dec 2017 16:56:59 +0100 Subject: [usb-lock-off] Reformatting code. --- modules-available/usblockoff/api.inc.php | 34 +++- modules-available/usblockoff/page.inc.php | 78 +++++--- .../usblockoff/templates/server-prop-bool.html | 6 +- .../usblockoff/templates/server-prop-dropdown.html | 8 +- .../usblockoff/templates/server-prop-generic.html | 6 +- .../usblockoff/templates/usb-choose-config.html | 206 +++++++++++---------- .../usblockoff/templates/usb-configuration.html | 39 ++-- .../usblockoff/templates/usb-device-list.html | 155 ++++++++-------- 8 files changed, 289 insertions(+), 243 deletions(-) (limited to 'modules-available/usblockoff') diff --git a/modules-available/usblockoff/api.inc.php b/modules-available/usblockoff/api.inc.php index 9029819d..14bc6805 100644 --- a/modules-available/usblockoff/api.inc.php +++ b/modules-available/usblockoff/api.inc.php @@ -2,9 +2,10 @@ HandleParameters(); -function HandleParameters() { +function HandleParameters() +{ $getAction = Request::get('action', 0, 'string'); - if ($getAction == "newdevice") { + if ($getAction == "newdevice") { $id = Request::get('id', '', 'string'); $serial = Request::get('serial', '', 'sting'); $name = Request::get('name', '', 'string'); @@ -28,22 +29,36 @@ function HandleParameters() { * @param string $serial USB-Device serial number. * @param string $name USB-Device name. */ -function newDevice($id, $serial, $name, $ip, $ruleInformation) { +function newDevice($id, $serial, $name, $ip, $ruleInformation) +{ $NOW = time(); //$machineuuid = Database::queryFirst("SELECT machineuuid, currentuser FROM machine AS m WHERE m.clientip = :ip", array('ip' => $ip)); - $client = Database::queryFirst("SELECT m.machineuuid AS 'muid', m.currentuser AS 'user' FROM machine AS m WHERE m.clientip=:ip", array('ip' => $ip)); + $client = Database::queryFirst("SELECT m.machineuuid AS 'muid', m.currentuser AS 'user' FROM machine AS m WHERE m.clientip=:ip", array('ip' => $ip)); // TODO: Same device when ID/Serial/Name are the same? Maybe hash value but the hash value can be different on multiple unix. $dbresult = Database::queryFirst("SELECT uid FROM `usb_devices` WHERE id=:id AND serial=:serialnr AND name=:name", array( - 'id' => $id, 'serialnr' => $serial, 'name' => $name)); + 'id' => $id, + 'serialnr' => $serial, + 'name' => $name)); if (empty($dbresult)) { $dbquery = Database::exec("INSERT INTO `usb_devices` (id, serial, name, machineuuid, time, user, ruleInformation) VALUES (:id, :serialnr, - :name, :machineuuid, :now, :user, :ruleInformation)", array('id' => $id, 'serialnr' => $serial, 'name' => $name, 'machineuuid' => $client['muid'], 'now' => $NOW, - 'user' => $client['user'], 'ruleInformation' => json_encode($ruleInformation))); + :name, :machineuuid, :now, :user, :ruleInformation)", array('id' => $id, + 'serialnr' => $serial, + 'name' => $name, + 'machineuuid' => $client['muid'], + 'now' => $NOW, + 'user' => $client['user'], + 'ruleInformation' => json_encode($ruleInformation))); echo "Successfully added"; } else { $dbquery = Database::exec("UPDATE `usb_devices` SET machineuuid=:machineuuid, time=:now, user=:user, ruleInformation=:ruleInformation WHERE id=:id AND serial=:serialnr AND name=:name", - array('id' => $id, 'serialnr' => $serial, 'name' => $name, 'machineuuid' => $client['muid'], 'now' => $NOW, 'user' => $client['user'], 'ruleInformation' => json_encode($ruleInformation))); + array('id' => $id, + 'serialnr' => $serial, + 'name' => $name, + 'machineuuid' => $client['muid'], + 'now' => $NOW, + 'user' => $client['user'], + 'ruleInformation' => json_encode($ruleInformation))); echo "Successfully updated"; } @@ -54,6 +69,7 @@ function newDevice($id, $serial, $name, $ip, $ruleInformation) { * * @param string $serial USB-Device serial number. */ -function deleteDevice($serial) { +function deleteDevice($serial) +{ $dbquery = Database::exec("DELETE FROM `usb_devices` WHERE serial=:serial", array('serial' => $serial)); } diff --git a/modules-available/usblockoff/page.inc.php b/modules-available/usblockoff/page.inc.php index e2effad4..efb85fb1 100644 --- a/modules-available/usblockoff/page.inc.php +++ b/modules-available/usblockoff/page.inc.php @@ -2,12 +2,15 @@ $glob3 = 'globale Variable 3'; $name = 'testname'; $logedIn = true; -class Page_usblockoff extends Page { + +class Page_usblockoff extends Page +{ /** * Called before any page rendering happens - early hook to check parameters etc. */ - protected function doPreprocess() { + protected function doPreprocess() + { User::load(); if (!User::isLoggedIn()) { @@ -31,12 +34,14 @@ class Page_usblockoff extends Page { /** * Menu etc. has already been generated, now it's time to generate page content. */ - protected function doRender() { + protected function doRender() + { $this->loadConfigChooser(); } - protected function loadConfigChooser() { + protected function loadConfigChooser() + { $dbquery = Database::simpleQuery("SELECT configid, configname FROM `usb_configs`"); $configs = array(); while ($dbentry = $dbquery->fetch(PDO::FETCH_ASSOC)) { @@ -45,10 +50,11 @@ class Page_usblockoff extends Page { $configs[] = $config; } - Render::addTemplate('usb-choose-config', array( 'config_list' => array_values($configs))); + Render::addTemplate('usb-choose-config', array('config_list' => array_values($configs))); } - protected function deleteConfig() { + protected function deleteConfig() + { $configID = Request::post('id', 0, 'int'); if ($configID != 0) { @@ -58,7 +64,8 @@ class Page_usblockoff extends Page { Util::redirect('?do=usblockoff'); } - protected function updateConfig() { + protected function updateConfig() + { // Add new settings in usbguard-daemon.conf here: $result['RuleFile'] = Request::post('RuleFile', '', 'string'); $result['ImplicitPolicyTarget'] = Request::post('ImplicitPolicyTarget', '', 'string'); @@ -96,18 +103,23 @@ class Page_usblockoff extends Page { } else { $splitstr = explode('=', $line); - $splitstr[1] = $result[$splitstr[0]]; - $newDaemonConf[] = implode('=', $splitstr)."\r\n"; + $splitstr[1] = $result[$splitstr[0]]; + $newDaemonConf[] = implode('=', $splitstr) . "\r\n"; } } // INSERT IN DB if ($id == '0') { $dbquery = Database::exec("INSERT INTO `usb_configs` (configname, rulesconfig, daemonconfig) VALUES (:configname, :rulesconfig, :daemonconfig)", - array('configname' => $configname, 'rulesconfig' => $result['rules'], 'daemonconfig' => implode($newDaemonConf))); + 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))); + array('configid' => $id, + 'configname' => $configname, + 'rulesconfig' => $result['rules'], + 'daemonconfig' => implode($newDaemonConf))); } } @@ -129,12 +141,13 @@ class Page_usblockoff extends Page { } } - private function ajaxConfig($id) { + private function ajaxConfig($id) + { $form = array(); $rulesConf; - if($id == 0) { + if ($id == 0) { $currentdir = getcwd(); $rulesConf = file_get_contents($currentdir . '/modules/usblockoff/inc/default-configs/rules.conf'); @@ -172,14 +185,15 @@ class Page_usblockoff extends Page { )); } - private function ajaxDeviceList() { + private function ajaxDeviceList() + { $usbdevices = array(); $dbquery = Database::simpleQuery("SELECT * FROM `usb_devices`"); while ($entry = $dbquery->fetch(PDO::FETCH_ASSOC)) { $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'])); + WHERE m.machineuuid=:machineuuid", array('machineuuid' => $entry['machineuuid'])); $device['uid'] = $entry['uid']; $device['id'] = $entry['id']; @@ -202,28 +216,38 @@ class Page_usblockoff extends Page { $settings = array(); $setting = array(); $setting['title'] = "Action"; - $setting['select_list'] = array(array( + $setting['select_list'] = array(array( 'option' => 'allow', 'active' => true, - ), array( - 'option' => 'block', - 'active' => false, - ), array( - 'option' => 'reject', - 'active' => false, - )); + ), + 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); + $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)), - ); + 'helptext' => array('helptext' => Dictionary::translateFile('rule', $key . "_helptext")), + 'property' => $key, + 'currentvalue' => $value)), + ); } echo Render::parse('usb-device-list', array( diff --git a/modules-available/usblockoff/templates/server-prop-bool.html b/modules-available/usblockoff/templates/server-prop-bool.html index f430d02c..de7c990a 100644 --- a/modules-available/usblockoff/templates/server-prop-bool.html +++ b/modules-available/usblockoff/templates/server-prop-bool.html @@ -7,9 +7,9 @@
{{#helptext}} - - - + + + {{/helptext}}
diff --git a/modules-available/usblockoff/templates/server-prop-dropdown.html b/modules-available/usblockoff/templates/server-prop-dropdown.html index 80667766..337c40aa 100644 --- a/modules-available/usblockoff/templates/server-prop-dropdown.html +++ b/modules-available/usblockoff/templates/server-prop-dropdown.html @@ -4,15 +4,15 @@
{{#helptext}} - - - + + + {{/helptext}}
diff --git a/modules-available/usblockoff/templates/server-prop-generic.html b/modules-available/usblockoff/templates/server-prop-generic.html index 9e94c23d..3c06585e 100644 --- a/modules-available/usblockoff/templates/server-prop-generic.html +++ b/modules-available/usblockoff/templates/server-prop-generic.html @@ -7,9 +7,9 @@
{{#helptext}} - - - + + + {{/helptext}}
diff --git a/modules-available/usblockoff/templates/usb-choose-config.html b/modules-available/usblockoff/templates/usb-choose-config.html index d446e4cf..f2f5bb10 100644 --- a/modules-available/usblockoff/templates/usb-choose-config.html +++ b/modules-available/usblockoff/templates/usb-choose-config.html @@ -3,116 +3,118 @@ -
-
{{lang_general}}
-
-
+
+
{{lang_general}}
+
+
-
-
-
- -
-
-
- - -
-
-
- - - -
-
-
+
+
+
+ +
+
+
+ + +
+
+
+ + + +
+
+
-
-
-
- -
-
-
- -
-
-
- - - -
-
-
+
+
+
+ +
+
+
+ +
+
+
+ + + +
+
+
-
-
-
- -
-
-
- - -
-
-
- - - -
-
-
+
+
+
+ +
+
+
+ + +
+
+
+ + + +
+
+
-
-
-
-
+
+
+
+
diff --git a/modules-available/usblockoff/templates/usb-configuration.html b/modules-available/usblockoff/templates/usb-configuration.html index d6317e11..7032e249 100644 --- a/modules-available/usblockoff/templates/usb-configuration.html +++ b/modules-available/usblockoff/templates/usb-configuration.html @@ -3,52 +3,53 @@
- {{#list}} + {{#list}}
-
+
- {{/list}} + {{/list}}
-
rules.conf
-
-
+
rules.conf
+
+
-
- -
+
+ +
-
-
+
+
@@ -62,7 +63,7 @@