| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php namespace pineapple;
- /**
- * This class will contain the base code which all modules
- * must extend.
- */
- abstract class Module
- {
- protected $request;
- protected $response;
- protected $moduleClass;
- protected $error;
- protected $streamFunction;
- const REMOTE_NAME = "GitHub.com";
- const REMOTE_URL = "https://raw.githubusercontent.com/xchwarze/wifi-pineapple-community/main";
- abstract public function route();
- public function __construct($request, $moduleClass)
- {
- $this->request = $request;
- $this->moduleClass = $moduleClass;
- $this->error = '';
- }
- public function getResponse()
- {
- if (empty($this->error) && !empty($this->response)) {
- return $this->response;
- } elseif (!empty($this->streamFunction)) {
- header('Content-Type: text/plain');
- $this->streamFunction->__invoke();
- return false;
- } elseif (empty($this->error) && empty($this->response)) {
- return ['error' => 'Module returned empty response'];
- } else {
- return ['error' => $this->error];
- }
- }
- public function execBackground($command)
- {
- return \helper\execBackground($command);
- }
- protected function isSDAvailable()
- {
- return \helper\isSDAvailable();
- }
- protected function sdReaderPresent() {
- return \helper\sdReaderPresent();
- }
- protected function sdCardPresent() {
- return \helper\sdCardPresent();
- }
- protected function checkRunning($processName)
- {
- return \helper\checkRunning($processName);
- }
- protected function checkRunningFull($processString) {
- return \helper\checkRunningFull($processString);
- }
- public function uciGet($uciString)
- {
- return \helper\uciGet($uciString);
- }
- public function uciSet($settingString, $value)
- {
- \helper\uciSet($settingString, $value);
- }
- public function uciAddList($settingString, $value)
- {
- \helper\uciAddList($settingString, $value);
- }
- protected function downloadFile($file)
- {
- return \helper\downloadFile($file);
- }
- protected function getFirmwareVersion()
- {
- return \helper\getFirmwareVersion();
- }
- protected function getDevice()
- {
- return \helper\getDevice();
- }
- protected function getBoard()
- {
- return \helper\getBoard();
- }
- protected function getMacFromInterface($interface)
- {
- return \helper\getMacFromInterface($interface);
- }
- protected function udsSend($path, $message)
- {
- return \helper\udsSend($path, $message);
- }
- protected function dgramUdsSend($path, $message)
- {
- return \helper\dgramUdsSend($path, $message);
- }
- protected function installDependency($dependencyName, $installToSD = false)
- {
- if ($installToSD && !$this->isSDAvailable()) {
- return false;
- }
- $destination = $installToSD ? '--dest sd' : '';
- $dependencyName = escapeshellarg($dependencyName);
- if (!$this->checkDependency($dependencyName)) {
- exec("opkg update");
- exec("opkg install {$dependencyName} {$destination}");
- }
- return $this->checkDependency($dependencyName);
- }
- protected function checkDependency($dependencyName)
- {
- return \helper\checkDependency($dependencyName);
- }
- }
|