Эх сурвалжийг харах

Add config.php and implemented it

DSR! 2 жил өмнө
parent
commit
aebba7efde

+ 5 - 0
src/pineapple/api/Module.php

@@ -101,6 +101,11 @@ abstract class Module
         return \helper\getBoard();
     }
 
+    protected function getDeviceConfig()
+    {
+        return \helper\getDeviceConfig();
+    }
+
     protected function getMacFromInterface($interface)
     {
         return \helper\getMacFromInterface($interface);

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

@@ -77,7 +77,7 @@ class Setup extends APIModule
 
         $this->response = array(
             'complete' => $complete,
-            'device'   => \helper\getDevice(),
+            'config'   => \helper\getDeviceConfig(),
         );
     }
 

+ 14 - 7
src/pineapple/api/pineapple.php

@@ -1,5 +1,7 @@
 <?php namespace helper;
 
+require_once('../config.php');
+
 function execBackground($command)
 {
     exec("echo \"{$command}\" | /usr/bin/at now", $var);
@@ -125,13 +127,18 @@ function getFirmwareVersion()
 
 function getDevice()
 {
-    $data = file_get_contents('/proc/cpuinfo');
-    if (preg_match('/NANO/', $data)) {
-        return 'nano';
-    } elseif (preg_match('/TETRA/', $data)) {
-        return 'tetra';
-    }
-    return 'unknown';
+    return \DeviceConfig::DEVICE_TYPE;
+}
+
+function getDeviceConfig()
+{
+    return [
+        'deviceType' => \DeviceConfig::DEVICE_TYPE,
+        'useInternalStorage' => \DeviceConfig::USE_INTERNAL_STORAGE,
+        'useUSBStorage' => \DeviceConfig::USE_USB_STORAGE,
+        'showFirewallConfig' => \DeviceConfig::SHOW_FIREWALL_CONFIG,
+        'showScanType' => \DeviceConfig::SHOW_SCAN_TYPE,
+    ];
 }
 
 function getMacFromInterface($interface)

+ 17 - 0
src/pineapple/config.php

@@ -0,0 +1,17 @@
+<?php
+
+class DeviceConfig
+{
+    // third party modules can change the options based on this
+    // the allowed values are: 'nano' or 'tetra'
+    const DEVICE_TYPE = 'tetra';
+
+    const USE_INTERNAL_STORAGE = true;
+
+    const USE_USB_STORAGE = true;
+
+    const SHOW_FIREWALL_CONFIG = true;
+
+    // third party modules do not have this flag implemented
+    const SHOW_SCAN_TYPE = true;
+}

+ 2 - 23
src/pineapple/js/directives.js

@@ -594,7 +594,6 @@
                 content: '=content'
             },
             controller: ['$scope', '$api', '$timeout', '$http', '$interval', '$templateCache', '$rootScope', function($scope, $api, $timeout, $http, $interval, $templateCache, $rootScope){
-                $scope.device = '';
                 $rootScope.installedModules = [];
                 $scope.selectedModule = null;
 
@@ -602,16 +601,6 @@
                     $('#install-hook').modal('hide');
                 };
 
-                $scope.getDevice = (function() {
-                    $api.request({
-                        module: "Configuration",
-                        action: "getDevice"
-                    }, function(response) {
-                        $scope.device = response.device;
-                    });
-                });
-                $scope.getDevice();
-
                 $scope.getInstalledModules = (function() {
                     $api.request({
                         module: "ModuleManager",
@@ -634,17 +623,6 @@
 
                 $scope.checkDestination = (function(moduleName, moduleSize, moduleType) {
                     $(window).scrollTop(0);
-
-                    if (moduleType === 'Sys') {
-                        $scope.selectedModule = {module: moduleName, internal: true, sd: false};
-                        return;
-                    }
-
-                    if ($scope.device === 'tetra') {
-                        $scope.selectedModule = {module: moduleName, internal: true, sd: false};
-                        return;
-                    }
-
                     $api.request({
                         module: 'ModuleManager',
                         action: 'checkDestination',
@@ -656,7 +634,6 @@
                         }
                     });
                 });
-                $scope.checkDestination($scope.content.name, $scope.content.module['size'], $scope.content.module['type']);
 
                 $scope.downloadModule = (function(dest) {
                     $api.request({
@@ -724,6 +701,8 @@
                         }, 500);
                     });
                 });
+
+                $scope.checkDestination($scope.content.name, $scope.content.module['size'], $scope.content.module['type']);
             }]
         };
     })

+ 4 - 2
src/pineapple/js/services.js

