-
Notifications
You must be signed in to change notification settings - Fork 0
/
well_known.module
161 lines (142 loc) · 5.62 KB
/
well_known.module
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
/**
* @file
* Module file for well_known.
*/
/**
* Implements hook_menu().
*/
function well_known_menu() {
$items['admin/config/system/well-known'] = array(
'title' => 'Well-known services',
'description' => 'Configure some <em>well-known</em> services.',
'page callback' => 'well_known_admin_page',
'access arguments' => array('administer site configuration'),
'file' => 'well_known.admin.inc',
);
$items['admin/config/system/well-known/autoconfig-mail'] = array(
'title' => 'Autoconfig mail',
'description' => 'Allow email clients to automatically configure themselves for your domain.',
'page callback' => 'backdrop_get_form',
'page arguments' => array('well_known_autoconfig_mail_form'),
'access arguments' => array('administer site configuration'),
'file' => 'well_known.autoconfig_mail.inc',
);
$items['.well-known/autoconfig/mail/config-v1.1.xml'] = array(
'title' => 'Autoconfig mail configuration',
'page callback' => 'well_known_autoconfig_mail_page',
'delivery callback' => 'well_known_xml_deliver',
'access callback' => 'config_get',
'access arguments' => array('well_known.autoconfig_mail', 'enabled'),
'file' => 'well_known.autoconfig_mail.inc',
'type' => MENU_CALLBACK,
);
/* The autoconfig-mail standard defines
* http(s)://autoconfig.example.org/mail/config-v1.1.xml as an additional
* location. This entry will only be useful if this site is configured to
* responde to requests to the autoconfig.example.org domain which will
* require appropriate DNS enteries and webserver configuration.
*/
$items['mail/config-v1.1.xml'] = array(
'title' => 'Autoconfig mail configuration',
'page callback' => 'well_known_autoconfig_mail_page',
'delivery callback' => 'well_known_xml_deliver',
'access callback' => 'config_get',
'access arguments' => array('well_known.autoconfig_mail', 'enabled'),
'file' => 'well_known.autoconfig_mail.inc',
'type' => MENU_CALLBACK,
);
$items['admin/config/system/well-known/change-password'] = array(
'title' => 'Change password',
'description' => 'Allow password managers to redirect users to your site\'s <em>change password</em> page.',
'page callback' => 'backdrop_get_form',
'page arguments' => array('well_known_change_password_form'),
'access arguments' => array('administer site configuration'),
'file' => 'well_known.change_password.inc',
);
$items['.well-known/change-password'] = array(
'title' => 'Change password redirect',
'page callback' => 'well_known_change_password_page',
'access callback' => 'config_get',
'access arguments' => array('well_known.change_password', 'enabled'),
'file' => 'well_known.change_password.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implements hook_config_info().
*/
function well_known_config_info() {
$prefixes['well_known.autoconfig_mail'] = array(
'label' => t('Autoconfig mail settings'),
'group' => t('Configuration'),
);
$prefixes['well_known.change_password'] = array(
'label' => t('Change password settings'),
'group' => t('Configuration'),
);
return $prefixes;
}
/**
* Packages and sends the result of a page callback to the browser as XML.
*
* @param mixed $page_callback_result
* The result of a page callback. Can be one of:
* - NULL: to indicate no content.
* - An integer menu status constant: to indicate an error condition.
* - An array of XML elements to be passed to format_xml_elements().
* - A string of XML which should be output as-is.
*
* @see backdrop_deliver_page()
* @see backdrop_deliver_html_page()
*/
function well_known_xml_deliver($page_callback_result) {
$output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
// Menu status constants are integers, XML content is either an array which
// will be fed to the format_xml_elements function, or a string which will be
// output as is.
if (is_int($page_callback_result)) {
switch ($page_callback_result) {
case MENU_NOT_FOUND:
backdrop_add_http_header('Status', '404 Not Found');
watchdog('page not found', check_plain($_GET['q']), NULL, WATCHDOG_WARNING);
$output .= '<error>' . t('Page not found') . '</error>';
break;
case MENU_ACCESS_DENIED:
backdrop_add_http_header('Status', '403 Forbidden');
watchdog('access denied', check_plain($_GET['q']), NULL, WATCHDOG_WARNING);
$output .= '<error>' . t('Access denied') . '</error>';
break;
case MENU_SITE_OFFLINE:
backdrop_add_http_header('Status', '503 Service unavailable');
$output .= '<error>' . t('Site is offline') . '</error>';
break;
default:
backdrop_add_http_header('Status', '500 Internal Server Error');
$output .= '<error>' . t('Internal Server Error') . '</error>';
break;
}
}
elseif (is_array($page_callback_result)) {
$output .= format_xml_elements($page_callback_result);
}
elseif (is_string($page_callback_result)) {
$output = $page_callback_result;
}
elseif (is_null($page_callback_result)) {
backdrop_add_http_header('Status', '501 Not Implemented');
watchdog('no page content', check_plain($_GET['q']), NULL, WATCHDOG_WARNING);
$output .= '<error>' . t('No page content') . '</error>';
}
else {
backdrop_add_http_header('Status', '500 Internal Server Error');
$output .= '<error>' . t('Internal Server Error') . '</error>';
}
// Set the content-type as XML.
backdrop_add_http_header('Content-Type', 'application/xml; charset=utf-8');
// Echo the output.
echo $output;
// Perform end-of-request tasks.
backdrop_page_footer();
}