index.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. if (cfr('SQLCONSOLE')) {
  3. $devCon = new DevConsole();
  4. /**
  5. * OnePunch scripts management
  6. */
  7. //new script creation
  8. if (ubRouting::checkPost(array($devCon::PROUTE_OPN_ALIAS, $devCon::PROUTE_OPN_NAME, $devCon::PROUTE_OPN_CONTENT))) {
  9. $onePunch = new OnePunch();
  10. $punchCreateResult = $onePunch->createScript(ubRouting::post($devCon::PROUTE_OPN_ALIAS), ubRouting::post($devCon::PROUTE_OPN_NAME), ubRouting::post($devCon::PROUTE_OPN_CONTENT));
  11. if (!empty($punchCreateResult)) {
  12. show_error($punchCreateResult);
  13. } else {
  14. ubRouting::nav($devCon::URL_DEVCON);
  15. }
  16. }
  17. //existing script deletion
  18. if (ubRouting::checkGet($devCon::ROUTE_OP_DELETE)) {
  19. $onePunch = new OnePunch();
  20. $punchDeleteResult = $onePunch->deleteScript(ubRouting::get($devCon::ROUTE_OP_DELETE));
  21. if (!empty($punchDeleteResult)) {
  22. show_error($punchDeleteResult);
  23. } else {
  24. ubRouting::nav($devCon::URL_DEVCON);
  25. }
  26. }
  27. //editing existing script
  28. if (ubRouting::checkPost(array($devCon::PROUTE_OPE_ID, $devCon::PROUTE_OPE_OLDALIAS, $devCon::PROUTE_OPE_NAME, $devCon::PROUTE_OPE_ALIAS, $devCon::PROUTE_OPE_CONTENT))) {
  29. $onePunch = new OnePunch();
  30. $onePunch->saveScript();
  31. ubRouting::nav($devCon::URL_DEVCON . '&' . $devCon::ROUTE_OP_EDIT . '=' . ubRouting::post($devCon::PROUTE_OPE_ALIAS));
  32. }
  33. //migrating old code templates from storage
  34. if (ubRouting::checkGet($devCon::ROUTE_OP_IMPORT)) {
  35. $onePunch = new OnePunch();
  36. $onePunch->importOldTemplates();
  37. ubRouting::nav($devCon::URL_DEVCON);
  38. }
  39. /**
  40. * showing required module interface on top
  41. */
  42. if (!ubRouting::checkGet($devCon::ROUTE_PHP_CON)) {
  43. show_window(__('SQL Console'), $devCon->renderSqlForm());
  44. } else {
  45. $devConWindowTitle = __('Developer Console');
  46. if (ubRouting::checkGet($devCon::ROUTE_OP_EDIT)) {
  47. $devConWindowTitle .= ': ' . __('Edit') . ' ' . __('One-Punch') . ' ' . __('Script');
  48. }
  49. if (ubRouting::checkGet($devCon::ROUTE_OP_CREATE)) {
  50. $devConWindowTitle .= ': ' . __('Create') . ' ' . __('One-Punch') . ' ' . __('Script');
  51. }
  52. $phpgrid = $devCon->renderPhpInterfaces();
  53. show_window($devConWindowTitle, $phpgrid);
  54. }
  55. /**
  56. * SQL queries / PHP code exection here
  57. */
  58. // SQL console requests processing
  59. if (ubRouting::checkPost($devCon::PROUTE_SQL)) {
  60. $devCon->executeSqlQuery();
  61. }
  62. // PHP console requests processing
  63. // must be here outside object to emulate normal modules behaviour
  64. if (ubRouting::checkPost($devCon::PROUTE_PHP)) {
  65. $phpcode = ubRouting::post($devCon::PROUTE_PHP, 'callback', 'trim');
  66. if (!empty($phpcode)) {
  67. //Optional code highlighting
  68. $devCon->showCodeHighlight($phpcode);
  69. //executing it
  70. $stripcode = substr($phpcode, 0, 70) . '..';
  71. log_register('DEVCONSOLE ' . $stripcode);
  72. ob_start();
  73. try {
  74. eval($phpcode);
  75. } catch (ParseError $e) {
  76. show_error(__('Error') . ':' . $e);
  77. }
  78. $debugData = ob_get_contents();
  79. ob_end_clean();
  80. $devCon->showDebugData($debugData);
  81. log_register('DEVCONSOLE DONE');
  82. } else {
  83. show_window(__('Result'), __('Empty code part received'));
  84. }
  85. }
  86. zb_BillingStats(true);
  87. } else {
  88. show_error(__('Access denied'));
  89. }