index.php 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. if (cfr('ROOT')) {
  3. if (!empty($_POST['showlogs']) && !empty($_POST['viewlog']) && is_array($_POST['viewlog'])) {
  4. $frm = new InputForm('', 'post', '&lt; ' . __('Back'));
  5. show_window('', $frm->show(true));
  6. $output = '';
  7. foreach ($_POST['viewlog'] as $logfile) {
  8. $logfile = basename($logfile);
  9. if (substr($logfile, -3) == '.gz') {
  10. $contents = gzfile_get_contents($system->logging . $logfile);
  11. } else {
  12. $contents = file_get_contents($system->logging . $logfile);
  13. }
  14. $output .= wf_tag('pre') . rcms_parse_text('---------------------------------' . $logfile . '' . $contents, true, false, true) . wf_tag('pre', true);
  15. }
  16. show_window(__('Showing') . ' ' . $logfile, $output);
  17. } elseif (!empty($_POST['showlogs_from_archive']) && !empty($_POST['archive']) && !empty($_POST['viewlog']) && is_array($_POST['viewlog'])) {
  18. $frm = new InputForm('', 'post', '&lt; ' . __('Back'));
  19. $frm->hidden('browse_archive', '1');
  20. $frm->hidden('browse', $_POST['archive']);
  21. show_window('', $frm->show(true));
  22. $_POST['archive'] = basename($_POST['archive']);
  23. if (@is_readable($system->logging . $_POST['archive'])) {
  24. $output = '';
  25. $archive = new tar();
  26. $archive->openTAR($system->logging . $_POST['archive']);
  27. foreach ($_POST['viewlog'] as $logfile) {
  28. $logfile = basename($logfile);
  29. if ($gz_contents = $archive->getFile($logfile)) {
  30. $gz_contents = $gz_contents['file'];
  31. if (substr($logfile, -3) == '.gz') {
  32. file_write_contents($system->logging . $logfile, $gz_contents);
  33. $contents = gzfile_get_contents($system->logging . $logfile);
  34. rcms_delete_files($system->logging . $logfile);
  35. } else {
  36. $contents = &$gz_contents;
  37. }
  38. $output .= rcms_parse_text('[quote=' . $logfile . ']' . $contents . '[/quote]', true, false, true);
  39. }
  40. }
  41. unset($archive);
  42. }
  43. deb($output);
  44. } elseif (!empty($_POST['browse_archive']) && !empty($_POST['browse'])) {
  45. $frm = new InputForm('', 'post', '&lt; ' . __('Back'));
  46. show_window('', $frm->show(true));
  47. $_POST['browse'] = basename($_POST['browse']);
  48. if (is_readable($system->logging . $_POST['browse'])) {
  49. $archive = new tar();
  50. $archive->openTAR($system->logging . $_POST['browse']);
  51. $frm = new InputForm('', 'post', __('Show selected'));
  52. $frm->addbreak(__('Avaible logs in archive') . ' ' . $_POST['browse']);
  53. $frm->hidden('showlogs_from_archive', '1');
  54. $frm->hidden('archive', $_POST['browse']);
  55. foreach ($archive->files as $file_data) {
  56. if (preg_match("/^((.*?)-(.*?)-(.*?))\.log(|.gz)$/i", $file_data['name'], $matches)) {
  57. $frm->addrow($matches[1], $frm->checkbox('viewlog[]', $file_data['name'], ''));
  58. }
  59. }
  60. deb($frm->show(true));
  61. unset($archive);
  62. }
  63. } else {
  64. if (!empty($_POST['build_monthly'])) {
  65. $system->logMergeByMonth();
  66. show_success(__('Archivation done'));
  67. }
  68. $frm = new InputForm('', 'post', __('Build monthly log archives (except current month)'));
  69. $frm->hidden('build_monthly', '1');
  70. show_window('', $frm->show(true));
  71. $frm = new InputForm('', 'post', __('Show selected'));
  72. $logs = rcms_scandir($system->logging);
  73. $frm->hidden('showlogs', '1');
  74. foreach ($logs as $log_entry) {
  75. if (preg_match("/^((.*?)-(.*?)-(.*?))\.log(|.gz)$/i", $log_entry, $matches)) {
  76. $frm->addrow($matches[1], $frm->checkbox('viewlog[]', $log_entry, ''));
  77. }
  78. }
  79. show_window(__('Avaible logs'), $frm->show(true));
  80. $frm = new InputForm('', 'post', __('Browse selected'));
  81. $frm->hidden('browse_archive', '1');
  82. foreach ($logs as $log_entry) {
  83. if (preg_match("/^((.*?)-(.*?))\.tar(|.gz)$/i", $log_entry, $matches)) {
  84. $frm->addrow($frm->radio_button('browse', array($log_entry => $log_entry), '-1'));
  85. }
  86. }
  87. show_window(__('Avaible monthly log archives'), $frm->show(true));
  88. }
  89. } else {
  90. show_error(__('Access denied'));
  91. }