index.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. if (cfr('ENVY')) {
  3. $altCfg = $ubillingConfig->getAlter();
  4. if (@$altCfg['ENVY_ENABLED']) {
  5. set_time_limit(0); // may be so slow
  6. $envy = new Envy();
  7. //new script creation
  8. if (ubRouting::checkPost(array('newscriptmodel'))) {
  9. $creationResult = $envy->createScript(ubRouting::post('newscriptmodel'), ubRouting::post('newscriptdata'));
  10. if (empty($creationResult)) {
  11. ubRouting::nav($envy::URL_ME . '&' . $envy::ROUTE_SCRIPTS . '=true');
  12. } else {
  13. show_error($creationResult);
  14. }
  15. }
  16. //existing script deletion
  17. if (ubRouting::checkGet(array('deletescript'))) {
  18. $deletionResult = $envy->deleteScript(ubRouting::get('deletescript'));
  19. if (empty($deletionResult)) {
  20. ubRouting::nav($envy::URL_ME . '&' . $envy::ROUTE_SCRIPTS . '=true');
  21. } else {
  22. show_error($deletionResult);
  23. }
  24. }
  25. //existing script editing
  26. if (ubRouting::checkPost('editscriptid')) {
  27. $savingResult = $envy->saveScript();
  28. if (empty($savingResult)) {
  29. ubRouting::nav($envy::URL_ME . '&' . $envy::ROUTE_SCRIPTS . '=true');
  30. } else {
  31. show_error($savingResult);
  32. }
  33. }
  34. //new device creation
  35. if (ubRouting::checkPost('newdeviceswitchid')) {
  36. $devCreationResult = $envy->createDevice();
  37. if (empty($devCreationResult)) {
  38. ubRouting::nav($envy::URL_ME . '&' . $envy::ROUTE_DEVICES . '=true');
  39. } else {
  40. show_error($devCreationResult);
  41. }
  42. }
  43. //editing existing device
  44. if (ubRouting::checkPost(array('editdeviceid', 'editdeviceswitchid'))) {
  45. $devSaveResult = $envy->saveDevice();
  46. if (empty($devSaveResult)) {
  47. ubRouting::nav($envy::URL_ME . '&' . $envy::ROUTE_DEVICES . '=true');
  48. } else {
  49. show_error($devSaveResult);
  50. }
  51. }
  52. //device config storing to archive
  53. if (ubRouting::checkGet('storedevice')) {
  54. $storeResult = $envy->procStoreArchiveData(ubRouting::get('storedevice'));
  55. if (empty($storeResult)) {
  56. if (ubRouting::checkGet('resave')) {
  57. $returnUrl = $envy::URL_ME;
  58. } else {
  59. $returnUrl = $envy::URL_ME . '&' . $envy::ROUTE_DEVICES . ' = true';
  60. }
  61. ubRouting::nav($returnUrl);
  62. } else {
  63. show_error($storeResult);
  64. }
  65. }
  66. //all existing devices config backup
  67. if (ubRouting::checkGet($envy::ROUTE_ARCHALL)) {
  68. $envy->storeArchiveAllDevices();
  69. ubRouting::nav($envy::URL_ME . '&' . $envy::ROUTE_DEVICES . ' = true');
  70. }
  71. //device deletion
  72. if (ubRouting::checkGet('deletedevice')) {
  73. $devDeletionResult = $envy->deleteDevice(ubRouting::get('deletedevice'));
  74. if (empty($devDeletionResult)) {
  75. ubRouting::nav($envy::URL_ME . '&' . $envy::ROUTE_DEVICES . ' = true');
  76. } else {
  77. show_error($devDeletionResult);
  78. }
  79. }
  80. //archive record deletion
  81. if (ubRouting::checkGet('deletearchiveid')) {
  82. $archDeletionResult = $envy->deleteArchiveRecord(ubRouting::get('deletearchiveid'));
  83. if (empty($archDeletionResult)) {
  84. ubRouting::nav($envy::URL_ME);
  85. } else {
  86. show_error($archDeletionResult);
  87. }
  88. }
  89. //archive record download
  90. if (ubRouting::checkGet('downloadarchiveid')) {
  91. $envy->downloadArchiveRecordConfig(ubRouting::get('downloadarchiveid'));
  92. }
  93. //archive records cleanup
  94. if (ubRouting::checkGet($envy::ROUTE_CLEANUP)) {
  95. $envy->cleanupArchive();
  96. ubRouting::nav($envy::URL_ME);
  97. }
  98. //background archive JSON rendering
  99. if (ubRouting::checkGet($envy::ROUTE_ARCHIVE_AJ)) {
  100. $envy->getAjArchive();
  101. }
  102. if (ubRouting::checkGet('previewdevice') OR ubRouting::checkGet('viewarchiveid')) {
  103. //device preview
  104. if (ubRouting::checkGet('previewdevice')) {
  105. show_window('', wf_BackLink($envy::URL_ME . '&' . $envy::ROUTE_DEVICES . ' = true'));
  106. show_window(__('Preview'), $envy->previewScriptsResult($envy->runDeviceScript(ubRouting::get('previewdevice'))));
  107. }
  108. //archive record view
  109. if (ubRouting::checkGet('viewarchiveid')) {
  110. show_window('', wf_BackLink($envy::URL_ME));
  111. show_window(__('Preview'), $envy->previewScriptsResult($envy->renderArchiveRecordConfig(ubRouting::get('viewarchiveid'))));
  112. }
  113. } else {
  114. //showing some module controls here
  115. show_window('', $envy->renderControls());
  116. //devices management
  117. if (ubRouting::checkGet($envy::ROUTE_DEVICES)) {
  118. show_window(__('Available envy devices'), $envy->renderDevicesList());
  119. }
  120. //scripts management
  121. if (ubRouting::checkGet($envy::ROUTE_SCRIPTS)) {
  122. show_window(__('Available envy scripts'), $envy->renderScriptsList());
  123. }
  124. //diff viewer
  125. if (ubRouting::checkGet($envy::ROUTE_DIFF)) {
  126. show_window('', $envy->renderDiffForm());
  127. //diff display between existing configs
  128. if (ubRouting::checkPost('rundiff', 'diffone', 'difftwo')) {
  129. show_window(__('Changes'), $envy->renderDiff(ubRouting::post('diffone'), ubRouting::post('difftwo')));
  130. }
  131. }
  132. //here previous data archive
  133. if (!ubRouting::checkGet($envy::ROUTE_DEVICES) AND ! ubRouting::checkGet($envy::ROUTE_SCRIPTS) AND ! ubRouting::checkGet($envy::ROUTE_DIFF)) {
  134. show_window(__('Previously collected devices configs'), $envy->renderArchive());
  135. zb_BillingStats(true);
  136. }
  137. //Envy archive cleanup
  138. // TODO
  139. }
  140. } else {
  141. show_error(__('This module is disabled'));
  142. }
  143. } else {
  144. show_error(__('Access denied'));
  145. }