forked from gronke/email-autodiscover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autodiscover.xml.php
92 lines (64 loc) · 2.45 KB
/
autodiscover.xml.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
try {
$config = loadConfig();
$xml = loadTemplate(determineTemplateFile());
} catch(Exception $e) {
header("HTTP/1.0 500 Internal Server Error");
exit;
}
header ("Content-Type:text/xml");
$xml = str_replace("%INFO/NAME%", $config['info']['name'], $xml);
$xml = str_replace("%INFO/URL%", $config['info']['url'], $xml);
$xml = str_replace("%INFO/DOMAIN%", $config['info']['domain'], $xml);
$xml = str_replace("%TTL%", $config['ttl'], $xml);
$xml = str_replace("%SERVER/SMTP/SSL_ON%", isOnOrOff($config['server']['smtp']['socket'] == "SSL"), $xml);
$xml = str_replace("%SERVER/IMAP/SSL_ON%", isOnOrOff($config['server']['imap']['socket'] == "SSL"), $xml);
$xml = str_replace("%SERVER/IMAP/DOMAIN_REQUIRED%", isOnOrOff($config['server']['domain_required']), $xml);
$xml = str_replace("%SERVER/SMTP/DOMAIN_REQUIRED%", isOnOrOff($config['server']['domain_required']), $xml);
$xml = str_replace("%SERVER/IMAP/HOST%", $config['server']['imap']['host'], $xml);
$xml = str_replace("%SERVER/IMAP/PORT%", $config['server']['imap']['port'], $xml);
$xml = str_replace("%SERVER/IMAP/SOCKET%", $config['server']['imap']['socket'], $xml);
$xml = str_replace("%SERVER/SMTP/HOST%", $config['server']['smtp']['host'], $xml);
$xml = str_replace("%SERVER/SMTP/PORT%", $config['server']['smtp']['port'], $xml);
$xml = str_replace("%SERVER/SMTP/SOCKET%", $config['server']['smtp']['socket'], $xml);
$xml = str_replace("%EMAIL%", getRequestEmail(), $xml);
$xml = removeComments($xml);
$xml = beautify($xml);
echo $xml;
function removeComments ($xml) {
$pattern = '/<!--(.*)?-->/sU';
return preg_replace($pattern, '', $xml);
}
function beautify ($xml) {
$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
$dom->loadXML($xml);
$dom->formatOutput = true;
return $dom->saveXml();
}
function isOnOrOff ($value) {
return ($value === true) ? 'on' : 'off';
}
function loadConfig () {
return json_decode(implode('', file('settings.json')), true);
}
function loadTemplate ($file) {
return implode("",file($file));
}
function determineTemplateFile () {
$template = array_key_exists('template', $_GET) ? $_GET['template'] : null;
switch($template) {
case "config-v1.1.xml":
$file = 'mail/config-v1.1.xml';
break;
default:
$file = 'mail/autodiscover.xml';
break;
}
return $file;
}
function getRequestEmail () {
$email = array_key_exists('email', $_GET) ? $_GET['email'] : null;
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
?>