[or-cvs] r14839: TorCheck shouldn't be called index.py, it should be called T (check/trunk/cgi-bin)

ioerror at seul.org ioerror at seul.org
Fri May 30 05:28:18 UTC 2008


Author: ioerror
Date: 2008-05-30 01:28:18 -0400 (Fri, 30 May 2008)
New Revision: 14839

Added:
   check/trunk/cgi-bin/TorCheck.py
Removed:
   check/trunk/cgi-bin/index.py
Log:
TorCheck shouldn't be called index.py, it should be called TorCheck.py. Docs need to be updated to reflect this change.


Copied: check/trunk/cgi-bin/TorCheck.py (from rev 14813, check/trunk/cgi-bin/index.py)
===================================================================
--- check/trunk/cgi-bin/TorCheck.py	                        (rev 0)
+++ check/trunk/cgi-bin/TorCheck.py	2008-05-30 05:28:18 UTC (rev 14839)
@@ -0,0 +1,240 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+ TorCheck.py
+
+ https://check.torproject.org - originally in perl, rewritten in python
+
+ By Jacob Appelbaum <jacob at appelbaum.net>
+ Written at ToorCon Seattle 2008 (Thanks for the great time h1kari!)
+ Thanks to Crispen for a power outlet :-)
+ 
+ Additional python suggestions from nickm
+ 
+ Best used with the Debian packages:
+    python-dns
+    libapache2-mod-python
+    locales-all
+
+"""
+
+__program__ = 'TorCheck.py'
+__version__ = '20080529.01'
+__url__ = 'https://tor-svn.freehaven.net/svn/check/'
+__author__ = 'Jacob Appelbaum <jacob at appelbaum.net>'
+__copyright__ = 'Copyright (c) 2008, Jacob Appelbaum'
+__license__ = 'See LICENSE for licensing information'
+
+try:
+    from future import antigravity
+except ImportError:
+    antigravity = None
+
+import DNS 
+# This is pydns and can be downloaded from http://pydns.sourceforge.net/ 
+# Or use the Debian package listed above
+from mod_python import apache
+from mod_python import util
+import cgitb; cgitb.enable()
+import gettext
+import locale
+
+# We could also explictly query the remote EL server
+# This is not as good as using a cache for obvious reasons
+DNS.DiscoverNameServers()
+
+def isUsingTor(clientIp):
+    # This is the exit node ip address
+    # This is where we want to dynamically recieve this from Apache
+    splitIp = clientIp.split('.')
+    splitIp.reverse()
+    ELExitNode = ".".join(splitIp)
+
+    # We'll attempt to reach this port on the Target host
+    ELPort = "80"
+
+    # We'll try to reach this host
+    ElTarget = "217.247.237.209"
+
+    # This is the ExitList DNS server we want to query
+    ELHost = "ip-port.exitlist.torproject.org"
+
+    # Prepare the question as an A record request
+    ELQuestion = ELExitNode + "." + ELPort + "." + ElTarget + "." + ELHost 
+    request = DNS.DnsRequest(name=ELQuestion,qtype='A')
+
+    # Ask the question and load the data into our answer
+    answer=request.req()
+
+    # Parse the answer and decide if it's allowing exits
+    # 127.0.0.2 is an exit and NXDOMAIN is not
+    if answer.header['status'] == "NXDOMAIN":
+        # We're not exiting from a Tor exit
+        return 1
+    else:
+        if not answer.answers:
+            # We're getting unexpected data - fail closed
+            return 2
+        for a in answer.answers:
+            if a['data'] != "127.0.0.2":
+                return 2
+        # If we're here, we've had a positive exit answer
+        return 0
+
+def getLocales():
+    locale_descriptions = { 'en_US' : 'English', 'de' : 'Deutsch', 'es' :
+    'español','fa_IR' : 'fa_IR', 'ja' : '(Nihogo)', 'it_IT' : 'Italiano', 
+    'pt_BR' : 'Português', 'pl': 'polski', 'ru': 'Русский (Russkij)', 
+    'zh_CN' :'(Simplified Chinese)' }
+    return locale_descriptions
+
+def getLocaleName(lang):
+    # If the user passes in a locale that matches what we support, good
+    # However, anything that we don't support will result in us using a default locale
+    # 
+    # Important! lang is tainted data, don't forget this!
+    #
+    
+    default_locale = "en_US"
+
+    # We'd really like these additional locales to be translated:
+    # locales = ( 'ar', 'fr', 'nl', 'pt-PT', 'ru' )
+
+    # Make sure we have a valid language
+    if not lang:
+        return default_locale
+
+    # This is to deal with Mozilla and Debian having different ideas about
+    # what it means to be a locale
+    lang = lang.replace("-", "_")
+
+    # Do a case insensitive match
+    lang = lang.lower()
+
+    # Check for an exact match of language_country
+    for item in getLocales().keys():
+        if item.lower() == lang:
+            return item
+
+    # Check for just the language
+    lang = lang.split("_", 1)[0]
+    for item in getLocales().keys():
+        if item.lower().startswith(lang):
+            return item    
+
+    # Fall back to default
+    return default_locale
+    
+def parseLang(req):
+    user_supplied_lang = None
+    formSubmission=util.FieldStorage(req)
+    user_supplied_lang = formSubmission.getfirst("lang", None)
+
+    # Find the bast match for the requested language
+    locale = getLocaleName(user_supplied_lang)
+
+    # i18n with Unicode!
+    # Ensure you have properly installed TorCheck.{po,pot,mo} files
+    lang = gettext.translation('TorCheck', languages=[locale])
+    lang.install()    
+
+# Now that we know everything we need, lets print the website
+def handler(req):
+
+    # Make a DNS request to the EL and decide what to tell the user
+    UsingTor = isUsingTor(req.connection.remote_ip)
+
+    req.send_http_header()
+    req.content_type = 'text/html; charset=utf-8'
+
+    # First lets construct the simple webpage:
+    req.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" '\
+    '"http://www.w3.org/TR/REC-html40/loose.dtd">\n')
+    req.write('<html>\n')
+    req.write('<head>\n')
+    req.write('<meta http-equiv="content-type" content="text/html; '\
+    'charset=utf-8">\n')
+    req.write('<title>Are you using Tor?</title>\n')
+    req.write('<link rel="shortcut icon" type="image/x-icon" '\
+    'href="./favicon.ico">\n')
+    req.write('<style type="text/css">\n')
+    req.write('img,acronym {\n')
+    req.write('  border: 0;')
+    req.write('  text-decoration: none;')
+    req.write('}')
+    req.write('</style>')
+    req.write('</head>\n')
+    req.write('<body>\n')
+
+    parseLang(req)
+
+    req.write('<center>\n')
+
+    if UsingTor == 0:
+        req.write('\n')
+        req.write('<img alt="' + _("Congratulations. You are using Tor.") + \
+        '" src="https://check.torproject.org/images/tor-on.png">\n<br>')
+        req.write('<h1 style="color: #0A0">\n')
+        req.write(_('Congratulations. You are using Tor.'))
+        req.write('<br>\n<br>\n')
+        req.write('</h1>\n')
+        req.write(_('Please refer to the <a href="https://www.torproject.org/">Tor website</a> for further information about using Tor safely.'))
+        req.write('<br>\n<br>\n')
+    
+    # This is the case where we have an NXDOMAIN and they aren't using Tor
+    elif UsingTor == 1:
+        req.write('\n')
+        req.write('<img alt="' + _("Sorry. You are not using Tor.") + '" '\
+        'src="https://check.torproject.org/images/tor-off.png">\n<br>')
+        req.write('<h1 style="color: #A00">')
+        req.write(_('Sorry. You are not using Tor.'))
+        req.write('<br>\n<br>\n')
+        req.write('</h1>')
+        req.write(_('If you are attempting to use a Tor client, please refer to the <a href="https://www.torproject.org/">Tor website</a> and specifically the <a href="https://wiki.torproject.org/noreply/TheOnionRouter/TorFAQ#ItDoesntWork">instructions for configuring your Tor client</a>.'))
+        req.write('<br>\n<br>\n')
+
+    # This means we have some strange data response we don't understand
+    # It's better that we fail closed and let the user know everything went wrong
+    elif UsingTor == 2:
+        req.write('\n')
+        req.write('<img alt="' + _("Sorry, your query failed or an unexpected response was received.") + '" '\
+        'src="https://check.torproject.org/images/tor-off.png">\n<br>')
+        req.write('<h1 style="color: #A00">\n')
+        req.write(_('Sorry, your query failed or an unexpected response was received.'))
+        req.write('<br>\n')
+        req.write('</h1>')
+        req.write(_('A temporary service outage prevents us from determining if your source IP address is a <a href="https://www.torproject.org/">Tor</a> node.  For other ways to test whether you are using Tor, please visit <a href="https://wiki.torproject.org/noreply/TheOnionRouter/TorFAQ#IsMyConnectionPrivate">this FAQ entry</a>.'))
+        req.write('<br>\n<br>\n')
+
+    # Now we'll close up this html rat hole
+    req.write('\n')
+    req.write('<br>\n');
+    req.write('<small>\n')
+    req.write('<tt>')
+    req.write(_('Additional information: '))
+    req.write('<br>\n')
+    req.write(_('Your IP address appears to be: '))
+    req.write('<b>%s</b><br>\n' % req.connection.remote_ip )
+    req.write(_('This small script is powered by <a href="6http://exitlist.torproject.org/">tordnsel</a>'))
+    req.write('<br>')
+    req.write(_('You may also be interested in the <a href="/cgi-bin/TorBulkExitList.py">Tor Bulk Exit List Exporter</a>'))
+    req.write('<br><br>')
+    req.write(_('This server does not log <i>any</i> information about visitors.'))
+    req.write('<br>\n<br>\n')
+    # We want to display little pretty images so users can choose their language
+    locales = getLocales()
+
+    for item in sorted(locales.keys()):
+        req.write('<a href="?lang=%s">' % item )
+        req.write('<acronym title="%s">' % locales[item] )
+        req.write('<img src="images/%s.png" ' % item )
+        req.write('alt="%s" width="24" height="16">' % item )
+        req.write('</acronym>')
+        req.write('</a> ')
+    req.write('</tt>')
+    req.write('</small>')
+    req.write('</center>\n')
+    req.write('</body>')
+    req.write('</html>')
+
+    return apache.OK

Deleted: check/trunk/cgi-bin/index.py
===================================================================
--- check/trunk/cgi-bin/index.py	2008-05-30 04:29:12 UTC (rev 14838)
+++ check/trunk/cgi-bin/index.py	2008-05-30 05:28:18 UTC (rev 14839)
@@ -1,240 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""
- TorCheck.py
-
- https://check.torproject.org - originally in perl, rewritten in python
-
- By Jacob Appelbaum <jacob at appelbaum.net>
- Written at ToorCon Seattle 2008 (Thanks for the great time h1kari!)
- Thanks to Crispen for a power outlet :-)
- 
- Additional python suggestions from nickm
- 
- Best used with the Debian packages:
-    python-dns
-    libapache2-mod-python
-    locales-all
-
-"""
-
-__program__ = 'TorCheck.py'
-__version__ = '20080529.01'
-__url__ = 'https://tor-svn.freehaven.net/svn/check/'
-__author__ = 'Jacob Appelbaum <jacob at appelbaum.net>'
-__copyright__ = 'Copyright (c) 2008, Jacob Appelbaum'
-__license__ = 'See LICENSE for licensing information'
-
-try:
-    from future import antigravity
-except ImportError:
-    antigravity = None
-
-import DNS 
-# This is pydns and can be downloaded from http://pydns.sourceforge.net/ 
-# Or use the Debian package listed above
-from mod_python import apache
-from mod_python import util
-import cgitb; cgitb.enable()
-import gettext
-import locale
-
-# We could also explictly query the remote EL server
-# This is not as good as using a cache for obvious reasons
-DNS.DiscoverNameServers()
-
-def isUsingTor(clientIp):
-    # This is the exit node ip address
-    # This is where we want to dynamically recieve this from Apache
-    splitIp = clientIp.split('.')
-    splitIp.reverse()
-    ELExitNode = ".".join(splitIp)
-
-    # We'll attempt to reach this port on the Target host
-    ELPort = "80"
-
-    # We'll try to reach this host
-    ElTarget = "217.247.237.209"
-
-    # This is the ExitList DNS server we want to query
-    ELHost = "ip-port.exitlist.torproject.org"
-
-    # Prepare the question as an A record request
-    ELQuestion = ELExitNode + "." + ELPort + "." + ElTarget + "." + ELHost 
-    request = DNS.DnsRequest(name=ELQuestion,qtype='A')
-
-    # Ask the question and load the data into our answer
-    answer=request.req()
-
-    # Parse the answer and decide if it's allowing exits
-    # 127.0.0.2 is an exit and NXDOMAIN is not
-    if answer.header['status'] == "NXDOMAIN":
-        # We're not exiting from a Tor exit
-        return 1
-    else:
-        if not answer.answers:
-            # We're getting unexpected data - fail closed
-            return 2
-        for a in answer.answers:
-            if a['data'] != "127.0.0.2":
-                return 2
-        # If we're here, we've had a positive exit answer
-        return 0
-
-def getLocales():
-    locale_descriptions = { 'en_US' : 'English', 'de' : 'Deutsch', 'es' :
-    'español','fa_IR' : 'fa_IR', 'ja' : '(Nihogo)', 'it_IT' : 'Italiano', 
-    'pt_BR' : 'Português', 'pl': 'polski', 'ru': 'Русский (Russkij)', 
-    'zh_CN' :'(Simplified Chinese)' }
-    return locale_descriptions
-
-def getLocaleName(lang):
-    # If the user passes in a locale that matches what we support, good
-    # However, anything that we don't support will result in us using a default locale
-    # 
-    # Important! lang is tainted data, don't forget this!
-    #
-    
-    default_locale = "en_US"
-
-    # We'd really like these additional locales to be translated:
-    # locales = ( 'ar', 'fr', 'nl', 'pt-PT', 'ru' )
-
-    # Make sure we have a valid language
-    if not lang:
-        return default_locale
-
-    # This is to deal with Mozilla and Debian having different ideas about
-    # what it means to be a locale
-    lang = lang.replace("-", "_")
-
-    # Do a case insensitive match
-    lang = lang.lower()
-
-    # Check for an exact match of language_country
-    for item in getLocales().keys():
-        if item.lower() == lang:
-            return item
-
-    # Check for just the language
-    lang = lang.split("_", 1)[0]
-    for item in getLocales().keys():
-        if item.lower().startswith(lang):
-            return item    
-
-    # Fall back to default
-    return default_locale
-    
-def parseLang(req):
-    user_supplied_lang = None
-    formSubmission=util.FieldStorage(req)
-    user_supplied_lang = formSubmission.getfirst("lang", None)
-
-    # Find the bast match for the requested language
-    locale = getLocaleName(user_supplied_lang)
-
-    # i18n with Unicode!
-    # Ensure you have properly installed TorCheck.{po,pot,mo} files
-    lang = gettext.translation('TorCheck', languages=[locale])
-    lang.install()    
-
-# Now that we know everything we need, lets print the website
-def handler(req):
-
-    # Make a DNS request to the EL and decide what to tell the user
-    UsingTor = isUsingTor(req.connection.remote_ip)
-
-    req.send_http_header()
-    req.content_type = 'text/html; charset=utf-8'
-
-    # First lets construct the simple webpage:
-    req.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" '\
-    '"http://www.w3.org/TR/REC-html40/loose.dtd">\n')
-    req.write('<html>\n')
-    req.write('<head>\n')
-    req.write('<meta http-equiv="content-type" content="text/html; '\
-    'charset=utf-8">\n')
-    req.write('<title>Are you using Tor?</title>\n')
-    req.write('<link rel="shortcut icon" type="image/x-icon" '\
-    'href="./favicon.ico">\n')
-    req.write('<style type="text/css">\n')
-    req.write('img,acronym {\n')
-    req.write('  border: 0;')
-    req.write('  text-decoration: none;')
-    req.write('}')
-    req.write('</style>')
-    req.write('</head>\n')
-    req.write('<body>\n')
-
-    parseLang(req)
-
-    req.write('<center>\n')
-
-    if UsingTor == 0:
-        req.write('\n')
-        req.write('<img alt="' + _("Congratulations. You are using Tor.") + \
-        '" src="https://check.torproject.org/images/tor-on.png">\n<br>')
-        req.write('<h1 style="color: #0A0">\n')
-        req.write(_('Congratulations. You are using Tor.'))
-        req.write('<br>\n<br>\n')
-        req.write('</h1>\n')
-        req.write(_('Please refer to the <a href="https://www.torproject.org/">Tor website</a> for further information about using Tor safely.'))
-        req.write('<br>\n<br>\n')
-    
-    # This is the case where we have an NXDOMAIN and they aren't using Tor
-    elif UsingTor == 1:
-        req.write('\n')
-        req.write('<img alt="' + _("Sorry. You are not using Tor.") + '" '\
-        'src="https://check.torproject.org/images/tor-off.png">\n<br>')
-        req.write('<h1 style="color: #A00">')
-        req.write(_('Sorry. You are not using Tor.'))
-        req.write('<br>\n<br>\n')
-        req.write('</h1>')
-        req.write(_('If you are attempting to use a Tor client, please refer to the <a href="https://www.torproject.org/">Tor website</a> and specifically the <a href="https://wiki.torproject.org/noreply/TheOnionRouter/TorFAQ#ItDoesntWork">instructions for configuring your Tor client</a>.'))
-        req.write('<br>\n<br>\n')
-
-    # This means we have some strange data response we don't understand
-    # It's better that we fail closed and let the user know everything went wrong
-    elif UsingTor == 2:
-        req.write('\n')
-        req.write('<img alt="' + _("Sorry, your query failed or an unexpected response was received.") + '" '\
-        'src="https://check.torproject.org/images/tor-off.png">\n<br>')
-        req.write('<h1 style="color: #A00">\n')
-        req.write(_('Sorry, your query failed or an unexpected response was received.'))
-        req.write('<br>\n')
-        req.write('</h1>')
-        req.write(_('A temporary service outage prevents us from determining if your source IP address is a <a href="https://www.torproject.org/">Tor</a> node.  For other ways to test whether you are using Tor, please visit <a href="https://wiki.torproject.org/noreply/TheOnionRouter/TorFAQ#IsMyConnectionPrivate">this FAQ entry</a>.'))
-        req.write('<br>\n<br>\n')
-
-    # Now we'll close up this html rat hole
-    req.write('\n')
-    req.write('<br>\n');
-    req.write('<small>\n')
-    req.write('<tt>')
-    req.write(_('Additional information: '))
-    req.write('<br>\n')
-    req.write(_('Your IP address appears to be: '))
-    req.write('<b>%s</b><br>\n' % req.connection.remote_ip )
-    req.write(_('This small script is powered by <a href="6http://exitlist.torproject.org/">tordnsel</a>'))
-    req.write('<br>')
-    req.write(_('You may also be interested in the <a href="/cgi-bin/TorBulkExitList.py">Tor Bulk Exit List Exporter</a>'))
-    req.write('<br><br>')
-    req.write(_('This server does not log <i>any</i> information about visitors.'))
-    req.write('<br>\n<br>\n')
-    # We want to display little pretty images so users can choose their language
-    locales = getLocales()
-
-    for item in sorted(locales.keys()):
-        req.write('<a href="?lang=%s">' % item )
-        req.write('<acronym title="%s">' % locales[item] )
-        req.write('<img src="images/%s.png" ' % item )
-        req.write('alt="%s" width="24" height="16">' % item )
-        req.write('</acronym>')
-        req.write('</a> ')
-    req.write('</tt>')
-    req.write('</small>')
-    req.write('</center>\n')
-    req.write('</body>')
-    req.write('</html>')
-
-    return apache.OK



More information about the tor-commits mailing list