debug.php 2.5 KB

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