Ticket #10214: SBLE_internal_81e644e.diff
File SBLE_internal_81e644e.diff, 8.9 KB (added by , 13 years ago) |
---|
-
django/conf/global_settings.py
diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py index 0aee63d..f4a75f6 100644
a b FILE_CHARSET = 'utf-8' 142 142 # E-mail address that error messages come from. 143 143 SERVER_EMAIL = 'root@localhost' 144 144 145 # Whether to send broken-link emails. 146 SEND_BROKEN_LINK_EMAILS = False145 # Whether to send broken-link emails. Can be 'all', 'internal' or 'none'. 146 SEND_BROKEN_LINK_EMAILS = 'none' 147 147 148 148 # Database connection info. 149 149 DATABASES = { … … ALLOWED_INCLUDE_ROOTS = () 245 245 ADMIN_FOR = () 246 246 247 247 # List of compiled regular expression objects representing URLs that need not 248 # be reported when SEND_BROKEN_LINK_EMAILS is True. Here are a few examples:248 # be reported when SEND_BROKEN_LINK_EMAILS is 'all' or 'internal'. Here are a few examples: 249 249 # import re 250 250 # IGNORABLE_404_URLS = ( 251 251 # re.compile(r'^/apple-touch-icon.*\.png$'), -
django/middleware/common.py
diff --git a/django/middleware/common.py b/django/middleware/common.py index 4dd2e14..4609e3d 100644
a b class CommonMiddleware(object): 92 92 def process_response(self, request, response): 93 93 "Send broken link emails and calculate the Etag, if needed." 94 94 if response.status_code == 404: 95 if settings.SEND_BROKEN_LINK_EMAILS and not settings.DEBUG:95 if settings.SEND_BROKEN_LINK_EMAILS in ['all', 'internal', True] and not settings.DEBUG: 96 96 # If the referrer was from an internal link or a non-search-engine site, 97 97 # send a note to the managers. 98 98 domain = request.get_host() 99 99 referer = request.META.get('HTTP_REFERER', None) 100 is_internal = _is_internal_request(domain, referer)101 100 path = request.get_full_path() 102 if referer and not _is_ignorable_404(path) and (is_internal or '?' not in referer): 103 ua = request.META.get('HTTP_USER_AGENT', '<none>') 104 ip = request.META.get('REMOTE_ADDR', '<none>') 105 mail_managers("Broken %slink on %s" % ((is_internal and 'INTERNAL ' or ''), domain), 106 "Referrer: %s\nRequested URL: %s\nUser agent: %s\nIP address: %s\n" \ 107 % (referer, request.get_full_path(), ua, ip), 108 fail_silently=True) 101 if referer and not _is_ignorable_404(path): 102 is_internal = _is_internal_request(domain, referer) 103 notify = is_internal if settings.SEND_BROKEN_LINK_EMAILS == 'internal' else ('?' not in referer) 104 if notify: 105 ua = request.META.get('HTTP_USER_AGENT', '<none>') 106 ip = request.META.get('REMOTE_ADDR', '<none>') 107 mail_managers("Broken %slink on %s" % ((is_internal and 'INTERNAL ' or ''), domain), 108 "Referrer: %s\nRequested URL: %s\nUser agent: %s\nIP address: %s\n" \ 109 % (referer, request.get_full_path(), ua, ip), 110 fail_silently=True) 109 111 return response 110 112 111 113 # Use ETags, if requested. -
docs/howto/error-reporting.txt
diff --git a/docs/howto/error-reporting.txt b/docs/howto/error-reporting.txt index 64af2a0..ddb9e65 100644
a b not found" errors). Django sends emails about 404 errors when: 58 58 59 59 * :setting:`DEBUG` is ``False`` 60 60 61 * :setting:`SEND_BROKEN_LINK_EMAILS` is `` True``61 * :setting:`SEND_BROKEN_LINK_EMAILS` is ``'all'`` or ``'internal'`` 62 62 63 63 * Your :setting:`MIDDLEWARE_CLASSES` setting includes ``CommonMiddleware`` 64 64 (which it does by default). … … crawlers often request:: 95 95 periods to escape them.) 96 96 97 97 The best way to disable this behavior is to set 98 :setting:`SEND_BROKEN_LINK_EMAILS` to ``False``.98 :setting:`SEND_BROKEN_LINK_EMAILS` to 'none'. 99 99 100 100 .. seealso:: 101 101 -
docs/ref/middleware.txt
diff --git a/docs/ref/middleware.txt b/docs/ref/middleware.txt index 737e0b2..802e658 100644
a b Adds a few conveniences for perfectionists: 62 62 normalize URLs. 63 63 64 64 * Sends broken link notification emails to :setting:`MANAGERS` if 65 :setting:`SEND_BROKEN_LINK_EMAILS` is set to `` True``.65 :setting:`SEND_BROKEN_LINK_EMAILS` is set to ``'all'`` or ``'internal'``. 66 66 67 67 * Handles ETags based on the :setting:`USE_ETAGS` setting. If 68 68 :setting:`USE_ETAGS` is set to ``True``, Django will calculate an ETag -
docs/ref/settings.txt
diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt index a35d99a..c2cf443 100644
a b ignored when reporting HTTP 404 errors via email (see 1133 1133 commonly requested file such as ``favicon.ico`` or ``robots.txt``, or if it 1134 1134 gets hammered by script kiddies. 1135 1135 1136 This is only used if :setting:`SEND_BROKEN_LINK_EMAILS` is set to `` True`` and1136 This is only used if :setting:`SEND_BROKEN_LINK_EMAILS` is set to ``'all'`` or ``'internal'`` and 1137 1137 ``CommonMiddleware`` is installed (see :doc:`/topics/http/middleware`). 1138 1138 1139 1139 .. setting:: INSTALLED_APPS … … MANAGERS 1330 1330 Default: ``()`` (Empty tuple) 1331 1331 1332 1332 A tuple in the same format as :setting:`ADMINS` that specifies who should get 1333 broken-link notifications when ``SEND_BROKEN_LINK_EMAILS =True``.1333 broken-link notifications when ``SEND_BROKEN_LINK_EMAILS`` is ``'all'`` or ``'internal'``. 1334 1334 1335 1335 .. setting:: MEDIA_ROOT 1336 1336 … … better. ``django-admin.py startproject`` creates one automatically. 1533 1533 SEND_BROKEN_LINK_EMAILS 1534 1534 ----------------------- 1535 1535 1536 Default: `` False``1536 Default: ``'none'`` 1537 1537 1538 1538 Whether to send an email to the :setting:`MANAGERS` each time somebody visits 1539 1539 a Django-powered page that is 404ed with a non-empty referer (i.e., a broken 1540 1540 link). This is only used if ``CommonMiddleware`` is installed (see 1541 :doc:`/topics/http/middleware`). See also :setting:`IGNORABLE_404_URLS` and 1541 :doc:`/topics/http/middleware`). Valid values are ``'none'``, ``'all'`` 1542 and ``'internal'``. See also :setting:`IGNORABLE_404_URLS` and 1542 1543 :doc:`/howto/error-reporting`. 1543 1544 1544 1545 .. setting:: SERIALIZATION_MODULES -
tests/regressiontests/middleware/tests.py
diff --git a/tests/regressiontests/middleware/tests.py b/tests/regressiontests/middleware/tests.py index 124eb19..272d784 100644
a b class CommonMiddlewareTest(TestCase): 262 262 263 263 def test_404_error_reporting(self): 264 264 settings.IGNORABLE_404_URLS = (re.compile(r'foo'),) 265 settings.SEND_BROKEN_LINK_EMAILS = True265 settings.SEND_BROKEN_LINK_EMAILS = 'all' 266 266 request = self._get_request('regular_url/that/does/not/exist') 267 267 request.META['HTTP_REFERER'] = '/another/url/' 268 268 response = self.client.get(request.path) … … class CommonMiddlewareTest(TestCase): 272 272 273 273 def test_404_error_reporting_no_referer(self): 274 274 settings.IGNORABLE_404_URLS = (re.compile(r'foo'),) 275 settings.SEND_BROKEN_LINK_EMAILS = True275 settings.SEND_BROKEN_LINK_EMAILS = 'all' 276 276 request = self._get_request('regular_url/that/does/not/exist') 277 277 response = self.client.get(request.path) 278 278 CommonMiddleware().process_response(request, response) … … class CommonMiddlewareTest(TestCase): 280 280 281 281 def test_404_error_reporting_ignored_url(self): 282 282 settings.IGNORABLE_404_URLS = (re.compile(r'foo'),) 283 settings.SEND_BROKEN_LINK_EMAILS = True283 settings.SEND_BROKEN_LINK_EMAILS = 'all' 284 284 request = self._get_request('foo_url/that/does/not/exist/either') 285 285 request.META['HTTP_REFERER'] = '/another/url/' 286 286 response = self.client.get(request.path) 287 287 CommonMiddleware().process_response(request, response) 288 288 self.assertEqual(len(mail.outbox), 0) 289 289 290 def test_404_error_reporting_internal(self): 291 settings.IGNORABLE_404_URLS = (re.compile(r'foo'),) 292 settings.SEND_BROKEN_LINK_EMAILS = 'internal' 293 request = self._get_request('regular_url/that/does/not/exist') 294 request.META['HTTP_REFERER'] = 'http://testserver/another/url/' 295 response = self.client.get(request.path) 296 CommonMiddleware().process_response(request, response) 297 self.assertEqual(len(mail.outbox), 1) 298 self.assertIn('Broken', mail.outbox[0].subject) 299 300 def test_404_error_reporting_external_ignore(self): 301 settings.IGNORABLE_404_URLS = (re.compile(r'foo'),) 302 settings.SEND_BROKEN_LINK_EMAILS = 'internal' 303 request = self._get_request('regular_url/that/does/not/exist') 304 request.META['HTTP_REFERER'] = '/another/url/' 305 response = self.client.get(request.path) 306 CommonMiddleware().process_response(request, response) 307 self.assertEqual(len(mail.outbox), 0) 308 290 309 291 310 class ConditionalGetMiddlewareTest(TestCase): 292 311 urls = 'regressiontests.middleware.cond_get_urls'