Browse Source

Mini cleanup

DSR! 2 years ago
parent
commit
64fce008ac

+ 2 - 2
src/pineapple/api/API.php

@@ -68,7 +68,7 @@ class API
         }
 
         if (file_exists('/etc/pineapple/setupRequired')) {
-            $this->response = array('error' => 'Not Authenticated', 'setupRequired' => true);
+            $this->response = ['error' => 'Not Authenticated', 'setupRequired' => true];
         } else {
             $this->error = "Not Authenticated";
         }
@@ -98,7 +98,7 @@ class API
     public function finalize()
     {
         if ($this->error) {
-            return ")]}',\n" . json_encode(array("error" => $this->error));
+            return ")]}',\n" . json_encode(["error" => $this->error]);
         } elseif ($this->response) {
             return ")]}',\n" . json_encode($this->response);
         }

+ 2 - 2
src/pineapple/api/APIModule.php

@@ -18,9 +18,9 @@ abstract class APIModule
         if (empty($this->error) && !empty($this->response)) {
             return $this->response;
         } elseif (empty($this->error) && empty($this->response)) {
-            return array('error' => 'API returned empty response');
+            return ['error' => 'API returned empty response'];
         } else {
-            return array('error' => $this->error);
+            return ['error' => $this->error];
         }
     }
 }

+ 2 - 2
src/pineapple/api/Module.php

@@ -33,9 +33,9 @@ abstract class Module
             $this->streamFunction->__invoke();
             return false;
         } elseif (empty($this->error) && empty($this->response)) {
-            return array('error' => 'Module returned empty response');
+            return ['error' => 'Module returned empty response'];
         } else {
-            return array('error' => $this->error);
+            return ['error' => $this->error];
         }
     }
 

+ 2 - 3
src/pineapple/api/Notifications.php

@@ -16,7 +16,7 @@ class Notifications extends APIModule
             $this->error = $this->dbConnection->strError();
             return;
         }
-        $this->notifications = array();
+        $this->notifications = [];
         $this->dbConnection->exec("CREATE TABLE IF NOT EXISTS notifications (message VARCHAR NOT NULL, time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP);");
         if (!empty($this->dbConnection->error)) {
             $this->error = $this->dbConnection->strError();
@@ -42,8 +42,7 @@ class Notifications extends APIModule
 
     public function addNotification($message)
     {
-        $result = $this->dbConnection->exec("INSERT INTO notifications (message) VALUES('%s');", $message);
-        return $result;
+        return $this->dbConnection->exec("INSERT INTO notifications (message) VALUES('%s');", $message);
     }
 
     public function getNotifications()

+ 23 - 26
src/pineapple/modules/Advanced/api/module.php

@@ -103,47 +103,47 @@ class Advanced extends SystemModule
         exec('free -m', $freeMem);
         $freeMem = implode("\n", $freeMem);
 
-        $this->response = array("freeDisk" => $freeDisk, "freeMem" => $freeMem);
+        $this->response = ["freeDisk" => $freeDisk, "freeMem" => $freeMem];
     }
 
     private function dropCaches()
     {
         $this->execBackground('echo 3 > /proc/sys/vm/drop_caches');
-        $this->response = array('success' => true);
+        $this->response = ['success' => true];
     }
 
     private function getUSB()
     {
         exec('lsusb', $lsusb);
         $lsusb = implode("\n", $lsusb);
-        $this->response = array('lsusb' => $lsusb);
+        $this->response = ['lsusb' => $lsusb];
     }
 
     private function getFstab()
     {
         $fstab = file_get_contents('/etc/config/fstab');
-        $this->response = array('fstab' => $fstab);
+        $this->response = ['fstab' => $fstab];
     }
 
     private function saveFstab()
     {
         if (isset($this->request->fstab)) {
             file_put_contents('/etc/config/fstab', $this->request->fstab);
-            $this->response = array("success" => true);
+            $this->response = ['success' => true];
         }
     }
 
     private function getCSS()
     {
         $css = file_get_contents('/pineapple/css/main.css');
-        $this->response = array('css' => $css);
+        $this->response = ['css' => $css];
     }
 
     private function saveCSS()
     {
         if (isset($this->request->css)) {
             file_put_contents('/pineapple/css/main.css', $this->request->css);
-            $this->response = array("success" => true);
+            $this->response = ['success' => true];
         }
     }
 
