Pages.php 2.6 KB

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