debug.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
  3. if (!isset($_SESSION['mailcow_cc_role']) || $_SESSION['mailcow_cc_role'] != "admin") {
  4. header('Location: /');
  5. exit();
  6. }
  7. require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/header.inc.php';
  8. $_SESSION['return_to'] = $_SERVER['REQUEST_URI'];
  9. $solr_status = (preg_match("/^([yY][eE][sS]|[yY])+$/", $_ENV["SKIP_SOLR"])) ? false : solr_status();
  10. $clamd_status = (preg_match("/^([yY][eE][sS]|[yY])+$/", $_ENV["SKIP_CLAMD"])) ? false : true;
  11. if (!isset($_SESSION['gal']) && $license_cache = $redis->Get('LICENSE_STATUS_CACHE')) {
  12. $_SESSION['gal'] = json_decode($license_cache, true);
  13. }
  14. $js_minifier->add('/web/js/site/debug.js');
  15. // vmail df
  16. $exec_fields = array('cmd' => 'system', 'task' => 'df', 'dir' => '/var/vmail');
  17. $vmail_df = explode(',', (string)json_decode(docker('post', 'dovecot-mailcow', 'exec', $exec_fields), true));
  18. // containers
  19. $containers = (array) docker('info');
  20. if ($clamd_status === false) unset($containers['clamd-mailcow']);
  21. if ($solr_status === false) unset($containers['solr-mailcow']);
  22. ksort($containers);
  23. foreach ($containers as $container => $container_info) {
  24. date_default_timezone_set('UTC');
  25. $StartedAt = date_parse($container_info['State']['StartedAt']);
  26. if ($StartedAt['hour'] !== false) {
  27. $date = new \DateTime();
  28. $date->setTimestamp(mktime(
  29. $StartedAt['hour'],
  30. $StartedAt['minute'],
  31. $StartedAt['second'],
  32. $StartedAt['month'],
  33. $StartedAt['day'],
  34. $StartedAt['year']));
  35. $user_tz = new DateTimeZone(getenv('TZ'));
  36. $date->setTimezone($user_tz);
  37. $started = $date->format('r');
  38. }
  39. else {
  40. $started = '?';
  41. }
  42. $containers[$container]['State']['StartedAtHR'] = $started;
  43. }
  44. // get mailcow data
  45. $hostname = getenv('MAILCOW_HOSTNAME');
  46. $timezone = getenv('TZ');
  47. $template = 'debug.twig';
  48. $template_data = [
  49. 'log_lines' => getenv('LOG_LINES'),
  50. 'vmail_df' => $vmail_df,
  51. 'hostname' => $hostname,
  52. 'timezone' => $timezone,
  53. 'gal' => @$_SESSION['gal'],
  54. 'license_guid' => license('guid'),
  55. 'solr_status' => $solr_status,
  56. 'solr_uptime' => round($solr_status['status']['dovecot-fts']['uptime'] / 1000 / 60 / 60),
  57. 'clamd_status' => $clamd_status,
  58. 'containers' => $containers,
  59. 'ip_check' => customize('get', 'ip_check'),
  60. 'lang_admin' => json_encode($lang['admin']),
  61. 'lang_debug' => json_encode($lang['debug']),
  62. 'lang_datatables' => json_encode($lang['datatables']),
  63. ];
  64. require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php';