Pages.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @author Open Mind
  4. * @date 04/12/2018
  5. * @time 15:22
  6. */
  7. namespace OpenMind\Admin;
  8. use OpenMind\FindBox\FindBoxCoreSystem;
  9. use OpenMind\Web\Controller;
  10. use Template;
  11. class Pages extends Controller
  12. {
  13. private $findBoxCore = null;
  14. public function __construct($f3)
  15. {
  16. parent::__construct($f3);
  17. $this->findBoxCore = new FindBoxCoreSystem(...array_values($f3->get('CORE.fb')));
  18. // Set Admin F3 UI folder
  19. $f3->set('UI', 'src/OpenMind/Admin/ui/');
  20. }
  21. public function Admin($f3)
  22. {
  23. echo Template::instance()->render('masterpage.tpl');
  24. }
  25. public function ESLStatus($f3)
  26. {
  27. $eslStatus = $this->findBoxCore->GetAllESLStatus();
  28. $f3->set('STATUS_BADGE_COLOR', [
  29. 'BLOCKED,FC' => 'info',
  30. 'OFFLINE' => 'warning',
  31. 'BLOCKED,FC' => 'danger',
  32. 'NO_STATUS' => 'light',
  33. 'OK' => 'success'
  34. ]);
  35. $f3->set('ESL_STATUS', $eslStatus);
  36. $f3->set('PAGENAME', 'Dashboard');
  37. $f3->set('CONTENT', 'labelstatus.tpl');
  38. echo Template::instance()->render('masterpage.tpl');
  39. }
  40. public function OML_Settings($f3)
  41. {
  42. global $frameworkUtils;
  43. $path = 'cfg/config.bin';
  44. if (!file_exists($path))
  45. throw new \Exception('Config file not found');
  46. $data = file_get_contents($path);
  47. $config = $frameworkUtils->Decrypt($data);
  48. $f3->set('PAGENAME', 'OM-Link Settings');
  49. $f3->set('CONTENT', 'omlsettings.tpl');
  50. $f3->set('CONFIG_TEXT', $config);
  51. echo Template::instance()->render('masterpage.tpl');
  52. }
  53. public function Config($f3)
  54. {
  55. global $frameworkUtils;
  56. $config = $f3->get('BODY');
  57. if (strlen($config) == 0) {
  58. echo json_encode([
  59. "err" => "Empty body command"
  60. ]);
  61. return;
  62. }
  63. $configOBJ = json_decode($config);
  64. switch ($configOBJ->method) {
  65. case 'saveconfig':
  66. $newConfig = $frameworkUtils->Encrypt($configOBJ->value);
  67. @rename('cfg/config.bin', 'cfg/config.bin.old');
  68. @file_put_contents('cfg/config.bin', $newConfig);
  69. echo json_encode([
  70. "err" => "Configuration saved"
  71. ]);
  72. break;
  73. case 'loadconfig':
  74. $config = $frameworkUtils->Decrypt(file_get_contents('cfg/config.bin'));
  75. echo json_encode([
  76. "err" => "Configuration reloaded successfully",
  77. "value" => $config
  78. ]);
  79. break;
  80. }
  81. return;
  82. }
  83. }