瀏覽代碼

Clean some ugly logic

DSR! 2 年之前
父節點
當前提交
1e6c29919f

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

@@ -199,7 +199,7 @@ class Advanced extends SystemModule
                 $this->response = array(
                     "completed" => true,
                     "sha256" => $fileHash,
-                    "downloaded" => sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor]
+                    "downloaded" => sprintf("%.2f", $bytes / pow(1024, $factor)) . @$sz[$factor]
                 );
             } else if ($fileHash == $this->request->checksum) {
                 $this->response = array("completed" => true);
@@ -266,6 +266,7 @@ class Advanced extends SystemModule
             $result = $this->dbConnection->query("SELECT token FROM api_tokens WHERE token='%s';", $token);
             if (!empty($result) && isset($result[0]["token"]) && $result[0]["token"] === $token) {
                 $this->response = array("valid" => true);
+                return;
             }
         }
 

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

@@ -93,12 +93,12 @@ class Clients extends SystemModule
         $arpData = $this->getARPData();
         $ssidData = $this->getSSIDData();
         foreach ($stationData as $mac => $signal) {
-            $client = array();
-            $client['mac'] = $mac;
-            $client['ip'] = $arpData[$mac];
-            $client['ssid'] = $ssidData[$mac];
-            $client['host'] = $dhcpData[$mac][1];
-            array_push($connectedClients, $client);
+            $connectedClients[] = [
+                'mac' => $mac,
+                'ip' => $arpData[$mac],
+                'ssid' => $ssidData[$mac],
+                'host' => $dhcpData[$mac][1],
+            ];
         }
         $this->response = array(
             'clients' => $connectedClients

+ 1 - 5
src/pineapple/modules/Configuration/api/module.php

@@ -89,11 +89,7 @@ class Configuration extends SystemModule
 
     private function resetPineapple()
     {
-        if ($this->getDevice() === "nano") {
-            $this->execBackground("mtd -r erase rootfs_data");
-        } else if ($this->getDevice() === "tetra") {
-            $this->execBackground("jffs2reset -y && reboot &");
-        }
+        $this->execBackground("jffs2reset -y && reboot &");
         $this->response = array("success" => true);
     }
 

+ 8 - 18
src/pineapple/modules/Filters/api/module.php

@@ -66,18 +66,16 @@ class Filters extends SystemModule
     {
         if (exec("hostapd_cli -i wlan0 karma_get_black_white") === "WHITE") {
             return "Allow";
-        } else {
-            return "Deny";
         }
+        return "Deny";
     }
 
     private function getClientMode()
     {
         if (exec("hostapd_cli -i wlan0 karma_get_mac_black_white") === "WHITE") {
             return "Allow";
-        } else {
-            return "Deny";
         }
+        return "Deny";
     }
 
     private function getSSIDFilters()
@@ -106,24 +104,16 @@ class Filters extends SystemModule
 
     private function toggleClientMode()
     {
-        if ($this->request->mode === "Allow") {
-            exec("pineap /tmp/pineap.conf mac_filter white");
-            $this->uciSet('pineap.@config[0].mac_filter', 'white');
-        } else {
-            exec("pineap /tmp/pineap.conf mac_filter black");
-            $this->uciSet('pineap.@config[0].mac_filter', 'black');
-        }
+        $value = ($this->request->mode === 'Allow') ? 'white' : 'black';
+        exec("pineap /tmp/pineap.conf mac_filter {$value}");
+        $this->uciSet('pineap.@config[0].mac_filter', $value);
     }
 
     private function toggleSSIDMode()
     {
-        if ($this->request->mode === "Allow") {
-            $this->uciSet('pineap.@config[0].ssid_filter', 'white');
-            exec("pineap /tmp/pineap.conf ssid_filter white");
-        } else {
-            $this->uciSet('pineap.@config[0].ssid_filter', 'black');
-            exec("pineap /tmp/pineap.conf ssid_filter black");
-        }
+        $value = ($this->request->mode === 'Allow') ? 'white' : 'black';
+        exec("pineap /tmp/pineap.conf ssid_filter {$value}");
+        $this->uciSet('pineap.@config[0].ssid_filter', $value);
     }
 
     private function getClientData()

+ 0 - 7
src/pineapple/modules/PineAP/api/PineAPHelper.php

@@ -223,8 +223,6 @@ class PineAPHelper
         } else {
             $this->setSetting("beacon_interval", "{$interval}");
         }