@@ -164,7 +164,7 @@ class Advanced extends SystemModule
                     }
 
                     unset($upgradeData['updates']);
-                    $this->response = array("upgrade" => true, "upgradeData" => $upgradeData);
+                    $this->response = ["upgrade" => true, "upgradeData" => $upgradeData];
                 } else {
                     $this->error = "No upgrade found.";
                 }
@@ -184,7 +184,7 @@ class Advanced extends SystemModule
         @unlink(self::UP_FLAG);
         $url = escapeshellarg($this->request->upgradeUrl);
         $this->execBackground("wget {$url} -O " . self::UP_PATH . " && touch " . self::UP_FLAG);
-        $this->response = array("success" => true);
+        $this->response = ["success" => true];
     }
 
     private function getDownloadStatus()
@@ -196,21 +196,21 @@ class Advanced extends SystemModule
                 $sz = 'BKMGTP';
                 $factor = floor((strlen($bytes) - 1) / 3);
   
-                $this->response = array(
+                $this->response = [
                     "completed" => true,
                     "sha256" => $fileHash,
                     "downloaded" => sprintf("%.2f", $bytes / pow(1024, $factor)) . @$sz[$factor]
-                );
+                ];
             } else if ($fileHash == $this->request->checksum) {
-                $this->response = array("completed" => true);
+                $this->response = ["completed" => true];
             } else {
                 $this->error = "Checksum mismatch";
             }
         } else {
-            $this->response = array(
+            $this->response = [
                 "completed" => false,
                 "downloaded" => filesize(self::UP_PATH)
-            );
+            ];
         }
     }
 
@@ -223,7 +223,7 @@ class Advanced extends SystemModule
             }
 
             $this->execBackground("sysupgrade {$params} " . self::UP_PATH);
-            $this->response = array("success" => true);
+            $this->response = ["success" => true];
         } else {
             $this->error = "Upgrade failed.";
         }
@@ -236,27 +236,24 @@ class Advanced extends SystemModule
 
     private function getCurrentVersion()
     {
-        $this->response = array("firmwareVersion" => $this->getFirmwareVersion());
+        $this->response = ["firmwareVersion" => $this->getFirmwareVersion()];
     }
 
     private function formatSDCard()
     {
         $this->execBackground("/pineapple/modules/Advanced/formatSD/format_sd");
-        $this->response = array('success' => true);
+        $this->response = ['success' => true];
     }
 
     private function formatSDCardStatus()
     {
-        if (!file_exists('/tmp/sd_format.progress')) {
-            $this->response = array('success' => true);
-        } else {
-            $this->response = array('success' => false);
-        }
+        $this->response = ['success' => (!file_exists('/tmp/sd_format.progress'))];
     }
 
     private function getApiTokens()
     {
-        $this->response = array("tokens" => $this->dbConnection->query("SELECT ROWID, token, name FROM api_tokens;"));
+        $tokens = $this->dbConnection->query("SELECT ROWID, token, name FROM api_tokens;");
+        $this->response = ["tokens" => $tokens];
     }
 
     private function checkApiToken()
@@ -265,12 +262,12 @@ class Advanced extends SystemModule
             $token = $this->request->token;
             $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);
+                $this->response = ["valid" => true];
                 return;
             }
         }
 
-        $this->response = array("valid" => false);
+        $this->response = ["valid" => false];
     }
 
     private function addApiToken()
@@ -279,7 +276,7 @@ class Advanced extends SystemModule
             $token = hash('sha512', openssl_random_pseudo_bytes(32));
             $name = $this->request->name;
             $this->dbConnection->exec("INSERT INTO api_tokens(token, name) VALUES('%s','%s');", $token, $name);
-            $this->response = array("success" => true, "token" => $token, "name" => $name);
+            $this->response = ["success" => true, "token" => $token, "name" => $name];
         } else {
             $this->error = "Missing token name";
         }