Module.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php namespace pineapple;
  2. /**
  3. * This class will contain the base code which all modules
  4. * must extend.
  5. */
  6. abstract class Module
  7. {
  8. protected $request;
  9. protected $response;
  10. protected $moduleClass;
  11. protected $error;
  12. protected $streamFunction;
  13. const REMOTE_NAME = "GitHub.com";
  14. const REMOTE_URL = "https://raw.githubusercontent.com/xchwarze/wifi-pineapple-community/main";
  15. abstract public function route();
  16. public function __construct($request, $moduleClass)
  17. {
  18. $this->request = $request;
  19. $this->moduleClass = $moduleClass;
  20. $this->error = '';
  21. }
  22. public function getResponse()
  23. {
  24. if (empty($this->error) && !empty($this->response)) {
  25. return $this->response;
  26. } elseif (!empty($this->streamFunction)) {
  27. header('Content-Type: text/plain');
  28. $this->streamFunction->__invoke();
  29. return false;
  30. } elseif (empty($this->error) && empty($this->response)) {
  31. return ['error' => 'Module returned empty response'];
  32. } else {
  33. return ['error' => $this->error];
  34. }
  35. }
  36. public function execBackground($command)
  37. {
  38. return \helper\execBackground($command);
  39. }
  40. protected function isSDAvailable()
  41. {
  42. return \helper\isSDAvailable();
  43. }
  44. protected function sdReaderPresent() {
  45. return \helper\sdReaderPresent();
  46. }
  47. protected function sdCardPresent() {
  48. return \helper\sdCardPresent();
  49. }
  50. protected function checkRunning($processName)
  51. {
  52. return \helper\checkRunning($processName);
  53. }
  54. protected function checkRunningFull($processString) {
  55. return \helper\checkRunningFull($processString);
  56. }
  57. public function uciGet($uciString)
  58. {
  59. return \helper\uciGet($uciString);
  60. }
  61. public function uciSet($settingString, $value)
  62. {
  63. \helper\uciSet($settingString, $value);
  64. }
  65. public function uciAddList($settingString, $value)
  66. {
  67. \helper\uciAddList($settingString, $value);
  68. }
  69. protected function downloadFile($file)
  70. {
  71. return \helper\downloadFile($file);
  72. }
  73. protected function getFirmwareVersion()
  74. {
  75. return \helper\getFirmwareVersion();
  76. }
  77. protected function getDevice()
  78. {
  79. return \helper\getDevice();
  80. }
  81. protected function getBoard()
  82. {
  83. return \helper\getBoard();
  84. }
  85. protected function getMacFromInterface($interface)
  86. {
  87. return \helper\getMacFromInterface($interface);
  88. }
  89. protected function udsSend($path, $message)
  90. {
  91. return \helper\udsSend($path, $message);
  92. }
  93. protected function dgramUdsSend($path, $message)
  94. {
  95. return \helper\dgramUdsSend($path, $message);
  96. }
  97. protected function installDependency($dependencyName, $installToSD = false)
  98. {
  99. if ($installToSD && !$this->isSDAvailable()) {
  100. return false;
  101. }
  102. $destination = $installToSD ? '--dest sd' : '';
  103. $dependencyName = escapeshellarg($dependencyName);
  104. if (!$this->checkDependency($dependencyName)) {
  105. exec("opkg update");
  106. exec("opkg install {$dependencyName} {$destination}");
  107. }
  108. return $this->checkDependency($dependencyName);
  109. }
  110. protected function checkDependency($dependencyName)
  111. {
  112. return \helper\checkDependency($dependencyName);
  113. }
  114. }