-
-        return;
     }
 
     public function setResponseInterval($interval)
@@ -235,8 +233,6 @@ class PineAPHelper
         } else {
             $this->setSetting("beacon_response_interval", "{$interval}");
         }
-
-        return;
     }
 
     public function setSource($mac)
@@ -247,8 +243,6 @@ class PineAPHelper
         } else {
             $this->setSetting("pineap_mac", "{$mac}");
         }
-
-        return;
     }
 
     public function setTarget($mac)
@@ -259,7 +253,6 @@ class PineAPHelper
         } else {
             $this->setSetting("target_mac", "{$mac}");
         }
-        return;
     }
 
     public function deauth($target, $source, $channel, $multiplier = 1)

+ 7 - 13
src/pineapple/modules/PineAP/api/module.php

@@ -308,8 +308,9 @@ class PineAP extends SystemModule
         if ($this->checkPineAP()) {
             $sta = $this->request->sta;
             $clients = $this->request->clients;
-            $multiplier = intval($this->request->multiplier, 10);
+            $multiplier = intval($this->request->multiplier);
             $channel = $this->request->channel;
+            $success = false;
 
             if (empty($clients)) {
                 $this->response = array('error' => 'This AP has no clients', 'success' => false);
@@ -683,8 +684,7 @@ class PineAP extends SystemModule
             if (strtoupper($row['type']) !== "MSCHAPV2" && strtoupper($row['type']) != "EAP-TTLS/MSCHAPV2") {
                 continue;
             }
-            $x = $row['username'] . ':$NETNTLM$' . $row['hex(challenge)'] . '$' . $row['hex(response)'];
-            array_push($data, $x);
+            $data[] = $row['username'] . ':$NETNTLM$' . $row['hex(challenge)'] . '$' . $row['hex(response)'];
         }
         file_put_contents($jtrLocation, join("\n", $data));
         $this->response = array("download" => $this->downloadFile($jtrLocation));
@@ -701,8 +701,7 @@ class PineAP extends SystemModule
             if (strtoupper($row['type']) !== "MSCHAPV2" && strtoupper($row['type']) != "EAP-TTLS/MSCHAPV2") {
                 continue;
             }
-            $x = $row['username'] . '::::' . $row['hex(response)'] . ':' . $row['hex(challenge)'];
-            array_push($data, $x);
+            $data[] = $row['username'] . '::::' . $row['hex(response)'] . ':' . $row['hex(challenge)'];
         }
         file_put_contents($hashcatLocation, join("\n", $data));
         $this->response = array("download" => $this->downloadFile($hashcatLocation));
@@ -731,13 +730,10 @@ class PineAP extends SystemModule
     {
         $bssid = $this->request->bssid;
         $channel = $this->request->channel;
+        // We already set $this->response in checkPineAP() if it isnt running.
         if ($this->checkPineAP()) {
             $this->execBackground("pineap /etc/pineap.conf handshake_capture_start ${bssid} ${channel}");
             $this->response = array('success' => true);
-            return;
-        } else {
-            // We already set $this->response in checkPineAP() if it isnt running.
-            return;
         }
     }
 
@@ -763,11 +759,9 @@ class PineAP extends SystemModule
     {
         $handshakes = array();
         foreach (glob("/tmp/handshakes/*.pcap") as $handshake) {
-            $handshake = str_replace("/tmp/handshakes/", "", $handshake);
-            $handshake = str_replace("_full.pcap", "", $handshake);
-            $handshake = str_replace("_partial.pcap", "", $handshake);
+            $handshake = str_replace(["/tmp/handshakes/", "_full.pcap", "_partial.pcap"], "", $handshake);
             $handshake = str_replace('-', ':', $handshake);
-            array_push($handshakes, $handshake);
+            $handshakes[] = $handshake;
         }
 
         $this->response = array("handshakes" => $handshakes);