瀏覽代碼

Refactor and cleanup

DSR! 2 年之前
父節點
當前提交
26c006ea58

+ 1 - 2
src/pineapple/api/DatabaseConnection.php

@@ -59,8 +59,7 @@ class DatabaseConnection
                 $sqlParameters[$i] = $escaped;
             }
         }
-        $safeQuery = vsprintf($sqlQuery, $sqlParameters);
-        return $safeQuery;
+        return vsprintf($sqlQuery, $sqlParameters);
     }
 
     public function query(...$query)

+ 0 - 1
src/pineapple/api/pineapple.php

@@ -49,7 +49,6 @@ function udsSend($path, $message)
 
 function dgramUdsSend($path, $message)
 {
-    $sock = NULL;
     if(!($sock = socket_create(AF_UNIX, SOCK_DGRAM, 0))) {
         return false;
     }

+ 2 - 2
src/pineapple/modules/Clients/api/module.php

@@ -64,7 +64,7 @@ class Clients extends SystemModule
             iw dev wlan0 station dump |
             awk \'{ if ($1 == "Station") { printf "%s ", $2; } else if ($1 == "inactive") {print $3;} }\'
         ', $stations);
-        foreach ($stations as $_ => $station) {
+        foreach ($stations as $key => $station) {
             if (empty($station)) {
                 continue;
             }
@@ -75,7 +75,7 @@ class Clients extends SystemModule
             iw dev wlan0-2 station dump |
             awk \'{ if ($1 == "Station") { printf "%s ", $2; } else if ($1 == "inactive") {print $3;} }\'
         ', $stations);
-        foreach ($stations as $_ => $station) {
+        foreach ($stations as $key => $station) {
             if (empty($station)) {
                 continue;
             }

+ 1 - 2
src/pineapple/modules/Dashboard/api/module.php

@@ -66,8 +66,7 @@ class Dashboard extends SystemModule
 
     private function getClients()
     {
-        $clients = exec('iw dev wlan0 station dump | grep Station | wc -l');
-        return $clients;
+        return exec('iw dev wlan0 station dump | grep Station | wc -l');
     }
 
     private function getLandingPageData()

+ 2 - 2
src/pineapple/modules/Help/files/dumpscan.php

@@ -118,7 +118,7 @@ $clients = $dbConnection->query("
     LEFT JOIN aps t2 ON
     t2.bssid = t1.bssid WHERE t2.bssid IS NULL AND
     t1.bssid != 'FF:FF:FF:FF:FF:FF' COLLATE NOCASE AND t1.scan_id='%d';
-    ", $client_row['scan_id']);
+    ", $scanID);
 
 foreach ($clients as $client_row) {
     $data[$scanID]['outOfRangeClients'][$client_row['mac']] = array();
@@ -129,7 +129,7 @@ $data[$scanID]['unassociatedClients'] = array();
 $clients = $dbConnection->query("SELECT mac FROM clients WHERE bssid='FF:FF:FF:FF:FF:FF' COLLATE NOCASE;");
 
 foreach ($clients as $client_row) {
-    array_push($data[$scanID]['unassociatedClients'], $client_row['mac']);
+    $data[$scanID]['unassociatedClients'][] = $client_row['mac'];
 }
 
 file_put_contents("php://stdout", json_encode($data, JSON_PRETTY_PRINT));

+ 1 - 1
src/pineapple/modules/Networking/api/module.php

@@ -166,7 +166,7 @@ class Networking extends SystemModule
             $this->error = "Error: SSIDs must be at least one character.";
             return;
         }
-        if (strlen($config->managementKey) < 8 && $config->disableManagementAP == false) {
+        if (strlen($config->managementKey) < 8 && !$config->disableManagementAP) {
             $this->error = "Error: WPA2 Passwords must be at least 8 characters long.";
             return;
         }

+ 1 - 1
src/pineapple/modules/Notes/api/module.php

@@ -103,7 +103,7 @@ class Notes extends SystemModule
         $keys = array();
         $res = $this->dbConnection->query("SELECT key FROM notes;");
         foreach ($res as $idx => $key) {
-            array_push($keys, $key['key']);
+            $keys[] = $key['key'];
         }
         return array("keys" => $keys);
     }

+ 16 - 16
src/pineapple/modules/PineAP/api/PineAPHelper.php

@@ -54,7 +54,7 @@ class PineAPHelper
 
     public function enableAssociations()
     {
-        if (\helper\checkRunning(CLI_PINEAPD)) {
+        if (\helper\checkRunning(self::CLI_PINEAPD)) {
             exec("pineap /tmp/pineap.conf karma on");
         } else {
             $this->setSetting("karma", "on");
@@ -65,7 +65,7 @@ class PineAPHelper
 
     public function disableAssociations()
     {
-        if (\helper\checkRunning(CLI_PINEAPD)) {
+        if (\helper\checkRunning(self::CLI_PINEAPD)) {
             exec("pineap /tmp/pineap.conf karma off");
         } else {
             $this->setSetting("karma", "off");
@@ -117,7 +117,7 @@ class PineAPHelper
 
     public function disableBeaconer()
     {
-        if (\helper\checkRunning(CLI_PINEAPD)) {
+        if (\helper\checkRunning(self::CLI_PINEAPD)) {
             exec('pineap /tmp/pineap.conf broadcast_pool off');
         } else {
             $this->setSetting("broadcast_ssid_pool", "off");
@@ -127,7 +127,7 @@ class PineAPHelper
 
     public function enableResponder()
     {
-        if (\helper\checkRunning(CLI_PINEAPD)) {
+        if (\helper\checkRunning(self::CLI_PINEAPD)) {
             exec('pineap /tmp/pineap.conf beacon_responses on');
         } else {
             $this->setSetting("beacon_responses", "on");
@@ -137,7 +137,7 @@ class PineAPHelper
 
     public function disableResponder()
     {
-        if (\helper\checkRunning(CLI_PINEAPD)) {
+        if (\helper\checkRunning(self::CLI_PINEAPD)) {
             exec('pineap /tmp/pineap.conf beacon_responses off');
         } else {
             $this->setSetting("beacon_responses", "off");
@@ -147,7 +147,7 @@ class PineAPHelper
 
     public function enableHarvester()
     {
-        if (\helper\checkRunning(CLI_PINEAPD)) {
+        if (\helper\checkRunning(self::CLI_PINEAPD)) {
             exec('pineap /tmp/pineap.conf capture_ssids on');
         } else {
             $this->setSetting("capture_ssids", "on");
@@ -157,7 +157,7 @@ class PineAPHelper
 
     public function disableHarvester()
     {
-        if (\helper\checkRunning(CLI_PINEAPD)) {
+        if (\helper\checkRunning(self::CLI_PINEAPD)) {
             exec('pineap /tmp/pineap.conf capture_ssids off');
         } else {
             $this->setSetting("capture_ssids", "off");
@@ -167,7 +167,7 @@ class PineAPHelper
 
     public function enableConnectNotifications()
     {
-        if (\helper\checkRunning(CLI_PINEAPD)) {
+        if (\helper\checkRunning(self::CLI_PINEAPD)) {
             exec('pineap /tmp/pineap.conf connect_notifications on');
         } else {
             $this->setSetting("connect_notifications", "on");
@@ -177,7 +177,7 @@ class PineAPHelper
 
     public function disableConnectNotifications()
     {
-        if (\helper\checkRunning(CLI_PINEAPD)) {
+        if (\helper\checkRunning(self::CLI_PINEAPD)) {
             exec('pineap /tmp/pineap.conf connect_notifications off');
         } else {
             $this->setSetting("connect_notifications", "off");
@@ -187,7 +187,7 @@ class PineAPHelper
 
     public function enableDisconnectNotifications()
     {
-        if (\helper\checkRunning(CLI_PINEAPD)) {
+        if (\helper\checkRunning(self::CLI_PINEAPD)) {
             exec('pineap /tmp/pineap.conf disconnect_notifications on');
         } else {
             $this->setSetting("disconnect_notifications", "on");
@@ -197,7 +197,7 @@ class PineAPHelper
 
     public function disableDisconnectNotifications()
     {
-        if (\helper\checkRunning(CLI_PINEAPD)) {
+        if (\helper\checkRunning(self::CLI_PINEAPD)) {
             exec('pineap /tmp/pineap.conf disconnect_notifications off');
         } else {
             $this->setSetting("disconnect_notifications", "off");
@@ -217,7 +217,7 @@ class PineAPHelper
 
     public function setBeaconInterval($interval)
     {
-        if (\helper\checkRunning(CLI_PINEAPD)) {
+        if (\helper\checkRunning(self::CLI_PINEAPD)) {
             $interval = escapeshellarg($interval);
             exec("pineap /tmp/pineap.conf beacon_interval {$interval}");
         } else {
@@ -227,7 +227,7 @@ class PineAPHelper
 
     public function setResponseInterval($interval)
     {
-        if (\helper\checkRunning(CLI_PINEAPD)) {
+        if (\helper\checkRunning(self::CLI_PINEAPD)) {
             $interval = escapeshellarg($interval);
             exec("pineap /tmp/pineap.conf beacon_response_interval {$interval}");
         } else {
@@ -237,7 +237,7 @@ class PineAPHelper
 
     public function setSource($mac)
     {
-        if (\helper\checkRunning(CLI_PINEAPD)) {
+        if (\helper\checkRunning(self::CLI_PINEAPD)) {
             $mac = escapeshellarg($mac);
             exec("pineap /tmp/pineap.conf set_source {$mac}");
         } else {
@@ -247,7 +247,7 @@ class PineAPHelper
 
     public function setTarget($mac)
     {
-        if (\helper\checkRunning(CLI_PINEAPD)) {
+        if (\helper\checkRunning(self::CLI_PINEAPD)) {
             $mac = escapeshellarg($mac);
             exec("pineap /tmp/pineap.conf set_target {$mac}");
         } else {
@@ -269,7 +269,7 @@ class PineAPHelper
 
     public function setPineapInterface($interface)
     {
-        if (\helper\checkRunning(CLI_PINEAPD)) {
+        if (\helper\checkRunning(self::CLI_PINEAPD)) {
             $this->disablePineAP();
         }
 

+ 1 - 2
src/pineapple/modules/PineAP/api/module.php

@@ -785,7 +785,6 @@ class PineAP extends SystemModule
         exec("pineap /tmp/pineap.conf get_status", $status_output);
         if ($status_output[0] === "PineAP is not running") {
             $this->error = "PineAP is not running";
-            return 0;
         } else {
             $status_output = implode("\n", $status_output);
             $status_output = json_decode($status_output, true);
@@ -801,8 +800,8 @@ class PineAP extends SystemModule
 
             // No scan is running.
             $this->response = array('running' => false, 'currentBSSID' => false);
-            return 0;
         }
+        return 0;
     }
 
     private function downloadHandshake()

+ 0 - 1
src/pineapple/modules/Recon/api/module.php

@@ -31,7 +31,6 @@ abstract class EncryptionFields
 
 class Recon extends SystemModule
 {
-    private $scanID = null;
     private $dbConnection = null;
     const PATH_WS_SCRIPT = '/pineapple/modules/Recon/api/reconpp.py';
     const CLI_PINEAP = 'pineap /tmp/pineap.conf';

+ 2 - 3
src/pineapple/modules/Reporting/api/module.php

@@ -39,7 +39,7 @@ class Reporting extends SystemModule
     {
         $this->response = [
             "config" => [
-                "generateReport" => (exec("grep files/reporting /etc/crontabs/root") == "") ? false : true,
+                "generateReport" => !(exec("grep files/reporting /etc/crontabs/root") == ""),
                 "storeReport" => $this->uciGet("reporting.@settings[0].save_report"),
                 "sendReport" => $this->uciGet("reporting.@settings[0].send_email"),
                 "interval" => (string) $this->uciGet("reporting.@settings[0].interval")
@@ -95,12 +95,11 @@ class Reporting extends SystemModule
             $hour_string = ($hours_minus_one == 0) ? "*" : "*/" . ($hours_minus_one + 1);
             exec("sed -i '/DO NOT TOUCH/d /\\/pineapple\\/modules\\/Reporting\\/files\\/reporting/d' /etc/crontabs/root");
             exec("echo -e '#DO NOT TOUCH BELOW\\n0 {$hour_string} * * * /pineapple/modules/Reporting/files/reporting\\n#DO NOT TOUCH ABOVE' >> /etc/crontabs/root");
-            exec("/etc/init.d/cron start");
         } else {
             exec("sed -i '/DO NOT TOUCH/d /\\/pineapple\\/modules\\/Reporting\\/files\\/reporting/d' /etc/crontabs/root");
             exec("/etc/init.d/cron stop");
-            exec("/etc/init.d/cron start");
         }
+        exec("/etc/init.d/cron start");
     }
 
     private function setReportContents()

+ 5 - 4
src/pineapple/modules/Reporting/files/getlog.php

@@ -22,12 +22,13 @@ if ($dbConnection === NULL) {
 if (isset($dbConnection->error['databaseConnectionError'])) {
 	exit($dbConnection->strError() . "\n");
 }
-$log = NULL;
+
+$sql = "SELECT * FROM log ORDER BY updated_at DESC;";
 if ($probesOnly) {
-    $log = $dbConnection->query("SELECT * FROM log WHERE log_type=0 ORDER BY updated_at DESC;");
-} else {
-    $log = $dbConnection->query("SELECT * FROM log ORDER BY updated_at DESC;");
+    $sql = "SELECT * FROM log WHERE log_type=0 ORDER BY updated_at DESC;";
 }
+$log = $dbConnection->query($sql);
+
 $clearlog = exec('uci get reporting.@settings[0].clear_log');
 if ($clearlog == '1') {
 	$dbConnection->exec('DELETE FROM log;');