@@ -29,6 +29,7 @@
     .service('$api', ['$http', function($http){
         this.navbarReloader = false;
         this.device = undefined;
+        this.deviceConfig = undefined;
         this.deviceCallbacks = [];
 
         this.request = (function(data, callback, scope) {
@@ -212,9 +213,10 @@
 
         this.request({
             module: 'Configuration',
-            action: 'getDevice'
+            action: 'getDeviceConfig'
         }, function(response, scope){
-            scope.device = response.device;
+            scope.device = response.config.deviceType;
+            scope.deviceConfig = response.config;
             for (var i = scope.deviceCallbacks.length - 1; i >= 0; --i) {
                 var callbackObj = scope.deviceCallbacks[i];
                 callbackObj.callback(scope.device, callbackObj.scope);

+ 2 - 2
src/pineapple/modules/Advanced/js/module.js

@@ -43,7 +43,7 @@ registerController("AdvancedUSBController", ['$api', '$scope', '$timeout', '$int
     $scope.lsusb = "";
     $scope.fstab = "";
     $scope.fstabSaved = false;
-    $scope.device = "";
+    $scope.useUSBStorage = false;
 
     $scope.formatSDCard = (function() {
         $api.request({
@@ -111,7 +111,7 @@ registerController("AdvancedUSBController", ['$api', '$scope', '$timeout', '$int
     $scope.reloadData();
     
     $api.onDeviceIdentified(function(device, scope) {
-        scope.device = device;
+        scope.useUSBStorage = $api.deviceConfig.useUSBStorage;
     }, $scope);
 
 

+ 1 - 1
src/pineapple/modules/Advanced/module.html

@@ -48,7 +48,7 @@
                     <div class="panel-heading">
                         <h3 class="panel-title">
                             USB &amp; Storage
-                            <span class="dropdown" ng-if="device == 'nano'">
+                            <span class="dropdown" ng-if="useUSBStorage">
                                 <button class="btn btn-xs btn-default dropdown-toggle" type="button" id="usbDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                     <span class="caret"></span>
                                 </button>

+ 8 - 16
src/pineapple/modules/Configuration/api/module.php

@@ -8,70 +8,57 @@ class Configuration extends SystemModule
             case 'getCurrentTimeZone':
                 $this->getCurrentTimeZone();
                 break;
-
             case 'getLandingPageData':
                 $this->getLandingPageData();
                 break;
-
             case 'saveLandingPage':
                 $this->saveLandingPageData();
                 break;
-
             case 'changePass':
                 $this->changePass();
                 break;
-
             case 'changeTimeZone':
                 $this->changeTimeZone();
                 break;
-
             case 'resetPineapple':
                 $this->resetPineapple();
                 break;
-
             case 'haltPineapple':
                 $this->haltPineapple();
                 break;
-
             case 'rebootPineapple':
                 $this->rebootPineapple();
                 break;
-
             case 'getLandingPageStatus':
                 $this->getLandingPageStatus();
                 break;
-
             case 'getAutoStartStatus':
                 $this->getAutoStartStatus();
                 break;
-
             case 'enableLandingPage':
                 $this->enableLandingPage();
                 break;
-
             case 'disableLandingPage':
                 $this->disableLandingPage();
                 break;
-
             case 'enableAutoStart':
                 $this->enableAutoStart();
                 break;
-
             case 'disableAutoStart':
                 $this->disableAutoStart();
                 break;
-
             case 'getButtonScript':
                 $this->getButtonScript();
                 break;
-
             case 'saveButtonScript':
                 $this->saveButtonScript();
                 break;
-
             case 'getDevice':
                 $this->getDeviceName();
                 break;
+            case 'getDeviceConfig':
+                $this->getDeviceConfigArray();
+                break;
         }
     }
 
@@ -192,6 +179,11 @@ class Configuration extends SystemModule
         $this->response = array("device" => $this->getDevice());
     }
 
+    private function getDeviceConfigArray()
+    {
+        $this->response = array("config" => $this->getDeviceConfig());
+    }
+
     protected function changePass()
     {
         if ($this->request->newPassword === $this->request->newPasswordRepeat) {

+ 6 - 11
src/pineapple/modules/ModuleManager/api/module.php

@@ -155,17 +155,12 @@ class ModuleManager extends SystemModule
 
     private function checkDestination()
     {
-        $responseArray = array('module' => $this->request->name, 'internal' => false, 'sd' => false);
-
-        if (disk_free_space('/') > ($this->request->size + 150000)) {
-            $responseArray['internal'] = true;
-        }
-
-        if ($this->isSDAvailable()) {
-            $responseArray['sd'] = true;
-        }
-
-        $this->response = $responseArray;
+        $config = $this->getDeviceConfig();
+        $this->response = array(
+            'module' => $this->request->name,
+            'internal' => (disk_free_space('/') > ($this->request->size + 150000) && $config['useInternalStorage']),
+            'sd' => ($this->isSDAvailable() && $config['useUSBStorage']),
+        );
     }
 
     private function removeModule()

+ 8 - 42
src/pineapple/modules/ModuleManager/js/module.js

@@ -9,17 +9,6 @@ registerController("ModuleManagerController", ['$api', '$scope', '$timeout', '$i
     $scope.downloading = false;
     $scope.installing = false;
     $scope.linking = true;
-    $scope.device = undefined;
-
-    $scope.getDevice = (function() {
-        $api.request({
-            module: "Configuration",
-            action: "getDevice"
-        }, function(response) {
-            $scope.device = response.device;
-        });
-    });
-    $scope.getDevice();
 
     $scope.getAvailableModules = (function() {
         $scope.loading = true;
@@ -61,32 +50,6 @@ registerController("ModuleManagerController", ['$api', '$scope', '$timeout', '$i
         });
     });
 
-    $scope.checkDestination = (function(moduleName, moduleSize) {
-        $(window).scrollTop(0);
-
-        if ($rootScope.installedModules[moduleName] !== undefined && $rootScope.installedModules[moduleName]['type'] === 'System') {
-            $scope.selectedModule = {module: moduleName, internal: true, sd: false};
-            return;
-        }
-
-        if ($scope.device === 'tetra') {
-            $scope.selectedModule = {module: moduleName, internal: true, sd: false};
-            $scope.downloadModule('internal');
-            return;
-        }
-
-        $api.request({
-            module: 'ModuleManager',
-            action: 'checkDestination',
-            name: moduleName,
-            size: moduleSize
-        }, function(response) {
-            if (response.error === undefined) {
-                $scope.selectedModule = response;
-            }
-        });
-    });
-
     $scope.removeModule = (function(name) {
         $api.request({
             module: 'ModuleManager',
@@ -119,10 +82,13 @@ registerController("ModuleManagerController", ['$api', '$scope', '$timeout', '$i
         });
     });
 
-    if ($scope.device === 'nano') {
-        $scope.restoreSDcardModules();
-    } else {
-        $scope.linking = false;
-    }
+    $api.onDeviceIdentified(function(device, scope) {
+        if ($api.deviceConfig.useUSBStorage) {
+            scope.restoreSDcardModules();
+        } else {
+            scope.linking = false;
+        }
+    }, $scope);
+
     $scope.getInstalledModules();
 }]);

+ 2 - 2
src/pineapple/modules/Networking/js/module.js

@@ -254,7 +254,7 @@ registerController('NetworkingFirewallController', ['$api', '$scope', '$timeout'
     $scope.firewallUpdated = false;
     $scope.WANSSHAccess = false;
     $scope.WANUIAccess = false;
-    $scope.device = '';
+    $scope.showFirewallConfig = false;
 
     $scope.reloadData = (function() {
         $api.request({
@@ -285,7 +285,7 @@ registerController('NetworkingFirewallController', ['$api', '$scope', '$timeout'
     });
 
     $api.onDeviceIdentified(function(device, scope) {
-        scope.device = device;
+        scope.showFirewallConfig = $api.deviceConfig.showFirewallConfig;
     }, $scope);
 
     //$scope.reloadData();

+ 1 - 1
src/pineapple/modules/Networking/module.html

@@ -441,7 +441,7 @@
                     </div>
                 </div>
 
-                <div class="controller" ng-controller="NetworkingFirewallController" ng-show="device == 'tetra'">
+                <div class="controller" ng-controller="NetworkingFirewallController" ng-show="showFirewallConfig">
                     <div class="panel panel-default">
                         <div class="panel-heading">
                             <h3 class="panel-title">Firewall</h3>

+ 9 - 8
src/pineapple/modules/Recon/js/module.js

@@ -35,6 +35,7 @@ registerController('ReconController', ['$api', '$scope', '$rootScope', '$interva
     $scope.error = false;
     $scope.scanID = null;
     $scope.device = undefined;
+    $scope.showScanType = false;
     $scope.wsStarted = false;
     $scope.noteKeys = [];
     $scope.noteRefreshInterval = null;
@@ -50,7 +51,7 @@ registerController('ReconController', ['$api', '$scope', '$rootScope', '$interva
         if ($scope.scanSettings.scanDuration === "0") {
             $scope.scanSettings.live = true;
         }
-        $cookies.put('liveScan', $scope.scanSettings.live);($cookies.getAll());
+        $cookies.put('liveScan', $scope.scanSettings.live);
     };
 
     function parseScanResults(results) {
@@ -509,18 +510,18 @@ registerController('ReconController', ['$api', '$scope', '$rootScope', '$interva
         return ($scope.noteKeys !== undefined) && ($scope.noteKeys.indexOf(key) !== -1);
     };
 
-
     $scope.checkScan();
     $scope.$on('$destroy', function() {
         $scope.cancelIntervals();
         $scope.closeWS();
     });
 
-    $api.onDeviceIdentified(function(device) {
-        $scope.updateScanSettings();
-        $scope.device = device;
-        $scope.getScanLocation();
-        $scope.displayCurrentScan();
-        $scope.getNoteKeys();
+    $api.onDeviceIdentified(function(device, scope) {
+        scope.device = device;
+        scope.showScanType = $api.deviceConfig.showScanType;
+        scope.updateScanSettings();
+        scope.getScanLocation();
+        scope.displayCurrentScan();
+        scope.getNoteKeys();
     }, $scope);
 }]);

+ 1 - 1
src/pineapple/modules/Recon/module.html

@@ -9,7 +9,7 @@
                     <div class="col-md-8">
                         <div class="row">
                             <div class="input-group">
-                                <div ng-show="device == 'tetra'">
+                                <div ng-show="showScanType">
                                     <label class="radio-inline"><input type="radio" ng-model="scanType" value="0" ng-disabled="running">2.4GHz</label>
                                     <label class="radio-inline"><input type="radio" ng-model="scanType" value="1" ng-disabled="running">5GHz</label>
                                     <label class="radio-inline"><input type="radio" ng-model="scanType" value="2" ng-disabled="running">Both</label>

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

@@ -43,13 +43,9 @@ class Reporting extends SystemModule
                 "storeReport" => $this->uciGet("reporting.@settings[0].save_report"),
                 "sendReport" => $this->uciGet("reporting.@settings[0].send_email"),
                 "interval" => (string) $this->uciGet("reporting.@settings[0].interval")
-            ]
+            ],
+            "sdDisabled" => !$this->isSDAvailable(),
         ];
-
-        if ($this->getDevice() == "nano" && !$this->isSDAvailable()) {
-            $this->response['config']['storeReport'] = false;
-            $this->response['sdDisabled'] = true;
-        }
     }
 
     private function getReportContents()

+ 10 - 11
src/pineapple/modules/Reporting/js/module.js

@@ -7,7 +7,6 @@ registerController('ReportConfigurationController', ['$api', '$scope', '$timeout
         sendReport: false,
         interval: 1
     };
-    $scope.device = undefined;
 
     $scope.saveConfiguration = (function() {
         $api.request({
@@ -24,17 +23,17 @@ registerController('ReportConfigurationController', ['$api', '$scope', '$timeout
         });
     });
 
-    $api.onDeviceIdentified(function(device, scope) {
-        scope.device = device;
-    }, $scope);
-
-    $api.request({
-        module: 'Reporting',
-        action: 'getReportConfiguration'
-    }, function(response) {
-        $scope.config = response.config;
-        $scope.sdDisabled = response.sdDisabled && $scope.device === 'nano';
+    $scope.getConfiguration = (function() {
+        $api.request({
+            module: 'Reporting',
+            action: 'getReportConfiguration'
+        }, function(response) {
+            $scope.config = response.config;
+            $scope.sdDisabled = response.sdDisabled;
+        });
     });
+
+    $scope.getConfiguration();
 }]);
 
 registerController('ReportContentController', ['$api', '$scope', '$timeout', function($api, $scope, $timeout) {

+ 2 - 2
src/pineapple/modules/Setup/js/module.js

@@ -8,7 +8,7 @@ registerController('SetupController', ['$api', '$scope', '$interval', '$timeout'
     $scope.selectedCountryCode = '';
     $scope.macFilterMode = '';
     $scope.ssidFilterMode = '';
-    $scope.device = '';
+    $scope.showFirewallConfig = false;
     $scope.error = '';
     $scope.changes = "";
     $scope.hideOpenAP = false;
@@ -137,7 +137,7 @@ registerController('SetupController', ['$api', '$scope', '$interval', '$timeout'
             system: 'setup',
             action: 'getDeviceData'
         }, function(response) {
-            $scope.device = response.device;
+            $scope.showFirewallConfig = response.config.showFirewallConfig;
             if (response.complete) {
                 $scope.complete = true;
                 $("#loginModal").remove();

+ 2 - 2
src/pineapple/modules/Setup/module.html

@@ -233,7 +233,7 @@
 
             <div class="panel panel-default">
                 <div class="panel-heading">
-                    <h4 class="panel-title">Filters <span ng-if="device == 'tetra'">&amp; Firewall</span></h4>
+                    <h4 class="panel-title">Filters <span ng-if="showFirewallConfig">&amp; Firewall</span></h4>
                 </div>
                 <div id="FiltersSetup" class="panel-body">
                     <div class="col-md-12">
@@ -299,7 +299,7 @@
                             </div>
                         </div>
                         <div class="row">
-                            <div class="col-md-5" ng-show="device == 'tetra'">
+                            <div class="col-md-5" ng-show="showFirewallConfig">
                                 <h3>Firewall Settings</h3>
                                 <div class="input-group">
                                     <p class="text-info">These firewall rules allow you to configure access to the SSH