autoconfig.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/vars.inc.php';
  3. $default_autodiscover_config = $autodiscover_config;
  4. if(file_exists('inc/vars.local.inc.php')) {
  5. include_once 'inc/vars.local.inc.php';
  6. }
  7. $autodiscover_config = array_merge($default_autodiscover_config, $autodiscover_config);
  8. error_reporting(0);
  9. if (empty($mailcow_hostname)) {
  10. exit();
  11. }
  12. $domain_dot = strpos($_SERVER['HTTP_HOST'], '.');
  13. $domain_port = strpos($_SERVER['HTTP_HOST'], ':');
  14. if ($domain_port === FALSE) {
  15. $domain = substr($_SERVER['HTTP_HOST'], $domain_dot+1);
  16. $port = 443;
  17. }
  18. else {
  19. $domain = substr($_SERVER['HTTP_HOST'], $domain_dot+1, $domain_port-$domain_dot-1);
  20. $port = substr($_SERVER['HTTP_HOST'], $domain_port+1);
  21. }
  22. header('Content-Type: application/xml');
  23. ?>
  24. <?= '<?xml version="1.0"?>'; ?>
  25. <clientConfig version="1.1">
  26. <emailProvider id="<?=$mailcow_hostname; ?>">
  27. <domain>%EMAILDOMAIN%</domain>
  28. <displayName>A mailcow mail server</displayName>
  29. <displayShortName>mail server</displayShortName>
  30. <incomingServer type="imap">
  31. <hostname><?=$autodiscover_config['imap']['server']; ?></hostname>
  32. <port><?=$autodiscover_config['imap']['port']; ?></port>
  33. <socketType>SSL</socketType>
  34. <username>%EMAILADDRESS%</username>
  35. <authentication>password-cleartext</authentication>
  36. </incomingServer>
  37. <?php
  38. $records = dns_get_record('_imap._tcp.' . $domain, DNS_SRV); // check if IMAP is announced as "not provided" via SRV record
  39. if (count($records) == 0 || $records[0]['target'] != '') { ?>
  40. <incomingServer type="imap">
  41. <hostname><?=$autodiscover_config['imap']['server']; ?></hostname>
  42. <port><?=$autodiscover_config['imap']['tlsport']; ?></port>
  43. <socketType>STARTTLS</socketType>
  44. <username>%EMAILADDRESS%</username>
  45. <authentication>password-cleartext</authentication>
  46. </incomingServer>
  47. <?php } ?>
  48. <?php
  49. $records = dns_get_record('_pop3s._tcp.' . $domain, DNS_SRV); // check if POP3 is announced as "not provided" via SRV record
  50. if (count($records) == 0 || $records[0]['target'] != '') { ?>
  51. <incomingServer type="pop3">
  52. <hostname><?=$autodiscover_config['pop3']['server']; ?></hostname>
  53. <port><?=$autodiscover_config['pop3']['port']; ?></port>
  54. <socketType>SSL</socketType>
  55. <username>%EMAILADDRESS%</username>
  56. <authentication>password-cleartext</authentication>
  57. </incomingServer>
  58. <?php } ?>
  59. <?php
  60. $records = dns_get_record('_pop3._tcp.' . $domain, DNS_SRV); // check if POP3 is announced as "not provided" via SRV record
  61. if (count($records) == 0 || $records[0]['target'] != '') { ?>
  62. <incomingServer type="pop3">
  63. <hostname><?=$autodiscover_config['pop3']['server']; ?></hostname>
  64. <port><?=$autodiscover_config['pop3']['tlsport']; ?></port>
  65. <socketType>STARTTLS</socketType>
  66. <username>%EMAILADDRESS%</username>
  67. <authentication>password-cleartext</authentication>
  68. </incomingServer>
  69. <?php } ?>
  70. <outgoingServer type="smtp">
  71. <hostname><?=$autodiscover_config['smtp']['server']; ?></hostname>
  72. <port><?=$autodiscover_config['smtp']['port']; ?></port>
  73. <socketType>SSL</socketType>
  74. <username>%EMAILADDRESS%</username>
  75. <authentication>password-cleartext</authentication>
  76. </outgoingServer>
  77. <?php
  78. $records = dns_get_record('_smtp._tcp.' . $domain, DNS_SRV); // check if SMTP is announced as "not provided" via SRV record
  79. if (count($records) == 0 || $records[0]['target'] != '') { ?>
  80. <outgoingServer type="smtp">
  81. <hostname><?=$autodiscover_config['smtp']['server']; ?></hostname>
  82. <port><?=$autodiscover_config['smtp']['tlsport']; ?></port>
  83. <socketType>STARTTLS</socketType>
  84. <username>%EMAILADDRESS%</username>
  85. <authentication>password-cleartext</authentication>
  86. </outgoingServer>
  87. <?php } ?>
  88. <enable visiturl="https://<?=$mailcow_hostname; ?><?php if ($port != 443) echo ':'.$port; ?>/admin.php">
  89. <instruction>If you didn't change the password given to you by the administrator or if you didn't change it in a long time, please consider doing that now.</instruction>
  90. <instruction lang="de">Sollten Sie das Ihnen durch den Administrator vergebene Passwort noch nicht geändert haben, empfehlen wir dies nun zu tun. Auch ein altes Passwort sollte aus Sicherheitsgründen geändert werden.</instruction>
  91. </enable>
  92. </emailProvider>
  93. <webMail>
  94. <loginPage url="https://<?=$mailcow_hostname; ?><?php if ($port != 443) echo ':'.$port; ?>/SOGo/" />
  95. </webMail>
  96. </clientConfig>